From 98290cd70183211e5a24d766932dc7d3b7d01f8b Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 05:06:13 +0300 Subject: [PATCH 01/23] Standardize actions more: ManageAttachments or ManageBoards as examples Signed-off-by: Norv --- sources/admin/ManageBans.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/sources/admin/ManageBans.php b/sources/admin/ManageBans.php index ff90f48eed..d423528069 100644 --- a/sources/admin/ManageBans.php +++ b/sources/admin/ManageBans.php @@ -38,21 +38,24 @@ public function action_index() require_once(SUBSDIR . '/Bans.subs.php'); $subActions = array( - 'add' => 'action_edit', - 'browse' => 'action_browse', - 'edittrigger' => 'action_edittrigger', - 'edit' => 'action_edit', - 'list' => 'action_list', - 'log' => 'action_log', + 'add' => array($this, 'action_edit'), + 'browse' => array($this, 'action_browse'), + 'edittrigger' => array($this, 'action_edittrigger'), + 'edit' => array($this, 'action_edit'), + 'list' => array($this, 'action_list'), + 'log' => array($this, 'action_log'), ); + $action = new Action(); + $action->initialize($subActions); + call_integration_hook('integrate_manage_bans', array(&$subActions)); // Default the sub-action to 'view ban list'. - $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'list'; + $subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'list'; $context['page_title'] = $txt['ban_title']; - $context['sub_action'] = $_REQUEST['sa']; + $context['sub_action'] = $subAction; // Tabs for browsing the different ban functions. $context[$context['admin_menu_name']]['tab_data'] = array( @@ -63,29 +66,29 @@ public function action_index() 'list' => array( 'description' => $txt['ban_description'], 'href' => $scripturl . '?action=admin;area=ban;sa=list', - 'is_selected' => $_REQUEST['sa'] == 'list' || $_REQUEST['sa'] == 'edit' || $_REQUEST['sa'] == 'edittrigger', + 'is_selected' => $subAction == 'list' || $subAction == 'edit' || $subAction == 'edittrigger', ), 'add' => array( 'description' => $txt['ban_description'], 'href' => $scripturl . '?action=admin;area=ban;sa=add', - 'is_selected' => $_REQUEST['sa'] == 'add', + 'is_selected' => $subAction == 'add', ), 'browse' => array( 'description' => $txt['ban_trigger_browse_description'], 'href' => $scripturl . '?action=admin;area=ban;sa=browse', - 'is_selected' => $_REQUEST['sa'] == 'browse', + 'is_selected' => $subAction == 'browse', ), 'log' => array( 'description' => $txt['ban_log_description'], 'href' => $scripturl . '?action=admin;area=ban;sa=log', - 'is_selected' => $_REQUEST['sa'] == 'log', + 'is_selected' => $subAction == 'log', 'is_last' => true, ), ), ); // Call the right function for this sub-action. - $this->{$subActions[$_REQUEST['sa']]}(); + $action->dispatch($subAction); } /** From af8b55b5d8f6256d70af13ad168f4fe3a5e6b7b1 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 05:07:41 +0300 Subject: [PATCH 02/23] Tweak actions for ManageCalendar (to standard, no $_REQUEST['sa']) Signed-off-by: Norv --- sources/admin/ManageCalendar.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/admin/ManageCalendar.php b/sources/admin/ManageCalendar.php index 2c3c10b5d8..0fc49fb992 100644 --- a/sources/admin/ManageCalendar.php +++ b/sources/admin/ManageCalendar.php @@ -58,7 +58,7 @@ public function action_index() call_integration_hook('integrate_manage_calendar', array(&$subActions)); - $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'holidays'; + $subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'holidays'; // Set up the two tabs here... $context[$context['admin_menu_name']]['tab_data'] = array( @@ -77,7 +77,7 @@ public function action_index() $action = new Action(); $action->initialize($subActions); - $action->dispatch($_REQUEST['sa']); + $action->dispatch($subAction); } /** From 1f679e499549149ce21c0722d595ee2851f3a0a0 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 05:14:56 +0300 Subject: [PATCH 03/23] CoreFeatures, add action_index() to delegate to its action_features(). This is simply a level of indirection, when the work is all done in action_features; core features is a form which accepts user input to switch on/off. If/when we split the user input handling from the rest of action_features(), we might have a benefit. Now it's just a matter of standardization attempt: action_index() directs to stuff, doesn't process usually. Signed-off-by: Norv --- sources/admin/ManageCoreFeatures.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sources/admin/ManageCoreFeatures.php b/sources/admin/ManageCoreFeatures.php index f671d31299..580080fdf5 100644 --- a/sources/admin/ManageCoreFeatures.php +++ b/sources/admin/ManageCoreFeatures.php @@ -29,6 +29,17 @@ */ class ManageCoreFeatures_Controller extends Action_Controller { + /** + * Default handler. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // just delegate to our preferred default + $this->action_features(); + } + /** * This is an overall control panel enabling/disabling lots of the forums key features. * @@ -41,7 +52,7 @@ class ManageCoreFeatures_Controller extends Action_Controller * save_callback - Function called on save, takes state as parameter. * */ - public function action_index() + public function action_features() { global $txt, $scripturl, $context, $settings, $modSettings; From c2fa393545bb6e7776395740cffac9e5cb873c07 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 05:50:36 +0300 Subject: [PATCH 04/23] Refactor the redirection to viewfile for $_REQUEST['file'] set. Add an activity for viewfile in ManageErrors. Signed-off-by: Norv --- sources/admin/AdminLog.php | 2 +- sources/admin/ManageBadBehavior.php | 2 +- sources/admin/ManageErrors.php | 38 +++++++++++++++++------------ sources/subs/Error.subs.php | 4 +-- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/sources/admin/AdminLog.php b/sources/admin/AdminLog.php index 182a85e01c..9e6a70f1d6 100644 --- a/sources/admin/AdminLog.php +++ b/sources/admin/AdminLog.php @@ -40,7 +40,7 @@ public function action_index() $log_functions = array( 'errorlog' => array( 'file' => 'ManageErrors.php', - 'function' => 'action_log', + 'function' => 'action_index', 'controller' => 'ManageErrors_Controller'), 'adminlog' => array( 'file' => 'Modlog.php', diff --git a/sources/admin/ManageBadBehavior.php b/sources/admin/ManageBadBehavior.php index a1ac108a8a..95947937ad 100644 --- a/sources/admin/ManageBadBehavior.php +++ b/sources/admin/ManageBadBehavior.php @@ -27,7 +27,7 @@ public function action_index() * View the forum's badbehavior log. * This function sets all the context up to show the badbehavior log for review. * It requires the maintain_forum permission. - * It is accessed from ?action=admin;area=logs;sa=errorlog. + * It is accessed from ?action=admin;area=logs;sa=badbehaviorlog. * * @uses the BadBehavior template and badbehavior_log sub template. */ diff --git a/sources/admin/ManageErrors.php b/sources/admin/ManageErrors.php index 43743763e0..e9edf3e5fd 100644 --- a/sources/admin/ManageErrors.php +++ b/sources/admin/ManageErrors.php @@ -28,24 +28,37 @@ class ManageErrors_Controller extends Action_Controller { /** * Calls the right handler. + * Requires admin_forum permission. * * @see Action_Controller::action_index() */ public function action_index() { - // view error log - $this->action_log(); + // Check for the administrative permission to do this. + isAllowedTo('admin_forum'); + + // The error log. View the list or view a file? + if (isset($_REQUEST['activity'])) + $activity = $_REQUEST['activity']; + + // Some code redundancy... and we only take this! + if (isset($activity) && $activity == 'file') + // view the file with the error + $this->action_viewfile(); + else + // view error log + $this->action_log(); } /** * View the forum's error log. - * This function sets all the context up to show the error log for maintenance. - * It requires the maintain_forum permission. + * This method sets all the context up to show the error log for maintenance. + * It requires the admin_forum permission. * It is accessed from ?action=admin;area=logs;sa=errorlog. * * @uses the Errors template and error_log sub template. */ - public function action_log() + protected function action_log() { global $scripturl, $txt, $context, $modSettings, $user_profile, $filter; @@ -53,13 +66,6 @@ public function action_log() require_once(SUBSDIR . '/Error.subs.php'); - // Viewing contents of a file? - if (isset($_GET['file'])) - return $this->action_viewfile(); - - // Check for the administrative permission to do this. - isAllowedTo('admin_forum'); - // Templates, etc... loadLanguage('ManageMaintenance'); loadTemplate('Errors'); @@ -214,16 +220,16 @@ public function action_log() * Preconditions: * - file must be readable, * - full file path must be base64 encoded, - * - user must have admin_forum permission. * The line number number is specified by $_REQUEST['line']... * The function will try to get the 20 lines before and after the specified line. */ - public function action_viewfile() + protected function action_viewfile() { global $context; - // Check for the administrative permission to do this. - isAllowedTo('admin_forum'); + // We can't help you if you don't spell it out loud :P + if (!isset($_REQUEST['file'])) + redirectexit(); // Decode the file and get the line $filename = base64_decode($_REQUEST['file']); diff --git a/sources/subs/Error.subs.php b/sources/subs/Error.subs.php index b2eb30313e..2a3f72248b 100644 --- a/sources/subs/Error.subs.php +++ b/sources/subs/Error.subs.php @@ -141,8 +141,8 @@ function getErrorLogData($start, $sort_direction = 'DESC', $filter = null) $log['errors'][$row['id_error']]['file'] = array( 'file' => $row['file'], 'line' => $row['line'], - 'href' => $scripturl . '?action=admin;area=logs;sa=errorlog;file=' . base64_encode($row['file']) . ';line=' . $row['line'], - 'link' => $linkfile ? '' . $row['file'] . '' : $row['file'], + 'href' => $scripturl . '?action=admin;area=logs;sa=errorlog;activity=file;file=' . base64_encode($row['file']) . ';line=' . $row['line'], + 'link' => $linkfile ? '' . $row['file'] . '' : $row['file'], 'search' => base64_encode($row['file']), ); } From 1cb88e03236c986589c17b9214b6d6b1d7dfe3c7 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 06:20:09 +0300 Subject: [PATCH 05/23] Add enabled/disabled and default actions to Action class. Signed-off-by: Norv --- sources/subs/Action.class.php | 44 ++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/sources/subs/Action.class.php b/sources/subs/Action.class.php index b200aa9caa..9b2895394d 100644 --- a/sources/subs/Action.class.php +++ b/sources/subs/Action.class.php @@ -22,21 +22,37 @@ class Action /** * Array of sub-actions. * The accepted array format is: - * - 'sub_action name' => 'function name', or - * - 'sub_action name' => array ('function' => 'function name'), or - * - 'sub_action name' => array ( + * 'sub_action name' => 'function name', + * or + * 'sub_action name' => array ( + * 'function' => 'function name'), + * or + * 'sub_action name' => array ( * 'controller' => 'controller name', - * 'function' => 'method name'), or - * - 'sub_action name' => array ('controller object, i.e. $this', 'method name'), or - * - 'sub_action name' => array ( + * 'function' => 'method name' + * 'enabled' => true/false), + * or + * 'sub_action name' => array ( + * 'controller object, i.e. $this', + * 'method name', + * 'enabled' => true/false), + * or + * 'sub_action name' => array ( * 'file' => 'file name', * 'dir' => 'controller file location', if not set ADMINDIR is assumed * 'controller' => 'controller name', - * 'function' => 'method name') + * 'function' => 'method name', + * 'enabled' => true/false) * @var array */ protected $_subActions; + /** + * The default subAction. + * @var string + */ + protected $_default; + /** * Initialize the instance with an array of sub-actions. * Sub-actions have to be in the format expected for Action::_subActions array, @@ -44,7 +60,7 @@ class Action * * @param array $subactions */ - function initialize ($subactions) + function initialize($subactions, $default = '') { $this->_subActions = array(); @@ -52,6 +68,9 @@ function initialize ($subactions) $subactions = array($subactions); $this->_subActions = $subactions; + + if (isset($subactions[$default])) + $this->_default = $default; } /** @@ -71,6 +90,15 @@ function dispatch($sa) $subAction = $this->_subActions[$sa]; + // unless it's disabled, then we redirect to the default action + if (isset($subAction['enabled']) && !$subAction['enabled']) + if (!empty($this->_default)) + $subAction = $this->_subActions[$this->_default]; + else + // no dice + fatal_lang_error('error_sa_not_set'); + + // are you even permitted to? if (isset($subAction['permission'])) isAllowedTo($subAction['permission']); From 7da9d7c22dc836ee8761d0f719485bae329b9b73 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 06:20:30 +0300 Subject: [PATCH 06/23] Refactor actions for admin features page to use enabled/disabled and default. Signed-off-by: Norv --- sources/admin/ManageFeatures.php | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/sources/admin/ManageFeatures.php b/sources/admin/ManageFeatures.php index c49d5ef7c6..140a3fa888 100644 --- a/sources/admin/ManageFeatures.php +++ b/sources/admin/ManageFeatures.php @@ -72,23 +72,25 @@ public function action_index() $subActions = array( 'basic' => array( 'controller' => $this, - 'function' => 'action_basicSettings_display', - 'default' => true), + 'function' => 'action_basicSettings_display'), 'layout' => array( 'controller' => $this, 'function' => 'action_layoutSettings_display'), 'karma' => array( 'controller' => $this, - 'function' => 'action_karmaSettings_display'), + 'function' => 'action_karmaSettings_display', + 'enabled' => in_array('k', $context['admin_features'])), 'likes' => array( 'controller' => $this, - 'function' => 'action_likesSettings_display'), + 'function' => 'action_likesSettings_display', + 'enabled' => in_array('l', $context['admin_features'])), 'sig' => array( 'controller' => $this, 'function' => 'action_signatureSettings_display'), 'profile' => array( 'controller' => $this, - 'function' => 'action_profile'), + 'function' => 'action_profile', + 'enabled' => in_array('cp', $context['admin_features'])), 'profileedit' => array( 'controller' => $this, 'function' => 'action_profileedit'), @@ -96,25 +98,13 @@ public function action_index() call_integration_hook('integrate_modify_features', array(&$subActions)); - // If Advanced Profile Fields are disabled don't show the setting page - if (!in_array('cp', $context['admin_features'])) - unset($subActions['profile']); - - // Same for Karma - if (!in_array('k', $context['admin_features'])) - unset($subActions['karma']); - - // And likes - if (!in_array('l', $context['admin_features'])) - unset($subActions['likes']); - // By default do the basic settings. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'basic'; $subAction = $_REQUEST['sa']; // Set up action/subaction stuff. $action = new Action(); - $action->initialize($subActions); + $action->initialize($subActions, 'basic'); loadLanguage('Help'); loadLanguage('ManageSettings'); From 0d2ac3a234d015e31c32e56ec513d1bfc744fa75 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 06:25:11 +0300 Subject: [PATCH 07/23] Small standardization of actions to languages admin. Signed-off-by: Norv --- sources/admin/ManageLanguages.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sources/admin/ManageLanguages.php b/sources/admin/ManageLanguages.php index b1df707165..e8ba1cbc37 100644 --- a/sources/admin/ManageLanguages.php +++ b/sources/admin/ManageLanguages.php @@ -62,8 +62,8 @@ public function action_index() call_integration_hook('integrate_manage_languages', array(&$subActions)); // By default we're managing languages. - $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'edit'; - $context['sub_action'] = $_REQUEST['sa']; + $subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'edit'; + $context['sub_action'] = $subAction; // Load up all the tabs... $context[$context['admin_menu_name']]['tab_data'] = array( @@ -73,8 +73,8 @@ public function action_index() // Call the right function for this sub-action. $action = new Action(); - $action->initialize($subActions); - $action->dispatch($_REQUEST['sa']); + $action->initialize($subActions, 'edit'); + $action->dispatch($subAction); } /** From 1a56404ae78d577927aebfb44f1327790adfc668 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 06:34:49 +0300 Subject: [PATCH 08/23] Tweaks to bring actions handling to the common pattern. Signed-off-by: Norv --- sources/admin/ManageMail.php | 8 ++++---- sources/admin/ManageMaillist.php | 2 +- sources/admin/ManageMembers.php | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sources/admin/ManageMail.php b/sources/admin/ManageMail.php index c57481c3bd..5098b3e93b 100644 --- a/sources/admin/ManageMail.php +++ b/sources/admin/ManageMail.php @@ -61,8 +61,8 @@ public function action_index() call_integration_hook('integrate_manage_mail', array(&$subActions)); // By default we want to browse - $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'browse'; - $context['sub_action'] = $_REQUEST['sa']; + $subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'browse'; + $context['sub_action'] = $subAction; // Load up all the tabs... $context[$context['admin_menu_name']]['tab_data'] = array( @@ -73,8 +73,8 @@ public function action_index() // Call the right function for this sub-action. $action = new Action(); - $action->initialize($subActions); - $action->dispatch($_REQUEST['sa']); + $action->initialize($subActions, 'browse'); + $action->dispatch($subAction); } /** diff --git a/sources/admin/ManageMaillist.php b/sources/admin/ManageMaillist.php index 9203fa4730..c3d7f7c9e4 100644 --- a/sources/admin/ManageMaillist.php +++ b/sources/admin/ManageMaillist.php @@ -58,7 +58,7 @@ public function action_index() // Set up the action class $action = new Action(); - $action->initialize($subActions); + $action->initialize($subActions, 'emaillist'); // Default to sub action 'emaillist' if none was given $subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) && (empty($subActions[$_REQUEST['sa']][1]) || allowedTo($subActions[$_REQUEST['sa']][1])) ? $_REQUEST['sa'] : 'emaillist'; diff --git a/sources/admin/ManageMembers.php b/sources/admin/ManageMembers.php index 36526796a6..0e5b78dbba 100644 --- a/sources/admin/ManageMembers.php +++ b/sources/admin/ManageMembers.php @@ -66,14 +66,14 @@ public function action_index() call_integration_hook('integrate_manage_members', array(&$subActions)); - // Default to sub action 'index' or 'settings' depending on permissions. + // Default to sub action 'all'. $subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'all'; $action = new Action(); - $action->initialize($subActions); + $action->initialize($subActions, 'all'); // You can't pass! - $action->isAllowedTo($subAction); // this isn't the simplest way, but lets accept it + $action->isAllowedTo($subAction); // Load the essentials. loadLanguage('ManageMembers'); From 9aed0ff37fb0e00ba2488b34d1a92d395daf2efc Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 06:47:35 +0300 Subject: [PATCH 09/23] Refactor enabled/disabled actions for security settings; tweaks. Signed-off-by: Norv --- sources/admin/ManageRegistration.php | 4 ++-- sources/admin/ManageScheduledTasks.php | 2 +- sources/admin/ManageSecurity.php | 8 ++------ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/sources/admin/ManageRegistration.php b/sources/admin/ManageRegistration.php index 7472d7659e..3fce60a2d4 100644 --- a/sources/admin/ManageRegistration.php +++ b/sources/admin/ManageRegistration.php @@ -72,11 +72,11 @@ public function action_index() call_integration_hook('integrate_manage_registrations', array(&$subActions)); // Work out which to call... - $subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('moderate_forum') ? 'register' : 'settings'); + $subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'register'; // Set up action/subaction stuff. $action = new Action(); - $action->initialize($subActions); + $action->initialize($subActions, 'register'); // You way will end here if you don't have permission. $action->isAllowedTo($subAction); diff --git a/sources/admin/ManageScheduledTasks.php b/sources/admin/ManageScheduledTasks.php index 4111fd155d..6e56534b54 100644 --- a/sources/admin/ManageScheduledTasks.php +++ b/sources/admin/ManageScheduledTasks.php @@ -58,7 +58,7 @@ public function action_index() // Set up action/subaction stuff. $action = new Action(); - $action->initialize($subActions); + $action->initialize($subActions, 'tasks'); // Now for the lovely tabs. That we all love. $context[$context['admin_menu_name']]['tab_data'] = array( diff --git a/sources/admin/ManageSecurity.php b/sources/admin/ManageSecurity.php index fa55d054fa..764d7111f8 100644 --- a/sources/admin/ManageSecurity.php +++ b/sources/admin/ManageSecurity.php @@ -63,15 +63,11 @@ public function action_index() 'general' => array($this, 'action_securitySettings_display'), 'spam' => array($this, 'action_spamSettings_display'), 'badbehavior' => array($this, 'action_bbSettings_display'), - 'moderation' => array($this, 'action_moderationSettings_display'), + 'moderation' => array($this, 'action_moderationSettings_display', 'enabled' => in_array('w', $context['admin_features'])), ); call_integration_hook('integrate_modify_security', array(&$subActions)); - // If Warning System is disabled don't show the setting page - if (!in_array('w', $context['admin_features'])) - unset($subActions['moderation']); - // @FIXME // loadGeneralSettingParameters($subActions, 'general'); @@ -92,7 +88,7 @@ public function action_index() // Set up action stuff. $action = new Action(); - $action->initialize($subActions); + $action->initialize($subActions, 'general'); // Load up all the tabs... $context[$context['admin_menu_name']]['tab_data'] = array( From 80a298c6ec5b2ed85409b72789ed8db75e7bd257 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 07:10:21 +0300 Subject: [PATCH 10/23] Add enabled/disabled and default to smileys admin actions. Added another method to Action, to tackle the 'real' sa which will be set. Not ideal.. Signed-off-by: Norv --- sources/admin/ManageSmileys.php | 31 ++++++++----------------------- sources/subs/Action.class.php | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/sources/admin/ManageSmileys.php b/sources/admin/ManageSmileys.php index 2218f39e31..56aa7b2c3b 100644 --- a/sources/admin/ManageSmileys.php +++ b/sources/admin/ManageSmileys.php @@ -52,36 +52,21 @@ public function action_index() loadTemplate('ManageSmileys'); $subActions = array( - 'addsmiley' => array($this, 'action_addsmiley'), - 'editicon' => array($this, 'action_editicon'), - 'editicons' => array($this, 'action_editicon'), + 'addsmiley' => array($this, 'action_addsmiley', 'enabled' => !empty($modSettings['smiley_enable'])), + 'editicon' => array($this, 'action_editicon', 'enabled' => !empty($modSettings['messageIcons_enable'])), + 'editicons' => array($this, 'action_editicon', 'enabled' => !empty($modSettings['messageIcons_enable'])), 'editsets' => array($this, 'action_edit'), - 'editsmileys' => array($this, 'action_editsmiley'), + 'editsmileys' => array($this, 'action_editsmiley', 'enabled' => !empty($modSettings['smiley_enable'])), 'import' => array($this, 'action_edit'), 'modifyset' => array($this, 'action_edit'), - 'modifysmiley' => array($this, 'action_editsmiley'), - 'setorder' => array($this, 'action_setorder'), + 'modifysmiley' => array($this, 'action_editsmiley', 'enabled' => !empty($modSettings['smiley_enable'])), + 'setorder' => array($this, 'action_setorder', 'enabled' => !empty($modSettings['smiley_enable'])), 'settings' => array($this, 'action_smileySettings_display'), 'install' => array($this, 'action_install') ); call_integration_hook('integrate_manage_smileys', array(&$subActions)); - // If customized smileys is disabled don't show the setting page - if (empty($modSettings['smiley_enable'])) - { - unset($subActions['addsmiley']); - unset($subActions['editsmileys']); - unset($subActions['setorder']); - unset($subActions['modifysmiley']); - } - // If customized message icons is disabled don't show their page either! - if (empty($modSettings['messageIcons_enable'])) - { - unset($subActions['editicon']); - unset($subActions['editicons']); - } - // Set the smiley context. $this->_initSmileyContext(); @@ -90,11 +75,11 @@ public function action_index() // Set up action/subaction stuff. $action = new Action(); - $action->initialize($subActions); + $action->initialize($subActions, 'editsets'); // Set up template stuff $context['page_title'] = $txt['smileys_manage']; - $context['sub_action'] = $subAction; + $context['sub_action'] = $action->subaction($subAction); // Load up all the tabs... $context[$context['admin_menu_name']]['tab_data'] = array( diff --git a/sources/subs/Action.class.php b/sources/subs/Action.class.php index 9b2895394d..daea254b3b 100644 --- a/sources/subs/Action.class.php +++ b/sources/subs/Action.class.php @@ -149,6 +149,28 @@ function dispatch($sa) } } + /** + * Return the subaction. + * This method checks if $sa is enabled, and falls back to default if not. + * Used only to set the context for the template. + * + * @param string $sa + */ + public function subaction($sa) + { + $subAction = $this->_subActions[$sa]; + + // if it's disabled, then default action + if (isset($subAction['enabled']) && !$subAction['enabled']) + if (!empty($this->_default)) + $sa = $this->_default; + else + // no dice + fatal_lang_error('error_sa_not_set'); + + return $sa; + } + /** * Security check: verify that the user has the permission to perform the given action. * Verifies if the user has the permission set for the given action. From dc47686aa6c7c55a24acdc4c6a6959224afd698b Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 07:40:30 +0300 Subject: [PATCH 11/23] Standardize themes admin actions more; tweak visibility and a useless line. Signed-off-by: Norv --- sources/admin/ManageFeatures.php | 3 +-- sources/admin/ManageTopics.php | 5 ++--- sources/admin/Reports.php | 12 ++++++------ sources/admin/Themes.php | 30 +++++++++++++++++------------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/sources/admin/ManageFeatures.php b/sources/admin/ManageFeatures.php index 140a3fa888..445584550f 100644 --- a/sources/admin/ManageFeatures.php +++ b/sources/admin/ManageFeatures.php @@ -99,8 +99,7 @@ public function action_index() call_integration_hook('integrate_modify_features', array(&$subActions)); // By default do the basic settings. - $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'basic'; - $subAction = $_REQUEST['sa']; + $subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'basic'; // Set up action/subaction stuff. $action = new Action(); diff --git a/sources/admin/ManageTopics.php b/sources/admin/ManageTopics.php index 4d56eeb414..1d95e4bb84 100644 --- a/sources/admin/ManageTopics.php +++ b/sources/admin/ManageTopics.php @@ -36,14 +36,13 @@ public function action_index() $subActions = array( 'display' => array ( 'controller' => $this, - 'function' => 'action_topicSettings_display', - 'default' => true)); + 'function' => 'action_topicSettings_display')); $subAction = 'display'; // Set up action/subaction stuff. $action = new Action(); - $action->initialize($subActions); + $action->initialize($subActions, 'display'); // lets just do it! $action->dispatch($subAction); diff --git a/sources/admin/Reports.php b/sources/admin/Reports.php index f93c797a6d..6aa6ca627f 100644 --- a/sources/admin/Reports.php +++ b/sources/admin/Reports.php @@ -46,7 +46,7 @@ class Reports_Controller extends Action_Controller * * @see Action_Controller::action_index() */ - function action_index() + public function action_index() { global $txt, $context, $scripturl; @@ -146,7 +146,7 @@ function action_index() * never access the context directly, but use the data handling * functions to do so. */ - function action_boards() + public function action_boards() { global $context, $txt, $modSettings; @@ -265,7 +265,7 @@ function action_boards() * never access the context directly, but use the data handling * functions to do so. */ - function action_board_perms() + public function action_board_perms() { global $context, $txt, $modSettings; @@ -432,7 +432,7 @@ function action_board_perms() * never access the context directly, but use the data handling * functions to do so. */ - function action_member_groups() + public function action_member_groups() { global $context, $txt, $settings, $modSettings; @@ -557,7 +557,7 @@ function action_member_groups() * never access the context directly, but use the data handling * functions to do so. */ - function action_group_perms() + public function action_group_perms() { global $context, $txt, $modSettings; @@ -662,7 +662,7 @@ function action_group_perms() * never access the context directly, but use the data handling * functions to do so. */ - function action_staff() + public function action_staff() { global $context, $txt; diff --git a/sources/admin/Themes.php b/sources/admin/Themes.php index 53cddab052..4283f2ef76 100644 --- a/sources/admin/Themes.php +++ b/sources/admin/Themes.php @@ -68,17 +68,17 @@ public function action_index() // Theme administration, removal, choice, or installation... $subActions = array( - 'admin' => 'action_admin', - 'list' => 'action_list', - 'reset' => 'action_options', - 'options' => 'action_options', - 'install' => 'action_install', - 'remove' => 'action_remove', - 'pick' => 'action_pick', - 'edit' => 'action_edit', - 'copy' => 'action_copy', - 'themelist' => 'action_themelist', - 'browse' => 'action_browse', + 'admin' => array($this, 'action_admin'), + 'list' => array($this, 'action_list'), + 'reset' => array($this, 'action_options'), + 'options' => array($this, 'action_options'), + 'install' => array($this, 'action_install'), + 'remove' => array($this, 'action_remove'), + 'pick' => array($this, 'action_pick'), + 'edit' => array($this, 'action_edit'), + 'copy' => array($this, 'action_copy'), + 'themelist' => array($this, 'action_themelist'), + 'browse' => array($this, 'action_browse'), ); // @todo Layout Settings? @@ -113,9 +113,13 @@ public function action_index() // Follow the sa or just go to administration. if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']])) - $this->{$subActions[$_GET['sa']]}(); + $subAction = $_GET['sa']; else - $this->{$subActions['admin']}(); + $subAction = 'admin'; + + $action = new Action(); + $action->initialize($subActions, 'admin'); + $action->dispatch($subAction); } public function action_index_api() From 5ecb3ecc614fcb6f1d84ff2c7048eb986f9c8118 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 09:26:06 +0300 Subject: [PATCH 12/23] Split PackageServers in its own template. (prepare for a PackageServers area) Signed-off-by: Norv --- sources/admin/PackageServers.php | 6 +- themes/default/PackageServers.template.php | 391 +++++++++++++++++++++ themes/default/Packages.template.php | 372 -------------------- 3 files changed, 395 insertions(+), 374 deletions(-) create mode 100644 themes/default/PackageServers.template.php diff --git a/sources/admin/PackageServers.php b/sources/admin/PackageServers.php index 34bf4c8e81..498c07c1d8 100644 --- a/sources/admin/PackageServers.php +++ b/sources/admin/PackageServers.php @@ -39,9 +39,11 @@ public function action_index() isAllowedTo('admin_forum'); require_once(SUBSDIR . '/Package.subs.php'); - // Use the Packages template... no reason to separate. + // Use the Packages language file. (split servers?) loadLanguage('Packages'); - loadTemplate('Packages', 'admin'); + + // Use the PackageServers template. + loadTemplate('PackageServers', 'admin'); $context['page_title'] = $txt['package']; diff --git a/themes/default/PackageServers.template.php b/themes/default/PackageServers.template.php new file mode 100644 index 0000000000..a005518a90 --- /dev/null +++ b/themes/default/PackageServers.template.php @@ -0,0 +1,391 @@ + + ', $context['package_ftp']['error'], ' + '; + + echo ' +
+
+

