From 81f7516340d82b919b1420ca49f09b73a8ce4b1f Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 7 Sep 2010 20:17:53 -0600 Subject: [PATCH] Initial work in getting Gollem to work again. --- gollem/clipboard.php | 40 +-- gollem/config/backends.php.dist | 246 +++++++-------- gollem/config/conf.xml | 6 +- gollem/config/credentials.php.dist | 29 -- gollem/config/prefs.php.dist | 42 ++- gollem/docs/CHANGES | 2 +- gollem/docs/INSTALL | 2 +- gollem/edit.php | 50 ++- gollem/index.php | 8 +- gollem/lib/Api.php | 345 ++++++++------------- gollem/lib/Application.php | 61 ++-- gollem/lib/Exception.php | 15 + gollem/lib/Gollem.php | 141 +++++---- .../LoginTasks/SystemTask/UpgradeFromGollem1.php | 47 +++ gollem/lib/Mime/Viewer/Images.php | 6 +- gollem/manager.php | 245 ++++++++------- gollem/permissions.php | 18 +- gollem/quota.php | 30 +- gollem/selectlist.php | 104 +++---- gollem/view.php | 40 +-- 20 files changed, 712 insertions(+), 765 deletions(-) delete mode 100644 gollem/config/credentials.php.dist create mode 100644 gollem/lib/Exception.php create mode 100644 gollem/lib/LoginTasks/SystemTask/UpgradeFromGollem1.php diff --git a/gollem/clipboard.php b/gollem/clipboard.php index 73c044648..b0fdf4da5 100644 --- a/gollem/clipboard.php +++ b/gollem/clipboard.php @@ -7,8 +7,10 @@ * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * - * @author Michael Slusarz - * @package Gollem + * @author Michael Slusarz + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Gollem */ require_once dirname(__FILE__) . '/lib/Application.php'; @@ -16,22 +18,6 @@ Horde_Registry::appInit('gollem'); $dir = Horde_Util::getFormData('dir'); -$title = _("Clipboard"); -Horde::addScriptFile('tables.js', 'horde'); -require GOLLEM_TEMPLATES . '/common-header.inc'; -Gollem::menu(); -Gollem::status(); - -$entry = array(); -foreach ($_SESSION['gollem']['clipboard'] as $key => $val) { - $entry[] = array( - 'copy' => ($val['action'] == 'copy'), - 'cut' => ($val['action'] == 'cut'), - 'id' => $key, - 'name' => $val['display'] - ); -} - /* Set up the template object. */ $template = $injector->createInstance('Horde_Template'); $template->setOption('gettext', true); @@ -42,8 +28,24 @@ $template->set('cutgraphic', Horde::img('cut.png', _("Cut"))); $template->set('copygraphic', Horde::img('copy.png', _("Copy"))); $template->set('currdir', Gollem::getDisplayPath($dir)); $template->set('dir', $dir); -$template->set('entry', $entry, true); $template->set('manager_url', Horde::url('manager.php')); +$entry = array(); +foreach ($_SESSION['gollem']['clipboard'] as $key => $val) { + $entry[] = array( + 'copy' => ($val['action'] == 'copy'), + 'cut' => ($val['action'] == 'cut'), + 'id' => $key, + 'name' => $val['display'] + ); +} +$template->set('entry', $entry, true); + +$title = _("Clipboard"); +Horde::addScriptFile('tables.js', 'horde'); +Gollem::prepareMenu(); +require GOLLEM_TEMPLATES . '/common-header.inc'; +Gollem::menu(); +Gollem::status(); echo $template->fetch(GOLLEM_TEMPLATES . '/clipboard/clipboard.html'); require $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/gollem/config/backends.php.dist b/gollem/config/backends.php.dist index 3096bf950..32a2c4229 100644 --- a/gollem/config/backends.php.dist +++ b/gollem/config/backends.php.dist @@ -1,58 +1,56 @@ = 3.1 for this parameter to - // have any effect. // 'maplocalids' => true, // The default permissions to set for newly created folders and files. // 'permissions' => '750' @@ -274,81 +270,75 @@ $backends['file'] = array( ); // SMB Example -// ** For the SMB backend to work, you must be using a version of Horde -// ** that contains the SMB VFS driver. See the test.php script to determine -// ** whether the SMB driver is present on your system. -// $backends['smb'] = array( -// 'name' => 'SMB Server', -// 'driver' => 'smb', -// 'preferred' => '', -// 'hordeauth' => false, -// 'params' => array( -// 'hostspec' => 'example', -// 'port' => 139, -// 'share' => 'homes', -// // Path to the smbclient executable. -// 'smbclient' => '/usr/bin/smbclient', -// // IP address of server (only needed if hostname is different from -// // NetBIOS name). -// // 'ipaddress' => '127.0.0.1', -// // The default permissions to set for newly created folders and -// // files. -// // 'permissions' => '750' -// ), -// 'loginparams' => array( -// // Allow the user to change to Samba server. -// // 'hostspec' => 'Hostname', -// // Allow the user to change the Samba port. -// // 'port' => 'Port', -// // Allow the user to change the Samba share. -// // 'share' => 'Share', -// ), -// // 'root' => '', -// // 'home' => '', -// // 'createhome' => false, -// // 'filter' => '^regex$', -// // 'quota' => false, -// 'clipboard' => true, -// 'attributes' => array('type', 'name', 'edit', 'download', 'modified', 'size') -// ); +$backends['smb'] = array( + 'name' => 'SMB Server', + 'driver' => 'smb', + 'preferred' => '', + 'hordeauth' => false, + 'params' => array( + 'hostspec' => 'example', + 'port' => 139, + 'share' => 'homes', + // Path to the smbclient executable. + 'smbclient' => '/usr/bin/smbclient', + // IP address of server (only needed if hostname is different from + // NetBIOS name). + // 'ipaddress' => '127.0.0.1', + // The default permissions to set for newly created folders and + // files. + // 'permissions' => '750' + ), + 'loginparams' => array( + // Allow the user to change to Samba server. + // 'hostspec' => 'Hostname', + // Allow the user to change the Samba port. + // 'port' => 'Port', + // Allow the user to change the Samba share. + // 'share' => 'Share', + ), + // 'root' => '', + // 'home' => '', + // 'createhome' => false, + // 'filter' => '^regex$', + // 'quota' => false, + 'clipboard' => true, + 'attributes' => array('type', 'name', 'edit', 'download', 'modified', 'size') +); // SSH2 Example -// ** For the SSH2 backend to work, you must be using a version of Horde -// ** that contains the SSH2 VFS driver. See the test.php script to determine -// ** whether the SSH2 driver is present on your system. -// $backends['ssh2'] = array( -// 'name' => 'SSH2 Server', -// 'driver' => 'ssh2', -// 'preferred' => '', -// 'hordeauth' => false, -// 'params' => array( -// // The hostname/IP Address of the SSH server -// 'hostspec' => 'ssh2.example.com', -// // The port number of the SSH server -// 'port' => 22, -// // Set timeout (in seconds) for the SSH server. Default: 90 seconds -// // 'timeout' => 90, -// // If true and the POSIX extension is available the driver will map -// // the user and group IDs returned from the SSH server with the local -// // IDs from the local password file. This is useful only if the SSH -// // server is running on localhost or if the local user/group -// // IDs are identical to the remote SSH server. -// // 'maplocalids' => true, -// // The default permissions to set for newly created folders and -// // files. -// // 'permissions' => '750' -// ), -// 'loginparams' => array( -// // Allow the user to change the SSH server -// // 'hostspec' => 'Hostname', -// // Allow the user to change the SSH port -// // 'port' => 'Port' -// ), -// // 'root' => '', -// // 'home' => '', -// // 'createhome' => false, -// // 'filter' => '^regex$', -// // 'quota' => false, -// 'clipboard' => true, -// 'attributes' => array('type', 'name', 'edit', 'download', 'modified', 'size', 'permission', 'owner', 'group') -// ); +$backends['ssh2'] = array( + 'name' => 'SSH2 Server', + 'driver' => 'ssh2', + 'preferred' => '', + 'hordeauth' => false, + 'params' => array( + // The hostname/IP Address of the SSH server + 'hostspec' => 'ssh2.example.com', + // The port number of the SSH server + 'port' => 22, + // Set timeout (in seconds) for the SSH server. Default: 90 seconds + // 'timeout' => 90, + // If true and the POSIX extension is available the driver will map + // the user and group IDs returned from the SSH server with the local + // IDs from the local password file. This is useful only if the SSH + // server is running on localhost or if the local user/group + // IDs are identical to the remote SSH server. + // 'maplocalids' => true, + // The default permissions to set for newly created folders and + // files. + // 'permissions' => '750' + ), + 'loginparams' => array( + // Allow the user to change the SSH server + // 'hostspec' => 'Hostname', + // Allow the user to change the SSH port + // 'port' => 'Port' + ), + // 'root' => '', + // 'home' => '', + // 'createhome' => false, + // 'filter' => '^regex$', + // 'quota' => false, + 'clipboard' => true, + 'attributes' => array('type', 'name', 'edit', 'download', 'modified', 'size', 'permission', 'owner', 'group') +); diff --git a/gollem/config/conf.xml b/gollem/config/conf.xml index bbea5f6af..6b6ab716e 100644 --- a/gollem/config/conf.xml +++ b/gollem/config/conf.xml @@ -13,9 +13,9 @@ If it is 'shown', the user will be able to pick from any of the options.">none - none - hidden - shown + none + hidden + shown diff --git a/gollem/config/credentials.php.dist b/gollem/config/credentials.php.dist deleted file mode 100644 index 713db9f5e..000000000 --- a/gollem/config/credentials.php.dist +++ /dev/null @@ -1,29 +0,0 @@ - 'text', - 'desc' => _("Username") -); - -$credentials['password'] = array( - 'type' => 'password', - 'desc' => _("Password") -); - -$credentials['email'] = array( - 'type' => 'email', - 'desc' => _("Email") -); diff --git a/gollem/config/prefs.php.dist b/gollem/config/prefs.php.dist index 45248cc76..90d786a0c 100644 --- a/gollem/config/prefs.php.dist +++ b/gollem/config/prefs.php.dist @@ -5,29 +5,32 @@ * $Id$ */ +// *** File Display Preferences *** + $prefGroups['display'] = array( 'column' => _("User Interface"), 'label' => _("File Display"), - 'desc' => _("Change your file sorting options."), + 'desc' => _("File display options."), 'members' => array( 'show_dotfiles', 'sortdirsfirst', 'columnselect', 'sortby', 'sortdir', 'perpage' ) ); -$prefGroups['settings'] = array( - 'column' => _("User Interface"), - 'label' => _("Settings"), - 'desc' => _("Change file and folder handling settings."), - 'members' => array('recursive_deletes')); - // show dotfiles? $_prefs['show_dotfiles'] = array( - 'value' => 1, + 'value' => 0, 'type' => 'checkbox', 'desc' => _("Show dotfiles?") ); +// always sort directories before files +$_prefs['sortdirsfirst'] = array( + 'value' => 1, + 'type' => 'checkbox', + 'desc' => _("List folders first?") +); + // columns selection widget $_prefs['columnselect'] = array( 'type' => 'special' @@ -35,9 +38,11 @@ $_prefs['columnselect'] = array( // columns to be displayed $_prefs['columns'] = array( - 'value' => "ftp\ttype\tname\tdownload\tmodified\tsize\tpermission\towner\tgroup" + // 'value' = json_encode(array()) + 'value' => '["ftp","type","name","download","modified","size","permission","owner","group"]' ); + // user preferred sorting column $_prefs['sortby'] = array( 'value' => Gollem::SORT_TYPE, @@ -62,20 +67,23 @@ $_prefs['sortdir'] = array( 'desc' => _("Default sorting direction:") ); -// always sort directories before files -$_prefs['sortdirsfirst'] = array( - 'value' => 0, - 'type' => 'checkbox', - 'desc' => _("List folders first?") -); - // number of items per page $_prefs['perpage'] = array( - 'value' => 20, + 'value' => 30, 'type' => 'number', 'desc' => _("Items per page") ); + + +// *** File Actions Preferences *** + +$prefGroups['settings'] = array( + 'column' => _("User Interface"), + 'label' => _("File Actions"), + 'desc' => _("File action settings."), + 'members' => array('recursive_deletes')); + // user preferred recursive deletes $_prefs['recursive_deletes'] = array( 'value' => 'disabled', diff --git a/gollem/docs/CHANGES b/gollem/docs/CHANGES index 5dbc782dd..16ea042cf 100644 --- a/gollem/docs/CHANGES +++ b/gollem/docs/CHANGES @@ -2,7 +2,7 @@ v2.0-git -------- - +[mms] Convert to use H4. ---------- diff --git a/gollem/docs/INSTALL b/gollem/docs/INSTALL index f886fa9ae..bf8c8917f 100644 --- a/gollem/docs/INSTALL +++ b/gollem/docs/INSTALL @@ -44,7 +44,7 @@ To function properly, Gollem **REQUIRES** the following: for Web applications written in PHP. You must install Horde before before installing Gollem. - .. Important:: Gollem 2.0 requires version 4.0 of the Horde Framework - + .. Important:: Gollem 2 requires version 4 of the Horde Framework - earlier versions of Horde will **not** work. The Horde Framework can be obtained from the Horde website and FTP server, diff --git a/gollem/edit.php b/gollem/edit.php index 0c4bdfddb..99ff74f4a 100644 --- a/gollem/edit.php +++ b/gollem/edit.php @@ -7,53 +7,51 @@ * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * - * @author Jan Schneider - * @package Gollem + * @author Jan Schneider + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Gollem */ require_once dirname(__FILE__) . '/lib/Application.php'; Horde_Registry::appInit('gollem'); -$actionID = Horde_Util::getFormData('actionID'); -$driver = Horde_Util::getFormData('driver'); -$filedir = Horde_Util::getFormData('dir'); -$filename = Horde_Util::getFormData('file'); -$type = Horde_Util::getFormData('type'); +$vars = Horde_Variables::getDefaultVariables(); -if ($driver != $GLOBALS['gollem_be']['driver']) { +if ($vars->driver != $GLOBALS['gollem_be']['driver']) { echo Horde::wrapInlineScript(array('window.close();')); exit; } /* Run through action handlers. */ -switch ($actionID) { +switch ($vars->actionID) { case 'save_file': - $data = Horde_Util::getFormData('content'); - $result = $gollem_vfs->writeData($filedir, $filename, $data); - if (is_a($result, 'PEAR_Error')) { - $message = sprintf(_("Access denied to %s"), $filename); - } else { - $message = sprintf(_("%s successfully saved."), $filename); + try { + $gollem_vfs->writeData($vars->filedir, $vars->filename, $vars->content); + $message = sprintf(_("%s successfully saved."), $vars->filename); + } catch (VFS_Exception $e) { + $message = sprintf(_("Access denied to %s"), $vars->filename); } echo Horde::wrapInlineScript(array( - 'alert("' . addslashes($message) . '");', - 'window.close();' + 'alert("' . addslashes($message) . '")' )); - exit; + break; case 'edit_file': - $data = $gollem_vfs->read($filedir, $filename); - if (is_a($data, 'PEAR_Error')) { + try { + $data = $gollem_vfs->read($vars->filedir, $vars->filename); + } catch (VFS_Exception $e) { echo Horde::wrapInlineScript(array( - 'alert("' . addslashes(sprintf(_("Access denied to %s"), $filename)) . '");', - 'window.close();' + 'alert("' . addslashes(sprintf(_("Access denied to %s"), $vars->filename)) . '")' )); - exit; + break; } - $mime_type = Horde_Mime_Magic::extToMIME($type); + + $mime_type = Horde_Mime_Magic::extToMIME($vars->type); if (strpos($mime_type, 'text/') !== 0) { - echo Horde::wrapInlineScript(array('window.close();')); + break; } + if ($mime_type == 'text/html') { $injector->getInstance('Horde_Editor')->getEditor('ckeditor', array('id' => 'content')); } @@ -64,4 +62,4 @@ case 'edit_file': exit; } -wcho Horde::wrapInlineScript(array('window.close();')); +echo Horde::wrapInlineScript(array('window.close()')); diff --git a/gollem/index.php b/gollem/index.php index 0ef70ec21..a2ee331f9 100644 --- a/gollem/index.php +++ b/gollem/index.php @@ -7,9 +7,11 @@ * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * - * @author Max Kalika - * @author Chuck Hagenbuch - * @package Gollem + * @author Max Kalika + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Gollem */ require dirname(__FILE__) . '/manager.php'; diff --git a/gollem/lib/Api.php b/gollem/lib/Api.php index 584d82b8c..016a5ce08 100644 --- a/gollem/lib/Api.php +++ b/gollem/lib/Api.php @@ -2,13 +2,20 @@ /** * Gollem external API interface. * - * This file defines Gollem's external API interface. Other - * applications can interact with Gollem through this API. + * This file defines Gollem's external API interface. Other applications + * can interact with Gollem through this API. * - * @author Amith Varghese - * @author Michael Slusarz - * @author Ben Klang - * @package Gollem + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @author Amith Varghese + * @author Michael Slusarz + * @author Ben Klang + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Gollem */ class Gollem_Api extends Horde_Registry_Api { @@ -19,21 +26,18 @@ class Gollem_Api extends Horde_Registry_Api * operations are allowed outside any VFS area. * * @param string $path The level of the tree to browse. - * @param array $properties The item properties to return. Defaults to 'name', - * 'icon', and 'browseable'. + * @param array $properties The item properties to return. Defaults to + * 'name', 'icon', and 'browseable'. * * @return array The contents of $path. + * @throws Gollem_Exception */ - public function browse($path = '', $properties = array()) + public function browse($path = '', + $properties = array('name', 'icon' ,'browseable')) { $path = Gollem::stripAPIPath($path); - - // Default properties. - if (!$properties) { - $properties = array('name', 'icon', 'browseable'); - } - $results = array(); + if ($path == '') { // We are at the root of gollem. Return a set of folders, one for // each backend available. @@ -44,30 +48,7 @@ class Gollem_Api extends Horde_Registry_Api } } } else { - // A file or directory has been requested. - - // Locate the backend_key in the path. - if (strchr($path, '/')) { - $backend_key = substr($path, 0, strpos($path, '/')); - } else { - $backend_key = $path; - } - - // Validate and perform permissions checks on the requested backend - if (!isset($backends[$backend_key])) { - return PEAR::raiseError(sprintf(_("Invalid backend requested: %s"), $backend_key)); - } - //if (!Gollem::canAutoLogin($backend_key)) { - // // FIXME: Is it possible to request secondary authentication - // // credentials here for backends that require it? - // return PEAR::raiseError(_("Additional authentication required.")); - //} - if (!Gollem_Session::createSession($backend_key)) { - return PEAR::raiseError(_("Unable to create Gollem session")); - } - if (!Gollem::checkPermissions('backend', Horde_Perms::READ)) { - return PEAR::raiseError(_("Permission denied to this backend.")); - } + $backend_key = $this->_getBackend($path); // Trim off the backend_key (and '/') to get the VFS relative path $fullpath = substr($path, strlen($backend_key) + 1); @@ -79,9 +60,6 @@ class Gollem_Api extends Horde_Registry_Api if ($GLOBALS['gollem_vfs']->isFolder($path, $name)) { // This is a folder request. Return a directory listing. $list = Gollem::listFolder($path . '/' . $name); - if (is_a($list, 'PEAR_Error')) { - return $list; - } // Iterate over the directory contents if (is_array($list) && count($list)) { @@ -100,7 +78,6 @@ class Gollem_Api extends Horde_Registry_Api } } else { // A file has been requested. Return the contents of the file. - // Get the file meta-data $list = Gollem::listFolder($path); $i = false; @@ -115,15 +92,9 @@ class Gollem_Api extends Horde_Registry_Api return $i; } - // Read the file contents - $data = $GLOBALS['gollem_vfs']->read($path, $name); - if (is_a($data, 'PEAR_Error')) { - return false; - } - // Send the file $results['name'] = $name; - $results['data'] = $data; + $results['data'] = $GLOBALS['gollem_vfs']->read($path, $name); $results['contentlength'] = $list[$i]['size']; $results['mtime'] = $list[$i]['date']; } @@ -133,13 +104,13 @@ class Gollem_Api extends Horde_Registry_Api } /** - * Accepts a file for storage into the VFS + * Accepts a file for storage into the VFS. * - * @param string $path Path to store file - * @param string $content Contents of file - * @param string $content_type MIME type of file + * @param string $path Path to store file. + * @param string $content Contents of file. + * @param string $content_type MIME type of file. * - * @return mixed True on success; PEAR_Error on failure + * @throws Gollem_Exception */ public function put($path, $content, $content_type) { @@ -149,40 +120,18 @@ class Gollem_Api extends Horde_Registry_Api if ($path == '') { // We are at the root of gollem. Any writes at this level are // disallowed. - return PEAR::raiseError(_("Files must be written inside a VFS backend.")); - } else { - // We must be inside one of the VFS areas. Determine which one. - // Locate the backend_key in the path - if (strchr($path, '/')) { - $backend_key = substr($path, 0, strpos($path, '/')); - } else { - $backend_key = $path; - } + throw new Gollem_Exception(_("Files must be written inside a VFS backend.")); + } - // Validate and perform permissions checks on the requested backend - if (!isset($backends[$backend_key])) { - return PEAR::raiseError(sprintf(_("Invalid backend requested: %s"), $backend_key)); - } - //if (!Gollem::canAutoLogin($backend_key)) { - // // FIXME: Is it possible to request secondary authentication - // // credentials here for backends that require it? - // return PEAR::raiseError(_("Additional authentication required.")); - //} - if (!Gollem_Session::createSession($backend_key)) { - return PEAR::raiseError(_("Unable to create Gollem session")); - } - if (!Gollem::checkPermissions('backend', Horde_Perms::EDIT)) { - return PEAR::raiseError(_("Permission denied to this backend.")); - } + $backend_key = $this->_getBackend($path); - // Trim off the backend_key (and '/') to get the VFS relative path - $fullpath = substr($path, strlen($backend_key) + 1); + // Trim off the backend_key (and '/') to get the VFS relative path + $fullpath = substr($path, strlen($backend_key) + 1); - // Get the VFS-standard $name,$path pair - list($name, $path) = Gollem::getVFSPath($fullpath); + // Get the VFS-standard $name,$path pair + list($name, $path) = Gollem::getVFSPath($fullpath); - return $GLOBALS['gollem_vfs']->writeData($path, $name, $content); - } + return $GLOBALS['gollem_vfs']->writeData($path, $name, $content); } /** @@ -190,7 +139,7 @@ class Gollem_Api extends Horde_Registry_Api * * @param string $path Path of directory to create * - * @return mixed True on success; PEAR_Error on failure + * @throws Gollem_Exception */ public function mkcol($path) { @@ -200,41 +149,18 @@ class Gollem_Api extends Horde_Registry_Api if ($path == '') { // We are at the root of gollem. Any writes at this level are // disallowed. - return PEAR::raiseError(_('Folders must be created inside a VFS backend.')); - } else { - // We must be inside one of the VFS areas. Determine which one. - // Locate the backend_key in the path - if (!strchr($path, '/')) { - // Disallow attempts to create a share-level directory. - return PEAR::raiseError(_('Folders must be created inside a VFS backend.')); - } else { - $backend_key = substr($path, 0, strpos($path, '/')); - } + throw new Gollem_Exception(_('Folders must be created inside a VFS backend.')); + } - // Validate and perform permissions checks on the requested backend - if (!isset($backends[$backend_key])) { - return PEAR::raiseError(sprintf(_("Invalid backend requested: %s"), $backend_key)); - } - //if (!Gollem::canAutoLogin($backend_key)) { - // // FIXME: Is it possible to request secondary authentication - // // credentials here for backends that require it? - // return PEAR::raiseError(_("Additional authentication required.")); - //} - if (!Gollem_Session::createSession($backend_key)) { - return PEAR::raiseError(_("Unable to create Gollem session")); - } - if (!Gollem::checkPermissions('backend', Horde_Perms::EDIT)) { - return PEAR::raiseError(_("Permission denied to this backend.")); - } + $backend_key = $this->_getBackend($path); - // Trim off the backend_key (and '/') to get the VFS relative path - $fullpath = substr($path, strlen($backend_key) + 1); + // Trim off the backend_key (and '/') to get the VFS relative path + $fullpath = substr($path, strlen($backend_key) + 1); - // Get the VFS-standard $name,$path pair - list($name, $path) = Gollem::getVFSPath($fullpath); + // Get the VFS-standard $name,$path pair + list($name, $path) = Gollem::getVFSPath($fullpath); - return $GLOBALS['gollem_vfs']->createFolder($path, $name); - } + return $GLOBALS['gollem_vfs']->createFolder($path, $name); } /** @@ -242,8 +168,6 @@ class Gollem_Api extends Horde_Registry_Api * * @param string $path Path to source object to be renamed * @param string $dest Path to new name - * - * @return mixed True on success; PEAR_Error on failure */ public function move($path, $dest) { @@ -254,62 +178,38 @@ class Gollem_Api extends Horde_Registry_Api if ($path == '') { // We are at the root of gollem. Any writes at this level are // disallowed. - return PEAR::raiseError(_('Folders must be created inside a VFS backend.')); - } else { - // We must be inside one of the VFS areas. Determine which one. - // Locate the backend_key in the path - if (!strchr($path, '/')) { - // Disallow attempts to rename a share-level directory. - return PEAR::raiseError(_('Renaming of backends is not allowed.')); - } else { - $backend_key = substr($path, 0, strpos($path, '/')); - } + throw new Gollem_Exception(_('Folders must be created inside a VFS backend.')); + } - // Ensure that the destination is within the same backend - if (!strchr($dest, '/')) { - // Disallow attempts to rename a share-level directory. - return PEAR::raiseError(_('Renaming of backends is not allowed.')); - } else { - $dest_backend_key = substr($path, 0, strpos($path, '/')); - if ($dest_backend_key != $backend_key) { - return PEAR::raiseError(_('Renaming across backends is not supported.')); - } - } + // We must be inside one of the VFS areas. Determine which one. + // Locate the backend_key in the path + if (!strchr($path, '/') || + !strchr($dest, '/')) { + // Disallow attempts to rename a share-level directory. + throw new Gollem_Exception(_('Renaming of backends is not allowed.')); + } - // Validate and perform permissions checks on the requested backend - if (!isset($backends[$backend_key])) { - return PEAR::raiseError(sprintf(_("Invalid backend requested: %s"), $backend_key)); - } - //if (!Gollem::canAutoLogin($backend_key)) { - // // FIXME: Is it possible to request secondary authentication - // // credentials here for backends that require it? - // return PEAR::raiseError(_("Additional authentication required.")); - //} - if (!Gollem_Session::createSession($backend_key)) { - return PEAR::raiseError(_("Unable to create Gollem session")); - } - if (!Gollem::checkPermissions('backend', Horde_Perms::EDIT)) { - return PEAR::raiseError(_("Permission denied to this backend.")); - } + $backend_key = $this->_getBackend($path); + $dest_backend_key = substr($path, 0, strpos($path, '/')); + if ($dest_backend_key != $backend_key) { + throw new Gollem_Exception(_('Renaming across backends is not supported.')); + } - // Trim off the backend_key (and '/') to get the VFS relative path - $srcfullpath = substr($path, strlen($backend_key) + 1); - $dstfullpath = substr($dest, strlen($backend_key) + 1); + // Trim off the backend_key (and '/') to get the VFS relative path + $srcfullpath = substr($path, strlen($backend_key) + 1); + $dstfullpath = substr($dest, strlen($backend_key) + 1); - // Get the VFS-standard $name,$path pair - list($srcname, $srcpath) = Gollem::getVFSPath($srcfullpath); - list($dstname, $dstpath) = Gollem::getVFSPath($dstfullpath); + // Get the VFS-standard $name,$path pair + list($srcname, $srcpath) = Gollem::getVFSPath($srcfullpath); + list($dstname, $dstpath) = Gollem::getVFSPath($dstfullpath); - return $GLOBALS['gollem_vfs']->rename($srcpath, $srcname, $dstpath, $dstname); - } + $GLOBALS['gollem_vfs']->rename($srcpath, $srcname, $dstpath, $dstname); } /** * Removes a file or folder from the VFS * * @param string $path Path of file or folder to delete - * - * @return mixed True on success; PEAR_Error on failure */ public function path_delete($path) { @@ -319,47 +219,24 @@ class Gollem_Api extends Horde_Registry_Api if ($path == '') { // We are at the root of gollem. Any writes at this level are // disallowed. - return PEAR::raiseError(_("The application folder can not be deleted.")); - } else { - // We must be inside one of the VFS areas. Determine which one. - // Locate the backend_key in the path - if (strchr($path, '/')) { - $backend_key = substr($path, 0, strpos($path, '/')); - } else { - $backend_key = $path; - } + throw new Gollem_Exception(_("The application folder can not be deleted.")); + } - // Validate and perform permissions checks on the requested backend - if (!isset($backends[$backend_key])) { - return PEAR::raiseError(sprintf(_("Invalid backend requested: %s"), $backend_key)); - } - //if (!Gollem::canAutoLogin($backend_key)) { - // // FIXME: Is it possible to request secondary authentication - // // credentials here for backends that require it? - // return PEAR::raiseError(_("Additional authentication required.")); - //} - if (!Gollem_Session::createSession($backend_key)) { - return PEAR::raiseError(_("Unable to create Gollem session")); - } - if (!Gollem::checkPermissions('backend', Horde_Perms::EDIT)) { - return PEAR::raiseError(_("Permission denied to this backend.")); - } + $backend_key = $this->_getBackend($path); - // Trim off the backend_key (and '/') to get the VFS relative path - $fullpath = substr($path, strlen($backend_key) + 1); + // Trim off the backend_key (and '/') to get the VFS relative path + $fullpath = substr($path, strlen($backend_key) + 1); - // Get the VFS-standard $name,$path pair - list($name, $path) = Gollem::getVFSPath($fullpath); + // Get the VFS-standard $name,$path pair + list($name, $path) = Gollem::getVFSPath($fullpath); - // Apparently Gollem::verifyDir() (called by deleteF* next) needs to - // see a path with a leading '/' - $path = $backends[$backend_key]['root'] . $path; - if ($GLOBALS['gollem_vfs']->isFolder($path, $name)) { - return Gollem::deleteFolder($path, $name); - } else { - return Gollem::deleteFile($path, $name); - } - } + // Apparently Gollem::verifyDir() (called by deleteF* next) needs to + // see a path with a leading '/' + $path = $backends[$backend_key]['root'] . $path; + + $GLOBALS['gollem_vfs']->isFolder($path, $name) + ? Gollem::deleteFolder($path, $name) + : Gollem::deleteFile($path, $name); } /** @@ -367,9 +244,10 @@ class Gollem_Api extends Horde_Registry_Api * * @param string $dir File absolute path * @param string $file File basename - * @param string $backend Backend key. Defaults to Gollem::getPreferredBackend() + * @param string $backend Backend key. Defaults to + * Gollem::getPreferredBackend(). * - * @return string The URL string. + * @return Horde_Url The URL object. */ public function getViewLink($dir, $file, $backend = '') { @@ -377,23 +255,21 @@ class Gollem_Api extends Horde_Registry_Api $backend = Gollem::getPreferredBackend(); } - $url = Horde_Util::addParameter( - Horde::url('view.php'), - array('actionID' => 'view_file', - 'type' => substr($file, strrpos($file, '.') + 1), - 'file' => $file, + return Horde::url('view.php')->add(array( + 'actionID' => 'view_file', 'dir' => $dir, - 'driver' => $_SESSION['gollem']['backends'][$backend]['driver'])); - - return $url; + 'driver' => $_SESSION['gollem']['backends'][$backend]['driver'], + 'file' => $file, + 'type' => substr($file, strrpos($file, '.') + 1) + )); } /** * Creates a link to the gollem file selection window. * - * The file section window will return a cache ID value which should be used - * (along with the selectListResults and returnFromSelectList functions below) - * to obtain the data from a list of selected files. + * The file section window will return a cache ID value which should be + * used (along with the selectListResults and returnFromSelectList + * functions below) to obtain the data from a list of selected files. * * There MUST be a form field named 'selectlist_selectid' in the calling * form. This field will be populated with the selection ID when the user @@ -408,7 +284,8 @@ class Gollem_Api extends Horde_Registry_Api * @param string $link_text The text to use in the link. * @param string $link_style The style to use for the link. * @param string $formid The formid of the calling script. - * @param boolean $icon Create the link with an icon instead of text? + * @param boolean $icon Create the link with an icon instead of + * text? * @param string $selectid Selection ID. * * @return string The URL string. @@ -429,8 +306,9 @@ class Gollem_Api extends Horde_Registry_Api * * @param string $selectid The selection ID. * - * @param array An array with each file entry stored in its own array, with - * the key as the directory name and the value as the filename. + * @param array An array with each file entry stored in its own array, + * with the key as the directory name and the value as the + * filename. */ public function selectlistResults($selectid) { @@ -469,9 +347,9 @@ class Gollem_Api extends Horde_Registry_Api * Sets the files selected for a given selection ID. * * @param string $selectid The selection ID to use. - * @param array $files An array with each file entry stored in its own - * array, with the key as the directory name and the - * value as the filename. + * @param array $files An array with each file entry stored in its + * own array, with the key as the directory name + * and the value as the filename. * * @return string The selection ID. */ @@ -492,4 +370,31 @@ class Gollem_Api extends Horde_Registry_Api return $selectid; } + /** + * @throws Gollem_Exception + */ + protected function _getBackend($path) + { + // A file or directory has been requested. + // Locate the backend_key in the path. + $backend_key = strchr($path, '/') + ? substr($path, 0, strpos($path, '/')) + : $path; + + // Validate and perform permissions checks on the requested backend + if (!isset($_SESSION['gollem']['backends'][$backend_key])) { + throw new Gollem_Exception(sprintf(_("Invalid backend requested: %s"), $backend_key)); + } + + if (!Gollem_Session::createSession($backend_key)) { + throw new Gollem_Exception(_("Unable to create Gollem session")); + } + + if (!Gollem::checkPermissions('backend', Horde_Perms::READ)) { + throw new Gollem_Exception(_("Permission denied to this backend.")); + } + + return $backend_key; + } + } diff --git a/gollem/lib/Application.php b/gollem/lib/Application.php index 67cc17b9c..45c276c36 100644 --- a/gollem/lib/Application.php +++ b/gollem/lib/Application.php @@ -5,13 +5,17 @@ * This file defines Horde's core API interface. Other core Horde libraries * can interact with Horde through this API. * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * - * @author Amith Varghese - * @author Michael Slusarz - * @author Ben Klang - * @package Gollem + * @author Amith Varghese + * @author Michael Slusarz + * @author Ben Klang + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Gollem */ /* Determine the base directories. */ @@ -43,13 +47,6 @@ class Gollem_Application extends Horde_Registry_Application public $version = 'H4 (2.0-git)'; /** - * Permissions cache. - * - * @var array - */ - protected $_permsCache = array(); - - /** * Gollem initialization. * * Global variables defined: @@ -80,8 +77,16 @@ class Gollem_Application extends Horde_Registry_Application return $this->_permsCache; } - $perms['tree']['gollem']['backends'] = false; - $perms['title']['gollem:backends'] = _("Backends"); + $perms = array( + 'tree' => array( + 'gollem' => array( + 'backends' => false + ) + ), + 'title' => array( + 'gollem:backends' => _("Backends") + ) + ); // Run through every backend. require GOLLEM_BASE . '/config/backends.php'; @@ -90,8 +95,6 @@ class Gollem_Application extends Horde_Registry_Application $perms['title']['gollem:backends:' . $key] = $val['name']; } - $this->_permsCache = $perms; - return $perms; } @@ -125,7 +128,7 @@ class Gollem_Application extends Horde_Registry_Application { switch ($item) { case 'columnselect': - $cols = Gollem::displayColumns(); + $cols = json_decode($GLOBALS['prefs']->getValue('columns')); $sources = array(); foreach ($GLOBALS['gollem_backends'] as $source => $info) { @@ -160,32 +163,6 @@ class Gollem_Application extends Horde_Registry_Application } /** - * Special preferences handling on update. - * - * @param Horde_Core_Prefs_Ui $ui The UI object. - * @param string $item The preference name. - * - * @return boolean True if preference was updated. - */ - public function prefsSpecialUpdate($ui, $item) - { - switch ($item) { - case 'columnselect': - if (isset($ui->vars->sources)) { - $pref = array(); - foreach (Horde_Serialize::unserialize($ui->vars->sources, Horde_Serialize::JSON) as $val) { - $pref[] = implode("\t", array_merge($val[0], $val[1])); - } - $GLOBALS['prefs']->setValue('columns', implode("\n", $pref)); - return true; - } - break; - } - - return false; - } - - /** * Generate the menu to use on the prefs page. * * @return Horde_Menu A Horde_Menu object. diff --git a/gollem/lib/Exception.php b/gollem/lib/Exception.php new file mode 100644 index 000000000..9dfaca777 --- /dev/null +++ b/gollem/lib/Exception.php @@ -0,0 +1,15 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Gollem + */ +class Gollem_Exception extends Horde_Exception_Prior {} diff --git a/gollem/lib/Gollem.php b/gollem/lib/Gollem.php index d2e69cdbb..e054245fe 100644 --- a/gollem/lib/Gollem.php +++ b/gollem/lib/Gollem.php @@ -7,10 +7,12 @@ * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * - * @author Max Kalika - * @author Chuck Hagenbuch - * @author Michael Slusarz - * @package Gollem + * @author Max Kalika + * @author Chuck Hagenbuch + * @author Michael Slusarz + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Gollem */ class Gollem { @@ -24,44 +26,48 @@ class Gollem const SORT_DESCEND = 1; /** + * prepareMenu() cache. + * + * @var array + */ + static private $_menu = null; + + /** * Changes the current directory of the Gollem session to the supplied * value. * * @param string $dir Directory name. * - * @return mixed True on Success, PEAR_Error on failure. + * @throws Gollem_Exception */ static public function setDir($dir) { $dir = Horde_Util::realPath($dir); if (!self::verifyDir($dir)) { - return PEAR::raiseError(sprintf(_("Access denied to folder \"%s\"."), $dir)); + throw new Gollem_Exception(sprintf(_("Access denied to folder \"%s\"."), $dir)); } $GLOBALS['gollem_be']['dir'] = $dir; self::_setLabel(); - - return true; } /** * Changes the current directory of the Gollem session based on the * 'dir' form field. * - * @return mixed True on Success, PEAR_Error on failure. + * @throws Gollem_Exception */ static public function changeDir() { $dir = Horde_Util::getFormData('dir'); - if ($dir !== null) { + if (is_null($dir)) { + self::_setLabel(); + } else { if (strpos($dir, '/') !== 0) { $dir = $GLOBALS['gollem_be']['dir'] . '/' . $dir; } - return self::setDir($dir); - } else { - self::_setLabel(); - return true; + self::setDir($dir); } } @@ -298,30 +304,23 @@ class Gollem * information, such as username, server, etc., that can be filled * in on the login form. * - * @return string The logout URL with parameters added. + * @return Horde_Url The logout URL with parameters added. */ static public function logoutUrl() { - $params = array(); - $url = 'login.php'; + $url = Horde::url('login.php', true); if (!empty($GLOBALS['gollem_be']['params']['username'])) { - $params['username'] = $GLOBALS['gollem_be']['params']['username']; + $url->add('username', $GLOBALS['gollem_be']['params']['username']); } elseif (Horde_Util::getFormData('username')) { - $params['username'] = Horde_Util::getFormData('username'); + $url->add('username', Horde_Util::getFormData('username')); } if (!empty($GLOBALS['gollem_be']['params']['port'])) { - $params['port'] = $GLOBALS['gollem_be']['params']['port']; + $url->add('port', $GLOBALS['gollem_be']['params']['port']); } - foreach ($params as $key => $val) { - if (!empty($val)) { - $url = Horde_Util::addParameter($url, $key, $val); - } - } - - return Horde::url($url, true); + return $url; } /** @@ -330,14 +329,14 @@ class Gollem * @param string $dir The directory path. * @param string $name The folder to create. * - * @return mixed True on success or a PEAR_Error object on failure. + * @throws Gollem_Exception * @throws VFS_Exception */ static public function createFolder($dir, $name) { $totalpath = Horde_Util::realPath($dir . '/' . $name); if (!Gollem::verifyDir($totalpath)) { - return PEAR::raiseError(sprintf(_("Access denied to folder \"%s\"."), $totalpath)); + throw new Gollem_Exception(sprintf(_("Access denied to folder \"%s\"."), $totalpath)); } /* The $name parameter may contain additional directories so we @@ -352,8 +351,6 @@ class Gollem if (!empty($GLOBALS['gollem_be']['params']['permissions'])) { $GLOBALS['gollem_vfs']->changePermissions($dir, $name, $GLOBALS['gollem_be']['params']['permissions']); } - - return true; } /** @@ -377,12 +374,13 @@ class Gollem * @param string $dir The subdirectory name. * @param string $name The folder name to delete. * + * @throws Gollem_Exception * @throws VFS_Exception */ static public function deleteFolder($dir, $name) { if (!Gollem::verifyDir($dir)) { - return PEAR::raiseError(sprintf(_("Access denied to folder \"%s\"."), $dir)); + throw new Gollem_Exception(sprintf(_("Access denied to folder \"%s\"."), $dir)); } ($GLOBALS['prefs']->getValue('recursive_deletes') != 'disabled') @@ -396,12 +394,13 @@ class Gollem * @param string $dir The directory name. * @param string $name The filename to delete. * + * @throws Gollem_Exception * @throws VFS_Exception */ static public function deleteFile($dir, $name) { if (!Gollem::verifyDir($dir)) { - return PEAR::raiseError(sprintf(_("Access denied to folder \"%s\"."), $dir)); + throw new Gollem_Exception(sprintf(_("Access denied to folder \"%s\"."), $dir)); } $GLOBALS['gollem_vfs']->deleteFile($dir, $name); } @@ -413,12 +412,13 @@ class Gollem * @param string $name The filename to change permissions on. * @param string $permission The permission mode to set. * + * @throws Gollem_Exception * @throws VFS_Exception */ static public function changePermissions($dir, $name, $permission) { if (!Gollem::verifyDir($dir)) { - return PEAR::raiseError(sprintf(_("Access denied to folder \"%s\"."), $dir)); + throw new Gollem_Exception(sprintf(_("Access denied to folder \"%s\"."), $dir)); } $GLOBALS['gollem_vfs']->changePermissions($dir, $name, $permission); } @@ -575,30 +575,6 @@ class Gollem return (Horde_String::substr(Horde_Util::realPath($dir), 0, Horde_String::length($rootdir)) == $rootdir); } - - /** - * Parse the 'columns' preference. - * - * @return array The list of columns to be displayed. - */ - static public function displayColumns() - { - $ret = array(); - $lines = explode("\n", $GLOBALS['prefs']->getValue('columns')); - foreach ($lines as $line) { - $line = trim($line); - if (!empty($line)) { - $columns = explode("\t", $line); - if (count($columns) > 1) { - $source = array_splice($columns, 0, 1); - $ret[$source[0]] = $columns; - } - } - } - - return $ret; - } - /** * Checks if a user has the specified permissions on the selected backend. * @@ -610,11 +586,12 @@ class Gollem * @return boolean Returns true if the user has permission, false if * they do not. */ - static public function checkPermissions($filter, $permission = Horde_Perms::READ, + static public function checkPermissions($filter, + $permission = Horde_Perms::READ, $backend = null) { $userID = $GLOBALS['registry']->getAuth(); - if ($backend === null) { + if (is_null($backend)) { $backend = $_SESSION['gollem']['backend_key']; } @@ -648,9 +625,10 @@ class Gollem $parts = explode('/', $currdir); $parts_count = count($parts); - $label[] = Horde::link(Horde_Util::addParameter($url, 'dir', $root_dir), sprintf(_("Up to %s"), $root_dir_name)) . '[' . $root_dir_name . ']'; + $url = new Horde_Url($url); + $label[] = Horde::link($url->add('dir', $root_dir), sprintf(_("Up to %s"), $root_dir_name)) . '[' . $root_dir_name . ']'; - for ($i = 1; $i <= $parts_count; $i++) { + for ($i = 1; $i <= $parts_count; ++$i) { $part = array_slice($parts, 0, $i); $dir = implode('/', $part); if ((strstr($dir, $root_dir) !== false) && @@ -658,7 +636,7 @@ class Gollem if ($i == $parts_count) { $label[] = $parts[($i - 1)]; } else { - $label[] = Horde::link(Horde_Util::addParameter($url, 'dir', $dir), sprintf(_("Up to %s"), $dir)) . $parts[($i - 1)] . ''; + $label[] = Horde::link($url->add('dir', $dir), sprintf(_("Up to %s"), $dir)) . $parts[($i - 1)] . ''; } } } @@ -675,21 +653,22 @@ class Gollem static public function getMenu() { $menu = new Horde_Menu(); - $menu->add(Horde_Util::addParameter(Horde::url('manager.php'), 'dir', Gollem::getHome()), _("_My Home"), 'folder_home.png'); + + $menu->add(Horde::url('manager.php')->add('dir', Gollem::getHome()), _("_My Home"), 'folder_home.png'); if (!empty($_SESSION['gollem'])) { $backend_key = $_SESSION['gollem']['backend_key']; if ($GLOBALS['registry']->isAdmin()) { - $menu->add(Horde_Util::addParameter(Horde::url('permissions.php'), 'backend', $backend_key), _("_Permissions"), 'perms.png', Horde_Themes::img(null, 'horde')); + $menu->add(Horde::url('permissions.php')->add('backend', $backend_key), _("_Permissions"), 'perms.png'); } if ($_SESSION['gollem']['backends'][$backend_key]['quota_val'] != -1) { if ($GLOBALS['browser']->hasFeature('javascript')) { $quota_url = 'javascript:' . Horde::popupJs(Horde::url('quota.php'), array('params' => array('backend' => $backend_key), 'height' => 300, 'width' => 300, 'urlencode' => true)); } else { - $quota_url = Horde_Util::addParameter(Horde::url('quota.php'), 'backend', $backend_key); + $quota_url = Horde::url('quota.php')->add('backend', $backend_key); } - $menu->add($quota_url, _("Check Quota"), 'info_icon.png', Horde_Themes::img(null, 'horde')); + $menu->add($quota_url, _("Check Quota"), 'info_icon.png'); } } @@ -697,24 +676,42 @@ class Gollem } /** - * Outputs Gollem's menu to the current output stream. + * Build Gollem's list of menu items. */ - static public function menu() + static public function prepareMenu() { + if (isset(self::$_menu)) { + return; + } + $t = $GLOBALS['injector']->createInstance('Horde_Template'); $t->set('forminput', Horde_Util::formInput()); - $t->set('be_select', Gollem::backendSelect(), true); + $t->set('be_select', self::backendSelect(), true); if ($t->get('be_select')) { $t->set('accesskey', $GLOBALS['prefs']->getValue('widget_accesskey') ? Horde::getAccessKey(_("_Change Server")) : ''); $menu_view = $GLOBALS['prefs']->getValue('menu_view'); $link = Horde::link('#', _("Change Server"), '', '', 'serverSubmit(true);return false;'); $t->set('slink', sprintf('
  • %s%s
    %s
