From 2eb810f2f6461614a8bf11437c1b76d0148fac77 Mon Sep 17 00:00:00 2001 From: Norv Date: Fri, 21 Jun 2013 20:54:12 +0300 Subject: [PATCH 01/34] Add abstract base class Action_Controller. Signed-off-by: Norv --- sources/Action.controller.php | 40 +++++++++++++++++++++++++++++++++++ sources/Dispatcher.class.php | 15 ++++--------- 2 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 sources/Action.controller.php diff --git a/sources/Action.controller.php b/sources/Action.controller.php new file mode 100644 index 0000000000..3343d32b37 --- /dev/null +++ b/sources/Action.controller.php @@ -0,0 +1,40 @@ + array($file, $class, $method) $actionArray = array( 'activate' => array('Register.controller.php', 'Register_Controller', 'action_activate'), - 'admin' => array('Admin.php', 'AdminMain'), - // 'announce' => array('Announce.controller.php', 'Announce_Controller', 'action_index'), + 'admin' => array('Admin.php', 'Admin_Controller', 'action_index'), 'attachapprove' => array('ModerateAttachments.controller.php', 'ModerateAttachments_Controller', 'action_attachapprove'), 'buddy' => array('Members.controller.php', 'Members_Controller', 'action_buddy'), - // 'calendar' => array('Calendar.controller.php', 'Calendar_Controller', 'action_calendar'), 'collapse' => array('BoardIndex.controller.php', 'BoardIndex_Controller', 'action_collapse'), 'contact' => array('Register.controller.php', 'Register_Controller', 'action_contact'), 'coppa' => array('Register.controller.php', 'Register_Controller', 'action_coppa'), @@ -145,15 +146,11 @@ public function __construct() 'disregardtopic' => array('Notify.controller.php', 'Notify_Controller', 'action_disregardtopic'), 'editpoll' => array('Poll.controller.php', 'Poll_Controller', 'action_editpoll'), 'editpoll2' => array('Poll.controller.php', 'Poll_Controller', 'action_editpoll2'), - // 'emailuser' => array('Emailuser.controller.php', 'Emailuser_Controller', 'action_emailuser'), 'findmember' => array('Members.controller.php', 'Members_Controller', 'action_findmember'), - // 'groups' => array('Groups.controller.php', 'Groups_Controller', 'action_list'), - // 'help' => array('Help.controller.php', 'Help_Controller', 'action_help'), 'quickhelp' => array('Help.controller.php', 'Help_Controller', 'action_quickhelp'), 'jsmodify' => array('Post.controller.php', 'Post_Controller', 'action_jsmodify'), 'jsoption' => array('Themes.php', 'Themes_Controller', 'action_jsoption'), 'loadeditorlocale' => array('subs/Editor.subs.php', 'action_loadlocale'), - // 'lock' => array('Topic.controller.php', 'Topic_Controller', 'action_lock'), 'lockvoting' => array('Poll.controller.php', 'Poll_Controller', 'action_lockvoting'), 'login' => array('Auth.controller.php', 'Auth_Controller', 'action_login'), 'login2' => array('Auth.controller.php', 'Auth_Controller', 'action_login2'), @@ -171,7 +168,6 @@ public function __construct() 'pm' => array('PersonalMessage.controller.php', 'PersonalMessage_Controller', 'action_index'), 'post' => array('Post.controller.php', 'Post_Controller', 'action_post'), 'post2' => array('Post.controller.php', 'Post_Controller', 'action_post2'), - // 'printpage' => array('Topic.controller.php', 'Topic_Controller', 'action_printpage'), // done 'profile' => array('Profile.controller.php', 'Profile_Controller', 'action_index'), 'quotefast' => array('Post.controller.php', 'Post_Controller', 'action_quotefast'), 'quickmod' => array('MessageIndex.controller.php', 'MessageIndex_Controller', 'action_quickmod'), @@ -179,19 +175,16 @@ public function __construct() 'recent' => array('Recent.controller.php', 'Recent_Controller', 'action_recent'), 'register' => array('Register.controller.php', 'Register_Controller', 'action_register'), 'register2' => array('Register.controller.php', 'Register_Controller', 'action_register2'), - // 'reminder' => array('Reminder.controller.php', ''), 'removepoll' => array('Poll.controller.php', 'Poll_Controller', 'action_removepoll'), 'removetopic2' => array('RemoveTopic.controller.php', 'RemoveTopic_Controller', 'action_removetopic2'), 'reporttm' => array('Emailuser.controller.php', 'Emailuser_Controller', 'action_reporttm'), 'restoretopic' => array('RemoveTopic.controller.php', 'RemoveTopic_Controller', 'action_restoretopic'), 'search' => array('Search.controller.php', 'Search_Controller', 'action_plushsearch1'), 'search2' => array('Search.controller.php', 'Search_Controller', 'action_plushsearch2'), - // 'sendtopic' => array('Emailuser.controller.php', 'Emailuser_Controller', 'action_sendtopic'), 'suggest' => array('Suggest.controller.php', 'Suggest_Controller', 'action_suggest'), 'spellcheck' => array('Post.controller.php', 'Post_Controller', 'action_spellcheck'), 'splittopics' => array('SplitTopics.controller.php', 'SplitTopics_Controller', 'action_splittopics'), 'stats' => array('Stats.controller.php', 'Stats_Controller', 'action_stats'), - // 'sticky' => array('Topic.controller.php', 'Topic_Controller', 'action_sticky'), // done 'theme' => array('Themes.php', 'Themes_Controller', 'action_thememain'), 'trackip' => array('ProfileHistory.controller.php', 'action_trackip'), 'unread' => array('Recent.controller.php', 'Recent_Controller', 'action_unread'), From 52c07289532fde578547eac6e468981502e58e49 Mon Sep 17 00:00:00 2001 From: Norv Date: Fri, 21 Jun 2013 21:12:40 +0300 Subject: [PATCH 02/34] Derive all admin controllers from Action_Controller. Document action_index() for each. Rename redundant 'extra'-word logs methods. (i.e. modlog->log) Signed-off-by: Norv --- sources/Action.controller.php | 5 +- sources/admin/Admin.php | 1050 ++++++++--------- sources/admin/AdminDebug.php | 8 +- sources/admin/AdminLog.php | 8 +- sources/admin/ManageAddonSettings.php | 6 +- sources/admin/ManageAttachments.php | 8 +- sources/admin/ManageAvatars.php | 2 +- sources/admin/ManageBBC.php | 2 +- sources/admin/ManageBadBehavior.php | 13 +- sources/admin/ManageBans.php | 2 +- sources/admin/ManageBoards.php | 2 +- sources/admin/ManageCalendar.php | 4 +- sources/admin/ManageCoreFeatures.php | 2 +- sources/admin/ManageDrafts.php | 2 +- sources/admin/ManageErrors.php | 13 +- sources/admin/ManageFeatures.php | 3 +- sources/admin/ManageLanguages.php | 9 +- sources/admin/ManageMail.php | 6 +- sources/admin/ManageMaillist.php | 6 +- sources/admin/ManageMaintenance.php | 7 +- sources/admin/ManageMembergroups.php | 3 +- sources/admin/ManageMembers.php | 4 +- sources/admin/ManageNews.php | 10 +- sources/admin/ManagePaid.php | 14 +- sources/admin/ManagePermissions.php | 4 +- sources/admin/ManagePosts.php | 4 +- sources/admin/ManageRegistration.php | 6 +- sources/admin/ManageScheduledTasks.php | 8 +- sources/admin/ManageSearch.php | 4 +- sources/admin/ManageSearchEngines.php | 4 +- sources/admin/ManageSecurity.php | 8 +- sources/admin/ManageServer.php | 4 +- sources/admin/ManageSmileys.php | 4 +- sources/admin/ManageTopics.php | 7 +- sources/admin/Modlog.php | 8 +- sources/admin/PackageServers.php | 9 +- sources/admin/Packages.php | 4 +- sources/admin/RepairBoards.php | 4 +- sources/admin/Reports.php | 4 +- .../ModerationCenter.controller.php | 2 +- sources/subs/Modlog.subs.php | 4 +- 41 files changed, 679 insertions(+), 598 deletions(-) diff --git a/sources/Action.controller.php b/sources/Action.controller.php index 3343d32b37..09e0186e6e 100644 --- a/sources/Action.controller.php +++ b/sources/Action.controller.php @@ -21,8 +21,9 @@ abstract class Action_Controller { /** * Default action handler. This will be called - * if no other subaction matches the ?sa= parameter - * in the request. + * by the dispatcher in many cases. It may set up a menu, + * sub-dispatch at its turn to the method matching ?sa= parameter + * or simply forward the request to a known default method. */ abstract public function action_index(); diff --git a/sources/admin/Admin.php b/sources/admin/Admin.php index 1ee9734ea1..026ec5e3ae 100644 --- a/sources/admin/Admin.php +++ b/sources/admin/Admin.php @@ -21,584 +21,584 @@ die('No access...'); /** - * The main admin handling function. - * It initialises all the basic context required for the admin center. - * It passes execution onto the relevant admin section. - * If the passed section is not found it shows the admin home page. - * Accessed by ?action=admin. + * Admin controller class. + * This class handles the first general admin screens: home, + * also admin search actions and end admin session. */ -function AdminMain() +class Admin_Controller extends Action_Controller { - global $txt, $context, $scripturl, $modSettings, $settings; - - // Load the language and templates.... - loadLanguage('Admin'); - loadTemplate('Admin', 'admin'); - loadJavascriptFile('admin.js', array(), 'admin_script'); - - // No indexing evil stuff. - $context['robot_no_index'] = true; - - require_once(SUBSDIR . '/Menu.subs.php'); - require_once(SUBSDIR . '/Action.class.php'); - - // Define the menu structure - see subs/Menu.subs.php for details! - $admin_areas = array( - 'forum' => array( - 'title' => $txt['admin_main'], - 'permission' => array('admin_forum', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_boards', 'manage_smileys', 'manage_attachments'), - 'areas' => array( - 'index' => array( - 'label' => $txt['admin_center'], - 'controller' => 'Admin_Controller', - 'function' => 'action_home', - 'icon' => 'transparent.png', - 'class' => 'admin_img_administration', - ), - 'credits' => array( - 'label' => $txt['support_credits_title'], - 'controller' => 'Admin_Controller', - 'function' => 'action_credits', - 'icon' => 'transparent.png', - 'class' => 'admin_img_support', - ), - 'maillist' => array( - 'label' => $txt['mail_center'], - 'file' => 'ManageMaillist.php', - 'controller' => 'ManageMaillist_Controller', - 'function' => 'action_index', - 'icon' => 'mail.png', - 'class' => 'admin_img_mail', - 'permission' => array('approve_emails', 'admin_forum'), - 'enabled' => in_array('pe', $context['admin_features']), - 'subsections' => array( - 'emaillist' => array($txt['mm_emailerror'], 'approve_emails'), - 'emailfilters' => array($txt['mm_emailfilters'], 'admin_forum'), - 'emailparser' => array($txt['mm_emailparsers'], 'admin_forum'), - 'emailtemplates' => array($txt['mm_emailtemplates'], 'approve_emails'), - 'emailsettings' => array($txt['mm_emailsettings'], 'admin_forum'), + /** + * The main admin handling function. + * It initialises all the basic context required for the admin center. + * It passes execution onto the relevant admin section. + * If the passed section is not found it shows the admin home page. + * Accessed by ?action=admin. + */ + public function action_index() + { + global $txt, $context, $scripturl, $modSettings, $settings; + + // Load the language and templates.... + loadLanguage('Admin'); + loadTemplate('Admin', 'admin'); + loadJavascriptFile('admin.js', array(), 'admin_script'); + + // No indexing evil stuff. + $context['robot_no_index'] = true; + + require_once(SUBSDIR . '/Menu.subs.php'); + require_once(SUBSDIR . '/Action.class.php'); + + // Define the menu structure - see subs/Menu.subs.php for details! + $admin_areas = array( + 'forum' => array( + 'title' => $txt['admin_main'], + 'permission' => array('admin_forum', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_boards', 'manage_smileys', 'manage_attachments'), + 'areas' => array( + 'index' => array( + 'label' => $txt['admin_center'], + 'controller' => 'Admin_Controller', + 'function' => 'action_home', + 'icon' => 'transparent.png', + 'class' => 'admin_img_administration', ), - ), - 'news' => array( - 'label' => $txt['news_title'], - 'file' => 'ManageNews.php', - 'controller' => 'ManageNews_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_news', - 'permission' => array('edit_news', 'send_mail', 'admin_forum'), - 'subsections' => array( - 'editnews' => array($txt['admin_edit_news'], 'edit_news'), - 'mailingmembers' => array($txt['admin_newsletters'], 'send_mail'), - 'settings' => array($txt['settings'], 'admin_forum'), + 'credits' => array( + 'label' => $txt['support_credits_title'], + 'controller' => 'Admin_Controller', + 'function' => 'action_credits', + 'icon' => 'transparent.png', + 'class' => 'admin_img_support', ), - ), - 'packages' => array( - 'label' => $txt['package'], - 'file' => 'Packages.php', - 'controller' => 'Packages_Controller', - 'function' => 'action_index', - 'permission' => array('admin_forum'), - 'icon' => 'transparent.png', - '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']), + 'maillist' => array( + 'label' => $txt['mail_center'], + 'file' => 'ManageMaillist.php', + 'controller' => 'ManageMaillist_Controller', + 'function' => 'action_index', + 'icon' => 'mail.png', + 'class' => 'admin_img_mail', + 'permission' => array('approve_emails', 'admin_forum'), + 'enabled' => in_array('pe', $context['admin_features']), + 'subsections' => array( + 'emaillist' => array($txt['mm_emailerror'], 'approve_emails'), + 'emailfilters' => array($txt['mm_emailfilters'], 'admin_forum'), + 'emailparser' => array($txt['mm_emailparsers'], 'admin_forum'), + 'emailtemplates' => array($txt['mm_emailtemplates'], 'approve_emails'), + 'emailsettings' => array($txt['mm_emailsettings'], 'admin_forum'), + ), + ), + 'news' => array( + 'label' => $txt['news_title'], + 'file' => 'ManageNews.php', + 'controller' => 'ManageNews_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_news', + 'permission' => array('edit_news', 'send_mail', 'admin_forum'), + 'subsections' => array( + 'editnews' => array($txt['admin_edit_news'], 'edit_news'), + 'mailingmembers' => array($txt['admin_newsletters'], 'send_mail'), + 'settings' => array($txt['settings'], 'admin_forum'), + ), + ), + 'packages' => array( + 'label' => $txt['package'], + 'file' => 'Packages.php', + 'controller' => 'Packages_Controller', + 'function' => 'action_index', + 'permission' => array('admin_forum'), + 'icon' => 'transparent.png', + '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']), + ), + ), + 'search' => array( + 'controller' => 'Admin_Controller', + 'function' => 'action_search', + 'permission' => array('admin_forum'), + 'select' => 'index' + ), + 'adminlogoff' => array( + 'controller' => 'Admin_Controller', + 'function' => 'action_endsession', + 'label' => $txt['admin_logoff'], + 'enabled' => empty($modSettings['securityDisable']), + 'icon' => 'transparent.png', + 'class' => 'admin_img_exit', ), - ), - 'search' => array( - 'controller' => 'Admin_Controller', - 'function' => 'action_search', - 'permission' => array('admin_forum'), - 'select' => 'index' - ), - 'adminlogoff' => array( - 'controller' => 'Admin_Controller', - 'function' => 'action_endsession', - 'label' => $txt['admin_logoff'], - 'enabled' => empty($modSettings['securityDisable']), - 'icon' => 'transparent.png', - 'class' => 'admin_img_exit', - ), - ), - ), - 'config' => array( - 'title' => $txt['admin_config'], - 'permission' => array('admin_forum'), - 'areas' => array( - 'corefeatures' => array( - 'label' => $txt['core_settings_title'], - 'file' => 'ManageCoreFeatures.php', - 'controller' => 'ManageCoreFeatures_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_corefeatures', ), - 'featuresettings' => array( - 'label' => $txt['modSettings_title'], - 'file' => 'ManageFeatures.php', - 'controller' => 'ManageFeatures_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_features', - 'subsections' => array( - 'basic' => array($txt['mods_cat_features']), - 'layout' => array($txt['mods_cat_layout']), - 'karma' => array($txt['karma'], 'enabled' => in_array('k', $context['admin_features'])), - 'likes' => array($txt['likes'], 'enabled' => in_array('l', $context['admin_features'])), - 'sig' => array($txt['signature_settings_short']), - 'profile' => array($txt['custom_profile_shorttitle'], 'enabled' => in_array('cp', $context['admin_features'])), + ), + 'config' => array( + 'title' => $txt['admin_config'], + 'permission' => array('admin_forum'), + 'areas' => array( + 'corefeatures' => array( + 'label' => $txt['core_settings_title'], + 'file' => 'ManageCoreFeatures.php', + 'controller' => 'ManageCoreFeatures_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_corefeatures', ), - ), - 'securitysettings' => array( - 'label' => $txt['admin_security_moderation'], - 'file' => 'ManageSecurity.php', - 'controller' => 'ManageSecurity_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_security', - 'subsections' => array( - 'general' => array($txt['mods_cat_security_general']), - 'spam' => array($txt['antispam_title']), - 'badbehavior' => array($txt['badbehavior_title']), - 'moderation' => array($txt['moderation_settings_short'], 'enabled' => !empty($modSettings['warning_enable'])), + 'featuresettings' => array( + 'label' => $txt['modSettings_title'], + 'file' => 'ManageFeatures.php', + 'controller' => 'ManageFeatures_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_features', + 'subsections' => array( + 'basic' => array($txt['mods_cat_features']), + 'layout' => array($txt['mods_cat_layout']), + 'karma' => array($txt['karma'], 'enabled' => in_array('k', $context['admin_features'])), + 'likes' => array($txt['likes'], 'enabled' => in_array('l', $context['admin_features'])), + 'sig' => array($txt['signature_settings_short']), + 'profile' => array($txt['custom_profile_shorttitle'], 'enabled' => in_array('cp', $context['admin_features'])), + ), ), - ), - 'languages' => array( - 'label' => $txt['language_configuration'], - 'file' => 'ManageLanguages.php', - 'controller' => 'ManageLanguages_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_languages', - 'subsections' => array( - 'edit' => array($txt['language_edit']), - 'add' => array($txt['language_add']), - 'settings' => array($txt['language_settings']), + 'securitysettings' => array( + 'label' => $txt['admin_security_moderation'], + 'file' => 'ManageSecurity.php', + 'controller' => 'ManageSecurity_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_security', + 'subsections' => array( + 'general' => array($txt['mods_cat_security_general']), + 'spam' => array($txt['antispam_title']), + 'badbehavior' => array($txt['badbehavior_title']), + 'moderation' => array($txt['moderation_settings_short'], 'enabled' => !empty($modSettings['warning_enable'])), + ), ), - ), - 'serversettings' => array( - 'label' => $txt['admin_server_settings'], - 'file' => 'ManageServer.php', - 'controller' => 'ManageServer_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_server', - 'subsections' => array( - 'general' => array($txt['general_settings']), - 'database' => array($txt['database_paths_settings']), - 'cookie' => array($txt['cookies_sessions_settings']), - 'cache' => array($txt['caching_settings']), - 'loads' => array($txt['load_balancing_settings']), - 'phpinfo' => array($txt['phpinfo_settings']), + 'languages' => array( + 'label' => $txt['language_configuration'], + 'file' => 'ManageLanguages.php', + 'controller' => 'ManageLanguages_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_languages', + 'subsections' => array( + 'edit' => array($txt['language_edit']), + 'add' => array($txt['language_add']), + 'settings' => array($txt['language_settings']), + ), ), - ), - 'current_theme' => array( - 'label' => $txt['theme_current_settings'], - 'file' => 'Themes.php', - 'controller' => 'Themes_Controller', - 'function' => 'action_index', - 'custom_url' => $scripturl . '?action=admin;area=theme;sa=list;th=' . $settings['theme_id'], - 'icon' => 'transparent.png', - 'class' => 'admin_img_current_theme', - ), - 'theme' => array( - 'label' => $txt['theme_admin'], - 'file' => 'Themes.php', - 'controller' => 'Themes_Controller', - 'function' => 'action_index', - 'custom_url' => $scripturl . '?action=admin;area=theme', - 'icon' => 'transparent.png', - 'class' => 'admin_img_themes', - 'subsections' => array( - 'admin' => array($txt['themeadmin_admin_title']), - 'list' => array($txt['themeadmin_list_title']), - 'reset' => array($txt['themeadmin_reset_title']), - 'themelist' => array($txt['themeadmin_edit_title'], 'active' => array('edit', 'browse')), - 'edit' => array($txt['themeadmin_edit_title'], 'enabled' => false), - 'browse' => array($txt['themeadmin_edit_title'], 'enabled' => false), + 'serversettings' => array( + 'label' => $txt['admin_server_settings'], + 'file' => 'ManageServer.php', + 'controller' => 'ManageServer_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_server', + 'subsections' => array( + 'general' => array($txt['general_settings']), + 'database' => array($txt['database_paths_settings']), + 'cookie' => array($txt['cookies_sessions_settings']), + 'cache' => array($txt['caching_settings']), + 'loads' => array($txt['load_balancing_settings']), + 'phpinfo' => array($txt['phpinfo_settings']), + ), ), - ), - 'modsettings' => array( - 'label' => $txt['admin_modifications'], - 'file' => 'ManageAddonSettings.php', - 'controller' => 'ManageAddonSettings_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_modifications', - 'subsections' => array( - 'general' => array($txt['mods_cat_modifications_misc']), - 'hooks' => array($txt['hooks_title_list']), - // Mod Authors for a "ADD AFTER" on this line. Ensure you end your change with a comma. For example: - // 'shout' => array($txt['shout']), - // Note the comma!! The setting with automatically appear with the first mod to be added. + 'current_theme' => array( + 'label' => $txt['theme_current_settings'], + 'file' => 'Themes.php', + 'controller' => 'Themes_Controller', + 'function' => 'action_index', + 'custom_url' => $scripturl . '?action=admin;area=theme;sa=list;th=' . $settings['theme_id'], + 'icon' => 'transparent.png', + 'class' => 'admin_img_current_theme', + ), + 'theme' => array( + 'label' => $txt['theme_admin'], + 'file' => 'Themes.php', + 'controller' => 'Themes_Controller', + 'function' => 'action_index', + 'custom_url' => $scripturl . '?action=admin;area=theme', + 'icon' => 'transparent.png', + 'class' => 'admin_img_themes', + 'subsections' => array( + 'admin' => array($txt['themeadmin_admin_title']), + 'list' => array($txt['themeadmin_list_title']), + 'reset' => array($txt['themeadmin_reset_title']), + 'themelist' => array($txt['themeadmin_edit_title'], 'active' => array('edit', 'browse')), + 'edit' => array($txt['themeadmin_edit_title'], 'enabled' => false), + 'browse' => array($txt['themeadmin_edit_title'], 'enabled' => false), + ), + ), + 'modsettings' => array( + 'label' => $txt['admin_modifications'], + 'file' => 'ManageAddonSettings.php', + 'controller' => 'ManageAddonSettings_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_modifications', + 'subsections' => array( + 'general' => array($txt['mods_cat_modifications_misc']), + 'hooks' => array($txt['hooks_title_list']), + // Mod Authors for a "ADD AFTER" on this line. Ensure you end your change with a comma. For example: + // 'shout' => array($txt['shout']), + // Note the comma!! The setting with automatically appear with the first mod to be added. + ), ), ), ), - ), - 'layout' => array( - 'title' => $txt['layout_controls'], - 'permission' => array('manage_boards', 'admin_forum', 'manage_smileys', 'manage_attachments', 'moderate_forum'), - 'areas' => array( - 'manageboards' => array( - 'label' => $txt['admin_boards'], - 'file' => 'ManageBoards.php', - 'controller' => 'ManageBoards_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_boards', - 'permission' => array('manage_boards'), - 'subsections' => array( - 'main' => array($txt['boardsEdit']), - 'newcat' => array($txt['mboards_new_cat']), - 'settings' => array($txt['settings'], 'admin_forum'), + 'layout' => array( + 'title' => $txt['layout_controls'], + 'permission' => array('manage_boards', 'admin_forum', 'manage_smileys', 'manage_attachments', 'moderate_forum'), + 'areas' => array( + 'manageboards' => array( + 'label' => $txt['admin_boards'], + 'file' => 'ManageBoards.php', + 'controller' => 'ManageBoards_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_boards', + 'permission' => array('manage_boards'), + 'subsections' => array( + 'main' => array($txt['boardsEdit']), + 'newcat' => array($txt['mboards_new_cat']), + 'settings' => array($txt['settings'], 'admin_forum'), + ), ), - ), - 'postsettings' => array( - 'label' => $txt['manageposts'], - 'file' => 'ManagePosts.php', - 'controller' => 'ManagePosts_Controller', - 'function' => 'action_index', - 'permission' => array('admin_forum'), - 'icon' => 'transparent.png', - 'class' => 'admin_img_posts', - 'subsections' => array( - 'posts' => array($txt['manageposts_settings']), - 'bbc' => array($txt['manageposts_bbc_settings']), - 'censor' => array($txt['admin_censored_words']), - 'topics' => array($txt['manageposts_topic_settings']), + 'postsettings' => array( + 'label' => $txt['manageposts'], + 'file' => 'ManagePosts.php', + 'controller' => 'ManagePosts_Controller', + 'function' => 'action_index', + 'permission' => array('admin_forum'), + 'icon' => 'transparent.png', + 'class' => 'admin_img_posts', + 'subsections' => array( + 'posts' => array($txt['manageposts_settings']), + 'bbc' => array($txt['manageposts_bbc_settings']), + 'censor' => array($txt['admin_censored_words']), + 'topics' => array($txt['manageposts_topic_settings']), + ), ), - ), - 'managedrafts' => array( - 'label' => $txt['manage_drafts'], - 'file' => 'ManageDrafts.php', - 'controller' => 'ManageDrafts_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_logs', - 'permission' => array('admin_forum'), - 'enabled' => in_array('dr', $context['admin_features']), - ), - 'managecalendar' => array( - 'label' => $txt['manage_calendar'], - 'file' => 'ManageCalendar.php', - 'controller' => 'ManageCalendar_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_calendar', - 'permission' => array('admin_forum'), - 'enabled' => in_array('cd', $context['admin_features']), - 'subsections' => array( - 'holidays' => array($txt['manage_holidays'], 'admin_forum', 'enabled' => !empty($modSettings['cal_enabled'])), - 'settings' => array($txt['calendar_settings'], 'admin_forum'), + 'managedrafts' => array( + 'label' => $txt['manage_drafts'], + 'file' => 'ManageDrafts.php', + 'controller' => 'ManageDrafts_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_logs', + 'permission' => array('admin_forum'), + 'enabled' => in_array('dr', $context['admin_features']), ), - ), - 'managesearch' => array( - 'label' => $txt['manage_search'], - 'file' => 'ManageSearch.php', - 'controller' => 'ManageSearch_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_search', - 'permission' => array('admin_forum'), - 'subsections' => array( - 'weights' => array($txt['search_weights']), - 'method' => array($txt['search_method']), - 'managesphinx' => array($txt['search_sphinx']), - 'settings' => array($txt['settings']), + 'managecalendar' => array( + 'label' => $txt['manage_calendar'], + 'file' => 'ManageCalendar.php', + 'controller' => 'ManageCalendar_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_calendar', + 'permission' => array('admin_forum'), + 'enabled' => in_array('cd', $context['admin_features']), + 'subsections' => array( + 'holidays' => array($txt['manage_holidays'], 'admin_forum', 'enabled' => !empty($modSettings['cal_enabled'])), + 'settings' => array($txt['calendar_settings'], 'admin_forum'), + ), ), - ), - 'smileys' => array( - 'label' => $txt['smileys_manage'], - 'file' => 'ManageSmileys.php', - 'controller' => 'ManageSmileys_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_smiley', - 'permission' => array('manage_smileys'), - 'subsections' => array( - 'editsets' => array($txt['smiley_sets']), - 'addsmiley' => array($txt['smileys_add'], 'enabled' => !empty($modSettings['smiley_enable'])), - 'editsmileys' => array($txt['smileys_edit'], 'enabled' => !empty($modSettings['smiley_enable'])), - 'setorder' => array($txt['smileys_set_order'], 'enabled' => !empty($modSettings['smiley_enable'])), - 'editicons' => array($txt['icons_edit_message_icons'], 'enabled' => !empty($modSettings['messageIcons_enable'])), - 'settings' => array($txt['settings']), + 'managesearch' => array( + 'label' => $txt['manage_search'], + 'file' => 'ManageSearch.php', + 'controller' => 'ManageSearch_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_search', + 'permission' => array('admin_forum'), + 'subsections' => array( + 'weights' => array($txt['search_weights']), + 'method' => array($txt['search_method']), + 'managesphinx' => array($txt['search_sphinx']), + 'settings' => array($txt['settings']), + ), ), - ), - 'manageattachments' => array( - 'label' => $txt['attachments_avatars'], - 'file' => 'ManageAttachments.php', - 'controller' => 'ManageAttachments_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_attachment', - 'permission' => array('manage_attachments'), - 'subsections' => array( - 'browse' => array($txt['attachment_manager_browse']), - 'attachments' => array($txt['attachment_manager_settings']), - 'avatars' => array($txt['attachment_manager_avatar_settings']), - 'attachpaths' => array($txt['attach_directories']), - 'maintenance' => array($txt['attachment_manager_maintenance']), + 'smileys' => array( + 'label' => $txt['smileys_manage'], + 'file' => 'ManageSmileys.php', + 'controller' => 'ManageSmileys_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_smiley', + 'permission' => array('manage_smileys'), + 'subsections' => array( + 'editsets' => array($txt['smiley_sets']), + 'addsmiley' => array($txt['smileys_add'], 'enabled' => !empty($modSettings['smiley_enable'])), + 'editsmileys' => array($txt['smileys_edit'], 'enabled' => !empty($modSettings['smiley_enable'])), + 'setorder' => array($txt['smileys_set_order'], 'enabled' => !empty($modSettings['smiley_enable'])), + 'editicons' => array($txt['icons_edit_message_icons'], 'enabled' => !empty($modSettings['messageIcons_enable'])), + 'settings' => array($txt['settings']), + ), + ), + 'manageattachments' => array( + 'label' => $txt['attachments_avatars'], + 'file' => 'ManageAttachments.php', + 'controller' => 'ManageAttachments_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_attachment', + 'permission' => array('manage_attachments'), + 'subsections' => array( + 'browse' => array($txt['attachment_manager_browse']), + 'attachments' => array($txt['attachment_manager_settings']), + 'avatars' => array($txt['attachment_manager_avatar_settings']), + 'attachpaths' => array($txt['attach_directories']), + 'maintenance' => array($txt['attachment_manager_maintenance']), + ), ), ), ), - ), - 'members' => array( - 'title' => $txt['admin_manage_members'], - 'permission' => array('moderate_forum', 'manage_membergroups', 'manage_bans', 'manage_permissions', 'admin_forum'), - 'areas' => array( - 'viewmembers' => array( - 'label' => $txt['admin_users'], - 'file' => 'ManageMembers.php', - 'controller' => 'ManageMembers_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_members', - 'permission' => array('moderate_forum'), - 'subsections' => array( - 'all' => array($txt['view_all_members']), - 'search' => array($txt['mlist_search']), + 'members' => array( + 'title' => $txt['admin_manage_members'], + 'permission' => array('moderate_forum', 'manage_membergroups', 'manage_bans', 'manage_permissions', 'admin_forum'), + 'areas' => array( + 'viewmembers' => array( + 'label' => $txt['admin_users'], + 'file' => 'ManageMembers.php', + 'controller' => 'ManageMembers_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_members', + 'permission' => array('moderate_forum'), + 'subsections' => array( + 'all' => array($txt['view_all_members']), + 'search' => array($txt['mlist_search']), + ), ), - ), - 'membergroups' => array( - 'label' => $txt['admin_groups'], - 'file' => 'ManageMembergroups.php', - 'controller' => 'ManageMembergroups_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_membergroups', - 'permission' => array('manage_membergroups'), - 'subsections' => array( - 'index' => array($txt['membergroups_edit_groups'], 'manage_membergroups'), - 'add' => array($txt['membergroups_new_group'], 'manage_membergroups'), - 'settings' => array($txt['settings'], 'admin_forum'), + 'membergroups' => array( + 'label' => $txt['admin_groups'], + 'file' => 'ManageMembergroups.php', + 'controller' => 'ManageMembergroups_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_membergroups', + 'permission' => array('manage_membergroups'), + 'subsections' => array( + 'index' => array($txt['membergroups_edit_groups'], 'manage_membergroups'), + 'add' => array($txt['membergroups_new_group'], 'manage_membergroups'), + 'settings' => array($txt['settings'], 'admin_forum'), + ), ), - ), - 'permissions' => array( - 'label' => $txt['edit_permissions'], - 'file' => 'ManagePermissions.php', - 'controller' => 'ManagePermissions_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_permissions', - 'permission' => array('manage_permissions'), - 'subsections' => array( - 'index' => array($txt['permissions_groups'], 'manage_permissions'), - 'board' => array($txt['permissions_boards'], 'manage_permissions'), - 'profiles' => array($txt['permissions_profiles'], 'manage_permissions'), - 'postmod' => array($txt['permissions_post_moderation'], 'manage_permissions', 'enabled' => $modSettings['postmod_active']), - 'settings' => array($txt['settings'], 'admin_forum'), + 'permissions' => array( + 'label' => $txt['edit_permissions'], + 'file' => 'ManagePermissions.php', + 'controller' => 'ManagePermissions_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_permissions', + 'permission' => array('manage_permissions'), + 'subsections' => array( + 'index' => array($txt['permissions_groups'], 'manage_permissions'), + 'board' => array($txt['permissions_boards'], 'manage_permissions'), + 'profiles' => array($txt['permissions_profiles'], 'manage_permissions'), + 'postmod' => array($txt['permissions_post_moderation'], 'manage_permissions', 'enabled' => $modSettings['postmod_active']), + 'settings' => array($txt['settings'], 'admin_forum'), + ), ), - ), - 'regcenter' => array( - 'label' => $txt['registration_center'], - 'file' => 'ManageRegistration.php', - 'controller' => 'ManageRegistration_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_regcenter', - 'permission' => array('admin_forum', 'moderate_forum'), - 'subsections' => array( - 'register' => array($txt['admin_browse_register_new'], 'moderate_forum'), - 'agreement' => array($txt['registration_agreement'], 'admin_forum'), - 'reservednames' => array($txt['admin_reserved_set'], 'admin_forum'), - 'settings' => array($txt['settings'], 'admin_forum'), + 'regcenter' => array( + 'label' => $txt['registration_center'], + 'file' => 'ManageRegistration.php', + 'controller' => 'ManageRegistration_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_regcenter', + 'permission' => array('admin_forum', 'moderate_forum'), + 'subsections' => array( + 'register' => array($txt['admin_browse_register_new'], 'moderate_forum'), + 'agreement' => array($txt['registration_agreement'], 'admin_forum'), + 'reservednames' => array($txt['admin_reserved_set'], 'admin_forum'), + 'settings' => array($txt['settings'], 'admin_forum'), + ), ), - ), - 'ban' => array( - 'label' => $txt['ban_title'], - 'file' => 'ManageBans.php', - 'controller' => 'ManageBans_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_ban', - 'permission' => 'manage_bans', - 'subsections' => array( - 'list' => array($txt['ban_edit_list']), - 'add' => array($txt['ban_add_new']), - 'browse' => array($txt['ban_trigger_browse']), - 'log' => array($txt['ban_log']), + 'ban' => array( + 'label' => $txt['ban_title'], + 'file' => 'ManageBans.php', + 'controller' => 'ManageBans_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_ban', + 'permission' => 'manage_bans', + 'subsections' => array( + 'list' => array($txt['ban_edit_list']), + 'add' => array($txt['ban_add_new']), + 'browse' => array($txt['ban_trigger_browse']), + 'log' => array($txt['ban_log']), + ), ), - ), - 'paidsubscribe' => array( - 'label' => $txt['paid_subscriptions'], - 'enabled' => in_array('ps', $context['admin_features']), - 'file' => 'ManagePaid.php', - 'controller' => 'ManagePaid_Controller', - 'icon' => 'transparent.png', - 'class' => 'admin_img_paid', - 'function' => 'action_index', - 'permission' => 'admin_forum', - 'subsections' => array( - 'view' => array($txt['paid_subs_view']), - 'settings' => array($txt['settings']), + 'paidsubscribe' => array( + 'label' => $txt['paid_subscriptions'], + 'enabled' => in_array('ps', $context['admin_features']), + 'file' => 'ManagePaid.php', + 'controller' => 'ManagePaid_Controller', + 'icon' => 'transparent.png', + 'class' => 'admin_img_paid', + 'function' => 'action_index', + 'permission' => 'admin_forum', + 'subsections' => array( + 'view' => array($txt['paid_subs_view']), + 'settings' => array($txt['settings']), + ), ), - ), - 'sengines' => array( - 'label' => $txt['search_engines'], - 'enabled' => in_array('sp', $context['admin_features']), - 'file' => 'ManageSearchEngines.php', - 'controller' => 'ManageSearchEngines_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_engines', - 'permission' => 'admin_forum', - 'subsections' => array( - 'stats' => array($txt['spider_stats']), - 'logs' => array($txt['spider_logs']), - 'spiders' => array($txt['spiders']), - 'settings' => array($txt['settings']), + 'sengines' => array( + 'label' => $txt['search_engines'], + 'enabled' => in_array('sp', $context['admin_features']), + 'file' => 'ManageSearchEngines.php', + 'controller' => 'ManageSearchEngines_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_engines', + 'permission' => 'admin_forum', + 'subsections' => array( + 'stats' => array($txt['spider_stats']), + 'logs' => array($txt['spider_logs']), + 'spiders' => array($txt['spiders']), + 'settings' => array($txt['settings']), + ), ), ), ), - ), - 'maintenance' => array( - 'title' => $txt['admin_maintenance'], - 'permission' => array('admin_forum'), - 'areas' => array( - 'maintain' => array( - 'label' => $txt['maintain_title'], - 'file' => 'ManageMaintenance.php', - 'controller' => 'ManageMaintenance_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_maintain', - 'subsections' => array( - 'routine' => array($txt['maintain_sub_routine'], 'admin_forum'), - 'database' => array($txt['maintain_sub_database'], 'admin_forum'), - 'members' => array($txt['maintain_sub_members'], 'admin_forum'), - 'topics' => array($txt['maintain_sub_topics'], 'admin_forum'), + 'maintenance' => array( + 'title' => $txt['admin_maintenance'], + 'permission' => array('admin_forum'), + 'areas' => array( + 'maintain' => array( + 'label' => $txt['maintain_title'], + 'file' => 'ManageMaintenance.php', + 'controller' => 'ManageMaintenance_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_maintain', + 'subsections' => array( + 'routine' => array($txt['maintain_sub_routine'], 'admin_forum'), + 'database' => array($txt['maintain_sub_database'], 'admin_forum'), + 'members' => array($txt['maintain_sub_members'], 'admin_forum'), + 'topics' => array($txt['maintain_sub_topics'], 'admin_forum'), + ), ), - ), - 'scheduledtasks' => array( - 'label' => $txt['maintain_tasks'], - 'file' => 'ManageScheduledTasks.php', - 'controller' => 'ManageScheduledTasks_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_scheduled', - 'subsections' => array( - 'tasks' => array($txt['maintain_tasks'], 'admin_forum'), - 'tasklog' => array($txt['scheduled_log'], 'admin_forum'), + 'scheduledtasks' => array( + 'label' => $txt['maintain_tasks'], + 'file' => 'ManageScheduledTasks.php', + 'controller' => 'ManageScheduledTasks_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_scheduled', + 'subsections' => array( + 'tasks' => array($txt['maintain_tasks'], 'admin_forum'), + 'tasklog' => array($txt['scheduled_log'], 'admin_forum'), + ), ), - ), - 'mailqueue' => array( - 'label' => $txt['mailqueue_title'], - 'file' => 'ManageMail.php', - 'controller' => 'ManageMail_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_mail', - 'subsections' => array( - 'browse' => array($txt['mailqueue_browse'], 'admin_forum'), - 'settings' => array($txt['mailqueue_settings'], 'admin_forum'), + 'mailqueue' => array( + 'label' => $txt['mailqueue_title'], + 'file' => 'ManageMail.php', + 'controller' => 'ManageMail_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_mail', + 'subsections' => array( + 'browse' => array($txt['mailqueue_browse'], 'admin_forum'), + 'settings' => array($txt['mailqueue_settings'], 'admin_forum'), + ), ), - ), - 'reports' => array( - 'enabled' => in_array('rg', $context['admin_features']), - 'label' => $txt['generate_reports'], - 'file' => 'Reports.php', - 'controller' => 'Reports_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_reports', - ), - 'logs' => array( - 'label' => $txt['logs'], - 'file' => 'AdminLog.php', - 'controller' => 'AdminLog_Controller', - 'function' => 'action_index', - 'icon' => 'transparent.png', - 'class' => 'admin_img_logs', - 'subsections' => array( - 'errorlog' => array($txt['errlog'], 'admin_forum', 'enabled' => !empty($modSettings['enableErrorLogging']), 'url' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc'), - 'adminlog' => array($txt['admin_log'], 'admin_forum', 'enabled' => in_array('ml', $context['admin_features'])), - 'modlog' => array($txt['moderation_log'], 'admin_forum', 'enabled' => in_array('ml', $context['admin_features'])), - 'banlog' => array($txt['ban_log'], 'manage_bans'), - 'spiderlog' => array($txt['spider_logs'], 'admin_forum', 'enabled' => in_array('sp', $context['admin_features'])), - 'tasklog' => array($txt['scheduled_log'], 'admin_forum'), - 'badbehaviorlog' => array($txt['badbehavior_log'], 'admin_forum', 'enabled' => !empty($modSettings['badbehavior_enabled']), 'url' => $scripturl . '?action=admin;area=logs;sa=badbehaviorlog;desc'), - 'pruning' => array($txt['pruning_title'], 'admin_forum'), + 'reports' => array( + 'enabled' => in_array('rg', $context['admin_features']), + 'label' => $txt['generate_reports'], + 'file' => 'Reports.php', + 'controller' => 'Reports_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_reports', + ), + 'logs' => array( + 'label' => $txt['logs'], + 'file' => 'AdminLog.php', + 'controller' => 'AdminLog_Controller', + 'function' => 'action_index', + 'icon' => 'transparent.png', + 'class' => 'admin_img_logs', + 'subsections' => array( + 'errorlog' => array($txt['errlog'], 'admin_forum', 'enabled' => !empty($modSettings['enableErrorLogging']), 'url' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc'), + 'adminlog' => array($txt['admin_log'], 'admin_forum', 'enabled' => in_array('ml', $context['admin_features'])), + 'modlog' => array($txt['moderation_log'], 'admin_forum', 'enabled' => in_array('ml', $context['admin_features'])), + 'banlog' => array($txt['ban_log'], 'manage_bans'), + 'spiderlog' => array($txt['spider_logs'], 'admin_forum', 'enabled' => in_array('sp', $context['admin_features'])), + 'tasklog' => array($txt['scheduled_log'], 'admin_forum'), + 'badbehaviorlog' => array($txt['badbehavior_log'], 'admin_forum', 'enabled' => !empty($modSettings['badbehavior_enabled']), 'url' => $scripturl . '?action=admin;area=logs;sa=badbehaviorlog;desc'), + 'pruning' => array($txt['pruning_title'], 'admin_forum'), + ), + ), + 'repairboards' => array( + 'label' => $txt['admin_repair'], + 'file' => 'RepairBoards.php', + 'controller' => 'RepairBoards_Controller', + 'function' => 'action_repairboards', + 'select' => 'maintain', + 'hidden' => true, ), - ), - 'repairboards' => array( - 'label' => $txt['admin_repair'], - 'file' => 'RepairBoards.php', - 'controller' => 'RepairBoards_Controller', - 'function' => 'action_repairboards', - 'select' => 'maintain', - 'hidden' => true, ), ), - ), - ); + ); - // Any files to include for administration? - if (!empty($modSettings['integrate_admin_include'])) - { - $admin_includes = explode(',', $modSettings['integrate_admin_include']); - foreach ($admin_includes as $include) + // Any files to include for administration? + if (!empty($modSettings['integrate_admin_include'])) { - $include = strtr(trim($include), array('BOARDDIR' => BOARDDIR, 'SOURCEDIR' => SOURCEDIR, '$themedir' => $settings['theme_dir'])); - if (file_exists($include)) - require_once($include); + $admin_includes = explode(',', $modSettings['integrate_admin_include']); + foreach ($admin_includes as $include) + { + $include = strtr(trim($include), array('BOARDDIR' => BOARDDIR, 'SOURCEDIR' => SOURCEDIR, '$themedir' => $settings['theme_dir'])); + if (file_exists($include)) + require_once($include); + } } - } - // Make sure the administrator has a valid session... - validateSession(); + // Make sure the administrator has a valid session... + validateSession(); - // Actually create the menu! - $admin_include_data = createMenu($admin_areas); - unset($admin_areas); + // Actually create the menu! + $admin_include_data = createMenu($admin_areas); + unset($admin_areas); - // Nothing valid? - if ($admin_include_data == false) - fatal_lang_error('no_access', false); + // Nothing valid? + if ($admin_include_data == false) + fatal_lang_error('no_access', false); - // Build the link tree. - $context['linktree'][] = array( - 'url' => $scripturl . '?action=admin', - 'name' => $txt['admin_center'], - ); - - if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index') + // Build the link tree. $context['linktree'][] = array( - 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'], - 'name' => $admin_include_data['label'], + 'url' => $scripturl . '?action=admin', + 'name' => $txt['admin_center'], ); - if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label']) - $context['linktree'][] = array( - 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'], - 'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0], - ); + if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index') + $context['linktree'][] = array( + 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'], + 'name' => $admin_include_data['label'], + ); - // Make a note of the Unique ID for this menu. - $context['admin_menu_id'] = $context['max_menu_id']; - $context['admin_menu_name'] = 'menu_data_' . $context['admin_menu_id']; + if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label']) + $context['linktree'][] = array( + 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'], + 'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0], + ); - // Where in the admin are we? - $context['admin_area'] = $admin_include_data['current_area']; + // Make a note of the Unique ID for this menu. + $context['admin_menu_id'] = $context['max_menu_id']; + $context['admin_menu_name'] = 'menu_data_' . $context['admin_menu_id']; - // Now - finally - call the right place! - if (isset($admin_include_data['file'])) - require_once(ADMINDIR . '/' . $admin_include_data['file']); + // Where in the admin are we? + $context['admin_area'] = $admin_include_data['current_area']; - callMenu($admin_include_data); -} + // Now - finally - call the right place! + if (isset($admin_include_data['file'])) + require_once(ADMINDIR . '/' . $admin_include_data['file']); + + callMenu($admin_include_data); + } -/** - * Admin controller class. - * This class handles the first general admin screen: home, - * also admin search actions and end admin session. - */ -class Admin_Controller -{ /** * The main administration section. * It prepares all the data necessary for the administration front page. diff --git a/sources/admin/AdminDebug.php b/sources/admin/AdminDebug.php index 1e41d4cd92..5f493c3a53 100644 --- a/sources/admin/AdminDebug.php +++ b/sources/admin/AdminDebug.php @@ -20,8 +20,14 @@ if (!defined('ELKARTE')) die('No access...'); -class AdminDebug_Controller +class AdminDebug_Controller extends Action_Controller { + public function action_index() + { + // what to do first... viewquery! What, it'll work or it won't. + $this->action_viewquery(); + } + /** * Show the database queries for debugging * What this does: diff --git a/sources/admin/AdminLog.php b/sources/admin/AdminLog.php index 92cd854fcb..e24e0d4d1c 100644 --- a/sources/admin/AdminLog.php +++ b/sources/admin/AdminLog.php @@ -17,7 +17,7 @@ * This class manages logs, and forwards to display, pruning, * and other actions on logs. */ -class AdminLog_Controller +class AdminLog_Controller extends Action_Controller { /** * Pruning Settings form @@ -44,16 +44,16 @@ public function action_index() 'controller' => 'ManageErrors_Controller'), 'adminlog' => array( 'file' => 'Modlog.php', - 'function' => 'action_modlog', + 'function' => 'action_log', 'controller' => 'Modlog_Controller'), 'modlog' => array( 'file' => 'Modlog.php', - 'function' => 'action_modlog', + 'function' => 'action_log', 'controller' => 'Modlog_Controller', 'disabled' => !in_array('ml', $context['admin_features'])), 'badbehaviorlog' => array( 'file' => 'ManageBadBehavior.php', - 'function' => 'action_badbehaviorlog', + 'function' => 'action_log', 'disabled' => empty($modSettings['badbehavior_enabled']), 'controller' => 'ManageBadBehavior_Controller'), 'banlog' => array( diff --git a/sources/admin/ManageAddonSettings.php b/sources/admin/ManageAddonSettings.php index 323edf6c66..7477c2ea33 100644 --- a/sources/admin/ManageAddonSettings.php +++ b/sources/admin/ManageAddonSettings.php @@ -21,7 +21,7 @@ * to admin search and otherwise benefit from admin areas security, * checks and display. */ -class ManageAddonSettings_Controller +class ManageAddonSettings_Controller extends Action_Controller { /** * General addon settings form. @@ -30,7 +30,9 @@ class ManageAddonSettings_Controller protected $_addonSettings; /** - * This my friend, is for all the mod authors out there. + * This, my friend, is for all the authors of add-ons out there. + * + * @see Action_Controller::action_index() */ public function action_index() { diff --git a/sources/admin/ManageAttachments.php b/sources/admin/ManageAttachments.php index 410a075bd0..09c40006ae 100644 --- a/sources/admin/ManageAttachments.php +++ b/sources/admin/ManageAttachments.php @@ -22,7 +22,7 @@ * This is the attachments and avatars controller class. * It is doing the job of attachments and avatars maintenance and management. */ -class ManageAttachments_Controller +class ManageAttachments_Controller extends Action_Controller { /** * Attachments settings form @@ -31,8 +31,8 @@ class ManageAttachments_Controller protected $_attachSettingsForm; /** - * The main 'Attachments and Avatars' management function. - * This function is the entry point for index.php?action=admin;area=manageattachments + * The main 'Attachments and Avatars' admin. + * This method is the entry point for index.php?action=admin;area=manageattachments * and it calls a function based on the sub-action. * It requires the manage_attachments permission. * @@ -40,6 +40,8 @@ class ManageAttachments_Controller * @uses Admin language file. * @uses template layer 'manage_files' for showing the tab bar. * + * @see Action_Controller::action_index() + * */ public function action_index() { diff --git a/sources/admin/ManageAvatars.php b/sources/admin/ManageAvatars.php index b5e5c44b83..ecb72b7e74 100644 --- a/sources/admin/ManageAvatars.php +++ b/sources/admin/ManageAvatars.php @@ -16,7 +16,7 @@ * This is the avatars administration controller class. * It is doing the job of maintenance and allow display and change of admin settings. */ -class ManageAvatars_Controller +class ManageAvatars_Controller extends Action_Controller { /** * Avatars settings form diff --git a/sources/admin/ManageBBC.php b/sources/admin/ManageBBC.php index 04a8ae3a3c..4a8577a502 100644 --- a/sources/admin/ManageBBC.php +++ b/sources/admin/ManageBBC.php @@ -15,7 +15,7 @@ /** * ManageBBC controller handles administration options for BBC tags. */ -class ManageBBC_Controller +class ManageBBC_Controller extends Action_Controller { /** * BBC settings form diff --git a/sources/admin/ManageBadBehavior.php b/sources/admin/ManageBadBehavior.php index c46c2e2075..d8a1020620 100644 --- a/sources/admin/ManageBadBehavior.php +++ b/sources/admin/ManageBadBehavior.php @@ -12,8 +12,17 @@ if (!defined('ELKARTE')) die('No access...'); -class ManageBadBehavior_Controller +class ManageBadBehavior_Controller extends Action_Controller { + /** + * Call the appropriate action method. + */ + public function action_index() + { + // all we know how to do is... + $this->action_log(); + } + /** * View the forum's badbehavior log. * This function sets all the context up to show the badbehavior log for review. @@ -22,7 +31,7 @@ class ManageBadBehavior_Controller * * @uses the BadBehavior template and badbehavior_log sub template. */ - public function action_badbehaviorlog() + public function action_log() { global $scripturl, $txt, $context, $modSettings, $user_profile, $filter; diff --git a/sources/admin/ManageBans.php b/sources/admin/ManageBans.php index c1823bf0f8..06f2df9f2a 100644 --- a/sources/admin/ManageBans.php +++ b/sources/admin/ManageBans.php @@ -16,7 +16,7 @@ * This class controls execution for admin actions in the bans area * of the admin panel. */ -class ManageBans_Controller +class ManageBans_Controller extends Action_Controller { /** * Ban center. The main entrance point for all ban center functions. diff --git a/sources/admin/ManageBoards.php b/sources/admin/ManageBoards.php index b0e8a3f698..a7c7e87652 100644 --- a/sources/admin/ManageBoards.php +++ b/sources/admin/ManageBoards.php @@ -20,7 +20,7 @@ if (!defined('ELKARTE')) die('No access...'); -class ManageBoards_Controller +class ManageBoards_Controller extends Action_Controller { /** * Boards settings form. diff --git a/sources/admin/ManageCalendar.php b/sources/admin/ManageCalendar.php index e8e1b0c029..35c774d0b0 100644 --- a/sources/admin/ManageCalendar.php +++ b/sources/admin/ManageCalendar.php @@ -20,7 +20,7 @@ if (!defined('ELKARTE')) die('No access...'); -class ManageCalendar_Controller +class ManageCalendar_Controller extends Action_Controller { /** * Calendar settings form @@ -219,7 +219,7 @@ public function action_editholiday() // Not too long good sir? $_REQUEST['title'] = Util::substr($_REQUEST['title'], 0, 60); $_REQUEST['holiday'] = isset($_REQUEST['holiday']) ? (int) $_REQUEST['holiday'] : 0; - + if (isset($_REQUEST['delete'])) removeHolidays($_REQUEST['holiday']); else diff --git a/sources/admin/ManageCoreFeatures.php b/sources/admin/ManageCoreFeatures.php index 7c2025fde8..3dc3b91b92 100644 --- a/sources/admin/ManageCoreFeatures.php +++ b/sources/admin/ManageCoreFeatures.php @@ -27,7 +27,7 @@ * updates the settings for enabled/disabled core features as requested. * */ -class ManageCoreFeatures_Controller +class ManageCoreFeatures_Controller extends Action_Controller { /** * This is an overall control panel enabling/disabling lots of the forums key features. diff --git a/sources/admin/ManageDrafts.php b/sources/admin/ManageDrafts.php index 8398476702..366416233c 100644 --- a/sources/admin/ManageDrafts.php +++ b/sources/admin/ManageDrafts.php @@ -15,7 +15,7 @@ * Drafts administration controller. * This class allows to modify admin drafts settings for the forum. */ -class ManageDrafts_Controller +class ManageDrafts_Controller extends Action_Controller { /** * Drafts settings form diff --git a/sources/admin/ManageErrors.php b/sources/admin/ManageErrors.php index 88f40c778b..6727babb52 100644 --- a/sources/admin/ManageErrors.php +++ b/sources/admin/ManageErrors.php @@ -24,8 +24,19 @@ /** * ManageErrors controller, administration of error log. */ -class ManageErrors_Controller +class ManageErrors_Controller extends Action_Controller { + /** + * Calls the right handler. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // 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. diff --git a/sources/admin/ManageFeatures.php b/sources/admin/ManageFeatures.php index 0fd85f8c0a..ec291f4e99 100644 --- a/sources/admin/ManageFeatures.php +++ b/sources/admin/ManageFeatures.php @@ -24,7 +24,7 @@ * to see and change the basic feature settings of their site. * */ -class ManageFeatures_Controller +class ManageFeatures_Controller extends Action_Controller { /** * Basic feature settings form @@ -58,6 +58,7 @@ class ManageFeatures_Controller /** * This function passes control through to the relevant tab. + * @see Action_Controller::action_index() */ public function action_index() { diff --git a/sources/admin/ManageLanguages.php b/sources/admin/ManageLanguages.php index 899d41f079..0910917b26 100644 --- a/sources/admin/ManageLanguages.php +++ b/sources/admin/ManageLanguages.php @@ -23,7 +23,7 @@ /** * Manage languages controller class. */ -class ManageLanguages_Controller +class ManageLanguages_Controller extends Action_Controller { /** * Language settings form @@ -37,6 +37,7 @@ class ManageLanguages_Controller * Loads the ManageLanguages template. (sub-actions will use it) * * @uses ManageSettings language file + * @see Action_Controller::action_index() */ public function action_index() { @@ -1046,7 +1047,7 @@ private function _initLanguageSettingsForm() // Warn the user if the backup of Settings.php failed. $settings_not_writable = !is_writable(BOARDDIR . '/Settings.php'); - + $config_vars = array( 'language' => array('language', $txt['default_language'], 'file', 'select', array(), null, 'disabled' => $settings_not_writable), array('userLanguage', $txt['userLanguage'], 'db', 'check', null, 'userLanguage'), @@ -1066,10 +1067,10 @@ private function _initLanguageSettingsForm() public function settings() { global $txt; - + // Warn the user if the backup of Settings.php failed. $settings_not_writable = !is_writable(BOARDDIR . '/Settings.php'); - + $config_vars = array( 'language' => array('language', $txt['default_language'], 'file', 'select', array(), null, 'disabled' => $settings_not_writable), array('userLanguage', $txt['userLanguage'], 'db', 'check', null, 'userLanguage'), diff --git a/sources/admin/ManageMail.php b/sources/admin/ManageMail.php index d07b4cef32..c382d47d26 100644 --- a/sources/admin/ManageMail.php +++ b/sources/admin/ManageMail.php @@ -23,7 +23,7 @@ * It handles mail configuration, it displays and allows to remove items from the mail queue. * */ -class ManageMail_Controller +class ManageMail_Controller extends Action_Controller { /** * Mail settings form @@ -33,7 +33,9 @@ class ManageMail_Controller /** * Main dispatcher. - * This function checks permissions and passes control through to the relevant section. + * This function checks permissions and passes control + * through to the relevant section. + * @see Action_Controller::action_index() */ public function action_index() { diff --git a/sources/admin/ManageMaillist.php b/sources/admin/ManageMaillist.php index 0726a4e6e8..03d876f3e8 100644 --- a/sources/admin/ManageMaillist.php +++ b/sources/admin/ManageMaillist.php @@ -21,7 +21,7 @@ * - handles the adding / editing / removing of both filters and parsers * */ -class ManageMaillist_Controller +class ManageMaillist_Controller extends Action_Controller { /** * Basic feature settings form @@ -31,7 +31,9 @@ class ManageMaillist_Controller /** * Main dispatcher. - * This function checks permissions and passes control to the sub action. + * This function checks permissions and passes control + * to the sub action. + * @see Action_Controller::action_index() */ public function action_index() { diff --git a/sources/admin/ManageMaintenance.php b/sources/admin/ManageMaintenance.php index 91b7cf63ee..e1c401aa9b 100644 --- a/sources/admin/ManageMaintenance.php +++ b/sources/admin/ManageMaintenance.php @@ -20,11 +20,14 @@ if (!defined('ELKARTE')) die('No access...'); -class ManageMaintenance_Controller +class ManageMaintenance_Controller extends Action_Controller { /** * Main dispatcher, the maintenance access point. - * This, as usual, checks permissions, loads language files, and forwards to the actual workers. + * This, as usual, checks permissions, loads language files, + * and forwards to the actual workers. + * + * @see Action_Controller::action_index() */ public function action_index() { diff --git a/sources/admin/ManageMembergroups.php b/sources/admin/ManageMembergroups.php index 771435c2d4..28174d35ce 100644 --- a/sources/admin/ManageMembergroups.php +++ b/sources/admin/ManageMembergroups.php @@ -21,7 +21,7 @@ /** * ManageMembergroups controller, administration page for membergroups. */ -class ManageMembergroups_Controller +class ManageMembergroups_Controller extends Action_Controller { /** * Groups Settings form @@ -38,6 +38,7 @@ class ManageMembergroups_Controller * * @uses ManageMembergroups template. * @uses ManageMembers language file. + * @see Action_Controller::action_index() */ public function action_index() { diff --git a/sources/admin/ManageMembers.php b/sources/admin/ManageMembers.php index 9f2224f4e1..d1950ab02c 100644 --- a/sources/admin/ManageMembers.php +++ b/sources/admin/ManageMembers.php @@ -24,7 +24,7 @@ * ManageMembers controller deals with members administration, approval, * admin-visible list and search in it. */ -class ManageMembers_Controller +class ManageMembers_Controller extends Action_Controller { /** * The main entrance point for the Manage Members screen. @@ -34,6 +34,8 @@ class ManageMembers_Controller * * @uses ManageMembers template * @uses ManageMembers language file. + * + * @see Action_Controller::action_index() */ public function action_index() { diff --git a/sources/admin/ManageNews.php b/sources/admin/ManageNews.php index 325f6bd182..b701d51dfe 100644 --- a/sources/admin/ManageNews.php +++ b/sources/admin/ManageNews.php @@ -21,7 +21,7 @@ /** * ManageNews controller, for news administration screens. */ -class ManageNews_Controller +class ManageNews_Controller extends Action_Controller { /** * News settings form. @@ -35,6 +35,8 @@ class ManageNews_Controller * Called by ?action=admin;area=news. * It does the permission checks, and calls the appropriate function * based on the requested sub-action. + * + * @see Action_Controller::action_index() */ public function action_index() { @@ -312,7 +314,7 @@ public function action_mailingmembers() $context['page_title'] = $txt['admin_newsletters']; $context['sub_template'] = 'email_members'; $context['groups'] = array(); - + $allgroups = getBasicMembergroupData(array('all'), array(), null, true); $context['groups'] = $allgroups['groups']; @@ -453,7 +455,7 @@ public function action_mailingcompose() if ((!empty($context['recipients']['groups']) && in_array(3, $context['recipients']['groups'])) || (!empty($context['recipients']['exclude_groups']) && in_array(3, $context['recipients']['exclude_groups']))) { $mods = getModerators(); - + foreach($mods as $row) { if (in_array(3, $context['recipients'])) @@ -748,7 +750,7 @@ public function action_mailingsend($clean_only = false) // Get the smelly people - note we respect the id_member range as it gives us a quicker query. $recipients = getNewsletterRecipients($sendQuery, $sendParams, $context['start'], $num_at_once, $i); - + foreach ($recipients as $row) { diff --git a/sources/admin/ManagePaid.php b/sources/admin/ManagePaid.php index 3cc4ed97e0..ea05a8afe5 100644 --- a/sources/admin/ManagePaid.php +++ b/sources/admin/ManagePaid.php @@ -24,7 +24,7 @@ /** * ManagePaid controller, administration controller for paid subscriptions. */ -class ManagePaid_Controller +class ManagePaid_Controller extends Action_Controller { /** * Paid subscriptions settings form. @@ -38,6 +38,8 @@ class ManagePaid_Controller * It defaults to sub-action 'view'. * Accessed from ?action=admin;area=paidsubscribe. * It requires admin_forum permission for admin based actions. + * + * @see Action_Controller::action_index() */ public function action_index() { @@ -588,7 +590,7 @@ public function action_viewsub() $context['sub_id'] = (int) $_REQUEST['sid']; // Load the subscription information. $context['subscription'] = getSubscription($context['sub_id']); - + // Are we searching for people? $search_string = isset($_POST['ssearch']) && !empty($_POST['sub_search']) ? ' AND IFNULL(mem.real_name, {string:guest}) LIKE {string:search}' : ''; $search_vars = empty($_POST['sub_search']) ? array() : array('search' => '%' . $_POST['sub_search'] . '%', 'guest' => $txt['guest']); @@ -799,7 +801,7 @@ public function action_modifyuser() // Find the user... require_once(SUBSDIR . '/Members.subs.php'); $member = getMemberByName($_POST['name']); - + if(alreadySubscribed($context['sub_id'], $member['id_member'])) fatal_lang_error('member_already_subscribed'); @@ -816,7 +818,7 @@ public function action_modifyuser() 'end_time' => $endtime, 'status' => $status, ); - + logSubscription($details); } } @@ -824,7 +826,7 @@ public function action_modifyuser() else { $subscription_status = getSubscriptionStatus($context['log_id']); - + // Pick the right permission stuff depending on what the status is changing from/to. if ($subscription_status['old_status'] == 1 && $status != 1) removeSubscription($context['sub_id'], $subscription_status['id_member']); @@ -839,7 +841,7 @@ public function action_modifyuser() 'end_time' => $endtime, 'status' => $status, 'current_log_item' => $context['log_id'] - ); + ); updateSubscriptionItem($item); } } diff --git a/sources/admin/ManagePermissions.php b/sources/admin/ManagePermissions.php index 8b70d87eea..c81ea50ba0 100644 --- a/sources/admin/ManagePermissions.php +++ b/sources/admin/ManagePermissions.php @@ -21,7 +21,7 @@ /** * ManagePermissions handles all possible permission stuff. */ -class ManagePermissions_Controller +class ManagePermissions_Controller extends Action_Controller { /** * Permissions settings form @@ -35,6 +35,8 @@ class ManagePermissions_Controller * Called by ?action=managepermissions. * * @uses ManagePermissions language file. + * + * @see Action_Controller::action_index() */ public function action_index() { diff --git a/sources/admin/ManagePosts.php b/sources/admin/ManagePosts.php index 4ad4b64e14..8c226e545f 100644 --- a/sources/admin/ManagePosts.php +++ b/sources/admin/ManagePosts.php @@ -22,7 +22,7 @@ * ManagePosts controller handles all the administration settings * for topics and posts. */ -class ManagePosts_Controller +class ManagePosts_Controller extends Action_Controller { /** * Posts settings form @@ -38,6 +38,8 @@ class ManagePosts_Controller * * Accessed from ?action=admin;area=postsettings. * Requires (and checks for) the admin_forum permission. + * + * @see Action_Controller::action_index() */ public function action_index() { diff --git a/sources/admin/ManageRegistration.php b/sources/admin/ManageRegistration.php index 2c0ead12ea..451dd81928 100644 --- a/sources/admin/ManageRegistration.php +++ b/sources/admin/ManageRegistration.php @@ -27,7 +27,7 @@ * to register a new member, to see and edit the registration agreement, * to set up reserved words for forum names. */ -class ManageRegistration_Controller +class ManageRegistration_Controller extends Action_Controller { /** * Registration settings form @@ -43,6 +43,8 @@ class ManageRegistration_Controller * * @uses Login language file * @uses Register template. + * + * @see Action_Controller::action_index() */ public function action_index() { @@ -174,7 +176,7 @@ public function action_register() foreach ($membergroups as $membergroup) $groups[$membergroup['id']] = $membergroup['name']; - $context['member_groups'] = $groups; + $context['member_groups'] = $groups; } else $context['member_groups'] = array(); diff --git a/sources/admin/ManageScheduledTasks.php b/sources/admin/ManageScheduledTasks.php index cc09ed97eb..7127e2928e 100644 --- a/sources/admin/ManageScheduledTasks.php +++ b/sources/admin/ManageScheduledTasks.php @@ -20,7 +20,7 @@ if (!defined('ELKARTE')) die('No access...'); -class ManageScheduledTasks_Controller +class ManageScheduledTasks_Controller extends Action_Controller { /** * Scheduled tasks management dispatcher. @@ -30,6 +30,8 @@ class ManageScheduledTasks_Controller * * @uses ManageScheduledTasks template file * @uses ManageScheduledTasks language file + * + * @see Action_Controller::action_index() */ public function action_index() { @@ -101,7 +103,7 @@ public function action_tasks() // We'll recalculate the dates at the end! require_once(SOURCEDIR . '/ScheduledTasks.php'); - + // Enable and disable as required. $enablers = array(0); @@ -127,7 +129,7 @@ public function action_tasks() // Load up the tasks. $nextTasks = loadTasks($tasks); - + // Lets get it on! require_once(SOURCEDIR . '/ScheduledTasks.php'); ignore_user_abort(true); diff --git a/sources/admin/ManageSearch.php b/sources/admin/ManageSearch.php index 9c8a67581c..7b693c0f0e 100644 --- a/sources/admin/ManageSearch.php +++ b/sources/admin/ManageSearch.php @@ -22,7 +22,7 @@ /** * ManageSearch controller admin class. */ -class ManageSearch_Controller +class ManageSearch_Controller extends Action_Controller { /** * Search settings form @@ -40,6 +40,8 @@ class ManageSearch_Controller * * @uses ManageSearch template. * @uses Search language file. + * + * @see Action_Controller::action_index() */ function action_index() { diff --git a/sources/admin/ManageSearchEngines.php b/sources/admin/ManageSearchEngines.php index 3d6444773e..9874949884 100644 --- a/sources/admin/ManageSearchEngines.php +++ b/sources/admin/ManageSearchEngines.php @@ -25,7 +25,7 @@ * This class handles all search engines pages in admin panel, * forwards to display and allows to change options. */ -class ManageSearchEngines_Controller +class ManageSearchEngines_Controller extends Action_Controller { /** * Search engines settings form @@ -35,6 +35,8 @@ class ManageSearchEngines_Controller /** * Entry point for this section. + * + * @see Action_Controller::action_index() */ function action_index() { diff --git a/sources/admin/ManageSecurity.php b/sources/admin/ManageSecurity.php index 85bc09eecd..27a0e706af 100644 --- a/sources/admin/ManageSecurity.php +++ b/sources/admin/ManageSecurity.php @@ -22,7 +22,7 @@ * ManageSecurity controller handles the Security and Moderation * pages in admin panel. */ -class ManageSecurity_Controller +class ManageSecurity_Controller extends Action_Controller { /** * Bad Behavior settings form. @@ -50,6 +50,8 @@ class ManageSecurity_Controller /** * This function passes control through to the relevant security tab. + * + * @see Action_Controller::action_index() */ public function action_index() { @@ -499,7 +501,7 @@ private function _initBBSettingsForm() // instantiate the form $this->_bbSettings = new Settings_Form(); - + // See if they supplied a valid looking http:BL API Key $context['invalid_badbehavior_httpbl_key'] = (!empty($modSettings['badbehavior_httpbl_key']) && (strlen($modSettings['badbehavior_httpbl_key']) !== 12 || !ctype_lower($modSettings['badbehavior_httpbl_key']))); @@ -683,7 +685,7 @@ public function spamSettings() public function bbSettings() { global $txt, $context, $modSettings; - + // See if they supplied a valid looking http:BL API Key $context['invalid_badbehavior_httpbl_key'] = (!empty($modSettings['badbehavior_httpbl_key']) && (strlen($modSettings['badbehavior_httpbl_key']) !== 12 || !ctype_lower($modSettings['badbehavior_httpbl_key']))); diff --git a/sources/admin/ManageServer.php b/sources/admin/ManageServer.php index d93ad321bc..b637a827b9 100644 --- a/sources/admin/ManageServer.php +++ b/sources/admin/ManageServer.php @@ -72,7 +72,7 @@ * It sends the data for display, and it allows the admin to change it. * */ -class ManageServer_Controller +class ManageServer_Controller extends Action_Controller { /** * Database settings form @@ -112,6 +112,8 @@ class ManageServer_Controller * Redirects to the appropriate function based on the sub-action. * * @uses edit_settings adminIndex. + * + * @see Action_Controller::action_index() */ public function action_index() { diff --git a/sources/admin/ManageSmileys.php b/sources/admin/ManageSmileys.php index b772fecd56..798aabc3cc 100644 --- a/sources/admin/ManageSmileys.php +++ b/sources/admin/ManageSmileys.php @@ -24,7 +24,7 @@ * This class is in charge with administration of smileys and message icons. * It handles actions from the Smileys pages in admin panel. */ -class ManageSmileys_Controller +class ManageSmileys_Controller extends Action_Controller { /** * Smileys configuration settings form @@ -39,6 +39,8 @@ class ManageSmileys_Controller /** * This is the dispatcher of smileys administration. + * + * @see Action_Controller::action_index() */ public function action_index() { diff --git a/sources/admin/ManageTopics.php b/sources/admin/ManageTopics.php index 02ed911622..29c1644fc0 100644 --- a/sources/admin/ManageTopics.php +++ b/sources/admin/ManageTopics.php @@ -15,7 +15,7 @@ /** * ManagePosts controller handles all the administration settings for topics and posts. */ -class ManageTopics_Controller +class ManageTopics_Controller extends Action_Controller { /** * Topic settings form @@ -23,6 +23,11 @@ class ManageTopics_Controller */ protected $_topicSettings; + /** + * Check permissions and forward to the right method. + * + * @see Action_Controller::action_index() + */ public function action_index() { // Only admins are allowed around here. diff --git a/sources/admin/Modlog.php b/sources/admin/Modlog.php index 20baf5935e..c6aa4f595d 100644 --- a/sources/admin/Modlog.php +++ b/sources/admin/Modlog.php @@ -26,15 +26,17 @@ * Depending on permissions, this class will display and allow to act on the log * for administrators or for moderators. */ -class Modlog_Controller +class Modlog_Controller extends Action_Controller { /** * Default method for this controller. + * + * @see Action_Controller::action_index() */ public function action_index() { // we haz nothing to do. :P - $this->action_modlog(); + $this->action_log(); } /** @@ -46,7 +48,7 @@ public function action_index() * * @uses Modlog template, main sub-template. */ - public function action_modlog() + public function action_log() { global $txt, $context, $scripturl; diff --git a/sources/admin/PackageServers.php b/sources/admin/PackageServers.php index 4a73a46a01..f8237d3167 100644 --- a/sources/admin/PackageServers.php +++ b/sources/admin/PackageServers.php @@ -24,10 +24,13 @@ * PackageServers controller handles browsing, adding and removing * package servers, and download of a package from them. */ -class PackageServers_Controller +class PackageServers_Controller extends Action_Controller { /** - * Browse the list of package servers, add servers... + * Main dispatcher for package servers. Checks permissions, + * load files, and forwards to the right method. + * + * @see Action_Controller::action_index() */ public function action_index() { @@ -198,7 +201,7 @@ public function action_browse() $packageserver = fetchPackageServers($server); $url = $packageserver[0]['url']; $name = $packageserver[0]['name']; - + // If the server does not exist, dump out. if (empty($url)) fatal_lang_error('couldnt_connect', false); diff --git a/sources/admin/Packages.php b/sources/admin/Packages.php index c2abbb2cb3..7f78649f7b 100644 --- a/sources/admin/Packages.php +++ b/sources/admin/Packages.php @@ -25,10 +25,12 @@ * Its main job is to install/uninstall, allow to browse, packages and package servers. * In fact, just about everything related to add-on packages, including FTP connections when necessary. */ -class Packages_Controller +class Packages_Controller extends Action_Controller { /** * Entry point, the default method of this controller. + * + * @see Action_Controller::action_index() */ public function action_index() { diff --git a/sources/admin/RepairBoards.php b/sources/admin/RepairBoards.php index d2c867b66c..2e3ce88fbe 100644 --- a/sources/admin/RepairBoards.php +++ b/sources/admin/RepairBoards.php @@ -24,10 +24,12 @@ * Repair boards controller handles a special admin action: * boards and categories attempt to repair, from maintenance. */ -class RepairBoards_Controller +class RepairBoards_Controller extends Action_Controller { /** * Default method. + * + * @see Action_Controller::action_index() */ function action_index() { diff --git a/sources/admin/Reports.php b/sources/admin/Reports.php index 70a59195bd..8634453ce8 100644 --- a/sources/admin/Reports.php +++ b/sources/admin/Reports.php @@ -28,7 +28,7 @@ if (!defined('ELKARTE')) die('No access...'); -class Reports_Controller +class Reports_Controller extends Action_Controller { /** * Handling function for generating reports. @@ -43,6 +43,8 @@ class Reports_Controller * Will call the relevant report generation function. * If generating report will call finishTables before returning. * Accessed through ?action=admin;area=reports. + * + * @see Action_Controller::action_index() */ function action_index() { diff --git a/sources/controllers/ModerationCenter.controller.php b/sources/controllers/ModerationCenter.controller.php index 705f26896c..30cac52fb0 100644 --- a/sources/controllers/ModerationCenter.controller.php +++ b/sources/controllers/ModerationCenter.controller.php @@ -1804,7 +1804,7 @@ function action_modcenter($dont_call = false) 'enabled' => !empty($modSettings['modlog_enabled']) && $context['can_moderate_boards'], 'file' => 'admin/Modlog.php', 'controller' => 'Modlog_Controller', - 'function' => 'action_modlog', + 'function' => 'action_log', ), 'warnings' => array( 'label' => $txt['mc_warnings'], diff --git a/sources/subs/Modlog.subs.php b/sources/subs/Modlog.subs.php index 7c0c5c99b4..eb4aa33da6 100644 --- a/sources/subs/Modlog.subs.php +++ b/sources/subs/Modlog.subs.php @@ -22,7 +22,7 @@ /** * Get the number of mod log entries. - * Callback for createList() in action_modlog(). + * Callback for createList() in Modlog::action_log(). * * @param $query_string * @param $query_params @@ -61,7 +61,7 @@ function list_getModLogEntryCount($query_string = '', $query_params = array(), $ /** * Gets the moderation log entries that match the specified parameters. - * Callback for createList() in action_modlog(). + * Callback for createList() in Modlog::action_log(). * * @param $start * @param $items_per_page From 5c95d4bd5ecdcc942201efa26111cabde89cb8a4 Mon Sep 17 00:00:00 2001 From: Norv Date: Fri, 21 Jun 2013 21:49:25 +0300 Subject: [PATCH 03/34] Make two dozen user/mod controllers extend Action_Controller. Add index where missing. Signed-off-by: Norv --- sources/controllers/Announce.controller.php | 6 ++--- sources/controllers/Auth.controller.php | 14 +++++++++- sources/controllers/BoardIndex.controller.php | 17 +++++++++--- sources/controllers/Calendar.controller.php | 6 +++-- sources/controllers/Draft.controller.php | 15 +++++++++-- sources/controllers/Emailpost.controller.php | 15 ++++++++++- sources/controllers/Emailuser.controller.php | 9 ++++--- sources/controllers/Groups.controller.php | 6 +++-- sources/controllers/Help.controller.php | 6 +++-- sources/controllers/Karma.controller.php | 27 ++++++++++++++----- sources/controllers/Likes.controller.php | 14 +++++++++- sources/controllers/Markasread.controller.php | 4 ++- sources/controllers/Memberlist.controller.php | 4 ++- sources/controllers/Members.controller.php | 13 ++++++++- .../controllers/MergeTopics.controller.php | 4 ++- .../controllers/MessageIndex.controller.php | 15 +++++++++-- .../ModerateAttachments.controller.php | 16 +++++++++-- sources/controllers/MoveTopic.controller.php | 15 +++++++++-- sources/controllers/News.controller.php | 15 +++++++++-- 19 files changed, 182 insertions(+), 39 deletions(-) diff --git a/sources/controllers/Announce.controller.php b/sources/controllers/Announce.controller.php index 7d027511c7..65899b73c5 100644 --- a/sources/controllers/Announce.controller.php +++ b/sources/controllers/Announce.controller.php @@ -20,15 +20,15 @@ if (!defined('ELKARTE')) die('No access...'); -class Announce_Controller +class Announce_Controller extends Action_Controller { /** * Default (sub)action for ?action=announce + * + * @see Action_Controller::action_index() */ public function action_index() { - loadLanguage('Post'); - // default for action=announce: action_selectgroup() function. $this->action_selectgroup(); } diff --git a/sources/controllers/Auth.controller.php b/sources/controllers/Auth.controller.php index 69a92d4160..22a8662d31 100644 --- a/sources/controllers/Auth.controller.php +++ b/sources/controllers/Auth.controller.php @@ -21,8 +21,20 @@ if (!defined('ELKARTE')) die('No access...'); -class Auth_Controller +class Auth_Controller extends Action_Controller { + /** + * Entry point in Auth controller + * (well no, not really. We route directly to the rest.) + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // what can we do? login page! + $this->action_login(); + } + /** * Ask them for their login information. (shows a page for the user to type * in their username and password.) diff --git a/sources/controllers/BoardIndex.controller.php b/sources/controllers/BoardIndex.controller.php index ea968984c2..950d261041 100644 --- a/sources/controllers/BoardIndex.controller.php +++ b/sources/controllers/BoardIndex.controller.php @@ -20,8 +20,19 @@ if (!defined('ELKARTE')) die('No access...'); -class BoardIndex_Controller +class BoardIndex_Controller extends Action_Controller { + /** + * Forwards to the action to execute here by default. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // what to do... boardindex, 'course! + $this->action_boardindex(); + } + /** * This function shows the board index. * It uses the BoardIndex template, and main sub template. @@ -29,7 +40,7 @@ class BoardIndex_Controller * It updates the most online statistics. * It is accessed by ?action=boardindex. */ - function action_boardindex() + public function action_boardindex() { global $txt, $user_info, $modSettings, $context, $settings, $scripturl; @@ -124,7 +135,7 @@ function action_boardindex() * Collapse or expand a category * ?action=collapse */ - function action_collapse() + public function action_collapse() { global $user_info, $context; diff --git a/sources/controllers/Calendar.controller.php b/sources/controllers/Calendar.controller.php index cd94e6ea5c..0c7bc42cc2 100644 --- a/sources/controllers/Calendar.controller.php +++ b/sources/controllers/Calendar.controller.php @@ -20,17 +20,19 @@ if (!defined('ELKARTE')) die('No access...'); -class Calendar_Controller +class Calendar_Controller extends Action_Controller { /** * Default action handler for requests on the calendar + * + * @see Action_Controller::action_index() */ public function action_index() { // when you don't know what you're doing... we know! :P $this->action_calendar(); } - + /** * Show the calendar. * It loads the specified month's events, holidays, and birthdays. diff --git a/sources/controllers/Draft.controller.php b/sources/controllers/Draft.controller.php index 87ace94102..7abc963e20 100644 --- a/sources/controllers/Draft.controller.php +++ b/sources/controllers/Draft.controller.php @@ -6,7 +6,7 @@ * @license BSD http://opensource.org/licenses/BSD-3-Clause * * @version 1.0 Alpha - * + * */ if (!defined('ELKARTE')) @@ -17,8 +17,19 @@ * This class handles requests that allow for the saving, * retrieving, deleting and settings for the drafts functionality. */ -class Draft_Controller +class Draft_Controller extends Action_Controller { + /** + * Default method, just forwards, if we ever get here. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // where do you want to go today? :P + $this->action_showProfileDrafts(); + } + /** * This method is executed before any action handler. * Loads language, common needed stuffs. diff --git a/sources/controllers/Emailpost.controller.php b/sources/controllers/Emailpost.controller.php index 60d2eaf0bf..1b69d9e9c5 100644 --- a/sources/controllers/Emailpost.controller.php +++ b/sources/controllers/Emailpost.controller.php @@ -16,8 +16,19 @@ /** * Post-by-email controller. */ -class Emailpost_Controller +class Emailpost_Controller extends Action_Controller { + /** + * Default entry point, it forwards to a worker method, + * if we ever get here. + * @see Action_Controller::action_index() + */ + public function action_index() + { + // default, default, by default... preview + $this->action_pbe_preview(); + } + /** * Main email posting controller, reads, parses, checks and posts an email message or PM * Allows a user to reply to a topic on the board by emailing a reply to a @@ -26,6 +37,7 @@ class Emailpost_Controller * - It must be from the email of a registered user * - The key must have been sent to that user * - Keys are used once and then discarded + * Accessed by email imap cron script, and ManageMaillist.php. * * @param string $data used to supply a full body+headers email * @param boolean $force used to override common failure errors @@ -175,6 +187,7 @@ function action_pbe_post($data = null, $force = false, $key = null) * - New topics do not have security keys in them so they are subject to spoofing * - It must be from the email of a registered user * - It must have been sent to an email ID that has been set to post new topics + * Accessed through emailtopic. * * @param string $data used to supply a full body+headers email * @param type $force used to override common failure errors diff --git a/sources/controllers/Emailuser.controller.php b/sources/controllers/Emailuser.controller.php index a14d5c54d0..f50ef7e9a7 100644 --- a/sources/controllers/Emailuser.controller.php +++ b/sources/controllers/Emailuser.controller.php @@ -21,7 +21,7 @@ if (!defined('ELKARTE')) die('No access...'); -class Emailuser_Controller +class Emailuser_Controller extends Action_Controller { /** * This function initializes or sets up the necessary, for the other actions @@ -38,11 +38,12 @@ function pre_dispatch() } /** - * Default action handler (when no ;sa is specified) + * Default action handler + * @see Action_Controller::action_index() */ - function action_emailuser() + function action_index() { - // default action: action_sendtopic() + // just accept we haz a default action: action_sendtopic() $this->action_sendtopic(); } diff --git a/sources/controllers/Groups.controller.php b/sources/controllers/Groups.controller.php index 07df18d41c..c170623736 100644 --- a/sources/controllers/Groups.controller.php +++ b/sources/controllers/Groups.controller.php @@ -20,11 +20,13 @@ if (!defined('ELKARTE')) die('No access...'); -class Groups_Controller +class Groups_Controller extends Action_Controller { /** * Entry point to groups. * It allows moderators and users to access the group showing functions. + * + * @see Action_Controller::action_index() */ function action_index() { @@ -40,7 +42,7 @@ function action_index() public function pre_dispatch() { global $context, $txt, $scripturl, $user_info; - + // Get the template stuff up and running. loadLanguage('ManageMembers'); loadLanguage('ModerationCenter'); diff --git a/sources/controllers/Help.controller.php b/sources/controllers/Help.controller.php index f5595f54ab..e23ec9356e 100644 --- a/sources/controllers/Help.controller.php +++ b/sources/controllers/Help.controller.php @@ -23,17 +23,19 @@ /** * Class to handle the help page and boxes */ -class Help_Controller +class Help_Controller extends Action_Controller { /** * Default action handler: just help. + * + * @see Action_Controller::action_index() */ public function action_index() { // I need help! $this->action_help(); } - + /** * Prepares the help page. * Uses Help template and Manual language file. diff --git a/sources/controllers/Karma.controller.php b/sources/controllers/Karma.controller.php index 0ecdd1cd8b..982ebed070 100644 --- a/sources/controllers/Karma.controller.php +++ b/sources/controllers/Karma.controller.php @@ -18,14 +18,26 @@ if (!defined('ELKARTE')) die('No access...'); -class Karma_Controller +class Karma_Controller extends Action_Controller { /** - * Modify a user's karma. - * It redirects back to the referrer afterward, whether by javascript or the passed parameters. - * Requires the karma_edit permission, and that the user isn't a guest. - * It depends on the karmaMode, karmaWaitTime, and karmaTimeRestrictAdmins settings. - * It is accessed via ?action=karma, sa=smite or sa=applaud. + * Default entry point, in case action methods aren't directly + * called. Simply forward to applaud. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // Applauds for us :P + $this->action_applaud(); + } + + /** + * Modify a user's karma. + * It redirects back to the referrer afterward, whether by javascript or the passed parameters. + * Requires the karma_edit permission, and that the user isn't a guest. + * It depends on the karmaMode, karmaWaitTime, and karmaTimeRestrictAdmins settings. + * It is accessed via ?action=karma, sa=smite or sa=applaud. */ function action_applaud() { @@ -41,6 +53,9 @@ function action_applaud() redirect_karma(); } + /** + * Smite a user. + */ function action_smite() { global $user_info; diff --git a/sources/controllers/Likes.controller.php b/sources/controllers/Likes.controller.php index c3f75d83f0..48c97e5ea5 100644 --- a/sources/controllers/Likes.controller.php +++ b/sources/controllers/Likes.controller.php @@ -15,8 +15,20 @@ /** * This class contains one likable use, which allows members to like a post */ -class Likes_Controller +class Likes_Controller extends Action_Controller { + /** + * Default action method, if a specific methods wasn't + * directly called already. Simply forwards to likepost. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // We like you. + $this->action_likepost(); + } + /** * Entry point function for likes, permission checks, just makes sure its on */ diff --git a/sources/controllers/Markasread.controller.php b/sources/controllers/Markasread.controller.php index cf4f791d5b..698dd8eed4 100644 --- a/sources/controllers/Markasread.controller.php +++ b/sources/controllers/Markasread.controller.php @@ -15,10 +15,12 @@ /** * This class handles a part of the actions to mark boards, topics, or replies, as read/unread. */ -class MarkRead_Controller +class MarkRead_Controller extends Action_Controller { /** * This is the main function for markasread file. + * + * @see Action_Controller::action_index() */ public function action_index() { diff --git a/sources/controllers/Memberlist.controller.php b/sources/controllers/Memberlist.controller.php index dc45f6fbc7..fb2cbb450a 100644 --- a/sources/controllers/Memberlist.controller.php +++ b/sources/controllers/Memberlist.controller.php @@ -26,13 +26,15 @@ /** * Memberlist Controller */ -class Memberlist_Controller +class Memberlist_Controller extends Action_Controller { /** * Sets up the context for showing a listing of registered members. * For the handlers in this file, it requires the view_mlist permission. * * @uses Memberlist template, main sub-template. + * + * @see Action_Controller::action_index() */ function action_index() { diff --git a/sources/controllers/Members.controller.php b/sources/controllers/Members.controller.php index 397a5f8c0e..7d8b21b6c7 100644 --- a/sources/controllers/Members.controller.php +++ b/sources/controllers/Members.controller.php @@ -23,8 +23,19 @@ /** * Members Controller */ -class Members_Controller +class Members_Controller extends Action_Controller { + /** + * Forwards to an action method. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // I don't think we know what to do... throw dies? + $this->action_buddy(); + } + /** * This simple function adds/removes the passed user from the current users buddy list. * Requires profile_identity_own permission. diff --git a/sources/controllers/MergeTopics.controller.php b/sources/controllers/MergeTopics.controller.php index d520ae6036..a65e27333f 100644 --- a/sources/controllers/MergeTopics.controller.php +++ b/sources/controllers/MergeTopics.controller.php @@ -21,7 +21,7 @@ if (!defined('ELKARTE')) die('No access...'); -class MergeTopics_Controller +class MergeTopics_Controller extends Action_Controller { /** * Merges two or more topics into one topic. @@ -29,6 +29,8 @@ class MergeTopics_Controller * loads the MergeTopics template. * requires the merge_any permission. * is accessed with ?action=mergetopics. + * + * @see Action_Controller::action_index() */ function action_index() { diff --git a/sources/controllers/MessageIndex.controller.php b/sources/controllers/MessageIndex.controller.php index 9ac6a22f4d..7d349d7025 100644 --- a/sources/controllers/MessageIndex.controller.php +++ b/sources/controllers/MessageIndex.controller.php @@ -24,8 +24,19 @@ /** * Message Index Controller */ -class MessageIndex_Controller +class MessageIndex_Controller extends Action_Controller { + /** + * Dispatches forward to message index handler. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // forward to message index, it's not like we know much more :P + $this->action_messageindex(); + } + /** * Show the list of topics in this board, along with any child boards. */ @@ -1018,7 +1029,7 @@ function action_quickmod() logAction($lockStatus[$topic] ? 'lock' : 'unlock', array('topic' => $topic, 'board' => $lockCacheBoards[$topic])); sendNotifications($topic, $lockStatus[$topic] ? 'lock' : 'unlock'); } - + foreach ($stickyCache as $topic) { logAction($stickyCacheStatus[$topic] ? 'unsticky' : 'sticky', array('topic' => $topic, 'board' => $stickyCacheBoards[$topic])); diff --git a/sources/controllers/ModerateAttachments.controller.php b/sources/controllers/ModerateAttachments.controller.php index ebed1a7ad9..f0bf31df9e 100644 --- a/sources/controllers/ModerateAttachments.controller.php +++ b/sources/controllers/ModerateAttachments.controller.php @@ -21,8 +21,20 @@ /** * Moderate Attachments Controller */ -class ModerateAttachments_Controller +class ModerateAttachments_Controller extends Action_Controller { + /** + * Forward to attachments approval method, the only responsibility + * of this controller. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // forward to our method(s) to do the job + $this->action_attachapprove(); + } + /** * Called from a mouse click, * works out what we want to do with attachments and actions it. @@ -41,7 +53,7 @@ function action_attachapprove() $is_approve = !isset($_GET['sa']) || $_GET['sa'] != 'reject' ? true : false; $attachments = array(); - + // If we are approving all ID's in a message , get the ID's. if ($_GET['sa'] == 'all' && !empty($_GET['mid'])) { diff --git a/sources/controllers/MoveTopic.controller.php b/sources/controllers/MoveTopic.controller.php index 9290cf57af..27b463a318 100644 --- a/sources/controllers/MoveTopic.controller.php +++ b/sources/controllers/MoveTopic.controller.php @@ -21,8 +21,19 @@ /** * Move Topic Controller */ -class MoveTopic_Controller +class MoveTopic_Controller extends Action_Controller { + /** + * Forwards to the action method to handle the action. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // move a topic, what else?! + $this->action_movetopic(); + } + /** * This function allows to move a topic, making sure to ask the moderator * to give reason for topic move. @@ -271,7 +282,7 @@ function action_movetopic2() 'redirect_expires' => $redirect_expires, 'redirect_topic' => $redirect_topic, ); - + $posterOptions = array( 'id' => $user_info['id'], 'update_post_count' => empty($board_info['count_posts']), diff --git a/sources/controllers/News.controller.php b/sources/controllers/News.controller.php index 81b9be6030..038c7f8970 100644 --- a/sources/controllers/News.controller.php +++ b/sources/controllers/News.controller.php @@ -23,8 +23,19 @@ /** * News Controller */ -class News_Controller +class News_Controller extends Action_Controller { + /** + * Dispatcher. Forwards to the action to execute. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // do... something, of your favorite, like xmlnews. + $this->action_xmlnews(); + } + /** * Outputs xml data representing recent information or a profile. * Can be passed 4 subactions which decide what is output: @@ -922,7 +933,7 @@ function cdata_parse($data, $ns = '') if ($pos2 === false) $pos2 = $n; - + $ent = Util::substr($data, $pos + 1, $pos2 - $pos - 1); if (Util::substr($data, $pos + 1, 1) == '#') From ac269a7a70be1694f37d809afd423afb6b07032a Mon Sep 17 00:00:00 2001 From: Norv Date: Fri, 21 Jun 2013 22:46:26 +0300 Subject: [PATCH 04/34] Update more user controllers to extend the base class. Signed-off-by: Norv --- sources/controllers/MoveTopic.controller.php | 2 +- sources/controllers/News.controller.php | 4 ++-- sources/controllers/Notify.controller.php | 13 ++++++++++++- sources/controllers/OpenID.controller.php | 13 ++++++++++++- sources/controllers/PersonalMessage.controller.php | 7 +++++-- sources/controllers/Poll.controller.php | 12 +++++++++++- sources/controllers/Post.controller.php | 13 ++++++++++++- 7 files changed, 55 insertions(+), 9 deletions(-) diff --git a/sources/controllers/MoveTopic.controller.php b/sources/controllers/MoveTopic.controller.php index 27b463a318..941a7dacd7 100644 --- a/sources/controllers/MoveTopic.controller.php +++ b/sources/controllers/MoveTopic.controller.php @@ -31,7 +31,7 @@ class MoveTopic_Controller extends Action_Controller public function action_index() { // move a topic, what else?! - $this->action_movetopic(); + // $this->action_movetopic(); } /** diff --git a/sources/controllers/News.controller.php b/sources/controllers/News.controller.php index 038c7f8970..43499ea638 100644 --- a/sources/controllers/News.controller.php +++ b/sources/controllers/News.controller.php @@ -32,8 +32,8 @@ class News_Controller extends Action_Controller */ public function action_index() { - // do... something, of your favorite, like xmlnews. - $this->action_xmlnews(); + // do... something, of your favorite. + // $this->action_xmlnews(); } /** diff --git a/sources/controllers/Notify.controller.php b/sources/controllers/Notify.controller.php index 22a7d3fd66..4546723bf7 100644 --- a/sources/controllers/Notify.controller.php +++ b/sources/controllers/Notify.controller.php @@ -24,8 +24,19 @@ /** * Notify Controller */ -class Notify_Controller +class Notify_Controller extends Action_Controller { + /** + * Dispatch to the right action. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // forward to our respective method. + // $this->action_notify(); + } + /** * Turn off/on notification for a particular topic. * Must be called with a topic specified in the URL. diff --git a/sources/controllers/OpenID.controller.php b/sources/controllers/OpenID.controller.php index a1cbf0a032..83cab484de 100644 --- a/sources/controllers/OpenID.controller.php +++ b/sources/controllers/OpenID.controller.php @@ -19,8 +19,19 @@ /** * OpenID controller. */ -class OpenID_Controller +class OpenID_Controller extends Action_Controller { + /** + * Forward to the right action. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // we only know one thing and know it well :P + $this->action_openidreturn(); + } + /** * Callback action handler for OpenID */ diff --git a/sources/controllers/PersonalMessage.controller.php b/sources/controllers/PersonalMessage.controller.php index 6f3211aa8e..a4490ea26f 100644 --- a/sources/controllers/PersonalMessage.controller.php +++ b/sources/controllers/PersonalMessage.controller.php @@ -25,13 +25,16 @@ /** * Personal Message Controller */ -class PersonalMessage_Controller +class PersonalMessage_Controller extends Action_Controller { /** * This is the main function of personal messages, called before the action handler. * PersonalMessages is a menu-based controller. - * It sets up the menu. @todo and call from the menu the appropriate method/function + * It sets up the menu. + * @todo and call from the menu the appropriate method/function * for the current area. + * + * @see Action_Controller::action_index() */ function action_index() { diff --git a/sources/controllers/Poll.controller.php b/sources/controllers/Poll.controller.php index bd6a9dd383..ef82c36d9e 100644 --- a/sources/controllers/Poll.controller.php +++ b/sources/controllers/Poll.controller.php @@ -24,8 +24,18 @@ * editing polls. Note that that posting polls is done in * Post.controller.php. */ -class Poll_Controller +class Poll_Controller extends Action_Controller { + /** + * Forward to the right action. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // Figure out the right action to do. + } + /** * Allow the user to vote. * It is called to register a vote in a poll. diff --git a/sources/controllers/Post.controller.php b/sources/controllers/Post.controller.php index 5955d26655..7786a2f20d 100644 --- a/sources/controllers/Post.controller.php +++ b/sources/controllers/Post.controller.php @@ -25,8 +25,19 @@ /** * Post Controller */ -class Post_Controller +class Post_Controller extends Action_Controller { + /** + * Dispatch to the right action method for the request. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // figure out the right action to do. + // hint: I'm post controller. :P + } + /** * Handles showing the post screen, loading the post to be modified, and loading any post quoted. * From b6aa853853f96006b2de23f6a08d2182b6beb6f2 Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 00:25:42 +0300 Subject: [PATCH 05/34] Refactor to action controller subclasses. Tweak modcenter. Signed-off-by: Norv --- sources/Dispatcher.class.php | 2 +- sources/controllers/Groups.controller.php | 3 ++- sources/controllers/PostModeration.controller.php | 14 ++++++++------ sources/controllers/Profile.controller.php | 6 ++++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/sources/Dispatcher.class.php b/sources/Dispatcher.class.php index 5b3beacdce..1de52c3d42 100644 --- a/sources/Dispatcher.class.php +++ b/sources/Dispatcher.class.php @@ -158,7 +158,7 @@ public function __construct() 'markasread' => array('Markasread.controller.php', 'MarkRead_Controller', 'action_index'), 'mergetopics' => array('MergeTopics.controller.php', 'MergeTopics_Controller', 'action_index'), 'memberlist' => array('Memberlist.controller.php', 'Memberlist_Controller', 'action_index'), - 'moderate' => array('ModerationCenter.controller.php', 'ModerationCenter_Controller', 'action_modcenter'), + 'moderate' => array('ModerationCenter.controller.php', 'ModerationCenter_Controller', 'action_index'), 'karma' => array('Karma.controller.php', 'Karma_Controller', ''), 'movetopic' => array('MoveTopic.controller.php', 'MoveTopic_Controller', 'action_movetopic'), 'movetopic2' => array('MoveTopic.controller.php', 'MoveTopic_Controller', 'action_movetopic2'), diff --git a/sources/controllers/Groups.controller.php b/sources/controllers/Groups.controller.php index c170623736..c45cf98d5f 100644 --- a/sources/controllers/Groups.controller.php +++ b/sources/controllers/Groups.controller.php @@ -53,7 +53,8 @@ public function pre_dispatch() { require_once(CONTROLLERDIR . '/ModerationCenter.controller.php'); $_GET['area'] = (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'requests') ? 'groups' : 'viewgroups'; - action_modcenter(true); + $controller = new ModerationCenter_Controller(); + $controller->prepareModcenter(); } // Otherwise add something to the link tree, for normal people. else diff --git a/sources/controllers/PostModeration.controller.php b/sources/controllers/PostModeration.controller.php index 1acf70b941..0ef15d86dd 100644 --- a/sources/controllers/PostModeration.controller.php +++ b/sources/controllers/PostModeration.controller.php @@ -21,12 +21,14 @@ /** * PostModeration Controller handles post moderation actions. (approvals, unapprovals) */ -class PostModeration_Controller +class PostModeration_Controller extends Action_Controller { /** - * This is a handling function for all things post moderation. + * This is the entry point for all things post moderation. + * + * @see Action_Controller::action_index() */ - function action_postmoderation() + public function action_index() { // @todo We'll shift these later bud. loadLanguage('ModerationCenter'); @@ -50,7 +52,7 @@ function action_postmoderation() /** * View all unapproved posts. */ - function action_unapproved() + public function action_unapproved() { global $txt, $scripturl, $context, $user_info; @@ -288,7 +290,7 @@ function action_unapproved() /** * View all unapproved attachments. */ - function action_unapproved_attachments() + public function action_unapproved_attachments() { global $txt, $scripturl, $context, $user_info, $modSettings; @@ -496,7 +498,7 @@ function action_unapproved_attachments() /** * Approve a post, just the one. */ - function action_approve() + public function action_approve() { global $user_info, $topic, $board; diff --git a/sources/controllers/Profile.controller.php b/sources/controllers/Profile.controller.php index 3b10e792a7..8bb74cc087 100644 --- a/sources/controllers/Profile.controller.php +++ b/sources/controllers/Profile.controller.php @@ -22,13 +22,15 @@ if (!defined('ELKARTE')) die('No access...'); -class Profile_Controller +class Profile_Controller extends Action_Controller { /** * Allow the change or view of profiles. * Loads the profile menu. + * + * @see Action_Controller::action_index() */ - function action_index() + public function action_index() { global $txt, $scripturl, $user_info, $context, $user_profile, $cur_profile; global $modSettings, $memberContext, $profile_vars, $post_errors, $user_settings; From dda2464d7ff3173662383745fedfd12ef9e79e7d Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 01:12:40 +0300 Subject: [PATCH 06/34] Rework createList() callbacks in moderation center controller: instance methods for the list, and database-working functions for the db work involved. Wip cleaning globals from subs (tweaks should be in list_() methods.) Signed-off-by: Norv --- sources/admin/ManageMaillist.php | 27 +- .../ModerationCenter.controller.php | 773 ++++++++---------- sources/subs/Moderation.subs.php | 242 +++++- 3 files changed, 594 insertions(+), 448 deletions(-) diff --git a/sources/admin/ManageMaillist.php b/sources/admin/ManageMaillist.php index 03d876f3e8..abdac533c9 100644 --- a/sources/admin/ManageMaillist.php +++ b/sources/admin/ManageMaillist.php @@ -1344,11 +1344,11 @@ public function action_view_bounce_templates() 'base_href' => $scripturl . '?action=admin;area=maillist;sa=emailtemplates;' . $context['session_var'] . '=' . $context['session_id'], 'default_sort_col' => 'title', 'get_items' => array( - 'function' => 'list_getWarningTemplates', + 'function' => array($this, 'list_getWarningTemplates'), 'params' => array('bnctpl'), ), 'get_count' => array( - 'function' => 'list_getWarningTemplateCount', + 'function' => array($this, 'list_getWarningTemplateCount'), 'params' => array('bnctpl'), ), 'columns' => array( @@ -1537,4 +1537,27 @@ public function action_modify_bounce_templates() createToken('mod-mlt'); } + + /** + * Callback for createList() to get all the templates of a type from the system + * + * @param $start + * @param $items_per_page + * @param $sort + * @param $template_type type of template to load + */ + function list_getWarningTemplates($start, $items_per_page, $sort, $template_type = 'warntpl') + { + return warningTemplates($start, $items_per_page, $sort, $template_type); + } + + /** + * Callback for createList() to get the number of templates of a type in the system + * + * @param string $template_type + */ + function list_getWarningTemplateCount($template_type = 'warntpl') + { + return warningTemplateCount($template_type); + } } \ No newline at end of file diff --git a/sources/controllers/ModerationCenter.controller.php b/sources/controllers/ModerationCenter.controller.php index 30cac52fb0..01a2f4edc6 100644 --- a/sources/controllers/ModerationCenter.controller.php +++ b/sources/controllers/ModerationCenter.controller.php @@ -23,8 +23,240 @@ /** * Moderation Center Controller */ -class ModerationCenter_Controller +class ModerationCenter_Controller extends Action_Controller { + private $_mod_include_data; + + /** + * Entry point for the moderation center. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // Set up moderation menu. + $this->prepareModcenter(); + + // Now call the menu action. + if (isset($this->_mod_include_data['file'])) + require_once(SOURCEDIR . '/' . $this->_mod_include_data['file']); + + callMenu($this->_mod_include_data); + } + + /** + * Prepare menu, make checks, load files, and create moderation menu. + * This can be called from the class, or from outside, to + * set up moderation menu. + */ + public function prepareModcenter() + { + global $txt, $context, $scripturl, $modSettings, $user_info, $options; + + // Don't run this twice... and don't conflict with the admin bar. + if (isset($context['admin_area'])) + return; + + $context['can_moderate_boards'] = $user_info['mod_cache']['bq'] != '0=1'; + $context['can_moderate_groups'] = $user_info['mod_cache']['gq'] != '0=1'; + $context['can_moderate_approvals'] = $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']); + + // Everyone using this area must be allowed here! + if (!$context['can_moderate_boards'] && !$context['can_moderate_groups'] && !$context['can_moderate_approvals']) + isAllowedTo('access_mod_center'); + + // We're gonna want a menu of some kind. + require_once(SUBSDIR . '/Menu.subs.php'); + + // Load the language, and the template. + loadLanguage('ModerationCenter'); + loadTemplate(false, 'admin'); + + $context['admin_preferences'] = !empty($options['admin_preferences']) ? unserialize($options['admin_preferences']) : array(); + $context['robot_no_index'] = true; + + // Moderation counts for things that this moderator can take care of + require_once(SUBSDIR . '/Moderation.subs.php'); + $mod_counts = loadModeratorMenuCounts(); + + // This is the menu structure - refer to subs/Menu.subs.php for the details. + $moderation_areas = array( + 'main' => array( + 'title' => $txt['mc_main'], + 'areas' => array( + 'index' => array( + 'label' => $txt['moderation_center'], + 'controller' => 'ModerationCenter_Controller', + 'function' => 'action_moderationHome', + ), + 'settings' => array( + 'label' => $txt['mc_settings'], + 'controller' => 'ModerationCenter_Controller', + 'function' => 'action_moderationSettings', + ), + 'modlogoff' => array( + 'label' => $txt['mc_logoff'], + 'controller' => 'ModerationCenter_Controller', + 'function' => 'action_modEndSession', + 'enabled' => empty($modSettings['securityDisable_moderate']), + ), + 'notice' => array( + 'controller' => 'ModerationCenter_Controller', + 'function' => 'action_showNotice', + 'select' => 'index' + ), + ), + ), + 'logs' => array( + 'title' => $txt['mc_logs'], + 'areas' => array( + 'modlog' => array( + 'label' => $txt['modlog_view'], + 'enabled' => !empty($modSettings['modlog_enabled']) && $context['can_moderate_boards'], + 'file' => 'admin/Modlog.php', + 'controller' => 'Modlog_Controller', + 'function' => 'action_log', + ), + 'warnings' => array( + 'label' => $txt['mc_warnings'], + 'enabled' => in_array('w', $context['admin_features']) && !empty($modSettings['warning_enable']) && $context['can_moderate_boards'], + 'controller' => 'ModerationCenter_Controller', + 'function' => 'action_viewWarnings', + 'subsections' => array( + 'log' => array($txt['mc_warning_log']), + 'templates' => array($txt['mc_warning_templates'], 'issue_warning'), + ), + ), + ), + ), + 'posts' => array( + 'title' => $txt['mc_posts'] . (!empty($mod_counts['total']) ? ' [' . $mod_counts['total'] . ']' : ''), + 'enabled' => $context['can_moderate_boards'] || $context['can_moderate_approvals'], + 'areas' => array( + 'postmod' => array( + 'label' => $txt['mc_unapproved_posts'] . (!empty($mod_counts['postmod']) ? ' [' . $mod_counts['postmod'] . ']' : ''), + 'enabled' => $context['can_moderate_approvals'], + 'file' => 'controllers/PostModeration.controller.php', + 'controller' => 'PostModeration_Controller', + 'function' => 'action_index', + 'custom_url' => $scripturl . '?action=moderate;area=postmod', + 'subsections' => array( + 'posts' => array($txt['mc_unapproved_replies']), + 'topics' => array($txt['mc_unapproved_topics']), + ), + ), + 'emailmod' => array( + 'label' => $txt['mc_emailerror'] . (!empty($mod_counts['emailmod']) ? ' [' . $mod_counts['emailmod'] . ']' : ''), + 'enabled' => !empty($modSettings['maillist_enabled']) && allowedTo('approve_emails'), + 'file' => 'admin/ManageMaillist.php', + 'function' => 'UnapprovedEmails', + 'custom_url' => $scripturl . '?action=admin;area=maillist;sa=emaillist', + ), + 'attachmod' => array( + 'label' => $txt['mc_unapproved_attachments'] . (!empty($mod_counts['attachments']) ? ' [' . $mod_counts['attachments'] . ']' : ''), + 'enabled' => $context['can_moderate_approvals'], + 'file' => 'controllers/PostModeration.controller.php', + 'controller' => 'PostModeration_Controller', + 'function' => 'action_index', + 'custom_url' => $scripturl . '?action=moderate;area=attachmod;sa=attachments', + ), + 'reports' => array( + 'label' => $txt['mc_reported_posts'] . (!empty($mod_counts['reports']) ? ' [' . $mod_counts['reports'] . ']' : ''), + 'enabled' => $context['can_moderate_boards'], + 'controller' => 'ModerationCenter_Controller', + 'function' => 'action_reportedPosts', + 'subsections' => array( + 'open' => array($txt['mc_reportedp_active'] . (!empty($mod_counts['reports']) ? ' [' . $mod_counts['reports'] . ']' : '')), + 'closed' => array($txt['mc_reportedp_closed']), + ), + ), + ), + ), + 'groups' => array( + 'title' => $txt['mc_groups'], + 'enabled' => $context['can_moderate_groups'], + 'areas' => array( + 'userwatch' => array( + 'label' => $txt['mc_watched_users_title'], + 'enabled' => in_array('w', $context['admin_features']) && !empty($modSettings['warning_enable']) && $context['can_moderate_boards'], + 'controller' => 'ModerationCenter_Controller', + 'function' => 'action_viewWatchedUsers', + 'subsections' => array( + 'member' => array($txt['mc_watched_users_member']), + 'post' => array($txt['mc_watched_users_post']), + ), + ), + 'groups' => array( + 'label' => $txt['mc_group_requests'], + 'file' => 'controllers/Groups.controller.php', + 'controller' => 'Groups_Controller', + 'function' => 'action_requests', + 'custom_url' => $scripturl . '?action=moderate;area=groups;sa=requests', + ), + 'viewgroups' => array( + 'label' => $txt['mc_view_groups'], + 'file' => 'controllers/Groups.controller.php', + 'controller' => 'Groups_Controller', + 'function' => 'action_list', + ), + ), + ), + ); + + // Make sure the administrator has a valid session... + validateSession('moderate'); + + // I don't know where we're going - I don't know where we've been... + $menuOptions = array( + 'action' => 'moderate', + 'disable_url_session_check' => true, + ); + + $mod_include_data = createMenu($moderation_areas, $menuOptions); + unset($moderation_areas); + + // We got something - didn't we? DIDN'T WE! + if ($mod_include_data == false) + fatal_lang_error('no_access', false); + + // Retain the ID information in case required by a subaction. + $context['moderation_menu_id'] = $context['max_menu_id']; + $context['moderation_menu_name'] = 'menu_data_' . $context['moderation_menu_id']; + + // @todo: html in here is not good + $context[$context['moderation_menu_name']]['tab_data'] = array( + 'title' => $txt['moderation_center'], + 'help' => '', + 'description' => ' + ' . $txt['hello_guest'] . ' ' . $context['user']['name'] . '! +

+ ' . $txt['mc_description']); + + // What a pleasant shortcut - even tho we're not *really* on the admin screen who cares... + $context['admin_area'] = $mod_include_data['current_area']; + + // Build the link tree. + $context['linktree'][] = array( + 'url' => $scripturl . '?action=moderate', + 'name' => $txt['moderation_center'], + ); + + if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index') + $context['linktree'][] = array( + 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'], + 'name' => $mod_include_data['label'], + ); + + if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label']) + $context['linktree'][] = array( + 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'] . ';sa=' . $mod_include_data['current_subsection'], + 'name' => $mod_include_data['subsections'][$mod_include_data['current_subsection']][0], + ); + + // Finally, store this, so that if we're called from the class, it can use it. + $this->_mod_include_data = $mod_include_data; + } + /** * This handler presents the home page of the moderation center. */ @@ -827,14 +1059,14 @@ function action_viewWatchedUsers() 'base_href' => $scripturl . '?action=moderate;area=userwatch;sa=' . ($context['view_posts'] ? 'post' : 'member'), 'default_sort_col' => $context['view_posts'] ? '' : 'member', 'get_items' => array( - 'function' => $context['view_posts'] ? 'list_getWatchedUserPosts' : 'list_getWatchedUsers', + 'function' => $context['view_posts'] ? array($this, 'list_getWatchedUserPosts') : array($this, 'list_getWatchedUsers'), 'params' => array( $approve_query, $delete_boards, ), ), 'get_count' => array( - 'function' => $context['view_posts'] ? 'list_getWatchedUserPostsCount' : 'list_getWatchedUserCount', + 'function' => $context['view_posts'] ? array($this, 'list_getWatchedUserPostsCount') : array($this, 'list_getWatchedUserCount'), 'params' => array( $approve_query, ), @@ -983,10 +1215,10 @@ function action_viewWarningLog() 'base_href' => $scripturl . '?action=moderate;area=warnings;sa=log;' . $context['session_var'] . '=' . $context['session_id'], 'default_sort_col' => 'time', 'get_items' => array( - 'function' => 'list_getWarnings', + 'function' => array($this, 'list_getWarnings'), ), 'get_count' => array( - 'function' => 'list_getWarningCount', + 'function' => array($this, 'list_getWarningCount'), ), // This assumes we are viewing by user. 'columns' => array( @@ -1101,10 +1333,10 @@ function action_viewWarningTemplates() 'base_href' => $scripturl . '?action=moderate;area=warnings;sa=templates;' . $context['session_var'] . '=' . $context['session_id'], 'default_sort_col' => 'title', 'get_items' => array( - 'function' => 'list_getWarningTemplates', + 'function' => array($this, 'list_getWarningTemplates'), ), 'get_count' => array( - 'function' => 'list_getWarningTemplateCount', + 'function' => array($this, 'list_getWarningTemplateCount'), ), 'columns' => array( 'title' => array( @@ -1216,6 +1448,103 @@ function action_viewWarnings() // Call the right function. $this->{$subActions[$_REQUEST['sa']][0]}(); } + + /** + * Callback for createList(). + * + * @param string $approve_query + */ + function list_getWatchedUserCount($approve_query) + { + global $modSettings; + + return watchedUserCount($approve_query, $modSettings['warning_watch']); + } + + /** + * Callback for createList(). + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param string $approve_query + * @param string $dummy + */ + function list_getWatchedUsers($start, $items_per_page, $sort, $approve_query, $dummy) + { + // find all our watched users + return watchedUsers($start, $items_per_page, $sort, $approve_query, $dummy); + } + + /** + * Callback for createList(). + * + * @param string $approve_query + */ + function list_getWatchedUserPostsCount($approve_query) + { + global $modSettings; + + return watchedUserPostsCount($approve_query, $modSettings['warning_watch']); + } + + /** + * Callback for createList(). + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param string $approve_query + * @param array $delete_boards + */ + function list_getWatchedUserPosts($start, $items_per_page, $sort, $approve_query, $delete_boards) + { + // watched users posts + return watchedUserPosts($start, $items_per_page, $sort, $approve_query, $delete_boards); + } + + /** + * Callback for createList() to get all the templates of a type from the system + * + * @param $start + * @param $items_per_page + * @param $sort + * @param $template_type type of template to load + */ + function list_getWarningTemplates($start, $items_per_page, $sort, $template_type = 'warntpl') + { + return warningTemplates($start, $items_per_page, $sort, $template_type); + } + + /** + * Callback for createList() to get the number of templates of a type in the system + * + * @param string $template_type + */ + function list_getWarningTemplateCount($template_type = 'warntpl') + { + return warningTemplateCount($template_type); + } + + /** + * Callback for createList() to get all issued warnings in the system + * + * @param $start + * @param $items_per_page + * @param $sort + */ + function list_getWarnings($start, $items_per_page, $sort) + { + return warnings($start, $items_per_page, $sort); + } + + /** + * Callback for createList(), get the total count of all current warnings + */ + function list_getWarningCount() + { + return warningCount(); + } } /** @@ -1522,432 +1851,4 @@ function ModBlockGroupRequests() $db->free_result($request); return 'group_requests_block'; -} - -/** - * Callback for createList(). - * @param string $approve_query - */ -function list_getWatchedUserCount($approve_query) -{ - global $modSettings; - - $db = database(); - - $request = $db->query('', ' - SELECT COUNT(*) - FROM {db_prefix}members - WHERE warning >= {int:warning_watch}', - array( - 'warning_watch' => $modSettings['warning_watch'], - ) - ); - list ($totalMembers) = $db->fetch_row($request); - $db->free_result($request); - - return $totalMembers; -} - -/** - * Callback for createList(). - * - * @param int $start - * @param int $items_per_page - * @param string $sort - * @param string $approve_query - * @param string $dummy - */ -function list_getWatchedUsers($start, $items_per_page, $sort, $approve_query, $dummy) -{ - global $txt, $modSettings, $user_info; - - $db = database(); - $request = $db->query('', ' - SELECT id_member, real_name, last_login, posts, warning - FROM {db_prefix}members - WHERE warning >= {int:warning_watch} - ORDER BY {raw:sort} - LIMIT ' . $start . ', ' . $items_per_page, - array( - 'warning_watch' => $modSettings['warning_watch'], - 'sort' => $sort, - ) - ); - $watched_users = array(); - $members = array(); - while ($row = $db->fetch_assoc($request)) - { - $watched_users[$row['id_member']] = array( - 'id' => $row['id_member'], - 'name' => $row['real_name'], - 'last_login' => $row['last_login'] ? standardTime($row['last_login']) : $txt['never'], - 'last_post' => $txt['not_applicable'], - 'last_post_id' => 0, - 'warning' => $row['warning'], - 'posts' => $row['posts'], - ); - $members[] = $row['id_member']; - } - $db->free_result($request); - - if (!empty($members)) - { - // First get the latest messages from these users. - $request = $db->query('', ' - SELECT m.id_member, MAX(m.id_msg) AS last_post_id - FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : ' - INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . ' - WHERE m.id_member IN ({array_int:member_list})' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : ' - AND m.approved = {int:is_approved}') . ' - GROUP BY m.id_member', - array( - 'member_list' => $members, - 'is_approved' => 1, - ) - ); - $latest_posts = array(); - while ($row = $db->fetch_assoc($request)) - $latest_posts[$row['id_member']] = $row['last_post_id']; - - if (!empty($latest_posts)) - { - // Now get the time those messages were posted. - $request = $db->query('', ' - SELECT id_member, poster_time - FROM {db_prefix}messages - WHERE id_msg IN ({array_int:message_list})', - array( - 'message_list' => $latest_posts, - ) - ); - while ($row = $db->fetch_assoc($request)) - { - $watched_users[$row['id_member']]['last_post'] = standardTime($row['poster_time']); - $watched_users[$row['id_member']]['last_post_id'] = $latest_posts[$row['id_member']]; - } - - $db->free_result($request); - } - - $request = $db->query('', ' - SELECT MAX(m.poster_time) AS last_post, MAX(m.id_msg) AS last_post_id, m.id_member - FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : ' - INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . ' - WHERE m.id_member IN ({array_int:member_list})' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : ' - AND m.approved = {int:is_approved}') . ' - GROUP BY m.id_member', - array( - 'member_list' => $members, - 'is_approved' => 1, - ) - ); - while ($row = $db->fetch_assoc($request)) - { - $watched_users[$row['id_member']]['last_post'] = standardTime($row['last_post']); - $watched_users[$row['id_member']]['last_post_id'] = $row['last_post_id']; - } - $db->free_result($request); - } - - return $watched_users; -} - -/** - * Callback for createList(). - * - * @param string $approve_query - */ -function list_getWatchedUserPostsCount($approve_query) -{ - global $modSettings; - - $db = database(); - - $request = $db->query('', ' - SELECT COUNT(*) - FROM {db_prefix}messages AS m - INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) - INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) - WHERE mem.warning >= {int:warning_watch} - AND {query_see_board} - ' . $approve_query, - array( - 'warning_watch' => $modSettings['warning_watch'], - ) - ); - list ($totalMemberPosts) = $db->fetch_row($request); - $db->free_result($request); - - return $totalMemberPosts; -} - -/** - * Callback for createList(). - * - * @param int $start - * @param int $items_per_page - * @param string $sort - * @param string $approve_query - * @param array $delete_boards - */ -function list_getWatchedUserPosts($start, $items_per_page, $sort, $approve_query, $delete_boards) -{ - global $scripturl, $modSettings; - - $db = database(); - - $request = $db->query('', ' - SELECT m.id_msg, m.id_topic, m.id_board, m.id_member, m.subject, m.body, m.poster_time, - m.approved, mem.real_name, m.smileys_enabled - FROM {db_prefix}messages AS m - INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) - INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) - WHERE mem.warning >= {int:warning_watch} - AND {query_see_board} - ' . $approve_query . ' - ORDER BY m.id_msg DESC - LIMIT ' . $start . ', ' . $items_per_page, - array( - 'warning_watch' => $modSettings['warning_watch'], - ) - ); - $member_posts = array(); - while ($row = $db->fetch_assoc($request)) - { - $row['subject'] = censorText($row['subject']); - $row['body'] = censorText($row['body']); - - $member_posts[$row['id_msg']] = array( - 'id' => $row['id_msg'], - 'id_topic' => $row['id_topic'], - 'author_link' => '' . $row['real_name'] . '', - 'subject' => $row['subject'], - 'body' => parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), - 'poster_time' => standardTime($row['poster_time']), - 'approved' => $row['approved'], - 'can_delete' => $delete_boards == array(0) || in_array($row['id_board'], $delete_boards), - ); - } - $db->free_result($request); - - return $member_posts; -} - -/** - * Entry point for the moderation center. - * - * @param bool $dont_call = false - */ -function action_modcenter($dont_call = false) -{ - global $txt, $context, $scripturl, $modSettings, $user_info, $options; - - // Don't run this twice... and don't conflict with the admin bar. - if (isset($context['admin_area'])) - return; - - $context['can_moderate_boards'] = $user_info['mod_cache']['bq'] != '0=1'; - $context['can_moderate_groups'] = $user_info['mod_cache']['gq'] != '0=1'; - $context['can_moderate_approvals'] = $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']); - - // Everyone using this area must be allowed here! - if (!$context['can_moderate_boards'] && !$context['can_moderate_groups'] && !$context['can_moderate_approvals']) - isAllowedTo('access_mod_center'); - - // We're gonna want a menu of some kind. - require_once(SUBSDIR . '/Menu.subs.php'); - - // Load the language, and the template. - loadLanguage('ModerationCenter'); - loadTemplate(false, 'admin'); - - $context['admin_preferences'] = !empty($options['admin_preferences']) ? unserialize($options['admin_preferences']) : array(); - $context['robot_no_index'] = true; - - // Moderation counts for things that this moderator can take care of - require_once(SUBSDIR . '/Moderation.subs.php'); - $mod_counts = loadModeratorMenuCounts(); - - // This is the menu structure - refer to subs/Menu.subs.php for the details. - $moderation_areas = array( - 'main' => array( - 'title' => $txt['mc_main'], - 'areas' => array( - 'index' => array( - 'label' => $txt['moderation_center'], - 'controller' => 'ModerationCenter_Controller', - 'function' => 'action_moderationHome', - ), - 'settings' => array( - 'label' => $txt['mc_settings'], - 'controller' => 'ModerationCenter_Controller', - 'function' => 'action_moderationSettings', - ), - 'modlogoff' => array( - 'label' => $txt['mc_logoff'], - 'controller' => 'ModerationCenter_Controller', - 'function' => 'action_modEndSession', - 'enabled' => empty($modSettings['securityDisable_moderate']), - ), - 'notice' => array( - 'controller' => 'ModerationCenter_Controller', - 'function' => 'action_showNotice', - 'select' => 'index' - ), - ), - ), - 'logs' => array( - 'title' => $txt['mc_logs'], - 'areas' => array( - 'modlog' => array( - 'label' => $txt['modlog_view'], - 'enabled' => !empty($modSettings['modlog_enabled']) && $context['can_moderate_boards'], - 'file' => 'admin/Modlog.php', - 'controller' => 'Modlog_Controller', - 'function' => 'action_log', - ), - 'warnings' => array( - 'label' => $txt['mc_warnings'], - 'enabled' => in_array('w', $context['admin_features']) && !empty($modSettings['warning_enable']) && $context['can_moderate_boards'], - 'controller' => 'ModerationCenter_Controller', - 'function' => 'action_viewWarnings', - 'subsections' => array( - 'log' => array($txt['mc_warning_log']), - 'templates' => array($txt['mc_warning_templates'], 'issue_warning'), - ), - ), - ), - ), - 'posts' => array( - 'title' => $txt['mc_posts'] . (!empty($mod_counts['total']) ? ' [' . $mod_counts['total'] . ']' : ''), - 'enabled' => $context['can_moderate_boards'] || $context['can_moderate_approvals'], - 'areas' => array( - 'postmod' => array( - 'label' => $txt['mc_unapproved_posts'] . (!empty($mod_counts['postmod']) ? ' [' . $mod_counts['postmod'] . ']' : ''), - 'enabled' => $context['can_moderate_approvals'], - 'file' => 'controllers/PostModeration.controller.php', - 'controller' => 'PostModeration_Controller', - 'function' => 'action_postmoderation', - 'custom_url' => $scripturl . '?action=moderate;area=postmod', - 'subsections' => array( - 'posts' => array($txt['mc_unapproved_replies']), - 'topics' => array($txt['mc_unapproved_topics']), - ), - ), - 'emailmod' => array( - 'label' => $txt['mc_emailerror'] . (!empty($mod_counts['emailmod']) ? ' [' . $mod_counts['emailmod'] . ']' : ''), - 'enabled' => !empty($modSettings['maillist_enabled']) && allowedTo('approve_emails'), - 'file' => 'admin/ManageMaillist.php', - 'function' => 'UnapprovedEmails', - 'custom_url' => $scripturl . '?action=admin;area=maillist;sa=emaillist', - ), - 'attachmod' => array( - 'label' => $txt['mc_unapproved_attachments'] . (!empty($mod_counts['attachments']) ? ' [' . $mod_counts['attachments'] . ']' : ''), - 'enabled' => $context['can_moderate_approvals'], - 'file' => 'controllers/PostModeration.controller.php', - 'controller' => 'PostModeration_Controller', - 'function' => 'action_postmoderation', - 'custom_url' => $scripturl . '?action=moderate;area=attachmod;sa=attachments', - ), - 'reports' => array( - 'label' => $txt['mc_reported_posts'] . (!empty($mod_counts['reports']) ? ' [' . $mod_counts['reports'] . ']' : ''), - 'enabled' => $context['can_moderate_boards'], - 'controller' => 'ModerationCenter_Controller', - 'function' => 'action_reportedPosts', - 'subsections' => array( - 'open' => array($txt['mc_reportedp_active'] . (!empty($mod_counts['reports']) ? ' [' . $mod_counts['reports'] . ']' : '')), - 'closed' => array($txt['mc_reportedp_closed']), - ), - ), - ), - ), - 'groups' => array( - 'title' => $txt['mc_groups'], - 'enabled' => $context['can_moderate_groups'], - 'areas' => array( - 'userwatch' => array( - 'label' => $txt['mc_watched_users_title'], - 'enabled' => in_array('w', $context['admin_features']) && !empty($modSettings['warning_enable']) && $context['can_moderate_boards'], - 'controller' => 'ModerationCenter_Controller', - 'function' => 'action_viewWatchedUsers', - 'subsections' => array( - 'member' => array($txt['mc_watched_users_member']), - 'post' => array($txt['mc_watched_users_post']), - ), - ), - 'groups' => array( - 'label' => $txt['mc_group_requests'], - 'file' => 'controllers/Groups.controller.php', - 'controller' => 'Groups_Controller', - 'function' => 'action_requests', - 'custom_url' => $scripturl . '?action=moderate;area=groups;sa=requests', - ), - 'viewgroups' => array( - 'label' => $txt['mc_view_groups'], - 'file' => 'controllers/Groups.controller.php', - 'controller' => 'Groups_Controller', - 'function' => 'action_list', - ), - ), - ), - ); - - // Make sure the administrator has a valid session... - validateSession('moderate'); - - // I don't know where we're going - I don't know where we've been... - $menuOptions = array( - 'action' => 'moderate', - 'disable_url_session_check' => true, - ); - - $mod_include_data = createMenu($moderation_areas, $menuOptions); - unset($moderation_areas); - - // We got something - didn't we? DIDN'T WE! - if ($mod_include_data == false) - fatal_lang_error('no_access', false); - - // Retain the ID information in case required by a subaction. - $context['moderation_menu_id'] = $context['max_menu_id']; - $context['moderation_menu_name'] = 'menu_data_' . $context['moderation_menu_id']; - - // @todo: html in here is not good - $context[$context['moderation_menu_name']]['tab_data'] = array( - 'title' => $txt['moderation_center'], - 'help' => '', - 'description' => ' - ' . $txt['hello_guest'] . ' ' . $context['user']['name'] . '! -

- ' . $txt['mc_description']); - - // What a pleasant shortcut - even tho we're not *really* on the admin screen who cares... - $context['admin_area'] = $mod_include_data['current_area']; - - // Build the link tree. - $context['linktree'][] = array( - 'url' => $scripturl . '?action=moderate', - 'name' => $txt['moderation_center'], - ); - - if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index') - $context['linktree'][] = array( - 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'], - 'name' => $mod_include_data['label'], - ); - - if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label']) - $context['linktree'][] = array( - 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'] . ';sa=' . $mod_include_data['current_subsection'], - 'name' => $mod_include_data['subsections'][$mod_include_data['current_subsection']][0], - ); - - // Now - finally - the bit before the encore - the main performance of course! - if (!$dont_call) - { - if (isset($mod_include_data['file'])) - require_once(SOURCEDIR . '/' . $mod_include_data['file']); - - callMenu($mod_include_data); - } -} +} \ No newline at end of file diff --git a/sources/subs/Moderation.subs.php b/sources/subs/Moderation.subs.php index d119c5c5f4..d22c6f22c8 100644 --- a/sources/subs/Moderation.subs.php +++ b/sources/subs/Moderation.subs.php @@ -116,7 +116,7 @@ function recountUnapprovedPosts($approve_query = null) /** * How many falied emails (that they can see) do we have? - * + * * @param string $approve_query */ function recountFailedEmails($approve_query = null) @@ -124,7 +124,7 @@ function recountFailedEmails($approve_query = null) global $context; $db = database(); - + if ($approve_query === null) return 0; @@ -337,14 +337,15 @@ function removeWarningTemplate($id_tpl, $template_type = 'warntpl') } /** - * Callback for createList() to get all the templates of a type from the system + * Returns all the templates of a type from the system. + * (used by createList() callbacks) * * @param $start * @param $items_per_page * @param $sort * @param $template_type type of template to load */ -function list_getWarningTemplates($start, $items_per_page, $sort, $template_type = 'warntpl') +function warningTemplates($start, $items_per_page, $sort, $template_type = 'warntpl') { global $scripturl, $user_info; @@ -383,13 +384,14 @@ function list_getWarningTemplates($start, $items_per_page, $sort, $template_type } /** - * Callback for createList() to get the number of templates of a type in the system + * Get the number of templates of a type in the system * - Loads the public and users private templates * - Loads warning templates by default + * (used by createList() callbacks) * * @param type $template_type */ -function list_getWarningTemplateCount($template_type = 'warntpl') +function warningTemplateCount($template_type = 'warntpl') { global $user_info; @@ -413,13 +415,13 @@ function list_getWarningTemplateCount($template_type = 'warntpl') } /** - * Callback for createList() to get all issued warnings in the system + * Get all issued warnings in the system. * * @param $start * @param $items_per_page * @param $sort */ -function list_getWarnings($start, $items_per_page, $sort) +function warnings($start, $items_per_page, $sort) { global $scripturl; @@ -457,9 +459,11 @@ function list_getWarnings($start, $items_per_page, $sort) } /** - * Callback for createList(), get the total count of all current warnings + * Get the total count of all current warnings. + * + * @return int */ -function list_getWarningCount() +function warningCount() { $db = database(); @@ -652,3 +656,221 @@ function approveAllUnapproved() cache_put_data('num_menu_errors', null, 900); } } + +/** + * Returns the number of watched users in the system. + * (used by createList() callbacks). + * + * @param string $approve_query + * @param int $warning_watch + * @return int + */ +function watchedUserCount($approve_query, $warning_watch = 0) +{ + $db = database(); + + // @todo $approve_query is not used + + $request = $db->query('', ' + SELECT COUNT(*) + FROM {db_prefix}members + WHERE warning >= {int:warning_watch}', + array( + 'warning_watch' => $warning_watch, + ) + ); + list ($totalMembers) = $db->fetch_row($request); + $db->free_result($request); + + return $totalMembers; +} + +/** + * Retrieved the watched users in the system. + * (used by createList() callbacks). + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param string $approve_query + * @param string $dummy + */ +function watchedUsers($start, $items_per_page, $sort, $approve_query, $dummy) +{ + global $txt, $modSettings, $user_info; + + $db = database(); + $request = $db->query('', ' + SELECT id_member, real_name, last_login, posts, warning + FROM {db_prefix}members + WHERE warning >= {int:warning_watch} + ORDER BY {raw:sort} + LIMIT ' . $start . ', ' . $items_per_page, + array( + 'warning_watch' => $modSettings['warning_watch'], + 'sort' => $sort, + ) + ); + $watched_users = array(); + $members = array(); + while ($row = $db->fetch_assoc($request)) + { + $watched_users[$row['id_member']] = array( + 'id' => $row['id_member'], + 'name' => $row['real_name'], + 'last_login' => $row['last_login'] ? standardTime($row['last_login']) : $txt['never'], + 'last_post' => $txt['not_applicable'], + 'last_post_id' => 0, + 'warning' => $row['warning'], + 'posts' => $row['posts'], + ); + $members[] = $row['id_member']; + } + $db->free_result($request); + + if (!empty($members)) + { + // First get the latest messages from these users. + $request = $db->query('', ' + SELECT m.id_member, MAX(m.id_msg) AS last_post_id + FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : ' + INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . ' + WHERE m.id_member IN ({array_int:member_list})' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : ' + AND m.approved = {int:is_approved}') . ' + GROUP BY m.id_member', + array( + 'member_list' => $members, + 'is_approved' => 1, + ) + ); + $latest_posts = array(); + while ($row = $db->fetch_assoc($request)) + $latest_posts[$row['id_member']] = $row['last_post_id']; + + if (!empty($latest_posts)) + { + // Now get the time those messages were posted. + $request = $db->query('', ' + SELECT id_member, poster_time + FROM {db_prefix}messages + WHERE id_msg IN ({array_int:message_list})', + array( + 'message_list' => $latest_posts, + ) + ); + while ($row = $db->fetch_assoc($request)) + { + $watched_users[$row['id_member']]['last_post'] = standardTime($row['poster_time']); + $watched_users[$row['id_member']]['last_post_id'] = $latest_posts[$row['id_member']]; + } + + $db->free_result($request); + } + + $request = $db->query('', ' + SELECT MAX(m.poster_time) AS last_post, MAX(m.id_msg) AS last_post_id, m.id_member + FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : ' + INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . ' + WHERE m.id_member IN ({array_int:member_list})' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : ' + AND m.approved = {int:is_approved}') . ' + GROUP BY m.id_member', + array( + 'member_list' => $members, + 'is_approved' => 1, + ) + ); + while ($row = $db->fetch_assoc($request)) + { + $watched_users[$row['id_member']]['last_post'] = standardTime($row['last_post']); + $watched_users[$row['id_member']]['last_post_id'] = $row['last_post_id']; + } + $db->free_result($request); + } + + return $watched_users; +} + +/** + * Count of posts of watched users. + * (used by createList() callbacks) + * + * @param string $approve_query + * @param int $warning_watch + * @return int + */ +function watchedUserPostsCount($approve_query, $warning_watch) +{ + $db = database(); + + // @todo $approve_query is not used in the function + + $request = $db->query('', ' + SELECT COUNT(*) + FROM {db_prefix}messages AS m + INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) + INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) + WHERE mem.warning >= {int:warning_watch} + AND {query_see_board} + ' . $approve_query, + array( + 'warning_watch' => $warning_watch, + ) + ); + list ($totalMemberPosts) = $db->fetch_row($request); + $db->free_result($request); + + return $totalMemberPosts; +} + +/** + * Retrieve the posts of watched users. + * (used by createList() callbacks). + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param string $approve_query + * @param array $delete_boards + */ +function watchedUserPosts($start, $items_per_page, $sort, $approve_query, $delete_boards) +{ + global $scripturl, $modSettings; + + $db = database(); + + $request = $db->query('', ' + SELECT m.id_msg, m.id_topic, m.id_board, m.id_member, m.subject, m.body, m.poster_time, + m.approved, mem.real_name, m.smileys_enabled + FROM {db_prefix}messages AS m + INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) + INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) + WHERE mem.warning >= {int:warning_watch} + AND {query_see_board} + ' . $approve_query . ' + ORDER BY m.id_msg DESC + LIMIT ' . $start . ', ' . $items_per_page, + array( + 'warning_watch' => $modSettings['warning_watch'], + ) + ); + $member_posts = array(); + while ($row = $db->fetch_assoc($request)) + { + $row['subject'] = censorText($row['subject']); + $row['body'] = censorText($row['body']); + + $member_posts[$row['id_msg']] = array( + 'id' => $row['id_msg'], + 'id_topic' => $row['id_topic'], + 'author_link' => '' . $row['real_name'] . '', + 'subject' => $row['subject'], + 'body' => parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), + 'poster_time' => standardTime($row['poster_time']), + 'approved' => $row['approved'], + 'can_delete' => $delete_boards == array(0) || in_array($row['id_board'], $delete_boards), + ); + } + $db->free_result($request); + + return $member_posts; +} \ No newline at end of file From 8384a695052e471ce89a3de5092a2d06d5b78b04 Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 01:50:40 +0300 Subject: [PATCH 07/34] Tweaks for list_ callbacks, add methods visibility. Signed-off-by: Norv --- sources/admin/ManageMaillist.php | 19 +++++----- .../ModerationCenter.controller.php | 38 +++++++++---------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/sources/admin/ManageMaillist.php b/sources/admin/ManageMaillist.php index abdac533c9..8b860c2456 100644 --- a/sources/admin/ManageMaillist.php +++ b/sources/admin/ManageMaillist.php @@ -1322,6 +1322,8 @@ public function action_view_bounce_templates() { global $modSettings, $context, $txt, $scripturl; + // We'll need this, because bounce templates are stored + // with warning templates. require_once(SUBSDIR . '/Moderation.subs.php'); // Submitting a new one or editing an existing one then pass this request off @@ -1344,11 +1346,10 @@ public function action_view_bounce_templates() 'base_href' => $scripturl . '?action=admin;area=maillist;sa=emailtemplates;' . $context['session_var'] . '=' . $context['session_id'], 'default_sort_col' => 'title', 'get_items' => array( - 'function' => array($this, 'list_getWarningTemplates'), - 'params' => array('bnctpl'), + 'function' => array($this, 'list_getBounceTemplates'), ), 'get_count' => array( - 'function' => array($this, 'list_getWarningTemplateCount'), + 'function' => array($this, 'list_getBounceTemplateCount'), 'params' => array('bnctpl'), ), 'columns' => array( @@ -1539,25 +1540,25 @@ public function action_modify_bounce_templates() } /** - * Callback for createList() to get all the templates of a type from the system + * Callback for createList() to get all the bounce templates from the system * * @param $start * @param $items_per_page * @param $sort * @param $template_type type of template to load */ - function list_getWarningTemplates($start, $items_per_page, $sort, $template_type = 'warntpl') + protected function list_getBounceTemplates($start, $items_per_page, $sort) { - return warningTemplates($start, $items_per_page, $sort, $template_type); + return warningTemplates($start, $items_per_page, $sort, 'bnctpl'); } /** - * Callback for createList() to get the number of templates of a type in the system + * Callback for createList() to get the number of bounce templates in the system * * @param string $template_type */ - function list_getWarningTemplateCount($template_type = 'warntpl') + protected function list_getBounceTemplateCount() { - return warningTemplateCount($template_type); + return warningTemplateCount('bnctpl'); } } \ No newline at end of file diff --git a/sources/controllers/ModerationCenter.controller.php b/sources/controllers/ModerationCenter.controller.php index 01a2f4edc6..4985e0822e 100644 --- a/sources/controllers/ModerationCenter.controller.php +++ b/sources/controllers/ModerationCenter.controller.php @@ -260,7 +260,7 @@ public function prepareModcenter() /** * This handler presents the home page of the moderation center. */ - function action_moderationHome() + public function action_moderationHome() { global $txt, $context, $user_settings; @@ -307,7 +307,7 @@ function action_moderationHome() /** * This ends a moderator session, requiring authentication to access the MCP again. */ - function action_modEndSession() + public function action_modEndSession() { // This is so easy! unset($_SESSION['moderate_time']); @@ -325,7 +325,7 @@ function action_modEndSession() /** * Show a notice sent to a user. */ - function action_showNotice() + public function action_showNotice() { global $txt, $context; @@ -359,7 +359,7 @@ function action_showNotice() * Browse all the reported posts... * @todo this needs to be given its own file? */ - function action_reportedPosts() + public function action_reportedPosts() { global $txt, $context, $scripturl, $user_info; @@ -536,7 +536,7 @@ function action_reportedPosts() /** * Change moderation preferences. */ - function action_moderationSettings() + public function action_moderationSettings() { global $context, $txt, $user_settings, $user_info; @@ -636,7 +636,7 @@ function action_moderationSettings() /** * Edit a warning template. */ - function action_modifyWarningTemplate() + public function action_modifyWarningTemplate() { global $context, $txt, $user_info; @@ -737,7 +737,7 @@ function action_modifyWarningTemplate() * Get details about the moderation report... * specified in $_REQUEST['report']. */ - function action_modReport() + public function action_modReport() { global $user_info, $context, $scripturl, $txt; @@ -983,7 +983,7 @@ function action_modReport() /** * View watched users. */ - function action_viewWatchedUsers() + public function action_viewWatchedUsers() { global $modSettings, $context, $txt, $scripturl; @@ -1196,7 +1196,7 @@ function action_viewWatchedUsers() /** * Simply put, look at the warning log! */ - function action_viewWarningLog() + public function action_viewWarningLog() { global $modSettings, $context, $txt, $scripturl; @@ -1301,7 +1301,7 @@ function action_viewWarningLog() * - Shows all the templates in the system * - Provides for actions to add or delete them */ - function action_viewWarningTemplates() + public function action_viewWarningTemplates() { global $modSettings, $context, $txt, $scripturl; @@ -1423,7 +1423,7 @@ function action_viewWarningTemplates() /** * Entry point for viewing warning related stuff. */ - function action_viewWarnings() + public function action_viewWarnings() { global $context, $txt; @@ -1454,7 +1454,7 @@ function action_viewWarnings() * * @param string $approve_query */ - function list_getWatchedUserCount($approve_query) + protected function list_getWatchedUserCount($approve_query) { global $modSettings; @@ -1470,7 +1470,7 @@ function list_getWatchedUserCount($approve_query) * @param string $approve_query * @param string $dummy */ - function list_getWatchedUsers($start, $items_per_page, $sort, $approve_query, $dummy) + protected function list_getWatchedUsers($start, $items_per_page, $sort, $approve_query, $dummy) { // find all our watched users return watchedUsers($start, $items_per_page, $sort, $approve_query, $dummy); @@ -1481,7 +1481,7 @@ function list_getWatchedUsers($start, $items_per_page, $sort, $approve_query, $d * * @param string $approve_query */ - function list_getWatchedUserPostsCount($approve_query) + protected function list_getWatchedUserPostsCount($approve_query) { global $modSettings; @@ -1497,7 +1497,7 @@ function list_getWatchedUserPostsCount($approve_query) * @param string $approve_query * @param array $delete_boards */ - function list_getWatchedUserPosts($start, $items_per_page, $sort, $approve_query, $delete_boards) + protected function list_getWatchedUserPosts($start, $items_per_page, $sort, $approve_query, $delete_boards) { // watched users posts return watchedUserPosts($start, $items_per_page, $sort, $approve_query, $delete_boards); @@ -1511,7 +1511,7 @@ function list_getWatchedUserPosts($start, $items_per_page, $sort, $approve_query * @param $sort * @param $template_type type of template to load */ - function list_getWarningTemplates($start, $items_per_page, $sort, $template_type = 'warntpl') + protected function list_getWarningTemplates($start, $items_per_page, $sort, $template_type = 'warntpl') { return warningTemplates($start, $items_per_page, $sort, $template_type); } @@ -1521,7 +1521,7 @@ function list_getWarningTemplates($start, $items_per_page, $sort, $template_type * * @param string $template_type */ - function list_getWarningTemplateCount($template_type = 'warntpl') + protected function list_getWarningTemplateCount($template_type = 'warntpl') { return warningTemplateCount($template_type); } @@ -1533,7 +1533,7 @@ function list_getWarningTemplateCount($template_type = 'warntpl') * @param $items_per_page * @param $sort */ - function list_getWarnings($start, $items_per_page, $sort) + protected function list_getWarnings($start, $items_per_page, $sort) { return warnings($start, $items_per_page, $sort); } @@ -1541,7 +1541,7 @@ function list_getWarnings($start, $items_per_page, $sort) /** * Callback for createList(), get the total count of all current warnings */ - function list_getWarningCount() + protected function list_getWarningCount() { return warningCount(); } From a0244083e67b35b4a8f3d773e76a3c7de00e9ef5 Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 01:51:23 +0300 Subject: [PATCH 08/34] Fix inclusion with TESTDIR. Signed-off-by: Norv --- tests/all_tests.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/all_tests.php b/tests/all_tests.php index 14daab1fe1..ff52ab9933 100644 --- a/tests/all_tests.php +++ b/tests/all_tests.php @@ -12,7 +12,7 @@ // not use SSI either. // Might wanna make two or three different suites. -require_once('../Settings.php'); +require_once(TESTDIR . '../Settings.php'); global $test_enabled; echo "WARNING! Tests may work directly with the local database. DON'T run them on ANY other than test installs!\n"; @@ -28,7 +28,7 @@ * * @todo set up a testing database, i.e. on sqlite maybe, or mysql, like populate script, at the * beginning of the suite, and remove or clean it up completely at the end of it. - * + * * To run all tests, execute php all_tests.php in tests directory * Or, scripturl/tests/all_tests.php */ @@ -39,22 +39,22 @@ function AllTests() $this->TestSuite('All tests'); // controllers (web tests) - $this->addFile('sources/controllers/TestAuth.php'); + $this->addFile(TESTDIR . 'sources/controllers/TestAuth.php'); // admin controllers (web tests) - $this->addFile('sources/admin/TestManageBoardsSettings.php'); - $this->addFile('sources/admin/TestManagePostsSettings.php'); + $this->addFile(TESTDIR . 'sources/admin/TestManageBoardsSettings.php'); + $this->addFile(TESTDIR . 'sources/admin/TestManagePostsSettings.php'); // install - $this->addFile('install/TestInstall.php'); + $this->addFile(TESTDIR . 'install/TestInstall.php'); // core sources - $this->addFile('sources/TestLogging.php'); - $this->addFile('sources/TestDispatcher.php'); - $this->addFile('sources/TestRequest.php'); + $this->addFile(TESTDIR . 'sources/TestLogging.php'); + $this->addFile(TESTDIR . 'sources/TestDispatcher.php'); + $this->addFile(TESTDIR . 'sources/TestRequest.php'); // subs APIs - $this->addFile('sources/subs/TestBoards.subs.php'); - $this->addFile('sources/subs/TestPoll.subs.php'); + $this->addFile(TESTDIR . 'sources/subs/TestBoards.subs.php'); + $this->addFile(TESTDIR . 'sources/subs/TestPoll.subs.php'); } } From a3e36cf049ed19b41a09a6dd69f472861439613c Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 05:21:08 +0300 Subject: [PATCH 09/34] Move Action_Controller to core files loaded by default.. SSI too. (tests grumble :P) Signed-off-by: Norv --- SSI.php | 3 ++- index.php | 1 + sources/Dispatcher.class.php | 3 --- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/SSI.php b/SSI.php index 0791275e3d..e22c7ee2b8 100644 --- a/SSI.php +++ b/SSI.php @@ -96,6 +96,7 @@ require_once(SOURCEDIR . '/Errors.class.php'); require_once(SUBSDIR . '/Util.class.php'); require_once(SUBSDIR . '/TemplateLayers.class.php'); +require_once(SOURCEDIR . '/Action.controller.php'); // Clean the request variables. cleanRequest(); @@ -103,7 +104,7 @@ // Create a variable to store some specific functions in. $smcFunc = array(); -// Initate the database connection and define some database functions to use. +// Initiate the database connection and define some database functions to use. loadDatabase(); // Load settings from the database. diff --git a/index.php b/index.php index 91993773c1..eaf4c50342 100644 --- a/index.php +++ b/index.php @@ -79,6 +79,7 @@ require_once(SOURCEDIR . '/Errors.class.php'); require_once(SUBSDIR . '/Util.class.php'); require_once(SUBSDIR . '/TemplateLayers.class.php'); +require_once(SOURCEDIR . '/Action.controller.php'); // Forum in extended maintenance mode? Our trip ends here with a bland message. if (!empty($maintenance) && $maintenance == 2) diff --git a/sources/Dispatcher.class.php b/sources/Dispatcher.class.php index 1de52c3d42..afa21b2c5c 100644 --- a/sources/Dispatcher.class.php +++ b/sources/Dispatcher.class.php @@ -56,9 +56,6 @@ public function __construct() { global $board, $topic, $modSettings, $settings, $user_info, $maintenance; - // ready to load 'em - require_once(SOURCEDIR . '/Action.controller.php'); - // default action of the forum: board index // everytime we don't know what to do, we'll do this :P $default_action = array( From 3c43d17d00ab67a42a667422745ed45387e2f02d Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 05:43:49 +0300 Subject: [PATCH 10/34] Another batch of user controllers, updated to inherit Action_Controller. Tweak index and method visibilities. Signed-off-by: Norv --- .../controllers/ProfileAccount.controller.php | 13 +++++++++++- sources/controllers/Recent.controller.php | 12 ++++++++++- sources/controllers/Register.controller.php | 14 ++++++++++++- sources/controllers/Reminder.controller.php | 14 ++++++------- .../controllers/RemoveTopic.controller.php | 11 +++++++++- sources/controllers/Search.controller.php | 12 ++++++++++- .../controllers/SplitTopics.controller.php | 12 ++++++++++- sources/controllers/Stats.controller.php | 18 ++++++++++++++--- sources/controllers/Suggest.controller.php | 20 +++++++++++++++---- sources/controllers/Topic.controller.php | 18 +++++++++++++++-- sources/controllers/Who.controller.php | 2 +- 11 files changed, 123 insertions(+), 23 deletions(-) diff --git a/sources/controllers/ProfileAccount.controller.php b/sources/controllers/ProfileAccount.controller.php index 184c52cc49..2ca3050145 100644 --- a/sources/controllers/ProfileAccount.controller.php +++ b/sources/controllers/ProfileAccount.controller.php @@ -21,8 +21,19 @@ /** * ProfileAccount controller handles actions made on a user's profile. */ -class ProfileAccount_Controller +class ProfileAccount_Controller extends Action_Controller { + /** + * Entry point for this class. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // figure out what action to do... if we're called directly + // actions in this class are called from the Profile menu, though. + } + /** * Issue/manage an user's warning status. */ diff --git a/sources/controllers/Recent.controller.php b/sources/controllers/Recent.controller.php index 97878f5a5c..7e1e14a9a4 100644 --- a/sources/controllers/Recent.controller.php +++ b/sources/controllers/Recent.controller.php @@ -23,8 +23,18 @@ /** * Recent Post Controller */ -class Recent_Controller +class Recent_Controller extends Action_Controller { + /** + * Intended entry point for recent controller class. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // figure out what action to do + } + /** * Find the ten most recent posts. * Accessed by action=recent. diff --git a/sources/controllers/Register.controller.php b/sources/controllers/Register.controller.php index e2b45bce98..82ad02c815 100644 --- a/sources/controllers/Register.controller.php +++ b/sources/controllers/Register.controller.php @@ -25,8 +25,20 @@ /** * Register Controller */ -class Register_Controller +class Register_Controller extends Action_Controller { + /** + * Intended entry point for this class. + * By default, this is called for action=register + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // figure out what action to do... register, what else. + $this->action_register(); + } + /** * Begin the registration process. * Accessed by ?action=register diff --git a/sources/controllers/Reminder.controller.php b/sources/controllers/Reminder.controller.php index 7eba74b37a..4719c6c507 100644 --- a/sources/controllers/Reminder.controller.php +++ b/sources/controllers/Reminder.controller.php @@ -21,14 +21,14 @@ /** * Reminder Controller handles sending out reminders, and checking the secret answer and question. */ -class Reminder_Controller +class Reminder_Controller extends Action_Controller { /** * This is the pre-dispatch function * * @uses Profile language files and Reminder template */ - function pre_dispatch() + public function pre_dispatch() { global $txt, $context; @@ -42,7 +42,7 @@ function pre_dispatch() /** * Default action for reminder. */ - function action_index() + public function action_index() { // nothing to do, the template will ask for an action to pick createToken('remind'); @@ -52,7 +52,7 @@ function action_index() * Pick a reminder type. * sa=picktype */ - function action_picktype() + public function action_picktype() { global $context, $txt, $scripturl, $user_info, $webmaster_email, $language, $modSettings; @@ -148,7 +148,7 @@ function action_picktype() * Set your new password * sa=setpassword */ - function action_setpassword() + public function action_setpassword() { global $txt, $context; @@ -174,7 +174,7 @@ function action_setpassword() * Handle the password change. * sa=setpassword2 */ - function action_setpassword2() + public function action_setpassword2() { global $context, $txt; @@ -243,7 +243,7 @@ function action_setpassword2() * Verify the answer to the secret question. * sa=secret2 */ - function action_secret2() + public function action_secret2() { global $txt, $context; diff --git a/sources/controllers/RemoveTopic.controller.php b/sources/controllers/RemoveTopic.controller.php index b749a2c43d..267eb9af8f 100644 --- a/sources/controllers/RemoveTopic.controller.php +++ b/sources/controllers/RemoveTopic.controller.php @@ -24,8 +24,17 @@ /** * Remove Topic Controller */ -class RemoveTopic_Controller +class RemoveTopic_Controller extends Action_Controller { + /** + * Intended entry point for this class. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // call the right method + } /** * Completely remove an entire topic. * Redirects to the board when completed. diff --git a/sources/controllers/Search.controller.php b/sources/controllers/Search.controller.php index 851f8c1078..0fbb00dad6 100644 --- a/sources/controllers/Search.controller.php +++ b/sources/controllers/Search.controller.php @@ -27,8 +27,18 @@ 'search_version' => strtr('ELKARTE 1+0=Alpha', array('+' => '.', '=' => ' ')), ); -class Search_Controller +class Search_Controller extends Action_Controller { + /** + * Intended entry point for this class. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // Call the right method. + } + /** * Ask the user what they want to search for. * What it does: diff --git a/sources/controllers/SplitTopics.controller.php b/sources/controllers/SplitTopics.controller.php index 98823d01da..2f21b35005 100644 --- a/sources/controllers/SplitTopics.controller.php +++ b/sources/controllers/SplitTopics.controller.php @@ -21,9 +21,19 @@ if (!defined('ELKARTE')) die('No access...'); -class SplitTopics_Controller +class SplitTopics_Controller extends Action_Controller { private $_new_topic_subject = null; + /** + * Intended entry point for this class. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // Call the right method. + } + /** * Splits a topic into two topics. * delegates to the other functions (based on the URL parameter 'sa'). diff --git a/sources/controllers/Stats.controller.php b/sources/controllers/Stats.controller.php index 08ade26d72..795c3e5f8a 100644 --- a/sources/controllers/Stats.controller.php +++ b/sources/controllers/Stats.controller.php @@ -23,8 +23,20 @@ /** * Statistics Controller */ -class Stats_Controller +class Stats_Controller extends Action_Controller { + /** + * Entry point for this class. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // Call the right method... wait, we only know how to do + // one thing (and do it well! :P) + $this->action_stats(); + } + /** * Display some useful/interesting board statistics. * @@ -33,14 +45,14 @@ class Stats_Controller * requires the view_stats permission. * accessed from ?action=stats. */ - function action_stats() + public function action_stats() { global $txt, $scripturl, $modSettings, $context; $db = database(); isAllowedTo('view_stats'); - + // Page disabled - redirect them out if (empty($modSettings['trackStats'])) fatal_lang_error('feature_disabled', true); diff --git a/sources/controllers/Suggest.controller.php b/sources/controllers/Suggest.controller.php index b152c6f26f..ccaf4ec5fa 100644 --- a/sources/controllers/Suggest.controller.php +++ b/sources/controllers/Suggest.controller.php @@ -21,8 +21,18 @@ /** * Suggest Controler */ -class Suggest_Controller +class Suggest_Controller extends Action_Controller { + /** + * Intended entry point for this class. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // Call the right method for this user request. + } + /** * This keeps track of all registered handling functions for auto suggest * functionality and passes execution to them. @@ -30,10 +40,12 @@ class Suggest_Controller * * @param bool $checkRegistered = null */ - function action_suggest($checkRegistered = null) + public function action_suggest($checkRegistered = null) { global $context; + // @todo this method shouldn't have a $checkRegistered parameter... + // These are all registered types. $searchTypes = array( 'member' => 'member', @@ -65,7 +77,7 @@ function action_suggest($checkRegistered = null) * * @return string */ - function action_suggest_member() + public function action_suggest_member() { global $user_info, $context; @@ -85,7 +97,7 @@ function action_suggest_member() * * @return string */ - function action_suggest_versions() + public function action_suggest_versions() { $xml_data = array( 'items' => array( diff --git a/sources/controllers/Topic.controller.php b/sources/controllers/Topic.controller.php index 8c05577e2e..b23e4aa7fb 100644 --- a/sources/controllers/Topic.controller.php +++ b/sources/controllers/Topic.controller.php @@ -24,8 +24,22 @@ /** * Topics Controller */ -class Topic_Controller +class Topic_Controller extends Action_Controller { + /** + * Entry point for this class (by default). + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // Call the right method, if it ain't done yet. + // this is done by the dispatcher, so lets leave it alone... + // we don't want to assume what it means if the user doesn't + // send us a ?sa=, do we? (lock topics out of nowhere?) + // Unless... we can printpage() + } + /** * Locks a topic... either by way of a moderator or the topic starter. * What this does: @@ -298,7 +312,7 @@ function action_printpage() } $context['user']['started'] = $user_info['id'] == $row['id_member'] && !$user_info['is_guest']; - + // Set up the basic poll information. $context['poll'] = array( 'id' => $row['id_poll'], diff --git a/sources/controllers/Who.controller.php b/sources/controllers/Who.controller.php index d2e1d79d70..aecb03f41c 100644 --- a/sources/controllers/Who.controller.php +++ b/sources/controllers/Who.controller.php @@ -24,7 +24,7 @@ /** * Who Controller */ -class Who_Controller +class Who_Controller extends Action_Controller { /** * Default action of this class. From ae925942b788ada88b819fcc30736bee4159c6cb Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 06:05:08 +0300 Subject: [PATCH 11/34] ProfileHistory controller. Make it a class; main methods visibility, the entry method is called action_index(). Signed-off-by: Norv --- sources/controllers/Profile.controller.php | 3 +- .../controllers/ProfileHistory.controller.php | 1855 +++++++++-------- 2 files changed, 932 insertions(+), 926 deletions(-) diff --git a/sources/controllers/Profile.controller.php b/sources/controllers/Profile.controller.php index 8bb74cc087..ceae6dfb3d 100644 --- a/sources/controllers/Profile.controller.php +++ b/sources/controllers/Profile.controller.php @@ -133,7 +133,8 @@ public function action_index() 'history' => array( 'label' => $txt['history'], 'file' => '/controllers/ProfileHistory.controller.php', - 'function' => 'action_history', + 'controller' => 'ProfileHistory_Controller', + 'function' => 'action_index', 'subsections' => array( 'activity' => array($txt['trackActivity'], 'moderate_forum'), 'ip' => array($txt['trackIP'], 'moderate_forum'), diff --git a/sources/controllers/ProfileHistory.controller.php b/sources/controllers/ProfileHistory.controller.php index 0eb0170d95..cbd744d311 100644 --- a/sources/controllers/ProfileHistory.controller.php +++ b/sources/controllers/ProfileHistory.controller.php @@ -18,1053 +18,1058 @@ if (!defined('ELKARTE')) die('No access...'); -/** - * Profile history main function. - * Re-directs to sub-actions (@todo it should only set the context) - */ -function action_history() +class ProfileHistory_Controller extends Action_Controller { - global $context, $txt, $modSettings, $user_profile; - - $memID = currentMemberID(); - - $subActions = array( - 'activity' => array('action_trackactivity', $txt['trackActivity']), - 'ip' => array('action_trackip', $txt['trackIP']), - 'edits' => array('action_trackedits', $txt['trackEdits']), - 'logins' => array('action_tracklogin', $txt['trackLogins']), - ); - - $context['history_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : 'activity'; - - // @todo what is $types? it is never set so this will never be true - if (isset($types[$context['history_area']][1])) - require_once(SOURCEDIR . '/' . $types[$context['history_area']][1]); - - // Create the tabs for the template. - $context[$context['profile_menu_name']]['tab_data'] = array( - 'title' => $txt['history'], - 'description' => $txt['history_description'], - 'icon' => 'profile_hd.png', - 'tabs' => array( - 'activity' => array(), - 'ip' => array(), - 'edits' => array(), - ), - ); - - // Moderation must be on to track edits. - if (empty($modSettings['modlog_enabled'])) - unset($context[$context['profile_menu_name']]['tab_data']['edits']); - - // Set a page title. - $context['page_title'] = $txt['trackUser'] . ' - ' . $subActions[$context['history_area']][1] . ' - ' . $user_profile[$memID]['real_name']; - - // Pass on to the actual function. - $subActions[$context['history_area']][0]($memID); -} + /** + * Profile history entry point. + * Re-directs to sub-actions. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + global $context, $txt, $modSettings, $user_profile; -/** - * Subaction for profile history actions: activity log. - * - * @param int $memID id_member - */ -function action_trackactivity($memID) -{ - global $scripturl, $txt, $modSettings, $user_profile, $context; + $memID = currentMemberID(); + + $subActions = array( + 'activity' => array('action_trackactivity', $txt['trackActivity']), + 'ip' => array('action_trackip', $txt['trackIP']), + 'edits' => array('action_trackedits', $txt['trackEdits']), + 'logins' => array('action_tracklogin', $txt['trackLogins']), + ); + + $context['history_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : 'activity'; + + // @todo what is $types? it is never set so this will never be true + if (isset($types[$context['history_area']][1])) + require_once(SOURCEDIR . '/' . $types[$context['history_area']][1]); + + // Create the tabs for the template. + $context[$context['profile_menu_name']]['tab_data'] = array( + 'title' => $txt['history'], + 'description' => $txt['history_description'], + 'icon' => 'profile_hd.png', + 'tabs' => array( + 'activity' => array(), + 'ip' => array(), + 'edits' => array(), + ), + ); - $db = database(); + // Moderation must be on to track edits. + if (empty($modSettings['modlog_enabled'])) + unset($context[$context['profile_menu_name']]['tab_data']['edits']); - // Verify if the user has sufficient permissions. - isAllowedTo('moderate_forum'); + // Set a page title. + $context['page_title'] = $txt['trackUser'] . ' - ' . $subActions[$context['history_area']][1] . ' - ' . $user_profile[$memID]['real_name']; - $context['last_ip'] = $user_profile[$memID]['member_ip']; + // Pass on to the actual method. + $this->{$subActions[$context['history_area']][0]}($memID); + } - if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) - $context['last_ip2'] = $user_profile[$memID]['member_ip2']; + /** + * Subaction for profile history actions: activity log. + * + * @param int $memID id_member + */ + public function action_trackactivity($memID) + { + global $scripturl, $txt, $modSettings, $user_profile, $context; - $context['member']['name'] = $user_profile[$memID]['real_name']; + $db = database(); - // Set the options for the list component. - $listOptions = array( - 'id' => 'track_name_user_list', - 'title' => $txt['errors_by'] . ' ' . $context['member']['name'], - 'items_per_page' => $modSettings['defaultMaxMessages'], - 'no_items_label' => $txt['no_errors_from_user'], - 'base_href' => $scripturl . '?action=profile;area=history;sa=user;u=' . $memID, - 'default_sort_col' => 'date', - 'get_items' => array( - 'function' => 'list_getUserErrors', - 'params' => array( - 'le.id_member = {int:current_member}', - array('current_member' => $memID), - ), - ), - 'get_count' => array( - 'function' => 'list_getUserErrorCount', - 'params' => array( - 'id_member = {int:current_member}', - array('current_member' => $memID), + // Verify if the user has sufficient permissions. + isAllowedTo('moderate_forum'); + + $context['last_ip'] = $user_profile[$memID]['member_ip']; + + if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) + $context['last_ip2'] = $user_profile[$memID]['member_ip2']; + + $context['member']['name'] = $user_profile[$memID]['real_name']; + + // Set the options for the list component. + $listOptions = array( + 'id' => 'track_name_user_list', + 'title' => $txt['errors_by'] . ' ' . $context['member']['name'], + 'items_per_page' => $modSettings['defaultMaxMessages'], + 'no_items_label' => $txt['no_errors_from_user'], + 'base_href' => $scripturl . '?action=profile;area=history;sa=user;u=' . $memID, + 'default_sort_col' => 'date', + 'get_items' => array( + 'function' => 'list_getUserErrors', + 'params' => array( + 'le.id_member = {int:current_member}', + array('current_member' => $memID), + ), ), - ), - 'columns' => array( - 'ip_address' => array( - 'header' => array( - 'value' => $txt['ip_address'], + 'get_count' => array( + 'function' => 'list_getUserErrorCount', + 'params' => array( + 'id_member = {int:current_member}', + array('current_member' => $memID), ), - 'data' => array( - 'sprintf' => array( - 'format' => '%1$s', - 'params' => array( - 'ip' => false, + ), + 'columns' => array( + 'ip_address' => array( + 'header' => array( + 'value' => $txt['ip_address'], + ), + 'data' => array( + 'sprintf' => array( + 'format' => '%1$s', + 'params' => array( + 'ip' => false, + ), ), ), + 'sort' => array( + 'default' => 'le.ip', + 'reverse' => 'le.ip DESC', + ), ), - 'sort' => array( - 'default' => 'le.ip', - 'reverse' => 'le.ip DESC', - ), - ), - 'message' => array( - 'header' => array( - 'value' => $txt['message'], - ), - 'data' => array( - 'sprintf' => array( - 'format' => '%1$s
%2$s', - 'params' => array( - 'message' => false, - 'url' => false, + 'message' => array( + 'header' => array( + 'value' => $txt['message'], + ), + 'data' => array( + 'sprintf' => array( + 'format' => '%1$s
%2$s', + 'params' => array( + 'message' => false, + 'url' => false, + ), ), ), ), - ), - 'date' => array( - 'header' => array( - 'value' => $txt['date'], - ), - 'data' => array( - 'db' => 'time', - ), - 'sort' => array( - 'default' => 'le.id_error DESC', - 'reverse' => 'le.id_error', + 'date' => array( + 'header' => array( + 'value' => $txt['date'], + ), + 'data' => array( + 'db' => 'time', + ), + 'sort' => array( + 'default' => 'le.id_error DESC', + 'reverse' => 'le.id_error', + ), ), ), - ), - 'additional_rows' => array( - array( - 'position' => 'after_title', - 'value' => $txt['errors_desc'], - 'class' => 'windowbg2', - 'style' => 'padding: 1ex 2ex;', + 'additional_rows' => array( + array( + 'position' => 'after_title', + 'value' => $txt['errors_desc'], + 'class' => 'windowbg2', + 'style' => 'padding: 1ex 2ex;', + ), ), - ), - ); - - // Create the list for viewing. - require_once(SUBSDIR . '/List.subs.php'); - createList($listOptions); - - // @todo cache this - // If this is a big forum, or a large posting user, let's limit the search. - if ($modSettings['totalMessages'] > 50000 && $user_profile[$memID]['posts'] > 500) - { - $request = $db->query('', ' - SELECT MAX(id_msg) - FROM {db_prefix}messages AS m - WHERE m.id_member = {int:current_member}', - array( - 'current_member' => $memID, - ) ); - list ($max_msg_member) = $db->fetch_row($request); - $db->free_result($request); - // There's no point worrying ourselves with messages made yonks ago, just get recent ones! - $min_msg_member = max(0, $max_msg_member - $user_profile[$memID]['posts'] * 3); - } + // Create the list for viewing. + require_once(SUBSDIR . '/List.subs.php'); + createList($listOptions); - // Default to at least the ones we know about. - $ips = array( - $user_profile[$memID]['member_ip'], - $user_profile[$memID]['member_ip2'], - ); - - // @todo cache this - // Get all IP addresses this user has used for his messages. - $request = $db->query('', ' - SELECT poster_ip - FROM {db_prefix}messages - WHERE id_member = {int:current_member} - ' . (isset($min_msg_member) ? ' - AND id_msg >= {int:min_msg_member} AND id_msg <= {int:max_msg_member}' : '') . ' - GROUP BY poster_ip', - array( - 'current_member' => $memID, - 'min_msg_member' => !empty($min_msg_member) ? $min_msg_member : 0, - 'max_msg_member' => !empty($max_msg_member) ? $max_msg_member : 0, - ) - ); - $context['ips'] = array(); - while ($row = $db->fetch_assoc($request)) - { - $context['ips'][] = '' . $row['poster_ip'] . ''; - $ips[] = $row['poster_ip']; - } - $db->free_result($request); - - // Now also get the IP addresses from the error messages. - $request = $db->query('', ' - SELECT COUNT(*) AS error_count, ip - FROM {db_prefix}log_errors - WHERE id_member = {int:current_member} - GROUP BY ip', - array( - 'current_member' => $memID, - ) - ); - $context['error_ips'] = array(); - while ($row = $db->fetch_assoc($request)) - { - $context['error_ips'][] = '' . $row['ip'] . ''; - $ips[] = $row['ip']; - } - $db->free_result($request); + // @todo cache this + // If this is a big forum, or a large posting user, let's limit the search. + if ($modSettings['totalMessages'] > 50000 && $user_profile[$memID]['posts'] > 500) + { + $request = $db->query('', ' + SELECT MAX(id_msg) + FROM {db_prefix}messages AS m + WHERE m.id_member = {int:current_member}', + array( + 'current_member' => $memID, + ) + ); + list ($max_msg_member) = $db->fetch_row($request); + $db->free_result($request); + + // There's no point worrying ourselves with messages made yonks ago, just get recent ones! + $min_msg_member = max(0, $max_msg_member - $user_profile[$memID]['posts'] * 3); + } - // Find other users that might use the same IP. - $context['members_in_range'] = array(); + // Default to at least the ones we know about. + $ips = array( + $user_profile[$memID]['member_ip'], + $user_profile[$memID]['member_ip2'], + ); - $ips = array_unique($ips); - if (!empty($ips)) - { - // Get member ID's which are in messages... + // @todo cache this + // Get all IP addresses this user has used for his messages. $request = $db->query('', ' - SELECT mem.id_member - FROM {db_prefix}messages AS m - INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) - WHERE m.poster_ip IN ({array_string:ip_list}) - GROUP BY mem.id_member - HAVING mem.id_member != {int:current_member}', + SELECT poster_ip + FROM {db_prefix}messages + WHERE id_member = {int:current_member} + ' . (isset($min_msg_member) ? ' + AND id_msg >= {int:min_msg_member} AND id_msg <= {int:max_msg_member}' : '') . ' + GROUP BY poster_ip', array( 'current_member' => $memID, - 'ip_list' => $ips, + 'min_msg_member' => !empty($min_msg_member) ? $min_msg_member : 0, + 'max_msg_member' => !empty($max_msg_member) ? $max_msg_member : 0, ) ); - $message_members = array(); + $context['ips'] = array(); while ($row = $db->fetch_assoc($request)) - $message_members[] = $row['id_member']; - $db->free_result($request); - - // Fetch their names, cause of the GROUP BY doesn't like giving us that normally. - if (!empty($message_members)) { - require_once(SUBSDIR . '/Members.subs.php'); - - // Get the latest activated member's display name. - $result = getBasicMemberData($message_members); - foreach ($result as $row) - $context['members_in_range'][$row['id_member']] = '' . $row['real_name'] . ''; + $context['ips'][] = '' . $row['poster_ip'] . ''; + $ips[] = $row['poster_ip']; } + $db->free_result($request); + // Now also get the IP addresses from the error messages. $request = $db->query('', ' - SELECT id_member, real_name - FROM {db_prefix}members - WHERE id_member != {int:current_member} - AND member_ip IN ({array_string:ip_list})', + SELECT COUNT(*) AS error_count, ip + FROM {db_prefix}log_errors + WHERE id_member = {int:current_member} + GROUP BY ip', array( 'current_member' => $memID, - 'ip_list' => $ips, ) ); + $context['error_ips'] = array(); while ($row = $db->fetch_assoc($request)) - $context['members_in_range'][$row['id_member']] = '' . $row['real_name'] . ''; + { + $context['error_ips'][] = '' . $row['ip'] . ''; + $ips[] = $row['ip']; + } $db->free_result($request); - } - loadTemplate('ProfileHistory'); - $context['sub_template'] = 'trackActivity'; -} - -/** - * Get the number of user errors. - * Callback for createList in action_trackip() and action_trackactivity() - * - * @param string $where - * @param array $where_vars = array() - * @return string number of user errors - */ -function list_getUserErrorCount($where, $where_vars = array()) -{ - $db = database(); - $request = $db->query('', ' - SELECT COUNT(*) AS error_count - FROM {db_prefix}log_errors - WHERE ' . $where, - $where_vars - ); - list ($count) = $db->fetch_row($request); - $db->free_result($request); + // Find other users that might use the same IP. + $context['members_in_range'] = array(); - return $count; -} - -/** - * Callback for createList in action_trackip() and action_trackactivity() - * - * @param int $start - * @param int $items_per_page - * @param string $sort - * @param string $where - * @param array $where_vars - * @return array error messages - */ -function list_getUserErrors($start, $items_per_page, $sort, $where, $where_vars = array()) -{ - global $txt, $scripturl; - - $db = database(); - - // Get a list of error messages from this ip (range). - $request = $db->query('', ' - SELECT - le.log_time, le.ip, le.url, le.message, IFNULL(mem.id_member, 0) AS id_member, - IFNULL(mem.real_name, {string:guest_title}) AS display_name, mem.member_name - FROM {db_prefix}log_errors AS le - LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = le.id_member) - WHERE ' . $where . ' - ORDER BY ' . $sort . ' - LIMIT ' . $start . ', ' . $items_per_page, - array_merge($where_vars, array( - 'guest_title' => $txt['guest_title'], - )) - ); - $error_messages = array(); - while ($row = $db->fetch_assoc($request)) - $error_messages[] = array( - 'ip' => $row['ip'], - 'member_link' => $row['id_member'] > 0 ? '' . $row['display_name'] . '' : $row['display_name'], - 'message' => strtr($row['message'], array('<span class="remove">' => '', '</span>' => '')), - 'url' => $row['url'], - 'time' => relativeTime($row['log_time']), - 'timestamp' => forum_time(true, $row['log_time']), - ); - $db->free_result($request); - - return $error_messages; -} + $ips = array_unique($ips); + if (!empty($ips)) + { + // Get member ID's which are in messages... + $request = $db->query('', ' + SELECT mem.id_member + FROM {db_prefix}messages AS m + INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) + WHERE m.poster_ip IN ({array_string:ip_list}) + GROUP BY mem.id_member + HAVING mem.id_member != {int:current_member}', + array( + 'current_member' => $memID, + 'ip_list' => $ips, + ) + ); + $message_members = array(); + while ($row = $db->fetch_assoc($request)) + $message_members[] = $row['id_member']; + $db->free_result($request); + + // Fetch their names, cause of the GROUP BY doesn't like giving us that normally. + if (!empty($message_members)) + { + require_once(SUBSDIR . '/Members.subs.php'); + + // Get the latest activated member's display name. + $result = getBasicMemberData($message_members); + foreach ($result as $row) + $context['members_in_range'][$row['id_member']] = '' . $row['real_name'] . ''; + } + + $request = $db->query('', ' + SELECT id_member, real_name + FROM {db_prefix}members + WHERE id_member != {int:current_member} + AND member_ip IN ({array_string:ip_list})', + array( + 'current_member' => $memID, + 'ip_list' => $ips, + ) + ); + while ($row = $db->fetch_assoc($request)) + $context['members_in_range'][$row['id_member']] = '' . $row['real_name'] . ''; + $db->free_result($request); + } + loadTemplate('ProfileHistory'); + $context['sub_template'] = 'trackActivity'; + } -/** - * Callback for createList() in TrackIP() - * - * @param string $where - * @param array $where_vars - * @return string count of messages matching the IP - */ -function list_getIPMessageCount($where, $where_vars = array()) -{ - $db = database(); + /** + * Track an IP address. + * Accessed through ?action=trackip + * and through ?action=profile;area=history;sa=ip + * + * @param int $memID = 0 id_member + */ + public function action_trackip($memID = 0) + { + global $user_profile, $scripturl, $txt, $user_info, $modSettings, $context; - $request = $db->query('', ' - SELECT COUNT(*) AS message_count - FROM {db_prefix}messages AS m - INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) - WHERE {query_see_board} AND ' . $where, - $where_vars - ); - list ($count) = $db->fetch_row($request); - $db->free_result($request); + $db = database(); - return $count; -} + // Can the user do this? + isAllowedTo('moderate_forum'); -/** - * Callback for createList() in TrackIP() - * - * @param int $start - * @param int $items_per_page - * @param string $sort - * @param string $where - * @param array $where_vars - * @return array an array of messages - */ -function list_getIPMessages($start, $items_per_page, $sort, $where, $where_vars = array()) -{ - global $scripturl; - - $db = database(); - - // Get all the messages fitting this where clause. - // @todo SLOW This query is using a filesort. - $request = $db->query('', ' - SELECT - m.id_msg, m.poster_ip, IFNULL(mem.real_name, m.poster_name) AS display_name, mem.id_member, - m.subject, m.poster_time, m.id_topic, m.id_board - FROM {db_prefix}messages AS m - INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) - LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) - WHERE {query_see_board} AND ' . $where . ' - ORDER BY ' . $sort . ' - LIMIT ' . $start . ', ' . $items_per_page, - array_merge($where_vars, array( - )) - ); - $messages = array(); - while ($row = $db->fetch_assoc($request)) - $messages[] = array( - 'ip' => $row['poster_ip'], - 'member_link' => empty($row['id_member']) ? $row['display_name'] : '' . $row['display_name'] . '', - 'board' => array( - 'id' => $row['id_board'], - 'href' => $scripturl . '?board=' . $row['id_board'] - ), - 'topic' => $row['id_topic'], - 'id' => $row['id_msg'], - 'subject' => $row['subject'], - 'time' => relativeTime($row['poster_time']), - 'timestamp' => forum_time(true, $row['poster_time']) - ); - $db->free_result($request); + loadTemplate('Profile'); + loadTemplate('ProfileHistory'); + loadLanguage('Profile'); - return $messages; -} + if ($memID == 0) + { + $context['ip'] = $user_info['ip']; + $context['page_title'] = $txt['profile']; + $context['base_url'] = $scripturl . '?action=trackip'; + } + else + { + $context['ip'] = $user_profile[$memID]['member_ip']; + $context['base_url'] = $scripturl . '?action=profile;area=history;sa=ip;u=' . $memID; + } -/** - * Track an IP address. - * Accessed through ?action=trackip - * and through ?action=profile;area=history;sa=ip - * - * @param int $memID = 0 id_member - */ -function action_trackip($memID = 0) -{ - global $user_profile, $scripturl, $txt, $user_info, $modSettings, $context; + // Searching? + if (isset($_REQUEST['searchip'])) + $context['ip'] = trim($_REQUEST['searchip']); - $db = database(); + if (preg_match('/^\d{1,3}\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$/', $context['ip']) == 0 && isValidIPv6($context['ip']) === false) + fatal_lang_error('invalid_tracking_ip', false); - // Can the user do this? - isAllowedTo('moderate_forum'); + $ip_var = str_replace('*', '%', $context['ip']); + $ip_string = strpos($ip_var, '%') === false ? '= {string:ip_address}' : 'LIKE {string:ip_address}'; - loadTemplate('Profile'); - loadTemplate('ProfileHistory'); - loadLanguage('Profile'); + if (empty($context['history_area'])) + $context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip']; - if ($memID == 0) - { - $context['ip'] = $user_info['ip']; - $context['page_title'] = $txt['profile']; - $context['base_url'] = $scripturl . '?action=trackip'; - } - else - { - $context['ip'] = $user_profile[$memID]['member_ip']; - $context['base_url'] = $scripturl . '?action=profile;area=history;sa=ip;u=' . $memID; - } + $request = $db->query('', ' + SELECT id_member, real_name AS display_name, member_ip + FROM {db_prefix}members + WHERE member_ip ' . $ip_string, + array( + 'ip_address' => $ip_var, + ) + ); + $context['ips'] = array(); + while ($row = $db->fetch_assoc($request)) + $context['ips'][$row['member_ip']][] = '' . $row['display_name'] . ''; + $db->free_result($request); - // Searching? - if (isset($_REQUEST['searchip'])) - $context['ip'] = trim($_REQUEST['searchip']); - - if (preg_match('/^\d{1,3}\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$/', $context['ip']) == 0 && isValidIPv6($context['ip']) === false) - fatal_lang_error('invalid_tracking_ip', false); - - $ip_var = str_replace('*', '%', $context['ip']); - $ip_string = strpos($ip_var, '%') === false ? '= {string:ip_address}' : 'LIKE {string:ip_address}'; - - if (empty($context['history_area'])) - $context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip']; - - $request = $db->query('', ' - SELECT id_member, real_name AS display_name, member_ip - FROM {db_prefix}members - WHERE member_ip ' . $ip_string, - array( - 'ip_address' => $ip_var, - ) - ); - $context['ips'] = array(); - while ($row = $db->fetch_assoc($request)) - $context['ips'][$row['member_ip']][] = '' . $row['display_name'] . ''; - $db->free_result($request); - - ksort($context['ips']); - - // Gonna want this for the list. - require_once(SUBSDIR . '/List.subs.php'); - - // Start with the user messages. - $listOptions = array( - 'id' => 'track_message_list', - 'title' => $txt['messages_from_ip'] . ' ' . $context['ip'], - 'start_var_name' => 'messageStart', - 'items_per_page' => $modSettings['defaultMaxMessages'], - 'no_items_label' => $txt['no_messages_from_ip'], - 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'], - 'default_sort_col' => 'date', - 'get_items' => array( - 'function' => 'list_getIPMessages', - 'params' => array( - 'm.poster_ip ' . $ip_string, - array('ip_address' => $ip_var), + ksort($context['ips']); + + // Gonna want this for the list. + require_once(SUBSDIR . '/List.subs.php'); + + // Start with the user messages. + $listOptions = array( + 'id' => 'track_message_list', + 'title' => $txt['messages_from_ip'] . ' ' . $context['ip'], + 'start_var_name' => 'messageStart', + 'items_per_page' => $modSettings['defaultMaxMessages'], + 'no_items_label' => $txt['no_messages_from_ip'], + 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'], + 'default_sort_col' => 'date', + 'get_items' => array( + 'function' => 'list_getIPMessages', + 'params' => array( + 'm.poster_ip ' . $ip_string, + array('ip_address' => $ip_var), + ), ), - ), - 'get_count' => array( - 'function' => 'list_getIPMessageCount', - 'params' => array( - 'm.poster_ip ' . $ip_string, - array('ip_address' => $ip_var), + 'get_count' => array( + 'function' => 'list_getIPMessageCount', + 'params' => array( + 'm.poster_ip ' . $ip_string, + array('ip_address' => $ip_var), + ), ), - ), - 'columns' => array( - 'ip_address' => array( - 'header' => array( - 'value' => $txt['ip_address'], + 'columns' => array( + 'ip_address' => array( + 'header' => array( + 'value' => $txt['ip_address'], + ), + 'data' => array( + 'sprintf' => array( + 'format' => '%1$s', + 'params' => array( + 'ip' => false, + ), + ), + ), + 'sort' => array( + 'default' => 'INET_ATON(m.poster_ip)', + 'reverse' => 'INET_ATON(m.poster_ip) DESC', + ), ), - 'data' => array( - 'sprintf' => array( - 'format' => '%1$s', - 'params' => array( - 'ip' => false, + 'poster' => array( + 'header' => array( + 'value' => $txt['poster'], + ), + 'data' => array( + 'db' => 'member_link', + ), + ), + 'subject' => array( + 'header' => array( + 'value' => $txt['subject'], + ), + 'data' => array( + 'sprintf' => array( + 'format' => '%3$s', + 'params' => array( + 'topic' => false, + 'id' => false, + 'subject' => false, + ), ), ), ), - 'sort' => array( - 'default' => 'INET_ATON(m.poster_ip)', - 'reverse' => 'INET_ATON(m.poster_ip) DESC', + 'date' => array( + 'header' => array( + 'value' => $txt['date'], + ), + 'data' => array( + 'db' => 'time', + ), + 'sort' => array( + 'default' => 'm.id_msg DESC', + 'reverse' => 'm.id_msg', + ), ), ), - 'poster' => array( - 'header' => array( - 'value' => $txt['poster'], + 'additional_rows' => array( + array( + 'position' => 'after_title', + 'value' => $txt['messages_from_ip_desc'], + 'class' => 'windowbg2', + 'style' => 'padding: 1ex 2ex;', ), - 'data' => array( - 'db' => 'member_link', + ), + ); + + // Create the messages list. + createList($listOptions); + + // Set the options for the error lists. + $listOptions = array( + 'id' => 'track_ip_user_list', + 'title' => $txt['errors_from_ip'] . ' ' . $context['ip'], + 'start_var_name' => 'errorStart', + 'items_per_page' => $modSettings['defaultMaxMessages'], + 'no_items_label' => $txt['no_errors_from_ip'], + 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'], + 'default_sort_col' => 'date2', + 'get_items' => array( + 'function' => 'list_getUserErrors', + 'params' => array( + 'le.ip ' . $ip_string, + array('ip_address' => $ip_var), ), ), - 'subject' => array( - 'header' => array( - 'value' => $txt['subject'], + 'get_count' => array( + 'function' => 'list_getUserErrorCount', + 'params' => array( + 'ip ' . $ip_string, + array('ip_address' => $ip_var), ), - 'data' => array( - 'sprintf' => array( - 'format' => '%3$s', - 'params' => array( - 'topic' => false, - 'id' => false, - 'subject' => false, + ), + 'columns' => array( + 'ip_address2' => array( + 'header' => array( + 'value' => $txt['ip_address'], + ), + 'data' => array( + 'sprintf' => array( + 'format' => '%1$s', + 'params' => array( + 'ip' => false, + ), ), ), + 'sort' => array( + 'default' => 'INET_ATON(le.ip)', + 'reverse' => 'INET_ATON(le.ip) DESC', + ), ), - ), - 'date' => array( - 'header' => array( - 'value' => $txt['date'], - ), - 'data' => array( - 'db' => 'time', - ), - 'sort' => array( - 'default' => 'm.id_msg DESC', - 'reverse' => 'm.id_msg', - ), - ), - ), - 'additional_rows' => array( - array( - 'position' => 'after_title', - 'value' => $txt['messages_from_ip_desc'], - 'class' => 'windowbg2', - 'style' => 'padding: 1ex 2ex;', - ), - ), - ); - - // Create the messages list. - createList($listOptions); - - // Set the options for the error lists. - $listOptions = array( - 'id' => 'track_ip_user_list', - 'title' => $txt['errors_from_ip'] . ' ' . $context['ip'], - 'start_var_name' => 'errorStart', - 'items_per_page' => $modSettings['defaultMaxMessages'], - 'no_items_label' => $txt['no_errors_from_ip'], - 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'], - 'default_sort_col' => 'date2', - 'get_items' => array( - 'function' => 'list_getUserErrors', - 'params' => array( - 'le.ip ' . $ip_string, - array('ip_address' => $ip_var), - ), - ), - 'get_count' => array( - 'function' => 'list_getUserErrorCount', - 'params' => array( - 'ip ' . $ip_string, - array('ip_address' => $ip_var), - ), - ), - 'columns' => array( - 'ip_address2' => array( - 'header' => array( - 'value' => $txt['ip_address'], + 'display_name' => array( + 'header' => array( + 'value' => $txt['display_name'], + ), + 'data' => array( + 'db' => 'member_link', + ), ), - 'data' => array( - 'sprintf' => array( - 'format' => '%1$s', - 'params' => array( - 'ip' => false, + 'message' => array( + 'header' => array( + 'value' => $txt['message'], + ), + 'data' => array( + 'sprintf' => array( + 'format' => '%1$s
%2$s', + 'params' => array( + 'message' => false, + 'url' => false, + ), ), ), ), - 'sort' => array( - 'default' => 'INET_ATON(le.ip)', - 'reverse' => 'INET_ATON(le.ip) DESC', + 'date2' => array( + 'header' => array( + 'value' => $txt['date'], + ), + 'data' => array( + 'db' => 'time', + ), + 'sort' => array( + 'default' => 'le.id_error DESC', + 'reverse' => 'le.id_error', + ), ), ), - 'display_name' => array( - 'header' => array( - 'value' => $txt['display_name'], - ), - 'data' => array( - 'db' => 'member_link', + 'additional_rows' => array( + array( + 'position' => 'after_title', + 'value' => $txt['errors_from_ip_desc'], + 'class' => 'windowbg2', + 'style' => 'padding: 1ex 2ex;', ), ), - 'message' => array( - 'header' => array( - 'value' => $txt['message'], + ); + + // Create the error list. + createList($listOptions); + + $context['single_ip'] = strpos($context['ip'], '*') === false; + if ($context['single_ip']) + { + $context['whois_servers'] = array( + 'afrinic' => array( + 'name' => $txt['whois_afrinic'], + 'url' => 'http://www.afrinic.net/cgi-bin/whois?searchtext=' . $context['ip'], + 'range' => array(41, 154, 196), ), - 'data' => array( - 'sprintf' => array( - 'format' => '%1$s
%2$s', - 'params' => array( - 'message' => false, - 'url' => false, - ), - ), + 'apnic' => array( + 'name' => $txt['whois_apnic'], + 'url' => 'http://wq.apnic.net/apnic-bin/whois.pl?searchtext=' . $context['ip'], + 'range' => array(58, 59, 60, 61, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, + 125, 126, 133, 150, 153, 163, 171, 202, 203, 210, 211, 218, 219, 220, 221, 222), ), - ), - 'date2' => array( - 'header' => array( - 'value' => $txt['date'], + 'arin' => array( + 'name' => $txt['whois_arin'], + 'url' => 'http://whois.arin.net/rest/ip/' . $context['ip'], + 'range' => array(7, 24, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 96, 97, 98, 99, + 128, 129, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 142, 143, 144, 146, 147, 148, 149, + 152, 155, 156, 157, 158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 169, 170, 172, 173, 174, + 192, 198, 199, 204, 205, 206, 207, 208, 209, 216), ), - 'data' => array( - 'db' => 'time', + 'lacnic' => array( + 'name' => $txt['whois_lacnic'], + 'url' => 'http://lacnic.net/cgi-bin/lacnic/whois?query=' . $context['ip'], + 'range' => array(186, 187, 189, 190, 191, 200, 201), ), - 'sort' => array( - 'default' => 'le.id_error DESC', - 'reverse' => 'le.id_error', + 'ripe' => array( + 'name' => $txt['whois_ripe'], + 'url' => 'http://www.db.ripe.net/whois?searchtext=' . $context['ip'], + 'range' => array(62, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 141, 145, 151, 188, 193, 194, 195, 212, 213, 217), ), - ), - ), - 'additional_rows' => array( - array( - 'position' => 'after_title', - 'value' => $txt['errors_from_ip_desc'], - 'class' => 'windowbg2', - 'style' => 'padding: 1ex 2ex;', - ), - ), - ); - - // Create the error list. - createList($listOptions); + ); + + foreach ($context['whois_servers'] as $whois) + { + // Strip off the "decimal point" and anything following... + if (in_array((int) $context['ip'], $whois['range'])) + $context['auto_whois_server'] = $whois; + } + } + $context['sub_template'] = 'trackIP'; + } - $context['single_ip'] = strpos($context['ip'], '*') === false; - if ($context['single_ip']) + /** + * Tracks the logins of a given user. + * Accessed by ?action=trackip + * and ?action=profile;area=history;sa=ip + * + * @param int $memID = 0 id_member + */ + public function action_tracklogin($memID = 0) { - $context['whois_servers'] = array( - 'afrinic' => array( - 'name' => $txt['whois_afrinic'], - 'url' => 'http://www.afrinic.net/cgi-bin/whois?searchtext=' . $context['ip'], - 'range' => array(41, 154, 196), - ), - 'apnic' => array( - 'name' => $txt['whois_apnic'], - 'url' => 'http://wq.apnic.net/apnic-bin/whois.pl?searchtext=' . $context['ip'], - 'range' => array(58, 59, 60, 61, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, - 125, 126, 133, 150, 153, 163, 171, 202, 203, 210, 211, 218, 219, 220, 221, 222), - ), - 'arin' => array( - 'name' => $txt['whois_arin'], - 'url' => 'http://whois.arin.net/rest/ip/' . $context['ip'], - 'range' => array(7, 24, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 96, 97, 98, 99, - 128, 129, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 142, 143, 144, 146, 147, 148, 149, - 152, 155, 156, 157, 158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 169, 170, 172, 173, 174, - 192, 198, 199, 204, 205, 206, 207, 208, 209, 216), - ), - 'lacnic' => array( - 'name' => $txt['whois_lacnic'], - 'url' => 'http://lacnic.net/cgi-bin/lacnic/whois?query=' . $context['ip'], - 'range' => array(186, 187, 189, 190, 191, 200, 201), - ), - 'ripe' => array( - 'name' => $txt['whois_ripe'], - 'url' => 'http://www.db.ripe.net/whois?searchtext=' . $context['ip'], - 'range' => array(62, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 141, 145, 151, 188, 193, 194, 195, 212, 213, 217), - ), - ); + global $scripturl, $txt, $context; - foreach ($context['whois_servers'] as $whois) - { - // Strip off the "decimal point" and anything following... - if (in_array((int) $context['ip'], $whois['range'])) - $context['auto_whois_server'] = $whois; - } - } - $context['sub_template'] = 'trackIP'; -} + // Gonna want this for the list. + require_once(SUBSDIR . '/List.subs.php'); -/** - * Tracks the logins of a given user. - * Accessed by ?action=trackip - * and ?action=profile;area=history;sa=ip - * - * @param int $memID = 0 id_member - */ -function action_tracklogin($memID = 0) -{ - global $scripturl, $txt, $context; - - // Gonna want this for the list. - require_once(SUBSDIR . '/List.subs.php'); - - if ($memID == 0) - $context['base_url'] = $scripturl . '?action=trackip'; - else - $context['base_url'] = $scripturl . '?action=profile;area=history;sa=ip;u=' . $memID; - - // Start with the user messages. - $listOptions = array( - 'id' => 'track_logins_list', - 'title' => $txt['trackLogins'], - 'no_items_label' => $txt['trackLogins_none_found'], - 'base_href' => $context['base_url'], - 'get_items' => array( - 'function' => 'list_getLogins', - 'params' => array( - 'id_member = {int:current_member}', - array('current_member' => $memID), - ), - ), - 'get_count' => array( - 'function' => 'list_getLoginCount', - 'params' => array( - 'id_member = {int:current_member}', - array('current_member' => $memID), - ), - ), - 'columns' => array( - 'time' => array( - 'header' => array( - 'value' => $txt['date'], + if ($memID == 0) + $context['base_url'] = $scripturl . '?action=trackip'; + else + $context['base_url'] = $scripturl . '?action=profile;area=history;sa=ip;u=' . $memID; + + // Start with the user messages. + $listOptions = array( + 'id' => 'track_logins_list', + 'title' => $txt['trackLogins'], + 'no_items_label' => $txt['trackLogins_none_found'], + 'base_href' => $context['base_url'], + 'get_items' => array( + 'function' => 'list_getLogins', + 'params' => array( + 'id_member = {int:current_member}', + array('current_member' => $memID), ), - 'data' => array( - 'db' => 'time', + ), + 'get_count' => array( + 'function' => 'list_getLoginCount', + 'params' => array( + 'id_member = {int:current_member}', + array('current_member' => $memID), ), ), - 'ip' => array( - 'header' => array( - 'value' => $txt['ip_address'], + 'columns' => array( + 'time' => array( + 'header' => array( + 'value' => $txt['date'], + ), + 'data' => array( + 'db' => 'time', + ), ), - 'data' => array( - 'sprintf' => array( - 'format' => '%1$s (%2$s) ', - 'params' => array( - 'ip' => false, - 'ip2' => false + 'ip' => array( + 'header' => array( + 'value' => $txt['ip_address'], + ), + 'data' => array( + 'sprintf' => array( + 'format' => '%1$s (%2$s) ', + 'params' => array( + 'ip' => false, + 'ip2' => false + ), ), ), ), ), - ), - 'additional_rows' => array( - array( - 'position' => 'after_title', - 'value' => $txt['trackLogins_desc'], - 'class' => 'windowbg2', - 'style' => 'padding: 1ex 2ex;', + 'additional_rows' => array( + array( + 'position' => 'after_title', + 'value' => $txt['trackLogins_desc'], + 'class' => 'windowbg2', + 'style' => 'padding: 1ex 2ex;', + ), ), - ), - ); + ); - // Create the messages list. - createList($listOptions); + // Create the messages list. + createList($listOptions); - $context['sub_template'] = 'show_list'; - $context['default_list'] = 'track_logins_list'; -} + $context['sub_template'] = 'show_list'; + $context['default_list'] = 'track_logins_list'; + } -/** - * Callback for trackLogins for counting history. - * (createList() in TrackLogins()) - * - * @param string $where - * @param array $where_vars - * @return string count of messages matching the IP - */ -function list_getLoginCount($where, $where_vars = array()) -{ - $db = database(); - - $request = $db->query('', ' - SELECT COUNT(*) AS message_count - FROM {db_prefix}member_logins - WHERE ' . $where, - array( - 'id_member' => $where_vars['current_member'], - ) - ); - list ($count) = $db->fetch_row($request); - $db->free_result($request); - - return $count; -} + /** + * Logs edits to a members profile. + * + * @param int $memID id_member + */ + public function action_trackedits($memID) + { + global $scripturl, $txt, $modSettings, $context; -/** - * Callback for trackLogins data. - * - * @param int $start - * @param int $items_per_page - * @param string $sort - * @param string $where - * @param array $where_vars - * @return array an array of messages - */ -function list_getLogins($start, $items_per_page, $sort, $where, $where_vars = array()) -{ - $db = database(); - - $request = $db->query('', ' - SELECT time, ip, ip2 - FROM {db_prefix}member_logins - WHERE ' . $where .' - ORDER BY time DESC', - array( - 'id_member' => $where_vars['current_member'], - ) - ); - $logins = array(); - while ($row = $db->fetch_assoc($request)) - $logins[] = array( - 'time' => relativeTime($row['time']), - 'ip' => $row['ip'], - 'ip2' => $row['ip2'], - ); - $db->free_result($request); + $db = database(); - return $logins; -} + require_once(SUBSDIR . '/List.subs.php'); -/** - * Logs edits to a members profile. - * - * @param int $memID id_member - */ -function action_trackedits($memID) -{ - global $scripturl, $txt, $modSettings, $context; - - $db = database(); - - require_once(SUBSDIR . '/List.subs.php'); - - // Get the names of any custom fields. - $request = $db->query('', ' - SELECT col_name, field_name, bbc - FROM {db_prefix}custom_fields', - array( - ) - ); - $context['custom_field_titles'] = array(); - while ($row = $db->fetch_assoc($request)) - $context['custom_field_titles']['customfield_' . $row['col_name']] = array( - 'title' => $row['field_name'], - 'parse_bbc' => $row['bbc'], + // Get the names of any custom fields. + $request = $db->query('', ' + SELECT col_name, field_name, bbc + FROM {db_prefix}custom_fields', + array( + ) ); - $db->free_result($request); - - // Set the options for the error lists. - $listOptions = array( - 'id' => 'edit_list', - 'title' => $txt['trackEdits'], - 'items_per_page' => $modSettings['defaultMaxMessages'], - 'no_items_label' => $txt['trackEdit_no_edits'], - 'base_href' => $scripturl . '?action=profile;area=history;sa=edits;u=' . $memID, - 'default_sort_col' => 'time', - 'get_items' => array( - 'function' => 'list_getProfileEdits', - 'params' => array( - $memID, - ), - ), - 'get_count' => array( - 'function' => 'list_getProfileEditCount', - 'params' => array( - $memID, - ), - ), - 'columns' => array( - 'action' => array( - 'header' => array( - 'value' => $txt['trackEdit_action'], - ), - 'data' => array( - 'db' => 'action_text', + $context['custom_field_titles'] = array(); + while ($row = $db->fetch_assoc($request)) + $context['custom_field_titles']['customfield_' . $row['col_name']] = array( + 'title' => $row['field_name'], + 'parse_bbc' => $row['bbc'], + ); + $db->free_result($request); + + // Set the options for the error lists. + $listOptions = array( + 'id' => 'edit_list', + 'title' => $txt['trackEdits'], + 'items_per_page' => $modSettings['defaultMaxMessages'], + 'no_items_label' => $txt['trackEdit_no_edits'], + 'base_href' => $scripturl . '?action=profile;area=history;sa=edits;u=' . $memID, + 'default_sort_col' => 'time', + 'get_items' => array( + 'function' => 'list_getProfileEdits', + 'params' => array( + $memID, ), ), - 'before' => array( - 'header' => array( - 'value' => $txt['trackEdit_before'], - ), - 'data' => array( - 'db' => 'before', + 'get_count' => array( + 'function' => 'list_getProfileEditCount', + 'params' => array( + $memID, ), ), - 'after' => array( - 'header' => array( - 'value' => $txt['trackEdit_after'], + 'columns' => array( + 'action' => array( + 'header' => array( + 'value' => $txt['trackEdit_action'], + ), + 'data' => array( + 'db' => 'action_text', + ), ), - 'data' => array( - 'db' => 'after', + 'before' => array( + 'header' => array( + 'value' => $txt['trackEdit_before'], + ), + 'data' => array( + 'db' => 'before', + ), ), - ), - 'time' => array( - 'header' => array( - 'value' => $txt['date'], + 'after' => array( + 'header' => array( + 'value' => $txt['trackEdit_after'], + ), + 'data' => array( + 'db' => 'after', + ), ), - 'data' => array( - 'db' => 'time', + 'time' => array( + 'header' => array( + 'value' => $txt['date'], + ), + 'data' => array( + 'db' => 'time', + ), + 'sort' => array( + 'default' => 'id_action DESC', + 'reverse' => 'id_action', + ), ), - 'sort' => array( - 'default' => 'id_action DESC', - 'reverse' => 'id_action', + 'applicator' => array( + 'header' => array( + 'value' => $txt['trackEdit_applicator'], + ), + 'data' => array( + 'db' => 'member_link', + ), ), ), - 'applicator' => array( - 'header' => array( - 'value' => $txt['trackEdit_applicator'], - ), - 'data' => array( - 'db' => 'member_link', + ); + + // Create the error list. + createList($listOptions); + + $context['sub_template'] = 'show_list'; + $context['default_list'] = 'edit_list'; + } + + /** + * Get the number of user errors. + * Callback for createList in action_trackip() and action_trackactivity() + * + * @param string $where + * @param array $where_vars = array() + * @return string number of user errors + */ + function list_getUserErrorCount($where, $where_vars = array()) + { + $db = database(); + + $request = $db->query('', ' + SELECT COUNT(*) AS error_count + FROM {db_prefix}log_errors + WHERE ' . $where, + $where_vars + ); + list ($count) = $db->fetch_row($request); + $db->free_result($request); + + return $count; + } + + /** + * Callback for createList in action_trackip() and action_trackactivity() + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param string $where + * @param array $where_vars + * @return array error messages + */ + function list_getUserErrors($start, $items_per_page, $sort, $where, $where_vars = array()) + { + global $txt, $scripturl; + + $db = database(); + + // Get a list of error messages from this ip (range). + $request = $db->query('', ' + SELECT + le.log_time, le.ip, le.url, le.message, IFNULL(mem.id_member, 0) AS id_member, + IFNULL(mem.real_name, {string:guest_title}) AS display_name, mem.member_name + FROM {db_prefix}log_errors AS le + LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = le.id_member) + WHERE ' . $where . ' + ORDER BY ' . $sort . ' + LIMIT ' . $start . ', ' . $items_per_page, + array_merge($where_vars, array( + 'guest_title' => $txt['guest_title'], + )) + ); + $error_messages = array(); + while ($row = $db->fetch_assoc($request)) + $error_messages[] = array( + 'ip' => $row['ip'], + 'member_link' => $row['id_member'] > 0 ? '' . $row['display_name'] . '' : $row['display_name'], + 'message' => strtr($row['message'], array('<span class="remove">' => '', '</span>' => '')), + 'url' => $row['url'], + 'time' => relativeTime($row['log_time']), + 'timestamp' => forum_time(true, $row['log_time']), + ); + $db->free_result($request); + + return $error_messages; + } + + /** + * Callback for createList() in TrackIP() + * + * @param string $where + * @param array $where_vars + * @return string count of messages matching the IP + */ + function list_getIPMessageCount($where, $where_vars = array()) + { + $db = database(); + + $request = $db->query('', ' + SELECT COUNT(*) AS message_count + FROM {db_prefix}messages AS m + INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) + WHERE {query_see_board} AND ' . $where, + $where_vars + ); + list ($count) = $db->fetch_row($request); + $db->free_result($request); + + return $count; + } + + /** + * Callback for createList() in TrackIP() + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param string $where + * @param array $where_vars + * @return array an array of messages + */ + function list_getIPMessages($start, $items_per_page, $sort, $where, $where_vars = array()) + { + global $scripturl; + + $db = database(); + + // Get all the messages fitting this where clause. + // @todo SLOW This query is using a filesort. + $request = $db->query('', ' + SELECT + m.id_msg, m.poster_ip, IFNULL(mem.real_name, m.poster_name) AS display_name, mem.id_member, + m.subject, m.poster_time, m.id_topic, m.id_board + FROM {db_prefix}messages AS m + INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) + LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) + WHERE {query_see_board} AND ' . $where . ' + ORDER BY ' . $sort . ' + LIMIT ' . $start . ', ' . $items_per_page, + array_merge($where_vars, array( + )) + ); + $messages = array(); + while ($row = $db->fetch_assoc($request)) + $messages[] = array( + 'ip' => $row['poster_ip'], + 'member_link' => empty($row['id_member']) ? $row['display_name'] : '' . $row['display_name'] . '', + 'board' => array( + 'id' => $row['id_board'], + 'href' => $scripturl . '?board=' . $row['id_board'] ), - ), - ), - ); + 'topic' => $row['id_topic'], + 'id' => $row['id_msg'], + 'subject' => $row['subject'], + 'time' => relativeTime($row['poster_time']), + 'timestamp' => forum_time(true, $row['poster_time']) + ); + $db->free_result($request); - // Create the error list. - createList($listOptions); + return $messages; + } - $context['sub_template'] = 'show_list'; - $context['default_list'] = 'edit_list'; -} + /** + * Callback for trackLogins for counting history. + * (createList() in TrackLogins()) + * + * @param string $where + * @param array $where_vars + * @return string count of messages matching the IP + */ + function list_getLoginCount($where, $where_vars = array()) + { + $db = database(); -/** - * How many edits? - * - * @param int $memID id_member - * @return string number of profile edits - */ -function list_getProfileEditCount($memID) -{ - $db = database(); - - $request = $db->query('', ' - SELECT COUNT(*) AS edit_count - FROM {db_prefix}log_actions - WHERE id_log = {int:log_type} - AND id_member = {int:owner}', - array( - 'log_type' => 2, - 'owner' => $memID, - ) - ); - list ($edit_count) = $db->fetch_row($request); - $db->free_result($request); - - return $edit_count; -} + $request = $db->query('', ' + SELECT COUNT(*) AS message_count + FROM {db_prefix}member_logins + WHERE ' . $where, + array( + 'id_member' => $where_vars['current_member'], + ) + ); + list ($count) = $db->fetch_row($request); + $db->free_result($request); -/** - * Callback function for createList in trackEdits(). - * - * @param int $start - * @param int $items_per_page - * @param string $sort - * @param int $memID - * @return array - */ -function list_getProfileEdits($start, $items_per_page, $sort, $memID) -{ - global $txt, $scripturl, $context; - - $db = database(); - - // Get a list of error messages from this ip (range). - $request = $db->query('', ' - SELECT - id_action, id_member, ip, log_time, action, extra - FROM {db_prefix}log_actions - WHERE id_log = {int:log_type} - AND id_member = {int:owner} - ORDER BY ' . $sort . ' - LIMIT ' . $start . ', ' . $items_per_page, - array( - 'log_type' => 2, - 'owner' => $memID, - ) - ); - $edits = array(); - $members = array(); - while ($row = $db->fetch_assoc($request)) + return $count; + } + + /** + * Callback for trackLogins data. + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param string $where + * @param array $where_vars + * @return array an array of messages + */ + function list_getLogins($start, $items_per_page, $sort, $where, $where_vars = array()) { - $extra = @unserialize($row['extra']); - if (!empty($extra['applicator'])) - $members[] = $extra['applicator']; - - // Work out what the name of the action is. - if (isset($txt['trackEdit_action_' . $row['action']])) - $action_text = $txt['trackEdit_action_' . $row['action']]; - elseif (isset($txt[$row['action']])) - $action_text = $txt[$row['action']]; - // Custom field? - elseif (isset($context['custom_field_titles'][$row['action']])) - $action_text = $context['custom_field_titles'][$row['action']]['title']; - else - $action_text = $row['action']; - - // Parse BBC? - $parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false; - - $edits[] = array( - 'id' => $row['id_action'], - 'ip' => $row['ip'], - 'id_member' => !empty($extra['applicator']) ? $extra['applicator'] : 0, - 'member_link' => $txt['trackEdit_deleted_member'], - 'action' => $row['action'], - 'action_text' => $action_text, - 'before' => !empty($extra['previous']) ? ($parse_bbc ? parse_bbc($extra['previous']) : $extra['previous']) : '', - 'after' => !empty($extra['new']) ? ($parse_bbc ? parse_bbc($extra['new']) : $extra['new']) : '', - 'time' => standardTime($row['log_time']), + $db = database(); + + $request = $db->query('', ' + SELECT time, ip, ip2 + FROM {db_prefix}member_logins + WHERE ' . $where .' + ORDER BY time DESC', + array( + 'id_member' => $where_vars['current_member'], + ) ); + $logins = array(); + while ($row = $db->fetch_assoc($request)) + $logins[] = array( + 'time' => relativeTime($row['time']), + 'ip' => $row['ip'], + 'ip2' => $row['ip2'], + ); + $db->free_result($request); + + return $logins; } - $db->free_result($request); - // Get any member names. - if (!empty($members)) + /** + * How many edits? + * + * @param int $memID id_member + * @return string number of profile edits + */ + function list_getProfileEditCount($memID) { - require_once(SUBSDIR . '/Members.subs.php'); - $result = getBasicMemberData($members); - $members = array(); - foreach ($result as $row) - $members[$row['id_member']] = $row['real_name']; + $db = database(); + + $request = $db->query('', ' + SELECT COUNT(*) AS edit_count + FROM {db_prefix}log_actions + WHERE id_log = {int:log_type} + AND id_member = {int:owner}', + array( + 'log_type' => 2, + 'owner' => $memID, + ) + ); + list ($edit_count) = $db->fetch_row($request); + $db->free_result($request); - foreach ($edits as $key => $value) - if (isset($members[$value['id_member']])) - $edits[$key]['member_link'] = '' . $members[$value['id_member']] . ''; + return $edit_count; } - return $edits; + /** + * Callback function for createList in trackEdits(). + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param int $memID + * @return array + */ + function list_getProfileEdits($start, $items_per_page, $sort, $memID) + { + global $txt, $scripturl, $context; + + $db = database(); + + // Get a list of error messages from this ip (range). + $request = $db->query('', ' + SELECT + id_action, id_member, ip, log_time, action, extra + FROM {db_prefix}log_actions + WHERE id_log = {int:log_type} + AND id_member = {int:owner} + ORDER BY ' . $sort . ' + LIMIT ' . $start . ', ' . $items_per_page, + array( + 'log_type' => 2, + 'owner' => $memID, + ) + ); + $edits = array(); + $members = array(); + while ($row = $db->fetch_assoc($request)) + { + $extra = @unserialize($row['extra']); + if (!empty($extra['applicator'])) + $members[] = $extra['applicator']; + + // Work out what the name of the action is. + if (isset($txt['trackEdit_action_' . $row['action']])) + $action_text = $txt['trackEdit_action_' . $row['action']]; + elseif (isset($txt[$row['action']])) + $action_text = $txt[$row['action']]; + // Custom field? + elseif (isset($context['custom_field_titles'][$row['action']])) + $action_text = $context['custom_field_titles'][$row['action']]['title']; + else + $action_text = $row['action']; + + // Parse BBC? + $parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false; + + $edits[] = array( + 'id' => $row['id_action'], + 'ip' => $row['ip'], + 'id_member' => !empty($extra['applicator']) ? $extra['applicator'] : 0, + 'member_link' => $txt['trackEdit_deleted_member'], + 'action' => $row['action'], + 'action_text' => $action_text, + 'before' => !empty($extra['previous']) ? ($parse_bbc ? parse_bbc($extra['previous']) : $extra['previous']) : '', + 'after' => !empty($extra['new']) ? ($parse_bbc ? parse_bbc($extra['new']) : $extra['new']) : '', + 'time' => standardTime($row['log_time']), + ); + } + $db->free_result($request); + + // Get any member names. + if (!empty($members)) + { + require_once(SUBSDIR . '/Members.subs.php'); + $result = getBasicMemberData($members); + $members = array(); + foreach ($result as $row) + $members[$row['id_member']] = $row['real_name']; + + foreach ($edits as $key => $value) + if (isset($members[$value['id_member']])) + $edits[$key]['member_link'] = '' . $members[$value['id_member']] . ''; + } + + return $edits; + } } \ No newline at end of file From 4e795f9bea9021970a6db1405345af465254fac1 Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 06:27:21 +0300 Subject: [PATCH 12/34] ProfileInfo, into a class. (wrapping methods only) Signed-off-by: Norv --- sources/controllers/Profile.controller.php | 5 + .../controllers/ProfileInfo.controller.php | 2704 +++++++++-------- 2 files changed, 1359 insertions(+), 1350 deletions(-) diff --git a/sources/controllers/Profile.controller.php b/sources/controllers/Profile.controller.php index ceae6dfb3d..7a3f5bd67f 100644 --- a/sources/controllers/Profile.controller.php +++ b/sources/controllers/Profile.controller.php @@ -80,6 +80,7 @@ public function action_index() 'summary' => array( 'label' => $txt['summary'], 'file' => '/controllers/ProfileInfo.controller.php', + 'controller' => 'ProfileInfo_Controller', 'function' => 'action_summary', 'permission' => array( 'own' => 'profile_view_own', @@ -89,6 +90,7 @@ public function action_index() 'statistics' => array( 'label' => $txt['statPanel'], 'file' => '/controllers/ProfileInfo.controller.php', + 'controller' => 'ProfileInfo_Controller', 'function' => 'action_statPanel', 'permission' => array( 'own' => 'profile_view_own', @@ -98,6 +100,7 @@ public function action_index() 'showposts' => array( 'label' => $txt['showPosts'], 'file' => '/controllers/ProfileInfo.controller.php', + 'controller' => 'ProfileInfo_Controller', 'function' => 'action_showPosts', 'subsections' => array( 'messages' => array($txt['showMessages'], array('profile_view_own', 'profile_view_any')), @@ -124,6 +127,7 @@ public function action_index() 'permissions' => array( 'label' => $txt['showPermissions'], 'file' => '/controllers/ProfileInfo.controller.php', + 'controller' => 'ProfileInfo_Controller', 'function' => 'action_showPermissions', 'permission' => array( 'own' => 'manage_permissions', @@ -150,6 +154,7 @@ public function action_index() 'label' => $txt['profile_view_warnings'], 'enabled' => in_array('w', $context['admin_features']) && !empty($modSettings['warning_enable']) && $cur_profile['warning'] && (!empty($modSettings['warning_show']) && ($context['user']['is_owner'] || $modSettings['warning_show'] == 2)), 'file' => '/controllers/ProfileInfo.controller.php', + 'controller' => 'ProfileInfo_Controller', 'function' => 'action_viewWarning', 'permission' => array( 'own' => 'profile_view_own', diff --git a/sources/controllers/ProfileInfo.controller.php b/sources/controllers/ProfileInfo.controller.php index 1aa4785f9f..7762004d8c 100644 --- a/sources/controllers/ProfileInfo.controller.php +++ b/sources/controllers/ProfileInfo.controller.php @@ -18,1515 +18,1519 @@ if (!defined('ELKARTE')) die('No access...'); -/** - * View a summary. - */ -function action_summary() +class ProfileInfo_Controller { - global $context, $memberContext, $txt, $modSettings, $user_info, $user_profile; - global $scripturl, $settings; - - $db = database(); - - $memID = currentMemberID(); - - // Attempt to load the member's profile data. - if (!loadMemberContext($memID) || !isset($memberContext[$memID])) - fatal_lang_error('not_a_user', false); - - loadTemplate('ProfileInfo'); - - // Set up the stuff and load the user. - $context += array( - 'page_title' => sprintf($txt['profile_of_username'], $memberContext[$memID]['name']), - 'can_send_pm' => allowedTo('pm_send'), - 'can_send_email' => allowedTo('send_email_to_members'), - 'can_have_buddy' => allowedTo('profile_identity_own') && !empty($modSettings['enable_buddylist']), - 'can_issue_warning' => in_array('w', $context['admin_features']) && allowedTo('issue_warning') && !empty($modSettings['warning_enable']), - ); - $context['member'] = &$memberContext[$memID]; - $context['can_view_warning'] = in_array('w', $context['admin_features']) && (allowedTo('issue_warning') && !$context['user']['is_owner']) || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $context['user']['is_owner'])); - - // Set a canonical URL for this page. - $context['canonical_url'] = $scripturl . '?action=profile;u=' . $memID; - - // Are there things we don't show? - $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); - - // Menu tab - $context[$context['profile_menu_name']]['tab_data'] = array( - 'title' => $txt['summary'], - 'icon' => 'profile_hd.png' - ); - - // See if they have broken any warning levels... - if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) - $context['warning_status'] = $txt['profile_warning_is_muted']; - elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) - $context['warning_status'] = $txt['profile_warning_is_moderation']; - elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) - $context['warning_status'] = $txt['profile_warning_is_watch']; - - // They haven't even been registered for a full day!? - $days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24)); - if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) - $context['member']['posts_per_day'] = $txt['not_applicable']; - else - $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3); - - // Set the age... - if (empty($context['member']['birth_date'])) - { - $context['member'] += array( - 'age' => $txt['not_applicable'], - 'today_is_birthday' => false - ); - } - else + /** + * View a summary. + */ + public function action_summary() { - list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d'); - $datearray = getdate(forum_time()); - $context['member'] += array( - 'age' => $birth_year <= 4 ? $txt['not_applicable'] : $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1), - 'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day - ); - } + global $context, $memberContext, $txt, $modSettings, $user_info, $user_profile; + global $scripturl, $settings; - if (allowedTo('moderate_forum')) - { - // Make sure it's a valid ip address; otherwise, don't bother... - if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) - $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']); - else - $context['member']['hostname'] = ''; + $db = database(); - $context['can_see_ip'] = true; - } - else - $context['can_see_ip'] = false; + $memID = currentMemberID(); - if (!empty($modSettings['who_enabled'])) - { - include_once(SUBSDIR . '/Who.subs.php'); - $action = determineActions($user_profile[$memID]['url']); + // Attempt to load the member's profile data. + if (!loadMemberContext($memID) || !isset($memberContext[$memID])) + fatal_lang_error('not_a_user', false); - if ($action !== false) - $context['member']['action'] = $action; - } + loadTemplate('ProfileInfo'); - // If the user is awaiting activation, and the viewer has permission - setup some activation context messages. - if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum')) - { - $context['activate_type'] = $context['member']['is_activated']; + // Set up the stuff and load the user. + $context += array( + 'page_title' => sprintf($txt['profile_of_username'], $memberContext[$memID]['name']), + 'can_send_pm' => allowedTo('pm_send'), + 'can_send_email' => allowedTo('send_email_to_members'), + 'can_have_buddy' => allowedTo('profile_identity_own') && !empty($modSettings['enable_buddylist']), + 'can_issue_warning' => in_array('w', $context['admin_features']) && allowedTo('issue_warning') && !empty($modSettings['warning_enable']), + ); + $context['member'] = &$memberContext[$memID]; + $context['can_view_warning'] = in_array('w', $context['admin_features']) && (allowedTo('issue_warning') && !$context['user']['is_owner']) || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $context['user']['is_owner'])); - // What should the link text be? - $context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate']; + // Set a canonical URL for this page. + $context['canonical_url'] = $scripturl . '?action=profile;u=' . $memID; - // Should we show a custom message? - $context['activate_message'] = isset($txt['account_activate_method_' . $context['member']['is_activated'] % 10]) ? $txt['account_activate_method_' . $context['member']['is_activated'] % 10] : $txt['account_not_activated']; - } + // Are there things we don't show? + $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); - // Is the signature even enabled on this forum? - $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1; + // Menu tab + $context[$context['profile_menu_name']]['tab_data'] = array( + 'title' => $txt['summary'], + 'icon' => 'profile_hd.png' + ); - // How about, are they banned? - $context['member']['bans'] = array(); - if (allowedTo('moderate_forum')) - { - // Can they edit the ban? - $context['can_edit_ban'] = allowedTo('manage_bans'); + // See if they have broken any warning levels... + if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) + $context['warning_status'] = $txt['profile_warning_is_muted']; + elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) + $context['warning_status'] = $txt['profile_warning_is_moderation']; + elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) + $context['warning_status'] = $txt['profile_warning_is_watch']; + + // They haven't even been registered for a full day!? + $days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24)); + if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) + $context['member']['posts_per_day'] = $txt['not_applicable']; + else + $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3); - $ban_query = array(); - $ban_query_vars = array( - 'time' => time(), - ); - $ban_query[] = 'id_member = ' . $context['member']['id']; - $ban_query[] = constructBanQueryIP($memberContext[$memID]['ip']); + // Set the age... + if (empty($context['member']['birth_date'])) + { + $context['member'] += array( + 'age' => $txt['not_applicable'], + 'today_is_birthday' => false + ); + } + else + { + list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d'); + $datearray = getdate(forum_time()); + $context['member'] += array( + 'age' => $birth_year <= 4 ? $txt['not_applicable'] : $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1), + 'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day + ); + } - // Do we have a hostname already? - if (!empty($context['member']['hostname'])) + if (allowedTo('moderate_forum')) { - $ban_query[] = '({string:hostname} LIKE hostname)'; - $ban_query_vars['hostname'] = $context['member']['hostname']; + // Make sure it's a valid ip address; otherwise, don't bother... + if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) + $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']); + else + $context['member']['hostname'] = ''; + + $context['can_see_ip'] = true; } + else + $context['can_see_ip'] = false; - // Check their email as well... - if (strlen($context['member']['email']) != 0) + if (!empty($modSettings['who_enabled'])) { - $ban_query[] = '({string:email} LIKE bi.email_address)'; - $ban_query_vars['email'] = $context['member']['email']; + include_once(SUBSDIR . '/Who.subs.php'); + $action = determineActions($user_profile[$memID]['url']); + + if ($action !== false) + $context['member']['action'] = $action; } - // So... are they banned? Dying to know! - $request = $db->query('', ' - SELECT bg.id_ban_group, bg.name, bg.cannot_access, bg.cannot_post, bg.cannot_register, - bg.cannot_login, bg.reason - FROM {db_prefix}ban_items AS bi - INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group AND (bg.expire_time IS NULL OR bg.expire_time > {int:time})) - WHERE (' . implode(' OR ', $ban_query) . ')', - $ban_query_vars - ); - while ($row = $db->fetch_assoc($request)) + // If the user is awaiting activation, and the viewer has permission - setup some activation context messages. + if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum')) { - // Work out what restrictions we actually have. - $ban_restrictions = array(); - foreach (array('access', 'register', 'login', 'post') as $type) - if ($row['cannot_' . $type]) - $ban_restrictions[] = $txt['ban_type_' . $type]; - - // No actual ban in place? - if (empty($ban_restrictions)) - continue; + $context['activate_type'] = $context['member']['is_activated']; - // Prepare the link for context. - $ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '' . $row['name'] . ''); + // What should the link text be? + $context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate']; - $context['member']['bans'][$row['id_ban_group']] = array( - 'reason' => empty($row['reason']) ? '' : '

' . $txt['ban_reason'] . ': ' . $row['reason'], - 'cannot' => array( - 'access' => !empty($row['cannot_access']), - 'register' => !empty($row['cannot_register']), - 'post' => !empty($row['cannot_post']), - 'login' => !empty($row['cannot_login']), - ), - 'explanation' => $ban_explanation, - ); + // Should we show a custom message? + $context['activate_message'] = isset($txt['account_activate_method_' . $context['member']['is_activated'] % 10]) ? $txt['account_activate_method_' . $context['member']['is_activated'] % 10] : $txt['account_not_activated']; } - $db->free_result($request); - } - // Load up the most recent attachments for this user for use in profile views etc. - $context['thumbs'] = array(); - if (!empty($modSettings['attachmentEnable']) && allowedTo('view_attachments') && !empty($settings['attachments_on_summary'])) - { - $boardsAllowed = boardsAllowedTo('view_attachments'); - if (empty($boardsAllowed)) - $boardsAllowed = array(-1); - $attachments = list_getAttachments(0, $settings['attachments_on_summary'], 'm.poster_time DESC', $boardsAllowed , $context['member']['id']); + // Is the signature even enabled on this forum? + $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1; + + // How about, are they banned? + $context['member']['bans'] = array(); + if (allowedTo('moderate_forum')) + { + // Can they edit the ban? + $context['can_edit_ban'] = allowedTo('manage_bans'); - // load them in to $context for use in the template - $i = 0; + $ban_query = array(); + $ban_query_vars = array( + 'time' => time(), + ); + $ban_query[] = 'id_member = ' . $context['member']['id']; + $ban_query[] = constructBanQueryIP($memberContext[$memID]['ip']); - // @todo keep or loose the mime thumbs ... useful at all? - $mime_images_url = $settings['default_images_url'] . '/mime_images/'; - $mime_path = $settings['default_theme_dir'] . '/images/mime_images/'; + // Do we have a hostname already? + if (!empty($context['member']['hostname'])) + { + $ban_query[] = '({string:hostname} LIKE hostname)'; + $ban_query_vars['hostname'] = $context['member']['hostname']; + } - for ($i = 0, $count = count($attachments); $i < $count; $i++) - { - $context['thumbs'][$i] = array( - 'url' => $scripturl . '?action=dlattach;topic=' . $attachments[$i]['topic'] . '.0;attach=' . $attachments[$i]['id'], - 'img' => '', + // Check their email as well... + if (strlen($context['member']['email']) != 0) + { + $ban_query[] = '({string:email} LIKE bi.email_address)'; + $ban_query_vars['email'] = $context['member']['email']; + } + + // So... are they banned? Dying to know! + $request = $db->query('', ' + SELECT bg.id_ban_group, bg.name, bg.cannot_access, bg.cannot_post, bg.cannot_register, + bg.cannot_login, bg.reason + FROM {db_prefix}ban_items AS bi + INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group AND (bg.expire_time IS NULL OR bg.expire_time > {int:time})) + WHERE (' . implode(' OR ', $ban_query) . ')', + $ban_query_vars ); + while ($row = $db->fetch_assoc($request)) + { + // Work out what restrictions we actually have. + $ban_restrictions = array(); + foreach (array('access', 'register', 'login', 'post') as $type) + if ($row['cannot_' . $type]) + $ban_restrictions[] = $txt['ban_type_' . $type]; + + // No actual ban in place? + if (empty($ban_restrictions)) + continue; + + // Prepare the link for context. + $ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '' . $row['name'] . ''); + + $context['member']['bans'][$row['id_ban_group']] = array( + 'reason' => empty($row['reason']) ? '' : '

' . $txt['ban_reason'] . ': ' . $row['reason'], + 'cannot' => array( + 'access' => !empty($row['cannot_access']), + 'register' => !empty($row['cannot_register']), + 'post' => !empty($row['cannot_post']), + 'login' => !empty($row['cannot_login']), + ), + 'explanation' => $ban_explanation, + ); + } + $db->free_result($request); + } + + // Load up the most recent attachments for this user for use in profile views etc. + $context['thumbs'] = array(); + if (!empty($modSettings['attachmentEnable']) && allowedTo('view_attachments') && !empty($settings['attachments_on_summary'])) + { + $boardsAllowed = boardsAllowedTo('view_attachments'); + if (empty($boardsAllowed)) + $boardsAllowed = array(-1); + $attachments = list_getAttachments(0, $settings['attachments_on_summary'], 'm.poster_time DESC', $boardsAllowed , $context['member']['id']); + + // load them in to $context for use in the template + $i = 0; + + // @todo keep or loose the mime thumbs ... useful at all? + $mime_images_url = $settings['default_images_url'] . '/mime_images/'; + $mime_path = $settings['default_theme_dir'] . '/images/mime_images/'; - // Show a thumbnail image well? - if ($attachments[$i]['is_image'] && !empty($modSettings['attachmentShowImages']) && !empty($modSettings['attachmentThumbnails'])) + for ($i = 0, $count = count($attachments); $i < $count; $i++) { - if (!empty($attachments[$i]['id_thumb'])) - $context['thumbs'][$i]['img'] = ''; - else + $context['thumbs'][$i] = array( + 'url' => $scripturl . '?action=dlattach;topic=' . $attachments[$i]['topic'] . '.0;attach=' . $attachments[$i]['id'], + 'img' => '', + ); + + // Show a thumbnail image well? + if ($attachments[$i]['is_image'] && !empty($modSettings['attachmentShowImages']) && !empty($modSettings['attachmentThumbnails'])) { - // no thumbnail available ... use html instead - if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight'])) + if (!empty($attachments[$i]['id_thumb'])) + $context['thumbs'][$i]['img'] = ''; + else { - if ($attachments[$i]['width'] > $modSettings['attachmentThumbWidth'] || $attachments[$i]['height'] > $modSettings['attachmentThumbHeight']) - $context['thumbs'][$i]['img'] = ''; - else - $context['thumbs'][$i]['img'] = ''; + // no thumbnail available ... use html instead + if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight'])) + { + if ($attachments[$i]['width'] > $modSettings['attachmentThumbWidth'] || $attachments[$i]['height'] > $modSettings['attachmentThumbHeight']) + $context['thumbs'][$i]['img'] = ''; + else + $context['thumbs'][$i]['img'] = ''; + } } } - } - // Not an image so lets set a mime thumbnail based off the filetype - else - { - if ((!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight'])) && (128 > $modSettings['attachmentThumbWidth'] || 128 > $modSettings['attachmentThumbHeight'])) - $context['thumbs'][$i]['img'] = ''; + // Not an image so lets set a mime thumbnail based off the filetype else - $context['thumbs'][$i]['img'] = ''; + { + if ((!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight'])) && (128 > $modSettings['attachmentThumbWidth'] || 128 > $modSettings['attachmentThumbHeight'])) + $context['thumbs'][$i]['img'] = ''; + else + $context['thumbs'][$i]['img'] = ''; + } } } - } - - // Would you be mine? Could you be mine? Be my buddy :D - if (!empty($modSettings['enable_buddylist']) && $context['user']['is_owner'] && !empty($user_info['buddies'])) - { - $context['buddies'] = array(); - loadMemberData($user_info['buddies'], false, 'profile'); - // Get the info for this buddy - foreach ($user_info['buddies'] as $buddy) + // Would you be mine? Could you be mine? Be my buddy :D + if (!empty($modSettings['enable_buddylist']) && $context['user']['is_owner'] && !empty($user_info['buddies'])) { - loadMemberContext($buddy); - $context['buddies'][$buddy] = $memberContext[$buddy]; + $context['buddies'] = array(); + loadMemberData($user_info['buddies'], false, 'profile'); + + // Get the info for this buddy + foreach ($user_info['buddies'] as $buddy) + { + loadMemberContext($buddy); + $context['buddies'][$buddy] = $memberContext[$buddy]; + } } - } - // To finish this off, custom profile fields. - require_once(SUBSDIR . '/Profile.subs.php'); - loadCustomFields($memID); -} + // To finish this off, custom profile fields. + require_once(SUBSDIR . '/Profile.subs.php'); + loadCustomFields($memID); + } -/** - * Show all posts by the current user - * @todo This function needs to be split up properly. - */ -function action_showPosts() -{ - global $txt, $user_info, $scripturl, $modSettings; - global $context, $user_profile, $board; + /** + * Show all posts by the current user. + * + * @todo This function needs to be split up properly. + */ + public function action_showPosts() + { + global $txt, $user_info, $scripturl, $modSettings; + global $context, $user_profile, $board; - $db = database(); + $db = database(); - $memID = currentMemberID(); + $memID = currentMemberID(); - // Some initial context. - $context['start'] = (int) $_REQUEST['start']; - $context['current_member'] = $memID; + // Some initial context. + $context['start'] = (int) $_REQUEST['start']; + $context['current_member'] = $memID; - loadTemplate('ProfileInfo'); + loadTemplate('ProfileInfo'); - // Create the tabs for the template. - $context[$context['profile_menu_name']]['tab_data'] = array( - 'title' => $txt['showPosts'], - 'description' => $txt['showPosts_help'], - 'icon' => 'profile_hd.png', - 'tabs' => array( - 'messages' => array( - ), - 'topics' => array( - ), - 'disregardedtopics' => array( - ), - 'attach' => array( + // Create the tabs for the template. + $context[$context['profile_menu_name']]['tab_data'] = array( + 'title' => $txt['showPosts'], + 'description' => $txt['showPosts_help'], + 'icon' => 'profile_hd.png', + 'tabs' => array( + 'messages' => array( + ), + 'topics' => array( + ), + 'disregardedtopics' => array( + ), + 'attach' => array( + ), ), - ), - ); - - // Set the page title - $context['page_title'] = $txt['showPosts'] . ' - ' . $user_profile[$memID]['real_name']; - - // Is the load average too high to allow searching just now? - if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) - fatal_lang_error('loadavg_show_posts_disabled', false); - - // If we're specifically dealing with attachments use that function! - if (isset($_GET['sa']) && $_GET['sa'] == 'attach') - return action_showAttachments($memID); - // Instead, if we're dealing with disregarded topics (and the feature is enabled) use that other function. - elseif (isset($_GET['sa']) && $_GET['sa'] == 'disregardedtopics' && $modSettings['enable_disregard']) - return action_showDisregarded($memID); + ); - // Are we just viewing topics? - $context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false; + // Set the page title + $context['page_title'] = $txt['showPosts'] . ' - ' . $user_profile[$memID]['real_name']; - // If just deleting a message, do it and then redirect back. - if (isset($_GET['delete']) && !$context['is_topics']) - { - checkSession('get'); + // Is the load average too high to allow searching just now? + if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) + fatal_lang_error('loadavg_show_posts_disabled', false); - // We need msg info for logging. - require_once(SUBSDIR . '/Messages.subs.php'); - $info = basicMessageInfo((int) $_GET['delete'], true); + // If we're specifically dealing with attachments use that function! + if (isset($_GET['sa']) && $_GET['sa'] == 'attach') + return $this->action_showAttachments($memID); + // Instead, if we're dealing with disregarded topics (and the feature is enabled) use that other function. + elseif (isset($_GET['sa']) && $_GET['sa'] == 'disregardedtopics' && $modSettings['enable_disregard']) + return $this->action_showDisregarded($memID); - // Trying to remove a message that doesn't exist. - if (empty($info)) - redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); + // Are we just viewing topics? + $context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false; - // We can be lazy, since removeMessage() will check the permissions for us. - require_once(SUBSDIR . '/Messages.subs.php'); - removeMessage((int) $_GET['delete']); + // If just deleting a message, do it and then redirect back. + if (isset($_GET['delete']) && !$context['is_topics']) + { + checkSession('get'); - // Add it to the mod log. - if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info['id_member'] != $user_info['id'])) - logAction('delete', array('topic' => $info['id_topic'], 'subject' => $info['subject'], 'member' => $info['id_member'], 'board' => $info['id_board'])); + // We need msg info for logging. + require_once(SUBSDIR . '/Messages.subs.php'); + $info = basicMessageInfo((int) $_GET['delete'], true); - // Back to... where we are now ;). - redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); - } + // Trying to remove a message that doesn't exist. + if (empty($info)) + redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); - // Default to 10. - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) - $_REQUEST['viewscount'] = '10'; + // We can be lazy, since removeMessage() will check the permissions for us. + require_once(SUBSDIR . '/Messages.subs.php'); + removeMessage((int) $_GET['delete']); - if ($context['is_topics']) - $request = $db->query('', ' - SELECT COUNT(*) - FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : ' - INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . ' - WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? ' - AND t.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' - AND t.approved = {int:is_approved}'), - array( - 'current_member' => $memID, - 'is_approved' => 1, - 'board' => $board, - ) - ); - else - $request = $db->query('', ' - SELECT COUNT(*) - FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : ' - INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . ' - WHERE m.id_member = {int:current_member}' . (!empty($board) ? ' - AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' - AND m.approved = {int:is_approved}'), - array( - 'current_member' => $memID, - 'is_approved' => 1, - 'board' => $board, - ) - ); - list ($msgCount) = $db->fetch_row($request); - $db->free_result($request); - - $request = $db->query('', ' - SELECT MIN(id_msg), MAX(id_msg) - FROM {db_prefix}messages AS m - WHERE m.id_member = {int:current_member}' . (!empty($board) ? ' - AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' - AND m.approved = {int:is_approved}'), - array( - 'current_member' => $memID, - 'is_approved' => 1, - 'board' => $board, - ) - ); - list ($min_msg_member, $max_msg_member) = $db->fetch_row($request); - $db->free_result($request); - - $reverse = false; - $range_limit = ''; - $maxIndex = (int) $modSettings['defaultMaxMessages']; - - // Make sure the starting place makes sense and construct our friend the page index. - $context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID . ';area=showposts' . ($context['is_topics'] ? ';sa=topics' : '') . (!empty($board) ? ';board=' . $board : ''), $context['start'], $msgCount, $maxIndex); - $context['current_page'] = $context['start'] / $maxIndex; - - // Reverse the query if we're past 50% of the pages for better performance. - $start = $context['start']; - $reverse = $_REQUEST['start'] > $msgCount / 2; - if ($reverse) - { - $maxIndex = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 && $msgCount > $context['start'] ? $msgCount - $context['start'] : (int) $modSettings['defaultMaxMessages']; - $start = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 || $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] ? 0 : $msgCount - $context['start'] - $modSettings['defaultMaxMessages']; - } + // Add it to the mod log. + if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info['id_member'] != $user_info['id'])) + logAction('delete', array('topic' => $info['id_topic'], 'subject' => $info['subject'], 'member' => $info['id_member'], 'board' => $info['id_board'])); - // Guess the range of messages to be shown. - if ($msgCount > 1000) - { - $margin = floor(($max_msg_member - $min_msg_member) * (($start + $modSettings['defaultMaxMessages']) / $msgCount) + .1 * ($max_msg_member - $min_msg_member)); - // Make a bigger margin for topics only. - if ($context['is_topics']) - { - $margin *= 5; - $range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin); + // Back to... where we are now ;). + redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); } - else - $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin); - } - // Find this user's posts. The left join on categories somehow makes this faster, weird as it looks. - $looped = false; - while (true) - { + // Default to 10. + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) + $_REQUEST['viewscount'] = '10'; + if ($context['is_topics']) - { $request = $db->query('', ' - SELECT - b.id_board, b.name AS bname, c.id_cat, c.name AS cname, t.id_member_started, t.id_first_msg, t.id_last_msg, - t.approved, m.body, m.smileys_enabled, m.subject, m.poster_time, m.id_topic, m.id_msg - FROM {db_prefix}topics AS t - INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) - LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) - INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg) + SELECT COUNT(*) + FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : ' + INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . ' WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? ' - AND t.id_board = {int:board}' : '') . (empty($range_limit) ? '' : ' - AND ' . $range_limit) . ' - AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' - AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . ' - ORDER BY t.id_first_msg ' . ($reverse ? 'ASC' : 'DESC') . ' - LIMIT ' . $start . ', ' . $maxIndex, + AND t.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' + AND t.approved = {int:is_approved}'), array( 'current_member' => $memID, 'is_approved' => 1, 'board' => $board, ) ); - } else - { $request = $db->query('', ' - SELECT - b.id_board, b.name AS bname, c.id_cat, c.name AS cname, m.id_topic, m.id_msg, - t.id_member_started, t.id_first_msg, t.id_last_msg, m.body, m.smileys_enabled, - m.subject, m.poster_time, m.approved - FROM {db_prefix}messages AS m - INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) - INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) - LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) + SELECT COUNT(*) + FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : ' + INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . ' WHERE m.id_member = {int:current_member}' . (!empty($board) ? ' - AND b.id_board = {int:board}' : '') . (empty($range_limit) ? '' : ' - AND ' . $range_limit) . ' - AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' - AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . ' - ORDER BY m.id_msg ' . ($reverse ? 'ASC' : 'DESC') . ' - LIMIT ' . $start . ', ' . $maxIndex, + AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' + AND m.approved = {int:is_approved}'), array( 'current_member' => $memID, 'is_approved' => 1, 'board' => $board, ) ); - } + list ($msgCount) = $db->fetch_row($request); + $db->free_result($request); + + $request = $db->query('', ' + SELECT MIN(id_msg), MAX(id_msg) + FROM {db_prefix}messages AS m + WHERE m.id_member = {int:current_member}' . (!empty($board) ? ' + AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' + AND m.approved = {int:is_approved}'), + array( + 'current_member' => $memID, + 'is_approved' => 1, + 'board' => $board, + ) + ); + list ($min_msg_member, $max_msg_member) = $db->fetch_row($request); + $db->free_result($request); - // Make sure we quit this loop. - if ($db->num_rows($request) === $maxIndex || $looped) - break; - $looped = true; + $reverse = false; $range_limit = ''; - } + $maxIndex = (int) $modSettings['defaultMaxMessages']; - // Start counting at the number of the first message displayed. - $counter = $reverse ? $context['start'] + $maxIndex + 1 : $context['start']; - $context['posts'] = array(); - $board_ids = array('own' => array(), 'any' => array()); - while ($row = $db->fetch_assoc($request)) - { - // Censor.... - censorText($row['body']); - censorText($row['subject']); - - // Do the code. - $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); - - // And the array... - $context['posts'][$counter += $reverse ? -1 : 1] = array( - 'body' => $row['body'], - 'counter' => $counter, - 'alternate' => $counter % 2, - 'category' => array( - 'name' => $row['cname'], - 'id' => $row['id_cat'] - ), - 'board' => array( - 'name' => $row['bname'], - 'id' => $row['id_board'] - ), - 'topic' => $row['id_topic'], - 'subject' => $row['subject'], - 'start' => 'msg' . $row['id_msg'], - 'time' => relativeTime($row['poster_time']), - 'timestamp' => forum_time(true, $row['poster_time']), - 'id' => $row['id_msg'], - 'can_reply' => false, - 'can_mark_notify' => false, - 'can_delete' => false, - 'delete_possible' => ($row['id_first_msg'] != $row['id_msg'] || $row['id_last_msg'] == $row['id_msg']) && (empty($modSettings['edit_disable_time']) || $row['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()), - 'approved' => $row['approved'], - ); + // Make sure the starting place makes sense and construct our friend the page index. + $context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID . ';area=showposts' . ($context['is_topics'] ? ';sa=topics' : '') . (!empty($board) ? ';board=' . $board : ''), $context['start'], $msgCount, $maxIndex); + $context['current_page'] = $context['start'] / $maxIndex; - if ($user_info['id'] == $row['id_member_started']) - $board_ids['own'][$row['id_board']][] = $counter; - $board_ids['any'][$row['id_board']][] = $counter; - } - $db->free_result($request); + // Reverse the query if we're past 50% of the pages for better performance. + $start = $context['start']; + $reverse = $_REQUEST['start'] > $msgCount / 2; + if ($reverse) + { + $maxIndex = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 && $msgCount > $context['start'] ? $msgCount - $context['start'] : (int) $modSettings['defaultMaxMessages']; + $start = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 || $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] ? 0 : $msgCount - $context['start'] - $modSettings['defaultMaxMessages']; + } - // All posts were retrieved in reverse order, get them right again. - if ($reverse) - $context['posts'] = array_reverse($context['posts'], true); + // Guess the range of messages to be shown. + if ($msgCount > 1000) + { + $margin = floor(($max_msg_member - $min_msg_member) * (($start + $modSettings['defaultMaxMessages']) / $msgCount) + .1 * ($max_msg_member - $min_msg_member)); + // Make a bigger margin for topics only. + if ($context['is_topics']) + { + $margin *= 5; + $range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin); + } + else + $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin); + } - // These are all the permissions that are different from board to board.. - if ($context['is_topics']) - $permissions = array( - 'own' => array( - 'post_reply_own' => 'can_reply', - ), - 'any' => array( - 'post_reply_any' => 'can_reply', - 'mark_any_notify' => 'can_mark_notify', - ) - ); - else - $permissions = array( - 'own' => array( - 'post_reply_own' => 'can_reply', - 'delete_own' => 'can_delete', - ), - 'any' => array( - 'post_reply_any' => 'can_reply', - 'mark_any_notify' => 'can_mark_notify', - 'delete_any' => 'can_delete', - ) - ); + // Find this user's posts. The left join on categories somehow makes this faster, weird as it looks. + $looped = false; + while (true) + { + if ($context['is_topics']) + { + $request = $db->query('', ' + SELECT + b.id_board, b.name AS bname, c.id_cat, c.name AS cname, t.id_member_started, t.id_first_msg, t.id_last_msg, + t.approved, m.body, m.smileys_enabled, m.subject, m.poster_time, m.id_topic, m.id_msg + FROM {db_prefix}topics AS t + INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) + LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) + INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg) + WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? ' + AND t.id_board = {int:board}' : '') . (empty($range_limit) ? '' : ' + AND ' . $range_limit) . ' + AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' + AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . ' + ORDER BY t.id_first_msg ' . ($reverse ? 'ASC' : 'DESC') . ' + LIMIT ' . $start . ', ' . $maxIndex, + array( + 'current_member' => $memID, + 'is_approved' => 1, + 'board' => $board, + ) + ); + } + else + { + $request = $db->query('', ' + SELECT + b.id_board, b.name AS bname, c.id_cat, c.name AS cname, m.id_topic, m.id_msg, + t.id_member_started, t.id_first_msg, t.id_last_msg, m.body, m.smileys_enabled, + m.subject, m.poster_time, m.approved + FROM {db_prefix}messages AS m + INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) + INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) + LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) + WHERE m.id_member = {int:current_member}' . (!empty($board) ? ' + AND b.id_board = {int:board}' : '') . (empty($range_limit) ? '' : ' + AND ' . $range_limit) . ' + AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' + AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . ' + ORDER BY m.id_msg ' . ($reverse ? 'ASC' : 'DESC') . ' + LIMIT ' . $start . ', ' . $maxIndex, + array( + 'current_member' => $memID, + 'is_approved' => 1, + 'board' => $board, + ) + ); + } - // For every permission in the own/any lists... - foreach ($permissions as $type => $list) - { - foreach ($list as $permission => $allowed) + // Make sure we quit this loop. + if ($db->num_rows($request) === $maxIndex || $looped) + break; + $looped = true; + $range_limit = ''; + } + + // Start counting at the number of the first message displayed. + $counter = $reverse ? $context['start'] + $maxIndex + 1 : $context['start']; + $context['posts'] = array(); + $board_ids = array('own' => array(), 'any' => array()); + while ($row = $db->fetch_assoc($request)) { - // Get the boards they can do this on... - $boards = boardsAllowedTo($permission); + // Censor.... + censorText($row['body']); + censorText($row['subject']); + + // Do the code. + $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); + + // And the array... + $context['posts'][$counter += $reverse ? -1 : 1] = array( + 'body' => $row['body'], + 'counter' => $counter, + 'alternate' => $counter % 2, + 'category' => array( + 'name' => $row['cname'], + 'id' => $row['id_cat'] + ), + 'board' => array( + 'name' => $row['bname'], + 'id' => $row['id_board'] + ), + 'topic' => $row['id_topic'], + 'subject' => $row['subject'], + 'start' => 'msg' . $row['id_msg'], + 'time' => relativeTime($row['poster_time']), + 'timestamp' => forum_time(true, $row['poster_time']), + 'id' => $row['id_msg'], + 'can_reply' => false, + 'can_mark_notify' => false, + 'can_delete' => false, + 'delete_possible' => ($row['id_first_msg'] != $row['id_msg'] || $row['id_last_msg'] == $row['id_msg']) && (empty($modSettings['edit_disable_time']) || $row['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()), + 'approved' => $row['approved'], + ); + + if ($user_info['id'] == $row['id_member_started']) + $board_ids['own'][$row['id_board']][] = $counter; + $board_ids['any'][$row['id_board']][] = $counter; + } + $db->free_result($request); + + // All posts were retrieved in reverse order, get them right again. + if ($reverse) + $context['posts'] = array_reverse($context['posts'], true); - // Hmm, they can do it on all boards, can they? - if (!empty($boards) && $boards[0] == 0) - $boards = array_keys($board_ids[$type]); + // These are all the permissions that are different from board to board.. + if ($context['is_topics']) + $permissions = array( + 'own' => array( + 'post_reply_own' => 'can_reply', + ), + 'any' => array( + 'post_reply_any' => 'can_reply', + 'mark_any_notify' => 'can_mark_notify', + ) + ); + else + $permissions = array( + 'own' => array( + 'post_reply_own' => 'can_reply', + 'delete_own' => 'can_delete', + ), + 'any' => array( + 'post_reply_any' => 'can_reply', + 'mark_any_notify' => 'can_mark_notify', + 'delete_any' => 'can_delete', + ) + ); - // Now go through each board they can do the permission on. - foreach ($boards as $board_id) + // For every permission in the own/any lists... + foreach ($permissions as $type => $list) + { + foreach ($list as $permission => $allowed) { - // There aren't any posts displayed from this board. - if (!isset($board_ids[$type][$board_id])) - continue; + // Get the boards they can do this on... + $boards = boardsAllowedTo($permission); + + // Hmm, they can do it on all boards, can they? + if (!empty($boards) && $boards[0] == 0) + $boards = array_keys($board_ids[$type]); + + // Now go through each board they can do the permission on. + foreach ($boards as $board_id) + { + // There aren't any posts displayed from this board. + if (!isset($board_ids[$type][$board_id])) + continue; - // Set the permission to true ;). - foreach ($board_ids[$type][$board_id] as $counter) - $context['posts'][$counter][$allowed] = true; + // Set the permission to true ;). + foreach ($board_ids[$type][$board_id] as $counter) + $context['posts'][$counter][$allowed] = true; + } } } + + // Clean up after posts that cannot be deleted and quoted. + $quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC'])); + foreach ($context['posts'] as $counter => $dummy) + { + $context['posts'][$counter]['can_delete'] &= $context['posts'][$counter]['delete_possible']; + $context['posts'][$counter]['can_quote'] = $context['posts'][$counter]['can_reply'] && $quote_enabled; + } } - // Clean up after posts that cannot be deleted and quoted. - $quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC'])); - foreach ($context['posts'] as $counter => $dummy) + /** + * Show all the attachments of a user. + */ + public function action_showAttachments() { - $context['posts'][$counter]['can_delete'] &= $context['posts'][$counter]['delete_possible']; - $context['posts'][$counter]['can_quote'] = $context['posts'][$counter]['can_reply'] && $quote_enabled; - } -} + global $txt, $scripturl, $modSettings; -/** - * Show all the attachments of a user. - */ -function action_showAttachments() -{ - global $txt, $scripturl, $modSettings; - - // OBEY permissions! - $boardsAllowed = boardsAllowedTo('view_attachments'); - - // Make sure we can't actually see anything... - if (empty($boardsAllowed)) - $boardsAllowed = array(-1); - - $memID = currentMemberID(); - - require_once(SUBSDIR . '/List.subs.php'); - - // This is all the information required to list attachments. - $listOptions = array( - 'id' => 'attachments', - 'width' => '100%', - 'items_per_page' => $modSettings['defaultMaxMessages'], - 'no_items_label' => $txt['show_attachments_none'], - 'base_href' => $scripturl . '?action=profile;area=showposts;sa=attach;u=' . $memID, - 'default_sort_col' => 'filename', - 'get_items' => array( - 'function' => 'list_getAttachments', - 'params' => array( - $boardsAllowed, - $memID, - ), - ), - 'get_count' => array( - 'function' => 'list_getNumAttachments', - 'params' => array( - $boardsAllowed, - $memID, + // OBEY permissions! + $boardsAllowed = boardsAllowedTo('view_attachments'); + + // Make sure we can't actually see anything... + if (empty($boardsAllowed)) + $boardsAllowed = array(-1); + + $memID = currentMemberID(); + + require_once(SUBSDIR . '/List.subs.php'); + + // This is all the information required to list attachments. + $listOptions = array( + 'id' => 'attachments', + 'width' => '100%', + 'items_per_page' => $modSettings['defaultMaxMessages'], + 'no_items_label' => $txt['show_attachments_none'], + 'base_href' => $scripturl . '?action=profile;area=showposts;sa=attach;u=' . $memID, + 'default_sort_col' => 'filename', + 'get_items' => array( + 'function' => 'list_getAttachments', + 'params' => array( + $boardsAllowed, + $memID, + ), ), - ), - 'data_check' => array( - 'class' => create_function('$data', ' - return $data[\'approved\'] ? \'\' : \'approvebg\'; - ') - ), - 'columns' => array( - 'filename' => array( - 'header' => array( - 'value' => $txt['show_attach_downloads'], - 'class' => 'lefttext', - 'style' => 'width: 25%;', + 'get_count' => array( + 'function' => 'list_getNumAttachments', + 'params' => array( + $boardsAllowed, + $memID, ), - 'data' => array( - 'db' => 'filename', + ), + 'data_check' => array( + 'class' => create_function('$data', ' + return $data[\'approved\'] ? \'\' : \'approvebg\'; + ') + ), + 'columns' => array( + 'filename' => array( + 'header' => array( + 'value' => $txt['show_attach_downloads'], + 'class' => 'lefttext', + 'style' => 'width: 25%;', + ), + 'data' => array( + 'db' => 'filename', + ), + 'sort' => array( + 'default' => 'a.filename', + 'reverse' => 'a.filename DESC', + ), ), - 'sort' => array( - 'default' => 'a.filename', - 'reverse' => 'a.filename DESC', + 'downloads' => array( + 'header' => array( + 'value' => $txt['show_attach_downloads'], + 'style' => 'width: 12%;', + ), + 'data' => array( + 'db' => 'downloads', + 'comma_format' => true, + ), + 'sort' => array( + 'default' => 'a.downloads', + 'reverse' => 'a.downloads DESC', + ), ), - ), - 'downloads' => array( - 'header' => array( - 'value' => $txt['show_attach_downloads'], - 'style' => 'width: 12%;', + 'subject' => array( + 'header' => array( + 'value' => $txt['message'], + 'class' => 'lefttext', + 'style' => 'width: 30%;', + ), + 'data' => array( + 'db' => 'subject', + ), + 'sort' => array( + 'default' => 'm.subject', + 'reverse' => 'm.subject DESC', + ), ), - 'data' => array( - 'db' => 'downloads', - 'comma_format' => true, + 'posted' => array( + 'header' => array( + 'value' => $txt['show_attach_posted'], + 'class' => 'lefttext', + ), + 'data' => array( + 'db' => 'posted', + 'timeformat' => true, + ), + 'sort' => array( + 'default' => 'm.poster_time', + 'reverse' => 'm.poster_time DESC', + ), ), - 'sort' => array( - 'default' => 'a.downloads', - 'reverse' => 'a.downloads DESC', + ), + ); + + // Create the request list. + createList($listOptions); + } + + /** + * Show all the disregarded topics. + * + */ + public function action_showDisregarded() + { + global $txt, $user_info, $scripturl, $modSettings, $context; + + $memID = currentMemberID(); + + // Only the owner can see the list (if the function is enabled of course) + if ($user_info['id'] != $memID || !$modSettings['enable_disregard']) + return; + + require_once(SUBSDIR . '/List.subs.php'); + + // And here they are: the topics you don't like + $listOptions = array( + 'id' => 'disregarded_topics', + 'width' => '100%', + 'items_per_page' => $modSettings['defaultMaxMessages'], + 'no_items_label' => $txt['disregarded_topics_none'], + 'base_href' => $scripturl . '?action=profile;area=showposts;sa=disregardedtopics;u=' . $memID, + 'default_sort_col' => 'started_on', + 'get_items' => array( + 'function' => 'list_getDisregarded', + 'params' => array( + $memID, ), ), - 'subject' => array( - 'header' => array( - 'value' => $txt['message'], - 'class' => 'lefttext', - 'style' => 'width: 30%;', + 'get_count' => array( + 'function' => 'list_getNumDisregarded', + 'params' => array( + $memID, ), - 'data' => array( - 'db' => 'subject', + ), + 'columns' => array( + 'subject' => array( + 'header' => array( + 'value' => $txt['subject'], + 'class' => 'lefttext', + 'style' => 'width: 30%;', + ), + 'data' => array( + 'sprintf' => array( + 'format' => '%2$s', + 'params' => array( + 'id_topic' => false, + 'subject' => false, + ), + ), + ), + 'sort' => array( + 'default' => 'm.subject', + 'reverse' => 'm.subject DESC', + ), ), - 'sort' => array( - 'default' => 'm.subject', - 'reverse' => 'm.subject DESC', + 'started_by' => array( + 'header' => array( + 'value' => $txt['started_by'], + 'style' => 'width: 15%;', + ), + 'data' => array( + 'db' => 'started_by', + ), + 'sort' => array( + 'default' => 'mem.real_name', + 'reverse' => 'mem.real_name DESC', + ), ), - ), - 'posted' => array( - 'header' => array( - 'value' => $txt['show_attach_posted'], - 'class' => 'lefttext', + 'started_on' => array( + 'header' => array( + 'value' => $txt['on'], + 'class' => 'lefttext', + 'style' => 'width: 20%;', + ), + 'data' => array( + 'db' => 'started_on', + 'timeformat' => true, + ), + 'sort' => array( + 'default' => 'm.poster_time', + 'reverse' => 'm.poster_time DESC', + ), ), - 'data' => array( - 'db' => 'posted', - 'timeformat' => true, + 'last_post_by' => array( + 'header' => array( + 'value' => $txt['last_post'], + 'style' => 'width: 15%;', + ), + 'data' => array( + 'db' => 'last_post_by', + ), + 'sort' => array( + 'default' => 'mem.real_name', + 'reverse' => 'mem.real_name DESC', + ), ), - 'sort' => array( - 'default' => 'm.poster_time', - 'reverse' => 'm.poster_time DESC', + 'last_post_on' => array( + 'header' => array( + 'value' => $txt['on'], + 'class' => 'lefttext', + 'style' => 'width: 20%;', + ), + 'data' => array( + 'db' => 'last_post_on', + 'timeformat' => true, + ), + 'sort' => array( + 'default' => 'm.poster_time', + 'reverse' => 'm.poster_time DESC', + ), ), ), - ), - ); + ); - // Create the request list. - createList($listOptions); -} + // Create the request list. + createList($listOptions); -/** - * Get a list of attachments for this user - * - * @param int $start - * @param int $items_per_page - * @param string $sort - * @param array $boardsAllowed - * @param ing $memID - * @return array - */ -function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID) -{ - global $board, $modSettings, $context, $settings, $scripturl, $txt; - - $db = database(); - - // Retrieve some attachments. - $request = $db->query('', ' - SELECT a.id_attach, a.id_msg, a.filename, a.downloads, a.approved, a.fileext, a.width, a.height, ' . - (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ' IFNULL(thumb.id_attach, 0) AS id_thumb, thumb.width AS thumb_width, thumb.height AS thumb_height, ') . ' - m.id_msg, m.id_topic, m.id_board, m.poster_time, m.subject, b.name - FROM {db_prefix}attachments AS a' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ' - LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = a.id_thumb)') . ' - INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) - INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board}) - WHERE a.attachment_type = {int:attachment_type} - AND a.id_msg != {int:no_message} - AND m.id_member = {int:current_member}' . (!empty($board) ? ' - AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? ' - AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' - AND m.approved = {int:is_approved}') . ' - ORDER BY {raw:sort} - LIMIT {int:offset}, {int:limit}', - array( - 'boards_list' => $boardsAllowed, - 'attachment_type' => 0, - 'no_message' => 0, - 'current_member' => $memID, - 'is_approved' => 1, - 'board' => $board, - 'sort' => $sort, - 'offset' => $start, - 'limit' => $items_per_page, - ) - ); - $attachments = array(); - while ($row = $db->fetch_assoc($request)) - { - if (!$row['approved']) - $row['filename'] = str_replace(array('{attachment_link}', '{txt_awaiting}'), array('' . $row['filename'] . '', $txt['awaiting_approval']), $settings['attachments_awaiting_approval']); - else - $row['filename'] = '' . $row['filename'] . ''; - - $attachments[] = array( - 'id' => $row['id_attach'], - 'filename' => $row['filename'], - 'fileext' => $row['fileext'], - 'width' => $row['width'], - 'height' => $row['height'], - 'downloads' => $row['downloads'], - 'is_image' => !empty($row['width']) && !empty($row['height']) && !empty($modSettings['attachmentShowImages']), - 'id_thumb' => $row['id_thumb'], - 'subject' => '' . censorText($row['subject']) . '', - 'posted' => $row['poster_time'], - 'msg' => $row['id_msg'], - 'topic' => $row['id_topic'], - 'board' => $row['id_board'], - 'board_name' => $row['name'], - 'approved' => $row['approved'], - ); + $context['sub_template'] = 'show_list'; + $context['default_list'] = 'disregarded_topics'; } - $db->free_result($request); + /** + * Gets the user stats for display. + * + */ + public function action_statPanel() + { + global $txt, $scripturl, $context, $user_profile, $user_info, $modSettings; - return $attachments; -} + $db = database(); -/** - * Gets the total number of attachments for the user - * - * @param type $boardsAllowed - * @param type $memID - * @return type - */ -function list_getNumAttachments($boardsAllowed, $memID) -{ - global $board, $modSettings, $context; - - $db = database(); - - // Get the total number of attachments they have posted. - $request = $db->query('', ' - SELECT COUNT(*) - FROM {db_prefix}attachments AS a - INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) - INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board}) - WHERE a.attachment_type = {int:attachment_type} - AND a.id_msg != {int:no_message} - AND m.id_member = {int:current_member}' . (!empty($board) ? ' - AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? ' - AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' - AND m.approved = {int:is_approved}'), - array( - 'boards_list' => $boardsAllowed, - 'attachment_type' => 0, - 'no_message' => 0, - 'current_member' => $memID, - 'is_approved' => 1, - 'board' => $board, - ) - ); - list ($attachCount) = $db->fetch_row($request); - $db->free_result($request); - - return $attachCount; -} + $memID = currentMemberID(); -/** - * Show all the disregarded topics. - * - */ -function action_showDisregarded() -{ - global $txt, $user_info, $scripturl, $modSettings, $context; - - $memID = currentMemberID(); - - // Only the owner can see the list (if the function is enabled of course) - if ($user_info['id'] != $memID || !$modSettings['enable_disregard']) - return; - - require_once(SUBSDIR . '/List.subs.php'); - - // And here they are: the topics you don't like - $listOptions = array( - 'id' => 'disregarded_topics', - 'width' => '100%', - 'items_per_page' => $modSettings['defaultMaxMessages'], - 'no_items_label' => $txt['disregarded_topics_none'], - 'base_href' => $scripturl . '?action=profile;area=showposts;sa=disregardedtopics;u=' . $memID, - 'default_sort_col' => 'started_on', - 'get_items' => array( - 'function' => 'list_getDisregarded', - 'params' => array( - $memID, - ), - ), - 'get_count' => array( - 'function' => 'list_getNumDisregarded', - 'params' => array( - $memID, - ), - ), - 'columns' => array( - 'subject' => array( - 'header' => array( - 'value' => $txt['subject'], - 'class' => 'lefttext', - 'style' => 'width: 30%;', - ), - 'data' => array( - 'sprintf' => array( - 'format' => '%2$s', - 'params' => array( - 'id_topic' => false, - 'subject' => false, - ), - ), - ), - 'sort' => array( - 'default' => 'm.subject', - 'reverse' => 'm.subject DESC', - ), - ), - 'started_by' => array( - 'header' => array( - 'value' => $txt['started_by'], - 'style' => 'width: 15%;', - ), - 'data' => array( - 'db' => 'started_by', - ), - 'sort' => array( - 'default' => 'mem.real_name', - 'reverse' => 'mem.real_name DESC', - ), - ), - 'started_on' => array( - 'header' => array( - 'value' => $txt['on'], - 'class' => 'lefttext', - 'style' => 'width: 20%;', - ), - 'data' => array( - 'db' => 'started_on', - 'timeformat' => true, - ), - 'sort' => array( - 'default' => 'm.poster_time', - 'reverse' => 'm.poster_time DESC', - ), - ), - 'last_post_by' => array( - 'header' => array( - 'value' => $txt['last_post'], - 'style' => 'width: 15%;', - ), - 'data' => array( - 'db' => 'last_post_by', - ), - 'sort' => array( - 'default' => 'mem.real_name', - 'reverse' => 'mem.real_name DESC', - ), - ), - 'last_post_on' => array( - 'header' => array( - 'value' => $txt['on'], - 'class' => 'lefttext', - 'style' => 'width: 20%;', - ), - 'data' => array( - 'db' => 'last_post_on', - 'timeformat' => true, - ), - 'sort' => array( - 'default' => 'm.poster_time', - 'reverse' => 'm.poster_time DESC', - ), - ), - ), - ); + $context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name']; - // Create the request list. - createList($listOptions); + // Is the load average too high to allow searching just now? + if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) + fatal_lang_error('loadavg_userstats_disabled', false); - $context['sub_template'] = 'show_list'; - $context['default_list'] = 'disregarded_topics'; -} + loadTemplate('ProfileInfo'); -/** - * Get the relevant topics in the disregarded list - * - * @param int $start - * @param int $items_per_page - * @param string $sort - * @param int $memID - */ -function list_getDisregarded($start, $items_per_page, $sort, $memID) -{ - $db = database(); + // General user statistics. + $timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400); + $timeHours = floor(($user_profile[$memID]['total_time_logged_in'] % 86400) / 3600); + $context['time_logged_in'] = ($timeDays > 0 ? $timeDays . $txt['totalTimeLogged2'] : '') . ($timeHours > 0 ? $timeHours . $txt['totalTimeLogged3'] : '') . floor(($user_profile[$memID]['total_time_logged_in'] % 3600) / 60) . $txt['totalTimeLogged4']; + $context['num_posts'] = comma_format($user_profile[$memID]['posts']); - // Get the list of topics we can see - $request = $db->query('', ' - SELECT lt.id_topic - FROM {db_prefix}log_topics as lt - LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic) - LEFT JOIN {db_prefix}boards as b ON (t.id_board = b.id_board) - LEFT JOIN {db_prefix}messages as m ON (t.id_first_msg = m.id_msg)' . (in_array($sort, array('mem.real_name', 'mem.real_name DESC', 'mem.poster_time', 'mem.poster_time DESC')) ? ' - LEFT JOIN {db_prefix}members as mem ON (m.id_member = mem.id_member)' : '') . ' - WHERE lt.id_member = {int:current_member} - AND disregarded = 1 - AND {query_see_board} - ORDER BY {raw:sort} - LIMIT {int:offset}, {int:limit}', - array( - 'current_member' => $memID, - 'sort' => $sort, - 'offset' => $start, - 'limit' => $items_per_page, - ) - ); - $topics = array(); - while ($row = $db->fetch_assoc($request)) - $topics[] = $row['id_topic']; - $db->free_result($request); - - // Any topics found? - $topicsInfo = array(); - if (!empty($topics)) - { - $request = $db->query('', ' - SELECT mf.subject, mf.poster_time as started_on, IFNULL(memf.real_name, mf.poster_name) as started_by, ml.poster_time as last_post_on, IFNULL(meml.real_name, ml.poster_name) as last_post_by, t.id_topic - FROM {db_prefix}topics AS t - INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) - INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg) - LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member) - LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member) - WHERE t.id_topic IN ({array_int:topics})', + // Menu tab + $context[$context['profile_menu_name']]['tab_data'] = array( + 'title' => $txt['statPanel_generalStats'] . ' - ' . $context['member']['name'], + 'icon' => 'stats_info_hd.png' + ); + + // Number of topics started. + $result = $db->query('', ' + SELECT COUNT(*) + FROM {db_prefix}topics + WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' + AND id_board != {int:recycle_board}' : ''), array( - 'topics' => $topics, + 'current_member' => $memID, + 'recycle_board' => $modSettings['recycle_board'], ) ); - while ($row = $db->fetch_assoc($request)) - $topicsInfo[] = $row; - $db->free_result($request); - } - - return $topicsInfo; -} - -/** - * Count the number of topics in the disregarded list - * - * @param int $memID - */ -function list_getNumDisregarded($memID) -{ - $db = database(); - - // Get the total number of attachments they have posted. - $request = $db->query('', ' - SELECT COUNT(*) - FROM {db_prefix}log_topics as lt - LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic) - LEFT JOIN {db_prefix}boards as b ON (t.id_board = b.id_board) - WHERE id_member = {int:current_member} - AND disregarded = 1 - AND {query_see_board}', - array( - 'current_member' => $memID, - ) - ); - list ($disregardedCount) = $db->fetch_row($request); - $db->free_result($request); - - return $disregardedCount; -} + list ($context['num_topics']) = $db->fetch_row($result); + $db->free_result($result); -/** - * Gets the user stats for display - * - */ -function action_statPanel() -{ - global $txt, $scripturl, $context, $user_profile, $user_info, $modSettings; - - $db = database(); - - $memID = currentMemberID(); - - $context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name']; - - // Is the load average too high to allow searching just now? - if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) - fatal_lang_error('loadavg_userstats_disabled', false); - - loadTemplate('ProfileInfo'); - - // General user statistics. - $timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400); - $timeHours = floor(($user_profile[$memID]['total_time_logged_in'] % 86400) / 3600); - $context['time_logged_in'] = ($timeDays > 0 ? $timeDays . $txt['totalTimeLogged2'] : '') . ($timeHours > 0 ? $timeHours . $txt['totalTimeLogged3'] : '') . floor(($user_profile[$memID]['total_time_logged_in'] % 3600) / 60) . $txt['totalTimeLogged4']; - $context['num_posts'] = comma_format($user_profile[$memID]['posts']); - - // Menu tab - $context[$context['profile_menu_name']]['tab_data'] = array( - 'title' => $txt['statPanel_generalStats'] . ' - ' . $context['member']['name'], - 'icon' => 'stats_info_hd.png' - ); - - // Number of topics started. - $result = $db->query('', ' - SELECT COUNT(*) - FROM {db_prefix}topics - WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' - AND id_board != {int:recycle_board}' : ''), - array( - 'current_member' => $memID, - 'recycle_board' => $modSettings['recycle_board'], - ) - ); - list ($context['num_topics']) = $db->fetch_row($result); - $db->free_result($result); - - // Number polls started. - $result = $db->query('', ' - SELECT COUNT(*) - FROM {db_prefix}topics - WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' - AND id_board != {int:recycle_board}' : '') . ' - AND id_poll != {int:no_poll}', - array( - 'current_member' => $memID, - 'recycle_board' => $modSettings['recycle_board'], - 'no_poll' => 0, - ) - ); - list ($context['num_polls']) = $db->fetch_row($result); - $db->free_result($result); - - // Number polls voted in. - $result = $db->query('distinct_poll_votes', ' - SELECT COUNT(DISTINCT id_poll) - FROM {db_prefix}log_polls - WHERE id_member = {int:current_member}', - array( - 'current_member' => $memID, - ) - ); - list ($context['num_votes']) = $db->fetch_row($result); - $db->free_result($result); - - // Format the numbers... - $context['num_topics'] = comma_format($context['num_topics']); - $context['num_polls'] = comma_format($context['num_polls']); - $context['num_votes'] = comma_format($context['num_votes']); - - // Grab the board this member posted in most often. - $result = $db->query('', ' - SELECT - b.id_board, MAX(b.name) AS name, MAX(b.num_posts) AS num_posts, COUNT(*) AS message_count - FROM {db_prefix}messages AS m - INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) - WHERE m.id_member = {int:current_member} - AND b.count_posts = {int:count_enabled} - AND {query_see_board} - GROUP BY b.id_board - ORDER BY message_count DESC - LIMIT 10', - array( - 'current_member' => $memID, - 'count_enabled' => 0, - ) - ); - $context['popular_boards'] = array(); - while ($row = $db->fetch_assoc($result)) - { - $context['popular_boards'][$row['id_board']] = array( - 'id' => $row['id_board'], - 'posts' => $row['message_count'], - 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', - 'link' => '' . $row['name'] . '', - 'posts_percent' => $user_profile[$memID]['posts'] == 0 ? 0 : ($row['message_count'] * 100) / $user_profile[$memID]['posts'], - 'total_posts' => $row['num_posts'], - 'total_posts_member' => $user_profile[$memID]['posts'], + // Number polls started. + $result = $db->query('', ' + SELECT COUNT(*) + FROM {db_prefix}topics + WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' + AND id_board != {int:recycle_board}' : '') . ' + AND id_poll != {int:no_poll}', + array( + 'current_member' => $memID, + 'recycle_board' => $modSettings['recycle_board'], + 'no_poll' => 0, + ) ); - } - $db->free_result($result); - - // Now get the 10 boards this user has most often participated in. - $result = $db->query('profile_board_stats', ' - SELECT - b.id_board, MAX(b.name) AS name, b.num_posts, COUNT(*) AS message_count, - CASE WHEN COUNT(*) > MAX(b.num_posts) THEN 1 ELSE COUNT(*) / MAX(b.num_posts) END * 100 AS percentage - FROM {db_prefix}messages AS m - INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) - WHERE m.id_member = {int:current_member} - AND {query_see_board} - GROUP BY b.id_board, b.num_posts - ORDER BY percentage DESC - LIMIT 10', - array( - 'current_member' => $memID, - ) - ); - $context['board_activity'] = array(); - while ($row = $db->fetch_assoc($result)) - { - $context['board_activity'][$row['id_board']] = array( - 'id' => $row['id_board'], - 'posts' => $row['message_count'], - 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', - 'link' => '' . $row['name'] . '', - 'percent' => comma_format((float) $row['percentage'], 2), - 'posts_percent' => (float) $row['percentage'], - 'total_posts' => $row['num_posts'], + list ($context['num_polls']) = $db->fetch_row($result); + $db->free_result($result); + + // Number polls voted in. + $result = $db->query('distinct_poll_votes', ' + SELECT COUNT(DISTINCT id_poll) + FROM {db_prefix}log_polls + WHERE id_member = {int:current_member}', + array( + 'current_member' => $memID, + ) ); - } - $db->free_result($result); - - // Posting activity by time. - $result = $db->query('user_activity_by_time', ' - SELECT - HOUR(FROM_UNIXTIME(poster_time + {int:time_offset})) AS hour, - COUNT(*) AS post_count - FROM {db_prefix}messages - WHERE id_member = {int:current_member}' . ($modSettings['totalMessages'] > 100000 ? ' - AND id_topic > {int:top_ten_thousand_topics}' : '') . ' - GROUP BY hour', - array( - 'current_member' => $memID, - 'top_ten_thousand_topics' => $modSettings['totalTopics'] - 10000, - 'time_offset' => (($user_info['time_offset'] + $modSettings['time_offset']) * 3600), - ) - ); - $maxPosts = $realPosts = 0; - $context['posts_by_time'] = array(); - while ($row = $db->fetch_assoc($result)) - { - // Cast as an integer to remove the leading 0. - $row['hour'] = (int) $row['hour']; - - $maxPosts = max($row['post_count'], $maxPosts); - $realPosts += $row['post_count']; - - $context['posts_by_time'][$row['hour']] = array( - 'hour' => $row['hour'], - 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $row['hour'] : date('g a', mktime($row['hour'])), - 'posts' => $row['post_count'], - 'posts_percent' => 0, - 'is_last' => $row['hour'] == 23, + list ($context['num_votes']) = $db->fetch_row($result); + $db->free_result($result); + + // Format the numbers... + $context['num_topics'] = comma_format($context['num_topics']); + $context['num_polls'] = comma_format($context['num_polls']); + $context['num_votes'] = comma_format($context['num_votes']); + + // Grab the board this member posted in most often. + $result = $db->query('', ' + SELECT + b.id_board, MAX(b.name) AS name, MAX(b.num_posts) AS num_posts, COUNT(*) AS message_count + FROM {db_prefix}messages AS m + INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) + WHERE m.id_member = {int:current_member} + AND b.count_posts = {int:count_enabled} + AND {query_see_board} + GROUP BY b.id_board + ORDER BY message_count DESC + LIMIT 10', + array( + 'current_member' => $memID, + 'count_enabled' => 0, + ) ); - } - $db->free_result($result); + $context['popular_boards'] = array(); + while ($row = $db->fetch_assoc($result)) + { + $context['popular_boards'][$row['id_board']] = array( + 'id' => $row['id_board'], + 'posts' => $row['message_count'], + 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', + 'link' => '' . $row['name'] . '', + 'posts_percent' => $user_profile[$memID]['posts'] == 0 ? 0 : ($row['message_count'] * 100) / $user_profile[$memID]['posts'], + 'total_posts' => $row['num_posts'], + 'total_posts_member' => $user_profile[$memID]['posts'], + ); + } + $db->free_result($result); + + // Now get the 10 boards this user has most often participated in. + $result = $db->query('profile_board_stats', ' + SELECT + b.id_board, MAX(b.name) AS name, b.num_posts, COUNT(*) AS message_count, + CASE WHEN COUNT(*) > MAX(b.num_posts) THEN 1 ELSE COUNT(*) / MAX(b.num_posts) END * 100 AS percentage + FROM {db_prefix}messages AS m + INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) + WHERE m.id_member = {int:current_member} + AND {query_see_board} + GROUP BY b.id_board, b.num_posts + ORDER BY percentage DESC + LIMIT 10', + array( + 'current_member' => $memID, + ) + ); + $context['board_activity'] = array(); + while ($row = $db->fetch_assoc($result)) + { + $context['board_activity'][$row['id_board']] = array( + 'id' => $row['id_board'], + 'posts' => $row['message_count'], + 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', + 'link' => '' . $row['name'] . '', + 'percent' => comma_format((float) $row['percentage'], 2), + 'posts_percent' => (float) $row['percentage'], + 'total_posts' => $row['num_posts'], + ); + } + $db->free_result($result); + + // Posting activity by time. + $result = $db->query('user_activity_by_time', ' + SELECT + HOUR(FROM_UNIXTIME(poster_time + {int:time_offset})) AS hour, + COUNT(*) AS post_count + FROM {db_prefix}messages + WHERE id_member = {int:current_member}' . ($modSettings['totalMessages'] > 100000 ? ' + AND id_topic > {int:top_ten_thousand_topics}' : '') . ' + GROUP BY hour', + array( + 'current_member' => $memID, + 'top_ten_thousand_topics' => $modSettings['totalTopics'] - 10000, + 'time_offset' => (($user_info['time_offset'] + $modSettings['time_offset']) * 3600), + ) + ); + $maxPosts = $realPosts = 0; + $context['posts_by_time'] = array(); + while ($row = $db->fetch_assoc($result)) + { + // Cast as an integer to remove the leading 0. + $row['hour'] = (int) $row['hour']; + + $maxPosts = max($row['post_count'], $maxPosts); + $realPosts += $row['post_count']; + + $context['posts_by_time'][$row['hour']] = array( + 'hour' => $row['hour'], + 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $row['hour'] : date('g a', mktime($row['hour'])), + 'posts' => $row['post_count'], + 'posts_percent' => 0, + 'is_last' => $row['hour'] == 23, + ); + } + $db->free_result($result); - if ($maxPosts > 0) - { - for ($hour = 0; $hour < 24; $hour++) + if ($maxPosts > 0) { - if (!isset($context['posts_by_time'][$hour])) - $context['posts_by_time'][$hour] = array( - 'hour' => $hour, - 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)), - 'posts' => 0, - 'posts_percent' => 0, - 'relative_percent' => 0, - 'is_last' => $hour == 23, - ); - else + for ($hour = 0; $hour < 24; $hour++) { - $context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts); - $context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts); + if (!isset($context['posts_by_time'][$hour])) + $context['posts_by_time'][$hour] = array( + 'hour' => $hour, + 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)), + 'posts' => 0, + 'posts_percent' => 0, + 'relative_percent' => 0, + 'is_last' => $hour == 23, + ); + else + { + $context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts); + $context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts); + } } } - } - - // Put it in the right order. - ksort($context['posts_by_time']); - // Custom stats (just add a template_layer to add it to the template!) - call_integration_hook('integrate_profile_stats', array($memID)); -} + // Put it in the right order. + ksort($context['posts_by_time']); -/** - * Show permissions for a user. - */ -function action_showPermissions() -{ - global $txt, $board, $user_profile, $context; - - $db = database(); - - // Verify if the user has sufficient permissions. - isAllowedTo('manage_permissions'); - - loadLanguage('ManagePermissions'); - loadLanguage('Admin'); - loadTemplate('ManageMembers'); - loadTemplate('ProfileInfo'); - - // Load all the permission profiles. - require_once(SUBSDIR . '/ManagePermissions.subs.php'); - loadPermissionProfiles(); - - $memID = currentMemberID(); - - $context['member']['id'] = $memID; - $context['member']['name'] = $user_profile[$memID]['real_name']; - - $context['page_title'] = $txt['showPermissions']; - $board = empty($board) ? 0 : (int) $board; - $context['board'] = $board; - - // Determine which groups this user is in. - if (empty($user_profile[$memID]['additional_groups'])) - $curGroups = array(); - else - $curGroups = explode(',', $user_profile[$memID]['additional_groups']); - $curGroups[] = $user_profile[$memID]['id_group']; - $curGroups[] = $user_profile[$memID]['id_post_group']; - - // Load a list of boards for the jump box - except the defaults. - $request = $db->query('order_by_board_order', ' - SELECT b.id_board, b.name, b.id_profile, b.member_groups, IFNULL(mods.id_member, 0) AS is_mod - FROM {db_prefix}boards AS b - LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member}) - WHERE {query_see_board}', - array( - 'current_member' => $memID, - ) - ); - $context['boards'] = array(); - $context['no_access_boards'] = array(); - while ($row = $db->fetch_assoc($request)) - { - if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) - $context['no_access_boards'][] = array( - 'id' => $row['id_board'], - 'name' => $row['name'], - 'is_last' => false, - ); - elseif ($row['id_profile'] != 1 || $row['is_mod']) - $context['boards'][$row['id_board']] = array( - 'id' => $row['id_board'], - 'name' => $row['name'], - 'selected' => $board == $row['id_board'], - 'profile' => $row['id_profile'], - 'profile_name' => $context['profiles'][$row['id_profile']]['name'], - ); + // Custom stats (just add a template_layer to add it to the template!) + call_integration_hook('integrate_profile_stats', array($memID)); } - $db->free_result($request); - - if (!empty($context['no_access_boards'])) - $context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true; - - $context['member']['permissions'] = array( - 'general' => array(), - 'board' => array() - ); - - // If you're an admin we know you can do everything, we might as well leave. - $context['member']['has_all_permissions'] = in_array(1, $curGroups); - if ($context['member']['has_all_permissions']) - return; - - $denied = array(); - - // Get all general permissions. - $result = $db->query('', ' - SELECT p.permission, p.add_deny, mg.group_name, p.id_group - FROM {db_prefix}permissions AS p - LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = p.id_group) - WHERE p.id_group IN ({array_int:group_list}) - ORDER BY p.add_deny DESC, p.permission, mg.min_posts, CASE WHEN mg.id_group < {int:newbie_group} THEN mg.id_group ELSE 4 END, mg.group_name', - array( - 'group_list' => $curGroups, - 'newbie_group' => 4, - ) - ); - while ($row = $db->fetch_assoc($result)) + + /** + * Show permissions for a user. + */ + public function action_showPermissions() { - // We don't know about this permission, it doesn't exist :P. - if (!isset($txt['permissionname_' . $row['permission']])) - continue; + global $txt, $board, $user_profile, $context; + + $db = database(); + + // Verify if the user has sufficient permissions. + isAllowedTo('manage_permissions'); + + loadLanguage('ManagePermissions'); + loadLanguage('Admin'); + loadTemplate('ManageMembers'); + loadTemplate('ProfileInfo'); - if (empty($row['add_deny'])) - $denied[] = $row['permission']; + // Load all the permission profiles. + require_once(SUBSDIR . '/ManagePermissions.subs.php'); + loadPermissionProfiles(); - // Permissions that end with _own or _any consist of two parts. - if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) - $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; + $memID = currentMemberID(); + + $context['member']['id'] = $memID; + $context['member']['name'] = $user_profile[$memID]['real_name']; + + $context['page_title'] = $txt['showPermissions']; + $board = empty($board) ? 0 : (int) $board; + $context['board'] = $board; + + // Determine which groups this user is in. + if (empty($user_profile[$memID]['additional_groups'])) + $curGroups = array(); else - $name = $txt['permissionname_' . $row['permission']]; + $curGroups = explode(',', $user_profile[$memID]['additional_groups']); + $curGroups[] = $user_profile[$memID]['id_group']; + $curGroups[] = $user_profile[$memID]['id_post_group']; + + // Load a list of boards for the jump box - except the defaults. + $request = $db->query('order_by_board_order', ' + SELECT b.id_board, b.name, b.id_profile, b.member_groups, IFNULL(mods.id_member, 0) AS is_mod + FROM {db_prefix}boards AS b + LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member}) + WHERE {query_see_board}', + array( + 'current_member' => $memID, + ) + ); + $context['boards'] = array(); + $context['no_access_boards'] = array(); + while ($row = $db->fetch_assoc($request)) + { + if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) + $context['no_access_boards'][] = array( + 'id' => $row['id_board'], + 'name' => $row['name'], + 'is_last' => false, + ); + elseif ($row['id_profile'] != 1 || $row['is_mod']) + $context['boards'][$row['id_board']] = array( + 'id' => $row['id_board'], + 'name' => $row['name'], + 'selected' => $board == $row['id_board'], + 'profile' => $row['id_profile'], + 'profile_name' => $context['profiles'][$row['id_profile']]['name'], + ); + } + $db->free_result($request); + + if (!empty($context['no_access_boards'])) + $context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true; + + $context['member']['permissions'] = array( + 'general' => array(), + 'board' => array() + ); - // Add this permission if it doesn't exist yet. - if (!isset($context['member']['permissions']['general'][$row['permission']])) + // If you're an admin we know you can do everything, we might as well leave. + $context['member']['has_all_permissions'] = in_array(1, $curGroups); + if ($context['member']['has_all_permissions']) + return; + + $denied = array(); + + // Get all general permissions. + $result = $db->query('', ' + SELECT p.permission, p.add_deny, mg.group_name, p.id_group + FROM {db_prefix}permissions AS p + LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = p.id_group) + WHERE p.id_group IN ({array_int:group_list}) + ORDER BY p.add_deny DESC, p.permission, mg.min_posts, CASE WHEN mg.id_group < {int:newbie_group} THEN mg.id_group ELSE 4 END, mg.group_name', + array( + 'group_list' => $curGroups, + 'newbie_group' => 4, + ) + ); + while ($row = $db->fetch_assoc($result)) { - $context['member']['permissions']['general'][$row['permission']] = array( - 'id' => $row['permission'], - 'groups' => array( - 'allowed' => array(), - 'denied' => array() - ), - 'name' => $name, - 'is_denied' => false, - 'is_global' => true, - ); + // We don't know about this permission, it doesn't exist :P. + if (!isset($txt['permissionname_' . $row['permission']])) + continue; + + if (empty($row['add_deny'])) + $denied[] = $row['permission']; + + // Permissions that end with _own or _any consist of two parts. + if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) + $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; + else + $name = $txt['permissionname_' . $row['permission']]; + + // Add this permission if it doesn't exist yet. + if (!isset($context['member']['permissions']['general'][$row['permission']])) + { + $context['member']['permissions']['general'][$row['permission']] = array( + 'id' => $row['permission'], + 'groups' => array( + 'allowed' => array(), + 'denied' => array() + ), + 'name' => $name, + 'is_denied' => false, + 'is_global' => true, + ); + } + + // Add the membergroup to either the denied or the allowed groups. + $context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name']; + + // Once denied is always denied. + $context['member']['permissions']['general'][$row['permission']]['is_denied'] |= empty($row['add_deny']); } + $db->free_result($result); - // Add the membergroup to either the denied or the allowed groups. - $context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name']; + $request = $db->query('', ' + SELECT + bp.add_deny, bp.permission, bp.id_group, mg.group_name' . (empty($board) ? '' : ', + b.id_profile, CASE WHEN mods.id_member IS NULL THEN 0 ELSE 1 END AS is_moderator') . ' + FROM {db_prefix}board_permissions AS bp' . (empty($board) ? '' : ' + INNER JOIN {db_prefix}boards AS b ON (b.id_board = {int:current_board}) + LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})') . ' + LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = bp.id_group) + WHERE bp.id_profile = {raw:current_profile} + AND bp.id_group IN ({array_int:group_list}' . (empty($board) ? ')' : ', {int:moderator_group}) + AND (mods.id_member IS NOT NULL OR bp.id_group != {int:moderator_group})'), + array( + 'current_board' => $board, + 'group_list' => $curGroups, + 'current_member' => $memID, + 'current_profile' => empty($board) ? '1' : 'b.id_profile', + 'moderator_group' => 3, + ) + ); - // Once denied is always denied. - $context['member']['permissions']['general'][$row['permission']]['is_denied'] |= empty($row['add_deny']); - } - $db->free_result($result); - - $request = $db->query('', ' - SELECT - bp.add_deny, bp.permission, bp.id_group, mg.group_name' . (empty($board) ? '' : ', - b.id_profile, CASE WHEN mods.id_member IS NULL THEN 0 ELSE 1 END AS is_moderator') . ' - FROM {db_prefix}board_permissions AS bp' . (empty($board) ? '' : ' - INNER JOIN {db_prefix}boards AS b ON (b.id_board = {int:current_board}) - LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})') . ' - LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = bp.id_group) - WHERE bp.id_profile = {raw:current_profile} - AND bp.id_group IN ({array_int:group_list}' . (empty($board) ? ')' : ', {int:moderator_group}) - AND (mods.id_member IS NOT NULL OR bp.id_group != {int:moderator_group})'), - array( - 'current_board' => $board, - 'group_list' => $curGroups, - 'current_member' => $memID, - 'current_profile' => empty($board) ? '1' : 'b.id_profile', - 'moderator_group' => 3, - ) - ); - - while ($row = $db->fetch_assoc($request)) - { - // We don't know about this permission, it doesn't exist :P. - if (!isset($txt['permissionname_' . $row['permission']])) - continue; + while ($row = $db->fetch_assoc($request)) + { + // We don't know about this permission, it doesn't exist :P. + if (!isset($txt['permissionname_' . $row['permission']])) + continue; - // The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'. - if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) - $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; - else - $name = $txt['permissionname_' . $row['permission']]; - - // Create the structure for this permission. - if (!isset($context['member']['permissions']['board'][$row['permission']])) - $context['member']['permissions']['board'][$row['permission']] = array( - 'id' => $row['permission'], - 'groups' => array( - 'allowed' => array(), - 'denied' => array() - ), - 'name' => $name, - 'is_denied' => false, - 'is_global' => empty($board), - ); + // The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'. + if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) + $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; + else + $name = $txt['permissionname_' . $row['permission']]; + + // Create the structure for this permission. + if (!isset($context['member']['permissions']['board'][$row['permission']])) + $context['member']['permissions']['board'][$row['permission']] = array( + 'id' => $row['permission'], + 'groups' => array( + 'allowed' => array(), + 'denied' => array() + ), + 'name' => $name, + 'is_denied' => false, + 'is_global' => empty($board), + ); - $context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name']; - $context['member']['permissions']['board'][$row['permission']]['is_denied'] |= empty($row['add_deny']); + $context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name']; + $context['member']['permissions']['board'][$row['permission']]['is_denied'] |= empty($row['add_deny']); + } + $db->free_result($request); } - $db->free_result($request); -} -/** - * View a members warnings? - */ -function action_viewWarning() -{ - global $modSettings, $context, $txt, $scripturl; - - // Firstly, can we actually even be here? - if (!allowedTo('issue_warning') && (empty($modSettings['warning_show']) || ($modSettings['warning_show'] == 1 && !$context['user']['is_owner']))) - fatal_lang_error('no_access', false); - - loadTemplate('ProfileInfo'); - - // We need this because of template_load_warning_variables - loadTemplate('Profile'); - - // Make sure things which are disabled stay disabled. - $modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110; - $modSettings['warning_moderate'] = !empty($modSettings['warning_moderate']) && !empty($modSettings['postmod_active']) ? $modSettings['warning_moderate'] : 110; - $modSettings['warning_mute'] = !empty($modSettings['warning_mute']) ? $modSettings['warning_mute'] : 110; - - // Let's use a generic list to get all the current warnings - // and use the issue warnings grab-a-granny thing. - require_once(SUBSDIR . '/List.subs.php'); - - $memID = currentMemberID(); - - $listOptions = array( - 'id' => 'view_warnings', - 'title' => $txt['profile_viewwarning_previous_warnings'], - 'items_per_page' => $modSettings['defaultMaxMessages'], - 'no_items_label' => $txt['profile_viewwarning_no_warnings'], - 'base_href' => $scripturl . '?action=profile;area=viewwarning;sa=user;u=' . $memID, - 'default_sort_col' => 'log_time', - 'get_items' => array( - 'function' => 'list_getUserWarnings', - 'params' => array( - $memID, - ), - ), - 'get_count' => array( - 'function' => 'list_getUserWarningCount', - 'params' => array( - $memID, - ), - ), - 'columns' => array( - 'log_time' => array( - 'header' => array( - 'value' => $txt['profile_warning_previous_time'], - ), - 'data' => array( - 'db' => 'time', - ), - 'sort' => array( - 'default' => 'lc.log_time DESC', - 'reverse' => 'lc.log_time', + /** + * View a members warnings. + */ + public function action_viewWarning() + { + global $modSettings, $context, $txt, $scripturl; + + // Firstly, can we actually even be here? + if (!allowedTo('issue_warning') && (empty($modSettings['warning_show']) || ($modSettings['warning_show'] == 1 && !$context['user']['is_owner']))) + fatal_lang_error('no_access', false); + + loadTemplate('ProfileInfo'); + + // We need this because of template_load_warning_variables + loadTemplate('Profile'); + + // Make sure things which are disabled stay disabled. + $modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110; + $modSettings['warning_moderate'] = !empty($modSettings['warning_moderate']) && !empty($modSettings['postmod_active']) ? $modSettings['warning_moderate'] : 110; + $modSettings['warning_mute'] = !empty($modSettings['warning_mute']) ? $modSettings['warning_mute'] : 110; + + // Let's use a generic list to get all the current warnings + // and use the issue warnings grab-a-granny thing. + require_once(SUBSDIR . '/List.subs.php'); + + $memID = currentMemberID(); + + $listOptions = array( + 'id' => 'view_warnings', + 'title' => $txt['profile_viewwarning_previous_warnings'], + 'items_per_page' => $modSettings['defaultMaxMessages'], + 'no_items_label' => $txt['profile_viewwarning_no_warnings'], + 'base_href' => $scripturl . '?action=profile;area=viewwarning;sa=user;u=' . $memID, + 'default_sort_col' => 'log_time', + 'get_items' => array( + 'function' => 'list_getUserWarnings', + 'params' => array( + $memID, ), ), - 'reason' => array( - 'header' => array( - 'value' => $txt['profile_warning_previous_reason'], - 'style' => 'width: 50%;', - ), - 'data' => array( - 'db' => 'reason', + 'get_count' => array( + 'function' => 'list_getUserWarningCount', + 'params' => array( + $memID, ), ), - 'level' => array( - 'header' => array( - 'value' => $txt['profile_warning_previous_level'], + 'columns' => array( + 'log_time' => array( + 'header' => array( + 'value' => $txt['profile_warning_previous_time'], + ), + 'data' => array( + 'db' => 'time', + ), + 'sort' => array( + 'default' => 'lc.log_time DESC', + 'reverse' => 'lc.log_time', + ), ), - 'data' => array( - 'db' => 'counter', + 'reason' => array( + 'header' => array( + 'value' => $txt['profile_warning_previous_reason'], + 'style' => 'width: 50%;', + ), + 'data' => array( + 'db' => 'reason', + ), ), - 'sort' => array( - 'default' => 'lc.counter DESC', - 'reverse' => 'lc.counter', + 'level' => array( + 'header' => array( + 'value' => $txt['profile_warning_previous_level'], + ), + 'data' => array( + 'db' => 'counter', + ), + 'sort' => array( + 'default' => 'lc.counter DESC', + 'reverse' => 'lc.counter', + ), ), ), - ), - 'additional_rows' => array( - array( - 'position' => 'after_title', - 'value' => $txt['profile_viewwarning_desc'], - 'class' => 'smalltext', - 'style' => 'padding: 2ex;', + 'additional_rows' => array( + array( + 'position' => 'after_title', + 'value' => $txt['profile_viewwarning_desc'], + 'class' => 'smalltext', + 'style' => 'padding: 2ex;', + ), ), - ), - ); - - // Create the list for viewing. - createList($listOptions); - - // Create some common text bits for the template. - $context['level_effects'] = array( - 0 => '', - $modSettings['warning_watch'] => $txt['profile_warning_effect_own_watched'], - $modSettings['warning_moderate'] => $txt['profile_warning_effect_own_moderated'], - $modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'], - ); - $context['current_level'] = 0; - $context['sub_template'] = 'viewWarning'; - foreach ($context['level_effects'] as $limit => $dummy) + ); + + // Create the list for viewing. + createList($listOptions); + + // Create some common text bits for the template. + $context['level_effects'] = array( + 0 => '', + $modSettings['warning_watch'] => $txt['profile_warning_effect_own_watched'], + $modSettings['warning_moderate'] => $txt['profile_warning_effect_own_moderated'], + $modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'], + ); + $context['current_level'] = 0; + $context['sub_template'] = 'viewWarning'; + foreach ($context['level_effects'] as $limit => $dummy) + { + if ($context['member']['warning'] >= $limit) + $context['current_level'] = $limit; + } + } + + /** + * Get a list of attachments for this user + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param array $boardsAllowed + * @param ing $memID + * @return array + */ + function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID) { - if ($context['member']['warning'] >= $limit) - $context['current_level'] = $limit; + global $board, $modSettings, $context, $settings, $scripturl, $txt; + + $db = database(); + + // Retrieve some attachments. + $request = $db->query('', ' + SELECT a.id_attach, a.id_msg, a.filename, a.downloads, a.approved, a.fileext, a.width, a.height, ' . + (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ' IFNULL(thumb.id_attach, 0) AS id_thumb, thumb.width AS thumb_width, thumb.height AS thumb_height, ') . ' + m.id_msg, m.id_topic, m.id_board, m.poster_time, m.subject, b.name + FROM {db_prefix}attachments AS a' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ' + LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = a.id_thumb)') . ' + INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) + INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board}) + WHERE a.attachment_type = {int:attachment_type} + AND a.id_msg != {int:no_message} + AND m.id_member = {int:current_member}' . (!empty($board) ? ' + AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? ' + AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' + AND m.approved = {int:is_approved}') . ' + ORDER BY {raw:sort} + LIMIT {int:offset}, {int:limit}', + array( + 'boards_list' => $boardsAllowed, + 'attachment_type' => 0, + 'no_message' => 0, + 'current_member' => $memID, + 'is_approved' => 1, + 'board' => $board, + 'sort' => $sort, + 'offset' => $start, + 'limit' => $items_per_page, + ) + ); + $attachments = array(); + while ($row = $db->fetch_assoc($request)) + { + if (!$row['approved']) + $row['filename'] = str_replace(array('{attachment_link}', '{txt_awaiting}'), array('' . $row['filename'] . '', $txt['awaiting_approval']), $settings['attachments_awaiting_approval']); + else + $row['filename'] = '' . $row['filename'] . ''; + + $attachments[] = array( + 'id' => $row['id_attach'], + 'filename' => $row['filename'], + 'fileext' => $row['fileext'], + 'width' => $row['width'], + 'height' => $row['height'], + 'downloads' => $row['downloads'], + 'is_image' => !empty($row['width']) && !empty($row['height']) && !empty($modSettings['attachmentShowImages']), + 'id_thumb' => $row['id_thumb'], + 'subject' => '' . censorText($row['subject']) . '', + 'posted' => $row['poster_time'], + 'msg' => $row['id_msg'], + 'topic' => $row['id_topic'], + 'board' => $row['id_board'], + 'board_name' => $row['name'], + 'approved' => $row['approved'], + ); + } + + $db->free_result($request); + + return $attachments; + } + + /** + * Gets the total number of attachments for the user + * + * @param type $boardsAllowed + * @param type $memID + * @return type + */ + function list_getNumAttachments($boardsAllowed, $memID) + { + global $board, $modSettings, $context; + + $db = database(); + + // Get the total number of attachments they have posted. + $request = $db->query('', ' + SELECT COUNT(*) + FROM {db_prefix}attachments AS a + INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) + INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board}) + WHERE a.attachment_type = {int:attachment_type} + AND a.id_msg != {int:no_message} + AND m.id_member = {int:current_member}' . (!empty($board) ? ' + AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? ' + AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' + AND m.approved = {int:is_approved}'), + array( + 'boards_list' => $boardsAllowed, + 'attachment_type' => 0, + 'no_message' => 0, + 'current_member' => $memID, + 'is_approved' => 1, + 'board' => $board, + ) + ); + list ($attachCount) = $db->fetch_row($request); + $db->free_result($request); + + return $attachCount; + } + + /** + * Get the relevant topics in the disregarded list + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param int $memID + */ + function list_getDisregarded($start, $items_per_page, $sort, $memID) + { + $db = database(); + + // Get the list of topics we can see + $request = $db->query('', ' + SELECT lt.id_topic + FROM {db_prefix}log_topics as lt + LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic) + LEFT JOIN {db_prefix}boards as b ON (t.id_board = b.id_board) + LEFT JOIN {db_prefix}messages as m ON (t.id_first_msg = m.id_msg)' . (in_array($sort, array('mem.real_name', 'mem.real_name DESC', 'mem.poster_time', 'mem.poster_time DESC')) ? ' + LEFT JOIN {db_prefix}members as mem ON (m.id_member = mem.id_member)' : '') . ' + WHERE lt.id_member = {int:current_member} + AND disregarded = 1 + AND {query_see_board} + ORDER BY {raw:sort} + LIMIT {int:offset}, {int:limit}', + array( + 'current_member' => $memID, + 'sort' => $sort, + 'offset' => $start, + 'limit' => $items_per_page, + ) + ); + $topics = array(); + while ($row = $db->fetch_assoc($request)) + $topics[] = $row['id_topic']; + $db->free_result($request); + + // Any topics found? + $topicsInfo = array(); + if (!empty($topics)) + { + $request = $db->query('', ' + SELECT mf.subject, mf.poster_time as started_on, IFNULL(memf.real_name, mf.poster_name) as started_by, ml.poster_time as last_post_on, IFNULL(meml.real_name, ml.poster_name) as last_post_by, t.id_topic + FROM {db_prefix}topics AS t + INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) + INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg) + LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member) + LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member) + WHERE t.id_topic IN ({array_int:topics})', + array( + 'topics' => $topics, + ) + ); + while ($row = $db->fetch_assoc($request)) + $topicsInfo[] = $row; + $db->free_result($request); + } + + return $topicsInfo; + } + + /** + * Count the number of topics in the disregarded list + * + * @param int $memID + */ + function list_getNumDisregarded($memID) + { + $db = database(); + + // Get the total number of attachments they have posted. + $request = $db->query('', ' + SELECT COUNT(*) + FROM {db_prefix}log_topics as lt + LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic) + LEFT JOIN {db_prefix}boards as b ON (t.id_board = b.id_board) + WHERE id_member = {int:current_member} + AND disregarded = 1 + AND {query_see_board}', + array( + 'current_member' => $memID, + ) + ); + list ($disregardedCount) = $db->fetch_row($request); + $db->free_result($request); + + return $disregardedCount; } } \ No newline at end of file From 0fd1ffab4a82a95464c284da331a5a6a5dc4c7b4 Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 06:34:41 +0300 Subject: [PATCH 13/34] Extend ProfileInfo controller from Action_Controller and add missing method. This will require quite a revamp. Signed-off-by: Norv --- sources/controllers/ProfileInfo.controller.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sources/controllers/ProfileInfo.controller.php b/sources/controllers/ProfileInfo.controller.php index 7762004d8c..abebc0d29a 100644 --- a/sources/controllers/ProfileInfo.controller.php +++ b/sources/controllers/ProfileInfo.controller.php @@ -18,8 +18,17 @@ if (!defined('ELKARTE')) die('No access...'); -class ProfileInfo_Controller +class ProfileInfo_Controller extends Action_Controller { + /** + * Intended as entry point which delegates to methods in this class... + */ + public function action_index() + { + // what do we do, do you even know what you do? + // $this->action_showPosts(); + } + /** * View a summary. */ From ca0746030faa2ae9e21927fcdf6427a96aed00f1 Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 06:39:54 +0300 Subject: [PATCH 14/34] action_activateaccount() was supposed to be in ProfileAccount.. (it was even called from there, must've been buggy.) Signed-off-by: Norv --- sources/controllers/Profile.controller.php | 7 ++- .../controllers/ProfileAccount.controller.php | 43 +++++++++++++++++++ .../ProfileSubscriptions.controller.php | 43 ------------------- 3 files changed, 49 insertions(+), 44 deletions(-) diff --git a/sources/controllers/Profile.controller.php b/sources/controllers/Profile.controller.php index 7a3f5bd67f..632821b3d9 100644 --- a/sources/controllers/Profile.controller.php +++ b/sources/controllers/Profile.controller.php @@ -339,6 +339,7 @@ public function action_index() ), 'activateaccount' => array( 'file' => '/controllers/ProfileAccount.controller.php', + 'controller' => 'ProfileAccount_Controller', 'function' => 'action_activateaccount', 'sc' => 'get', 'token' => 'profile-aa%u', @@ -560,7 +561,11 @@ public function action_index() if ($current_area == 'activateaccount') { if (empty($post_errors)) - action_activateaccount(); + { + require_once(CONTROLLERDIR . '/ProfileAccount.controller.php'); + $controller = new ProfileAccount_Controller(); + $controller->action_activateaccount(); + } } elseif ($current_area == 'deleteaccount') { diff --git a/sources/controllers/ProfileAccount.controller.php b/sources/controllers/ProfileAccount.controller.php index 2ca3050145..47ca5de487 100644 --- a/sources/controllers/ProfileAccount.controller.php +++ b/sources/controllers/ProfileAccount.controller.php @@ -540,4 +540,47 @@ function action_deleteaccount2() redirectexit(); } } + + /** + * Activate an account. + * This function is called from the profile account actions area. + */ + function action_activateaccount() + { + global $context, $user_profile, $modSettings; + + isAllowedTo('moderate_forum'); + + $memID = currentMemberID(); + + if (isset($_REQUEST['save']) && isset($user_profile[$memID]['is_activated']) && $user_profile[$memID]['is_activated'] != 1) + { + // If we are approving the deletion of an account, we do something special ;) + if ($user_profile[$memID]['is_activated'] == 4) + { + require_once(SUBSDIR . '/Members.subs.php'); + deleteMembers($context['id_member']); + redirectexit(); + } + + // Let the integrations know of the activation. + call_integration_hook('integrate_activate', array($user_profile[$memID]['member_name'])); + + // Actually update this member now, as it guarantees the unapproved count can't get corrupted. + updateMemberData($context['id_member'], array('is_activated' => $user_profile[$memID]['is_activated'] >= 10 ? 11 : 1, 'validation_code' => '')); + + // Log what we did? + logAction('approve_member', array('member' => $memID), 'admin'); + + // If we are doing approval, update the stats for the member just in case. + if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 13, 14))) + updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0))); + + // Make sure we update the stats too. + updateStats('member', false); + } + + // Leave it be... + redirectexit('action=profile;u=' . $memID . ';area=summary'); + } } diff --git a/sources/controllers/ProfileSubscriptions.controller.php b/sources/controllers/ProfileSubscriptions.controller.php index fa1b80b1c5..ec9a7233eb 100644 --- a/sources/controllers/ProfileSubscriptions.controller.php +++ b/sources/controllers/ProfileSubscriptions.controller.php @@ -284,47 +284,4 @@ function action_subscriptions() } else $context['sub_template'] = 'user_subscription'; -} - -/** - * Activate an account. - * This function is called from the profile account actions area. - */ -function action_activateaccount() -{ - global $context, $user_profile, $modSettings; - - isAllowedTo('moderate_forum'); - - $memID = currentMemberID(); - - if (isset($_REQUEST['save']) && isset($user_profile[$memID]['is_activated']) && $user_profile[$memID]['is_activated'] != 1) - { - // If we are approving the deletion of an account, we do something special ;) - if ($user_profile[$memID]['is_activated'] == 4) - { - require_once(SUBSDIR . '/Members.subs.php'); - deleteMembers($context['id_member']); - redirectexit(); - } - - // Let the integrations know of the activation. - call_integration_hook('integrate_activate', array($user_profile[$memID]['member_name'])); - - // Actually update this member now, as it guarantees the unapproved count can't get corrupted. - updateMemberData($context['id_member'], array('is_activated' => $user_profile[$memID]['is_activated'] >= 10 ? 11 : 1, 'validation_code' => '')); - - // Log what we did? - logAction('approve_member', array('member' => $memID), 'admin'); - - // If we are doing approval, update the stats for the member just in case. - if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 13, 14))) - updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0))); - - // Make sure we update the stats too. - updateStats('member', false); - } - - // Leave it be... - redirectexit('action=profile;u=' . $memID . ';area=summary'); } \ No newline at end of file From c7aee79118bdb0a84a9c95aef73ac00b9f796b8f Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 06:48:42 +0300 Subject: [PATCH 15/34] ProfileSubscriptions controller, make into a class, extend Action_Controller. Signed-off-by: Norv --- sources/controllers/Profile.controller.php | 1 + .../ProfileSubscriptions.controller.php | 444 +++++++++--------- 2 files changed, 229 insertions(+), 216 deletions(-) diff --git a/sources/controllers/Profile.controller.php b/sources/controllers/Profile.controller.php index 632821b3d9..ef7df01e52 100644 --- a/sources/controllers/Profile.controller.php +++ b/sources/controllers/Profile.controller.php @@ -317,6 +317,7 @@ public function action_index() 'subscriptions' => array( 'label' => $txt['subscriptions'], 'file' => '/controllers/ProfileSubscriptions.controller.php', + 'controller' => 'ProfileSubscriptions_Controller', 'function' => 'action_subscriptions', 'enabled' => !empty($modSettings['paid_enabled']), 'permission' => array( diff --git a/sources/controllers/ProfileSubscriptions.controller.php b/sources/controllers/ProfileSubscriptions.controller.php index ec9a7233eb..40b195168f 100644 --- a/sources/controllers/ProfileSubscriptions.controller.php +++ b/sources/controllers/ProfileSubscriptions.controller.php @@ -13,275 +13,287 @@ * * @version 1.0 Alpha * - * This file handles subscriptions on a user's profile. - * */ if (!defined('ELKARTE')) die('No access...'); /** - * Function for doing all the paid subscription stuff - kinda. - * + * This class handles subscriptions on a user's profile. */ -function action_subscriptions() +class ProfileSubscriptions_Controller extends Action_Controller { - global $context, $txt, $modSettings, $scripturl; + /** + * @see Action_Controller::action_index() + */ + public function action_index() + { + // $this->action_subscriptions(); + } - $db = database(); + /** + * Method for doing all the paid subscription stuff - kinda. + * + */ + public function action_subscriptions() + { + global $context, $txt, $modSettings, $scripturl; - // Load the paid template anyway. - loadTemplate('ManagePaid'); - loadLanguage('ManagePaid'); + $db = database(); - $memID = currentMemberID(); + // Load the paid template anyway. + loadTemplate('ManagePaid'); + loadLanguage('ManagePaid'); - // Load all of the subscriptions. - require_once(SUBSDIR . '/ManagePaid.subs.php'); - loadSubscriptions(); - $context['member']['id'] = $memID; + $memID = currentMemberID(); - // Remove any invalid ones. - foreach ($context['subscriptions'] as $id => $sub) - { - // Work out the costs. - $costs = @unserialize($sub['real_cost']); + // Load all of the subscriptions. + require_once(SUBSDIR . '/ManagePaid.subs.php'); + loadSubscriptions(); + $context['member']['id'] = $memID; - $cost_array = array(); - if ($sub['real_length'] == 'F') + // Remove any invalid ones. + foreach ($context['subscriptions'] as $id => $sub) { - foreach ($costs as $duration => $cost) + // Work out the costs. + $costs = @unserialize($sub['real_cost']); + + $cost_array = array(); + if ($sub['real_length'] == 'F') + { + foreach ($costs as $duration => $cost) + { + if ($cost != 0) + $cost_array[$duration] = $cost; + } + } + else + $cost_array['fixed'] = $costs['fixed']; + + if (empty($cost_array)) + unset($context['subscriptions'][$id]); + else { - if ($cost != 0) - $cost_array[$duration] = $cost; + $context['subscriptions'][$id]['member'] = 0; + $context['subscriptions'][$id]['subscribed'] = false; + $context['subscriptions'][$id]['costs'] = $cost_array; } } - else - $cost_array['fixed'] = $costs['fixed']; - if (empty($cost_array)) - unset($context['subscriptions'][$id]); - else + // Work out what gateways are enabled. + $gateways = loadPaymentGateways(); + foreach ($gateways as $id => $gateway) { - $context['subscriptions'][$id]['member'] = 0; - $context['subscriptions'][$id]['subscribed'] = false; - $context['subscriptions'][$id]['costs'] = $cost_array; - } - } + $gateways[$id] = new $gateway['display_class'](); - // Work out what gateways are enabled. - $gateways = loadPaymentGateways(); - foreach ($gateways as $id => $gateway) - { - $gateways[$id] = new $gateway['display_class'](); + if (!$gateways[$id]->gatewayEnabled()) + unset($gateways[$id]); + } - if (!$gateways[$id]->gatewayEnabled()) - unset($gateways[$id]); - } + // No gateways yet? + if (empty($gateways)) + fatal_error($txt['paid_admin_not_setup_gateway']); - // No gateways yet? - if (empty($gateways)) - fatal_error($txt['paid_admin_not_setup_gateway']); - - // Get the current subscriptions. - $request = $db->query('', ' - SELECT id_sublog, id_subscribe, start_time, end_time, status, payments_pending, pending_details - FROM {db_prefix}log_subscribed - WHERE id_member = {int:selected_member}', - array( - 'selected_member' => $memID, - ) - ); - $context['current'] = array(); - while ($row = $db->fetch_assoc($request)) - { - // The subscription must exist! - if (!isset($context['subscriptions'][$row['id_subscribe']])) - continue; - - $context['current'][$row['id_subscribe']] = array( - 'id' => $row['id_sublog'], - 'sub_id' => $row['id_subscribe'], - 'hide' => $row['status'] == 0 && $row['end_time'] == 0 && $row['payments_pending'] == 0, - 'name' => $context['subscriptions'][$row['id_subscribe']]['name'], - 'start' => standardTime($row['start_time'], false), - 'end' => $row['end_time'] == 0 ? $txt['not_applicable'] : standardTime($row['end_time'], false), - 'pending_details' => $row['pending_details'], - 'status' => $row['status'], - 'status_text' => $row['status'] == 0 ? ($row['payments_pending'] ? $txt['paid_pending'] : $txt['paid_finished']) : $txt['paid_active'], + // Get the current subscriptions. + $request = $db->query('', ' + SELECT id_sublog, id_subscribe, start_time, end_time, status, payments_pending, pending_details + FROM {db_prefix}log_subscribed + WHERE id_member = {int:selected_member}', + array( + 'selected_member' => $memID, + ) ); + $context['current'] = array(); + while ($row = $db->fetch_assoc($request)) + { + // The subscription must exist! + if (!isset($context['subscriptions'][$row['id_subscribe']])) + continue; + + $context['current'][$row['id_subscribe']] = array( + 'id' => $row['id_sublog'], + 'sub_id' => $row['id_subscribe'], + 'hide' => $row['status'] == 0 && $row['end_time'] == 0 && $row['payments_pending'] == 0, + 'name' => $context['subscriptions'][$row['id_subscribe']]['name'], + 'start' => standardTime($row['start_time'], false), + 'end' => $row['end_time'] == 0 ? $txt['not_applicable'] : standardTime($row['end_time'], false), + 'pending_details' => $row['pending_details'], + 'status' => $row['status'], + 'status_text' => $row['status'] == 0 ? ($row['payments_pending'] ? $txt['paid_pending'] : $txt['paid_finished']) : $txt['paid_active'], + ); - if ($row['status'] == 1) - $context['subscriptions'][$row['id_subscribe']]['subscribed'] = true; - } - $db->free_result($request); - - // Simple "done"? - if (isset($_GET['done'])) - { - $_GET['sub_id'] = (int) $_GET['sub_id']; + if ($row['status'] == 1) + $context['subscriptions'][$row['id_subscribe']]['subscribed'] = true; + } + $db->free_result($request); - // Must exist but let's be sure... - if (isset($context['current'][$_GET['sub_id']])) + // Simple "done"? + if (isset($_GET['done'])) { - // What are the details like? - $current_pending = @unserialize($context['current'][$_GET['sub_id']]['pending_details']); - if (!empty($current_pending)) + $_GET['sub_id'] = (int) $_GET['sub_id']; + + // Must exist but let's be sure... + if (isset($context['current'][$_GET['sub_id']])) { - $current_pending = array_reverse($current_pending); - foreach ($current_pending as $id => $sub) + // What are the details like? + $current_pending = @unserialize($context['current'][$_GET['sub_id']]['pending_details']); + if (!empty($current_pending)) { - // Just find one and change it. - if ($sub[0] == $_GET['sub_id'] && $sub[3] == 'prepay') + $current_pending = array_reverse($current_pending); + foreach ($current_pending as $id => $sub) { - $current_pending[$id][3] = 'payback'; - break; + // Just find one and change it. + if ($sub[0] == $_GET['sub_id'] && $sub[3] == 'prepay') + { + $current_pending[$id][3] = 'payback'; + break; + } } - } - // Save the details back. - $pending_details = serialize($current_pending); - - $db->query('', ' - UPDATE {db_prefix}log_subscribed - SET payments_pending = payments_pending + 1, pending_details = {string:pending_details} - WHERE id_sublog = {int:current_subscription_id} - AND id_member = {int:selected_member}', - array( - 'current_subscription_id' => $context['current'][$_GET['sub_id']]['id'], - 'selected_member' => $memID, - 'pending_details' => $pending_details, - ) - ); + // Save the details back. + $pending_details = serialize($current_pending); + + $db->query('', ' + UPDATE {db_prefix}log_subscribed + SET payments_pending = payments_pending + 1, pending_details = {string:pending_details} + WHERE id_sublog = {int:current_subscription_id} + AND id_member = {int:selected_member}', + array( + 'current_subscription_id' => $context['current'][$_GET['sub_id']]['id'], + 'selected_member' => $memID, + 'pending_details' => $pending_details, + ) + ); + } } + + $context['sub_template'] = 'paid_done'; + return; } - $context['sub_template'] = 'paid_done'; - return; - } + // If this is confirmation then it's simpler... + if (isset($_GET['confirm']) && isset($_POST['sub_id']) && is_array($_POST['sub_id'])) + { + // Hopefully just one. + foreach ($_POST['sub_id'] as $k => $v) + $ID_SUB = (int) $k; - // If this is confirmation then it's simpler... - if (isset($_GET['confirm']) && isset($_POST['sub_id']) && is_array($_POST['sub_id'])) - { - // Hopefully just one. - foreach ($_POST['sub_id'] as $k => $v) - $ID_SUB = (int) $k; + if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0) + fatal_lang_error('paid_sub_not_active'); - if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0) - fatal_lang_error('paid_sub_not_active'); + // Simplify... + $context['sub'] = $context['subscriptions'][$ID_SUB]; + $period = 'xx'; + if ($context['sub']['flexible']) + $period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx'; - // Simplify... - $context['sub'] = $context['subscriptions'][$ID_SUB]; - $period = 'xx'; - if ($context['sub']['flexible']) - $period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx'; + // Check we have a valid cost. + if ($context['sub']['flexible'] && $period == 'xx') + fatal_lang_error('paid_sub_not_active'); - // Check we have a valid cost. - if ($context['sub']['flexible'] && $period == 'xx') - fatal_lang_error('paid_sub_not_active'); + // Sort out the cost/currency. + $context['currency'] = $modSettings['paid_currency_code']; + $context['recur'] = $context['sub']['repeatable']; - // Sort out the cost/currency. - $context['currency'] = $modSettings['paid_currency_code']; - $context['recur'] = $context['sub']['repeatable']; + if ($context['sub']['flexible']) + { + // Real cost... + $context['value'] = $context['sub']['costs'][$_POST['cur'][$ID_SUB]]; + $context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']) . '/' . $txt[$_POST['cur'][$ID_SUB]]; + // The period value for paypal. + $context['paypal_period'] = strtoupper(substr($_POST['cur'][$ID_SUB], 0, 1)); + } + else + { + // Real cost... + $context['value'] = $context['sub']['costs']['fixed']; + $context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']); + + // Recur? + preg_match('~(\d*)(\w)~', $context['sub']['real_length'], $match); + $context['paypal_unit'] = $match[1]; + $context['paypal_period'] = $match[2]; + } - if ($context['sub']['flexible']) - { - // Real cost... - $context['value'] = $context['sub']['costs'][$_POST['cur'][$ID_SUB]]; - $context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']) . '/' . $txt[$_POST['cur'][$ID_SUB]]; - // The period value for paypal. - $context['paypal_period'] = strtoupper(substr($_POST['cur'][$ID_SUB], 0, 1)); - } - else - { - // Real cost... - $context['value'] = $context['sub']['costs']['fixed']; - $context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']); - - // Recur? - preg_match('~(\d*)(\w)~', $context['sub']['real_length'], $match); - $context['paypal_unit'] = $match[1]; - $context['paypal_period'] = $match[2]; - } + // Setup the gateway context. + $context['gateways'] = array(); + foreach ($gateways as $id => $gateway) + { + $fields = $gateways[$id]->fetchGatewayFields($context['sub']['id'] . '+' . $memID, $context['sub'], $context['value'], $period, $scripturl . '?action=profile;u=' . $memID . ';area=subscriptions;sub_id=' . $context['sub']['id'] . ';done'); + if (!empty($fields['form'])) + $context['gateways'][] = $fields; + } - // Setup the gateway context. - $context['gateways'] = array(); - foreach ($gateways as $id => $gateway) - { - $fields = $gateways[$id]->fetchGatewayFields($context['sub']['id'] . '+' . $memID, $context['sub'], $context['value'], $period, $scripturl . '?action=profile;u=' . $memID . ';area=subscriptions;sub_id=' . $context['sub']['id'] . ';done'); - if (!empty($fields['form'])) - $context['gateways'][] = $fields; - } + // Bugger?! + if (empty($context['gateways'])) + fatal_error($txt['paid_admin_not_setup_gateway']); - // Bugger?! - if (empty($context['gateways'])) - fatal_error($txt['paid_admin_not_setup_gateway']); + // Now we are going to assume they want to take this out ;) + $new_data = array($context['sub']['id'], $context['value'], $period, 'prepay'); + if (isset($context['current'][$context['sub']['id']])) + { + // What are the details like? + $current_pending = array(); + if ($context['current'][$context['sub']['id']]['pending_details'] != '') + $current_pending = @unserialize($context['current'][$context['sub']['id']]['pending_details']); - // Now we are going to assume they want to take this out ;) - $new_data = array($context['sub']['id'], $context['value'], $period, 'prepay'); - if (isset($context['current'][$context['sub']['id']])) - { - // What are the details like? - $current_pending = array(); - if ($context['current'][$context['sub']['id']]['pending_details'] != '') - $current_pending = @unserialize($context['current'][$context['sub']['id']]['pending_details']); + // Don't get silly. + if (count($current_pending) > 9) + $current_pending = array(); + $pending_count = 0; - // Don't get silly. - if (count($current_pending) > 9) - $current_pending = array(); - $pending_count = 0; + // Only record real pending payments as will otherwise confuse the admin! + foreach ($current_pending as $pending) + { + if ($pending[3] == 'payback') + $pending_count++; + } - // Only record real pending payments as will otherwise confuse the admin! - foreach ($current_pending as $pending) - { - if ($pending[3] == 'payback') - $pending_count++; - } + if (!in_array($new_data, $current_pending)) + { + $current_pending[] = $new_data; + $pending_details = serialize($current_pending); + + $db->query('', ' + UPDATE {db_prefix}log_subscribed + SET payments_pending = {int:pending_count}, pending_details = {string:pending_details} + WHERE id_sublog = {int:current_subscription_item} + AND id_member = {int:selected_member}', + array( + 'pending_count' => $pending_count, + 'current_subscription_item' => $context['current'][$context['sub']['id']]['id'], + 'selected_member' => $memID, + 'pending_details' => $pending_details, + ) + ); + } - if (!in_array($new_data, $current_pending)) + } + // Never had this before, lovely. + else { - $current_pending[] = $new_data; - $pending_details = serialize($current_pending); - - $db->query('', ' - UPDATE {db_prefix}log_subscribed - SET payments_pending = {int:pending_count}, pending_details = {string:pending_details} - WHERE id_sublog = {int:current_subscription_item} - AND id_member = {int:selected_member}', + $pending_details = serialize(array($new_data)); + $db->insert('', + '{db_prefix}log_subscribed', + array( + 'id_subscribe' => 'int', 'id_member' => 'int', 'status' => 'int', 'payments_pending' => 'int', 'pending_details' => 'string-65534', + 'start_time' => 'int', 'vendor_ref' => 'string-255', + ), array( - 'pending_count' => $pending_count, - 'current_subscription_item' => $context['current'][$context['sub']['id']]['id'], - 'selected_member' => $memID, - 'pending_details' => $pending_details, - ) + $context['sub']['id'], $memID, 0, 0, $pending_details, + time(), '', + ), + array('id_sublog') ); } + // Change the template. + $context['sub_template'] = 'choose_payment'; + + // Quit. + return; } - // Never had this before, lovely. else - { - $pending_details = serialize(array($new_data)); - $db->insert('', - '{db_prefix}log_subscribed', - array( - 'id_subscribe' => 'int', 'id_member' => 'int', 'status' => 'int', 'payments_pending' => 'int', 'pending_details' => 'string-65534', - 'start_time' => 'int', 'vendor_ref' => 'string-255', - ), - array( - $context['sub']['id'], $memID, 0, 0, $pending_details, - time(), '', - ), - array('id_sublog') - ); - } - - // Change the template. - $context['sub_template'] = 'choose_payment'; - - // Quit. - return; + $context['sub_template'] = 'user_subscription'; } - else - $context['sub_template'] = 'user_subscription'; } \ No newline at end of file From cef6e3daf419cc1692e7a7baac95396f994e7874 Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 13:19:58 +0300 Subject: [PATCH 16/34] Rework ProfileOptions controller as a class, initial pass. Move to boards subs getBoardNotificationsCount(). (uses db; other boards notifications functions are currently in boards subs). Few other cleaning up bits, methods visibilities. Signed-off-by: Norv --- .../PersonalMessage.controller.php | 7 +- sources/controllers/Profile.controller.php | 19 +- .../controllers/ProfileOptions.controller.php | 2234 ++++++++--------- sources/subs/Boards.subs.php | 31 + 4 files changed, 1162 insertions(+), 1129 deletions(-) diff --git a/sources/controllers/PersonalMessage.controller.php b/sources/controllers/PersonalMessage.controller.php index a4490ea26f..b7e0454aed 100644 --- a/sources/controllers/PersonalMessage.controller.php +++ b/sources/controllers/PersonalMessage.controller.php @@ -1728,6 +1728,8 @@ function action_settings() loadLanguage('Profile'); loadTemplate('Profile'); + require_once(SUBSDIR . '/Profile.subs.php'); + $context['page_title'] = $txt['pm_settings']; $context['user']['is_owner'] = true; $context['id_member'] = $user_info['id']; @@ -1752,7 +1754,6 @@ function action_settings() $_POST = htmlspecialchars__recursive($_POST); // Save the fields. - require_once(SUBSDIR . '/Profile.subs.php'); saveProfileFields(); if (!empty($profile_vars)) @@ -1761,8 +1762,8 @@ function action_settings() // Load up the fields. require_once(CONTROLLERDIR . '/ProfileOptions.controller.php'); - require_once(SUBSDIR . '/Profile.subs.php'); - action_pmprefs($user_info['id']); + $controller = new ProfileOptions_Controller(); + $controller->action_pmprefs($user_info['id']); } /** diff --git a/sources/controllers/Profile.controller.php b/sources/controllers/Profile.controller.php index ef7df01e52..d20a2dcaab 100644 --- a/sources/controllers/Profile.controller.php +++ b/sources/controllers/Profile.controller.php @@ -169,6 +169,7 @@ public function action_index() 'account' => array( 'label' => $txt['account'], 'file' => '/controllers/ProfileOptions.controller.php', + 'controller' => 'ProfileOptions_Controller', 'function' => 'action_account', 'enabled' => $context['user']['is_admin'] || ($cur_profile['id_group'] != 1 && !in_array(1, explode(',', $cur_profile['additional_groups']))), 'sc' => 'post', @@ -182,6 +183,7 @@ public function action_index() 'forumprofile' => array( 'label' => $txt['forumprofile'], 'file' => '/controllers/ProfileOptions.controller.php', + 'controller' => 'ProfileOptions_Controller', 'function' => 'action_forumProfile', 'sc' => 'post', 'token' => 'profile-fp%u', @@ -193,6 +195,7 @@ public function action_index() 'theme' => array( 'label' => $txt['theme'], 'file' => '/controllers/ProfileOptions.controller.php', + 'controller' => 'ProfileOptions_Controller', 'function' => 'action_themepick', 'sc' => 'post', 'token' => 'profile-th%u', @@ -204,6 +207,7 @@ public function action_index() 'authentication' => array( 'label' => $txt['authentication'], 'file' => '/controllers/ProfileOptions.controller.php', + 'controller' => 'ProfileOptions_Controller', 'function' => 'action_authentication', 'enabled' => !empty($modSettings['enableOpenID']) || !empty($cur_profile['openid_uri']), 'sc' => 'post', @@ -218,6 +222,7 @@ public function action_index() 'notification' => array( 'label' => $txt['notification'], 'file' => '/controllers/ProfileOptions.controller.php', + 'controller' => 'ProfileOptions_Controller', 'function' => 'action_notification', 'sc' => 'post', 'token' => 'profile-nt%u', @@ -230,6 +235,7 @@ public function action_index() 'pmprefs' => array( 'label' => $txt['pmprefs'], 'file' => '/controllers/ProfileOptions.controller.php', + 'controller' => 'ProfileOptions_Controller', 'function' => 'action_pmprefs', 'enabled' => allowedTo(array('profile_extra_own', 'profile_extra_any')), 'sc' => 'post', @@ -242,6 +248,7 @@ public function action_index() 'ignoreboards' => array( 'label' => $txt['ignoreboards'], 'file' => '/controllers/ProfileOptions.controller.php', + 'controller' => 'ProfileOptions_Controller', 'function' => 'action_ignoreboards', 'enabled' => !empty($modSettings['allow_ignore_boards']), 'sc' => 'post', @@ -254,6 +261,7 @@ public function action_index() 'lists' => array( 'label' => $txt['editBuddyIgnoreLists'], 'file' => '/controllers/ProfileOptions.controller.php', + 'controller' => 'ProfileOptions_Controller', 'function' => 'action_editBuddyIgnoreLists', 'enabled' => !empty($modSettings['enable_buddylist']) && $context['user']['is_owner'], 'sc' => 'post', @@ -270,6 +278,7 @@ public function action_index() 'groupmembership' => array( 'label' => $txt['groupmembership'], 'file' => '/controllers/ProfileOptions.controller.php', + 'controller' => 'ProfileOptions_Controller', 'function' => 'action_groupMembership', 'enabled' => !empty($modSettings['show_group_membership']) && $context['user']['is_owner'], 'sc' => 'request', @@ -580,14 +589,20 @@ public function action_index() } elseif ($current_area == 'groupmembership' && empty($post_errors)) { - $msg = action_groupMembership2($profile_vars, $post_errors, $memID); + require_once(CONTROLLERDIR . '/ProfileOptions.controller.php'); + $controller = new Profileoptions_Controller(); + $msg = $controller->action_groupMembership2($profile_vars, $post_errors, $memID); // Whatever we've done, we have nothing else to do here... redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=groupmembership' . (!empty($msg) ? ';msg=' . $msg : '')); } // Authentication changes? elseif ($current_area == 'authentication') - action_authentication($memID, true); + { + require_once(CONTROLLERDIR . '/ProfileOptions.controller.php'); + $controller = new ProfileOptions_Controller(); + $controller->action_authentication($memID, true); + } elseif (in_array($current_area, array('account', 'forumprofile', 'theme', 'pmprefs'))) saveProfileFields(); else diff --git a/sources/controllers/ProfileOptions.controller.php b/sources/controllers/ProfileOptions.controller.php index 6927a4bbf1..08f9ab8dd2 100644 --- a/sources/controllers/ProfileOptions.controller.php +++ b/sources/controllers/ProfileOptions.controller.php @@ -22,1344 +22,1330 @@ if (!defined('ELKARTE')) die('No access...'); -/** - * Show all the users buddies, as well as a add/delete interface. - * - */ -function action_editBuddyIgnoreLists() +class ProfileOptions_Controller extends Action_Controller { - global $context, $txt, $modSettings; - - $memID = currentMemberID(); - - // Do a quick check to ensure people aren't getting here illegally! - if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) - fatal_lang_error('no_access', false); - - loadTemplate('ProfileOptions'); - - // Can we email the user direct? - $context['can_moderate_forum'] = allowedTo('moderate_forum'); - $context['can_send_email'] = allowedTo('send_email_to_members'); + /** + * Default method, if another action is not called + * by the menu. + * + * @see Action_Controller::action_index() + */ + public function action_index() + { + // action_account() is the first to do + // these subactions are mostly routed to from the profile + // menu though. + } - $subActions = array( - 'buddies' => array('action_editBuddies', $txt['editBuddies']), - 'ignore' => array('action_editIgnoreList', $txt['editIgnoreList']), - ); + /** + * Show all the users buddies, as well as a add/delete interface. + * + */ + public function action_editBuddyIgnoreLists() + { + global $context, $txt, $modSettings; - $context['list_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : 'buddies'; + $memID = currentMemberID(); - // Create the tabs for the template. - $context[$context['profile_menu_name']]['tab_data'] = array( - 'title' => $txt['editBuddyIgnoreLists'], - 'description' => $txt['buddy_ignore_desc'], - 'icon' => 'profile_hd.png', - 'tabs' => array( - 'buddies' => array(), - 'ignore' => array(), - ), - ); + // Do a quick check to ensure people aren't getting here illegally! + if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) + fatal_lang_error('no_access', false); - // Pass on to the actual function. - $subActions[$context['list_area']][0]($memID); -} + loadTemplate('ProfileOptions'); -/** - * Show all the users buddies, as well as a add/delete interface. - * - * @param int $memID id_member - */ -function action_editBuddies($memID) -{ - global $context, $user_profile, $memberContext; + // Can we email the user direct? + $context['can_moderate_forum'] = allowedTo('moderate_forum'); + $context['can_send_email'] = allowedTo('send_email_to_members'); - $db = database(); + $subActions = array( + 'buddies' => array('action_editBuddies', $txt['editBuddies']), + 'ignore' => array('action_editIgnoreList', $txt['editIgnoreList']), + ); - loadTemplate('ProfileOptions'); + $context['list_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : 'buddies'; - // We want to view what we're doing :P - $context['sub_template'] = 'editBuddies'; + // Create the tabs for the template. + $context[$context['profile_menu_name']]['tab_data'] = array( + 'title' => $txt['editBuddyIgnoreLists'], + 'description' => $txt['buddy_ignore_desc'], + 'icon' => 'profile_hd.png', + 'tabs' => array( + 'buddies' => array(), + 'ignore' => array(), + ), + ); - // For making changes! - $buddiesArray = explode(',', $user_profile[$memID]['buddy_list']); - foreach ($buddiesArray as $k => $dummy) - if ($dummy == '') - unset($buddiesArray[$k]); + // Pass on to the actual function. + $this->{$subActions[$context['list_area']][0]}($memID); + } - // Removing a buddy? - if (isset($_GET['remove'])) + /** + * Show all the users buddies, as well as a add/delete interface. + * + * @param int $memID id_member + */ + public function action_editBuddies($memID) { - checkSession('get'); + global $context, $user_profile, $memberContext; - call_integration_hook('integrate_remove_buddy', array($memID)); + $db = database(); - // Heh, I'm lazy, do it the easy way... - foreach ($buddiesArray as $key => $buddy) - if ($buddy == (int) $_GET['remove']) - unset($buddiesArray[$key]); + loadTemplate('ProfileOptions'); - // Make the changes. - $user_profile[$memID]['buddy_list'] = implode(',', $buddiesArray); - updateMemberData($memID, array('buddy_list' => $user_profile[$memID]['buddy_list'])); - - // Redirect off the page because we don't like all this ugly query stuff to stick in the history. - redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID); - } - elseif (isset($_POST['new_buddy'])) - { - checkSession(); + // We want to view what we're doing :P + $context['sub_template'] = 'editBuddies'; - // Prepare the string for extraction... - $_POST['new_buddy'] = strtr(Util::htmlspecialchars($_POST['new_buddy'], ENT_QUOTES), array('"' => '"')); - preg_match_all('~"([^"]+)"~', $_POST['new_buddy'], $matches); - $new_buddies = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST['new_buddy'])))); + // For making changes! + $buddiesArray = explode(',', $user_profile[$memID]['buddy_list']); + foreach ($buddiesArray as $k => $dummy) + if ($dummy == '') + unset($buddiesArray[$k]); - foreach ($new_buddies as $k => $dummy) + // Removing a buddy? + if (isset($_GET['remove'])) { - $new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => ''')); + checkSession('get'); - if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) - unset($new_buddies[$k]); - } + call_integration_hook('integrate_remove_buddy', array($memID)); - call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies)); + // Heh, I'm lazy, do it the easy way... + foreach ($buddiesArray as $key => $buddy) + if ($buddy == (int) $_GET['remove']) + unset($buddiesArray[$key]); - if (!empty($new_buddies)) - { - // Now find out the id_member of the buddy. - $request = $db->query('', ' - SELECT id_member - FROM {db_prefix}members - WHERE member_name IN ({array_string:new_buddies}) OR real_name IN ({array_string:new_buddies}) - LIMIT {int:count_new_buddies}', - array( - 'new_buddies' => $new_buddies, - 'count_new_buddies' => count($new_buddies), - ) - ); - - // Add the new member to the buddies array. - while ($row = $db->fetch_assoc($request)) - $buddiesArray[] = (int) $row['id_member']; - $db->free_result($request); - - // Now update the current users buddy list. + // Make the changes. $user_profile[$memID]['buddy_list'] = implode(',', $buddiesArray); updateMemberData($memID, array('buddy_list' => $user_profile[$memID]['buddy_list'])); + + // Redirect off the page because we don't like all this ugly query stuff to stick in the history. + redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID); } + elseif (isset($_POST['new_buddy'])) + { + checkSession(); - // Back to the buddy list! - redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID); - } + // Prepare the string for extraction... + $_POST['new_buddy'] = strtr(Util::htmlspecialchars($_POST['new_buddy'], ENT_QUOTES), array('"' => '"')); + preg_match_all('~"([^"]+)"~', $_POST['new_buddy'], $matches); + $new_buddies = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST['new_buddy'])))); - // Get all the users "buddies"... - $buddies = array(); + foreach ($new_buddies as $k => $dummy) + { + $new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => ''')); - if (!empty($buddiesArray)) - { - require_once(SUBSDIR . '/Members.subs.php'); - $result = getBasicMemberData($buddiesArray, array('sort' => 'real_name', 'limit' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1)); - foreach ($result as $row) - $buddies[] = $row['id_member']; - } + if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) + unset($new_buddies[$k]); + } - $context['buddy_count'] = count($buddies); + call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies)); - // Load all the members up. - loadMemberData($buddies, false, 'profile'); + if (!empty($new_buddies)) + { + // Now find out the id_member of the buddy. + $request = $db->query('', ' + SELECT id_member + FROM {db_prefix}members + WHERE member_name IN ({array_string:new_buddies}) OR real_name IN ({array_string:new_buddies}) + LIMIT {int:count_new_buddies}', + array( + 'new_buddies' => $new_buddies, + 'count_new_buddies' => count($new_buddies), + ) + ); - // Setup the context for each buddy. - $context['buddies'] = array(); - foreach ($buddies as $buddy) - { - loadMemberContext($buddy); - $context['buddies'][$buddy] = $memberContext[$buddy]; - } + // Add the new member to the buddies array. + while ($row = $db->fetch_assoc($request)) + $buddiesArray[] = (int) $row['id_member']; + $db->free_result($request); - call_integration_hook('integrate_view_buddies', array($memID)); -} + // Now update the current users buddy list. + $user_profile[$memID]['buddy_list'] = implode(',', $buddiesArray); + updateMemberData($memID, array('buddy_list' => $user_profile[$memID]['buddy_list'])); + } -/** - * Allows the user to view their ignore list, - * as well as the option to manage members on it. - * - * @param int $memID id_member - */ -function action_editIgnoreList($memID) -{ - global $context, $user_profile, $memberContext; + // Back to the buddy list! + redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID); + } - $db = database(); + // Get all the users "buddies"... + $buddies = array(); - loadTemplate('ProfileOptions'); + if (!empty($buddiesArray)) + { + require_once(SUBSDIR . '/Members.subs.php'); + $result = getBasicMemberData($buddiesArray, array('sort' => 'real_name', 'limit' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1)); + foreach ($result as $row) + $buddies[] = $row['id_member']; + } - // We want to view what we're doing :P - $context['sub_template'] = 'editIgnoreList'; + $context['buddy_count'] = count($buddies); - // For making changes! - $ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']); - foreach ($ignoreArray as $k => $dummy) - { - if ($dummy == '') - unset($ignoreArray[$k]); + // Load all the members up. + loadMemberData($buddies, false, 'profile'); + + // Setup the context for each buddy. + $context['buddies'] = array(); + foreach ($buddies as $buddy) + { + loadMemberContext($buddy); + $context['buddies'][$buddy] = $memberContext[$buddy]; + } + + call_integration_hook('integrate_view_buddies', array($memID)); } - // Removing a member from the ignore list? - if (isset($_GET['remove'])) + /** + * Allows the user to view their ignore list, + * as well as the option to manage members on it. + * + * @param int $memID id_member + */ + public function action_editIgnoreList($memID) { - checkSession('get'); + global $context, $user_profile, $memberContext; - // Heh, I'm lazy, do it the easy way... - foreach ($ignoreArray as $key => $id_remove) - if ($id_remove == (int) $_GET['remove']) - unset($ignoreArray[$key]); + $db = database(); - // Make the changes. - $user_profile[$memID]['pm_ignore_list'] = implode(',', $ignoreArray); - updateMemberData($memID, array('pm_ignore_list' => $user_profile[$memID]['pm_ignore_list'])); - - // Redirect off the page because we don't like all this ugly query stuff to stick in the history. - redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID); - } - elseif (isset($_POST['new_ignore'])) - { - checkSession(); + loadTemplate('ProfileOptions'); - // Prepare the string for extraction... - $_POST['new_ignore'] = strtr(Util::htmlspecialchars($_POST['new_ignore'], ENT_QUOTES), array('"' => '"')); - preg_match_all('~"([^"]+)"~', $_POST['new_ignore'], $matches); - $new_entries = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST['new_ignore'])))); + // We want to view what we're doing :P + $context['sub_template'] = 'editIgnoreList'; - foreach ($new_entries as $k => $dummy) + // For making changes! + $ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']); + foreach ($ignoreArray as $k => $dummy) { - $new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => ''')); - - if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) - unset($new_entries[$k]); + if ($dummy == '') + unset($ignoreArray[$k]); } - if (!empty($new_entries)) + // Removing a member from the ignore list? + if (isset($_GET['remove'])) { - // Now find out the id_member for the members in question. - $request = $db->query('', ' - SELECT id_member - FROM {db_prefix}members - WHERE member_name IN ({array_string:new_entries}) OR real_name IN ({array_string:new_entries}) - LIMIT {int:count_new_entries}', - array( - 'new_entries' => $new_entries, - 'count_new_entries' => count($new_entries), - ) - ); + checkSession('get'); - // Add the new member to the buddies array. - while ($row = $db->fetch_assoc($request)) - $ignoreArray[] = (int) $row['id_member']; - $db->free_result($request); + // Heh, I'm lazy, do it the easy way... + foreach ($ignoreArray as $key => $id_remove) + if ($id_remove == (int) $_GET['remove']) + unset($ignoreArray[$key]); - // Now update the current users buddy list. + // Make the changes. $user_profile[$memID]['pm_ignore_list'] = implode(',', $ignoreArray); updateMemberData($memID, array('pm_ignore_list' => $user_profile[$memID]['pm_ignore_list'])); + + // Redirect off the page because we don't like all this ugly query stuff to stick in the history. + redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID); } + elseif (isset($_POST['new_ignore'])) + { + checkSession(); - // Back to the list of pityful people! - redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID); - } + // Prepare the string for extraction... + $_POST['new_ignore'] = strtr(Util::htmlspecialchars($_POST['new_ignore'], ENT_QUOTES), array('"' => '"')); + preg_match_all('~"([^"]+)"~', $_POST['new_ignore'], $matches); + $new_entries = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST['new_ignore'])))); - // Initialise the list of members we're ignoring. - $ignored = array(); + foreach ($new_entries as $k => $dummy) + { + $new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => ''')); - if (!empty($ignoreArray)) - { - require_once(SUBSDIR . '/Members.subs.php'); - $result = getBasicMemberData($ignoreArray, array('sort' => 'real_name', 'limit' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1)); - foreach ($result as $row) - $ignored[] = $row['id_member']; - } + if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) + unset($new_entries[$k]); + } - $context['ignore_count'] = count($ignored); + if (!empty($new_entries)) + { + // Now find out the id_member for the members in question. + $request = $db->query('', ' + SELECT id_member + FROM {db_prefix}members + WHERE member_name IN ({array_string:new_entries}) OR real_name IN ({array_string:new_entries}) + LIMIT {int:count_new_entries}', + array( + 'new_entries' => $new_entries, + 'count_new_entries' => count($new_entries), + ) + ); - // Load all the members up. - loadMemberData($ignored, false, 'profile'); + // Add the new member to the buddies array. + while ($row = $db->fetch_assoc($request)) + $ignoreArray[] = (int) $row['id_member']; + $db->free_result($request); - // Setup the context for each buddy. - $context['ignore_list'] = array(); - foreach ($ignored as $ignore_member) - { - loadMemberContext($ignore_member); - $context['ignore_list'][$ignore_member] = $memberContext[$ignore_member]; - } -} + // Now update the current users buddy list. + $user_profile[$memID]['pm_ignore_list'] = implode(',', $ignoreArray); + updateMemberData($memID, array('pm_ignore_list' => $user_profile[$memID]['pm_ignore_list'])); + } -/** - * Allows the user to see or change their account info. - * - */ -function action_account() -{ - global $context, $txt; + // Back to the list of pityful people! + redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID); + } - $memID = currentMemberID(); + // Initialise the list of members we're ignoring. + $ignored = array(); - loadTemplate('ProfileOptions'); - loadThemeOptions($memID); + if (!empty($ignoreArray)) + { + require_once(SUBSDIR . '/Members.subs.php'); + $result = getBasicMemberData($ignoreArray, array('sort' => 'real_name', 'limit' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1)); + foreach ($result as $row) + $ignored[] = $row['id_member']; + } - if (allowedTo(array('profile_identity_own', 'profile_identity_any'))) - loadCustomFields($memID, 'account'); + $context['ignore_count'] = count($ignored); - $context['sub_template'] = 'edit_options'; - $context['page_desc'] = $txt['account_info']; + // Load all the members up. + loadMemberData($ignored, false, 'profile'); - setupProfileContext( - array( - 'member_name', 'real_name', 'date_registered', 'posts', 'lngfile', 'hr', - 'id_group', 'hr', - 'email_address', 'hide_email', 'show_online', 'hr', - 'passwrd1', 'passwrd2', 'hr', - 'secret_question', 'secret_answer', - ) - ); -} + // Setup the context for each buddy. + $context['ignore_list'] = array(); + foreach ($ignored as $ignore_member) + { + loadMemberContext($ignore_member); + $context['ignore_list'][$ignore_member] = $memberContext[$ignore_member]; + } + } -/** - * Allow the user to change the forum options in their profile. - * - */ -function action_forumProfile() -{ - global $context, $txt; + /** + * Allows the user to see or change their account info. + * + */ + public function action_account() + { + global $context, $txt; - $memID = currentMemberID(); + $memID = currentMemberID(); - loadTemplate('ProfileOptions'); - loadThemeOptions($memID); + loadTemplate('ProfileOptions'); + loadThemeOptions($memID); - if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) - loadCustomFields($memID, 'forumprofile'); + if (allowedTo(array('profile_identity_own', 'profile_identity_any'))) + loadCustomFields($memID, 'account'); - $context['sub_template'] = 'edit_options'; - $context['page_desc'] = $txt['forumProfile_info']; - $context['show_preview_button'] = true; + $context['sub_template'] = 'edit_options'; + $context['page_desc'] = $txt['account_info']; - setupProfileContext( - array( - 'avatar_choice', 'hr', 'personal_text', 'hr', - 'bday1', 'location', 'gender', 'hr', - 'usertitle', 'signature', 'hr', - 'karma_good', 'hr', - 'website_title', 'website_url', - ) - ); -} + setupProfileContext( + array( + 'member_name', 'real_name', 'date_registered', 'posts', 'lngfile', 'hr', + 'id_group', 'hr', + 'email_address', 'hide_email', 'show_online', 'hr', + 'passwrd1', 'passwrd2', 'hr', + 'secret_question', 'secret_answer', + ) + ); + } -/** - * Allow the edit of *someone elses* personal message settings. - * - */ -function action_pmprefs() -{ - global $context, $txt; + /** + * Allow the user to change the forum options in their profile. + * + */ + public function action_forumProfile() + { + global $context, $txt; - $memID = currentMemberID(); + $memID = currentMemberID(); - loadThemeOptions($memID); - loadCustomFields($memID, 'pmprefs'); - loadTemplate('ProfileOptions'); + loadTemplate('ProfileOptions'); + loadThemeOptions($memID); - $context['sub_template'] = 'edit_options'; - $context['page_desc'] = $txt['pm_settings_desc']; + if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) + loadCustomFields($memID, 'forumprofile'); - setupProfileContext( - array( - 'pm_prefs', - ) - ); -} + $context['sub_template'] = 'edit_options'; + $context['page_desc'] = $txt['forumProfile_info']; + $context['show_preview_button'] = true; -/** - * Allow the user to pick a theme. - * - */ -function action_themepick() -{ - global $txt, $context; + setupProfileContext( + array( + 'avatar_choice', 'hr', 'personal_text', 'hr', + 'bday1', 'location', 'gender', 'hr', + 'usertitle', 'signature', 'hr', + 'karma_good', 'hr', + 'website_title', 'website_url', + ) + ); + } - $memID = currentMemberID(); + /** + * Allow the edit of *someone elses* personal message settings. + * + */ + public function action_pmprefs() + { + global $context, $txt; - loadThemeOptions($memID); + $memID = currentMemberID(); - if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) - loadCustomFields($memID, 'theme'); + loadThemeOptions($memID); + loadCustomFields($memID, 'pmprefs'); + loadTemplate('ProfileOptions'); - loadTemplate('ProfileOptions'); + $context['sub_template'] = 'edit_options'; + $context['page_desc'] = $txt['pm_settings_desc']; - $context['sub_template'] = 'edit_options'; - $context['page_desc'] = $txt['theme_info']; + setupProfileContext( + array( + 'pm_prefs', + ) + ); + } - setupProfileContext( - array( - 'id_theme', 'smiley_set', 'hr', - 'time_format', 'time_offset', 'hr', - 'theme_settings', - ) - ); -} + /** + * Allow the user to pick a theme. + * + */ + public function action_themepick() + { + global $txt, $context; -/** - * Changing authentication method? - * Only appropriate for people using OpenID. - * - * @param int $memID id_member - * @param bool $saving = false - */ -function action_authentication($memID, $saving = false) -{ - global $context, $cur_profile, $post_errors, $modSettings; + $memID = currentMemberID(); + + loadThemeOptions($memID); - loadLanguage('Login'); + if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) + loadCustomFields($memID, 'theme'); - loadTemplate('ProfileOptions'); + loadTemplate('ProfileOptions'); - // We are saving? - if ($saving) + $context['sub_template'] = 'edit_options'; + $context['page_desc'] = $txt['theme_info']; + + setupProfileContext( + array( + 'id_theme', 'smiley_set', 'hr', + 'time_format', 'time_offset', 'hr', + 'theme_settings', + ) + ); + } + + /** + * Changing authentication method? + * Only appropriate for people using OpenID. + * + * @param int $memID id_member + * @param bool $saving = false + */ + public function action_authentication($memID, $saving = false) { - // Moving to password passed authentication? - if ($_POST['authenticate'] == 'passwd') - { - // Didn't enter anything? - if ($_POST['passwrd1'] == '') - $post_errors[] = 'no_password'; - // Do the two entries for the password even match? - elseif (!isset($_POST['passwrd2']) || $_POST['passwrd1'] != $_POST['passwrd2']) - $post_errors[] = 'bad_new_password'; - // Is it valid? - else - { - require_once(SUBSDIR . '/Auth.subs.php'); - $passwordErrors = validatePassword($_POST['passwrd1'], $cur_profile['member_name'], array($cur_profile['real_name'], $cur_profile['email_address'])); + global $context, $cur_profile, $post_errors, $modSettings; - // Were there errors? - if ($passwordErrors != null) - $post_errors[] = 'password_' . $passwordErrors; - } + loadLanguage('Login'); + + loadTemplate('ProfileOptions'); - if (empty($post_errors)) + // We are saving? + if ($saving) + { + // Moving to password passed authentication? + if ($_POST['authenticate'] == 'passwd') { - // Integration? - call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd1'])); + // Didn't enter anything? + if ($_POST['passwrd1'] == '') + $post_errors[] = 'no_password'; + // Do the two entries for the password even match? + elseif (!isset($_POST['passwrd2']) || $_POST['passwrd1'] != $_POST['passwrd2']) + $post_errors[] = 'bad_new_password'; + // Is it valid? + else + { + require_once(SUBSDIR . '/Auth.subs.php'); + $passwordErrors = validatePassword($_POST['passwrd1'], $cur_profile['member_name'], array($cur_profile['real_name'], $cur_profile['email_address'])); - // Go then. - $passwd = sha1(strtolower($cur_profile['member_name']) . un_htmlspecialchars($_POST['passwrd1'])); + // Were there errors? + if ($passwordErrors != null) + $post_errors[] = 'password_' . $passwordErrors; + } - // Do the important bits. - updateMemberData($memID, array('openid_uri' => '', 'passwd' => $passwd)); - if ($context['user']['is_owner']) + if (empty($post_errors)) { - setLoginCookie(60 * $modSettings['cookieTime'], $memID, sha1(sha1(strtolower($cur_profile['member_name']) . un_htmlspecialchars($_POST['passwrd2'])) . $cur_profile['password_salt'])); - redirectexit('action=profile;area=authentication;updated'); + // Integration? + call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd1'])); + + // Go then. + $passwd = sha1(strtolower($cur_profile['member_name']) . un_htmlspecialchars($_POST['passwrd1'])); + + // Do the important bits. + updateMemberData($memID, array('openid_uri' => '', 'passwd' => $passwd)); + if ($context['user']['is_owner']) + { + setLoginCookie(60 * $modSettings['cookieTime'], $memID, sha1(sha1(strtolower($cur_profile['member_name']) . un_htmlspecialchars($_POST['passwrd2'])) . $cur_profile['password_salt'])); + redirectexit('action=profile;area=authentication;updated'); + } + else + redirectexit('action=profile;u=' . $memID); } - else - redirectexit('action=profile;u=' . $memID); - } - - return true; - } - // Not right yet! - elseif ($_POST['authenticate'] == 'openid' && !empty($_POST['openid_identifier'])) - { - require_once(SUBSDIR . '/OpenID.subs.php'); - $_POST['openid_identifier'] = openID_canonize($_POST['openid_identifier']); - if (openid_member_exists($_POST['openid_identifier'])) - $post_errors[] = 'openid_in_use'; - elseif (empty($post_errors)) + return true; + } + // Not right yet! + elseif ($_POST['authenticate'] == 'openid' && !empty($_POST['openid_identifier'])) { - // Authenticate using the new OpenID URI first to make sure they didn't make a mistake. - if ($context['user']['is_owner']) - { - $_SESSION['new_openid_uri'] = $_POST['openid_identifier']; + require_once(SUBSDIR . '/OpenID.subs.php'); + $_POST['openid_identifier'] = openID_canonize($_POST['openid_identifier']); - openID_validate($_POST['openid_identifier'], false, null, 'change_uri'); + if (openid_member_exists($_POST['openid_identifier'])) + $post_errors[] = 'openid_in_use'; + elseif (empty($post_errors)) + { + // Authenticate using the new OpenID URI first to make sure they didn't make a mistake. + if ($context['user']['is_owner']) + { + $_SESSION['new_openid_uri'] = $_POST['openid_identifier']; + + openID_validate($_POST['openid_identifier'], false, null, 'change_uri'); + } + else + updateMemberData($memID, array('openid_uri' => $_POST['openid_identifier'])); } - else - updateMemberData($memID, array('openid_uri' => $_POST['openid_identifier'])); } } - } - // Some stuff. - $context['member']['openid_uri'] = $cur_profile['openid_uri']; - $context['auth_method'] = empty($cur_profile['openid_uri']) ? 'password' : 'openid'; - $context['sub_template'] = 'authentication_method'; -} + // Some stuff. + $context['member']['openid_uri'] = $cur_profile['openid_uri']; + $context['auth_method'] = empty($cur_profile['openid_uri']) ? 'password' : 'openid'; + $context['sub_template'] = 'authentication_method'; + } -/** - * Display the notifications and settings for changes. - * - */ -function action_notification() -{ - global $txt, $scripturl, $user_profile, $context, $modSettings; - - loadTemplate('ProfileOptions'); - - $memID = currentMemberID(); - - // Gonna want this for the list. - require_once(SUBSDIR . '/List.subs.php'); - - // Fine, start with the board list. - $listOptions = array( - 'id' => 'board_notification_list', - 'width' => '100%', - 'no_items_label' => $txt['notifications_boards_none'] . '

' . $txt['notifications_boards_howto'], - 'no_items_align' => 'left', - 'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification', - 'default_sort_col' => 'board_name', - 'get_items' => array( - 'function' => 'list_getBoardNotifications', - 'params' => array( - $memID, - ), - ), - 'columns' => array( - 'board_name' => array( - 'header' => array( - 'value' => $txt['notifications_boards'], - 'class' => 'lefttext first_th', + /** + * Display the notifications and settings for changes. + * + */ + public function action_notification() + { + global $txt, $scripturl, $user_profile, $context, $modSettings; + + loadTemplate('ProfileOptions'); + + $memID = currentMemberID(); + + // Gonna want this for the list. + require_once(SUBSDIR . '/List.subs.php'); + require_once(SUBSDIR . '/Boards.subs.php'); + + // Fine, start with the board list. + $listOptions = array( + 'id' => 'board_notification_list', + 'width' => '100%', + 'no_items_label' => $txt['notifications_boards_none'] . '

' . $txt['notifications_boards_howto'], + 'no_items_align' => 'left', + 'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification', + 'default_sort_col' => 'board_name', + 'get_items' => array( + 'function' => 'list_getBoardNotifications', + 'params' => array( + $memID, ), - 'data' => array( - 'function' => create_function('$board', ' - global $settings, $txt; + ), + 'columns' => array( + 'board_name' => array( + 'header' => array( + 'value' => $txt['notifications_boards'], + 'class' => 'lefttext first_th', + ), + 'data' => array( + 'function' => create_function('$board', ' + global $settings, $txt; - $link = $board[\'link\']; + $link = $board[\'link\']; - if ($board[\'new\']) - $link .= \' ' . $txt['new'] . '\'; + if ($board[\'new\']) + $link .= \' ' . $txt['new'] . '\'; - return $link; - '), - ), - 'sort' => array( - 'default' => 'name', - 'reverse' => 'name DESC', - ), - ), - 'delete' => array( - 'header' => array( - 'value' => '', - 'style' => 'width: 4%;', - 'class' => 'centertext', + return $link; + '), + ), + 'sort' => array( + 'default' => 'name', + 'reverse' => 'name DESC', + ), ), - 'data' => array( - 'sprintf' => array( - 'format' => '', - 'params' => array( - 'id' => false, - 'checked' => false, + 'delete' => array( + 'header' => array( + 'value' => '', + 'style' => 'width: 4%;', + 'class' => 'centertext', + ), + 'data' => array( + 'sprintf' => array( + 'format' => '', + 'params' => array( + 'id' => false, + 'checked' => false, + ), + 'class' => 'centertext', ), - 'class' => 'centertext', ), ), ), - ), - 'form' => array( - 'href' => $scripturl . '?action=profile;area=notification;save', - 'include_sort' => true, - 'include_start' => true, - 'hidden_fields' => array( - 'u' => $memID, - 'sa' => $context['menu_item_selected'], - $context['session_var'] => $context['session_id'], - ), - 'token' => $context['token_check'], - ), - 'additional_rows' => array( - array( - 'position' => 'bottom_of_list', - 'value' => '', - ), - array( - 'position' => 'after_title', - 'value' => getBoardNotificationsCount($memID) == 0 ? $txt['notifications_boards_none'] . '
' . $txt['notifications_boards_howto'] : $txt['notifications_boards_current'], - 'class' => 'windowbg2', + 'form' => array( + 'href' => $scripturl . '?action=profile;area=notification;save', + 'include_sort' => true, + 'include_start' => true, + 'hidden_fields' => array( + 'u' => $memID, + 'sa' => $context['menu_item_selected'], + $context['session_var'] => $context['session_id'], + ), + 'token' => $context['token_check'], ), - ), - ); - - // Create the board notification list. - createList($listOptions); - - // Now do the topic notifications. - $listOptions = array( - 'id' => 'topic_notification_list', - 'width' => '100%', - 'items_per_page' => $modSettings['defaultMaxMessages'], - 'no_items_label' => $txt['notifications_topics_none'] . '

' . $txt['notifications_topics_howto'], - 'no_items_align' => 'left', - 'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification', - 'default_sort_col' => 'last_post', - 'get_items' => array( - 'function' => 'list_getTopicNotifications', - 'params' => array( - $memID, + 'additional_rows' => array( + array( + 'position' => 'bottom_of_list', + 'value' => '', + ), + array( + 'position' => 'after_title', + 'value' => getBoardNotificationsCount($memID) == 0 ? $txt['notifications_boards_none'] . '
' . $txt['notifications_boards_howto'] : $txt['notifications_boards_current'], + 'class' => 'windowbg2', + ), ), - ), - 'get_count' => array( - 'function' => 'list_getTopicNotificationCount', - 'params' => array( - $memID, + ); + + // Create the board notification list. + createList($listOptions); + + // Now do the topic notifications. + $listOptions = array( + 'id' => 'topic_notification_list', + 'width' => '100%', + 'items_per_page' => $modSettings['defaultMaxMessages'], + 'no_items_label' => $txt['notifications_topics_none'] . '

' . $txt['notifications_topics_howto'], + 'no_items_align' => 'left', + 'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification', + 'default_sort_col' => 'last_post', + 'get_items' => array( + 'function' => 'list_getTopicNotifications', + 'params' => array( + $memID, + ), ), - ), - 'columns' => array( - 'subject' => array( - 'header' => array( - 'value' => $txt['notifications_topics'], - 'class' => 'lefttext first_th', + 'get_count' => array( + 'function' => 'list_getTopicNotificationCount', + 'params' => array( + $memID, ), - 'data' => array( - 'function' => create_function('$topic', ' - global $settings, $txt; + ), + 'columns' => array( + 'subject' => array( + 'header' => array( + 'value' => $txt['notifications_topics'], + 'class' => 'lefttext first_th', + ), + 'data' => array( + 'function' => create_function('$topic', ' + global $settings, $txt; - $link = $topic[\'link\']; + $link = $topic[\'link\']; - if ($topic[\'new\']) - $link .= \' \' . $txt[\'new\'] . \'\'; + if ($topic[\'new\']) + $link .= \' \' . $txt[\'new\'] . \'\'; - $link .= \'
\' . $txt[\'in\'] . \' \' . $topic[\'board_link\'] . \'\'; + $link .= \'
\' . $txt[\'in\'] . \' \' . $topic[\'board_link\'] . \'\'; - return $link; - '), - ), - 'sort' => array( - 'default' => 'ms.subject', - 'reverse' => 'ms.subject DESC', - ), - ), - 'started_by' => array( - 'header' => array( - 'value' => $txt['started_by'], - 'class' => 'lefttext', - ), - 'data' => array( - 'db' => 'poster_link', - ), - 'sort' => array( - 'default' => 'real_name_col', - 'reverse' => 'real_name_col DESC', + return $link; + '), + ), + 'sort' => array( + 'default' => 'ms.subject', + 'reverse' => 'ms.subject DESC', + ), ), - ), - 'last_post' => array( - 'header' => array( - 'value' => $txt['last_post'], + 'started_by' => array( + 'header' => array( + 'value' => $txt['started_by'], 'class' => 'lefttext', + ), + 'data' => array( + 'db' => 'poster_link', + ), + 'sort' => array( + 'default' => 'real_name_col', + 'reverse' => 'real_name_col DESC', + ), ), - 'data' => array( - 'sprintf' => array( - 'format' => '%1$s
' . $txt['by'] . ' %2$s
', - 'params' => array( - 'updated' => false, - 'poster_updated_link' => false, + 'last_post' => array( + 'header' => array( + 'value' => $txt['last_post'], + 'class' => 'lefttext', + ), + 'data' => array( + 'sprintf' => array( + 'format' => '%1$s
' . $txt['by'] . ' %2$s
', + 'params' => array( + 'updated' => false, + 'poster_updated_link' => false, + ), ), ), + 'sort' => array( + 'default' => 'ml.id_msg DESC', + 'reverse' => 'ml.id_msg', + ), ), - 'sort' => array( - 'default' => 'ml.id_msg DESC', - 'reverse' => 'ml.id_msg', - ), - ), - 'delete' => array( - 'header' => array( - 'value' => '', - 'style' => 'width: 4%;', - 'class' => 'centertext', - ), - 'data' => array( - 'sprintf' => array( - 'format' => '', - 'params' => array( - 'id' => false, + 'delete' => array( + 'header' => array( + 'value' => '', + 'style' => 'width: 4%;', + 'class' => 'centertext', + ), + 'data' => array( + 'sprintf' => array( + 'format' => '', + 'params' => array( + 'id' => false, + ), ), + 'class' => 'centertext', ), - 'class' => 'centertext', ), ), - ), - 'form' => array( - 'href' => $scripturl . '?action=profile;area=notification;save', - 'include_sort' => true, - 'include_start' => true, - 'hidden_fields' => array( - 'u' => $memID, - 'sa' => $context['menu_item_selected'], - $context['session_var'] => $context['session_id'], + 'form' => array( + 'href' => $scripturl . '?action=profile;area=notification;save', + 'include_sort' => true, + 'include_start' => true, + 'hidden_fields' => array( + 'u' => $memID, + 'sa' => $context['menu_item_selected'], + $context['session_var'] => $context['session_id'], + ), + 'token' => $context['token_check'], ), - 'token' => $context['token_check'], - ), - 'additional_rows' => array( - array( - 'position' => 'bottom_of_list', - 'value' => '', - 'align' => 'right', + 'additional_rows' => array( + array( + 'position' => 'bottom_of_list', + 'value' => '', + 'align' => 'right', + ), ), - ), - ); - - // Create the notification list. - createList($listOptions); - - // What options are set? - $context['member'] += array( - 'notify_announcements' => $user_profile[$memID]['notify_announcements'], - 'notify_send_body' => $user_profile[$memID]['notify_send_body'], - 'notify_types' => $user_profile[$memID]['notify_types'], - 'notify_regularity' => $user_profile[$memID]['notify_regularity'], - ); + ); - loadThemeOptions($memID); -} + // Create the notification list. + createList($listOptions); -/** - * Callback for createList() in action_notification() - * Retrieve topic notifications count. - * - * @param int $memID id_member - * @return string - */ -function list_getTopicNotificationCount($memID) -{ - global $user_info, $modSettings; - - $db = database(); - - $request = $db->query('', ' - SELECT COUNT(*) - FROM {db_prefix}log_notify AS ln' . (!$modSettings['postmod_active'] && $user_info['query_see_board'] === '1=1' ? '' : ' - INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic)') . ($user_info['query_see_board'] === '1=1' ? '' : ' - INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)') . ' - WHERE ln.id_member = {int:selected_member}' . ($user_info['query_see_board'] === '1=1' ? '' : ' - AND {query_see_board}') . ($modSettings['postmod_active'] ? ' - AND t.approved = {int:is_approved}' : ''), - array( - 'selected_member' => $memID, - 'is_approved' => 1, - ) - ); - list ($totalNotifications) = $db->fetch_row($request); - $db->free_result($request); - - // @todo make this an integer before it gets returned - return $totalNotifications; -} - -/** - * Callback for createList() in action_notification() - * - * @param int $start - * @param int $items_per_page - * @param string $sort - * @param int $memID id_member - * @return array $notification_topics - */ -function list_getTopicNotifications($start, $items_per_page, $sort, $memID) -{ - global $scripturl, $user_info, $modSettings; - - $db = database(); - - // All the topics with notification on... - $request = $db->query('', ' - SELECT - IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from, b.id_board, b.name, - t.id_topic, ms.subject, ms.id_member, IFNULL(mem.real_name, ms.poster_name) AS real_name_col, - ml.id_msg_modified, ml.poster_time, ml.id_member AS id_member_updated, - IFNULL(mem2.real_name, ml.poster_name) AS last_real_name - FROM {db_prefix}log_notify AS ln - INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic' . ($modSettings['postmod_active'] ? ' AND t.approved = {int:is_approved}' : '') . ') - INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board}) - INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg) - INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) - LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = ms.id_member) - LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = ml.id_member) - LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member}) - LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member}) - WHERE ln.id_member = {int:selected_member} - ORDER BY {raw:sort} - LIMIT {int:offset}, {int:items_per_page}', - array( - 'current_member' => $user_info['id'], - 'is_approved' => 1, - 'selected_member' => $memID, - 'sort' => $sort, - 'offset' => $start, - 'items_per_page' => $items_per_page, - ) - ); - $notification_topics = array(); - while ($row = $db->fetch_assoc($request)) - { - censorText($row['subject']); - - $notification_topics[] = array( - 'id' => $row['id_topic'], - 'poster_link' => empty($row['id_member']) ? $row['real_name_col'] : '' . $row['real_name_col'] . '', - 'poster_updated_link' => empty($row['id_member_updated']) ? $row['last_real_name'] : '' . $row['last_real_name'] . '', - 'subject' => $row['subject'], - 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0', - 'link' => '' . $row['subject'] . '', - 'new' => $row['new_from'] <= $row['id_msg_modified'], - 'new_from' => $row['new_from'], - 'updated' => relativeTime($row['poster_time']), - 'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new', - 'new_link' => '' . $row['subject'] . '', - 'board_link' => '' . $row['name'] . '', + // What options are set? + $context['member'] += array( + 'notify_announcements' => $user_profile[$memID]['notify_announcements'], + 'notify_send_body' => $user_profile[$memID]['notify_send_body'], + 'notify_types' => $user_profile[$memID]['notify_types'], + 'notify_regularity' => $user_profile[$memID]['notify_regularity'], ); + + loadThemeOptions($memID); } - $db->free_result($request); - return $notification_topics; -} + /** + * Callback for createList() in action_notification() + * Retrieve topic notifications count. + * + * @param int $memID id_member + * @return string + */ + function list_getTopicNotificationCount($memID) + { + global $user_info, $modSettings; -/** - * counts the board notification for a given member - * - * @param int $memID - * @return int - */ -function getBoardNotificationsCount($memID) -{ - global $user_info; - - $db = database(); - - // All the boards that you have notification enabled - $request = $db->query('', ' - SELECT COUNT(*) - FROM {db_prefix}log_notify AS ln - INNER JOIN {db_prefix}boards AS b ON (b.id_board = ln.id_board) - LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member}) - WHERE ln.id_member = {int:selected_member} - AND {query_see_board}', - array( - 'current_member' => $user_info['id'], - 'selected_member' => $memID, - ) - ); - list ($totalNotifications) = $db->fetch_row($request); - $db->free_result($request); - - return $totalNotifications; -} + $db = database(); -/** - * Callback for createList() in action_notification() - * - * @param int $start - * @param int $items_per_page - * @param string $sort - * @param int $memID id_member - * @return array - */ -function list_getBoardNotifications($start, $items_per_page, $sort, $memID) -{ - global $scripturl, $user_info, $modSettings; - - $db = database(); - - // All the boards that you have notification enabled - $request = $db->query('', ' - SELECT b.id_board, b.name, IFNULL(lb.id_msg, 0) AS board_read, b.id_msg_updated - FROM {db_prefix}log_notify AS ln - INNER JOIN {db_prefix}boards AS b ON (b.id_board = ln.id_board) - LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member}) - WHERE ln.id_member = {int:selected_member} - AND {query_see_board} - ORDER BY ' . $sort, - array( - 'current_member' => $user_info['id'], - 'selected_member' => $memID, - ) - ); - - $notification_boards = array(); - while ($row = $db->fetch_assoc($request)) - $notification_boards[] = array( - 'id' => $row['id_board'], - 'name' => $row['name'], - 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', - 'link' => '' .'' . $row['name'] . '', - 'new' => $row['board_read'] < $row['id_msg_updated'], - 'checked' => 'checked="checked"', - ); - $db->free_result($request); - - // and all the boards that you can see but don't have notify turned on for - $request = $db->query('', ' - SELECT b.id_board, b.name, IFNULL(lb.id_msg, 0) AS board_read, b.id_msg_updated - FROM {db_prefix}boards AS b - LEFT JOIN {db_prefix}log_notify AS ln ON (ln.id_board = b.id_board AND ln.id_member = {int:selected_member}) - LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member}) - WHERE {query_see_board} - AND ln.id_board is null ' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' - AND b.id_board != {int:recycle_board}' : '') . ' - ORDER BY ' . $sort, - array( - 'selected_member' => $memID, - 'current_member' => $user_info['id'], - 'recycle_board' => $modSettings['recycle_board'], - ) - ); - while ($row = $db->fetch_assoc($request)) - $notification_boards[] = array( - 'id' => $row['id_board'], - 'name' => $row['name'], - 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', - 'link' => '' . $row['name'] . '', - 'new' => $row['board_read'] < $row['id_msg_updated'], - 'checked' => '', + $request = $db->query('', ' + SELECT COUNT(*) + FROM {db_prefix}log_notify AS ln' . (!$modSettings['postmod_active'] && $user_info['query_see_board'] === '1=1' ? '' : ' + INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic)') . ($user_info['query_see_board'] === '1=1' ? '' : ' + INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)') . ' + WHERE ln.id_member = {int:selected_member}' . ($user_info['query_see_board'] === '1=1' ? '' : ' + AND {query_see_board}') . ($modSettings['postmod_active'] ? ' + AND t.approved = {int:is_approved}' : ''), + array( + 'selected_member' => $memID, + 'is_approved' => 1, + ) ); - $db->free_result($request); - - return $notification_boards; -} + list ($totalNotifications) = $db->fetch_row($request); + $db->free_result($request); -/** - * Load the options for an user. - * - * @param int $memID id_member - */ -function loadThemeOptions($memID) -{ - global $context, $options, $cur_profile; + // @todo make this an integer before it gets returned + return $totalNotifications; + } - $db = database(); + /** + * Callback for createList() in action_notification() + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param int $memID id_member + * @return array $notification_topics + */ + function list_getTopicNotifications($start, $items_per_page, $sort, $memID) + { + global $scripturl, $user_info, $modSettings; - if (isset($_POST['default_options'])) - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; + $db = database(); - if ($context['user']['is_owner']) - { - $context['member']['options'] = $options; - if (isset($_POST['options']) && is_array($_POST['options'])) - foreach ($_POST['options'] as $k => $v) - $context['member']['options'][$k] = $v; - } - else - { + // All the topics with notification on... $request = $db->query('', ' - SELECT id_member, variable, value - FROM {db_prefix}themes - WHERE id_theme IN (1, {int:member_theme}) - AND id_member IN (-1, {int:selected_member})', + SELECT + IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from, b.id_board, b.name, + t.id_topic, ms.subject, ms.id_member, IFNULL(mem.real_name, ms.poster_name) AS real_name_col, + ml.id_msg_modified, ml.poster_time, ml.id_member AS id_member_updated, + IFNULL(mem2.real_name, ml.poster_name) AS last_real_name + FROM {db_prefix}log_notify AS ln + INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic' . ($modSettings['postmod_active'] ? ' AND t.approved = {int:is_approved}' : '') . ') + INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board}) + INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg) + INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) + LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = ms.id_member) + LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = ml.id_member) + LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member}) + LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member}) + WHERE ln.id_member = {int:selected_member} + ORDER BY {raw:sort} + LIMIT {int:offset}, {int:items_per_page}', array( - 'member_theme' => (int) $cur_profile['id_theme'], + 'current_member' => $user_info['id'], + 'is_approved' => 1, 'selected_member' => $memID, + 'sort' => $sort, + 'offset' => $start, + 'items_per_page' => $items_per_page, ) ); - $temp = array(); + $notification_topics = array(); while ($row = $db->fetch_assoc($request)) { - if ($row['id_member'] == -1) - { - $temp[$row['variable']] = $row['value']; - continue; - } - - if (isset($_POST['options'][$row['variable']])) - $row['value'] = $_POST['options'][$row['variable']]; - $context['member']['options'][$row['variable']] = $row['value']; + censorText($row['subject']); + + $notification_topics[] = array( + 'id' => $row['id_topic'], + 'poster_link' => empty($row['id_member']) ? $row['real_name_col'] : '' . $row['real_name_col'] . '', + 'poster_updated_link' => empty($row['id_member_updated']) ? $row['last_real_name'] : '' . $row['last_real_name'] . '', + 'subject' => $row['subject'], + 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0', + 'link' => '' . $row['subject'] . '', + 'new' => $row['new_from'] <= $row['id_msg_modified'], + 'new_from' => $row['new_from'], + 'updated' => relativeTime($row['poster_time']), + 'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new', + 'new_link' => '' . $row['subject'] . '', + 'board_link' => '' . $row['name'] . '', + ); } $db->free_result($request); - // Load up the default theme options for any missing. - foreach ($temp as $k => $v) - { - if (!isset($context['member']['options'][$k])) - $context['member']['options'][$k] = $v; - } + return $notification_topics; } -} - -/** - * Allows the user to see the list of their ignored boards. - * (and un-ignore them) - * - */ -function action_ignoreboards() -{ - global $context, $modSettings, $cur_profile; - - $memID = currentMemberID(); - - // Have the admins enabled this option? - if (empty($modSettings['allow_ignore_boards'])) - fatal_lang_error('ignoreboards_disallowed', 'user'); - loadTemplate('ProfileOptions'); + /** + * Callback for createList() in action_notification() + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param int $memID id_member + * @return array + */ + function list_getBoardNotifications($start, $items_per_page, $sort, $memID) + { + global $scripturl, $user_info, $modSettings; - $context['sub_template'] = 'ignoreboards'; - require_once(SUBSDIR . '/Boards.subs.php'); - $context += getBoardList(array('use_permissions' => true, 'not_redirection' => true, 'ignore' => !empty($cur_profile['ignore_boards']) ? explode(',', $cur_profile['ignore_boards']) : array())); + $db = database(); - // Include a list of boards per category for easy toggling. - foreach ($context['categories'] as &$category) - $category['child_ids'] = array_keys($category['boards']); + // All the boards that you have notification enabled + $request = $db->query('', ' + SELECT b.id_board, b.name, IFNULL(lb.id_msg, 0) AS board_read, b.id_msg_updated + FROM {db_prefix}log_notify AS ln + INNER JOIN {db_prefix}boards AS b ON (b.id_board = ln.id_board) + LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member}) + WHERE ln.id_member = {int:selected_member} + AND {query_see_board} + ORDER BY ' . $sort, + array( + 'current_member' => $user_info['id'], + 'selected_member' => $memID, + ) + ); - loadThemeOptions($memID); -} + $notification_boards = array(); + while ($row = $db->fetch_assoc($request)) + $notification_boards[] = array( + 'id' => $row['id_board'], + 'name' => $row['name'], + 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', + 'link' => '' .'' . $row['name'] . '', + 'new' => $row['board_read'] < $row['id_msg_updated'], + 'checked' => 'checked="checked"', + ); + $db->free_result($request); -/** - * Function to allow the user to choose group membership etc... - * - */ -function action_groupMembership() -{ - global $txt, $user_profile, $context; - - $db = database(); - - $memID = currentMemberID(); - - loadTemplate('ProfileOptions'); - - $curMember = $user_profile[$memID]; - $context['primary_group'] = $curMember['id_group']; - - // Can they manage groups? - $context['can_manage_membergroups'] = allowedTo('manage_membergroups'); - $context['can_manage_protected'] = allowedTo('admin_forum'); - $context['can_edit_primary'] = $context['can_manage_protected']; - $context['update_message'] = isset($_GET['msg']) && isset($txt['group_membership_msg_' . $_GET['msg']]) ? $txt['group_membership_msg_' . $_GET['msg']] : ''; - - // Get all the groups this user is a member of. - $groups = explode(',', $curMember['additional_groups']); - $groups[] = $curMember['id_group']; - - // Ensure the query doesn't croak! - if (empty($groups)) - $groups = array(0); - - // Just to be sure... - foreach ($groups as $k => $v) - $groups[$k] = (int) $v; - - // Get all the membergroups they can join. - $request = $db->query('', ' - SELECT mg.id_group, mg.group_name, mg.description, mg.group_type, mg.online_color, mg.hidden, - IFNULL(lgr.id_member, 0) AS pending - FROM {db_prefix}membergroups AS mg - LEFT JOIN {db_prefix}log_group_requests AS lgr ON (lgr.id_member = {int:selected_member} AND lgr.id_group = mg.id_group) - WHERE (mg.id_group IN ({array_int:group_list}) - OR mg.group_type > {int:nonjoin_group_id}) - AND mg.min_posts = {int:min_posts} - AND mg.id_group != {int:moderator_group} - ORDER BY group_name', - array( - 'group_list' => $groups, - 'selected_member' => $memID, - 'nonjoin_group_id' => 1, - 'min_posts' => -1, - 'moderator_group' => 3, - ) - ); - // This beast will be our group holder. - $context['groups'] = array( - 'member' => array(), - 'available' => array() - ); - while ($row = $db->fetch_assoc($request)) - { - // Can they edit their primary group? - if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) - $context['can_edit_primary'] = true; - - // If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it. - if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) - continue; - - $context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array( - 'id' => $row['id_group'], - 'name' => $row['group_name'], - 'desc' => $row['description'], - 'color' => $row['online_color'], - 'type' => $row['group_type'], - 'pending' => $row['pending'], - 'is_primary' => $row['id_group'] == $context['primary_group'], - 'can_be_primary' => $row['hidden'] != 2, - // Anything more than this needs to be done through account settings for security. - 'can_leave' => $row['id_group'] != 1 && $row['group_type'] > 1 ? true : false, + // and all the boards that you can see but don't have notify turned on for + $request = $db->query('', ' + SELECT b.id_board, b.name, IFNULL(lb.id_msg, 0) AS board_read, b.id_msg_updated + FROM {db_prefix}boards AS b + LEFT JOIN {db_prefix}log_notify AS ln ON (ln.id_board = b.id_board AND ln.id_member = {int:selected_member}) + LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member}) + WHERE {query_see_board} + AND ln.id_board is null ' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' + AND b.id_board != {int:recycle_board}' : '') . ' + ORDER BY ' . $sort, + array( + 'selected_member' => $memID, + 'current_member' => $user_info['id'], + 'recycle_board' => $modSettings['recycle_board'], + ) ); - } - $db->free_result($request); - - // Add registered members on the end. - $context['groups']['member'][0] = array( - 'id' => 0, - 'name' => $txt['regular_members'], - 'desc' => $txt['regular_members_desc'], - 'type' => 0, - 'is_primary' => $context['primary_group'] == 0 ? true : false, - 'can_be_primary' => true, - 'can_leave' => 0, - ); - - // No changing primary one unless you have enough groups! - if (count($context['groups']['member']) < 2) - $context['can_edit_primary'] = false; - - // In the special case that someone is requesting membership of a group, setup some special context vars. - if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) - $context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']]; -} + while ($row = $db->fetch_assoc($request)) + $notification_boards[] = array( + 'id' => $row['id_board'], + 'name' => $row['name'], + 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', + 'link' => '' . $row['name'] . '', + 'new' => $row['board_read'] < $row['id_msg_updated'], + 'checked' => '', + ); + $db->free_result($request); -/** - * This function actually makes all the group changes - * - * @param array $profile_vars - * @param array $post_errors - * @param int $memID id_member - * @return mixed - */ -function action_groupMembership2($profile_vars, $post_errors, $memID) -{ - global $context, $user_profile, $modSettings, $scripturl, $language; + return $notification_boards; + } - $db = database(); + /** + * Allows the user to see the list of their ignored boards. + * (and un-ignore them) + * + */ + public function action_ignoreboards() + { + global $context, $modSettings, $cur_profile; - // Let's be extra cautious... - if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) - isAllowedTo('manage_membergroups'); + $memID = currentMemberID(); - if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) - fatal_lang_error('no_access', false); + // Have the admins enabled this option? + if (empty($modSettings['allow_ignore_boards'])) + fatal_lang_error('ignoreboards_disallowed', 'user'); - checkSession(isset($_GET['gid']) ? 'get' : 'post'); + loadTemplate('ProfileOptions'); - require_once(SUBSDIR . '/Membergroups.subs.php'); + $context['sub_template'] = 'ignoreboards'; + require_once(SUBSDIR . '/Boards.subs.php'); + $context += getBoardList(array('use_permissions' => true, 'not_redirection' => true, 'ignore' => !empty($cur_profile['ignore_boards']) ? explode(',', $cur_profile['ignore_boards']) : array())); - $old_profile = &$user_profile[$memID]; - $context['can_manage_membergroups'] = allowedTo('manage_membergroups'); - $context['can_manage_protected'] = allowedTo('admin_forum'); + // Include a list of boards per category for easy toggling. + foreach ($context['categories'] as &$category) + $category['child_ids'] = array_keys($category['boards']); - // By default the new primary is the old one. - $newPrimary = $old_profile['id_group']; - $addGroups = array_flip(explode(',', $old_profile['additional_groups'])); - $canChangePrimary = $old_profile['id_group'] == 0 ? 1 : 0; - $changeType = isset($_POST['primary']) ? 'primary' : (isset($_POST['req']) ? 'request' : 'free'); + loadThemeOptions($memID); + } - // One way or another, we have a target group in mind... - $group_id = isset($_REQUEST['gid']) ? (int) $_REQUEST['gid'] : (int) $_POST['primary']; - $foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false; + /** + * Function to allow the user to choose group membership etc... + * + */ + public function action_groupMembership() + { + global $txt, $user_profile, $context; - // Sanity check!! - if ($group_id == 1) - isAllowedTo('admin_forum'); + $db = database(); - // What ever we are doing, we need to determine if changing primary is possible! - $groups_details = membergroupsById(array($group_id, $old_profile['id_group']), 0, true); + $memID = currentMemberID(); - // Protected groups require proper permissions! - if ($group_id != 1 && $groups_details[$group_id]['group_type'] == 1) - isAllowedTo('admin_forum'); + loadTemplate('ProfileOptions'); - foreach ($groups_details as $key => $row) - { - // Is this the new group? - if ($row['id_group'] == $group_id) - { - $foundTarget = true; - $group_name = $row['group_name']; - - // Does the group type match what we're doing - are we trying to request a non-requestable group? - if ($changeType == 'request' && $row['group_type'] != 2) - fatal_lang_error('no_access', false); - // What about leaving a requestable group we are not a member of? - elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) - fatal_lang_error('no_access', false); - elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) - fatal_lang_error('no_access', false); - - // We can't change the primary group if this is hidden! - if ($row['hidden'] == 2) - $canChangePrimary = false; - } + $curMember = $user_profile[$memID]; + $context['primary_group'] = $curMember['id_group']; - // If this is their old primary, can we change it? - if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) - $canChangePrimary = 1; + // Can they manage groups? + $context['can_manage_membergroups'] = allowedTo('manage_membergroups'); + $context['can_manage_protected'] = allowedTo('admin_forum'); + $context['can_edit_primary'] = $context['can_manage_protected']; + $context['update_message'] = isset($_GET['msg']) && isset($txt['group_membership_msg_' . $_GET['msg']]) ? $txt['group_membership_msg_' . $_GET['msg']] : ''; - // If we are not doing a force primary move, don't do it automatically if current primary is not 0. - if ($changeType != 'primary' && $old_profile['id_group'] != 0) - $canChangePrimary = false; + // Get all the groups this user is a member of. + $groups = explode(',', $curMember['additional_groups']); + $groups[] = $curMember['id_group']; - // If this is the one we are acting on, can we even act? - if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) - $canChangePrimary = false; - } + // Ensure the query doesn't croak! + if (empty($groups)) + $groups = array(0); - // Didn't find the target? - if (!$foundTarget) - fatal_lang_error('no_access', false); + // Just to be sure... + foreach ($groups as $k => $v) + $groups[$k] = (int) $v; - // Final security check, don't allow users to promote themselves to admin. - if ($context['can_manage_membergroups'] && !allowedTo('admin_forum')) - { + // Get all the membergroups they can join. $request = $db->query('', ' - SELECT COUNT(permission) - FROM {db_prefix}permissions - WHERE id_group = {int:selected_group} - AND permission = {string:admin_forum} - AND add_deny = {int:not_denied}', + SELECT mg.id_group, mg.group_name, mg.description, mg.group_type, mg.online_color, mg.hidden, + IFNULL(lgr.id_member, 0) AS pending + FROM {db_prefix}membergroups AS mg + LEFT JOIN {db_prefix}log_group_requests AS lgr ON (lgr.id_member = {int:selected_member} AND lgr.id_group = mg.id_group) + WHERE (mg.id_group IN ({array_int:group_list}) + OR mg.group_type > {int:nonjoin_group_id}) + AND mg.min_posts = {int:min_posts} + AND mg.id_group != {int:moderator_group} + ORDER BY group_name', array( - 'selected_group' => $group_id, - 'not_denied' => 1, - 'admin_forum' => 'admin_forum', + 'group_list' => $groups, + 'selected_member' => $memID, + 'nonjoin_group_id' => 1, + 'min_posts' => -1, + 'moderator_group' => 3, ) ); - list ($disallow) = $db->fetch_row($request); + // This beast will be our group holder. + $context['groups'] = array( + 'member' => array(), + 'available' => array() + ); + while ($row = $db->fetch_assoc($request)) + { + // Can they edit their primary group? + if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) + $context['can_edit_primary'] = true; + + // If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it. + if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) + continue; + + $context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array( + 'id' => $row['id_group'], + 'name' => $row['group_name'], + 'desc' => $row['description'], + 'color' => $row['online_color'], + 'type' => $row['group_type'], + 'pending' => $row['pending'], + 'is_primary' => $row['id_group'] == $context['primary_group'], + 'can_be_primary' => $row['hidden'] != 2, + // Anything more than this needs to be done through account settings for security. + 'can_leave' => $row['id_group'] != 1 && $row['group_type'] > 1 ? true : false, + ); + } $db->free_result($request); - if ($disallow) - isAllowedTo('admin_forum'); + // Add registered members on the end. + $context['groups']['member'][0] = array( + 'id' => 0, + 'name' => $txt['regular_members'], + 'desc' => $txt['regular_members_desc'], + 'type' => 0, + 'is_primary' => $context['primary_group'] == 0 ? true : false, + 'can_be_primary' => true, + 'can_leave' => 0, + ); + + // No changing primary one unless you have enough groups! + if (count($context['groups']['member']) < 2) + $context['can_edit_primary'] = false; + + // In the special case that someone is requesting membership of a group, setup some special context vars. + if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) + $context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']]; } - // If we're requesting, add the note then return. - if ($changeType == 'request') + /** + * This function actually makes all the group changes + * + * @param array $profile_vars + * @param array $post_errors + * @param int $memID id_member + * @return mixed + */ + function action_groupMembership2($profile_vars, $post_errors, $memID) { - $request = $db->query('', ' - SELECT id_member - FROM {db_prefix}log_group_requests - WHERE id_member = {int:selected_member} - AND id_group = {int:selected_group}', - array( - 'selected_member' => $memID, - 'selected_group' => $group_id, - ) - ); - if ($db->num_rows($request) != 0) - fatal_lang_error('profile_error_already_requested_group'); - $db->free_result($request); + global $context, $user_profile, $modSettings, $scripturl, $language; - // Log the request. - $db->insert('', - '{db_prefix}log_group_requests', - array( - 'id_member' => 'int', 'id_group' => 'int', 'time_applied' => 'int', 'reason' => 'string-65534', - ), - array( - $memID, $group_id, time(), $_POST['reason'], - ), - array('id_request') - ); + $db = database(); - // Send an email to all group moderators etc. - require_once(SUBSDIR . '/Mail.subs.php'); + // Let's be extra cautious... + if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) + isAllowedTo('manage_membergroups'); - // Do we have any group moderators? - $request = $db->query('', ' - SELECT id_member - FROM {db_prefix}group_moderators - WHERE id_group = {int:selected_group}', - array( - 'selected_group' => $group_id, - ) - ); - $moderators = array(); - while ($row = $db->fetch_assoc($request)) - $moderators[] = $row['id_member']; - $db->free_result($request); + if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) + fatal_lang_error('no_access', false); - // Otherwise this is the backup! - if (empty($moderators)) + checkSession(isset($_GET['gid']) ? 'get' : 'post'); + + require_once(SUBSDIR . '/Membergroups.subs.php'); + + $old_profile = &$user_profile[$memID]; + $context['can_manage_membergroups'] = allowedTo('manage_membergroups'); + $context['can_manage_protected'] = allowedTo('admin_forum'); + + // By default the new primary is the old one. + $newPrimary = $old_profile['id_group']; + $addGroups = array_flip(explode(',', $old_profile['additional_groups'])); + $canChangePrimary = $old_profile['id_group'] == 0 ? 1 : 0; + $changeType = isset($_POST['primary']) ? 'primary' : (isset($_POST['req']) ? 'request' : 'free'); + + // One way or another, we have a target group in mind... + $group_id = isset($_REQUEST['gid']) ? (int) $_REQUEST['gid'] : (int) $_POST['primary']; + $foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false; + + // Sanity check!! + if ($group_id == 1) + isAllowedTo('admin_forum'); + + // What ever we are doing, we need to determine if changing primary is possible! + $groups_details = membergroupsById(array($group_id, $old_profile['id_group']), 0, true); + + // Protected groups require proper permissions! + if ($group_id != 1 && $groups_details[$group_id]['group_type'] == 1) + isAllowedTo('admin_forum'); + + foreach ($groups_details as $key => $row) { - require_once(SUBSDIR . '/Members.subs.php'); - $moderators = membersAllowedTo('manage_membergroups'); + // Is this the new group? + if ($row['id_group'] == $group_id) + { + $foundTarget = true; + $group_name = $row['group_name']; + + // Does the group type match what we're doing - are we trying to request a non-requestable group? + if ($changeType == 'request' && $row['group_type'] != 2) + fatal_lang_error('no_access', false); + // What about leaving a requestable group we are not a member of? + elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) + fatal_lang_error('no_access', false); + elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) + fatal_lang_error('no_access', false); + + // We can't change the primary group if this is hidden! + if ($row['hidden'] == 2) + $canChangePrimary = false; + } + + // If this is their old primary, can we change it? + if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) + $canChangePrimary = 1; + + // If we are not doing a force primary move, don't do it automatically if current primary is not 0. + if ($changeType != 'primary' && $old_profile['id_group'] != 0) + $canChangePrimary = false; + + // If this is the one we are acting on, can we even act? + if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) + $canChangePrimary = false; } - if (!empty($moderators)) + // Didn't find the target? + if (!$foundTarget) + fatal_lang_error('no_access', false); + + // Final security check, don't allow users to promote themselves to admin. + if ($context['can_manage_membergroups'] && !allowedTo('admin_forum')) { - require_once(SUBSDIR . '/Members.subs.php'); - $members = getBasicMemberData($moderators, array('preferences' => true, 'sort' => 'lngfile')); + $request = $db->query('', ' + SELECT COUNT(permission) + FROM {db_prefix}permissions + WHERE id_group = {int:selected_group} + AND permission = {string:admin_forum} + AND add_deny = {int:not_denied}', + array( + 'selected_group' => $group_id, + 'not_denied' => 1, + 'admin_forum' => 'admin_forum', + ) + ); + list ($disallow) = $db->fetch_row($request); + $db->free_result($request); + + if ($disallow) + isAllowedTo('admin_forum'); + } - foreach ($members as $member) + // If we're requesting, add the note then return. + if ($changeType == 'request') + { + $request = $db->query('', ' + SELECT id_member + FROM {db_prefix}log_group_requests + WHERE id_member = {int:selected_member} + AND id_group = {int:selected_group}', + array( + 'selected_member' => $memID, + 'selected_group' => $group_id, + ) + ); + if ($db->num_rows($request) != 0) + fatal_lang_error('profile_error_already_requested_group'); + $db->free_result($request); + + // Log the request. + $db->insert('', + '{db_prefix}log_group_requests', + array( + 'id_member' => 'int', 'id_group' => 'int', 'time_applied' => 'int', 'reason' => 'string-65534', + ), + array( + $memID, $group_id, time(), $_POST['reason'], + ), + array('id_request') + ); + + // Send an email to all group moderators etc. + require_once(SUBSDIR . '/Mail.subs.php'); + + // Do we have any group moderators? + $request = $db->query('', ' + SELECT id_member + FROM {db_prefix}group_moderators + WHERE id_group = {int:selected_group}', + array( + 'selected_group' => $group_id, + ) + ); + $moderators = array(); + while ($row = $db->fetch_assoc($request)) + $moderators[] = $row['id_member']; + $db->free_result($request); + + // Otherwise this is the backup! + if (empty($moderators)) { - if ($member['notify_types'] != 4) - continue; + require_once(SUBSDIR . '/Members.subs.php'); + $moderators = membersAllowedTo('manage_membergroups'); + } - // Check whether they are interested. - if (!empty($member['mod_prefs'])) + if (!empty($moderators)) + { + require_once(SUBSDIR . '/Members.subs.php'); + $members = getBasicMemberData($moderators, array('preferences' => true, 'sort' => 'lngfile')); + + foreach ($members as $member) { - list(,, $pref_binary) = explode('|', $member['mod_prefs']); - if (!($pref_binary & 4)) + if ($member['notify_types'] != 4) continue; - } - $replacements = array( - 'RECPNAME' => $member['member_name'], - 'APPYNAME' => $old_profile['member_name'], - 'GROUPNAME' => $group_name, - 'REASON' => $_POST['reason'], - 'MODLINK' => $scripturl . '?action=moderate;area=groups;sa=requests', - ); + // Check whether they are interested. + if (!empty($member['mod_prefs'])) + { + list(,, $pref_binary) = explode('|', $member['mod_prefs']); + if (!($pref_binary & 4)) + continue; + } + + $replacements = array( + 'RECPNAME' => $member['member_name'], + 'APPYNAME' => $old_profile['member_name'], + 'GROUPNAME' => $group_name, + 'REASON' => $_POST['reason'], + 'MODLINK' => $scripturl . '?action=moderate;area=groups;sa=requests', + ); + + $emaildata = loadEmailTemplate('request_membership', $replacements, empty($member['lngfile']) || empty($modSettings['userLanguage']) ? $language : $member['lngfile']); + sendmail($member['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 2); + } + } - $emaildata = loadEmailTemplate('request_membership', $replacements, empty($member['lngfile']) || empty($modSettings['userLanguage']) ? $language : $member['lngfile']); - sendmail($member['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 2); + return $changeType; + } + // Otherwise we are leaving/joining a group. + elseif ($changeType == 'free') + { + // Are we leaving? + if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id])) + { + if ($old_profile['id_group'] == $group_id) + $newPrimary = 0; + else + unset($addGroups[$group_id]); + } + // ... if not, must be joining. + else + { + // Can we change the primary, and do we want to? + if ($canChangePrimary) + { + if ($old_profile['id_group'] != 0) + $addGroups[$old_profile['id_group']] = -1; + $newPrimary = $group_id; + } + // Otherwise it's an additional group... + else + $addGroups[$group_id] = -1; } } + // Finally, we must be setting the primary. + elseif ($canChangePrimary) + { + if ($old_profile['id_group'] != 0) + $addGroups[$old_profile['id_group']] = -1; + if (isset($addGroups[$group_id])) + unset($addGroups[$group_id]); + $newPrimary = $group_id; + } + + // Finally, we can make the changes! + foreach ($addGroups as $id => $dummy) + { + if (empty($id)) + unset($addGroups[$id]); + } + $addGroups = implode(',', array_flip($addGroups)); + + // Ensure that we don't cache permissions if the group is changing. + if ($context['user']['is_owner']) + $_SESSION['mc']['time'] = 0; + else + updateSettings(array('settings_updated' => time())); + + updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups)); return $changeType; } - // Otherwise we are leaving/joining a group. - elseif ($changeType == 'free') + + /** + * Load the options for an user. + * + * @param int $memID id_member + */ + function loadThemeOptions($memID) { - // Are we leaving? - if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id])) + global $context, $options, $cur_profile; + + $db = database(); + + if (isset($_POST['default_options'])) + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; + + if ($context['user']['is_owner']) { - if ($old_profile['id_group'] == $group_id) - $newPrimary = 0; - else - unset($addGroups[$group_id]); + $context['member']['options'] = $options; + if (isset($_POST['options']) && is_array($_POST['options'])) + foreach ($_POST['options'] as $k => $v) + $context['member']['options'][$k] = $v; } - // ... if not, must be joining. else { - // Can we change the primary, and do we want to? - if ($canChangePrimary) + $request = $db->query('', ' + SELECT id_member, variable, value + FROM {db_prefix}themes + WHERE id_theme IN (1, {int:member_theme}) + AND id_member IN (-1, {int:selected_member})', + array( + 'member_theme' => (int) $cur_profile['id_theme'], + 'selected_member' => $memID, + ) + ); + $temp = array(); + while ($row = $db->fetch_assoc($request)) + { + if ($row['id_member'] == -1) + { + $temp[$row['variable']] = $row['value']; + continue; + } + + if (isset($_POST['options'][$row['variable']])) + $row['value'] = $_POST['options'][$row['variable']]; + $context['member']['options'][$row['variable']] = $row['value']; + } + $db->free_result($request); + + // Load up the default theme options for any missing. + foreach ($temp as $k => $v) { - if ($old_profile['id_group'] != 0) - $addGroups[$old_profile['id_group']] = -1; - $newPrimary = $group_id; + if (!isset($context['member']['options'][$k])) + $context['member']['options'][$k] = $v; } - // Otherwise it's an additional group... - else - $addGroups[$group_id] = -1; } } - // Finally, we must be setting the primary. - elseif ($canChangePrimary) - { - if ($old_profile['id_group'] != 0) - $addGroups[$old_profile['id_group']] = -1; - if (isset($addGroups[$group_id])) - unset($addGroups[$group_id]); - $newPrimary = $group_id; - } - - // Finally, we can make the changes! - foreach ($addGroups as $id => $dummy) - { - if (empty($id)) - unset($addGroups[$id]); - } - $addGroups = implode(',', array_flip($addGroups)); - - // Ensure that we don't cache permissions if the group is changing. - if ($context['user']['is_owner']) - $_SESSION['mc']['time'] = 0; - else - updateSettings(array('settings_updated' => time())); - - updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups)); - - return $changeType; } \ No newline at end of file diff --git a/sources/subs/Boards.subs.php b/sources/subs/Boards.subs.php index fff8333744..cbaefb2a3f 100644 --- a/sources/subs/Boards.subs.php +++ b/sources/subs/Boards.subs.php @@ -1197,6 +1197,37 @@ function resetSentBoardNotification($id_member, $id_board, $check = true) return true; } +/** + * Counts the board notification for a given member. + * + * @param int $memID + * @return int + */ +function getBoardNotificationsCount($memID) +{ + global $user_info; + + $db = database(); + + // All the boards that you have notification enabled + $request = $db->query('', ' + SELECT COUNT(*) + FROM {db_prefix}log_notify AS ln + INNER JOIN {db_prefix}boards AS b ON (b.id_board = ln.id_board) + LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member}) + WHERE ln.id_member = {int:selected_member} + AND {query_see_board}', + array( + 'current_member' => $user_info['id'], + 'selected_member' => $memID, + ) + ); + list ($totalNotifications) = $db->fetch_row($request); + $db->free_result($request); + + return $totalNotifications; +} + /** * Returns all the boards accessible to the current user. * If $id_parents is given, return only the child boards of those boards. From 60a26436b8052a346396f39e2989cc405f9da9b1 Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 14:42:13 +0300 Subject: [PATCH 17/34] Rework the list_ callbacks for ProfileOptions controller: utility functions in subs (boards and topic... we don't have notifications subs?), and list_ methods in controller. Signed-off-by: Norv --- .../controllers/ProfileOptions.controller.php | 245 +++++------------- sources/subs/Boards.subs.php | 75 ++++++ sources/subs/Topic.subs.php | 103 +++++++- 3 files changed, 235 insertions(+), 188 deletions(-) diff --git a/sources/controllers/ProfileOptions.controller.php b/sources/controllers/ProfileOptions.controller.php index 08f9ab8dd2..3301822ee5 100644 --- a/sources/controllers/ProfileOptions.controller.php +++ b/sources/controllers/ProfileOptions.controller.php @@ -523,6 +523,7 @@ public function action_notification() // Gonna want this for the list. require_once(SUBSDIR . '/List.subs.php'); require_once(SUBSDIR . '/Boards.subs.php'); + require_once(SUBSDIR . '/Topic.subs.php'); // Fine, start with the board list. $listOptions = array( @@ -533,7 +534,7 @@ public function action_notification() 'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification', 'default_sort_col' => 'board_name', 'get_items' => array( - 'function' => 'list_getBoardNotifications', + 'function' => array($this, 'list_getBoardNotifications'), 'params' => array( $memID, ), @@ -616,13 +617,13 @@ public function action_notification() 'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification', 'default_sort_col' => 'last_post', 'get_items' => array( - 'function' => 'list_getTopicNotifications', + 'function' => array($this, 'list_getTopicNotifications'), 'params' => array( $memID, ), ), 'get_count' => array( - 'function' => 'list_getTopicNotificationCount', + 'function' => array($this, 'list_getTopicNotificationCount'), 'params' => array( $memID, ), @@ -744,28 +745,8 @@ public function action_notification() */ function list_getTopicNotificationCount($memID) { - global $user_info, $modSettings; - - $db = database(); - - $request = $db->query('', ' - SELECT COUNT(*) - FROM {db_prefix}log_notify AS ln' . (!$modSettings['postmod_active'] && $user_info['query_see_board'] === '1=1' ? '' : ' - INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic)') . ($user_info['query_see_board'] === '1=1' ? '' : ' - INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)') . ' - WHERE ln.id_member = {int:selected_member}' . ($user_info['query_see_board'] === '1=1' ? '' : ' - AND {query_see_board}') . ($modSettings['postmod_active'] ? ' - AND t.approved = {int:is_approved}' : ''), - array( - 'selected_member' => $memID, - 'is_approved' => 1, - ) - ); - list ($totalNotifications) = $db->fetch_row($request); - $db->free_result($request); - - // @todo make this an integer before it gets returned - return $totalNotifications; + // topic notifications count, for the list + return topicNotificationCount($memID); } /** @@ -775,65 +756,12 @@ function list_getTopicNotificationCount($memID) * @param int $items_per_page * @param string $sort * @param int $memID id_member - * @return array $notification_topics + * @return array */ function list_getTopicNotifications($start, $items_per_page, $sort, $memID) { - global $scripturl, $user_info, $modSettings; - - $db = database(); - - // All the topics with notification on... - $request = $db->query('', ' - SELECT - IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from, b.id_board, b.name, - t.id_topic, ms.subject, ms.id_member, IFNULL(mem.real_name, ms.poster_name) AS real_name_col, - ml.id_msg_modified, ml.poster_time, ml.id_member AS id_member_updated, - IFNULL(mem2.real_name, ml.poster_name) AS last_real_name - FROM {db_prefix}log_notify AS ln - INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic' . ($modSettings['postmod_active'] ? ' AND t.approved = {int:is_approved}' : '') . ') - INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board}) - INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg) - INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) - LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = ms.id_member) - LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = ml.id_member) - LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member}) - LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member}) - WHERE ln.id_member = {int:selected_member} - ORDER BY {raw:sort} - LIMIT {int:offset}, {int:items_per_page}', - array( - 'current_member' => $user_info['id'], - 'is_approved' => 1, - 'selected_member' => $memID, - 'sort' => $sort, - 'offset' => $start, - 'items_per_page' => $items_per_page, - ) - ); - $notification_topics = array(); - while ($row = $db->fetch_assoc($request)) - { - censorText($row['subject']); - - $notification_topics[] = array( - 'id' => $row['id_topic'], - 'poster_link' => empty($row['id_member']) ? $row['real_name_col'] : '' . $row['real_name_col'] . '', - 'poster_updated_link' => empty($row['id_member_updated']) ? $row['last_real_name'] : '' . $row['last_real_name'] . '', - 'subject' => $row['subject'], - 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0', - 'link' => '' . $row['subject'] . '', - 'new' => $row['new_from'] <= $row['id_msg_modified'], - 'new_from' => $row['new_from'], - 'updated' => relativeTime($row['poster_time']), - 'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new', - 'new_link' => '' . $row['subject'] . '', - 'board_link' => '' . $row['name'] . '', - ); - } - $db->free_result($request); - - return $notification_topics; + // topic notifications, for the list + return topicNotifications($start, $items_per_page, $sort, $memID); } /** @@ -847,65 +775,8 @@ function list_getTopicNotifications($start, $items_per_page, $sort, $memID) */ function list_getBoardNotifications($start, $items_per_page, $sort, $memID) { - global $scripturl, $user_info, $modSettings; - - $db = database(); - - // All the boards that you have notification enabled - $request = $db->query('', ' - SELECT b.id_board, b.name, IFNULL(lb.id_msg, 0) AS board_read, b.id_msg_updated - FROM {db_prefix}log_notify AS ln - INNER JOIN {db_prefix}boards AS b ON (b.id_board = ln.id_board) - LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member}) - WHERE ln.id_member = {int:selected_member} - AND {query_see_board} - ORDER BY ' . $sort, - array( - 'current_member' => $user_info['id'], - 'selected_member' => $memID, - ) - ); - - $notification_boards = array(); - while ($row = $db->fetch_assoc($request)) - $notification_boards[] = array( - 'id' => $row['id_board'], - 'name' => $row['name'], - 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', - 'link' => '' .'' . $row['name'] . '', - 'new' => $row['board_read'] < $row['id_msg_updated'], - 'checked' => 'checked="checked"', - ); - $db->free_result($request); - - // and all the boards that you can see but don't have notify turned on for - $request = $db->query('', ' - SELECT b.id_board, b.name, IFNULL(lb.id_msg, 0) AS board_read, b.id_msg_updated - FROM {db_prefix}boards AS b - LEFT JOIN {db_prefix}log_notify AS ln ON (ln.id_board = b.id_board AND ln.id_member = {int:selected_member}) - LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member}) - WHERE {query_see_board} - AND ln.id_board is null ' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' - AND b.id_board != {int:recycle_board}' : '') . ' - ORDER BY ' . $sort, - array( - 'selected_member' => $memID, - 'current_member' => $user_info['id'], - 'recycle_board' => $modSettings['recycle_board'], - ) - ); - while ($row = $db->fetch_assoc($request)) - $notification_boards[] = array( - 'id' => $row['id_board'], - 'name' => $row['name'], - 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', - 'link' => '' . $row['name'] . '', - 'new' => $row['board_read'] < $row['id_msg_updated'], - 'checked' => '', - ); - $db->free_result($request); - - return $notification_boards; + // return boards you see and their notification status for the list + return boardNotifications($start, $items_per_page, $sort, $memID); } /** @@ -1291,61 +1162,61 @@ function action_groupMembership2($profile_vars, $post_errors, $memID) return $changeType; } +} - /** - * Load the options for an user. - * - * @param int $memID id_member - */ - function loadThemeOptions($memID) - { - global $context, $options, $cur_profile; +/** + * Load the options for an user. + * + * @param int $memID id_member + */ +function loadThemeOptions($memID) +{ + global $context, $options, $cur_profile; - $db = database(); + $db = database(); - if (isset($_POST['default_options'])) - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; + if (isset($_POST['default_options'])) + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; - if ($context['user']['is_owner']) - { - $context['member']['options'] = $options; - if (isset($_POST['options']) && is_array($_POST['options'])) - foreach ($_POST['options'] as $k => $v) - $context['member']['options'][$k] = $v; - } - else + if ($context['user']['is_owner']) + { + $context['member']['options'] = $options; + if (isset($_POST['options']) && is_array($_POST['options'])) + foreach ($_POST['options'] as $k => $v) + $context['member']['options'][$k] = $v; + } + else + { + $request = $db->query('', ' + SELECT id_member, variable, value + FROM {db_prefix}themes + WHERE id_theme IN (1, {int:member_theme}) + AND id_member IN (-1, {int:selected_member})', + array( + 'member_theme' => (int) $cur_profile['id_theme'], + 'selected_member' => $memID, + ) + ); + $temp = array(); + while ($row = $db->fetch_assoc($request)) { - $request = $db->query('', ' - SELECT id_member, variable, value - FROM {db_prefix}themes - WHERE id_theme IN (1, {int:member_theme}) - AND id_member IN (-1, {int:selected_member})', - array( - 'member_theme' => (int) $cur_profile['id_theme'], - 'selected_member' => $memID, - ) - ); - $temp = array(); - while ($row = $db->fetch_assoc($request)) + if ($row['id_member'] == -1) { - if ($row['id_member'] == -1) - { - $temp[$row['variable']] = $row['value']; - continue; - } - - if (isset($_POST['options'][$row['variable']])) - $row['value'] = $_POST['options'][$row['variable']]; - $context['member']['options'][$row['variable']] = $row['value']; + $temp[$row['variable']] = $row['value']; + continue; } - $db->free_result($request); - // Load up the default theme options for any missing. - foreach ($temp as $k => $v) - { - if (!isset($context['member']['options'][$k])) - $context['member']['options'][$k] = $v; - } + if (isset($_POST['options'][$row['variable']])) + $row['value'] = $_POST['options'][$row['variable']]; + $context['member']['options'][$row['variable']] = $row['value']; + } + $db->free_result($request); + + // Load up the default theme options for any missing. + foreach ($temp as $k => $v) + { + if (!isset($context['member']['options'][$k])) + $context['member']['options'][$k] = $v; } } } \ No newline at end of file diff --git a/sources/subs/Boards.subs.php b/sources/subs/Boards.subs.php index cbaefb2a3f..10f670862b 100644 --- a/sources/subs/Boards.subs.php +++ b/sources/subs/Boards.subs.php @@ -1725,3 +1725,78 @@ function incrementBoard($board, $stat) ) ); } + +/** + * Retrieve all the boards the user can see, + * and their notification status: if they're subscribed + * to notifications for new topics in each of them or they're not. + * (used by createList() callbacks) + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param int $memID id_member + * @return array + */ +function boardNotifications($start, $items_per_page, $sort, $memID) +{ + global $scripturl, $user_info, $modSettings; + + $db = database(); + + // All the boards that you have notification enabled + $request = $db->query('', ' + SELECT b.id_board, b.name, IFNULL(lb.id_msg, 0) AS board_read, b.id_msg_updated + FROM {db_prefix}log_notify AS ln + INNER JOIN {db_prefix}boards AS b ON (b.id_board = ln.id_board) + LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member}) + WHERE ln.id_member = {int:selected_member} + AND {query_see_board} + ORDER BY ' . $sort, + array( + 'current_member' => $user_info['id'], + 'selected_member' => $memID, + ) + ); + + $notification_boards = array(); + while ($row = $db->fetch_assoc($request)) + $notification_boards[] = array( + 'id' => $row['id_board'], + 'name' => $row['name'], + 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', + 'link' => '' .'' . $row['name'] . '', + 'new' => $row['board_read'] < $row['id_msg_updated'], + 'checked' => 'checked="checked"', + ); + $db->free_result($request); + + // and all the boards that you can see but don't have notify turned on for + $request = $db->query('', ' + SELECT b.id_board, b.name, IFNULL(lb.id_msg, 0) AS board_read, b.id_msg_updated + FROM {db_prefix}boards AS b + LEFT JOIN {db_prefix}log_notify AS ln ON (ln.id_board = b.id_board AND ln.id_member = {int:selected_member}) + LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member}) + WHERE {query_see_board} + AND ln.id_board is null ' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' + AND b.id_board != {int:recycle_board}' : '') . ' + ORDER BY ' . $sort, + array( + 'selected_member' => $memID, + 'current_member' => $user_info['id'], + 'recycle_board' => $modSettings['recycle_board'], + ) + ); + while ($row = $db->fetch_assoc($request)) + $notification_boards[] = array( + 'id' => $row['id_board'], + 'name' => $row['name'], + 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', + 'link' => '' . $row['name'] . '', + 'new' => $row['board_read'] < $row['id_msg_updated'], + 'checked' => '', + ); + $db->free_result($request); + + return $notification_boards; +} \ No newline at end of file diff --git a/sources/subs/Topic.subs.php b/sources/subs/Topic.subs.php index 9615b56465..cba01558b7 100644 --- a/sources/subs/Topic.subs.php +++ b/sources/subs/Topic.subs.php @@ -424,7 +424,7 @@ function moveTopics($topics, $toBoard) // Only a single topic. if (is_numeric($topics)) $topics = array($topics); - + $fromBoards = array(); // Destination board empty or equal to 0? @@ -2308,3 +2308,104 @@ function splitDestinationBoard() return array('current' => $current_board, 'destination' => $destination_board); } + +/** + * Retrieve topic notifications count. + * (used by createList() callbacks, amongst others.) + * + * @param int $memID id_member + * @return string + */ +function topicNotificationCount($memID) +{ + global $user_info, $modSettings; + + $db = database(); + + $request = $db->query('', ' + SELECT COUNT(*) + FROM {db_prefix}log_notify AS ln' . (!$modSettings['postmod_active'] && $user_info['query_see_board'] === '1=1' ? '' : ' + INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic)') . ($user_info['query_see_board'] === '1=1' ? '' : ' + INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)') . ' + WHERE ln.id_member = {int:selected_member}' . ($user_info['query_see_board'] === '1=1' ? '' : ' + AND {query_see_board}') . ($modSettings['postmod_active'] ? ' + AND t.approved = {int:is_approved}' : ''), + array( + 'selected_member' => $memID, + 'is_approved' => 1, + ) + ); + list ($totalNotifications) = $db->fetch_row($request); + $db->free_result($request); + + return (int)$totalNotifications; +} + +/** + * Retrieve all topic notifications for the given user. + * (used by createList() callbacks) + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param int $memID id_member + * @return array + */ +function topicNotifications($start, $items_per_page, $sort, $memID) +{ + global $scripturl, $user_info, $modSettings; + + $db = database(); + + // All the topics with notification on... + $request = $db->query('', ' + SELECT + IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from, b.id_board, b.name, + t.id_topic, ms.subject, ms.id_member, IFNULL(mem.real_name, ms.poster_name) AS real_name_col, + ml.id_msg_modified, ml.poster_time, ml.id_member AS id_member_updated, + IFNULL(mem2.real_name, ml.poster_name) AS last_real_name + FROM {db_prefix}log_notify AS ln + INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic' . ($modSettings['postmod_active'] ? ' AND t.approved = {int:is_approved}' : '') . ') + INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board}) + INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg) + INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) + LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = ms.id_member) + LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = ml.id_member) + LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member}) + LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member}) + WHERE ln.id_member = {int:selected_member} + ORDER BY {raw:sort} + LIMIT {int:offset}, {int:items_per_page}', + array( + 'current_member' => $user_info['id'], + 'is_approved' => 1, + 'selected_member' => $memID, + 'sort' => $sort, + 'offset' => $start, + 'items_per_page' => $items_per_page, + ) + ); + $notification_topics = array(); + while ($row = $db->fetch_assoc($request)) + { + censorText($row['subject']); + + $notification_topics[] = array( + 'id' => $row['id_topic'], + 'poster_link' => empty($row['id_member']) ? $row['real_name_col'] : '' . $row['real_name_col'] . '', + 'poster_updated_link' => empty($row['id_member_updated']) ? $row['last_real_name'] : '' . $row['last_real_name'] . '', + 'subject' => $row['subject'], + 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0', + 'link' => '' . $row['subject'] . '', + 'new' => $row['new_from'] <= $row['id_msg_modified'], + 'new_from' => $row['new_from'], + 'updated' => relativeTime($row['poster_time']), + 'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new', + 'new_link' => '' . $row['subject'] . '', + 'board_link' => '' . $row['name'] . '', + ); + } + $db->free_result($request); + + return $notification_topics; +} \ No newline at end of file From 805f16c2eb80234a712fe49c0bcafc0bc7557356 Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 15:02:36 +0300 Subject: [PATCH 18/34] Rework Xml requests: XmlPreview controller handles previews. Xml controller, the rest of xmlhttp. Signed-off-by: Norv --- sources/Dispatcher.class.php | 3 +- sources/admin/ManageNews.php | 2 +- sources/controllers/Xml.controller.php | 619 +++++------------- sources/controllers/Xmlpreview.controller.php | 320 +++++++++ themes/default/Maillist.template.php | 2 +- themes/default/ModerationCenter.template.php | 2 +- themes/default/ProfileAccount.template.php | 2 +- themes/default/scripts/post.js | 2 +- themes/default/scripts/profile.js | 2 +- 9 files changed, 482 insertions(+), 472 deletions(-) create mode 100644 sources/controllers/Xmlpreview.controller.php diff --git a/sources/Dispatcher.class.php b/sources/Dispatcher.class.php index afa21b2c5c..3bb160bda5 100644 --- a/sources/Dispatcher.class.php +++ b/sources/Dispatcher.class.php @@ -192,7 +192,8 @@ public function __construct() 'viewquery' => array('AdminDebug.php', 'AdminDebug_Controller', 'action_viewquery'), 'viewadminfile' => array('AdminDebug.php', 'AdminDebug_Controller', 'action_viewadminfile'), '.xml' => array('News.controller.php', 'News_Controller', 'action_showfeed'), - 'xmlhttp' => array('Xml.controller.php', 'action_xmlhttp'), + 'xmlhttp' => array('Xml.controller.php', 'Xml_Controller', 'action_index'), + 'xmlpreview' => array('Xmlpreview.controller.php', 'XmlPreview_Controller', 'action_index'), ); $adminActions = array ('admin', 'attachapprove', 'jsoption', 'theme', 'viewadminfile', 'viewquery'); diff --git a/sources/admin/ManageNews.php b/sources/admin/ManageNews.php index b701d51dfe..381bd94afe 100644 --- a/sources/admin/ManageNews.php +++ b/sources/admin/ManageNews.php @@ -257,7 +257,7 @@ function make_preview_btn (preview_id) $("#preview_" + preview_id).text(\'' . $txt['preview'] . '\').click(function () { $.ajax({ type: "POST", - url: "' . $scripturl . '?action=xmlhttp;sa=previews;xml", + url: "' . $scripturl . '?action=xmlpreview;xml", data: {item: "newspreview", news: $("#data_" + preview_id).val()}, context: document.body, success: function(request){ diff --git a/sources/controllers/Xml.controller.php b/sources/controllers/Xml.controller.php index 390dacf6d4..b4989e7402 100644 --- a/sources/controllers/Xml.controller.php +++ b/sources/controllers/Xml.controller.php @@ -5,519 +5,208 @@ * @copyright ElkArte Forum contributors * @license BSD http://opensource.org/licenses/BSD-3-Clause * - * This software is a derived product, based on: - * - * Simple Machines Forum (SMF) - * copyright: 2011 Simple Machines (http://www.simplemachines.org) - * license: BSD, See included LICENSE.TXT for terms and conditions. - * * @version 1.0 Alpha - * - * Maintains all XML-based interaction (mainly XMLhttp) - * */ if (!defined('ELKARTE')) die('No access...'); /** - * Main function for action=xmlhttp. + * Xml controller receives XMLhttp requests of various types. + * (jump to, message and group icons, core features) */ -function action_xmlhttp() +class Xml_Controller { - loadTemplate('Xml'); - - $subActions = array( - 'jumpto' => array('action_jumpto'), - 'messageicons' => array('action_messageicons'), - 'groupicons' => array('action_groupicons'), - 'corefeatures' => array('action_corefeatures', 'admin_forum'), - 'previews' => array('action_previews'), - ); - - // Easy adding of xml sub actions - call_integration_hook('integrate_xmlhttp', array(&$subActions)); - - // Valid action? - if (!isset($_REQUEST['sa'], $subActions[$_REQUEST['sa']])) - fatal_lang_error('no_access', false); - - // Permissions check in the subAction? - if (isset($subActions[$_REQUEST['sa']][1])) - isAllowedTo($subActions[$_REQUEST['sa']][1]); - - // Off we go then - $subActions[$_REQUEST['sa']][0](); -} - -/** - * Get a list of boards and categories used for the jumpto dropdown. - */ -function action_jumpto() -{ - global $context; - - // Find the boards/categories they can see. - require_once(SUBSDIR . '/Boards.subs.php'); - $boardListOptions = array( - 'use_permissions' => true, - 'selected_board' => isset($context['current_board']) ? $context['current_board'] : 0, - ); - $context += getBoardList($boardListOptions); - - // Make the board safe for display. - foreach ($context['categories'] as $id_cat => $cat) + /** + * Main function for action=xmlhttp. + */ + public function action_index() { - $context['categories'][$id_cat]['name'] = un_htmlspecialchars(strip_tags($cat['name'])); - foreach ($cat['boards'] as $id_board => $board) - $context['categories'][$id_cat]['boards'][$id_board]['name'] = un_htmlspecialchars(strip_tags($board['name'])); - } - - $context['sub_template'] = 'jump_to'; -} + loadTemplate('Xml'); -/** - * Get the message icons available for a given board - */ -function action_messageicons() -{ - global $context, $board; + $subActions = array( + 'jumpto' => array('action_jumpto'), + 'messageicons' => array('action_messageicons'), + 'groupicons' => array('action_groupicons'), + 'corefeatures' => array('action_corefeatures', 'admin_forum'), + ); - require_once(SUBSDIR . '/Editor.subs.php'); - $context['icons'] = getMessageIcons($board); + // Easy adding of xml sub actions + call_integration_hook('integrate_xmlhttp', array(&$subActions)); - $context['sub_template'] = 'message_icons'; -} + // Valid action? + if (!isset($_REQUEST['sa'], $subActions[$_REQUEST['sa']])) + fatal_lang_error('no_access', false); -/** - * Get the member group icons - */ -function action_groupicons() -{ - global $context, $settings; + // Permissions check in the subAction? + if (isset($subActions[$_REQUEST['sa']][1])) + isAllowedTo($subActions[$_REQUEST['sa']][1]); - // Only load images - $allowedTypes = array('jpeg', 'jpg', 'gif', 'png', 'bmp'); - $context['membergroup_icons'] = array(); - $directory = $settings['theme_dir'] . '/images/group_icons'; + // Off we go then + $this->{$subActions[$_REQUEST['sa']][0]}(); + } - // Get all the available member group icons - $files = scandir($directory); - foreach ($files as $id => $file) + /** + * Get a list of boards and categories used for the jumpto dropdown. + */ + public function action_jumpto() { - if ($file === 'blank.png') - continue; + global $context; - if (in_array(strtolower(pathinfo($file, PATHINFO_EXTENSION)), $allowedTypes)) + // Find the boards/categories they can see. + require_once(SUBSDIR . '/Boards.subs.php'); + $boardListOptions = array( + 'use_permissions' => true, + 'selected_board' => isset($context['current_board']) ? $context['current_board'] : 0, + ); + $context += getBoardList($boardListOptions); + + // Make the board safe for display. + foreach ($context['categories'] as $id_cat => $cat) { - $icons[$id] = array( - 'value' => $file, - 'name' => '', - 'url' => $settings['images_url'] . '/group_icons/' . $file, - 'is_last' => false, - ); + $context['categories'][$id_cat]['name'] = un_htmlspecialchars(strip_tags($cat['name'])); + foreach ($cat['boards'] as $id_board => $board) + $context['categories'][$id_cat]['boards'][$id_board]['name'] = un_htmlspecialchars(strip_tags($board['name'])); } - } - - $context['icons'] = array_values($icons); - $context['sub_template'] = 'message_icons'; -} -/** - * Turns on or off a core forum feature via ajax - */ -function action_corefeatures() -{ - global $context, $modSettings, $txt, $settings; + $context['sub_template'] = 'jump_to'; + } - $context['xml_data'] = array(); + /** + * Get the message icons available for a given board + */ + public function action_messageicons() + { + global $context, $board; - // Just in case, maybe we don't need it - loadLanguage('Errors'); + require_once(SUBSDIR . '/Editor.subs.php'); + $context['icons'] = getMessageIcons($board); - // We need (at least) this to ensure that mod files are included - if (!empty($modSettings['integrate_admin_include'])) - { - $admin_includes = explode(',', $modSettings['integrate_admin_include']); - foreach ($admin_includes as $include) - { - $include = strtr(trim($include), array('BOARDDIR' => BOARDDIR, 'SOURCEDIR' => SOURCEDIR, '$themedir' => $settings['theme_dir'])); - if (file_exists($include)) - require_once($include); - } + $context['sub_template'] = 'message_icons'; } - $errors = array(); - $returns = array(); - $tokens = array(); - - // You have to be allowed to do this of course - $validation = validateSession(); - if (empty($validation)) + /** + * Get the member group icons + */ + public function action_groupicons() { - require_once(ADMINDIR . '/ManageCoreFeatures.php'); - $controller = new ManageCoreFeatures_Controller(); - $result = $controller->action_index(); + global $context, $settings; + + // Only load images + $allowedTypes = array('jpeg', 'jpg', 'gif', 'png', 'bmp'); + $context['membergroup_icons'] = array(); + $directory = $settings['theme_dir'] . '/images/group_icons'; - // Load up the core features of the system - if (empty($result)) + // Get all the available member group icons + $files = scandir($directory); + foreach ($files as $id => $file) { - $id = isset($_POST['feature_id']) ? $_POST['feature_id'] : ''; + if ($file === 'blank.png') + continue; - // The feature being enabled does exist, no messing about - if (!empty($id) && isset($context['features'][$id])) + if (in_array(strtolower(pathinfo($file, PATHINFO_EXTENSION)), $allowedTypes)) { - $feature = $context['features'][$id]; - $returns[] = array( - 'value' => (!empty($_POST['feature_' . $id]) && $feature['url'] ? '' . $feature['title'] . '' : $feature['title']), - ); - - createToken('admin-core', 'post'); - $tokens = array( - array( - 'value' => $context['admin-core_token'], - 'attributes' => array('type' => 'token_var'), - ), - array( - 'value' => $context['admin-core_token_var'], - 'attributes' => array('type' => 'token'), - ), + $icons[$id] = array( + 'value' => $file, + 'name' => '', + 'url' => $settings['images_url'] . '/group_icons/' . $file, + 'is_last' => false, ); } - else - $errors[] = array('value' => $txt['feature_no_exists']); } - // Some problem loading in the core feature set - else - $errors[] = array('value' => $txt[$result]); - } - // Failed session validation I'm afraid - else - $errors[] = array('value' => $txt[$validation]); - - - // Return the response to the calling program - $context['sub_template'] = 'generic_xml'; - $context['xml_data'] = array( - 'corefeatures' => array( - 'identifier' => 'corefeature', - 'children' => $returns, - ), - 'tokens' => array( - 'identifier' => 'token', - 'children' => $tokens, - ), - 'errors' => array( - 'identifier' => 'error', - 'children' => $errors, - ), - ); -} - -/** - * Returns a preview of an item for use in an ajax enabled template - * - Calls the correct function for the action - */ -function action_previews() -{ - global $context; - - $subActions = array( - 'newspreview' => array('action_newspreview'), - 'newsletterpreview' => array('action_newsletterpreview'), - 'sig_preview' => array('action_sig_preview'), - 'warning_preview' => array('action_warning_preview'), - 'bounce_preview' => array('action_bounce_preview'), - ); - - $context['sub_template'] = 'generic_xml'; - - // Valid action? - if (!isset($_REQUEST['item'], $subActions[$_REQUEST['item']])) - return false; - - // A preview it is then - $subActions[$_REQUEST['item']][0](); -} - -/** - * Get a preview of the important forum news for review before use - * - Calls parse bbc to render bbc tags for the preview - */ -function action_newspreview() -{ - global $context; - - // Needed for parse bbc - require_once(SUBSDIR . '/Post.subs.php'); - - $errors = array(); - $news = !isset($_POST['news']) ? '' : Util::htmlspecialchars($_POST['news'], ENT_QUOTES); - if (empty($news)) - $errors[] = array('value' => 'no_news'); - else - preparsecode($news); - - // Return the xml response to the template - $context['xml_data'] = array( - 'news' => array( - 'identifier' => 'parsedNews', - 'children' => array( - array( - 'value' => parse_bbc($news), - ), - ), - ), - 'errors' => array( - 'identifier' => 'error', - 'children' => $errors - ), - ); -} -/** - * Get a preview of a news letter before its sent on to the masses - * - Uses prepareMailingForPreview to create the actual preview - */ -function action_newsletterpreview() -{ - global $context, $txt; - - // needed to create the preview - require_once(SUBSDIR . '/Mail.subs.php'); - loadLanguage('Errors'); - - $context['post_error']['messages'] = array(); - $context['send_pm'] = !empty($_POST['send_pm']) ? 1 : 0; - $context['send_html'] = !empty($_POST['send_html']) ? 1 : 0; - - // Let them know about any mistakes - if (empty($_POST['subject'])) - $context['post_error']['messages'][] = $txt['error_no_subject']; - if (empty($_POST['message'])) - $context['post_error']['messages'][] = $txt['error_no_message']; - - prepareMailingForPreview(); - - $context['sub_template'] = 'pm'; -} - -/** - * Let them see what their signature looks like before they use it like spam - */ -function action_sig_preview() -{ - global $context, $txt, $user_info; - - require_once(SUBSDIR . '/Profile.subs.php'); - loadLanguage('Profile'); - loadLanguage('Errors'); - - $user = isset($_POST['user']) ? (int) $_POST['user'] : 0; - $is_owner = $user == $user_info['id']; - - // @todo Temporary - // Borrowed from loadAttachmentContext in Display.controller.php - $can_change = $is_owner ? allowedTo(array('profile_extra_any', 'profile_extra_own')) : allowedTo('profile_extra_any'); - - $errors = array(); - if (!empty($user) && $can_change) - { - require_once(SUBSDIR . '/Members.subs.php'); - // Get the current signature - $member = getBasicMemberData($user, array('preferences' => true)); - - censorText($member['signature']); - $member['signature'] = parse_bbc($member['signature'], true, 'sig' . $user); - - // And now what they want it to be - $preview_signature = !empty($_POST['signature']) ? $_POST['signature'] : ''; - $validation = profileValidateSignature($preview_signature); - - // An odd check for errors to be sure - if ($validation !== true && $validation !== false) - $errors[] = array('value' => $txt['profile_error_' . $validation], 'attributes' => array('type' => 'error')); - - censorText($preview_signature); - $preview_signature = parse_bbc($preview_signature, true, 'sig' . $user); - } - // Sorry but you can't change the signature - elseif (!$can_change) - { - if ($is_owner) - $errors[] = array('value' => $txt['cannot_profile_extra_own'], 'attributes' => array('type' => 'error')); - else - $errors[] = array('value' => $txt['cannot_profile_extra_any'], 'attributes' => array('type' => 'error')); + $context['icons'] = array_values($icons); + $context['sub_template'] = 'message_icons'; } - else - $errors[] = array('value' => $txt['no_user_selected'], 'attributes' => array('type' => 'error')); - - // Return the response for the template - $context['xml_data']['signatures'] = array( - 'identifier' => 'signature', - 'children' => array() - ); - - if (isset($member['signature'])) - $context['xml_data']['signatures']['children'][] = array( - 'value' => $member['signature'], - 'attributes' => array('type' => 'current'), - ); - - if (isset($preview_signature)) - $context['xml_data']['signatures']['children'][] = array( - 'value' => $preview_signature, - 'attributes' => array('type' => 'preview'), - ); - - if (!empty($errors)) - $context['xml_data']['errors'] = array( - 'identifier' => 'error', - 'children' => array_merge( - array( - array( - 'value' => $txt['profile_errors_occurred'], - 'attributes' => array('type' => 'errors_occurred'), - ), - ), $errors - ), - ); -} - -/** - * Used to preview custom warning templates before they are saved to submitted to the user - */ -function action_warning_preview() -{ - global $context, $txt, $user_info, $scripturl, $mbname; - require_once(SUBSDIR . '/Post.subs.php'); - loadLanguage('Errors'); - loadLanguage('ModerationCenter'); + /** + * Turns on or off a core forum feature via ajax + */ + public function action_corefeatures() + { + global $context, $modSettings, $txt, $settings; - $context['post_error']['messages'] = array(); + $context['xml_data'] = array(); - // If you can't issue the warning, what are you doing here? - if (allowedTo('issue_warning')) - { - $warning_body = !empty($_POST['body']) ? trim(censorText($_POST['body'])) : ''; - $context['preview_subject'] = !empty($_POST['title']) ? trim(Util::htmlspecialchars($_POST['title'])) : ''; - if (isset($_POST['issuing'])) - { - if (empty($_POST['title']) || empty($_POST['body'])) - $context['post_error']['messages'][] = $txt['warning_notify_blank']; - } - else - { - if (empty($_POST['title'])) - $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title']; - if (empty($_POST['body'])) - $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body']; - // Add in few replacements. - /** - * These are the defaults: - * - {MEMBER} - Member Name. => current user for review - * - {MESSAGE} - Link to Offending Post. (If Applicable) => not applicable here, so not replaced - * - {FORUMNAME} - Forum Name. - * - {SCRIPTURL} - Web address of forum. - * - {REGARDS} - Standard email sign-off. - */ - $find = array( - '{MEMBER}', - '{FORUMNAME}', - '{SCRIPTURL}', - '{REGARDS}', - ); - $replace = array( - $user_info['name'], - $mbname, - $scripturl, - $txt['regards_team'], - ); - $warning_body = str_replace($find, $replace, $warning_body); - } + // Just in case, maybe we don't need it + loadLanguage('Errors'); - // Deal with any BBC so it looks good for the preview - if (!empty($_POST['body'])) + // We need (at least) this to ensure that mod files are included + if (!empty($modSettings['integrate_admin_include'])) { - preparsecode($warning_body); - $warning_body = parse_bbc($warning_body, true); + $admin_includes = explode(',', $modSettings['integrate_admin_include']); + foreach ($admin_includes as $include) + { + $include = strtr(trim($include), array('BOARDDIR' => BOARDDIR, 'SOURCEDIR' => SOURCEDIR, '$themedir' => $settings['theme_dir'])); + if (file_exists($include)) + require_once($include); + } } - $context['preview_message'] = $warning_body; - } - else - $context['post_error']['messages'][] = array('value' => $txt['cannot_issue_warning'], 'attributes' => array('type' => 'error')); - - $context['sub_template'] = 'pm'; -} - -/** - * Used to preview custom email bounce templates before they are saved for use - */ -function action_bounce_preview() -{ - global $context, $txt, $scripturl, $mbname, $modSettings; - require_once(SUBSDIR . '/Post.subs.php'); - loadLanguage('Errors'); - loadLanguage('ModerationCenter'); + $errors = array(); + $returns = array(); + $tokens = array(); - $context['post_error']['messages'] = array(); - - // If you can't approve emails, what are you doing here? - if (allowedTo('approve_emails')) - { - $body = !empty($_POST['body']) ? trim(censorText($_POST['body'])) : ''; - $context['preview_subject'] = !empty($_POST['title']) ? trim(Util::htmlspecialchars($_POST['title'])) : ''; - - if (isset($_POST['issuing'])) + // You have to be allowed to do this of course + $validation = validateSession(); + if (empty($validation)) { - if (empty($_POST['title']) || empty($_POST['body'])) - $context['post_error']['messages'][] = $txt['warning_notify_blank']; + require_once(ADMINDIR . '/ManageCoreFeatures.php'); + $controller = new ManageCoreFeatures_Controller(); + $result = $controller->action_index(); + + // Load up the core features of the system + if (empty($result)) + { + $id = isset($_POST['feature_id']) ? $_POST['feature_id'] : ''; + + // The feature being enabled does exist, no messing about + if (!empty($id) && isset($context['features'][$id])) + { + $feature = $context['features'][$id]; + $returns[] = array( + 'value' => (!empty($_POST['feature_' . $id]) && $feature['url'] ? '' . $feature['title'] . '' : $feature['title']), + ); + + createToken('admin-core', 'post'); + $tokens = array( + array( + 'value' => $context['admin-core_token'], + 'attributes' => array('type' => 'token_var'), + ), + array( + 'value' => $context['admin-core_token_var'], + 'attributes' => array('type' => 'token'), + ), + ); + } + else + $errors[] = array('value' => $txt['feature_no_exists']); + } + // Some problem loading in the core feature set + else + $errors[] = array('value' => $txt[$result]); } + // Failed session validation I'm afraid else - { - if (empty($_POST['title'])) - $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title']; + $errors[] = array('value' => $txt[$validation]); - if (empty($_POST['body'])) - $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body']; - // Add in few replacements. - /** - * These are the defaults: - * - {FORUMNAME} - Forum Name, the full name with all the bells - * - {FORUMNAMESHORT} - Short and simple name - * - {SCRIPTURL} - Web address of forum. - * - {ERROR} - The error that was generated by the post, its unique to the post so cant render it here - * - {SUBJECT} - The subject of the email thats being discussed, unique to the post so cant render it here - * - {REGARDS} - Standard email sign-off. - * - {EMAILREGARDS} - Maybe a bit more friendly sign-off. - */ - $find = array( - '{FORUMNAME}', - '{FORUMNAMESHORT}', - '{SCRIPTURL}', - '{REGARDS}', - '{EMAILREGARDS}', - ); - $replace = array( - $mbname, - (!empty($modSettings['maillist_sitename']) ? $modSettings['maillist_sitename'] : $mbname), - $scripturl, - $txt['regards_team'], - (!empty($modSettings['maillist_sitename_regards']) ? $modSettings['maillist_sitename_regards'] : '') - ); - $body = str_replace($find, $replace, $body); - } - // Deal with any BBC so it looks good for the preview - if (!empty($_POST['body'])) - { - preparsecode($body); - $body = parse_bbc($body, true); - } - $context['preview_message'] = $body; + // Return the response to the calling program + $context['sub_template'] = 'generic_xml'; + $context['xml_data'] = array( + 'corefeatures' => array( + 'identifier' => 'corefeature', + 'children' => $returns, + ), + 'tokens' => array( + 'identifier' => 'token', + 'children' => $tokens, + ), + 'errors' => array( + 'identifier' => 'error', + 'children' => $errors, + ), + ); } - - $context['sub_template'] = 'pm'; } \ No newline at end of file diff --git a/sources/controllers/Xmlpreview.controller.php b/sources/controllers/Xmlpreview.controller.php new file mode 100644 index 0000000000..2d2cea8ea5 --- /dev/null +++ b/sources/controllers/Xmlpreview.controller.php @@ -0,0 +1,320 @@ + array('action_newspreview'), + 'newsletterpreview' => array('action_newsletterpreview'), + 'sig_preview' => array('action_sig_preview'), + 'warning_preview' => array('action_warning_preview'), + 'bounce_preview' => array('action_bounce_preview'), + ); + + $context['sub_template'] = 'generic_xml'; + + // Valid action? + if (!isset($_REQUEST['item'], $subActions[$_REQUEST['item']])) + return false; + + // A preview it is then + $subActions[$_REQUEST['item']][0](); + } + + /** + * Get a preview of the important forum news for review before use + * - Calls parse bbc to render bbc tags for the preview + */ + function action_newspreview() + { + global $context; + + // Needed for parse bbc + require_once(SUBSDIR . '/Post.subs.php'); + + $errors = array(); + $news = !isset($_POST['news']) ? '' : Util::htmlspecialchars($_POST['news'], ENT_QUOTES); + if (empty($news)) + $errors[] = array('value' => 'no_news'); + else + preparsecode($news); + + // Return the xml response to the template + $context['xml_data'] = array( + 'news' => array( + 'identifier' => 'parsedNews', + 'children' => array( + array( + 'value' => parse_bbc($news), + ), + ), + ), + 'errors' => array( + 'identifier' => 'error', + 'children' => $errors + ), + ); + } + + /** + * Get a preview of a news letter before its sent on to the masses + * - Uses prepareMailingForPreview to create the actual preview + */ + function action_newsletterpreview() + { + global $context, $txt; + + // needed to create the preview + require_once(SUBSDIR . '/Mail.subs.php'); + loadLanguage('Errors'); + + $context['post_error']['messages'] = array(); + $context['send_pm'] = !empty($_POST['send_pm']) ? 1 : 0; + $context['send_html'] = !empty($_POST['send_html']) ? 1 : 0; + + // Let them know about any mistakes + if (empty($_POST['subject'])) + $context['post_error']['messages'][] = $txt['error_no_subject']; + if (empty($_POST['message'])) + $context['post_error']['messages'][] = $txt['error_no_message']; + + prepareMailingForPreview(); + + $context['sub_template'] = 'pm'; + } + + /** + * Let them see what their signature looks like before they use it like spam + */ + function action_sig_preview() + { + global $context, $txt, $user_info; + + require_once(SUBSDIR . '/Profile.subs.php'); + loadLanguage('Profile'); + loadLanguage('Errors'); + + $user = isset($_POST['user']) ? (int) $_POST['user'] : 0; + $is_owner = $user == $user_info['id']; + + // @todo Temporary + // Borrowed from loadAttachmentContext in Display.controller.php + $can_change = $is_owner ? allowedTo(array('profile_extra_any', 'profile_extra_own')) : allowedTo('profile_extra_any'); + + $errors = array(); + if (!empty($user) && $can_change) + { + require_once(SUBSDIR . '/Members.subs.php'); + // Get the current signature + $member = getBasicMemberData($user, array('preferences' => true)); + + censorText($member['signature']); + $member['signature'] = parse_bbc($member['signature'], true, 'sig' . $user); + + // And now what they want it to be + $preview_signature = !empty($_POST['signature']) ? $_POST['signature'] : ''; + $validation = profileValidateSignature($preview_signature); + + // An odd check for errors to be sure + if ($validation !== true && $validation !== false) + $errors[] = array('value' => $txt['profile_error_' . $validation], 'attributes' => array('type' => 'error')); + + censorText($preview_signature); + $preview_signature = parse_bbc($preview_signature, true, 'sig' . $user); + } + // Sorry but you can't change the signature + elseif (!$can_change) + { + if ($is_owner) + $errors[] = array('value' => $txt['cannot_profile_extra_own'], 'attributes' => array('type' => 'error')); + else + $errors[] = array('value' => $txt['cannot_profile_extra_any'], 'attributes' => array('type' => 'error')); + } + else + $errors[] = array('value' => $txt['no_user_selected'], 'attributes' => array('type' => 'error')); + + // Return the response for the template + $context['xml_data']['signatures'] = array( + 'identifier' => 'signature', + 'children' => array() + ); + + if (isset($member['signature'])) + $context['xml_data']['signatures']['children'][] = array( + 'value' => $member['signature'], + 'attributes' => array('type' => 'current'), + ); + + if (isset($preview_signature)) + $context['xml_data']['signatures']['children'][] = array( + 'value' => $preview_signature, + 'attributes' => array('type' => 'preview'), + ); + + if (!empty($errors)) + $context['xml_data']['errors'] = array( + 'identifier' => 'error', + 'children' => array_merge( + array( + array( + 'value' => $txt['profile_errors_occurred'], + 'attributes' => array('type' => 'errors_occurred'), + ), + ), $errors + ), + ); + } + + /** + * Used to preview custom warning templates before they are saved to submitted to the user + */ + function action_warning_preview() + { + global $context, $txt, $user_info, $scripturl, $mbname; + + require_once(SUBSDIR . '/Post.subs.php'); + loadLanguage('Errors'); + loadLanguage('ModerationCenter'); + + $context['post_error']['messages'] = array(); + + // If you can't issue the warning, what are you doing here? + if (allowedTo('issue_warning')) + { + $warning_body = !empty($_POST['body']) ? trim(censorText($_POST['body'])) : ''; + $context['preview_subject'] = !empty($_POST['title']) ? trim(Util::htmlspecialchars($_POST['title'])) : ''; + if (isset($_POST['issuing'])) + { + if (empty($_POST['title']) || empty($_POST['body'])) + $context['post_error']['messages'][] = $txt['warning_notify_blank']; + } + else + { + if (empty($_POST['title'])) + $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title']; + if (empty($_POST['body'])) + $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body']; + // Add in few replacements. + /** + * These are the defaults: + * - {MEMBER} - Member Name. => current user for review + * - {MESSAGE} - Link to Offending Post. (If Applicable) => not applicable here, so not replaced + * - {FORUMNAME} - Forum Name. + * - {SCRIPTURL} - Web address of forum. + * - {REGARDS} - Standard email sign-off. + */ + $find = array( + '{MEMBER}', + '{FORUMNAME}', + '{SCRIPTURL}', + '{REGARDS}', + ); + $replace = array( + $user_info['name'], + $mbname, + $scripturl, + $txt['regards_team'], + ); + $warning_body = str_replace($find, $replace, $warning_body); + } + + // Deal with any BBC so it looks good for the preview + if (!empty($_POST['body'])) + { + preparsecode($warning_body); + $warning_body = parse_bbc($warning_body, true); + } + $context['preview_message'] = $warning_body; + } + else + $context['post_error']['messages'][] = array('value' => $txt['cannot_issue_warning'], 'attributes' => array('type' => 'error')); + + $context['sub_template'] = 'pm'; + } + + /** + * Used to preview custom email bounce templates before they are saved for use + */ + function action_bounce_preview() + { + global $context, $txt, $scripturl, $mbname, $modSettings; + + require_once(SUBSDIR . '/Post.subs.php'); + loadLanguage('Errors'); + loadLanguage('ModerationCenter'); + + $context['post_error']['messages'] = array(); + + // If you can't approve emails, what are you doing here? + if (allowedTo('approve_emails')) + { + $body = !empty($_POST['body']) ? trim(censorText($_POST['body'])) : ''; + $context['preview_subject'] = !empty($_POST['title']) ? trim(Util::htmlspecialchars($_POST['title'])) : ''; + + if (isset($_POST['issuing'])) + { + if (empty($_POST['title']) || empty($_POST['body'])) + $context['post_error']['messages'][] = $txt['warning_notify_blank']; + } + else + { + if (empty($_POST['title'])) + $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title']; + + if (empty($_POST['body'])) + $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body']; + // Add in few replacements. + /** + * These are the defaults: + * - {FORUMNAME} - Forum Name, the full name with all the bells + * - {FORUMNAMESHORT} - Short and simple name + * - {SCRIPTURL} - Web address of forum. + * - {ERROR} - The error that was generated by the post, its unique to the post so cant render it here + * - {SUBJECT} - The subject of the email thats being discussed, unique to the post so cant render it here + * - {REGARDS} - Standard email sign-off. + * - {EMAILREGARDS} - Maybe a bit more friendly sign-off. + */ + $find = array( + '{FORUMNAME}', + '{FORUMNAMESHORT}', + '{SCRIPTURL}', + '{REGARDS}', + '{EMAILREGARDS}', + ); + $replace = array( + $mbname, + (!empty($modSettings['maillist_sitename']) ? $modSettings['maillist_sitename'] : $mbname), + $scripturl, + $txt['regards_team'], + (!empty($modSettings['maillist_sitename_regards']) ? $modSettings['maillist_sitename_regards'] : '') + ); + $body = str_replace($find, $replace, $body); + } + + // Deal with any BBC so it looks good for the preview + if (!empty($_POST['body'])) + { + preparsecode($body); + $body = parse_bbc($body, true); + } + $context['preview_message'] = $body; + } + + $context['sub_template'] = 'pm'; + } +} \ No newline at end of file diff --git a/themes/default/Maillist.template.php b/themes/default/Maillist.template.php index e7dc8acdf4..c203a7db9b 100644 --- a/themes/default/Maillist.template.php +++ b/themes/default/Maillist.template.php @@ -413,7 +413,7 @@ function ajax_getTemplatePreview () { $.ajax({ type: "POST", - url: "' . $scripturl . '?action=xmlhttp;sa=previews;xml", + url: "' . $scripturl . '?action=xmlpreview;xml", data: {item: "bounce_preview", title: $("#template_title").val(), body: $("#template_body").val()}, context: document.body, success: function(request){ diff --git a/themes/default/ModerationCenter.template.php b/themes/default/ModerationCenter.template.php index c49ece63a0..2078311838 100644 --- a/themes/default/ModerationCenter.template.php +++ b/themes/default/ModerationCenter.template.php @@ -712,7 +712,7 @@ function ajax_getTemplatePreview () { $.ajax({ type: "POST", - url: "' . $scripturl . '?action=xmlhttp;sa=previews;xml", + url: "' . $scripturl . '?action=xmlpreview;xml", data: {item: "warning_preview", title: $("#template_title").val(), body: $("#template_body").val(), user: $(\'input[name="u"]\').attr("value")}, context: document.body, success: function(request){ diff --git a/themes/default/ProfileAccount.template.php b/themes/default/ProfileAccount.template.php index 965f3cf031..93a6886905 100644 --- a/themes/default/ProfileAccount.template.php +++ b/themes/default/ProfileAccount.template.php @@ -314,7 +314,7 @@ function ajax_getTemplatePreview () { $.ajax({ type: "POST", - url: "' . $scripturl . '?action=xmlhttp;sa=previews;xml", + url: "' . $scripturl . '?action=xmlpreview;xml", data: {item: "warning_preview", title: $("#warn_sub").val(), body: $("#warn_body").val(), issuing: true}, context: document.body, success: function(request){ diff --git a/themes/default/scripts/post.js b/themes/default/scripts/post.js index 6a89d7a1f5..5d3d4696a7 100644 --- a/themes/default/scripts/post.js +++ b/themes/default/scripts/post.js @@ -130,7 +130,7 @@ function previewNews() x[x.length] = 'item=newsletterpreview'; // Send in document for previewing - sendXMLDocument(smf_prepareScriptUrl(smf_scripturl) + 'action=xmlhttp;sa=previews;xml', x.join('&'), onDocSent); + sendXMLDocument(smf_prepareScriptUrl(smf_scripturl) + 'action=xmlpreview;xml', x.join('&'), onDocSent); // Update the preview section with our results document.getElementById('preview_section').style.display = ''; diff --git a/themes/default/scripts/profile.js b/themes/default/scripts/profile.js index 38018e397f..97e536c0a6 100644 --- a/themes/default/scripts/profile.js +++ b/themes/default/scripts/profile.js @@ -94,7 +94,7 @@ function ajax_getSignaturePreview (showPreview) showPreview = (typeof showPreview === 'undefined') ? false : showPreview; $.ajax({ type: "POST", - url: smf_scripturl + "?action=xmlhttp;sa=previews;xml", + url: smf_scripturl + "?action=xmlpreview;xml", data: {item: "sig_preview", signature: $("#signature").val(), user: $('input[name="u"]').attr("value")}, context: document.body, success: function(request){ From 9288b92c24b4b983c779938b08f75d1cc892ac79 Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 15:05:40 +0300 Subject: [PATCH 19/34] Xml controllers extend Action_Controller. Methods visibility. Signed-off-by: Norv --- sources/controllers/Xml.controller.php | 2 +- sources/controllers/Xmlpreview.controller.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sources/controllers/Xml.controller.php b/sources/controllers/Xml.controller.php index b4989e7402..0c778f13eb 100644 --- a/sources/controllers/Xml.controller.php +++ b/sources/controllers/Xml.controller.php @@ -15,7 +15,7 @@ * Xml controller receives XMLhttp requests of various types. * (jump to, message and group icons, core features) */ -class Xml_Controller +class Xml_Controller extends Action_Controller { /** * Main function for action=xmlhttp. diff --git a/sources/controllers/Xmlpreview.controller.php b/sources/controllers/Xmlpreview.controller.php index 2d2cea8ea5..48b100c527 100644 --- a/sources/controllers/Xmlpreview.controller.php +++ b/sources/controllers/Xmlpreview.controller.php @@ -8,13 +8,13 @@ * @version 1.0 Alpha */ -class XmlPreview_Controller +class XmlPreview_Controller extends Action_Controller { /** * Returns a preview of an item for use in an ajax enabled template * - Calls the correct function for the action */ - function action_index() + public function action_index() { global $context; @@ -33,14 +33,14 @@ function action_index() return false; // A preview it is then - $subActions[$_REQUEST['item']][0](); + $this->{$subActions[$_REQUEST['item']][0]}(); } /** * Get a preview of the important forum news for review before use * - Calls parse bbc to render bbc tags for the preview */ - function action_newspreview() + public function action_newspreview() { global $context; @@ -75,7 +75,7 @@ function action_newspreview() * Get a preview of a news letter before its sent on to the masses * - Uses prepareMailingForPreview to create the actual preview */ - function action_newsletterpreview() + public function action_newsletterpreview() { global $context, $txt; @@ -101,7 +101,7 @@ function action_newsletterpreview() /** * Let them see what their signature looks like before they use it like spam */ - function action_sig_preview() + public function action_sig_preview() { global $context, $txt, $user_info; @@ -183,7 +183,7 @@ function action_sig_preview() /** * Used to preview custom warning templates before they are saved to submitted to the user */ - function action_warning_preview() + public function action_warning_preview() { global $context, $txt, $user_info, $scripturl, $mbname; @@ -250,7 +250,7 @@ function action_warning_preview() /** * Used to preview custom email bounce templates before they are saved for use */ - function action_bounce_preview() + public function action_bounce_preview() { global $context, $txt, $scripturl, $mbname, $modSettings; From 2771278e5273e341e64048485184acf399dc08c0 Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 15:13:11 +0300 Subject: [PATCH 20/34] Batch of method visibilities updates. (mostly public for actions handlers.) Signed-off-by: Norv --- sources/controllers/Emailuser.controller.php | 13 +++++++------ sources/controllers/Groups.controller.php | 6 +++--- sources/controllers/Karma.controller.php | 4 ++-- sources/controllers/Likes.controller.php | 8 ++++---- sources/controllers/Memberlist.controller.php | 6 +++--- sources/controllers/MergeTopics.controller.php | 8 ++++---- sources/controllers/MessageIndex.controller.php | 4 ++-- .../controllers/ModerateAttachments.controller.php | 2 +- sources/controllers/MoveTopic.controller.php | 4 ++-- sources/controllers/News.controller.php | 10 +++++----- 10 files changed, 33 insertions(+), 32 deletions(-) diff --git a/sources/controllers/Emailuser.controller.php b/sources/controllers/Emailuser.controller.php index f50ef7e9a7..c885bc6e5f 100644 --- a/sources/controllers/Emailuser.controller.php +++ b/sources/controllers/Emailuser.controller.php @@ -26,7 +26,7 @@ class Emailuser_Controller extends Action_Controller /** * This function initializes or sets up the necessary, for the other actions */ - function pre_dispatch() + public function pre_dispatch() { global $context; @@ -39,9 +39,10 @@ function pre_dispatch() /** * Default action handler + * * @see Action_Controller::action_index() */ - function action_index() + public function action_index() { // just accept we haz a default action: action_sendtopic() $this->action_sendtopic(); @@ -54,7 +55,7 @@ function action_index() * Redirects back to the first page of the topic when done. * Is accessed via ?action=emailuser;sa=sendtopic. */ - function action_sendtopic() + public function action_sendtopic() { global $topic, $txt, $context, $scripturl, $modSettings; @@ -147,7 +148,7 @@ function action_sendtopic() * Does not check permissions for a message ID as there is no information disclosed. * ?action=emailuser;sa=email */ - function action_email() + public function action_email() { global $context, $modSettings, $user_info, $txt, $scripturl; @@ -273,7 +274,7 @@ function action_email() * Uses action_reporttm2() if post data was sent. * Accessed through ?action=reporttm. */ - function action_reporttm() + public function action_reporttm() { global $txt, $topic, $modSettings, $user_info, $context; @@ -361,7 +362,7 @@ function action_reporttm() * Called by action_reporttm(), and thus has the same permission and setting requirements as it does. * Accessed through ?action=reporttm when posting. */ - function action_reporttm2() + public function action_reporttm2() { global $txt, $scripturl, $topic, $board, $user_info, $modSettings, $language, $context; diff --git a/sources/controllers/Groups.controller.php b/sources/controllers/Groups.controller.php index c45cf98d5f..634af712d1 100644 --- a/sources/controllers/Groups.controller.php +++ b/sources/controllers/Groups.controller.php @@ -71,7 +71,7 @@ public function pre_dispatch() /** * This very simply lists the groups, nothing snazy. */ - function action_list() + public function action_list() { global $txt, $context, $scripturl, $user_info; @@ -200,7 +200,7 @@ function action_list() * It redirects to itself. * @uses ManageMembergroups template, group_members sub template. */ - function action_members() + public function action_members() { global $txt, $scripturl, $context, $modSettings, $user_info, $settings; @@ -444,7 +444,7 @@ function action_members() /** * Show and manage all group requests. */ - function action_requests() + public function action_requests() { global $txt, $context, $scripturl, $user_info, $modSettings, $language; diff --git a/sources/controllers/Karma.controller.php b/sources/controllers/Karma.controller.php index 982ebed070..65bb804bb8 100644 --- a/sources/controllers/Karma.controller.php +++ b/sources/controllers/Karma.controller.php @@ -39,7 +39,7 @@ public function action_index() * It depends on the karmaMode, karmaWaitTime, and karmaTimeRestrictAdmins settings. * It is accessed via ?action=karma, sa=smite or sa=applaud. */ - function action_applaud() + public function action_applaud() { global $user_info; @@ -56,7 +56,7 @@ function action_applaud() /** * Smite a user. */ - function action_smite() + public function action_smite() { global $user_info; diff --git a/sources/controllers/Likes.controller.php b/sources/controllers/Likes.controller.php index 48c97e5ea5..28cd34396f 100644 --- a/sources/controllers/Likes.controller.php +++ b/sources/controllers/Likes.controller.php @@ -32,7 +32,7 @@ public function action_index() /** * Entry point function for likes, permission checks, just makes sure its on */ - function pre_dispatch() + public function pre_dispatch() { global $modSettings; @@ -47,7 +47,7 @@ function pre_dispatch() * It redirects back to the referrer afterward. * It is accessed via ?action=like,sa=likepost */ - function action_likepost() + public function action_likepost() { global $user_info, $topic; @@ -74,7 +74,7 @@ function action_likepost() * It redirects back to the referrer afterward. * It is accessed via ?action=like,sa=unlikepost. */ - function action_unlikepost() + public function action_unlikepost() { global $user_info, $topic; @@ -101,7 +101,7 @@ function action_unlikepost() * @param type $id_liked * @return type */ - function prepare_like() + private function prepare_like() { global $modSettings, $user_info; diff --git a/sources/controllers/Memberlist.controller.php b/sources/controllers/Memberlist.controller.php index fb2cbb450a..ccc69fefe4 100644 --- a/sources/controllers/Memberlist.controller.php +++ b/sources/controllers/Memberlist.controller.php @@ -36,7 +36,7 @@ class Memberlist_Controller extends Action_Controller * * @see Action_Controller::action_index() */ - function action_index() + public function action_index() { global $scripturl, $txt, $modSettings, $context; @@ -179,7 +179,7 @@ function action_index() * Can be passed a sort parameter, to order the display of members. * Calls printMemberListRows to retrieve the results of the query. */ - function action_mlall() + public function action_mlall() { global $txt, $scripturl, $modSettings, $context; @@ -321,7 +321,7 @@ function action_mlall() * If variable $_REQUEST['search'] is empty displays search dialog box, using the search sub-template. * Calls printMemberListRows to retrieve the results of the query. */ - function action_mlsearch() + public function action_mlsearch() { global $txt, $scripturl, $context, $modSettings; diff --git a/sources/controllers/MergeTopics.controller.php b/sources/controllers/MergeTopics.controller.php index a65e27333f..820f317aec 100644 --- a/sources/controllers/MergeTopics.controller.php +++ b/sources/controllers/MergeTopics.controller.php @@ -32,7 +32,7 @@ class MergeTopics_Controller extends Action_Controller * * @see Action_Controller::action_index() */ - function action_index() + public function action_index() { // Load the template.... loadTemplate('MergeTopics'); @@ -58,7 +58,7 @@ function action_index() * uses 'merge' sub template of the MergeTopics template. * allows to set a different target board. */ - function action_mergeIndex() + public function action_mergeIndex() { global $txt, $board, $context; global $scripturl, $user_info, $modSettings; @@ -198,7 +198,7 @@ function action_mergeIndex() * * redirects to ?action=mergetopics;sa=done. * @param array $topics = array() */ - function action_mergeExecute($topics = array()) + public function action_mergeExecute($topics = array()) { global $user_info, $txt, $context, $scripturl; global $language, $modSettings; @@ -797,7 +797,7 @@ function action_mergeExecute($topics = array()) * is accessed with ?action=mergetopics;sa=done. * uses 'merge_done' sub template of the MergeTopics template. */ - function action_mergeDone() + public function action_mergeDone() { global $txt, $context; diff --git a/sources/controllers/MessageIndex.controller.php b/sources/controllers/MessageIndex.controller.php index 7d349d7025..9cc8cbcff0 100644 --- a/sources/controllers/MessageIndex.controller.php +++ b/sources/controllers/MessageIndex.controller.php @@ -40,7 +40,7 @@ public function action_index() /** * Show the list of topics in this board, along with any child boards. */ - function action_messageindex() + public function action_messageindex() { global $txt, $scripturl, $board, $modSettings, $context; global $options, $settings, $board_info, $user_info; @@ -531,7 +531,7 @@ function action_messageindex() * Allows for moderation from the message index. * @todo refactor this... */ - function action_quickmod() + public function action_quickmod() { global $board, $user_info, $modSettings, $context; diff --git a/sources/controllers/ModerateAttachments.controller.php b/sources/controllers/ModerateAttachments.controller.php index f0bf31df9e..ebb61bd677 100644 --- a/sources/controllers/ModerateAttachments.controller.php +++ b/sources/controllers/ModerateAttachments.controller.php @@ -40,7 +40,7 @@ public function action_index() * works out what we want to do with attachments and actions it. * Accessed by ?action=attachapprove */ - function action_attachapprove() + public function action_attachapprove() { global $user_info; diff --git a/sources/controllers/MoveTopic.controller.php b/sources/controllers/MoveTopic.controller.php index 941a7dacd7..1c6baaf02b 100644 --- a/sources/controllers/MoveTopic.controller.php +++ b/sources/controllers/MoveTopic.controller.php @@ -45,7 +45,7 @@ public function action_index() * * @uses the MoveTopic template, main sub-template. */ - function action_movetopic() + public function action_movetopic() { global $txt, $topic, $user_info, $context, $language, $scripturl, $modSettings; @@ -121,7 +121,7 @@ function action_movetopic() * * @uses subs/Post.subs.php. */ - function action_movetopic2() + public function action_movetopic2() { global $txt, $board, $topic, $scripturl, $modSettings, $context; global $board, $language, $user_info; diff --git a/sources/controllers/News.controller.php b/sources/controllers/News.controller.php index 43499ea638..3f5daf65e5 100644 --- a/sources/controllers/News.controller.php +++ b/sources/controllers/News.controller.php @@ -51,7 +51,7 @@ public function action_index() * * @uses Stats language file. */ - function action_showfeed() + public function action_showfeed() { global $board, $board_info, $context, $scripturl, $boardurl, $txt, $modSettings, $user_info; global $query_this_board, $forum_version, $cdata_override, $settings; @@ -337,7 +337,7 @@ function action_showfeed() * @param string $xml_format * @return array */ - function action_xmlmembers($xml_format) + public function action_xmlmembers($xml_format) { global $scripturl; @@ -404,7 +404,7 @@ function action_xmlmembers($xml_format) * @param $xml_format * @return array, array of topics */ - function action_xmlnews($xml_format) + public function action_xmlnews($xml_format) { global $scripturl, $modSettings, $board; global $query_this_board, $context; @@ -552,7 +552,7 @@ function action_xmlnews($xml_format) * @param $xml_format * @return array, of recent posts */ - function action_xmlrecent($xml_format) + public function action_xmlrecent($xml_format) { global $scripturl, $modSettings, $board, $query_this_board, $context; @@ -726,7 +726,7 @@ function action_xmlrecent($xml_format) * @param $xml_format * @return array, of profile data. */ - function action_xmlprofile($xml_format) + public function action_xmlprofile($xml_format) { global $scripturl, $memberContext, $user_profile, $modSettings, $user_info; From 4c8b51900c935c1e5179daeaf484f752bf7b3d4a Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 15:13:56 +0300 Subject: [PATCH 21/34] Attachment controller extends Action_Controller (looks it was missed.) Signed-off-by: Norv --- sources/controllers/Attachment.controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/controllers/Attachment.controller.php b/sources/controllers/Attachment.controller.php index afd6ef86bd..9fba25c786 100644 --- a/sources/controllers/Attachment.controller.php +++ b/sources/controllers/Attachment.controller.php @@ -17,13 +17,13 @@ * */ -class Attachment_Controller +class Attachment_Controller extends Action_Controller { /** * The default action is to download an attachment. * This allows ?action=attachment to be forwarded to action_dlattach() */ - public function action_attachment() + public function action_index() { // default action to execute $this->action_dlattach(); From 22d4727274de495cb529106bb804ae3766183797 Mon Sep 17 00:00:00 2001 From: Norv Date: Sat, 22 Jun 2013 15:25:31 +0300 Subject: [PATCH 22/34] Tweak dispatcher. Signed-off-by: Norv --- sources/Dispatcher.class.php | 4 ++-- tests/sources/TestDispatcher.php | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sources/Dispatcher.class.php b/sources/Dispatcher.class.php index 3bb160bda5..36ec73c919 100644 --- a/sources/Dispatcher.class.php +++ b/sources/Dispatcher.class.php @@ -139,7 +139,7 @@ public function __construct() 'contact' => array('Register.controller.php', 'Register_Controller', 'action_contact'), 'coppa' => array('Register.controller.php', 'Register_Controller', 'action_coppa'), 'deletemsg' => array('RemoveTopic.controller.php', 'RemoveTopic_Controller', 'action_deletemsg'), - 'dlattach' => array('Attachment.controller.php', 'Attachment_Controller', 'action_dlattach'), + 'dlattach' => array('Attachment.controller.php', 'Attachment_Controller', 'action_index'), 'disregardtopic' => array('Notify.controller.php', 'Notify_Controller', 'action_disregardtopic'), 'editpoll' => array('Poll.controller.php', 'Poll_Controller', 'action_editpoll'), 'editpoll2' => array('Poll.controller.php', 'Poll_Controller', 'action_editpoll2'), @@ -183,7 +183,7 @@ public function __construct() 'splittopics' => array('SplitTopics.controller.php', 'SplitTopics_Controller', 'action_splittopics'), 'stats' => array('Stats.controller.php', 'Stats_Controller', 'action_stats'), 'theme' => array('Themes.php', 'Themes_Controller', 'action_thememain'), - 'trackip' => array('ProfileHistory.controller.php', 'action_trackip'), + 'trackip' => array('ProfileHistory.controller.php', 'ProfileHistory_Controller', 'action_trackip'), 'unread' => array('Recent.controller.php', 'Recent_Controller', 'action_unread'), 'unreadreplies' => array('Recent.controller.php', 'Recent_Controller', 'action_unread'), 'verificationcode' => array('Register.controller.php', 'Register_Controller', 'action_verificationcode'), diff --git a/tests/sources/TestDispatcher.php b/tests/sources/TestDispatcher.php index 656761058d..caff0d4806 100644 --- a/tests/sources/TestDispatcher.php +++ b/tests/sources/TestDispatcher.php @@ -29,6 +29,7 @@ function testAutoDispatch() 'topic' => array('lock', 'printpage', 'sticky'), 'profile' => array('index'), 'reminder' => array('picktype', 'secret2', 'setpassword', 'setpassword2'), + 'xmlpreview' => array('index'), ); foreach (array_keys($auto_actions) as $action) @@ -69,7 +70,7 @@ function testSaDispatch() 'quickmod' => 'MessageIndex', 'quickmod2' => 'Display', 'openidreturn' => 'OpenID', - + ); foreach (array_keys($actions) as $action) @@ -88,7 +89,7 @@ function testLegacyDispatch() // dunno how useful this is :P // controller and sa hardcoded $legacy_actions = array( - + ); $leftovers = array( @@ -134,7 +135,7 @@ function testLegacyDispatch() 'viewquery' => array('AdminDebug.php', 'AdminDebug_Controller', 'action_viewquery'), 'viewadminfile' => array('AdminDebug.php', 'AdminDebug_Controller', 'action_viewadminfile'), '.xml' => array('News.controller.php', 'News_Controller', 'action_showfeed'), - 'xmlhttp' => array('Xml.controller.php', 'action_xmlhttp'), + 'xmlhttp' => array('Xml.controller.php', 'Xml_Controller', 'action_index'), ); $adminActions = array ('admin', 'attachapprove', 'jsoption', 'theme', 'viewadminfile', 'viewquery'); From cd823bc40578b5b7e7fd61d550d22b1fc6fc2a2f Mon Sep 17 00:00:00 2001 From: Norv Date: Sun, 23 Jun 2013 17:22:19 +0300 Subject: [PATCH 23/34] Oops, list_ () callbacks are public. Signed-off-by: Norv --- sources/admin/ManageMaillist.php | 6 +++--- .../ModerationCenter.controller.php | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sources/admin/ManageMaillist.php b/sources/admin/ManageMaillist.php index 8b860c2456..0ebdf6b148 100644 --- a/sources/admin/ManageMaillist.php +++ b/sources/admin/ManageMaillist.php @@ -1547,7 +1547,7 @@ public function action_modify_bounce_templates() * @param $sort * @param $template_type type of template to load */ - protected function list_getBounceTemplates($start, $items_per_page, $sort) + public function list_getBounceTemplates($start, $items_per_page, $sort) { return warningTemplates($start, $items_per_page, $sort, 'bnctpl'); } @@ -1557,8 +1557,8 @@ protected function list_getBounceTemplates($start, $items_per_page, $sort) * * @param string $template_type */ - protected function list_getBounceTemplateCount() + public function list_getBounceTemplateCount() { return warningTemplateCount('bnctpl'); } -} \ No newline at end of file +} diff --git a/sources/controllers/ModerationCenter.controller.php b/sources/controllers/ModerationCenter.controller.php index 4985e0822e..36c930cbb9 100644 --- a/sources/controllers/ModerationCenter.controller.php +++ b/sources/controllers/ModerationCenter.controller.php @@ -1454,7 +1454,7 @@ public function action_viewWarnings() * * @param string $approve_query */ - protected function list_getWatchedUserCount($approve_query) + public function list_getWatchedUserCount($approve_query) { global $modSettings; @@ -1470,7 +1470,7 @@ protected function list_getWatchedUserCount($approve_query) * @param string $approve_query * @param string $dummy */ - protected function list_getWatchedUsers($start, $items_per_page, $sort, $approve_query, $dummy) + public function list_getWatchedUsers($start, $items_per_page, $sort, $approve_query, $dummy) { // find all our watched users return watchedUsers($start, $items_per_page, $sort, $approve_query, $dummy); @@ -1481,7 +1481,7 @@ protected function list_getWatchedUsers($start, $items_per_page, $sort, $approve * * @param string $approve_query */ - protected function list_getWatchedUserPostsCount($approve_query) + public function list_getWatchedUserPostsCount($approve_query) { global $modSettings; @@ -1497,7 +1497,7 @@ protected function list_getWatchedUserPostsCount($approve_query) * @param string $approve_query * @param array $delete_boards */ - protected function list_getWatchedUserPosts($start, $items_per_page, $sort, $approve_query, $delete_boards) + public function list_getWatchedUserPosts($start, $items_per_page, $sort, $approve_query, $delete_boards) { // watched users posts return watchedUserPosts($start, $items_per_page, $sort, $approve_query, $delete_boards); @@ -1511,7 +1511,7 @@ protected function list_getWatchedUserPosts($start, $items_per_page, $sort, $app * @param $sort * @param $template_type type of template to load */ - protected function list_getWarningTemplates($start, $items_per_page, $sort, $template_type = 'warntpl') + public function list_getWarningTemplates($start, $items_per_page, $sort, $template_type = 'warntpl') { return warningTemplates($start, $items_per_page, $sort, $template_type); } @@ -1521,7 +1521,7 @@ protected function list_getWarningTemplates($start, $items_per_page, $sort, $tem * * @param string $template_type */ - protected function list_getWarningTemplateCount($template_type = 'warntpl') + public function list_getWarningTemplateCount($template_type = 'warntpl') { return warningTemplateCount($template_type); } @@ -1533,7 +1533,7 @@ protected function list_getWarningTemplateCount($template_type = 'warntpl') * @param $items_per_page * @param $sort */ - protected function list_getWarnings($start, $items_per_page, $sort) + public function list_getWarnings($start, $items_per_page, $sort) { return warnings($start, $items_per_page, $sort); } @@ -1541,7 +1541,7 @@ protected function list_getWarnings($start, $items_per_page, $sort) /** * Callback for createList(), get the total count of all current warnings */ - protected function list_getWarningCount() + public function list_getWarningCount() { return warningCount(); } @@ -1851,4 +1851,4 @@ function ModBlockGroupRequests() $db->free_result($request); return 'group_requests_block'; -} \ No newline at end of file +} From d2fc184b584fb904f5c4d99bf9a011370fd2e779 Mon Sep 17 00:00:00 2001 From: Norv Date: Mon, 24 Jun 2013 00:16:13 +0300 Subject: [PATCH 24/34] Topic controller. Move a query to subs. Clean up topic attributes functions. Signed-off-by: Norv --- sources/controllers/Topic.controller.php | 31 ++++-------- sources/subs/Topic.subs.php | 61 +++++++++++++++++++++--- 2 files changed, 64 insertions(+), 28 deletions(-) diff --git a/sources/controllers/Topic.controller.php b/sources/controllers/Topic.controller.php index b23e4aa7fb..76af48c767 100644 --- a/sources/controllers/Topic.controller.php +++ b/sources/controllers/Topic.controller.php @@ -50,7 +50,7 @@ public function action_index() * - returns to the topic after it is done. * - it is accessed via ?action=topic;sa=lock. */ - function action_lock() + public function action_lock() { global $topic, $user_info, $board; @@ -64,8 +64,8 @@ function action_lock() require_once(SUBSDIR . '/Post.subs.php'); require_once(SUBSDIR . '/Topic.subs.php'); - // Find out who started the topic - list ($starter, $locked) = topicStarter($topic); + // Find out who started the topic and its lock status + list ($starter, $locked) = topicStatus($topic); // Can you lock topics here, mister? $user_lock = !allowedTo('lock_any'); @@ -88,7 +88,7 @@ function action_lock() else fatal_lang_error('locked_by_admin', 'user'); - // Actually lock the topic + // Lock the topic! setTopicAttribute($topic, array('locked' => $locked)); // If they are allowed a "moderator" permission, log it in the moderator log. @@ -112,12 +112,10 @@ function action_lock() * - when done, sends the user back to the topic. * - accessed via ?action=topic;sa=sticky. */ - function action_sticky() + public function action_sticky() { global $modSettings, $topic, $board; - $db = database(); - // Make sure the user can sticky it, and they are stickying *something*. isAllowedTo('make_sticky'); @@ -133,23 +131,14 @@ function action_sticky() // We need subs/Post.subs.php for the sendNotifications() function. require_once(SUBSDIR . '/Post.subs.php'); + // And Topic subs for topic attributes. require_once(SUBSDIR . '/Topic.subs.php'); // Is this topic already stickied, or no? - $request = $db->query('', ' - SELECT is_sticky - FROM {db_prefix}topics - WHERE id_topic = {int:current_topic} - LIMIT 1', - array( - 'current_topic' => $topic, - ) - ); - list ($is_sticky) = $db->fetch_row($request); - $db->free_result($request); + $is_sticky = topicAttribute($topic, 'sticky'); // Toggle the sticky value. - setTopicAttribute($topic, array('sticky' => $is_sticky)); + setTopicAttribute($topic, array('sticky' => (empty($is_sticky) ? 1 : 0))); // Log this sticky action - always a moderator thing. logAction(empty($is_sticky) ? 'sticky' : 'unsticky', array('topic' => $topic, 'board' => $board)); @@ -170,7 +159,7 @@ function action_sticky() * @uses Printpage template, main sub-template. * @uses print_above/print_below later without the main layer. */ - function action_printpage() + public function action_printpage() { global $topic, $txt, $scripturl, $context, $user_info; global $board_info, $modSettings, $settings; @@ -486,4 +475,4 @@ function action_printpage() // Set a canonical URL for this page. $context['canonical_url'] = $scripturl . '?topic=' . $topic . '.0'; } -} \ No newline at end of file +} diff --git a/sources/subs/Topic.subs.php b/sources/subs/Topic.subs.php index cba01558b7..ecde5eb01c 100644 --- a/sources/subs/Topic.subs.php +++ b/sources/subs/Topic.subs.php @@ -1584,16 +1584,16 @@ function updateSplitTopics($options, $id_board) } /** - * Find out who started a topic + * Find out who started a topic, and the lock status * * @param int $topic - * @return int + * @return array with id_member_started and locked */ -function topicStarter($topic) +function topicStatus($topic) { $db = database(); - // Find out who started the topic - in case User Topic Locking is enabled. + // Find out who started the topic, and the lock status. $request = $db->query('', ' SELECT id_member_started, locked FROM {db_prefix}topics @@ -1614,6 +1614,7 @@ function topicStarter($topic) * Parameter $attributes is an array with: * - 'locked' => lock_value, * - 'sticky' => sticky_value + * It sets the new value for the attribute as passed to it. * * @param int $topic * @param array $attributes @@ -1634,18 +1635,64 @@ function setTopicAttribute($topic, $attributes) ) ); if (isset($attributes['sticky'])) - // Toggle the sticky value... pretty simple ;). + // Set the new sticky value. $db->query('', ' UPDATE {db_prefix}topics SET is_sticky = {int:is_sticky} WHERE id_topic = {int:current_topic}', array( 'current_topic' => $topic, - 'is_sticky' => empty($attributes['sticky']) ? 1 : 0, + 'is_sticky' => empty($attributes['sticky']) ? 0 : 1, ) ); } +/** + * Retrieve the locked or sticky status of a topic. + * + * @param string $attribute 'locked' or 'sticky' + */ +function topicAttribute($id_topic, $attribute) +{ + $db = database(); + + if ($attribute == 'locked') + { + // check the lock status + $request = $db->query('', ' + SELECT locked + FROM {db_prefix}topics + WHERE id_topic = {int:current_topic} + LIMIT 1', + array( + 'current_topic' => $id_topic, + ) + ); + list ($locked) = $db->fetch_row($request); + $db->free_result($request); + + return $locked; + } + + if ($attribute == 'sticky') + { + // Is this topic already stickied, or no? + $request = $db->query('', ' + SELECT is_sticky + FROM {db_prefix}topics + WHERE id_topic = {int:current_topic} + LIMIT 1', + array( + 'current_topic' => $id_topic, + ) + ); + list ($sticky) = $db->fetch_row($request); + $db->free_result($request); + + return $sticky; + } +} + /** * Toggle sticky status for the passed topics. * @@ -2408,4 +2455,4 @@ function topicNotifications($start, $items_per_page, $sort, $memID) $db->free_result($request); return $notification_topics; -} \ No newline at end of file +} From 8b5d1f1ac261b8ca42b64ec26e1bd160df78733b Mon Sep 17 00:00:00 2001 From: Norv Date: Mon, 24 Jun 2013 00:54:22 +0300 Subject: [PATCH 25/34] MoveTopic controller. Move two queries to subs. Signed-off-by: Norv --- sources/controllers/MoveTopic.controller.php | 27 ++++----------- sources/subs/Post.subs.php | 36 ++++++++++++++++++++ sources/subs/Topic.subs.php | 2 +- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/sources/controllers/MoveTopic.controller.php b/sources/controllers/MoveTopic.controller.php index 1c6baaf02b..627a4e6a30 100644 --- a/sources/controllers/MoveTopic.controller.php +++ b/sources/controllers/MoveTopic.controller.php @@ -203,7 +203,8 @@ public function action_movetopic2() // If it's still valid move onwards and upwards. if ($custom_subject != '') { - if (isset($_POST['enforce_subject'])) + $all_messages = isset($_POST['enforce_subject']); + if ($all_messages) { // Get a response prefix, but in the forum's default language. if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) @@ -219,26 +220,10 @@ public function action_movetopic2() cache_put_data('response_prefix', $context['response_prefix'], 600); } - $db->query('', ' - UPDATE {db_prefix}messages - SET subject = {string:subject} - WHERE id_topic = {int:current_topic}', - array( - 'current_topic' => $topic, - 'subject' => $context['response_prefix'] . $custom_subject, - ) - ); + topicSubject($topic_info, $custom_subject, $context['response_prefix'], $all_messages); } - - $db->query('', ' - UPDATE {db_prefix}messages - SET subject = {string:custom_subject} - WHERE id_msg = {int:id_first_msg}', - array( - 'id_first_msg' => $topic_info['id_first_msg'], - 'custom_subject' => $custom_subject, - ) - ); + else + topicSubject($topic_info, $custom_subject); // Fix the subject cache. updateStats('subject', $topic, $custom_subject); @@ -341,4 +326,4 @@ public function action_movetopic2() else redirectexit('topic=' . $topic . '.0'); } -} \ No newline at end of file +} diff --git a/sources/subs/Post.subs.php b/sources/subs/Post.subs.php index 24b1c8c2b7..110b84ac8f 100644 --- a/sources/subs/Post.subs.php +++ b/sources/subs/Post.subs.php @@ -2427,3 +2427,39 @@ function getFormMsgSubject($editing, $topic, $first_subject = '') return array($form_subject, $form_message); } } + +/** + * Update topic subject. + * If $all is true, for all messages in the topic, otherwise only the first message. + * + * @param array $topic_info topic information as returned by getTopicInfo() + * @param string $custom_subject + * @param string $response_prefix = '' + * @param bool $all = false + */ +function topicSubject($topic_info, $custom_subject, $response_prefix = '', $all = false) +{ + $db = database(); + + if ($all) + { + $db->query('', ' + UPDATE {db_prefix}messages + SET subject = {string:subject} + WHERE id_topic = {int:current_topic}', + array( + 'current_topic' => $topic_info['id_topic'], + 'subject' => $response_prefix . $custom_subject, + ) + ); + } + $db->query('', ' + UPDATE {db_prefix}messages + SET subject = {string:custom_subject} + WHERE id_msg = {int:id_first_msg}', + array( + 'id_first_msg' => $topic_info['id_first_msg'], + 'custom_subject' => $custom_subject, + ) + ); +} diff --git a/sources/subs/Topic.subs.php b/sources/subs/Topic.subs.php index ecde5eb01c..cd6cb439e3 100644 --- a/sources/subs/Topic.subs.php +++ b/sources/subs/Topic.subs.php @@ -1126,7 +1126,7 @@ function getTopicInfo($topic_parameters, $full = '', $selects = array(), $tables // Create the query, taking full and integration in to account $request = $db->query('', ' SELECT - t.is_sticky, t.id_board, t.id_first_msg, t.id_last_msg, + t.id_topic, t.is_sticky, t.id_board, t.id_first_msg, t.id_last_msg, t.id_member_started, t.id_member_updated, t.id_poll, t.num_replies, t.num_views, t.num_likes, t.locked, t.redirect_expires, t.id_redirect_topic, t.unapproved_posts, t.approved' . ($messages_table ? ', From 4de7c7bc834ffb7994ee11dd098c4bfd72797a14 Mon Sep 17 00:00:00 2001 From: Norv Date: Mon, 24 Jun 2013 01:02:07 +0300 Subject: [PATCH 26/34] MoveTopic controller. The last query gone. Clean-up useless $db. Signed-off-by: Norv --- sources/controllers/MoveTopic.controller.php | 22 +------------- sources/subs/Topic.subs.php | 32 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/sources/controllers/MoveTopic.controller.php b/sources/controllers/MoveTopic.controller.php index 627a4e6a30..11dc3c9e8b 100644 --- a/sources/controllers/MoveTopic.controller.php +++ b/sources/controllers/MoveTopic.controller.php @@ -126,8 +126,6 @@ public function action_movetopic2() global $txt, $board, $topic, $scripturl, $modSettings, $context; global $board, $language, $user_info; - $db = database(); - if (empty($topic)) fatal_lang_error('no_access', false); @@ -279,25 +277,7 @@ public function action_movetopic2() if ($board_from['count_posts'] != $board_info['count_posts']) { - $request = $db->query('', ' - SELECT id_member - FROM {db_prefix}messages - WHERE id_topic = {int:current_topic} - AND approved = {int:is_approved}', - array( - 'current_topic' => $topic, - 'is_approved' => 1, - ) - ); - $posters = array(); - while ($row = $db->fetch_assoc($request)) - { - if (!isset($posters[$row['id_member']])) - $posters[$row['id_member']] = 0; - - $posters[$row['id_member']]++; - } - $db->free_result($request); + $posters = postersCount($topic); foreach ($posters as $id_member => $posts) { diff --git a/sources/subs/Topic.subs.php b/sources/subs/Topic.subs.php index cd6cb439e3..954b615b9d 100644 --- a/sources/subs/Topic.subs.php +++ b/sources/subs/Topic.subs.php @@ -2456,3 +2456,35 @@ function topicNotifications($start, $items_per_page, $sort, $memID) return $notification_topics; } + +/** + * Get a list of posters in this topic, and their posts counts in the topic. + * Used to update users posts counts when topics are moved or are deleted. + */ +function postersCount($id_topic) +{ + $db = database(); + + // we only care about approved topics, the rest don't count. + $request = $db->query('', ' + SELECT id_member + FROM {db_prefix}messages + WHERE id_topic = {int:current_topic} + AND approved = {int:is_approved}', + array( + 'current_topic' => $id_topic, + 'is_approved' => 1, + ) + ); + $posters = array(); + while ($row = $db->fetch_assoc($request)) + { + if (!isset($posters[$row['id_member']])) + $posters[$row['id_member']] = 0; + + $posters[$row['id_member']]++; + } + $db->free_result($request); + + return $posters; +} From 0f9acb53abd0068cf2dceda8f26b275325adf864 Mon Sep 17 00:00:00 2001 From: Norv Date: Mon, 24 Jun 2013 03:47:49 +0300 Subject: [PATCH 27/34] Fix Xml controllers. Signed-off-by: Norv --- sources/admin/Themes.php | 4 ++-- sources/controllers/Xml.controller.php | 6 ++++-- sources/controllers/Xmlpreview.controller.php | 21 +++++++++++++------ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/sources/admin/Themes.php b/sources/admin/Themes.php index c01231e2c5..492e775051 100644 --- a/sources/admin/Themes.php +++ b/sources/admin/Themes.php @@ -44,7 +44,7 @@ class Themes_Controller * sub-action. * It loads both the Themes and Settings language files. * Checks the session by GET or POST to verify the sent data. - * Requires the user not be a guest. (@todo what?) + * Requires the user to not be a guest. * Accessed via ?action=admin;area=theme. */ public function action_index() @@ -55,7 +55,7 @@ public function action_index() loadLanguage('Themes'); loadLanguage('Settings'); - // No funny business - guests only. + // No guests in here. is_not_guest(); // Default the page title to Theme Administration by default. diff --git a/sources/controllers/Xml.controller.php b/sources/controllers/Xml.controller.php index 0c778f13eb..deebfd00f8 100644 --- a/sources/controllers/Xml.controller.php +++ b/sources/controllers/Xml.controller.php @@ -18,7 +18,9 @@ class Xml_Controller extends Action_Controller { /** - * Main function for action=xmlhttp. + * Main dispatcher for action=xmlhttp. + * + * @see Action_Controller::action_index() */ public function action_index() { @@ -209,4 +211,4 @@ public function action_corefeatures() ), ); } -} \ No newline at end of file +} diff --git a/sources/controllers/Xmlpreview.controller.php b/sources/controllers/Xmlpreview.controller.php index 48b100c527..ebcd48f330 100644 --- a/sources/controllers/Xmlpreview.controller.php +++ b/sources/controllers/Xmlpreview.controller.php @@ -8,11 +8,18 @@ * @version 1.0 Alpha */ +if (!defined('ELKARTE')) + die('No access...'); + +/** + * This class handles requests for previews of an item, in an ajax enabled template. + */ class XmlPreview_Controller extends Action_Controller { /** - * Returns a preview of an item for use in an ajax enabled template - * - Calls the correct function for the action + * Calls the correct function for the action. + * + * @see Action_Controller::action_index() */ public function action_index() { @@ -26,11 +33,13 @@ public function action_index() 'bounce_preview' => array('action_bounce_preview'), ); - $context['sub_template'] = 'generic_xml'; - // Valid action? if (!isset($_REQUEST['item'], $subActions[$_REQUEST['item']])) - return false; + return; + + // Set up the template and default sub-template. + loadTemplate('Xml'); + $context['sub_template'] = 'generic_xml'; // A preview it is then $this->{$subActions[$_REQUEST['item']][0]}(); @@ -317,4 +326,4 @@ public function action_bounce_preview() $context['sub_template'] = 'pm'; } -} \ No newline at end of file +} From d2b0a8b558d4fd6240eca84c34dece345e0221cb Mon Sep 17 00:00:00 2001 From: Norv Date: Mon, 24 Jun 2013 05:04:51 +0300 Subject: [PATCH 28/34] Themes controller inherits Action_Controller. Signed-off-by: Norv --- sources/admin/Themes.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sources/admin/Themes.php b/sources/admin/Themes.php index 492e775051..6e37ebad2c 100644 --- a/sources/admin/Themes.php +++ b/sources/admin/Themes.php @@ -37,7 +37,7 @@ if (!defined('ELKARTE')) die('No access...'); -class Themes_Controller +class Themes_Controller extends Action_Controller { /** * Subaction handler - manages the action and delegates control to the proper @@ -46,6 +46,8 @@ class Themes_Controller * Checks the session by GET or POST to verify the sent data. * Requires the user to not be a guest. * Accessed via ?action=admin;area=theme. + * + * @see Action_Controller::action_index() */ public function action_index() { From 8965a2fc04be4eb0b5daee67b452d065f8201024 Mon Sep 17 00:00:00 2001 From: Norv Date: Mon, 24 Jun 2013 05:25:13 +0300 Subject: [PATCH 29/34] Adapt mod blocks functions, as helper methods in the controller. Naming. Signed-off-by: Norv --- .../ModerationCenter.controller.php | 518 +++++++++--------- 1 file changed, 259 insertions(+), 259 deletions(-) diff --git a/sources/controllers/ModerationCenter.controller.php b/sources/controllers/ModerationCenter.controller.php index 36c930cbb9..de3ae15c69 100644 --- a/sources/controllers/ModerationCenter.controller.php +++ b/sources/controllers/ModerationCenter.controller.php @@ -272,17 +272,17 @@ public function action_moderationHome() // Load what blocks the user actually can see... $valid_blocks = array( - 'n' => 'LatestNews', - 'p' => 'Notes', + 'n' => 'latestNews', + 'p' => 'notes', ); if ($context['can_moderate_groups']) - $valid_blocks['g'] = 'GroupRequests'; + $valid_blocks['g'] = 'groupRequests'; if ($context['can_moderate_boards']) { - $valid_blocks['r'] = 'ReportedPosts'; - $valid_blocks['w'] = 'WatchedUsers'; + $valid_blocks['r'] = 'reportedPosts'; + $valid_blocks['w'] = 'watchedUsers'; } if (empty($user_settings['mod_prefs'])) @@ -297,9 +297,9 @@ public function action_moderationHome() { if (in_array($k, $user_blocks)) { - $block = 'ModBlock' . $block; - if (function_exists($block)) - $context['mod_blocks'][] = $block(); + $block = 'block_' . $block; + if (method_exists($this, $block)) + $context['mod_blocks'][] = $this->{$block}(); } } } @@ -1545,310 +1545,310 @@ public function list_getWarningCount() { return warningCount(); } -} -/** - * Just prepares the time stuff for the latest news. - */ -function ModBlockLatestNews() -{ - global $context, $user_info; - - $context['time_format'] = urlencode($user_info['time_format']); + /** + * Show a list of all the group requests they can see. + * Checks permissions for group moderation. + */ + public function block_groupRequests() + { + global $context, $user_info, $scripturl; - // Return the template to use. - return 'latest_news'; -} + $db = database(); -/** - * Show a list of the most active watched users. - */ -function ModBlockWatchedUsers() -{ - global $context, $scripturl, $modSettings; + $context['group_requests'] = array(); - $db = database(); + // Make sure they can even moderate someone! + if ($user_info['mod_cache']['gq'] == '0=1') + return 'group_requests_block'; - if (($watched_users = cache_get_data('recent_user_watches', 240)) === null) - { - $modSettings['warning_watch'] = empty($modSettings['warning_watch']) ? 1 : $modSettings['warning_watch']; + // What requests are outstanding? $request = $db->query('', ' - SELECT id_member, real_name, last_login - FROM {db_prefix}members - WHERE warning >= {int:warning_watch} - ORDER BY last_login DESC + SELECT lgr.id_request, lgr.id_member, lgr.id_group, lgr.time_applied, mem.member_name, mg.group_name, mem.real_name + FROM {db_prefix}log_group_requests AS lgr + INNER JOIN {db_prefix}members AS mem ON (mem.id_member = lgr.id_member) + INNER JOIN {db_prefix}membergroups AS mg ON (mg.id_group = lgr.id_group) + WHERE ' . ($user_info['mod_cache']['gq'] == '1=1' || $user_info['mod_cache']['gq'] == '0=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']) . ' + ORDER BY lgr.id_request DESC LIMIT 10', array( - 'warning_watch' => $modSettings['warning_watch'], ) ); - $watched_users = array(); - while ($row = $db->fetch_assoc($request)) - $watched_users[] = $row; + for ($i = 0; $row = $db->fetch_assoc($request); $i ++) + { + $context['group_requests'][] = array( + 'id' => $row['id_request'], + 'alternate' => $i % 2, + 'request_href' => $scripturl . '?action=groups;sa=requests;gid=' . $row['id_group'], + 'member' => array( + 'id' => $row['id_member'], + 'name' => $row['real_name'], + 'link' => '' . $row['real_name'] . '', + 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], + ), + 'group' => array( + 'id' => $row['id_group'], + 'name' => $row['group_name'], + ), + 'time_submitted' => standardTime($row['time_applied']), + ); + } $db->free_result($request); - cache_put_data('recent_user_watches', $watched_users, 240); + return 'group_requests_block'; } - $context['watched_users'] = array(); - foreach ($watched_users as $user) + /** + * Just prepares the time stuff for the latest news. + */ + public function block_latestNews() { - $context['watched_users'][] = array( - 'id' => $user['id_member'], - 'name' => $user['real_name'], - 'link' => '' . $user['real_name'] . '', - 'href' => $scripturl . '?action=profile;u=' . $user['id_member'], - 'last_login' => !empty($user['last_login']) ? standardTime($user['last_login']) : '', - ); - } - - return 'watched_users'; -} + global $context, $user_info; -/** - * Show an area for the moderator to type into. - */ -function ModBlockNotes() -{ - global $context, $scripturl, $txt, $user_info; + $context['time_format'] = urlencode($user_info['time_format']); - $db = database(); + // Return the template to use. + return 'latest_news'; + } - // Are we saving a note? - if (isset($_POST['makenote']) && isset($_POST['new_note'])) + /** + * Show a list of the most active watched users. + */ + public function block_watchedUsers() { - checkSession(); + global $context, $scripturl, $modSettings; - $_POST['new_note'] = Util::htmlspecialchars(trim($_POST['new_note'])); + $db = database(); - // Make sure they actually entered something. - if (!empty($_POST['new_note']) && $_POST['new_note'] !== $txt['mc_click_add_note']) + if (($watched_users = cache_get_data('recent_user_watches', 240)) === null) { - // Insert it into the database then! - $db->insert('', - '{db_prefix}log_comments', - array( - 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'recipient_name' => 'string', - 'body' => 'string', 'log_time' => 'int', - ), + $modSettings['warning_watch'] = empty($modSettings['warning_watch']) ? 1 : $modSettings['warning_watch']; + $request = $db->query('', ' + SELECT id_member, real_name, last_login + FROM {db_prefix}members + WHERE warning >= {int:warning_watch} + ORDER BY last_login DESC + LIMIT 10', array( - $user_info['id'], $user_info['name'], 'modnote', '', $_POST['new_note'], time(), - ), - array('id_comment') + 'warning_watch' => $modSettings['warning_watch'], + ) ); + $watched_users = array(); + while ($row = $db->fetch_assoc($request)) + $watched_users[] = $row; + $db->free_result($request); - // Clear the cache. - cache_put_data('moderator_notes', null, 240); - cache_put_data('moderator_notes_total', null, 240); + cache_put_data('recent_user_watches', $watched_users, 240); } - // Redirect otherwise people can resubmit. - redirectexit('action=moderate'); + $context['watched_users'] = array(); + foreach ($watched_users as $user) + { + $context['watched_users'][] = array( + 'id' => $user['id_member'], + 'name' => $user['real_name'], + 'link' => '' . $user['real_name'] . '', + 'href' => $scripturl . '?action=profile;u=' . $user['id_member'], + 'last_login' => !empty($user['last_login']) ? standardTime($user['last_login']) : '', + ); + } + + return 'watched_users'; } - // Bye... bye... - if (isset($_GET['notes']) && isset($_GET['delete']) && is_numeric($_GET['delete'])) + /** + * Show an area for the moderator to type into. + */ + public function block_notes() { - checkSession('get'); + global $context, $scripturl, $txt, $user_info; - // Lets delete it. - $db->query('', ' - DELETE FROM {db_prefix}log_comments - WHERE id_comment = {int:note} - AND comment_type = {string:type}', - array( - 'note' => $_GET['delete'], - 'type' => 'modnote', - ) - ); + $db = database(); - // Clear the cache. - cache_put_data('moderator_notes', null, 240); - cache_put_data('moderator_notes_total', null, 240); + // Are we saving a note? + if (isset($_POST['makenote']) && isset($_POST['new_note'])) + { + checkSession(); - redirectexit('action=moderate'); - } + $_POST['new_note'] = Util::htmlspecialchars(trim($_POST['new_note'])); - // How many notes in total? - if (($moderator_notes_total = cache_get_data('moderator_notes_total', 240)) === null) - { - $request = $db->query('', ' - SELECT COUNT(*) - FROM {db_prefix}log_comments AS lc - LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member) - WHERE lc.comment_type = {string:modnote}', - array( - 'modnote' => 'modnote', - ) - ); - list ($moderator_notes_total) = $db->fetch_row($request); - $db->free_result($request); + // Make sure they actually entered something. + if (!empty($_POST['new_note']) && $_POST['new_note'] !== $txt['mc_click_add_note']) + { + // Insert it into the database then! + $db->insert('', + '{db_prefix}log_comments', + array( + 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'recipient_name' => 'string', + 'body' => 'string', 'log_time' => 'int', + ), + array( + $user_info['id'], $user_info['name'], 'modnote', '', $_POST['new_note'], time(), + ), + array('id_comment') + ); - cache_put_data('moderator_notes_total', $moderator_notes_total, 240); - } + // Clear the cache. + cache_put_data('moderator_notes', null, 240); + cache_put_data('moderator_notes_total', null, 240); + } - // Grab the current notes. We can only use the cache for the first page of notes. - $offset = isset($_GET['notes']) && isset($_GET['start']) ? $_GET['start'] : 0; - if ($offset != 0 || ($moderator_notes = cache_get_data('moderator_notes', 240)) === null) - { - $request = $db->query('', ' - SELECT IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS member_name, - lc.log_time, lc.body, lc.id_comment AS id_note - FROM {db_prefix}log_comments AS lc - LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member) - WHERE lc.comment_type = {string:modnote} - ORDER BY id_comment DESC - LIMIT {int:offset}, 10', - array( - 'modnote' => 'modnote', - 'offset' => $offset, - ) - ); - $moderator_notes = array(); - while ($row = $db->fetch_assoc($request)) - $moderator_notes[] = $row; - $db->free_result($request); + // Redirect otherwise people can resubmit. + redirectexit('action=moderate'); + } - if ($offset == 0) - cache_put_data('moderator_notes', $moderator_notes, 240); - } + // Bye... bye... + if (isset($_GET['notes']) && isset($_GET['delete']) && is_numeric($_GET['delete'])) + { + checkSession('get'); - // Lets construct a page index. - $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=index;notes', $_GET['start'], $moderator_notes_total, 10); - $context['start'] = $_GET['start']; + // Lets delete it. + $db->query('', ' + DELETE FROM {db_prefix}log_comments + WHERE id_comment = {int:note} + AND comment_type = {string:type}', + array( + 'note' => $_GET['delete'], + 'type' => 'modnote', + ) + ); - $context['notes'] = array(); - foreach ($moderator_notes as $note) - { - $context['notes'][] = array( - 'author' => array( - 'id' => $note['id_member'], - 'link' => $note['id_member'] ? ('' . $note['member_name'] . '') : $note['member_name'], - ), - 'time' => standardTime($note['log_time']), - 'text' => parse_bbc($note['body']), - 'delete_href' => $scripturl . '?action=moderate;area=index;notes;delete=' . $note['id_note'] . ';' . $context['session_var'] . '=' . $context['session_id'], - ); - } + // Clear the cache. + cache_put_data('moderator_notes', null, 240); + cache_put_data('moderator_notes_total', null, 240); - return 'notes'; -} + redirectexit('action=moderate'); + } -/** - * Show a list of the most recent reported posts. - */ -function ModBlockReportedPosts() -{ - global $context, $user_info, $scripturl; + // How many notes in total? + if (($moderator_notes_total = cache_get_data('moderator_notes_total', 240)) === null) + { + $request = $db->query('', ' + SELECT COUNT(*) + FROM {db_prefix}log_comments AS lc + LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member) + WHERE lc.comment_type = {string:modnote}', + array( + 'modnote' => 'modnote', + ) + ); + list ($moderator_notes_total) = $db->fetch_row($request); + $db->free_result($request); - $db = database(); + cache_put_data('moderator_notes_total', $moderator_notes_total, 240); + } - // Got the info already? - $cachekey = md5(serialize($user_info['mod_cache']['bq'])); - $context['reported_posts'] = array(); + // Grab the current notes. We can only use the cache for the first page of notes. + $offset = isset($_GET['notes']) && isset($_GET['start']) ? $_GET['start'] : 0; + if ($offset != 0 || ($moderator_notes = cache_get_data('moderator_notes', 240)) === null) + { + $request = $db->query('', ' + SELECT IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS member_name, + lc.log_time, lc.body, lc.id_comment AS id_note + FROM {db_prefix}log_comments AS lc + LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member) + WHERE lc.comment_type = {string:modnote} + ORDER BY id_comment DESC + LIMIT {int:offset}, 10', + array( + 'modnote' => 'modnote', + 'offset' => $offset, + ) + ); + $moderator_notes = array(); + while ($row = $db->fetch_assoc($request)) + $moderator_notes[] = $row; + $db->free_result($request); - if ($user_info['mod_cache']['bq'] == '0=1') - return 'reported_posts_block'; + if ($offset == 0) + cache_put_data('moderator_notes', $moderator_notes, 240); + } - if (($reported_posts = cache_get_data('reported_posts_' . $cachekey, 90)) === null) - { - // By George, that means we in a position to get the reports, jolly good. - $request = $db->query('', ' - SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, - lr.num_reports, IFNULL(mem.real_name, lr.membername) AS author_name, - IFNULL(mem.id_member, 0) AS id_author - FROM {db_prefix}log_reported AS lr - LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member) - WHERE ' . ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1' ? $user_info['mod_cache']['bq'] : 'lr.' . $user_info['mod_cache']['bq']) . ' - AND lr.closed = {int:not_closed} - AND lr.ignore_all = {int:not_ignored} - ORDER BY lr.time_updated DESC - LIMIT 10', - array( - 'not_closed' => 0, - 'not_ignored' => 0, - ) - ); - $reported_posts = array(); - while ($row = $db->fetch_assoc($request)) - $reported_posts[] = $row; - $db->free_result($request); + // Lets construct a page index. + $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=index;notes', $_GET['start'], $moderator_notes_total, 10); + $context['start'] = $_GET['start']; + + $context['notes'] = array(); + foreach ($moderator_notes as $note) + { + $context['notes'][] = array( + 'author' => array( + 'id' => $note['id_member'], + 'link' => $note['id_member'] ? ('' . $note['member_name'] . '') : $note['member_name'], + ), + 'time' => standardTime($note['log_time']), + 'text' => parse_bbc($note['body']), + 'delete_href' => $scripturl . '?action=moderate;area=index;notes;delete=' . $note['id_note'] . ';' . $context['session_var'] . '=' . $context['session_id'], + ); + } - // Cache it. - cache_put_data('reported_posts_' . $cachekey, $reported_posts, 90); + return 'notes'; } - $context['reported_posts'] = array(); - foreach ($reported_posts as $i => $row) + /** + * Show a list of the most recent reported posts. + */ + public function block_reportedPosts() { - $context['reported_posts'][] = array( - 'id' => $row['id_report'], - 'alternate' => $i % 2, - 'topic_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'], - 'report_href' => $scripturl . '?action=moderate;area=reports;report=' . $row['id_report'], - 'author' => array( - 'id' => $row['id_author'], - 'name' => $row['author_name'], - 'link' => $row['id_author'] ? '' . $row['author_name'] . '' : $row['author_name'], - 'href' => $scripturl . '?action=profile;u=' . $row['id_author'], - ), - 'comments' => array(), - 'subject' => $row['subject'], - 'num_reports' => $row['num_reports'], - ); - } + global $context, $user_info, $scripturl; - return 'reported_posts_block'; -} + $db = database(); -/** - * Show a list of all the group requests they can see. - * Checks permissions for group moderation. - */ -function ModBlockGroupRequests() -{ - global $context, $user_info, $scripturl; + // Got the info already? + $cachekey = md5(serialize($user_info['mod_cache']['bq'])); + $context['reported_posts'] = array(); - $db = database(); + if ($user_info['mod_cache']['bq'] == '0=1') + return 'reported_posts_block'; - $context['group_requests'] = array(); + if (($reported_posts = cache_get_data('reported_posts_' . $cachekey, 90)) === null) + { + // By George, that means we in a position to get the reports, jolly good. + $request = $db->query('', ' + SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, + lr.num_reports, IFNULL(mem.real_name, lr.membername) AS author_name, + IFNULL(mem.id_member, 0) AS id_author + FROM {db_prefix}log_reported AS lr + LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member) + WHERE ' . ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1' ? $user_info['mod_cache']['bq'] : 'lr.' . $user_info['mod_cache']['bq']) . ' + AND lr.closed = {int:not_closed} + AND lr.ignore_all = {int:not_ignored} + ORDER BY lr.time_updated DESC + LIMIT 10', + array( + 'not_closed' => 0, + 'not_ignored' => 0, + ) + ); + $reported_posts = array(); + while ($row = $db->fetch_assoc($request)) + $reported_posts[] = $row; + $db->free_result($request); - // Make sure they can even moderate someone! - if ($user_info['mod_cache']['gq'] == '0=1') - return 'group_requests_block'; + // Cache it. + cache_put_data('reported_posts_' . $cachekey, $reported_posts, 90); + } - // What requests are outstanding? - $request = $db->query('', ' - SELECT lgr.id_request, lgr.id_member, lgr.id_group, lgr.time_applied, mem.member_name, mg.group_name, mem.real_name - FROM {db_prefix}log_group_requests AS lgr - INNER JOIN {db_prefix}members AS mem ON (mem.id_member = lgr.id_member) - INNER JOIN {db_prefix}membergroups AS mg ON (mg.id_group = lgr.id_group) - WHERE ' . ($user_info['mod_cache']['gq'] == '1=1' || $user_info['mod_cache']['gq'] == '0=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']) . ' - ORDER BY lgr.id_request DESC - LIMIT 10', - array( - ) - ); - for ($i = 0; $row = $db->fetch_assoc($request); $i ++) - { - $context['group_requests'][] = array( - 'id' => $row['id_request'], - 'alternate' => $i % 2, - 'request_href' => $scripturl . '?action=groups;sa=requests;gid=' . $row['id_group'], - 'member' => array( - 'id' => $row['id_member'], - 'name' => $row['real_name'], - 'link' => '' . $row['real_name'] . '', - 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], - ), - 'group' => array( - 'id' => $row['id_group'], - 'name' => $row['group_name'], - ), - 'time_submitted' => standardTime($row['time_applied']), - ); - } - $db->free_result($request); + $context['reported_posts'] = array(); + foreach ($reported_posts as $i => $row) + { + $context['reported_posts'][] = array( + 'id' => $row['id_report'], + 'alternate' => $i % 2, + 'topic_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'], + 'report_href' => $scripturl . '?action=moderate;area=reports;report=' . $row['id_report'], + 'author' => array( + 'id' => $row['id_author'], + 'name' => $row['author_name'], + 'link' => $row['id_author'] ? '' . $row['author_name'] . '' : $row['author_name'], + 'href' => $scripturl . '?action=profile;u=' . $row['id_author'], + ), + 'comments' => array(), + 'subject' => $row['subject'], + 'num_reports' => $row['num_reports'], + ); + } - return 'group_requests_block'; -} + return 'reported_posts_block'; + } +} \ No newline at end of file From 9b0ac9761efbc5a6618e3004d71e9ebd432ceb69 Mon Sep 17 00:00:00 2001 From: Norv Date: Mon, 24 Jun 2013 05:57:50 +0300 Subject: [PATCH 30/34] Moderator blocks code redesigned. Signed-off-by: Norv --- .../ModerationCenter.controller.php | 166 +------------ sources/subs/Moderation.subs.php | 229 ++++++++++++++++++ 2 files changed, 242 insertions(+), 153 deletions(-) diff --git a/sources/controllers/ModerationCenter.controller.php b/sources/controllers/ModerationCenter.controller.php index de3ae15c69..b6a851c52a 100644 --- a/sources/controllers/ModerationCenter.controller.php +++ b/sources/controllers/ModerationCenter.controller.php @@ -1554,46 +1554,11 @@ public function block_groupRequests() { global $context, $user_info, $scripturl; - $db = database(); - - $context['group_requests'] = array(); - // Make sure they can even moderate someone! if ($user_info['mod_cache']['gq'] == '0=1') return 'group_requests_block'; - // What requests are outstanding? - $request = $db->query('', ' - SELECT lgr.id_request, lgr.id_member, lgr.id_group, lgr.time_applied, mem.member_name, mg.group_name, mem.real_name - FROM {db_prefix}log_group_requests AS lgr - INNER JOIN {db_prefix}members AS mem ON (mem.id_member = lgr.id_member) - INNER JOIN {db_prefix}membergroups AS mg ON (mg.id_group = lgr.id_group) - WHERE ' . ($user_info['mod_cache']['gq'] == '1=1' || $user_info['mod_cache']['gq'] == '0=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']) . ' - ORDER BY lgr.id_request DESC - LIMIT 10', - array( - ) - ); - for ($i = 0; $row = $db->fetch_assoc($request); $i ++) - { - $context['group_requests'][] = array( - 'id' => $row['id_request'], - 'alternate' => $i % 2, - 'request_href' => $scripturl . '?action=groups;sa=requests;gid=' . $row['id_group'], - 'member' => array( - 'id' => $row['id_member'], - 'name' => $row['real_name'], - 'link' => '' . $row['real_name'] . '', - 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], - ), - 'group' => array( - 'id' => $row['id_group'], - 'name' => $row['group_name'], - ), - 'time_submitted' => standardTime($row['time_applied']), - ); - } - $db->free_result($request); + $context['group_requests'] = groupRequests(); return 'group_requests_block'; } @@ -1618,28 +1583,7 @@ public function block_watchedUsers() { global $context, $scripturl, $modSettings; - $db = database(); - - if (($watched_users = cache_get_data('recent_user_watches', 240)) === null) - { - $modSettings['warning_watch'] = empty($modSettings['warning_watch']) ? 1 : $modSettings['warning_watch']; - $request = $db->query('', ' - SELECT id_member, real_name, last_login - FROM {db_prefix}members - WHERE warning >= {int:warning_watch} - ORDER BY last_login DESC - LIMIT 10', - array( - 'warning_watch' => $modSettings['warning_watch'], - ) - ); - $watched_users = array(); - while ($row = $db->fetch_assoc($request)) - $watched_users[] = $row; - $db->free_result($request); - - cache_put_data('recent_user_watches', $watched_users, 240); - } + $watched_users = basicWatchedUsers(); $context['watched_users'] = array(); foreach ($watched_users as $user) @@ -1670,23 +1614,13 @@ public function block_notes() { checkSession(); - $_POST['new_note'] = Util::htmlspecialchars(trim($_POST['new_note'])); + $new_note = Util::htmlspecialchars(trim($_POST['new_note'])); // Make sure they actually entered something. - if (!empty($_POST['new_note']) && $_POST['new_note'] !== $txt['mc_click_add_note']) + if (!empty($new_note) && $new_note !== $txt['mc_click_add_note']) { // Insert it into the database then! - $db->insert('', - '{db_prefix}log_comments', - array( - 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'recipient_name' => 'string', - 'body' => 'string', 'log_time' => 'int', - ), - array( - $user_info['id'], $user_info['name'], 'modnote', '', $_POST['new_note'], time(), - ), - array('id_comment') - ); + addModeratorNote($user_info['id'], $user_info['name'], $new_note); // Clear the cache. cache_put_data('moderator_notes', null, 240); @@ -1702,16 +1636,11 @@ public function block_notes() { checkSession('get'); + // Just checkin'! + $id_delete = (int) $_GET['delete']; + // Lets delete it. - $db->query('', ' - DELETE FROM {db_prefix}log_comments - WHERE id_comment = {int:note} - AND comment_type = {string:type}', - array( - 'note' => $_GET['delete'], - 'type' => 'modnote', - ) - ); + removeModeratorNote($id_delete); // Clear the cache. cache_put_data('moderator_notes', null, 240); @@ -1721,48 +1650,11 @@ public function block_notes() } // How many notes in total? - if (($moderator_notes_total = cache_get_data('moderator_notes_total', 240)) === null) - { - $request = $db->query('', ' - SELECT COUNT(*) - FROM {db_prefix}log_comments AS lc - LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member) - WHERE lc.comment_type = {string:modnote}', - array( - 'modnote' => 'modnote', - ) - ); - list ($moderator_notes_total) = $db->fetch_row($request); - $db->free_result($request); - - cache_put_data('moderator_notes_total', $moderator_notes_total, 240); - } + $moderator_notes_total = countModeratorNotes(); // Grab the current notes. We can only use the cache for the first page of notes. $offset = isset($_GET['notes']) && isset($_GET['start']) ? $_GET['start'] : 0; - if ($offset != 0 || ($moderator_notes = cache_get_data('moderator_notes', 240)) === null) - { - $request = $db->query('', ' - SELECT IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS member_name, - lc.log_time, lc.body, lc.id_comment AS id_note - FROM {db_prefix}log_comments AS lc - LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member) - WHERE lc.comment_type = {string:modnote} - ORDER BY id_comment DESC - LIMIT {int:offset}, 10', - array( - 'modnote' => 'modnote', - 'offset' => $offset, - ) - ); - $moderator_notes = array(); - while ($row = $db->fetch_assoc($request)) - $moderator_notes[] = $row; - $db->free_result($request); - - if ($offset == 0) - cache_put_data('moderator_notes', $moderator_notes, 240); - } + $moderator_notes = moderatorNotes($offset); // Lets construct a page index. $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=index;notes', $_GET['start'], $moderator_notes_total, 10); @@ -1792,44 +1684,12 @@ public function block_reportedPosts() { global $context, $user_info, $scripturl; - $db = database(); - - // Got the info already? - $cachekey = md5(serialize($user_info['mod_cache']['bq'])); - $context['reported_posts'] = array(); - if ($user_info['mod_cache']['bq'] == '0=1') return 'reported_posts_block'; - if (($reported_posts = cache_get_data('reported_posts_' . $cachekey, 90)) === null) - { - // By George, that means we in a position to get the reports, jolly good. - $request = $db->query('', ' - SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, - lr.num_reports, IFNULL(mem.real_name, lr.membername) AS author_name, - IFNULL(mem.id_member, 0) AS id_author - FROM {db_prefix}log_reported AS lr - LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member) - WHERE ' . ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1' ? $user_info['mod_cache']['bq'] : 'lr.' . $user_info['mod_cache']['bq']) . ' - AND lr.closed = {int:not_closed} - AND lr.ignore_all = {int:not_ignored} - ORDER BY lr.time_updated DESC - LIMIT 10', - array( - 'not_closed' => 0, - 'not_ignored' => 0, - ) - ); - $reported_posts = array(); - while ($row = $db->fetch_assoc($request)) - $reported_posts[] = $row; - $db->free_result($request); - - // Cache it. - cache_put_data('reported_posts_' . $cachekey, $reported_posts, 90); - } - $context['reported_posts'] = array(); + + $reported_posts = reportedPosts(); foreach ($reported_posts as $i => $row) { $context['reported_posts'][] = array( diff --git a/sources/subs/Moderation.subs.php b/sources/subs/Moderation.subs.php index d22c6f22c8..4deb4f5e61 100644 --- a/sources/subs/Moderation.subs.php +++ b/sources/subs/Moderation.subs.php @@ -873,4 +873,233 @@ function watchedUserPosts($start, $items_per_page, $sort, $approve_query, $delet $db->free_result($request); return $member_posts; +} + +/** + * Show a list of all the group requests they can see. + * Checks permissions for group moderation. + */ +function groupRequests() +{ + global $user_info, $scripturl; + + $db = database(); + + $group_requests = array(); + + // Make sure they can even moderate someone! + if ($user_info['mod_cache']['gq'] == '0=1') + return 'group_requests_block'; + + // What requests are outstanding? + $request = $db->query('', ' + SELECT lgr.id_request, lgr.id_member, lgr.id_group, lgr.time_applied, mem.member_name, mg.group_name, mem.real_name + FROM {db_prefix}log_group_requests AS lgr + INNER JOIN {db_prefix}members AS mem ON (mem.id_member = lgr.id_member) + INNER JOIN {db_prefix}membergroups AS mg ON (mg.id_group = lgr.id_group) + WHERE ' . ($user_info['mod_cache']['gq'] == '1=1' || $user_info['mod_cache']['gq'] == '0=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']) . ' + ORDER BY lgr.id_request DESC + LIMIT 10', + array( + ) + ); + for ($i = 0; $row = $db->fetch_assoc($request); $i ++) + { + $group_requests[] = array( + 'id' => $row['id_request'], + 'alternate' => $i % 2, + 'request_href' => $scripturl . '?action=groups;sa=requests;gid=' . $row['id_group'], + 'member' => array( + 'id' => $row['id_member'], + 'name' => $row['real_name'], + 'link' => '' . $row['real_name'] . '', + 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], + ), + 'group' => array( + 'id' => $row['id_group'], + 'name' => $row['group_name'], + ), + 'time_submitted' => standardTime($row['time_applied']), + ); + } + $db->free_result($request); + + return $group_requests; +} + +/** + * Returns an array of basic info about the most active watched users. + */ +function basicWatchedUsers() +{ + global $scripturl, $modSettings; + + $db = database(); + + if (($watched_users = cache_get_data('recent_user_watches', 240)) === null) + { + $modSettings['warning_watch'] = empty($modSettings['warning_watch']) ? 1 : $modSettings['warning_watch']; + $request = $db->query('', ' + SELECT id_member, real_name, last_login + FROM {db_prefix}members + WHERE warning >= {int:warning_watch} + ORDER BY last_login DESC + LIMIT 10', + array( + 'warning_watch' => $modSettings['warning_watch'], + ) + ); + $watched_users = array(); + while ($row = $db->fetch_assoc($request)) + $watched_users[] = $row; + $db->free_result($request); + + cache_put_data('recent_user_watches', $watched_users, 240); + } + + return $watched_users; +} + +/** + * Returns the most recent reported posts as array + * + * @return array + */ +function reportedPosts() +{ + global $user_info, $scripturl; + + $db = database(); + + // Got the info already? + $cachekey = md5(serialize($user_info['mod_cache']['bq'])); + + if (($reported_posts = cache_get_data('reported_posts_' . $cachekey, 90)) === null) + { + // By George, that means we in a position to get the reports, jolly good. + $request = $db->query('', ' + SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, + lr.num_reports, IFNULL(mem.real_name, lr.membername) AS author_name, + IFNULL(mem.id_member, 0) AS id_author + FROM {db_prefix}log_reported AS lr + LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member) + WHERE ' . ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1' ? $user_info['mod_cache']['bq'] : 'lr.' . $user_info['mod_cache']['bq']) . ' + AND lr.closed = {int:not_closed} + AND lr.ignore_all = {int:not_ignored} + ORDER BY lr.time_updated DESC + LIMIT 10', + array( + 'not_closed' => 0, + 'not_ignored' => 0, + ) + ); + $reported_posts = array(); + while ($row = $db->fetch_assoc($request)) + $reported_posts[] = $row; + $db->free_result($request); + + // Cache it. + cache_put_data('reported_posts_' . $cachekey, $reported_posts, 90); + } + + return $reported_posts; +} + +/** + * Remove a moderator note. + */ +function removeModeratorNote($id_note) +{ + $db = database(); + + // Lets delete it. + $db->query('', ' + DELETE FROM {db_prefix}log_comments + WHERE id_comment = {int:note} + AND comment_type = {string:type}', + array( + 'note' => $id_note, + 'type' => 'modnote', + ) + ); +} + +/** + * Get the number of moderator notes stored on the site. + * + * @return int + */ +function countModeratorNotes() +{ + $db = database(); + + if (($moderator_notes_total = cache_get_data('moderator_notes_total', 240)) === null) + { + $request = $db->query('', ' + SELECT COUNT(*) + FROM {db_prefix}log_comments AS lc + LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member) + WHERE lc.comment_type = {string:modnote}', + array( + 'modnote' => 'modnote', + ) + ); + list ($moderator_notes_total) = $db->fetch_row($request); + $db->free_result($request); + + cache_put_data('moderator_notes_total', $moderator_notes_total, 240); + } + + return $moderator_notes_total; +} + +function addModeratorNote($id_poster, $poster_name, $contents) +{ + $db = database(); + + // Insert it into the database + $db->insert('', + '{db_prefix}log_comments', + array( + 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'recipient_name' => 'string', + 'body' => 'string', 'log_time' => 'int', + ), + array( + $id_poster, $poster_name, 'modnote', '', $contents, time(), + ), + array('id_comment') + ); +} + +function moderatorNotes($offset) +{ + $db = database(); + + // Grab the current notes. + // We can only use the cache for the first page of notes. + if ($offset != 0 || ($moderator_notes = cache_get_data('moderator_notes', 240)) === null) + { + $request = $db->query('', ' + SELECT IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS member_name, + lc.log_time, lc.body, lc.id_comment AS id_note + FROM {db_prefix}log_comments AS lc + LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member) + WHERE lc.comment_type = {string:modnote} + ORDER BY id_comment DESC + LIMIT {int:offset}, 10', + array( + 'modnote' => 'modnote', + 'offset' => $offset, + ) + ); + $moderator_notes = array(); + while ($row = $db->fetch_assoc($request)) + $moderator_notes[] = $row; + $db->free_result($request); + + if ($offset == 0) + cache_put_data('moderator_notes', $moderator_notes, 240); + } + + return $moderator_notes; } \ No newline at end of file From 8357325e77628376261e71ca1803fc8d42259ea3 Mon Sep 17 00:00:00 2001 From: Norv Date: Mon, 24 Jun 2013 06:33:48 +0300 Subject: [PATCH 31/34] Make moderatorNotice() function also in moderation subs, and clean some more the mod center controller. Signed-off-by: Norv --- .../ModerationCenter.controller.php | 13 +++-------- sources/subs/Moderation.subs.php | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/sources/controllers/ModerationCenter.controller.php b/sources/controllers/ModerationCenter.controller.php index b6a851c52a..386ca6062b 100644 --- a/sources/controllers/ModerationCenter.controller.php +++ b/sources/controllers/ModerationCenter.controller.php @@ -339,17 +339,10 @@ public function action_showNotice() // @todo Assumes nothing needs permission more than accessing moderation center! $id_notice = (int) $_GET['nid']; - $request = $db->query('', ' - SELECT body, subject - FROM {db_prefix}log_member_notices - WHERE id_notice = {int:id_notice}', - array( - 'id_notice' => $id_notice, - ) - ); - if ($db->num_rows($request) == 0) + $notice = moderatorNotice($id_notice); + if (empty($notice)) fatal_lang_error('no_access', false); - list ($context['notice_body'], $context['notice_subject']) = $db->fetch_row($request); + list ($context['notice_body'], $context['notice_subject']) = $notice; $db->free_result($request); $context['notice_body'] = parse_bbc($context['notice_body'], false); diff --git a/sources/subs/Moderation.subs.php b/sources/subs/Moderation.subs.php index 4deb4f5e61..5088c93952 100644 --- a/sources/subs/Moderation.subs.php +++ b/sources/subs/Moderation.subs.php @@ -1102,4 +1102,26 @@ function moderatorNotes($offset) } return $moderator_notes; +} + +function moderatorNotice($id_notice) +{ + $db = database(); + + $request = $db->query('', ' + SELECT body, subject + FROM {db_prefix}log_member_notices + WHERE id_notice = {int:id_notice}', + array( + 'id_notice' => $id_notice, + ) + ); + if ($db->num_rows($request) == 0) + return array(); + list ($notice_body, $notice_subject) = $db->fetch_row($request); + $db->free_result($request); + + $notice_body = parse_bbc($notice_body, false); + + return array($notice_body, $notice_subject); } \ No newline at end of file From 992c56c373aa8176504c9401b38f044249c3d190 Mon Sep 17 00:00:00 2001 From: Norv Date: Tue, 25 Jun 2013 21:13:49 +0300 Subject: [PATCH 32/34] Adapt list_ callbacks as controller methods, and respective subs functions. Signed-off-by: Norv --- sources/admin/ManageNews.php | 11 + sources/admin/ManageSearchEngines.php | 219 ++++++------------ .../controllers/ProfileInfo.controller.php | 111 ++------- sources/subs/ManageNews.subs.php | 4 +- sources/subs/Profile.subs.php | 119 ++++++++++ sources/subs/SearchEngines.subs.php | 155 +++++++++++++ 6 files changed, 371 insertions(+), 248 deletions(-) diff --git a/sources/admin/ManageNews.php b/sources/admin/ManageNews.php index 381bd94afe..fe6cc629fd 100644 --- a/sources/admin/ManageNews.php +++ b/sources/admin/ManageNews.php @@ -922,4 +922,15 @@ public function settings() return $config_vars; } + + /** + * Prepares an array of the forum news items for display in the template + * Callback for createList() + * + * @return array + */ + function list_getNews() + { + return getNews(); + } } diff --git a/sources/admin/ManageSearchEngines.php b/sources/admin/ManageSearchEngines.php index 9874949884..26d6dbf0f4 100644 --- a/sources/admin/ManageSearchEngines.php +++ b/sources/admin/ManageSearchEngines.php @@ -283,10 +283,10 @@ function action_spiders() 'base_href' => $scripturl . '?action=admin;area=sengines;sa=spiders', 'default_sort_col' => 'name', 'get_items' => array( - 'function' => 'list_getSpiders', + 'function' => array($this, 'list_getSpiders'), ), 'get_count' => array( - 'function' => 'list_getNumSpiders', + 'function' => array($this, 'list_getNumSpiders'), ), 'no_items_label' => $txt['spiders_no_entries'], 'columns' => array( @@ -519,10 +519,10 @@ function action_logs() 'base_href' => $context['admin_area'] == 'sengines' ? $scripturl . '?action=admin;area=sengines;sa=logs' : $scripturl . '?action=admin;area=logs;sa=spiderlog', 'default_sort_col' => 'log_time', 'get_items' => array( - 'function' => 'list_getSpiderLogs', + 'function' => array($this, 'list_getSpiderLogs'), ), 'get_count' => array( - 'function' => 'list_getNumSpiderLogs', + 'function' => array($this, 'list_getNumSpiderLogs'), ), 'columns' => array( 'name' => array( @@ -722,10 +722,10 @@ function action_stats() 'base_href' => $scripturl . '?action=admin;area=sengines;sa=stats', 'default_sort_col' => 'stat_date', 'get_items' => array( - 'function' => 'list_getSpiderStats', + 'function' => array($this, 'list_getSpiderStats'), ), 'get_count' => array( - 'function' => 'list_getNumSpiderStats', + 'function' => array($this, 'list_getNumSpiderStats'), ), 'no_items_label' => $txt['spider_stats_no_entries'], 'columns' => array( @@ -786,151 +786,74 @@ function action_stats() $context['sub_template'] = 'show_spider_stats'; } -} -/** - * Callback function for createList() - * @param int $start - * @param int $items_per_page - * @param string sort - */ -function list_getSpiders($start, $items_per_page, $sort) -{ - $db = database(); - - $request = $db->query('', ' - SELECT id_spider, spider_name, user_agent, ip_info - FROM {db_prefix}spiders - ORDER BY ' . $sort . ' - LIMIT ' . $start . ', ' . $items_per_page, - array( - ) - ); - $spiders = array(); - while ($row = $db->fetch_assoc($request)) - $spiders[$row['id_spider']] = $row; - $db->free_result($request); - - return $spiders; -} - -/** - * Callback function for createList() - * @return int - */ -function list_getNumSpiders() -{ - $db = database(); - - $request = $db->query('', ' - SELECT COUNT(*) AS num_spiders - FROM {db_prefix}spiders', - array( - ) - ); - list ($numSpiders) = $db->fetch_row($request); - $db->free_result($request); - - return $numSpiders; -} - -/** - * Callback function for createList() - * - * @param int $start - * @param int $items_per_page - * @param string $sort - * @return array - */ -function list_getSpiderLogs($start, $items_per_page, $sort) -{ - $db = database(); - - $request = $db->query('', ' - SELECT sl.id_spider, sl.url, sl.log_time, s.spider_name - FROM {db_prefix}log_spider_hits AS sl - INNER JOIN {db_prefix}spiders AS s ON (s.id_spider = sl.id_spider) - ORDER BY ' . $sort . ' - LIMIT ' . $start . ', ' . $items_per_page, - array( - ) - ); - $spider_logs = array(); - while ($row = $db->fetch_assoc($request)) - $spider_logs[] = $row; - $db->free_result($request); - - return $spider_logs; -} + /** + * Callback function for createList() + * + * @param int $start + * @param int $items_per_page + * @param string sort + * @return array + */ + function list_getSpiders($start, $items_per_page, $sort) + { + // retrieve spiders within these limits + return getSpiders($start, $items_per_page, $sort); + } -/** - * Callback function for createList() - * @return int - */ -function list_getNumSpiderLogs() -{ - $db = database(); + /** + * Callback function for createList() + * + * @return int + */ + function list_getNumSpiders() + { + return getNumSpiders(); + } - $request = $db->query('', ' - SELECT COUNT(*) AS num_logs - FROM {db_prefix}log_spider_hits', - array( - ) - ); - list ($numLogs) = $db->fetch_row($request); - $db->free_result($request); + /** + * Callback function for createList() + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @return array + */ + function list_getSpiderLogs($start, $items_per_page, $sort) + { + return getSpiderLogs($start, $items_per_page, $sort); + } - return $numLogs; -} + /** + * Callback function for createList() + * + * @return int + */ + function list_getNumSpiderLogs() + { + return getNumSpiderLogs(); + } -/** - * Callback function for createList() - * Get a list of spider stats from the log_spider table - * - * @param type $start - * @param type $items_per_page - * @param type $sort - * @return array - */ -function list_getSpiderStats($start, $items_per_page, $sort) -{ - $db = database(); - - $request = $db->query('', ' - SELECT ss.id_spider, ss.stat_date, ss.page_hits, s.spider_name - FROM {db_prefix}log_spider_stats AS ss - INNER JOIN {db_prefix}spiders AS s ON (s.id_spider = ss.id_spider) - ORDER BY ' . $sort . ' - LIMIT ' . $start . ', ' . $items_per_page, - array( - ) - ); - $spider_stats = array(); - while ($row = $db->fetch_assoc($request)) - $spider_stats[] = $row; - $db->free_result($request); - - return $spider_stats; -} + /** + * Callback function for createList() + * + * @param type $start + * @param type $items_per_page + * @param type $sort + * @return array + */ + function list_getSpiderStats($start, $items_per_page, $sort) + { + return getSpiderStats($start, $items_per_page, $sort); + } -/** - * Callback function for createList() - * Get the number of spider stat rows from the log spicer stats table - * - * @return int - */ -function list_getNumSpiderStats() -{ - $db = database(); - - $request = $db->query('', ' - SELECT COUNT(*) AS num_stats - FROM {db_prefix}log_spider_stats', - array( - ) - ); - list ($numStats) = $db->fetch_row($request); - $db->free_result($request); - - return $numStats; -} + /** + * Callback function for createList() + * + * @return int + */ + function list_getNumSpiderStats() + { + return getNumSpiderStats(); + } +} \ No newline at end of file diff --git a/sources/controllers/ProfileInfo.controller.php b/sources/controllers/ProfileInfo.controller.php index abebc0d29a..5a0767eca1 100644 --- a/sources/controllers/ProfileInfo.controller.php +++ b/sources/controllers/ProfileInfo.controller.php @@ -213,7 +213,7 @@ public function action_summary() $boardsAllowed = boardsAllowedTo('view_attachments'); if (empty($boardsAllowed)) $boardsAllowed = array(-1); - $attachments = list_getAttachments(0, $settings['attachments_on_summary'], 'm.poster_time DESC', $boardsAllowed , $context['member']['id']); + $attachments = $this->list_getAttachments(0, $settings['attachments_on_summary'], 'm.poster_time DESC', $boardsAllowed , $context['member']['id']); // load them in to $context for use in the template $i = 0; @@ -632,14 +632,14 @@ public function action_showAttachments() 'base_href' => $scripturl . '?action=profile;area=showposts;sa=attach;u=' . $memID, 'default_sort_col' => 'filename', 'get_items' => array( - 'function' => 'list_getAttachments', + 'function' => array($this, 'list_getAttachments'), 'params' => array( $boardsAllowed, $memID, ), ), 'get_count' => array( - 'function' => 'list_getNumAttachments', + 'function' => array($this, 'list_getNumAttachments'), 'params' => array( $boardsAllowed, $memID, @@ -739,13 +739,13 @@ public function action_showDisregarded() 'base_href' => $scripturl . '?action=profile;area=showposts;sa=disregardedtopics;u=' . $memID, 'default_sort_col' => 'started_on', 'get_items' => array( - 'function' => 'list_getDisregarded', + 'function' => array($this, 'list_getDisregarded'), 'params' => array( $memID, ), ), 'get_count' => array( - 'function' => 'list_getNumDisregarded', + 'function' => array($this, 'list_getNumDisregarded'), 'params' => array( $memID, ), @@ -1339,6 +1339,7 @@ public function action_viewWarning() /** * Get a list of attachments for this user + * Callback for createList() * * @param int $start * @param int $items_per_page @@ -1349,73 +1350,13 @@ public function action_viewWarning() */ function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID) { - global $board, $modSettings, $context, $settings, $scripturl, $txt; - - $db = database(); - - // Retrieve some attachments. - $request = $db->query('', ' - SELECT a.id_attach, a.id_msg, a.filename, a.downloads, a.approved, a.fileext, a.width, a.height, ' . - (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ' IFNULL(thumb.id_attach, 0) AS id_thumb, thumb.width AS thumb_width, thumb.height AS thumb_height, ') . ' - m.id_msg, m.id_topic, m.id_board, m.poster_time, m.subject, b.name - FROM {db_prefix}attachments AS a' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ' - LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = a.id_thumb)') . ' - INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) - INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board}) - WHERE a.attachment_type = {int:attachment_type} - AND a.id_msg != {int:no_message} - AND m.id_member = {int:current_member}' . (!empty($board) ? ' - AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? ' - AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' - AND m.approved = {int:is_approved}') . ' - ORDER BY {raw:sort} - LIMIT {int:offset}, {int:limit}', - array( - 'boards_list' => $boardsAllowed, - 'attachment_type' => 0, - 'no_message' => 0, - 'current_member' => $memID, - 'is_approved' => 1, - 'board' => $board, - 'sort' => $sort, - 'offset' => $start, - 'limit' => $items_per_page, - ) - ); - $attachments = array(); - while ($row = $db->fetch_assoc($request)) - { - if (!$row['approved']) - $row['filename'] = str_replace(array('{attachment_link}', '{txt_awaiting}'), array('' . $row['filename'] . '', $txt['awaiting_approval']), $settings['attachments_awaiting_approval']); - else - $row['filename'] = '' . $row['filename'] . ''; - - $attachments[] = array( - 'id' => $row['id_attach'], - 'filename' => $row['filename'], - 'fileext' => $row['fileext'], - 'width' => $row['width'], - 'height' => $row['height'], - 'downloads' => $row['downloads'], - 'is_image' => !empty($row['width']) && !empty($row['height']) && !empty($modSettings['attachmentShowImages']), - 'id_thumb' => $row['id_thumb'], - 'subject' => '' . censorText($row['subject']) . '', - 'posted' => $row['poster_time'], - 'msg' => $row['id_msg'], - 'topic' => $row['id_topic'], - 'board' => $row['id_board'], - 'board_name' => $row['name'], - 'approved' => $row['approved'], - ); - } - - $db->free_result($request); - - return $attachments; + // @todo tweak this method to use $context, etc, + // then call subs function with params set. + profileLoadAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID); } /** - * Gets the total number of attachments for the user + * Callback for createList() * * @param type $boardsAllowed * @param type $memID @@ -1423,35 +1364,9 @@ function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $me */ function list_getNumAttachments($boardsAllowed, $memID) { - global $board, $modSettings, $context; - - $db = database(); - - // Get the total number of attachments they have posted. - $request = $db->query('', ' - SELECT COUNT(*) - FROM {db_prefix}attachments AS a - INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) - INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board}) - WHERE a.attachment_type = {int:attachment_type} - AND a.id_msg != {int:no_message} - AND m.id_member = {int:current_member}' . (!empty($board) ? ' - AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? ' - AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' - AND m.approved = {int:is_approved}'), - array( - 'boards_list' => $boardsAllowed, - 'attachment_type' => 0, - 'no_message' => 0, - 'current_member' => $memID, - 'is_approved' => 1, - 'board' => $board, - ) - ); - list ($attachCount) = $db->fetch_row($request); - $db->free_result($request); - - return $attachCount; + // @todo tweak this method to use $context, etc, + // then call subs function with params set. + return getNumAttachments($boardsAllowed, $memID); } /** diff --git a/sources/subs/ManageNews.subs.php b/sources/subs/ManageNews.subs.php index f3d8e1bfa9..af5e8a7ec5 100644 --- a/sources/subs/ManageNews.subs.php +++ b/sources/subs/ManageNews.subs.php @@ -19,11 +19,11 @@ die('No access...'); /** - * Prepares an array of the forum news items for display in the template + * Prepares an array of the forum news items * * @return array */ -function list_getNews() +function getNews() { global $modSettings; diff --git a/sources/subs/Profile.subs.php b/sources/subs/Profile.subs.php index 9d247c17bf..baaf31d6b8 100644 --- a/sources/subs/Profile.subs.php +++ b/sources/subs/Profile.subs.php @@ -2379,4 +2379,123 @@ function list_getUserWarningCount($memID) $db->free_result($request); return $total_warnings; +} + +/** + * Get a list of attachments for this user + * (used by createList() callback and others) + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param array $boardsAllowed + * @param ing $memID + * @return array + */ +function profileLoadAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID) +{ + global $board, $modSettings, $context, $settings, $scripturl, $txt; + + $db = database(); + + // Retrieve some attachments. + $request = $db->query('', ' + SELECT a.id_attach, a.id_msg, a.filename, a.downloads, a.approved, a.fileext, a.width, a.height, ' . + (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ' IFNULL(thumb.id_attach, 0) AS id_thumb, thumb.width AS thumb_width, thumb.height AS thumb_height, ') . ' + m.id_msg, m.id_topic, m.id_board, m.poster_time, m.subject, b.name + FROM {db_prefix}attachments AS a' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ' + LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = a.id_thumb)') . ' + INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) + INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board}) + WHERE a.attachment_type = {int:attachment_type} + AND a.id_msg != {int:no_message} + AND m.id_member = {int:current_member}' . (!empty($board) ? ' + AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? ' + AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' + AND m.approved = {int:is_approved}') . ' + ORDER BY {raw:sort} + LIMIT {int:offset}, {int:limit}', + array( + 'boards_list' => $boardsAllowed, + 'attachment_type' => 0, + 'no_message' => 0, + 'current_member' => $memID, + 'is_approved' => 1, + 'board' => $board, + 'sort' => $sort, + 'offset' => $start, + 'limit' => $items_per_page, + ) + ); + $attachments = array(); + while ($row = $db->fetch_assoc($request)) + { + if (!$row['approved']) + $row['filename'] = str_replace(array('{attachment_link}', '{txt_awaiting}'), array('' . $row['filename'] . '', $txt['awaiting_approval']), $settings['attachments_awaiting_approval']); + else + $row['filename'] = '' . $row['filename'] . ''; + + $attachments[] = array( + 'id' => $row['id_attach'], + 'filename' => $row['filename'], + 'fileext' => $row['fileext'], + 'width' => $row['width'], + 'height' => $row['height'], + 'downloads' => $row['downloads'], + 'is_image' => !empty($row['width']) && !empty($row['height']) && !empty($modSettings['attachmentShowImages']), + 'id_thumb' => $row['id_thumb'], + 'subject' => '' . censorText($row['subject']) . '', + 'posted' => $row['poster_time'], + 'msg' => $row['id_msg'], + 'topic' => $row['id_topic'], + 'board' => $row['id_board'], + 'board_name' => $row['name'], + 'approved' => $row['approved'], + ); + } + + $db->free_result($request); + + return $attachments; +} + +/** + * Gets the total number of attachments for the user + * (used by createList() callbacks) + * + * @param type $boardsAllowed + * @param type $memID + * @return type + */ +function getNumAttachments($boardsAllowed, $memID) +{ + global $board, $modSettings, $context; + + $db = database(); + + // Get the total number of attachments they have posted. + $request = $db->query('', ' + SELECT COUNT(*) + FROM {db_prefix}attachments AS a + INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) + INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board}) + WHERE a.attachment_type = {int:attachment_type} + AND a.id_msg != {int:no_message} + AND m.id_member = {int:current_member}' . (!empty($board) ? ' + AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? ' + AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' + AND m.approved = {int:is_approved}'), + array( + 'boards_list' => $boardsAllowed, + 'attachment_type' => 0, + 'no_message' => 0, + 'current_member' => $memID, + 'is_approved' => 1, + 'board' => $board, + ) + ); + list ($attachCount) = $db->fetch_row($request); + $db->free_result($request); + + return $attachCount; } \ No newline at end of file diff --git a/sources/subs/SearchEngines.subs.php b/sources/subs/SearchEngines.subs.php index f60f66b6fb..8a13757451 100644 --- a/sources/subs/SearchEngines.subs.php +++ b/sources/subs/SearchEngines.subs.php @@ -285,4 +285,159 @@ function sortSpiderTable() // Remove the sorting column. $table->db_remove_column('{db_prefix}spiders', 'temp_order'); +} + +/** + * Return spiders, within the limits specified by parameters + * (used by createList() callbacks) + * + * @param int $start + * @param int $items_per_page + * @param string sort + */ +function getSpiders($start, $items_per_page, $sort) +{ + $db = database(); + + $request = $db->query('', ' + SELECT id_spider, spider_name, user_agent, ip_info + FROM {db_prefix}spiders + ORDER BY ' . $sort . ' + LIMIT ' . $start . ', ' . $items_per_page, + array( + ) + ); + $spiders = array(); + while ($row = $db->fetch_assoc($request)) + $spiders[$row['id_spider']] = $row; + $db->free_result($request); + + return $spiders; +} + +/** + * Return the registered spiders count. + * (used by createList() callbacks) + * + * @return int + */ +function getNumSpiders() +{ + $db = database(); + + $request = $db->query('', ' + SELECT COUNT(*) AS num_spiders + FROM {db_prefix}spiders', + array( + ) + ); + list ($numSpiders) = $db->fetch_row($request); + $db->free_result($request); + + return $numSpiders; +} + +/** + * Retrieve spider logs within the specified limits. + * (used by createList() callbacks) + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @return array + */ +function getSpiderLogs($start, $items_per_page, $sort) +{ + $db = database(); + + $request = $db->query('', ' + SELECT sl.id_spider, sl.url, sl.log_time, s.spider_name + FROM {db_prefix}log_spider_hits AS sl + INNER JOIN {db_prefix}spiders AS s ON (s.id_spider = sl.id_spider) + ORDER BY ' . $sort . ' + LIMIT ' . $start . ', ' . $items_per_page, + array( + ) + ); + $spider_logs = array(); + while ($row = $db->fetch_assoc($request)) + $spider_logs[] = $row; + $db->free_result($request); + + return $spider_logs; +} + +/** + * Returns the count of spider logs. + * (used by createList() callbacks) + * + * @return int + */ +function getNumSpiderLogs() +{ + $db = database(); + + $request = $db->query('', ' + SELECT COUNT(*) AS num_logs + FROM {db_prefix}log_spider_hits', + array( + ) + ); + list ($numLogs) = $db->fetch_row($request); + $db->free_result($request); + + return $numLogs; +} + +/** + * Get a list of spider stats from the log_spider table within the specified + * limits. + * (used by createList() callbacks) + * + * @param type $start + * @param type $items_per_page + * @param type $sort + * @return array + */ +function getSpiderStats($start, $items_per_page, $sort) +{ + $db = database(); + + $request = $db->query('', ' + SELECT ss.id_spider, ss.stat_date, ss.page_hits, s.spider_name + FROM {db_prefix}log_spider_stats AS ss + INNER JOIN {db_prefix}spiders AS s ON (s.id_spider = ss.id_spider) + ORDER BY ' . $sort . ' + LIMIT ' . $start . ', ' . $items_per_page, + array( + ) + ); + $spider_stats = array(); + while ($row = $db->fetch_assoc($request)) + $spider_stats[] = $row; + $db->free_result($request); + + return $spider_stats; +} + +/** + * Get the number of spider stat rows from the log spicer stats table + * (used by createList() callbacks) + * + * @return int + */ +function getNumSpiderStats() +{ + $db = database(); + + $request = $db->query('', ' + SELECT COUNT(*) AS num_stats + FROM {db_prefix}log_spider_stats', + array( + ) + ); + list ($numStats) = $db->fetch_row($request); + $db->free_result($request); + + return $numStats; } \ No newline at end of file From fb8301614687e4423532f5f83751f2882d010e7b Mon Sep 17 00:00:00 2001 From: Norv Date: Tue, 25 Jun 2013 21:28:48 +0300 Subject: [PATCH 33/34] Adapt a couple more createList() callbacks in profile. Signed-off-by: Norv --- .../controllers/ProfileInfo.controller.php | 84 +++-------------- sources/subs/Profile.subs.php | 90 +++++++++++++++++++ 2 files changed, 101 insertions(+), 73 deletions(-) diff --git a/sources/controllers/ProfileInfo.controller.php b/sources/controllers/ProfileInfo.controller.php index 5a0767eca1..28e9c6cf23 100644 --- a/sources/controllers/ProfileInfo.controller.php +++ b/sources/controllers/ProfileInfo.controller.php @@ -1345,10 +1345,10 @@ public function action_viewWarning() * @param int $items_per_page * @param string $sort * @param array $boardsAllowed - * @param ing $memID + * @param int $memID * @return array */ - function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID) + public function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID) { // @todo tweak this method to use $context, etc, // then call subs function with params set. @@ -1360,9 +1360,9 @@ function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $me * * @param type $boardsAllowed * @param type $memID - * @return type + * @return int */ - function list_getNumAttachments($boardsAllowed, $memID) + public function list_getNumAttachments($boardsAllowed, $memID) { // @todo tweak this method to use $context, etc, // then call subs function with params set. @@ -1371,90 +1371,28 @@ function list_getNumAttachments($boardsAllowed, $memID) /** * Get the relevant topics in the disregarded list + * Callback for createList() * * @param int $start * @param int $items_per_page * @param string $sort * @param int $memID + * @return array */ function list_getDisregarded($start, $items_per_page, $sort, $memID) { - $db = database(); - - // Get the list of topics we can see - $request = $db->query('', ' - SELECT lt.id_topic - FROM {db_prefix}log_topics as lt - LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic) - LEFT JOIN {db_prefix}boards as b ON (t.id_board = b.id_board) - LEFT JOIN {db_prefix}messages as m ON (t.id_first_msg = m.id_msg)' . (in_array($sort, array('mem.real_name', 'mem.real_name DESC', 'mem.poster_time', 'mem.poster_time DESC')) ? ' - LEFT JOIN {db_prefix}members as mem ON (m.id_member = mem.id_member)' : '') . ' - WHERE lt.id_member = {int:current_member} - AND disregarded = 1 - AND {query_see_board} - ORDER BY {raw:sort} - LIMIT {int:offset}, {int:limit}', - array( - 'current_member' => $memID, - 'sort' => $sort, - 'offset' => $start, - 'limit' => $items_per_page, - ) - ); - $topics = array(); - while ($row = $db->fetch_assoc($request)) - $topics[] = $row['id_topic']; - $db->free_result($request); - - // Any topics found? - $topicsInfo = array(); - if (!empty($topics)) - { - $request = $db->query('', ' - SELECT mf.subject, mf.poster_time as started_on, IFNULL(memf.real_name, mf.poster_name) as started_by, ml.poster_time as last_post_on, IFNULL(meml.real_name, ml.poster_name) as last_post_by, t.id_topic - FROM {db_prefix}topics AS t - INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) - INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg) - LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member) - LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member) - WHERE t.id_topic IN ({array_int:topics})', - array( - 'topics' => $topics, - ) - ); - while ($row = $db->fetch_assoc($request)) - $topicsInfo[] = $row; - $db->free_result($request); - } - - return $topicsInfo; + return getDisregardedBy($start, $items_per_page, $sort, $memID); } /** * Count the number of topics in the disregarded list + * Callback for createList() * * @param int $memID + * @return int */ - function list_getNumDisregarded($memID) + public function list_getNumDisregarded($memID) { - $db = database(); - - // Get the total number of attachments they have posted. - $request = $db->query('', ' - SELECT COUNT(*) - FROM {db_prefix}log_topics as lt - LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic) - LEFT JOIN {db_prefix}boards as b ON (t.id_board = b.id_board) - WHERE id_member = {int:current_member} - AND disregarded = 1 - AND {query_see_board}', - array( - 'current_member' => $memID, - ) - ); - list ($disregardedCount) = $db->fetch_row($request); - $db->free_result($request); - - return $disregardedCount; + return getNumDisregardedBy($memID); } } \ No newline at end of file diff --git a/sources/subs/Profile.subs.php b/sources/subs/Profile.subs.php index baaf31d6b8..1ce1985f74 100644 --- a/sources/subs/Profile.subs.php +++ b/sources/subs/Profile.subs.php @@ -2498,4 +2498,94 @@ function getNumAttachments($boardsAllowed, $memID) $db->free_result($request); return $attachCount; +} + +/** + * Get the relevant topics in the disregarded list + * (used by createList() callbacks) + * + * @param int $start + * @param int $items_per_page + * @param string $sort + * @param int $memID + */ +function getDisregardedBy($start, $items_per_page, $sort, $memID) +{ + $db = database(); + + // Get the list of topics we can see + $request = $db->query('', ' + SELECT lt.id_topic + FROM {db_prefix}log_topics as lt + LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic) + LEFT JOIN {db_prefix}boards as b ON (t.id_board = b.id_board) + LEFT JOIN {db_prefix}messages as m ON (t.id_first_msg = m.id_msg)' . (in_array($sort, array('mem.real_name', 'mem.real_name DESC', 'mem.poster_time', 'mem.poster_time DESC')) ? ' + LEFT JOIN {db_prefix}members as mem ON (m.id_member = mem.id_member)' : '') . ' + WHERE lt.id_member = {int:current_member} + AND disregarded = 1 + AND {query_see_board} + ORDER BY {raw:sort} + LIMIT {int:offset}, {int:limit}', + array( + 'current_member' => $memID, + 'sort' => $sort, + 'offset' => $start, + 'limit' => $items_per_page, + ) + ); + $topics = array(); + while ($row = $db->fetch_assoc($request)) + $topics[] = $row['id_topic']; + $db->free_result($request); + + // Any topics found? + $topicsInfo = array(); + if (!empty($topics)) + { + $request = $db->query('', ' + SELECT mf.subject, mf.poster_time as started_on, IFNULL(memf.real_name, mf.poster_name) as started_by, ml.poster_time as last_post_on, IFNULL(meml.real_name, ml.poster_name) as last_post_by, t.id_topic + FROM {db_prefix}topics AS t + INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) + INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg) + LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member) + LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member) + WHERE t.id_topic IN ({array_int:topics})', + array( + 'topics' => $topics, + ) + ); + while ($row = $db->fetch_assoc($request)) + $topicsInfo[] = $row; + $db->free_result($request); + } + + return $topicsInfo; +} + +/** + * Count the number of topics in the disregarded list + * + * @param int $memID + */ +function getNumDisregardedBy($memID) +{ + $db = database(); + + // Get the total number of attachments they have posted. + $request = $db->query('', ' + SELECT COUNT(*) + FROM {db_prefix}log_topics as lt + LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic) + LEFT JOIN {db_prefix}boards as b ON (t.id_board = b.id_board) + WHERE id_member = {int:current_member} + AND disregarded = 1 + AND {query_see_board}', + array( + 'current_member' => $memID, + ) + ); + list ($disregardedCount) = $db->fetch_row($request); + $db->free_result($request); + + return $disregardedCount; } \ No newline at end of file From e2ee56fca306ca89f0a2c2eea67009c14f55a62f Mon Sep 17 00:00:00 2001 From: Norv Date: Tue, 25 Jun 2013 21:55:59 +0300 Subject: [PATCH 34/34] Adapt list_ callbacks in AdminDebug and ManageAddonSettings controllers. Signed-off-by: Norv --- sources/admin/AdminDebug.php | 9 +++++-- sources/admin/ManageAddonSettings.php | 33 ++++++++++++++++++++--- sources/subs/AdminDebug.subs.php | 2 +- sources/subs/ManageAddonSettings.subs.php | 16 +++++------ 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/sources/admin/AdminDebug.php b/sources/admin/AdminDebug.php index 5f493c3a53..2353bb87ce 100644 --- a/sources/admin/AdminDebug.php +++ b/sources/admin/AdminDebug.php @@ -22,10 +22,15 @@ class AdminDebug_Controller extends Action_Controller { + /** + * Main dispatcher. + * + * @see Action_Controller::action_index() + */ public function action_index() { // what to do first... viewquery! What, it'll work or it won't. - $this->action_viewquery(); + // $this->action_viewquery(); } /** @@ -216,7 +221,7 @@ public function action_viewadminfile() if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename'])) fatal_lang_error('no_access', false); - $file = list_getAdminInfoFile($_REQUEST['filename']); + $file = adminInfoFile($_REQUEST['filename']); // @todo Temp // Figure out if sesc is still being used. diff --git a/sources/admin/ManageAddonSettings.php b/sources/admin/ManageAddonSettings.php index 7477c2ea33..367a1cdd1f 100644 --- a/sources/admin/ManageAddonSettings.php +++ b/sources/admin/ManageAddonSettings.php @@ -219,10 +219,10 @@ public function action_hooks() 'base_href' => $scripturl . '?action=admin;area=modsettings;sa=hooks' . $context['filter_url'] . ';' . $context['session_var'] . '=' . $context['session_id'], 'default_sort_col' => 'hook_name', 'get_items' => array( - 'function' => 'list_integration_hooks_data', + 'function' => array($this, 'list_getIntegrationHooks'), ), 'get_count' => array( - 'function' => 'list_integration_hooks_count', + 'function' => array($this, 'list_getIntegrationHooksCount'), ), 'no_items_label' => $txt['hooks_no_hooks'], 'columns' => array( @@ -368,4 +368,31 @@ public function loadGeneralSettingParameters($subActions = array(), $defaultActi $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (!empty($defaultAction) ? $defaultAction : array_pop($temp = array_keys($subActions))); $context['sub_action'] = $_REQUEST['sa']; } -} \ No newline at end of file + + /** + * Simply returns the total count of integration hooks + * Callback for createList(). + * + * @return int + */ + function list_getIntegrationHooksCount() + { + global $context; + + $context['filter'] = false; + if (isset($_GET['filter'])) + $context['filter'] = $_GET['filter']; + + return get_integration_hooks_count($context['filter']); + } + + /** + * Callback for createList(). + * + * @return array + */ + function list_getIntegrationHooks() + { + return get_integration_hooks(); + } +} diff --git a/sources/subs/AdminDebug.subs.php b/sources/subs/AdminDebug.subs.php index 1eefd06eb1..1cfd12cc14 100644 --- a/sources/subs/AdminDebug.subs.php +++ b/sources/subs/AdminDebug.subs.php @@ -19,7 +19,7 @@ * * @return array */ -function list_getAdminInfoFile($filename) +function adminInfoFile($filename) { $db = database(); diff --git a/sources/subs/ManageAddonSettings.subs.php b/sources/subs/ManageAddonSettings.subs.php index c908b78eb8..708b7a2e0b 100644 --- a/sources/subs/ManageAddonSettings.subs.php +++ b/sources/subs/ManageAddonSettings.subs.php @@ -216,26 +216,21 @@ function list_integration_hooks_data($start, $per_page, $sort) } /** - * Simply returns the total count of integraion hooks - * Used but the intergation hooks list function (list_integration_hooks) + * Simply returns the total count of integration hooks + * (used by createList() callbacks) * - * @global type $context * @return int */ -function list_integration_hooks_count() +function integration_hooks_count($filter = false) { global $context; $hooks = get_integration_hooks(); $hooks_count = 0; - $context['filter'] = false; - if (isset($_GET['filter'])) - $context['filter'] = $_GET['filter']; - foreach ($hooks as $hook => $functions) { - if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook)) + if (empty($filter) || ($filter == $hook)) $hooks_count += count($functions); } @@ -244,9 +239,10 @@ function list_integration_hooks_count() /** * Parses modSettings to create integration hook array + * (used by createList() callbacks) * * @staticvar type $integration_hooks - * @return type + * @return array */ function get_integration_hooks() {