', $txt['download_new_package'], '

+
'; + + if ($context['package_download_broken']) + { + echo ' +
+

', $txt['package_ftp_necessary'], '

+
+
+
+

+ ', $txt['package_ftp_why_download'], ' +

+
+
+
+ +
+
+ + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+
+
'; + } + + echo ' +
+
+
+ ' . $txt['package_servers'] . ' + +
+
+ ' . $txt['add_server'] . ' +
+
+
+ ' . $txt['server_name'] . ': +
+
+ +
+
+ ' . $txt['serverurl'] . ': +
+
+ +
+
+
+ + +
+
+
+
+ ', $txt['package_download_by_url'], ' +
+
+
+ ' . $txt['serverurl'] . ': +
+
+ +
+
+ ', $txt['package_download_filename'], ': +
+
+
+ ', $txt['package_download_filename_info'], ' +
+
+
+ +
+
+
+
+
+
+
+

' . $txt['package_upload_title'] . '

+
+
+
+
+
+
+ ' . $txt['package_upload_select'] . ': +
+
+ +
+
+
+ + +
+
+
+
'; +} + +function template_package_confirm() +{ + global $context, $txt; + + echo ' +
+
+

', $context['page_title'], '

+
+ +
'; +} + +function template_package_list() +{ + global $context, $settings, $txt; + + echo ' +
+
+