', $link, ($menu_view != 'text') ? Horde::img('gollem.png') : '', ($menu_view != 'icon') ? Horde::highlightAccessKey(_("_Change Server"), $t->get('accesskey')) : '')); } - $t->set('menu_string', Gollem::getMenu()->render()); + $t->set('menu_string', self::getMenu()->render()); + + self::$_menu = $t->fetch(GOLLEM_TEMPLATES . '/menu/menu.html'); - echo $t->fetch(GOLLEM_TEMPLATES . '/menu.html'); + /* Need to buffer sidebar output here, because it may add things like + * cookies which need to be sent before output begins. */ + Horde::startBuffer(); require HORDE_BASE . '/services/sidebar.php'; + self::$_menu .= Horde::endBuffer(); + } + + /** + * Outputs Gollem's menu to the current output stream. + */ + static public function menu() + { + self::prepareMenu(); + echo self::$_menu; } /** diff --git a/gollem/lib/LoginTasks/SystemTask/UpgradeFromGollem1.php b/gollem/lib/LoginTasks/SystemTask/UpgradeFromGollem1.php new file mode 100644 index 000000000..3077a3adb --- /dev/null +++ b/gollem/lib/LoginTasks/SystemTask/UpgradeFromGollem1.php @@ -0,0 +1,47 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Gollem + */ +class Gollem_LoginTasks_SystemTask_UpgradeFromGollem1 extends Horde_LoginTasks_SystemTask +{ + /** + * The interval at which to run the task. + * + * @var integer + */ + public $interval = Horde_LoginTasks::ONCE; + + /** + * Perform all functions for this task. + */ + public function execute() + { + $this->_upgradePrefs(); + } + + /** + * Upgrade to the new preferences. + */ + protected function _upgradePrefs() + { + global $prefs; + + if (!$prefs->isDefault('columns')) { + $cols = $prefs->getValue('columns'); + if (!is_array(json_decode($cols))) { + $prefs->setValue('columns', json_encode(explode("\t", $cols))); + } + } + } + +} diff --git a/gollem/lib/Mime/Viewer/Images.php b/gollem/lib/Mime/Viewer/Images.php index dc0998d33..1ddca30de 100644 --- a/gollem/lib/Mime/Viewer/Images.php +++ b/gollem/lib/Mime/Viewer/Images.php @@ -8,8 +8,10 @@ * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * - * @author Mike Cochrane - * @package Horde_Mime + * @author Mike Cochrane + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Gollem */ class Gollem_Mime_Viewer_Images extends Horde_Mime_Viewer_Images { diff --git a/gollem/manager.php b/gollem/manager.php index 28ad684e4..8fb6ba701 100644 --- a/gollem/manager.php +++ b/gollem/manager.php @@ -7,18 +7,20 @@ * See the enclosed file COPYING for license information (GPL). If you * did notcan receive this file, see http://www.fsf.org/copyleft/gpl.html. * - * @author Max Kalika - * @author Chuck Hagenbuch - * @author Michael Slusarz - * @package Gollem + * @author Max Kalika + * @author Chuck Hagenbuch + * @author Michael Slusarz + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Gollem */ require_once dirname(__FILE__) . '/lib/Application.php'; Horde_Registry::appInit('gollem'); -$actionID = Horde_Util::getFormData('actionID'); $backkey = $_SESSION['gollem']['backend_key']; $old_dir = Gollem::getDir(); +$vars = Horde_Variables::getDefaultVariables(); /* Get permissions. */ $delete_perms = Gollem::checkPermissions('backend', Horde_Perms::DELETE); @@ -26,21 +28,22 @@ $edit_perms = Gollem::checkPermissions('backend', Horde_Perms::EDIT); $read_perms = Gollem::checkPermissions('backend', Horde_Perms::READ); /* Set directory. */ -if (is_a($result = Gollem::changeDir(), 'PEAR_Error')) { - $notification->push($result); +try { + Gollem::changeDir(); +} catch (VFS_Exception $e) { + $notification->push($e); } /* Run through the action handlers. */ -switch ($actionID) { +switch ($vars->actionID) { case 'create_folder': - if ($edit_perms) { - if ($new_folder = Horde_Util::getPost('new_folder')) { - $result = Gollem::createFolder($old_dir, $new_folder); - if (is_a($result, 'PEAR_Error')) { - $notification->push($result->getMessage(), 'horde.error'); - } else { - $notification->push(_("New folder created: ") . $new_folder, 'horde.success'); - } + if ($edit_perms && + ($new_folder = Horde_Util::getPost('new_folder'))) { + try { + Gollem::createFolder($old_dir, $new_folder); + $notification->push(_("New folder created: ") . $new_folder, 'horde.success'); + } catch (Gollem_Exception $e) { + $notification->push($e, 'horde.error'); } } break; @@ -51,11 +54,11 @@ case 'rename_items': $old = explode('|', Horde_Util::getPost('old_names')); if (!empty($new) && !empty($old) && (count($new) == count($old))) { for ($i = 0, $iMax = count($new); $i < $iMax; ++$i) { - $result = Gollem::renameItem($old_dir, $old[$i], $old_dir, $new[$i]); - if (is_a($result, 'PEAR_Error')) { - $notification->push($result->getMessage(), 'horde.error'); - } else { + try { + Gollem::renameItem($old_dir, $old[$i], $old_dir, $new[$i]); $notification->push(sprintf(_("\"%s\" renamed to \"%s\""), $old[$i], $new[$i]), 'horde.success'); + } catch (Gollem_Exception $e) { + $notification->push($e, 'horde.error'); } } Gollem::expireCache($old_dir); @@ -72,29 +75,30 @@ case 'delete_items': if (is_array($items) && count($items)) { $chmod = Horde_Util::getPost('chmod'); foreach ($items as $item) { - if (($actionID == 'chmod_modify') && $chmod) { - if (!is_a(Gollem::changePermissions(Gollem::getDir(), $item, $chmod), 'PEAR_Error')) { + if (($vars->actionID == 'chmod_modify') && $chmod) { + try { + Gollem::changePermissions(Gollem::getDir(), $item, $chmod); Gollem::expireCache($old_dir); $notification->push(_("Chmod done: ") . $item, 'horde.success'); - } else { - $notification->push(sprintf(_("Cannot chmod %s: %s"), $item, $result->getMessage()), 'horde.error'); + } catch (Gollem_Exception $e) { + $notification->push(sprintf(_("Cannot chmod %s: %s"), $item, $e->getMessage()), 'horde.error'); } - } elseif ($actionID == 'delete_items') { - if ($GLOBALS['gollem_vfs']->isFolder($old_dir, $item)) { - $result = Gollem::deleteFolder($old_dir, $item); - if (is_a($result, 'PEAR_Error')) { - $notification->push(sprintf(_("Unable to delete folder %s: %s"), $item, $result->getMessage()), 'horde.error'); - } else { + } elseif ($vars->actionID == 'delete_items') { + if ($gollem_vfs->isFolder($old_dir, $item)) { + try { + Gollem::deleteFolder($old_dir, $item); Gollem::expireCache($old_dir); $notification->push(_("Folder removed: ") . $item, 'horde.success'); + } catch (Gollem_Exception $e) { + $notification->push(sprintf(_("Unable to delete folder %s: %s"), $item, $e->getMessage()), 'horde.error'); } } else { - $result = Gollem::deleteFile($old_dir, $item); - if (is_a($result, 'PEAR_Error')) { - $notification->push(sprintf(_("Unable to delete file %s: %s"), $item, $result->getMessage()), 'horde.error'); - } else { + try { + Gollem::deleteFile($old_dir, $item); Gollem::expireCache($old_dir); $notification->push(_("File deleted: ") . $item, 'horde.success'); + } catch (Gollem_Exception $e) { + $notification->push(sprintf(_("Unable to delete file %s: %s"), $item, $e->getMessage()), 'horde.error'); } } } @@ -109,17 +113,16 @@ case 'upload_file': $val = 'file_upload_' . $i; if (isset($_FILES[$val]) && ($_FILES[$val]['error'] != 4)) { try { - $GLOBALS['browser']->wasFileUploaded($val); + $browser->wasFileUploaded($val); $filename = Horde_Util::dispelMagicQuotes($_FILES[$val]['name']); - $res = Gollem::writeFile($old_dir, $filename, $_FILES[$val]['tmp_name']); - if (is_a($res, 'PEAR_Error')) { - $notification->push($res, 'horde.error'); - } else { - Gollem::expireCache($old_dir); - $notification->push(sprintf(_("File received: %s"), $filename), 'horde.success'); - } + + Gollem::writeFile($old_dir, $filename, $_FILES[$val]['tmp_name']); + Gollem::expireCache($old_dir); + $notification->push(sprintf(_("File received: %s"), $filename), 'horde.success'); } catch (Horde_Browser_Exception $e) { $notification->push($e, 'horde.error'); + } catch (Gollem_Exception $e) { + $notification->push($e, 'horde.error'); } } } @@ -128,8 +131,8 @@ case 'upload_file': case 'copy_items': case 'cut_items': - if ($edit_perms && !empty($GLOBALS['gollem_be']['clipboard'])) { - $action = ($actionID == 'copy_items') ? 'copy' : 'cut'; + if ($edit_perms && !empty($gollem_be['clipboard'])) { + $action = ($vars->actionID == 'copy_items') ? 'copy' : 'cut'; $items = Horde_Util::getPost('items'); if (is_array($items) && count($items)) { @@ -160,26 +163,27 @@ case 'cut_items': case 'clear_items': case 'paste_items': - if ($edit_perms && !empty($GLOBALS['gollem_be']['clipboard'])) { + if ($edit_perms && !empty($gollem_be['clipboard'])) { $items = Horde_Util::getPost('items'); if (is_array($items) && count($items)) { foreach ($items as $val) { if (isset($_SESSION['gollem']['clipboard'][$val])) { $file = $_SESSION['gollem']['clipboard'][$val]; - if ($actionID == 'paste_items') { - if ($file['action'] == 'cut') { - $res = Gollem::moveFile($file['backend'], $file['path'], $file['name'], $backkey, $old_dir); - } else { - $res = Gollem::copyFile($file['backend'], $file['path'], $file['name'], $backkey, $old_dir); - } - if (is_a($res, 'PEAR_Error')) { - $notification->push(sprintf(_("Cannot paste \"%s\" (file cleared from clipboard): %s"), $file['name'], $res->getMessage()), 'horde.error'); - } else { + if ($vars->actionID == 'paste_items') { + try { + if ($file['action'] == 'cut') { + Gollem::moveFile($file['backend'], $file['path'], $file['name'], $backkey, $old_dir); + } else { + Gollem::copyFile($file['backend'], $file['path'], $file['name'], $backkey, $old_dir); + } + Gollem::expireCache($old_dir); if ($file['action'] == 'cut') { Gollem::expireCache($file['path']); } $notification->push(sprintf(_("%s was successfully pasted."), $file['name'], $old_dir), 'horde.success'); + } catch (VFS_Exception $e) { + $notification->push(sprintf(_("Cannot paste \"%s\" (file cleared from clipboard): %s"), $file['name'], $e->getMessage()), 'horde.error'); } } unset($_SESSION['gollem']['clipboard'][$val]); @@ -191,14 +195,14 @@ case 'paste_items': break; case 'change_sortby': - if (($sortby = Horde_Util::getFormData('sortby')) !== null) { - $prefs->setValue('sortby', $sortby); + if (isset($vars->sortby)) { + $prefs->setValue('sortby', $vars->sortby); } break; case 'change_sortdir': - if (($sortdir = Horde_Util::getFormData('sortdir')) !== null) { - $prefs->setValue('sortdir', $sortdir); + if (isset($vars->sortdir)) { + $prefs->setValue('sortdir', $vars->sortdir); } break; } @@ -207,61 +211,63 @@ case 'change_sortdir': * etc., to make sure we can catch any errors. */ $currdir = Gollem::getDir(); -$list = Gollem::listFolder($currdir); -if (is_a($list, 'PEAR_Error')) { +try { + Gollem::listFolder($currdir); +} catch (Gollem_Exception $e) { /* If this is a user's home directory, try autocreating it. */ if ($currdir == Gollem::getHome()) { - if (is_a($created = Gollem::createFolder('', $currdir), 'PEAR_Error')) { + try { + Gollem::createFolder('', $currdir); + try { + $list = Gollem::listFolder($currdir); + } catch (Gollem_Exception $e) { + /* If that didn't work, fall back to the parent or the home + * directory. */ + $notification->push(sprintf(_("Permission denied to folder \"%s\": %s"), $currdir, $e->getMessage()), 'horde.error'); + + $loc = strrpos($currdir, '/'); + Gollem::setDir(($loc !== false) ? substr($currdir, 0, $loc) : Gollem::getHome()); + $currdir = Gollem::getDir(); + $list = Gollem::listFolder($currdir); + } + } catch (Gollem_Exception $e) { $notification->push(sprintf(_("Cannot create home directory: %s"), $created->getMessage()), 'horde.error'); - } else { - $list = Gollem::listFolder($currdir); } } - - /* If that didn't work, fall back to the parent or the home directory. */ - if (is_a($list, 'PEAR_Error')) { - $notification->push(sprintf(_("Permission denied to folder \"%s\": %s"), $currdir, $list->getMessage()), 'horde.error'); - - $loc = strrpos($currdir, '/'); - Gollem::setDir(($loc !== false) ? substr($currdir, 0, $loc) : Gollem::getHome()); - $currdir = Gollem::getDir(); - $list = Gollem::listFolder($currdir); - } } $numitem = count($list); -$title = $GLOBALS['gollem_be']['label']; +$title = $gollem_be['label']; /* Image links. */ -$image_dir = Horde_Themes::img(null, 'horde'); -$edit_img = Horde::img('edit.png', _("Edit"), null, $image_dir); -$download_img = Horde::img('download.png', _("Download"), null, $image_dir); +$edit_img = Horde::img('edit.png', _("Edit")); +$download_img = Horde::img('download.png', _("Download")); $folder_img = Horde::img('folder.png', _("folder")); $symlink_img = Horde::img('folder_symlink.png', _("symlink")); /* Init some form vars. */ -$page = Horde_Util::getFormData('page', 0); -$filter = Horde_Util::getFormData('filter', ''); +$page = isset($vars->page) + ? $vars->page + : 0; if (isset($_SESSION['gollem']['filter']) && - $_SESSION['gollem']['filter'] != $filter) { + ($_SESSION['gollem']['filter'] != $vars->filter)) { $page = 0; } -$_SESSION['gollem']['filter'] = $filter; +$_SESSION['gollem']['filter'] = strval($vars->filter); /* Commonly used URLs. */ $view_url = Horde::url('view.php'); $edit_url = Horde::url('edit.php'); $manager_url = Horde::url('manager.php'); -$refresh_params = array('page' => $page); -if ($filter) { - $refresh_params['filter'] = $filter; +$refresh_url = $manager_url->copy()->add('page', $page); +if ($vars->filter) { + $refresh_url->add('filter', $vars->filter); } -$refresh_url = Horde_Util::addParameter($manager_url, $refresh_params); /* Get the list of copy/cut files in this directory. */ $clipboard_files = array(); -if (!empty($GLOBALS['gollem_be']['clipboard'])) { +if (!empty($gollem_be['clipboard'])) { foreach ($_SESSION['gollem']['clipboard'] as $val) { if (($backkey == $val['backend']) && ($val['path'] == $currdir)) { $clipboard_files[$val['name']] = 1; @@ -270,14 +276,16 @@ if (!empty($GLOBALS['gollem_be']['clipboard'])) { } /* Read the columns to display from the preferences. */ -$sources = Gollem::displayColumns(); -$columns = isset($sources[$backkey]) ? $sources[$backkey] : $GLOBALS['gollem_be']['attributes']; +$sources = json_decode($prefs->getValue('columns')); +$columns = isset($sources[$backkey]) + ? $sources[$backkey] + : $gollem_be['attributes']; /* Prepare the template. */ $template = $injector->createInstance('Horde_Template'); $template->setOption('gettext', true); -$attrib = $GLOBALS['gollem_vfs']->getModifiablePermissions(); +$attrib = $gollem_vfs->getModifiablePermissions(); foreach (array('owner', 'group', 'all') as $val) { foreach (array('read', 'write', 'execute') as $val2) { $template->set($val . '_' . $val2, !$attrib[$val][$val2], true); @@ -296,14 +304,14 @@ $template->set('action', $refresh_url); $template->set('forminput', Horde_Util::formInput()); $template->set('dir', $currdir); $template->set('navlink', Gollem::directoryNavLink($currdir, $manager_url)); -$template->set('refresh', Horde::link($refresh_url, sprintf("%s %s", _("Refresh"), $GLOBALS['gollem_be']['label']), '', '', '', '', '', array('id' => 'refreshimg')) . Horde::img('reload.png', sprintf("%s %s", _("Refresh"), htmlspecialchars($GLOBALS['gollem_be']['label'])), null, $image_dir) . ''); +$template->set('refresh', Horde::link($refresh_url, sprintf("%s %s", _("Refresh"), $gollem_be['label']), '', '', '', '', '', array('id' => 'refreshimg')) . Horde::img('reload.png', sprintf("%s %s", _("Refresh"), htmlspecialchars($gollem_be['label']))) . ''); -$template->set('hasclipboard', !$edit_perms || !empty($GLOBALS['gollem_be']['clipboard']), true); +$template->set('hasclipboard', !$edit_perms || !empty($gollem_be['clipboard']), true); if (!$template->get('hasclipboard') || empty($_SESSION['gollem']['clipboard'])) { $template->set('clipboard', null); } else { - $template->set('clipboard', Horde::link(Horde_Util::addParameter(Horde::url('clipboard.php'), 'dir', $currdir), _("View Clipboard")) . Horde::img('clipboard.png', _("View Clipboard")) . ''); + $template->set('clipboard', Horde::link(Horde::url('clipboard.php')->add('dir', $currdir), _("View Clipboard")) . Horde::img('clipboard.png', _("View Clipboard")) . ''); } if ($edit_perms) { @@ -350,8 +358,8 @@ if (is_array($list) && $numitem && $read_perms) { foreach ($list as $key => $val) { /* Check if a filter is not empty and filter matches filename. */ - if (strlen($filter) && - !preg_match('/' . preg_quote($filter, '/') . '/', $val['name'])) { + if (strlen($vars->filter) && + !preg_match('/' . preg_quote($vars->filter, '/') . '/', $val['name'])) { continue; } @@ -362,7 +370,7 @@ if (is_array($list) && $numitem && $read_perms) { $item = array( 'date' => htmlspecialchars(strftime($prefs->getValue('date_format'), $val['date'])), - 'date_sort' => (int)$val['date'], + 'date_sort' => intval($val['date']), 'dl' => false, 'edit' => false, 'group' => empty($val['group']) ? '-' : htmlspecialchars($val['group']), @@ -397,8 +405,8 @@ if (is_array($list) && $numitem && $read_perms) { /* Create proper link. */ switch ($val['type']) { case '**dir': - $url = Horde_Util::addParameter($manager_url, array('dir' => Gollem::subdirectory($currdir, $val['name']))); - $item['link'] = Horde::link($url) . '' . $name . ''; + $url = $manager_url->copy()->add('dir', Gollem::subdirectory($currdir, $val['name'])); + $item['link'] = $url->link() . '' . $name . ''; break; case '**broken': @@ -416,8 +424,8 @@ if (is_array($list) && $numitem && $read_perms) { $dir = $currdir; } - $url = Horde_Util::addParameter($manager_url, array('dir' => Gollem::subdirectory($dir, $name))); - $item['link'] = $item['name'] . ' -> ' . Horde::link($url) . $val['link'] . ''; + $url = $manager_url->copy()->add('dir', Gollem::subdirectory($dir, $name)); + $item['link'] = $item['name'] . ' -> ' . $url->link() . $val['link'] . ''; } else { $item['link'] = $item['name'] . ' -> ' . $val['link']; } @@ -428,15 +436,27 @@ if (is_array($list) && $numitem && $read_perms) { // Edit link if possible. if (strpos($mime_type, 'text/') === 0) { - $url = Horde_Util::addParameter($edit_url, array('actionID' => 'edit_file', 'type' => $val['type'], 'file' => $val['name'], 'dir' => $currdir, 'driver' => $GLOBALS['gollem_be']['driver'])); + $url = $edit_url->copy()->add(array( + 'actionID' => 'edit_file', + 'type' => $val['type'], + 'file' => $val['name'], + 'dir' => $currdir, + 'driver' => $gollem_be['driver'] + )); $item['edit'] = Horde::link('#', '', '', '_blank', Horde::popupJs($url) . 'return false;') . $edit_img . ''; } // We can always download files. - $item['dl'] = Horde::link(Horde::downloadUrl($val['name'], array('actionID' => 'download_file', 'dir' => $currdir, 'driver' => $GLOBALS['gollem_be']['driver'], 'file' => $val['name'])), sprintf(_("Download %s"), $val['name'])) . $download_img . ''; + $item['dl'] = Horde::link(Horde::downloadUrl($val['name'], array('actionID' => 'download_file', 'dir' => $currdir, 'driver' => $gollem_be['driver'], 'file' => $val['name'])), sprintf(_("Download %s"), $val['name'])) . $download_img . ''; // Try a view link. - $url = Horde_Util::addParameter($view_url, array('actionID' => 'view_file', 'type' => $val['type'], 'file' => $val['name'], 'dir' => $currdir, 'driver' => $GLOBALS['gollem_be']['driver'])); + $url = $view_url->copy()->add(array( + 'actionID' => 'view_file', + 'type' => $val['type'], + 'file' => $val['name'], + 'dir' => $currdir, + 'driver' => $gollem_be['driver'] + )); $item['link'] = Horde::link('#', '', '', '_blank', Horde::popupJs($url) . 'return false;') . $name . ''; break; } @@ -453,9 +473,13 @@ if (is_array($list) && $numitem && $read_perms) { $start = ($page * $perpage) + 1; $end = min($total, $start + $perpage - 1); - $vars = Horde_Variables::getDefaultVariables(); $vars->set('page', $page); - $pager = new Horde_Core_Ui_Pager('page', $vars, array('num' => $total, 'url' => $refresh_url, 'page_count' => 10, 'perpage' => $perpage)); + $pager = new Horde_Core_Ui_Pager('page', $vars, array( + 'num' => $total, + 'url' => $refresh_url, + 'page_count' => 10, + 'perpage' => $perpage + )); $page_caption = $pager->render(); } @@ -537,7 +561,7 @@ if (is_array($list) && $numitem && $read_perms) { if ($sortby == $sort) { $hdr['class'] = ($sortdir ? 'sortup' : 'sortdown'); } - $hdr['label'] = '' . htmlspecialchars($hdr['label']) . ''; + $hdr['label'] = '' . htmlspecialchars($hdr['label']) . ''; } $headers[] = $hdr; @@ -547,22 +571,21 @@ if (is_array($list) && $numitem && $read_perms) { $template->set('headers', $headers, true); $template->set('entry', $entry, true); $template->set('page_caption', $page_caption); - $template->set('filter_val', $filter); + $template->set('filter_val', $vars->filter); $template->set('checkall', Horde::getAccessKeyAndTitle(_("Check _All/None"))); } else { $template->set('empty_dir', true, true); } $template->set('itemcount', sprintf(ngettext(_("%d item"), _("%d items"), $total), $total)); -$js_code = array( - 'var warn_recursive = ' . intval($GLOBALS['prefs']->getValue('recursive_deletes') == 'warn'), -); - Horde::addScriptFile('manager.js', 'gollem'); Horde::addScriptFile('tables.js', 'horde'); +Horde::addInlineJsVars(array( + '-warn_recursive' => intval($prefs->getValue('recursive_deletes') == 'warn') +)); +Gollem::prepareMenu(); require GOLLEM_TEMPLATES . '/common-header.inc'; -Horde::addInlineScript(implode(';', $js_code)); Gollem::menu(); Gollem::status(); echo $template->fetch(GOLLEM_TEMPLATES . '/manager/manager.html'); diff --git a/gollem/permissions.php b/gollem/permissions.php index 39701c419..ba629e4f9 100644 --- a/gollem/permissions.php +++ b/gollem/permissions.php @@ -6,18 +6,24 @@ * * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @author Vijay Mahrra + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Gollem */ require_once dirname(__FILE__) . '/lib/Application.php'; Horde_Registry::appInit('gollem', array('admin' => true)); if (!Gollem::getBackends('all')) { + $notification->push(_("You need at least one backend defined to set permissions."), 'horde.error'); + $title = _("Gollem Backend Permissions Administration"); + Gollem::prepareMenu(); require GOLLEM_TEMPLATES . '/common-header.inc'; Gollem::menu(); Gollem::status(); - $notification->push(_("You need at least one backend defined to set permissions."), 'horde.error'); - $notification->notify(); require $registry->get('templates', 'horde') . '/common-footer.inc'; exit; } @@ -33,11 +39,13 @@ if ($perms->exists($backendTag)) { $perm_id = $perms->getPermissionId($permission); } else { $permission = $perms->newPermission($backendTag); - $result = $perms->addPermission($permission, $app); - if ($result instanceof PEAR_Error) { - $notification->push(sprintf(_("Unable to create backend permission: %s"), $result->getMessage()), 'horde.error'); + try { + $perms->addPermission($permission, $app); + } catch (Horde_Perms_Exception $e) { + $notification->push(sprintf(_("Unable to create backend permission: %s"), $e->getMessage()), 'horde.error'); Horde::url('redirect.php', true)->redirect(); } + $perm_id = $perms->getPermissionId($permission); $notification->push(sprintf(_("Created empty permissions for \"%s\". You must explicitly grant access to this backend now."), $key), 'horde.warning'); } diff --git a/gollem/quota.php b/gollem/quota.php index 96c52dcf5..67c4164d1 100644 --- a/gollem/quota.php +++ b/gollem/quota.php @@ -7,7 +7,10 @@ * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * - * @author Michael Slusarz + * @author Michael Slusarz + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Gollem */ require_once dirname(__FILE__) . '/lib/Application.php'; @@ -16,13 +19,6 @@ Horde_Registry::appInit('gollem'); /* Is this a popup window? */ $isPopup = $browser->hasFeature('javascript'); -$title = _("Quota Display"); -require GOLLEM_TEMPLATES . '/common-header.inc'; -if (!$isPopup) { - Gollem::menu(); - Gollem::status(); -} - /* Set up the template object. */ $template = $injector->createInstance('Horde_Template'); $template->setOption('gettext', true); @@ -37,13 +33,10 @@ $template->set('noquota', true, true); $template->set('quotaerror', false, true); $template->set('quotadisplay', false, true); $template->set('quotagraph', false, true); -if ($GLOBALS['gollem_be']['quota_val'] > -1) { +if ($gollem_be['quota_val'] > -1) { $template->set('noquota', false, true); - $quota_info = $GLOBALS['gollem_vfs']->getQuota(); - if (is_a($quota_info, 'PEAR_Error')) { - $template->set('quotaerror', true, true); - $template->set('quotaerrormsg', $quota_info->getMessage()); - } else { + try { + $quota_info = $gollem_vfs->getQuota(); $usage = $quota_info['usage'] / (1024 * 1024.0); $limit = $quota_info['limit'] / (1024 * 1024.0); @@ -54,8 +47,17 @@ if ($GLOBALS['gollem_be']['quota_val'] > -1) { $template->set('quotastyle', '
'); } $template->set('quotadisplay', sprintf(_("%.2fMB / %.2fMB (%.2f%%)"), $usage, $limit, $percent), true); + } catch (VFS_Exception $e) { + $template->set('quotaerror', true, true); + $template->set('quotaerrormsg', $e->getMessage()); } } +$title = _("Quota Display"); +require GOLLEM_TEMPLATES . '/common-header.inc'; +if (!$isPopup) { + Gollem::menu(); + Gollem::status(); +} echo $template->fetch(GOLLEM_TEMPLATES . '/quota/quota.html'); require $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/gollem/selectlist.php b/gollem/selectlist.php index 8a670640b..a36e4f66d 100644 --- a/gollem/selectlist.php +++ b/gollem/selectlist.php @@ -1,26 +1,35 @@ + * @author Michael Slusarz + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Gollem */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => array('authentication' => 'selectlist')); +Horde_Registry::appInit('gollem', array( + 'authentication' => 'selectlist' +)); /* Set directory. */ -if (is_a($result = Gollem::changeDir(), 'PEAR_Error')) { - $notification->push($result); +try { + Gollem::changeDir(); +} catch (Gollem_Exception $e) { + $notification->push($e); } $currdir = Gollem::getDir(); /* Create a new cache ID if one does not already exist. */ $cacheid = Horde_Util::getFormData('cacheid'); if (empty($cacheid)) { - $cacheid = uniqid(mt_rand()); + $cacheid = strval(new Horde_Support_Randomid()); $_SESSION['gollem']['selectlist'][$cacheid] = array(); } @@ -28,8 +37,7 @@ if (empty($cacheid)) { $formid = Horde_Util::getFormData('formid'); /* Run through the action handlers. */ -$actionID = Horde_Util::getFormData('actionID'); -switch ($actionID) { +switch (Horde_Util::getFormData('actionID')) { case 'select': $items = Horde_Util::getPost('items'); if (is_array($items) && count($items)) { @@ -52,17 +60,20 @@ case 'select': break; } -$info = array(); -$info['list'] = Gollem::listFolder($currdir); - -/* If that didn't work, fall back to the parent or the home directory. */ -if (is_a($info['list'], 'PEAR_Error')) { - $notification->push(sprintf(_("Permission denied to %s: %s"), $currdir, $info['list']->getMessage()), 'horde.error'); +try { + $info = array( + 'list' => Gollem::listFolder($currdir) + ); +} catch (Gollem_Exception $e) { + /* If that didn't work, fall back to the parent or the home directory. */ + $notification->push(sprintf(_("Permission denied to %s: %s"), $currdir, $e->getMessage()), 'horde.error'); $loc = strrpos($currdir, '/'); Gollem::setDir(($loc !== false) ? substr($currdir, 0, $loc) : Gollem::getHome()); $currdir = Gollem::getDir(); - $info['list'] = Gollem::listFolder($currdir); + $info = array( + 'list' => Gollem::listFolder($currdir) + ); } $info['title'] = htmlspecialchars($GLOBALS['gollem_be']['label']); @@ -74,22 +85,6 @@ $symlink_img = Horde::img('folder_symlink.png', _("symlink")); /* Commonly used URLs. */ $self_url = Horde::url('selectlist.php'); -/* Now actually display everything, after we've notified the user of - any errors. */ -$backkey = $_SESSION['gollem']['backend_key']; -$list = $info['list']; -$title = $info['title']; - -$js_code = array( - 'var cacheid = \'' . $cacheid . '\'', - 'var formid = \'' . $formid . '\'', -); - -Horde::addScriptFile('selectlist.js', 'gollem'); -require GOLLEM_TEMPLATES . '/common-header.inc'; -Horde::addInlineScript(implode(';', $js_code)); -Gollem::status(); - /* Set up the template object. */ $t = $injector->createInstance('Horde_Template'); $t->set('addbutton', _("Add")); @@ -100,21 +95,22 @@ $t->set('forminput', Horde_Util::formInput()); $t->set('cacheid', htmlspecialchars($cacheid)); $t->set('currdir', htmlspecialchars($currdir)); $t->set('formid', htmlspecialchars($formid)); -$t->set('navlink', Gollem::directoryNavLink($currdir, Horde_Util::addParameter($self_url, array('cacheid' => $cacheid, 'formid' => $formid)))); +$t->set('navlink', Gollem::directoryNavLink($currdir, $self_url->copy()->add(array('cacheid' => $cacheid, 'formid' => $formid)))); if ($GLOBALS['conf']['backend']['backend_list'] == 'shown') { - $t->set('changeserver', Horde::link(htmlspecialchars(Horde_Auth::addLogoutParameters(Horde_Util::addParameter(Horde::url('login.php'), array('url' => Horde_Util::addParameter(Horde::url('selectlist.php'), array('formid' => $formid)))), Horde_Auth::REASON_LOGOUT)), _("Change Server")) . Horde::img('logout.png', _("Change Server")) . '', true); + // TODO + //$t->set('changeserver', Horde::link(htmlspecialchars(Horde_Auth::addLogoutParameters(Horde_Util::addParameter(Horde::url('login.php'), array('url' => Horde_Util::addParameter(Horde::url('selectlist.php'), array('formid' => $formid)))), Horde_Auth::REASON_LOGOUT)), _("Change Server")) . Horde::img('logout.png', _("Change Server")) . '', true); } else { $t->set('changeserver', '', true); } -if (is_array($list) && - count($list) && +if (is_array($info['list']) && + count($info['list']) && Gollem::checkPermissions('backend', Horde_Perms::READ)) { $entry = $icon_cache = array(); $rowct = 0; - foreach ($list as $key => $val) { + foreach ($info['list'] as $key => $val) { $item = array( 'dir' => false, 'name' => htmlspecialchars($val['name']), @@ -131,19 +127,7 @@ if (is_array($list) && $item['graphic'] = $folder_img; } else { if (empty($icon_cache[$val['type']])) { - require_once 'Horde/MIME/Magic.php'; - require_once 'Horde/MIME/Viewer.php'; - if (is_callable(array('Horde', 'loadConfiguration'))) { - $result = Horde::loadConfiguration('mime_drivers.php', array('mime_drivers', 'mime_drivers_map'), 'horde'); - extract($result); - $result = Horde::loadConfiguration('mime_drivers.php', array('mime_drivers', 'mime_drivers_map'), 'gollem'); - $mime_drivers = array_merge_recursive($mime_drivers, $result['mime_drivers']); - $mime_drivers_map = array_merge_recursive($mime_drivers_map, $result['mime_drivers_map']); - } else { - require HORDE_BASE . '/config/mime_drivers.php'; - require GOLLEM_BASE . '/config/mime_drivers.php'; - } - $icon_cache[$val['type']] = Horde::img(MIME_Viewer::getIcon(MIME_Magic::extToMIME($val['type'])), '', '', ''); + $icon_cache[$val['type']] = $injector->getInstance('Horde_Mime_Viewer')->getIcon($val['type']); } $item['graphic'] = $icon_cache[$val['type']]; } @@ -151,8 +135,12 @@ if (is_array($list) && /* Create proper link. */ switch ($val['type']) { case '**dir': - $url = Horde_Util::addParameter($self_url, array('dir' => Gollem::subdirectory($currdir, $val['name']), 'cacheid' => $cacheid, 'formid' => $formid)); - $item['link'] = Horde::link($url) . '' . $name . ''; + $url = $self_url->copy()->add(array( + 'cacheid' => $cacheid, + 'dir' => Gollem::subdirectory($currdir, $val['name']), + 'formid' => $formid + )); + $item['link'] = $url->link() . '' . $name . ''; $item['dir'] = true; break; @@ -167,8 +155,12 @@ if (is_array($list) && $dir = $currdir; } - $url = Horde_Util::addParameter($self_url, array('dir' => Gollem::subdirectory($currdir, $val['name']), 'cacheid' => $cacheid, 'formid' => $formid)); - $item['link'] = $item['name'] . ' -> ' . Horde::link($url) . $val['link'] . ''; + $url = $self_url->copy()->add(array( + 'cacheid' => $cacheid, + 'dir' => Gollem::subdirectory($currdir, $val['name']), + 'formid' => $formid + )); + $item['link'] = $item['name'] . ' -> ' . $url->link() . $val['link'] . ''; } else { $item['link'] = $item['name'] . ' -> ' . $val['link']; } @@ -195,5 +187,13 @@ if (is_array($list) && $t->set('nofiles', _("There are no files in this folder."), true); } +$title = $info['title']; +Horde::addScriptFile('selectlist.js', 'gollem'); +Horde::addInlineJsVars(array( + 'cacheid' => $cacheid, + 'formid' => $formid +)); +require GOLLEM_TEMPLATES . '/common-header.inc'; +Gollem::status(); echo $t->fetch(GOLLEM_TEMPLATES . '/selectlist/selectlist.html'); require $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/gollem/view.php b/gollem/view.php index e184c71bc..223ca050d 100644 --- a/gollem/view.php +++ b/gollem/view.php @@ -7,34 +7,35 @@ * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * - * @author Max Kalika - * @author Chuck Hagenbuch + * @author Max Kalika + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Gollem */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => array('session_control' => 'readonly')); +Horde_Registry::appInit('imp', array( + 'session_control' => 'readonly' +)); -$actionID = Horde_Util::getFormData('actionID'); -$driver = Horde_Util::getFormData('driver'); -$filedir = Horde_Util::getFormData('dir'); -$filename = Horde_Util::getFormData('file'); -$type = Horde_Util::getFormData('type'); +$vars = Horde_Variables::getDefaultVariables(); -if ($driver != $GLOBALS['gollem_be']['driver']) { - Horde::url('login.php') - ->add(array('backend_key' => $driver, - 'change_backend' => 1, - 'url' => Horde::selfURL(true))) - ->redirect(); +if ($vars->driver != $gollem_be['driver']) { + Horde::url('login.php')->add(array( + 'backend_key' => $vars->driver, + 'change_backend' => 1, + 'url' => Horde::selfURL(true) + ))->redirect(); } $stream = null; $data = ''; try { if (is_callable(array($gollem_vfs, 'readStream'))) { - $stream = $gollem_vfs->readStream($filedir, $filename); + $stream = $gollem_vfs->readStream($vars->dir, $vars->file); } else { - $data = $gollem_vfs->read($filedir, $filename); + $data = $gollem_vfs->read($vars->dir, $vars->file); } } catch (VFS_Exception $e) { Horde::logMessage($e, 'NOTICE'); @@ -42,9 +43,9 @@ try { } /* Run through action handlers. */ -switch ($actionID) { +switch ($vars->actionID) { case 'download_file': - $browser->downloadHeaders($filename, null, false, $GLOBALS['gollem_vfs']->size($filedir, $filename)); + $browser->downloadHeaders($vars->file, null, false, $gollem_vfs->size($vars->dir, $vars->file)); if (is_resource($stream)) { while ($buffer = fread($stream, 8192)) { echo $buffer; @@ -67,8 +68,7 @@ case 'view_file': // TODO exit; - Horde_Mime_Magic::extToMIME($type), $data); - $mime->setName($filename); + $mime->setName($vars->name); $contents = new MIME_Contents($mime); $body = $contents->renderMIMEPart($mime); $type = $contents->getMIMEViewerType($mime); -- 2.11.0