' . $context['page_title'] . '

+
+
+
'; + + // No packages, as yet. + if (empty($context['package_list'])) + echo ' +
    +
  • ', $txt['no_packages'], '
  • +
'; + // List out the packages... + else + { + echo ' +
    '; + foreach ($context['package_list'] as $i => $packageSection) + { + echo ' +
  • + ', $packageSection['title'], ''; + + if (!empty($packageSection['text'])) + echo ' +
    ', $packageSection['text'], '
    '; + + echo ' + <', $context['list_type'], ' id="package_section_', $i, '" class="packages">'; + + $alt = false; + + foreach ($packageSection['items'] as $id => $package) + { + echo ' +
  • '; + // Textual message. Could be empty just for a blank line... + if ($package['is_text']) + echo ' + ', empty($package['name']) ? ' ' : $package['name']; + // This is supposed to be a rule.. + elseif ($package['is_line']) + echo ' +
    '; + // A remote link. + elseif ($package['is_remote']) + { + echo ' + ', $package['link'], ''; + } + // A title? + elseif ($package['is_heading'] || $package['is_title']) + { + echo ' + ', $package['name'], ''; + } + // Otherwise, it's a package. + else + { + // 1. Some mod [ Download ]. + echo ' + ', $package['can_install'] ? '' . $package['name'] . ' [ ' . $txt['download'] . ' ]': $package['name']; + + // Mark as installed and current? + if ($package['is_installed'] && !$package['is_newer']) + echo '', $package['is_current'] ? $txt['package_installed_current'] : $txt['package_installed_old'], ''; + + echo ' + +
      '; + + // Show the mod type? + if ($package['type'] != '') + echo ' +
    • ', $txt['package_type'], ':  ', Util::ucwords(Util::strtolower($package['type'])), '
    • '; + // Show the version number? + if ($package['version'] != '') + echo ' +
    • ', $txt['mod_version'], ':  ', $package['version'], '
    • '; + // How 'bout the author? + if (!empty($package['author']) && $package['author']['name'] != '' && isset($package['author']['link'])) + echo ' +
    • ', $txt['mod_author'], ':  ', $package['author']['link'], '
    • '; + // The homepage.... + if ($package['author']['website']['link'] != '') + echo ' +
    • ', $txt['author_website'], ':  ', $package['author']['website']['link'], '
    • '; + + // Desciption: bleh bleh! + // Location of file: http://someplace/. + echo ' +
    • ', $txt['file_location'], ':  ', $package['href'], '
    • +
    • ', $txt['package_description'], ':  ', $package['description'], '
    • +
    '; + } + $alt = !$alt; + echo ' +
  • '; + } + echo ' + + '; + } + echo ' +
'; + + } + + echo ' +
+
+
+ ', $txt['package_installed_key'], ' + ', $txt['package_installed_current'], ' + ', $txt['package_installed_old'], ' +
+
+ + '; + // Now go through and turn off all the sections. + if (!empty($context['package_list'])) + { + $section_count = count($context['package_list']); + echo ' + '; + } +} + +function template_downloaded() +{ + global $context, $txt, $scripturl; + + echo ' +
+
+

', $context['page_title'], '

+
+
+
+

', (empty($context['package_server']) ? $txt['package_uploaded_successfully'] : $txt['package_downloaded_successfully']), '

+
    +
  • ', $context['package']['name'], ' + ', $context['package']['list_files']['link'], ' + ', $context['package']['install']['link'], ' +
  • +
+

+

[ ', $txt['back'], ' ]

+
+
+
'; +} \ No newline at end of file diff --git a/themes/default/Packages.template.php b/themes/default/Packages.template.php index 0c164d911a..7bb9afaaba 100644 --- a/themes/default/Packages.template.php +++ b/themes/default/Packages.template.php @@ -671,378 +671,6 @@ function template_browse() // ]]>'; } -function template_servers() -{ - global $context, $txt, $scripturl; - - if (!empty($context['package_ftp']['error'])) - echo ' -
- ', $context['package_ftp']['error'], ' -
'; - - echo ' -
-
-

', $txt['download_new_package'], '

-
'; - - if ($context['package_download_broken']) - { - echo ' -
-

', $txt['package_ftp_necessary'], '

-
-
-
-

- ', $txt['package_ftp_why_download'], ' -

-
-
-
- -
-
- - -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- -
-
-
-
'; - } - - echo ' -
-
-
- ' . $txt['package_servers'] . ' - -
-
- ' . $txt['add_server'] . ' -
-
-
- ' . $txt['server_name'] . ': -
-
- -
-
- ' . $txt['serverurl'] . ': -
-
- -
-
-
- - -
-
-
-
- ', $txt['package_download_by_url'], ' -
-
-
- ' . $txt['serverurl'] . ': -
-
- -
-
- ', $txt['package_download_filename'], ': -
-
-
- ', $txt['package_download_filename_info'], ' -
-
-
- -
-
-
-
-
-
-
-

' . $txt['package_upload_title'] . '

-
-
-
-
-
-
- ' . $txt['package_upload_select'] . ': -
-
- -
-
-
- - -
-
-
-
'; -} - -function template_package_confirm() -{ - global $context, $txt; - - echo ' -
-
-

', $context['page_title'], '

-
- -
'; -} - -function template_package_list() -{ - global $context, $settings, $txt; - - echo ' -
-
-

' . $context['page_title'] . '

-
-
-
'; - - // No packages, as yet. - if (empty($context['package_list'])) - echo ' -
    -
  • ', $txt['no_packages'], '
  • -
'; - // List out the packages... - else - { - echo ' -
    '; - foreach ($context['package_list'] as $i => $packageSection) - { - echo ' -
  • - ', $packageSection['title'], ''; - - if (!empty($packageSection['text'])) - echo ' -
    ', $packageSection['text'], '
    '; - - echo ' - <', $context['list_type'], ' id="package_section_', $i, '" class="packages">'; - - $alt = false; - - foreach ($packageSection['items'] as $id => $package) - { - echo ' -
  • '; - // Textual message. Could be empty just for a blank line... - if ($package['is_text']) - echo ' - ', empty($package['name']) ? ' ' : $package['name']; - // This is supposed to be a rule.. - elseif ($package['is_line']) - echo ' -
    '; - // A remote link. - elseif ($package['is_remote']) - { - echo ' - ', $package['link'], ''; - } - // A title? - elseif ($package['is_heading'] || $package['is_title']) - { - echo ' - ', $package['name'], ''; - } - // Otherwise, it's a package. - else - { - // 1. Some mod [ Download ]. - echo ' - ', $package['can_install'] ? '' . $package['name'] . ' [ ' . $txt['download'] . ' ]': $package['name']; - - // Mark as installed and current? - if ($package['is_installed'] && !$package['is_newer']) - echo '', $package['is_current'] ? $txt['package_installed_current'] : $txt['package_installed_old'], ''; - - echo ' - -
      '; - - // Show the mod type? - if ($package['type'] != '') - echo ' -
    • ', $txt['package_type'], ':  ', Util::ucwords(Util::strtolower($package['type'])), '
    • '; - // Show the version number? - if ($package['version'] != '') - echo ' -
    • ', $txt['mod_version'], ':  ', $package['version'], '
    • '; - // How 'bout the author? - if (!empty($package['author']) && $package['author']['name'] != '' && isset($package['author']['link'])) - echo ' -
    • ', $txt['mod_author'], ':  ', $package['author']['link'], '
    • '; - // The homepage.... - if ($package['author']['website']['link'] != '') - echo ' -
    • ', $txt['author_website'], ':  ', $package['author']['website']['link'], '
    • '; - - // Desciption: bleh bleh! - // Location of file: http://someplace/. - echo ' -
    • ', $txt['file_location'], ':  ', $package['href'], '
    • -
    • ', $txt['package_description'], ':  ', $package['description'], '
    • -
    '; - } - $alt = !$alt; - echo ' -
  • '; - } - echo ' - - '; - } - echo ' -
'; - - } - - echo ' -
-
-
- ', $txt['package_installed_key'], ' - ', $txt['package_installed_current'], ' - ', $txt['package_installed_old'], ' -
-
- - '; - // Now go through and turn off all the sections. - if (!empty($context['package_list'])) - { - $section_count = count($context['package_list']); - echo ' - '; - } -} - -function template_downloaded() -{ - global $context, $txt, $scripturl; - - echo ' -
-
-

', $context['page_title'], '

-
-
-
-

', (empty($context['package_server']) ? $txt['package_uploaded_successfully'] : $txt['package_downloaded_successfully']), '

-
    -
  • ', $context['package']['name'], ' - ', $context['package']['list_files']['link'], ' - ', $context['package']['install']['link'], ' -
  • -
-

-

[ ', $txt['back'], ' ]

-
-
-
'; -} - function template_install_options() { global $context, $txt, $scripturl; From 94717e5c9ffde1776ccb8b6c0474008b8927cef5 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 09:52:49 +0300 Subject: [PATCH 13/23] Add Package Servers admin area. Signed-off-by: Norv --- sources/admin/Admin.php | 13 ++++++++- sources/admin/PackageServers.php | 28 +++++++++---------- sources/admin/Packages.php | 13 +-------- themes/default/Admin.template.php | 2 +- themes/default/languages/Admin.english.php | 1 + themes/default/languages/Packages.english.php | 1 - 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/sources/admin/Admin.php b/sources/admin/Admin.php index fad1f11ec6..93468eaf4b 100644 --- a/sources/admin/Admin.php +++ b/sources/admin/Admin.php @@ -110,12 +110,23 @@ public function action_index() 'class' => 'admin_img_packages', 'subsections' => array( 'browse' => array($txt['browse_packages']), - 'packageget' => array($txt['download_packages'], 'url' => $scripturl . '?action=admin;area=packages;sa=packageget;get'), 'installed' => array($txt['installed_packages']), 'perms' => array($txt['package_file_perms']), 'options' => array($txt['package_settings']), ), ), + 'packageservers' => array( + 'label' => $txt['package_servers'], + 'file' => 'PackageServers.php', + 'controller' => 'PackageServers_Controller', + 'function' => 'action_index', + 'permission' => array('admin_forum'), + 'icon' => 'transparent.png', + 'class' => 'admin_img_packages', + 'subsections' => array( + 'servers' => array($txt['download_packages'], 'url' => $scripturl . '?action=admin;area=packageservers'), + ), + ), 'search' => array( 'controller' => 'Admin_Controller', 'function' => 'action_search', diff --git a/sources/admin/PackageServers.php b/sources/admin/PackageServers.php index 498c07c1d8..2cc78fb45c 100644 --- a/sources/admin/PackageServers.php +++ b/sources/admin/PackageServers.php @@ -36,7 +36,10 @@ public function action_index() { global $txt, $context; + // This is for admins only. isAllowedTo('admin_forum'); + + // Load our subs. require_once(SUBSDIR . '/Package.subs.php'); // Use the Packages language file. (split servers?) @@ -60,9 +63,6 @@ public function action_index() // Now let's decide where we are taking this... if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) $subAction = $_REQUEST['sa']; - // We need to support possible old javascript links... - elseif (isset($_GET['pgdownload'])) - $subAction = 'download'; else $subAction = 'servers'; @@ -73,7 +73,7 @@ public function action_index() $context['sub_action'] = $subAction; // We need to force the "Download" tab as selected. - $context['menu_data_' . $context['admin_menu_id']]['current_subsection'] = 'packageget'; + $context['menu_data_' . $context['admin_menu_id']]['current_subsection'] = 'servers'; // Now create the tabs for the template. $context[$context['admin_menu_name']]['tab_data'] = array( @@ -83,7 +83,7 @@ public function action_index() 'tabs' => array( 'browse' => array( ), - 'packageget' => array( + 'servers' => array( 'description' => $txt['download_packages_desc'], ), 'installed' => array( @@ -195,7 +195,7 @@ public function action_browse() if (isset($_GET['server'])) { if ($_GET['server'] == '') - redirectexit('action=admin;area=packages;get'); + redirectexit('action=admin;area=packageservers'); $server = (int) $_GET['server']; @@ -233,7 +233,7 @@ public function action_browse() $context['page_title'] = $txt['package_servers']; $context['confirm_message'] = sprintf($txt['package_confirm_view_package_content'], htmlspecialchars($_GET['absolute'])); - $context['proceed_href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . urlencode($_GET['absolute']) . ';confirm=' . $token; + $context['proceed_href'] = $scripturl . '?action=admin;area=packageservers;sa=browse;absolute=' . urlencode($_GET['absolute']) . ';confirm=' . $token; return; } @@ -346,14 +346,14 @@ public function action_browse() $current_url .= $thisPackage->fetch('@href'); if (isset($_GET['absolute'])) - $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url; + $package['href'] = $scripturl . '?action=admin;area=packageservers;sa=browse;absolute=' . $current_url; else - $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $context['package_server'] . ';relative=' . $current_url; + $package['href'] = $scripturl . '?action=admin;area=packageservers;sa=browse;server=' . $context['package_server'] . ';relative=' . $current_url; } else { $current_url = $thisPackage->fetch('@href'); - $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url; + $package['href'] = $scripturl . '?action=admin;area=packageservers;sa=browse;absolute=' . $current_url; } $package['name'] = Util::htmlspecialchars($thisPackage->fetch('.')); @@ -402,7 +402,7 @@ public function action_browse() $package['href'] = $url . '/' . $package['filename']; $package['name'] = Util::htmlspecialchars($package['name']); $package['link'] = '' . $package['name'] . ''; - $package['download']['href'] = $scripturl . '?action=admin;area=packages;get;sa=download' . $server_att . ';package=' . $current_url . $package['filename'] . ($package['download_conflict'] ? ';conflict' : '') . ';' . $context['session_var'] . '=' . $context['session_id']; + $package['download']['href'] = $scripturl . '?action=admin;area=packageservers;sa=download' . $server_att . ';package=' . $current_url . $package['filename'] . ($package['download_conflict'] ? ';conflict' : '') . ';' . $context['session_var'] . '=' . $context['session_id']; $package['download']['link'] = '' . $package['name'] . ''; if ($thisPackage->exists('author') || isset($default_author)) @@ -579,7 +579,7 @@ public function action_download() fatal_lang_error($packageInfo); // Use FTP if necessary. - create_chmod_control(array(BOARDDIR . '/packages/' . $package_name), array('destination_url' => $scripturl . '?action=admin;area=packages;get;sa=download' . (isset($_GET['server']) ? ';server=' . $_GET['server'] : '') . (isset($_REQUEST['auto']) ? ';auto' : '') . ';package=' . $_REQUEST['package'] . (isset($_REQUEST['conflict']) ? ';conflict' : '') . ';' . $context['session_var'] . '=' . $context['session_id'], 'crash_on_error' => true)); + create_chmod_control(array(BOARDDIR . '/packages/' . $package_name), array('destination_url' => $scripturl . '?action=admin;area=packageservers;sa=download' . (isset($_GET['server']) ? ';server=' . $_GET['server'] : '') . (isset($_REQUEST['auto']) ? ';auto' : '') . ';package=' . $_REQUEST['package'] . (isset($_REQUEST['conflict']) ? ';conflict' : '') . ';' . $context['session_var'] . '=' . $context['session_id'], 'crash_on_error' => true)); package_put_contents(BOARDDIR . '/packages/' . $package_name, fetch_web_data($url . $_REQUEST['package'])); // Done! Did we get this package automatically? @@ -721,7 +721,7 @@ public function action_add() addPackageServer($servername, $serverurl); - redirectexit('action=admin;area=packages;get'); + redirectexit('action=admin;area=packageservers'); } /** @@ -736,6 +736,6 @@ public function action_remove() $_GET['server'] = (int) $_GET['server']; deletePackageServer($_GET['server']); - redirectexit('action=admin;area=packages;get'); + redirectexit('action=admin;area=packageservers'); } } \ No newline at end of file diff --git a/sources/admin/Packages.php b/sources/admin/Packages.php index f0e0751178..2e4bc426ac 100644 --- a/sources/admin/Packages.php +++ b/sources/admin/Packages.php @@ -36,15 +36,7 @@ public function action_index() { global $txt, $context; - // @todo Remove this! - if (isset($_GET['get']) || isset($_GET['pgdownload'])) - { - require_once(ADMINDIR . '/PackageServers.php'); - $controller = new PackageServers_Controller(); - $controller->action_index(); - return; - } - + // Admins-only! isAllowedTo('admin_forum'); // Load all the basic stuff. @@ -90,9 +82,6 @@ public function action_index() 'tabs' => array( 'browse' => array( ), - 'packageget' => array( - 'description' => $txt['download_packages_desc'], - ), 'installed' => array( 'description' => $txt['installed_packages_desc'], ), diff --git a/themes/default/Admin.template.php b/themes/default/Admin.template.php index 0139b75c6e..75139b59d1 100644 --- a/themes/default/Admin.template.php +++ b/themes/default/Admin.template.php @@ -154,7 +154,7 @@ function template_admin() '), ', - sUpdateNotificationLink: elk_scripturl + ', JavaScriptEscape('?action=admin;area=packages;pgdownload;auto;package=%package%;' . $context['session_var'] . '=' . $context['session_id']), ' + sUpdateNotificationLink: elk_scripturl + ', JavaScriptEscape('?action=admin;area=packageservers;sa=download;auto;package=%package%;' . $context['session_var'] . '=' . $context['session_id']), ' }); // ]]>'; diff --git a/themes/default/languages/Admin.english.php b/themes/default/languages/Admin.english.php index b25f9cab13..676b439404 100644 --- a/themes/default/languages/Admin.english.php +++ b/themes/default/languages/Admin.english.php @@ -719,6 +719,7 @@ $txt['installed_packages'] = 'Installed Packages'; $txt['package_file_perms'] = 'File Permissions'; $txt['package_settings'] = 'Settings'; +$txt['package_servers'] = 'Package Servers'; $txt['themeadmin_admin_title'] = 'Manage and Install'; $txt['themeadmin_list_title'] = 'Theme Settings'; $txt['themeadmin_reset_title'] = 'Member Options'; diff --git a/themes/default/languages/Packages.english.php b/themes/default/languages/Packages.english.php index 1afca27d06..71c2da16f9 100644 --- a/themes/default/languages/Packages.english.php +++ b/themes/default/languages/Packages.english.php @@ -13,7 +13,6 @@ $txt['list_file'] = 'List files in package'; $txt['files_archive'] = 'Files in archive'; $txt['package_get'] = 'Package Get'; -$txt['package_servers'] = 'Package servers'; $txt['package_browse'] = 'Browse'; $txt['add_server'] = 'Add server'; $txt['server_name'] = 'Server name'; From a6906b63e4b25b76da6f0c4184ea0939f4e34d1b Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 10:12:18 +0300 Subject: [PATCH 14/23] Clean up redundant menu sections. Signed-off-by: Norv --- sources/admin/PackageServers.php | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/sources/admin/PackageServers.php b/sources/admin/PackageServers.php index 2cc78fb45c..303b231553 100644 --- a/sources/admin/PackageServers.php +++ b/sources/admin/PackageServers.php @@ -13,7 +13,8 @@ * * @version 1.0 Alpha * - * This file handles the package servers and packages download from Package Manager. + * This file handles the package servers and packages download, in Package Servers + * area of admininstration panel. * */ @@ -77,24 +78,12 @@ public function action_index() // Now create the tabs for the template. $context[$context['admin_menu_name']]['tab_data'] = array( - 'title' => $txt['package_manager'], - //'help' => 'registrations', + 'title' => $txt['package_servers'], 'description' => $txt['package_manager_desc'], 'tabs' => array( - 'browse' => array( - ), 'servers' => array( 'description' => $txt['download_packages_desc'], ), - 'installed' => array( - 'description' => $txt['installed_packages_desc'], - ), - 'perms' => array( - 'description' => $txt['package_file_perms_desc'], - ), - 'options' => array( - 'description' => $txt['package_install_options_ftp_why'], - ), ), ); From c09addbb4d0005e24d692372e14ef910977b1940 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 10:24:56 +0300 Subject: [PATCH 15/23] Make list_getPackages() a method. Missed string in package servers. Signed-off-by: Norv --- sources/admin/PackageServers.php | 2 +- sources/admin/Packages.php | 448 +++++++++++++++---------------- 2 files changed, 225 insertions(+), 225 deletions(-) diff --git a/sources/admin/PackageServers.php b/sources/admin/PackageServers.php index 303b231553..c3bf1c1454 100644 --- a/sources/admin/PackageServers.php +++ b/sources/admin/PackageServers.php @@ -49,7 +49,7 @@ public function action_index() // Use the PackageServers template. loadTemplate('PackageServers', 'admin'); - $context['page_title'] = $txt['package']; + $context['page_title'] = $txt['package_servers']; // Here is a list of all the potentially valid actions. $subActions = array( diff --git a/sources/admin/Packages.php b/sources/admin/Packages.php index 2e4bc426ac..7a19dad6e3 100644 --- a/sources/admin/Packages.php +++ b/sources/admin/Packages.php @@ -1266,7 +1266,7 @@ public function action_browse() 'title' => $installed ? $txt['view_and_remove'] : $txt[$type . '_package'], 'no_items_label' => $txt['no_packages'], 'get_items' => array( - 'function' => 'list_getPackages', + 'function' => array($this, 'list_getPackages'), 'params' => array('type' => $type, 'installed' => $installed), ), 'base_href' => $scripturl . '?action=admin;area=packages;sa=' . $context['sub_action'] . ';type=' . $type, @@ -2075,283 +2075,283 @@ function build_special_files__recursive($path, &$data) // If we're here we are done! redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(serialize($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']); } -} - -/** - * Get a listing of all the packages - * Determines if the package is a mod, avatar, language package - * Determines if the package has been installed or not - * - * @param int $start - * @param int $items_per_page - * @param string $sort - * @param array $params - * @param bool $installed - * @return type - */ -function list_getPackages($start, $items_per_page, $sort, $params, $installed) -{ - global $scripturl, $context, $forum_version; - static $instmods, $packages; - - // Start things up - if (!isset($packages[$params])) - $packages[$params] = array(); - // We need the packages directory to be writable for this. - if (!@is_writable(BOARDDIR . '/packages')) - create_chmod_control(array(BOARDDIR . '/packages'), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true)); - - list($the_brand, $the_version) = explode(' ', $forum_version, 2); - - // Here we have a little code to help those who class themselves as something of gods, version emulation ;) - if (isset($_GET['version_emulate']) && strtr($_GET['version_emulate'], array($the_brand => '')) == $the_version) - { - unset($_SESSION['version_emulate']); - } - elseif (isset($_GET['version_emulate'])) + /** + * Get a listing of all the packages + * Determines if the package is a mod, avatar, language package + * Determines if the package has been installed or not + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param array $params + * @param bool $installed + * @return type + */ + function list_getPackages($start, $items_per_page, $sort, $params, $installed) { - if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate'])) - unset($_SESSION['version_emulate']); - elseif ($_GET['version_emulate'] !== 0) - $_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', $the_brand . ' ' => '')); - } + global $scripturl, $context, $forum_version; + static $instmods, $packages; - if (!empty($_SESSION['version_emulate'])) - { - $context['forum_version'] = $the_brand . ' ' . $_SESSION['version_emulate']; - $the_version = $_SESSION['version_emulate']; - } + // Start things up + if (!isset($packages[$params])) + $packages[$params] = array(); - if (isset($_SESSION['single_version_emulate'])) - unset($_SESSION['single_version_emulate']); + // We need the packages directory to be writable for this. + if (!@is_writable(BOARDDIR . '/packages')) + create_chmod_control(array(BOARDDIR . '/packages'), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true)); - if (empty($instmods)) - { - $instmods = loadInstalledPackages(); - $installed_mods = array(); - - // Look through the list of installed mods... - foreach ($instmods as $installed_mod) - $installed_mods[$installed_mod['package_id']] = array( - 'id' => $installed_mod['id'], - 'version' => $installed_mod['version'], - ); + list($the_brand, $the_version) = explode(' ', $forum_version, 2); - // Get a list of all the ids installed, so the latest packages won't include already installed ones. - $context['installed_mods'] = array_keys($installed_mods); - } + // Here we have a little code to help those who class themselves as something of gods, version emulation ;) + if (isset($_GET['version_emulate']) && strtr($_GET['version_emulate'], array($the_brand => '')) == $the_version) + { + unset($_SESSION['version_emulate']); + } + elseif (isset($_GET['version_emulate'])) + { + if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate'])) + unset($_SESSION['version_emulate']); + elseif ($_GET['version_emulate'] !== 0) + $_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', $the_brand . ' ' => '')); + } - if ($installed) - { - $sort_id = 1; - foreach ($instmods as $installed_mod) + if (!empty($_SESSION['version_emulate'])) { - $context['available_modification'][$installed_mod['package_id']] = array( - 'sort_id' => $sort_id++, - 'can_uninstall' => true, - 'name' => $installed_mod['name'], - 'filename' => $installed_mod['filename'], - 'installed_id' => $installed_mod['id'], - 'version' => $installed_mod['version'], - 'is_installed' => true, - 'is_current' => true, - ); + $context['forum_version'] = $the_brand . ' ' . $_SESSION['version_emulate']; + $the_version = $_SESSION['version_emulate']; } - } - if (empty($packages)) - foreach ($context['modification_types'] as $type) - $packages[$type] = array(); + if (isset($_SESSION['single_version_emulate'])) + unset($_SESSION['single_version_emulate']); - if ($dir = @opendir(BOARDDIR . '/packages')) - { - $dirs = array(); - $sort_id = array( - 'mod' => 1, - 'modification' => 1, - 'avatar' => 1, - 'language' => 1, - 'unknown' => 1, - ); - while ($package = readdir($dir)) + if (empty($instmods)) { - if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir(BOARDDIR . '/packages/' . $package) && file_exists(BOARDDIR . '/packages/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) - continue; - - $skip = false; - foreach ($context['modification_types'] as $type) - if (isset($context['available_' . $type][md5($package)])) - $skip = true; + $instmods = loadInstalledPackages(); + $installed_mods = array(); + + // Look through the list of installed mods... + foreach ($instmods as $installed_mod) + $installed_mods[$installed_mod['package_id']] = array( + 'id' => $installed_mod['id'], + 'version' => $installed_mod['version'], + ); - if ($skip) - continue; + // Get a list of all the ids installed, so the latest packages won't include already installed ones. + $context['installed_mods'] = array_keys($installed_mods); + } - // Skip directories or files that are named the same. - if (is_dir(BOARDDIR . '/packages/' . $package)) + if ($installed) + { + $sort_id = 1; + foreach ($instmods as $installed_mod) { - if (in_array($package, $dirs)) - continue; - $dirs[] = $package; + $context['available_modification'][$installed_mod['package_id']] = array( + 'sort_id' => $sort_id++, + 'can_uninstall' => true, + 'name' => $installed_mod['name'], + 'filename' => $installed_mod['filename'], + 'installed_id' => $installed_mod['id'], + 'version' => $installed_mod['version'], + 'is_installed' => true, + 'is_current' => true, + ); } - elseif (substr(strtolower($package), -7) == '.tar.gz') + } + + if (empty($packages)) + foreach ($context['modification_types'] as $type) + $packages[$type] = array(); + + if ($dir = @opendir(BOARDDIR . '/packages')) + { + $dirs = array(); + $sort_id = array( + 'mod' => 1, + 'modification' => 1, + 'avatar' => 1, + 'language' => 1, + 'unknown' => 1, + ); + while ($package = readdir($dir)) { - if (in_array(substr($package, 0, -7), $dirs)) + if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir(BOARDDIR . '/packages/' . $package) && file_exists(BOARDDIR . '/packages/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) continue; - $dirs[] = substr($package, 0, -7); - } - elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz') - { - if (in_array(substr($package, 0, -4), $dirs)) + + $skip = false; + foreach ($context['modification_types'] as $type) + if (isset($context['available_' . $type][md5($package)])) + $skip = true; + + if ($skip) continue; - $dirs[] = substr($package, 0, -4); - } - $packageInfo = getPackageInfo($package); - if (!is_array($packageInfo)) - continue; + // Skip directories or files that are named the same. + if (is_dir(BOARDDIR . '/packages/' . $package)) + { + if (in_array($package, $dirs)) + continue; + $dirs[] = $package; + } + elseif (substr(strtolower($package), -7) == '.tar.gz') + { + if (in_array(substr($package, 0, -7), $dirs)) + continue; + $dirs[] = substr($package, 0, -7); + } + elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz') + { + if (in_array(substr($package, 0, -4), $dirs)) + continue; + $dirs[] = substr($package, 0, -4); + } - if (!empty($packageInfo)) - { - $packageInfo['installed_id'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['id'] : 0; - $packageInfo['sort_id'] = $sort_id[$packageInfo['type']]; - $packageInfo['is_installed'] = isset($installed_mods[$packageInfo['id']]); - $packageInfo['is_current'] = $packageInfo['is_installed'] && ($installed_mods[$packageInfo['id']]['version'] == $packageInfo['version']); - $packageInfo['is_newer'] = $packageInfo['is_installed'] && ($installed_mods[$packageInfo['id']]['version'] > $packageInfo['version']); - $packageInfo['can_install'] = false; - $packageInfo['can_uninstall'] = false; - $packageInfo['can_upgrade'] = false; - $packageInfo['can_emulate_install'] = false; - $packageInfo['can_emulate_uninstall'] = false; - - // This package is currently NOT installed. Check if it can be. - if (!$packageInfo['is_installed'] && $packageInfo['xml']->exists('install')) + $packageInfo = getPackageInfo($package); + if (!is_array($packageInfo)) + continue; + + if (!empty($packageInfo)) { - // Check if there's an install for *THIS* version - $installs = $packageInfo['xml']->set('install'); - foreach ($installs as $install) + $packageInfo['installed_id'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['id'] : 0; + $packageInfo['sort_id'] = $sort_id[$packageInfo['type']]; + $packageInfo['is_installed'] = isset($installed_mods[$packageInfo['id']]); + $packageInfo['is_current'] = $packageInfo['is_installed'] && ($installed_mods[$packageInfo['id']]['version'] == $packageInfo['version']); + $packageInfo['is_newer'] = $packageInfo['is_installed'] && ($installed_mods[$packageInfo['id']]['version'] > $packageInfo['version']); + $packageInfo['can_install'] = false; + $packageInfo['can_uninstall'] = false; + $packageInfo['can_upgrade'] = false; + $packageInfo['can_emulate_install'] = false; + $packageInfo['can_emulate_uninstall'] = false; + + // This package is currently NOT installed. Check if it can be. + if (!$packageInfo['is_installed'] && $packageInfo['xml']->exists('install')) { - if (!$install->exists('@for') || matchPackageVersion($the_version, $install->fetch('@for'))) + // Check if there's an install for *THIS* version + $installs = $packageInfo['xml']->set('install'); + foreach ($installs as $install) { - // Okay, this one is good to go. - $packageInfo['can_install'] = true; - break; + if (!$install->exists('@for') || matchPackageVersion($the_version, $install->fetch('@for'))) + { + // Okay, this one is good to go. + $packageInfo['can_install'] = true; + break; + } } - } - - // no install found for our version, lets see if one exists for another - if ($packageInfo['can_install'] === false && $install->exists('@for') && empty($_SESSION['version_emulate'])) - { - $reset = true; - // Get the highest install version that is available from the package - foreach ($installs as $install) + // no install found for our version, lets see if one exists for another + if ($packageInfo['can_install'] === false && $install->exists('@for') && empty($_SESSION['version_emulate'])) { - $packageInfo['can_emulate_install'] = matchHighestPackageVersion($install->fetch('@for'), $reset, $the_version); - $reset = false; - } - } - } - // An already installed, but old, package. Can we upgrade it? - elseif ($packageInfo['is_installed'] && !$packageInfo['is_current'] && $packageInfo['xml']->exists('upgrade')) - { - $upgrades = $packageInfo['xml']->set('upgrade'); + $reset = true; - // First go through, and check against the current version of ElkArte. - foreach ($upgrades as $upgrade) - { - // Even if it is for this ElkArte, is it for the installed version of the mod? - if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for'))) - if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from'))) + // Get the highest install version that is available from the package + foreach ($installs as $install) { - $packageInfo['can_upgrade'] = true; - break; + $packageInfo['can_emulate_install'] = matchHighestPackageVersion($install->fetch('@for'), $reset, $the_version); + $reset = false; } + } } - } - // Note that it has to be the current version to be uninstallable. Shucks. - elseif ($packageInfo['is_installed'] && $packageInfo['is_current'] && $packageInfo['xml']->exists('uninstall')) - { - $uninstalls = $packageInfo['xml']->set('uninstall'); - - // Can we find any uninstallation methods that work for this ElkArte version? - foreach ($uninstalls as $uninstall) + // An already installed, but old, package. Can we upgrade it? + elseif ($packageInfo['is_installed'] && !$packageInfo['is_current'] && $packageInfo['xml']->exists('upgrade')) { - if (!$uninstall->exists('@for') || matchPackageVersion($the_version, $uninstall->fetch('@for'))) + $upgrades = $packageInfo['xml']->set('upgrade'); + + // First go through, and check against the current version of ElkArte. + foreach ($upgrades as $upgrade) { - $packageInfo['can_uninstall'] = true; - break; + // Even if it is for this ElkArte, is it for the installed version of the mod? + if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for'))) + if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from'))) + { + $packageInfo['can_upgrade'] = true; + break; + } } } - - // no uninstall found for this version, lets see if one exists for another - if ($packageInfo['can_uninstall'] === false && $uninstall->exists('@for') && empty($_SESSION['version_emulate'])) + // Note that it has to be the current version to be uninstallable. Shucks. + elseif ($packageInfo['is_installed'] && $packageInfo['is_current'] && $packageInfo['xml']->exists('uninstall')) { - $reset = true; + $uninstalls = $packageInfo['xml']->set('uninstall'); - // Get the highest install version that is available from the package + // Can we find any uninstallation methods that work for this ElkArte version? foreach ($uninstalls as $uninstall) { - $packageInfo['can_emulate_uninstall'] = matchHighestPackageVersion($uninstall->fetch('@for'), $reset, $the_version); - $reset = false; + if (!$uninstall->exists('@for') || matchPackageVersion($the_version, $uninstall->fetch('@for'))) + { + $packageInfo['can_uninstall'] = true; + break; + } + } + + // no uninstall found for this version, lets see if one exists for another + if ($packageInfo['can_uninstall'] === false && $uninstall->exists('@for') && empty($_SESSION['version_emulate'])) + { + $reset = true; + + // Get the highest install version that is available from the package + foreach ($uninstalls as $uninstall) + { + $packageInfo['can_emulate_uninstall'] = matchHighestPackageVersion($uninstall->fetch('@for'), $reset, $the_version); + $reset = false; + } } } - } - // Modification. - if ($packageInfo['type'] == 'modification' || $packageInfo['type'] == 'mod') - { - $sort_id['modification']++; - $sort_id['mod']++; - if ($installed) + // Modification. + if ($packageInfo['type'] == 'modification' || $packageInfo['type'] == 'mod') { - if (!empty($context['available_modification'][$packageInfo['id']])) + $sort_id['modification']++; + $sort_id['mod']++; + if ($installed) { - $packages['modification'][strtolower($packageInfo[$sort]) . '_' . $sort_id['mod']] = $packageInfo['id']; - $context['available_modification'][$packageInfo['id']] = array_merge($context['available_modification'][$packageInfo['id']], $packageInfo); + if (!empty($context['available_modification'][$packageInfo['id']])) + { + $packages['modification'][strtolower($packageInfo[$sort]) . '_' . $sort_id['mod']] = $packageInfo['id']; + $context['available_modification'][$packageInfo['id']] = array_merge($context['available_modification'][$packageInfo['id']], $packageInfo); + } } + else + { + $packages['modification'][strtolower($packageInfo[$sort]) . '_' . $sort_id['mod']] = md5($package); + $context['available_modification'][md5($package)] = $packageInfo; + } + } + // Avatar package. + elseif ($packageInfo['type'] == 'avatar') + { + $sort_id[$packageInfo['type']]++; + $packages['avatar'][strtolower($packageInfo[$sort])] = md5($package); + $context['available_avatar'][md5($package)] = $packageInfo; + } + // Language package. + elseif ($packageInfo['type'] == 'language') + { + $sort_id[$packageInfo['type']]++; + $packages['language'][strtolower($packageInfo[$sort])] = md5($package); + $context['available_language'][md5($package)] = $packageInfo; } + // Other stuff. else { - $packages['modification'][strtolower($packageInfo[$sort]) . '_' . $sort_id['mod']] = md5($package); - $context['available_modification'][md5($package)] = $packageInfo; + $sort_id['unknown']++; + $packages['unknown'][strtolower($packageInfo[$sort])] = md5($package); + $context['available_unknown'][md5($package)] = $packageInfo; } } - // Avatar package. - elseif ($packageInfo['type'] == 'avatar') - { - $sort_id[$packageInfo['type']]++; - $packages['avatar'][strtolower($packageInfo[$sort])] = md5($package); - $context['available_avatar'][md5($package)] = $packageInfo; - } - // Language package. - elseif ($packageInfo['type'] == 'language') - { - $sort_id[$packageInfo['type']]++; - $packages['language'][strtolower($packageInfo[$sort])] = md5($package); - $context['available_language'][md5($package)] = $packageInfo; - } - // Other stuff. - else - { - $sort_id['unknown']++; - $packages['unknown'][strtolower($packageInfo[$sort])] = md5($package); - $context['available_unknown'][md5($package)] = $packageInfo; - } } + closedir($dir); } - closedir($dir); - } - if (isset($_GET['type']) && $_GET['type'] == $params) - { - if (isset($_GET['desc'])) - krsort($packages[$params]); - else - ksort($packages[$params]); - } + if (isset($_GET['type']) && $_GET['type'] == $params) + { + if (isset($_GET['desc'])) + krsort($packages[$params]); + else + ksort($packages[$params]); + } - return $packages[$params]; + return $packages[$params]; + } } /** From 84b0c03ff676af2d8506e48af51fa06137309e47 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 10:26:22 +0300 Subject: [PATCH 16/23] Remove unused method InstalledList() (old leftover from createList()) Signed-off-by: Norv --- sources/admin/Packages.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/sources/admin/Packages.php b/sources/admin/Packages.php index 7a19dad6e3..74939bd14e 100644 --- a/sources/admin/Packages.php +++ b/sources/admin/Packages.php @@ -1178,21 +1178,6 @@ public function action_examine() } } - /** - * List the installed packages. - */ - public function InstalledList() - { - global $txt, $context; - - // @todo this isn't used, why - $context['page_title'] .= ' - ' . $txt['installed_packages']; - $context['sub_template'] = 'view_installed'; - - // Load the installed mods and send them to the template. - $context['installed_mods'] = loadInstalledPackages(); - } - /** * Empty out the installed list. */ From 403511f443ae5cfce680e1c34f976dd4b2b20879 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 10:27:58 +0300 Subject: [PATCH 17/23] Rename list method list_packages Signed-off-by: Norv --- sources/admin/Packages.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/admin/Packages.php b/sources/admin/Packages.php index 74939bd14e..7916ea0003 100644 --- a/sources/admin/Packages.php +++ b/sources/admin/Packages.php @@ -1251,7 +1251,7 @@ public function action_browse() 'title' => $installed ? $txt['view_and_remove'] : $txt[$type . '_package'], 'no_items_label' => $txt['no_packages'], 'get_items' => array( - 'function' => array($this, 'list_getPackages'), + 'function' => array($this, 'list_packages'), 'params' => array('type' => $type, 'installed' => $installed), ), 'base_href' => $scripturl . '?action=admin;area=packages;sa=' . $context['sub_action'] . ';type=' . $type, @@ -2073,7 +2073,7 @@ function build_special_files__recursive($path, &$data) * @param bool $installed * @return type */ - function list_getPackages($start, $items_per_page, $sort, $params, $installed) + function list_packages($start, $items_per_page, $sort, $params, $installed) { global $scripturl, $context, $forum_version; static $instmods, $packages; From 485539b941f4ee067c8723334abc2a135ca94d10 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 10:34:57 +0300 Subject: [PATCH 18/23] Fix leftover links to area=packageservers Signed-off-by: Norv --- themes/default/PackageServers.template.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/themes/default/PackageServers.template.php b/themes/default/PackageServers.template.php index a005518a90..92c576ceb3 100644 --- a/themes/default/PackageServers.template.php +++ b/themes/default/PackageServers.template.php @@ -45,7 +45,7 @@ function template_servers()

', $txt['package_ftp_why_download'], '

-
+
@@ -91,15 +91,15 @@ function template_servers() echo '
  • ' . $server['name'] . ' - [ ' . $txt['delete'] . ' ] - [ ' . $txt['package_browse'] . ' ] + [ ' . $txt['delete'] . ' ] + [ ' . $txt['package_browse'] . ' ]
  • '; echo '
    ' . $txt['add_server'] . ' - +
    ' . $txt['server_name'] . ': @@ -122,7 +122,7 @@ function template_servers()
    ', $txt['package_download_by_url'], ' - +
    ' . $txt['serverurl'] . ': @@ -151,7 +151,7 @@ function template_servers()
    - +
    ' . $txt['package_upload_select'] . ': @@ -384,7 +384,7 @@ function template_downloaded()

    -

    [ ', $txt['back'], ' ]

    +

    [ ', $txt['back'], ' ]

    '; From 02db579455773bcab48fc1f19b57ddaf05dced2d Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 10:39:27 +0300 Subject: [PATCH 19/23] Quick rename: why package upload would be mapped to action_update()? (!) Signed-off-by: Norv --- sources/admin/PackageServers.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/admin/PackageServers.php b/sources/admin/PackageServers.php index c3bf1c1454..e125b4642e 100644 --- a/sources/admin/PackageServers.php +++ b/sources/admin/PackageServers.php @@ -58,7 +58,7 @@ public function action_index() 'browse' => array($this, 'action_browse'), 'download' => array($this, 'action_download'), 'remove' => array($this, 'action_remove'), - 'upload' => array($this, 'action_update'), + 'upload' => array($this, 'action_upload'), ); // Now let's decide where we are taking this... @@ -603,7 +603,7 @@ public function action_download() /** * Upload a new package to the directory. */ - public function action_update() + public function action_upload() { global $txt, $scripturl, $context; From a5e76664b743f70e1488d2da2e8224e962bc0147 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 11:09:06 +0300 Subject: [PATCH 20/23] Split ftp_connect() into a little method of its own. We will need it again if we make two or more tabs for which we want it. Document the code. Signed-off-by: Norv --- sources/admin/PackageServers.php | 186 +++++++++++++++++++------------ sources/admin/Packages.php | 1 - 2 files changed, 113 insertions(+), 74 deletions(-) diff --git a/sources/admin/PackageServers.php b/sources/admin/PackageServers.php index e125b4642e..6f4735bd53 100644 --- a/sources/admin/PackageServers.php +++ b/sources/admin/PackageServers.php @@ -30,6 +30,7 @@ class PackageServers_Controller extends Action_Controller /** * Main dispatcher for package servers. Checks permissions, * load files, and forwards to the right method. + * Accessed by action=admin;area=packageservers * * @see Action_Controller::action_index() */ @@ -73,9 +74,6 @@ public function action_index() $context['sub_action'] = $subAction; - // We need to force the "Download" tab as selected. - $context['menu_data_' . $context['admin_menu_id']]['current_subsection'] = 'servers'; - // Now create the tabs for the template. $context[$context['admin_menu_name']]['tab_data'] = array( 'title' => $txt['package_servers'], @@ -93,6 +91,7 @@ public function action_index() /** * Load a list of package servers. + * Accessed by action=admin;area=packageservers;sa=servers */ public function action_list() { @@ -106,81 +105,26 @@ public function action_list() // Load the list of servers. $context['servers'] = fetchPackageServers(); - $context['package_download_broken'] = !is_writable(BOARDDIR . '/packages') || !is_writable(BOARDDIR . '/packages/installed.list'); - - if ($context['package_download_broken']) - { - @chmod(BOARDDIR . '/packages', 0777); - @chmod(BOARDDIR . '/packages/installed.list', 0777); - } + // Check if we will be able to write new archives in /packages folder. $context['package_download_broken'] = !is_writable(BOARDDIR . '/packages') || !is_writable(BOARDDIR . '/packages/installed.list'); if ($context['package_download_broken']) - { - if (isset($_POST['ftp_username'])) - { - require_once(SUBSDIR . '/FTPConnection.class.php'); - $ftp = new Ftp_Connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']); - - if ($ftp->error === false) - { - // I know, I know... but a lot of people want to type /home/xyz/... which is wrong, but logical. - if (!$ftp->chdir($_POST['ftp_path'])) - { - $ftp_error = $ftp->error; - $ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $_POST['ftp_path'])); - } - } - } - - if (!isset($ftp) || $ftp->error !== false) - { - if (!isset($ftp)) - { - require_once(SUBSDIR . '/FTPConnection.class.php'); - $ftp = new Ftp_Connection(null); - } - elseif ($ftp->error !== false && !isset($ftp_error)) - $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; - - list ($username, $detect_path, $found_path) = $ftp->detect_path(BOARDDIR); - - if ($found_path || !isset($_POST['ftp_path'])) - $_POST['ftp_path'] = $detect_path; - - if (!isset($_POST['ftp_username'])) - $_POST['ftp_username'] = $username; - - $context['package_ftp'] = array( - 'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'), - 'port' => isset($_POST['ftp_port']) ? $_POST['ftp_port'] : (isset($modSettings['package_port']) ? $modSettings['package_port'] : '21'), - 'username' => isset($_POST['ftp_username']) ? $_POST['ftp_username'] : (isset($modSettings['package_username']) ? $modSettings['package_username'] : ''), - 'path' => $_POST['ftp_path'], - 'error' => empty($ftp_error) ? null : $ftp_error, - ); - } - else - { - $context['package_download_broken'] = false; - - $ftp->chmod('packages', 0777); - $ftp->chmod('packages/installed.list', 0777); - - $ftp->close(); - } - } + $this->ftp_connect(); } /** * Browse a server's list of packages. + * Accessed by action=admin;area=packageservers;sa=browse */ public function action_browse() { global $txt, $context, $scripturl, $forum_version, $context; + // Load our subs worker. require_once(SUBSDIR . '/PackageServers.subs.php'); + // Browsing the packages from a server if (isset($_GET['server'])) { if ($_GET['server'] == '') @@ -206,7 +150,7 @@ public function action_browse() } elseif (isset($_GET['absolute']) && $_GET['absolute'] != '') { - // Initialize the requried variables. + // Initialize the required variables. $server = ''; $url = $_GET['absolute']; $name = ''; @@ -268,6 +212,8 @@ public function action_browse() // By default we use an unordered list, unless there are no lists with more than one package. $context['list_type'] = 'ul'; + // Load the installed packages + // We'll figure out if what they select a package they already have installed. $instmods = loadInstalledPackages(); $installed_mods = array(); @@ -394,6 +340,7 @@ public function action_browse() $package['download']['href'] = $scripturl . '?action=admin;area=packageservers;sa=download' . $server_att . ';package=' . $current_url . $package['filename'] . ($package['download_conflict'] ? ';conflict' : '') . ';' . $context['session_var'] . '=' . $context['session_id']; $package['download']['link'] = '' . $package['name'] . ''; + // Author name, email if ($thisPackage->exists('author') || isset($default_author)) { if ($thisPackage->exists('author/@email')) @@ -414,6 +361,7 @@ public function action_browse() } } + // Author website if ($thisPackage->exists('website') || isset($default_website)) { if ($thisPackage->exists('website') && $thisPackage->exists('website/@title')) @@ -426,22 +374,22 @@ public function action_browse() $package['author']['website']['name'] = $default_website; if ($thisPackage->exists('website') && $thisPackage->fetch('website') != '') - $authorhompage = $thisPackage->fetch('website'); + $authorhomepage = $thisPackage->fetch('website'); else - $authorhompage = $default_website; + $authorhomepage = $default_website; - if (stripos($authorhompage, 'a href') === false) + if (stripos($authorhomepage, 'a href') === false) { - $package['author']['website']['href'] = $authorhompage; - $package['author']['website']['link'] = '' . $package['author']['website']['name'] . ''; + $package['author']['website']['href'] = $authorhomepage; + $package['author']['website']['link'] = '' . $package['author']['website']['name'] . ''; } else { - if (preg_match('/a href="(.+?)"/', $authorhompage, $match) == 1) + if (preg_match('/a href="(.+?)"/', $authorhomepage, $match) == 1) $package['author']['website']['href'] = $match[1]; else $package['author']['website']['href'] = ''; - $package['author']['website']['link'] = $authorhompage; + $package['author']['website']['link'] = $authorhomepage; } } else @@ -500,6 +448,7 @@ public function action_browse() /** * Download a package. + * Accessed by action=admin;area=packageservers;sa=download */ public function action_download() { @@ -533,7 +482,7 @@ public function action_download() } else { - // Initialize the requried variables. + // Initialize the required variables. $server = ''; $url = ''; } @@ -601,7 +550,8 @@ public function action_download() } /** - * Upload a new package to the directory. + * Upload a new package to the packages directory. + * Accessed by action=admin;area=packageservers;sa=upload */ public function action_upload() { @@ -657,10 +607,12 @@ public function action_upload() if ($package == '.' || $package == '..' || $package == 'temp' || $package == $packageName || (!(is_dir(BOARDDIR . '/packages/' . $package) && file_exists(BOARDDIR . '/packages/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) continue; + // Read package info for the archive we found $packageInfo = getPackageInfo($package); if (!is_array($packageInfo)) continue; + // If it was already uploaded, don't upload it again. if ($packageInfo['id'] == $context['package']['id'] && $packageInfo['version'] == $context['package']['version']) { @unlink($destination); @@ -689,10 +641,13 @@ public function action_upload() /** * Add a package server to the list. + * Accessed by action=admin;area=packageservers;sa=add */ public function action_add() { + // Load our subs file. require_once(SUBSDIR . '/PackageServers.subs.php'); + // Validate the user. checkSession(); @@ -708,6 +663,7 @@ public function action_add() if (strpos($serverurl, 'http://') !== 0 && strpos($serverurl, 'https://') !== 0) $serverurl = 'http://' . $serverurl; + // Add it to the list of package servers. addPackageServer($servername, $serverurl); redirectexit('action=admin;area=packageservers'); @@ -715,6 +671,7 @@ public function action_add() /** * Remove a server from the list. + * Accessed by action=admin;area=packageservers;sa=remove */ public function action_remove() { @@ -722,9 +679,92 @@ public function action_remove() require_once(SUBSDIR . '/PackageServer.subs.php'); + // We no longer browse this server. $_GET['server'] = (int) $_GET['server']; deletePackageServer($_GET['server']); redirectexit('action=admin;area=packageservers'); } + + /** + * This method attempts to chmod packages and installed.list + * using FTP if necessary. + * It sets the $context['package_download_broken'] status for the template. + * Used by package servers pages. + */ + public function ftp_connect() + { + global $context; + + // Try to chmod from PHP first + @chmod(BOARDDIR . '/packages', 0777); + @chmod(BOARDDIR . '/packages/installed.list', 0777); + + $unwritable = !is_writable(BOARDDIR . '/packages') || !is_writable(BOARDDIR . '/packages/installed.list'); + + if ($unwritable) + { + // Are they connecting to their FTP account already? + if (isset($_POST['ftp_username'])) + { + require_once(SUBSDIR . '/FTPConnection.class.php'); + $ftp = new Ftp_Connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']); + + if ($ftp->error === false) + { + // I know, I know... but a lot of people want to type /home/xyz/... which is wrong, but logical. + if (!$ftp->chdir($_POST['ftp_path'])) + { + $ftp_error = $ftp->error; + $ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $_POST['ftp_path'])); + } + } + } + + // No attempt yet, or we had an error last time + if (!isset($ftp) || $ftp->error !== false) + { + // Maybe we didn't even try yet + if (!isset($ftp)) + { + require_once(SUBSDIR . '/FTPConnection.class.php'); + $ftp = new Ftp_Connection(null); + } + // ...or we failed + elseif ($ftp->error !== false && !isset($ftp_error)) + $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; + + list ($username, $detect_path, $found_path) = $ftp->detect_path(BOARDDIR); + + if ($found_path || !isset($_POST['ftp_path'])) + $_POST['ftp_path'] = $detect_path; + + if (!isset($_POST['ftp_username'])) + $_POST['ftp_username'] = $username; + + // Fill the boxes for a FTP connection with data from the previous attempt too, if any + $context['package_ftp'] = array( + 'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'), + 'port' => isset($_POST['ftp_port']) ? $_POST['ftp_port'] : (isset($modSettings['package_port']) ? $modSettings['package_port'] : '21'), + 'username' => isset($_POST['ftp_username']) ? $_POST['ftp_username'] : (isset($modSettings['package_username']) ? $modSettings['package_username'] : ''), + 'path' => $_POST['ftp_path'], + 'error' => empty($ftp_error) ? null : $ftp_error, + ); + + // Announce the template it's time to display the ftp connection box. + $context['package_download_broken'] = true; + } + else + { + // FTP connection has succeeded + $context['package_download_broken'] = false; + + // Try to chmod packages folder and our list file. + $ftp->chmod('packages', 0777); + $ftp->chmod('packages/installed.list', 0777); + + $ftp->close(); + } + } + } } \ No newline at end of file diff --git a/sources/admin/Packages.php b/sources/admin/Packages.php index 7916ea0003..1b6a253bd4 100644 --- a/sources/admin/Packages.php +++ b/sources/admin/Packages.php @@ -77,7 +77,6 @@ public function action_index() // Set up some tabs... $context[$context['admin_menu_name']]['tab_data'] = array( 'title' => $txt['package_manager'], - // @todo 'help' => 'registrations', 'description' => $txt['package_manager_desc'], 'tabs' => array( 'browse' => array( From 320a93de8a8bc889ab21ec0ca9652297bfdebaa8 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 11:34:33 +0300 Subject: [PATCH 21/23] Wrong syntax for fetchPackageServers() query. Signed-off-by: Norv --- sources/subs/PackageServers.subs.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sources/subs/PackageServers.subs.php b/sources/subs/PackageServers.subs.php index ee59421e4a..a6577a06ac 100644 --- a/sources/subs/PackageServers.subs.php +++ b/sources/subs/PackageServers.subs.php @@ -21,19 +21,19 @@ function fetchPackageServers($server = null) { $db = database(); - + $servers = array(); // Load the list of servers. $request = $db->query('', ' SELECT id_server, name, url FROM {db_prefix}package_servers' . - (!empty($server) ? 'WHERE id_server = {int:current_server}' : ''), + (!empty($server) ? ' WHERE id_server = {int:current_server}' : ''), array( 'current_server' => $server, ) ); - + while ($row = $db->fetch_assoc($request)) { $servers[] = array( From c146fc8f8bb572d19efc4f03f491e4f8736d6195 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 12:48:07 +0300 Subject: [PATCH 22/23] Split the upload form from package servers page, to a second tab of the area. Signed-off-by: Norv --- sources/admin/Admin.php | 3 +- sources/admin/PackageServers.php | 29 ++- themes/default/PackageServers.template.php | 172 +++++++++++------- themes/default/languages/Admin.english.php | 1 + themes/default/languages/Packages.english.php | 9 +- 5 files changed, 139 insertions(+), 75 deletions(-) diff --git a/sources/admin/Admin.php b/sources/admin/Admin.php index 93468eaf4b..9f9f8404a8 100644 --- a/sources/admin/Admin.php +++ b/sources/admin/Admin.php @@ -124,7 +124,8 @@ public function action_index() 'icon' => 'transparent.png', 'class' => 'admin_img_packages', 'subsections' => array( - 'servers' => array($txt['download_packages'], 'url' => $scripturl . '?action=admin;area=packageservers'), + 'servers' => array($txt['download_packages']), + 'upload' => array($txt['upload_packages']), ), ), 'search' => array( diff --git a/sources/admin/PackageServers.php b/sources/admin/PackageServers.php index 6f4735bd53..7e56bf4bb4 100644 --- a/sources/admin/PackageServers.php +++ b/sources/admin/PackageServers.php @@ -60,6 +60,7 @@ public function action_index() 'download' => array($this, 'action_download'), 'remove' => array($this, 'action_remove'), 'upload' => array($this, 'action_upload'), + 'upload2' => array($this, 'action_upload2'), ); // Now let's decide where we are taking this... @@ -77,11 +78,14 @@ public function action_index() // Now create the tabs for the template. $context[$context['admin_menu_name']]['tab_data'] = array( 'title' => $txt['package_servers'], - 'description' => $txt['package_manager_desc'], + 'description' => $txt['package_servers_desc'], 'tabs' => array( 'servers' => array( 'description' => $txt['download_packages_desc'], ), + 'upload' => array( + 'description' => $txt['upload_packages_desc'], + ), ), ); @@ -551,9 +555,9 @@ public function action_download() /** * Upload a new package to the packages directory. - * Accessed by action=admin;area=packageservers;sa=upload + * Accessed by action=admin;area=packageservers;sa=upload2 */ - public function action_upload() + public function action_upload2() { global $txt, $scripturl, $context; @@ -686,6 +690,25 @@ public function action_remove() redirectexit('action=admin;area=packageservers'); } + /** + * Display the upload package form. + */ + public function action_upload() + { + global $txt, $context, $modSettings; + + // Set up the upload template, and page title. + $context['sub_template'] = 'upload'; + $context['page_title'] .= ' - ' . $txt['upload_packages']; + + // Check if we will be able to write new archives in /packages folder. + $context['package_download_broken'] = !is_writable(BOARDDIR . '/packages') || !is_writable(BOARDDIR . '/packages/installed.list'); + + // Give FTP a chance... + if ($context['package_download_broken']) + $this->ftp_connect(); + } + /** * This method attempts to chmod packages and installed.list * using FTP if necessary. diff --git a/themes/default/PackageServers.template.php b/themes/default/PackageServers.template.php index 92c576ceb3..09ce5c6809 100644 --- a/themes/default/PackageServers.template.php +++ b/themes/default/PackageServers.template.php @@ -31,55 +31,10 @@ function template_servers() echo '
    -

    ', $txt['download_new_package'], '

    +

    ', $txt['package_servers'], '

    '; - if ($context['package_download_broken']) - { - echo ' -
    -

    ', $txt['package_ftp_necessary'], '

    -
    -
    -
    -

    - ', $txt['package_ftp_why_download'], ' -

    - -
    -
    - -
    -
    - - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    -
    - -
    - -
    -
    '; - } + template_ftp_required(); echo '
    @@ -87,6 +42,7 @@ function template_servers()
    ' . $txt['package_servers'] . '
      '; + foreach ($context['servers'] as $server) echo '
    • @@ -145,27 +101,6 @@ function template_servers()
    -
    -
    -

    ' . $txt['package_upload_title'] . '

    -
    -
    -
    -
    -
    -
    - ' . $txt['package_upload_select'] . ': -
    -
    - -
    -
    -
    - - -
    -
    -
    '; } @@ -365,6 +300,9 @@ function template_package_list() } } +/** + * Displays a success message for the download or upload of a package. + */ function template_downloaded() { global $context, $txt, $scripturl; @@ -388,4 +326,102 @@ function template_downloaded() '; +} + +/** + * Shows a form to upload a package from the local computer. + */ +function template_upload() +{ + global $context, $txt, $scripturl; + + if (!empty($context['package_ftp']['error'])) + echo ' +
    + ', $context['package_ftp']['error'], ' +
    '; + + echo ' +
    +
    +

    ', $txt['upload_new_package'], '

    +
    '; + + template_ftp_required(); + + echo ' +
    +

    ' . $txt['package_upload_title'] . '

    +
    +
    +
    +
    +
    +
    + ' . $txt['package_upload_select'] . ': +
    +
    + +
    +
    +
    + + +
    +
    +
    +
    '; +} + +/** + * Section of package servers tabs + * It displays a form to connect to admin's FTP account. + */ +function template_ftp_required() +{ + global $context, $txt, $scripturl; + + echo ' +
    +

    ', $txt['package_ftp_necessary'], '

    +
    +
    +
    +

    + ', $txt['package_ftp_why_download'], ' +

    +
    +
    +
    + +
    +
    + + +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    +
    + +
    +
    +
    +
    '; } \ No newline at end of file diff --git a/themes/default/languages/Admin.english.php b/themes/default/languages/Admin.english.php index 676b439404..b677f7da57 100644 --- a/themes/default/languages/Admin.english.php +++ b/themes/default/languages/Admin.english.php @@ -716,6 +716,7 @@ $txt['browse_packages'] = 'Browse Packages'; $txt['download_packages'] = 'Download Packages'; +$txt['upload_packages'] = 'Upload Package'; $txt['installed_packages'] = 'Installed Packages'; $txt['package_file_perms'] = 'File Permissions'; $txt['package_settings'] = 'Settings'; diff --git a/themes/default/languages/Packages.english.php b/themes/default/languages/Packages.english.php index 71c2da16f9..f059fd7be9 100644 --- a/themes/default/languages/Packages.english.php +++ b/themes/default/languages/Packages.english.php @@ -3,7 +3,7 @@ // Version: 1.0; Packages $txt['package_proceed'] = 'Proceed'; -$txt['php_script'] = 'Modification file was extracted, but this add-on also comes with a PHP script which should be executed before it will work'; +$txt['php_script'] = 'The add-on archive was extracted, but this add-on also comes with a PHP script which should be executed before it will work'; $txt['package_run'] = 'Run'; $txt['package_id'] = 'ID'; $txt['package_read'] = 'Read'; @@ -24,7 +24,7 @@ $txt['package_manager'] = 'Package Manager'; $txt['install_mod'] = 'Install Add-on'; $txt['uninstall_mod'] = 'Uninstall Add-on'; -$txt['sql_file'] = 'The Modification file has been extracted. This add-on also comes with a database file containing changes the database needs. You will need to execute this file for the add-on to function properly.'; +$txt['sql_file'] = 'The add-on archive has been extracted. This add-on also comes with a database file containing changes the database needs. You will need to execute this file for the add-on to function properly.'; $txt['sql_queries'] = 'SQL Queries'; $txt['no_mods_installed'] = 'No add-ons currently installed'; $txt['browse_installed'] = 'Browse installed add-ons'; @@ -36,10 +36,13 @@ $txt['package_manager_desc'] = 'From this easy to use interface, you can download and install add-ons for use on your forum.'; $txt['installed_packages_desc'] = 'You can use the interface below to view those packages currently installed on the forum, and remove the ones you no longer require.'; -$txt['download_packages_desc'] = 'From this section you can choose to either download new packages from package servers, or upload a package file directly to the forum.'; +$txt['download_packages_desc'] = 'From this section you can add or remove package servers, browse for packages, or download new packages from servers.'; +$txt['package_servers_desc'] = 'From this easy to use interface, you can manage your package servers and download add-on archives on your forum.'; +$txt['upload_packages_desc'] = 'From this section you can upload a package file from your local computer directly to the forum.'; $txt['create_package'] = 'Create a new Package'; $txt['download_new_package'] = 'Download new packages'; +$txt['upload_new_package'] = 'Upload new package'; $txt['view_and_remove'] = 'View and remove installed packages'; $txt['modification_package'] = 'Add-on packages'; $txt['avatar_package'] = 'Avatar packages'; From 691edbeba7aefdf3eee42f864fe8243abcb25288 Mon Sep 17 00:00:00 2001 From: Norv Date: Wed, 17 Jul 2013 12:51:06 +0300 Subject: [PATCH 23/23] Include the correct file. Tweak $action. Signed-off-by: Norv --- sources/admin/PackageServers.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/admin/PackageServers.php b/sources/admin/PackageServers.php index 7e56bf4bb4..c59c3e02b8 100644 --- a/sources/admin/PackageServers.php +++ b/sources/admin/PackageServers.php @@ -71,7 +71,7 @@ public function action_index() // Set up action/subaction stuff. $action = new Action(); - $action->initialize($subActions); + $action->initialize($subActions, 'servers'); $context['sub_action'] = $subAction; @@ -681,7 +681,7 @@ public function action_remove() { checkSession('get'); - require_once(SUBSDIR . '/PackageServer.subs.php'); + require_once(SUBSDIR . '/PackageServers.subs.php'); // We no longer browse this server. $_GET['server'] = (int) $_GET['server'];