From d72f0f80f26f47f41073d7debba4498fa5887a8e Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 5 Jan 2011 11:28:13 +0000 Subject: [PATCH] Added forumlist module --- root/includes/acp/acp_portal_config.php | 172 ------------ root/includes/acp/acp_portal_links.php | 259 ------------------ .../mods/portal/portal_forumlist_module.php | 37 +++ .../mods/portal/portal_forumlist_module.php | 37 +++ root/portal/modules/portal_forumlist.php | 106 +++++++ .../template/portal/modules/forumlist.html | 11 + 6 files changed, 191 insertions(+), 431 deletions(-) delete mode 100644 root/includes/acp/acp_portal_config.php delete mode 100644 root/includes/acp/acp_portal_links.php create mode 100644 root/language/de/mods/portal/portal_forumlist_module.php create mode 100644 root/language/en/mods/portal/portal_forumlist_module.php create mode 100644 root/portal/modules/portal_forumlist.php create mode 100644 root/styles/prosilver/template/portal/modules/forumlist.html diff --git a/root/includes/acp/acp_portal_config.php b/root/includes/acp/acp_portal_config.php deleted file mode 100644 index 20dc84b0..00000000 --- a/root/includes/acp/acp_portal_config.php +++ /dev/null @@ -1,172 +0,0 @@ -add_lang('mods/portal'); - $submit = (isset($_POST['submit'])) ? true : false; - - $form_key = 'acp_time'; - add_form_key($form_key); - - /** - * Validation types are: - * string, int, bool, - * script_path (absolute path in url - beginning with / and no trailing slash), - * rpath (relative), rwpath (realtive, writeable), path (relative path, but able to escape the root), wpath (writeable) - */ - switch ($mode) - { - case 'config': - $display_vars = array( - 'title' => 'ACP_PORTAL_GENERAL_TITLE', - 'vars' => array( - 'legend1' => 'ACP_PORTAL_GENERAL_INFO', - 'portal_enable' => array('lang' => 'PORTAL_ENABLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'portal_left_column_width' => array('lang' => 'PORTAL_LEFT_COLUMN_WIDTH', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), - 'portal_right_column_width' => array('lang' => 'PORTAL_RIGHT_COLUMN_WIDTH', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), - ) - ); - break; - default: - trigger_error('NO_MODE', E_USER_ERROR); - break; - } - - $this->new_config = $config; - $cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config; - $error = array(); - - // We validate the complete config if whished - validate_config_vars($display_vars['vars'], $cfg_array, $error); - if ($submit && !check_form_key($form_key)) - { - $error[] = $user->lang['FORM_INVALID']; - } - - // Do not write values if there is an error - if (sizeof($error)) - { - $submit = false; - } - - // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... - foreach ($display_vars['vars'] as $config_name => $null) - { - if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) - { - continue; - } - - $this->new_config[$config_name] = $config_value = $cfg_array[$config_name]; - - if ($submit) - { - set_portal_config($config_name, $config_value); - } - } - - if ($submit) - { - $cache->destroy('sql', PORTAL_CONFIG_TABLE); - add_log('admin', 'LOG_PORTAL_CONFIG', $user->lang['ACP_PORTAL_' . strtoupper($mode) . '_INFO']); - trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); - } - - $this->tpl_name = 'acp_portal_config'; - $this->page_title = $display_vars['title']; - - $template->assign_vars(array( - 'L_TITLE' => $user->lang[$display_vars['title']], - 'L_TITLE_EXPLAIN' => $user->lang[$display_vars['title'] . '_EXPLAIN'], - - 'S_ERROR' => (sizeof($error)) ? true : false, - 'ERROR_MSG' => implode('
', $error), - - 'U_ACTION' => $this->u_action) - ); - - // Output relevant page - foreach ($display_vars['vars'] as $config_key => $vars) - { - if (!is_array($vars) && strpos($config_key, 'legend') === false) - { - continue; - } - - if (strpos($config_key, 'legend') !== false) - { - $template->assign_block_vars('options', array( - 'S_LEGEND' => true, - 'LEGEND' => (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars) - ); - - continue; - } - $this->new_config[$config_key] = $portal_config[$config_key]; - $type = explode(':', $vars['type']); - - $l_explain = ''; - if ($vars['explain']) - { - $l_explain = (isset($user->lang[$vars['lang'] . '_EXP'])) ? $user->lang[$vars['lang'] . '_EXP'] : ''; - } - - $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); - - if (empty($content)) - { - continue; - } - - $template->assign_block_vars('options', array( - 'KEY' => $config_key, - 'TITLE' => (isset($user->lang[$vars['lang']])) ? $user->lang[$vars['lang']] : $vars['lang'], - 'S_EXPLAIN' => $vars['explain'], - 'TITLE_EXPLAIN' => $l_explain, - 'CONTENT' => $content, - )); - - unset($display_vars['vars'][$config_key]); - } - } -} -?> \ No newline at end of file diff --git a/root/includes/acp/acp_portal_links.php b/root/includes/acp/acp_portal_links.php deleted file mode 100644 index 4b991820..00000000 --- a/root/includes/acp/acp_portal_links.php +++ /dev/null @@ -1,259 +0,0 @@ -add_lang('mods/portal'); - $portal_root_path = PORTAL_ROOT_PATH; - $portal_icons_path = PORTAL_ICONS_PATH; - include($phpbb_root_path . $portal_root_path . 'includes/functions.' . $phpEx); - $portal_config = obtain_portal_config(); - - // Set up general vars - $action = request_var('action', ''); - $action = (isset($_POST['add'])) ? 'add' : $action; - $action = (isset($_POST['save'])) ? 'save' : $action; - $link_id = request_var('id', 0); - - $this->tpl_name = 'acp_portal_links'; - $this->page_title = 'ACP_PORTAL_LINKS'; - - $form_name = 'acp_portal_links'; - add_form_key($form_name); - - switch ($action) - { - case 'save': - - if (!check_form_key($form_name)) - { - trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING); - } - - $link_title = utf8_normalize_nfc(request_var('link_title', '', true)); - $link_is_cat = request_var('link_is_cat', 0); - $link_url = ($link_is_cat) ? '' : request_var('link_url', ''); - - if (!$link_title) - { - trigger_error($user->lang['NO_LINK_TITLE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (!$link_is_cat && !$link_url) - { - trigger_error($user->lang['NO_LINK_URL'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $sql_ary = array( - 'link_title' => $link_title, - 'link_is_cat' => $link_is_cat, - 'link_url' => htmlspecialchars_decode($link_url), - ); - - $order_ary = array( - 'link_order' => $portal_config['num_links'] + 1, - ); - - if ($link_id) - { - $sql = 'UPDATE ' . PORTAL_LINKS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE link_id = $link_id"; - $message = $user->lang['LINK_UPDATED']; - - add_log('admin', 'LOG_PORTAL_LINK_UPDATED', $link_title); - } - else - { - $sql = 'INSERT INTO ' . PORTAL_LINKS_TABLE . ' ' . $db->sql_build_array('INSERT', array_merge($sql_ary, $order_ary)); - $message = $user->lang['LINK_ADDED']; - - set_portal_config('num_links', $portal_config['num_links'] + 1, true); - add_log('admin', 'LOG_PORTAL_LINK_ADDED', $link_title); - } - $db->sql_query($sql); - - $cache->destroy('_links'); - - trigger_error($message . adm_back_link($this->u_action)); - - break; - - case 'delete': - - if (!$link_id) - { - trigger_error($user->lang['MUST_SELECT_LINK'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (confirm_box(true)) - { - $sql = 'SELECT link_title, link_order - FROM ' . PORTAL_LINKS_TABLE . " - WHERE link_id = $link_id"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($row) - { - $row['link_title'] = (string) $row['link_title']; - $row['link_order'] = (int) $row['link_order']; - } - - $sql = 'DELETE FROM ' . PORTAL_LINKS_TABLE . " WHERE link_id = $link_id"; - $db->sql_query($sql); - - // Reset link order... - $sql = 'UPDATE ' . PORTAL_LINKS_TABLE . ' SET link_order = link_order - 1 WHERE link_order > ' . $row['link_order']; - $db->sql_query($sql); - - $cache->destroy('_links'); - - set_portal_config('num_links', $portal_config['num_links'] - 1, true); - add_log('admin', 'LOG_PORTAL_LINK_REMOVED', $row['link_title']); - } - else - { - confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( - 'i' => $id, - 'mode' => $mode, - 'link_id' => $link_id, - 'action' => 'delete', - ))); - } - - break; - - case 'move_up': - case 'move_down': - - if (!$link_id) - { - trigger_error($user->lang['MUST_SELECT_LINK'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Get current order id... - $sql = 'SELECT link_order AS current_order - FROM ' . PORTAL_LINKS_TABLE . " - WHERE link_id = $link_id"; - $result = $db->sql_query($sql); - $current_order = (int) $db->sql_fetchfield('current_order'); - $db->sql_freeresult($result); - - if ($current_order == 0 && $action == 'move_up') - { - break; - } - - // on move_down, switch position with next order_id... - // on move_up, switch position with previous order_id... - $switch_order_id = ($action == 'move_down') ? $current_order + 1 : $current_order - 1; - - // Update order values - $sql = 'UPDATE ' . PORTAL_LINKS_TABLE . " - SET link_order = $current_order - WHERE link_order = $switch_order_id - AND link_id <> $link_id"; - $db->sql_query($sql); - - // Only update the other entry too if the previous entry got updated - if ($db->sql_affectedrows()) - { - $sql = 'UPDATE ' . PORTAL_LINKS_TABLE . " - SET link_order = $switch_order_id - WHERE link_order = $current_order - AND link_id = $link_id"; - $db->sql_query($sql); - } - - break; - - case 'edit': - case 'add': - - $links = array(); - - $sql = 'SELECT * - FROM ' . PORTAL_LINKS_TABLE . ' - ORDER BY link_order'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - if ($action == 'edit' && $link_id == $row['link_id']) - { - $links = $row; - } - } - $db->sql_freeresult($result); - - $template->assign_vars(array( - 'LINK_TITLE' => (isset($links['link_title'])) ? $links['link_title'] : '', - 'LINK_URL' => (isset($links['link_url']) && !$links['link_is_cat']) ? $links['link_url'] : '', - - 'U_BACK' => $this->u_action, - 'U_ACTION' => $this->u_action . '&id=' . $link_id, - - 'S_EDIT' => true, - 'S_LINK_IS_CAT' => (!isset($links['link_is_cat']) || $links['link_is_cat']) ? true : false, - )); - - return; - - break; - } - - $template->assign_vars(array( - 'U_ACTION' => $this->u_action, - )); - - $sql = 'SELECT * - FROM ' . PORTAL_LINKS_TABLE . ' - ORDER BY link_order'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $template->assign_block_vars('links', array( - 'LINK_TITLE' => $row['link_title'], - 'LINK_URL' => $row['link_url'], - - 'U_EDIT' => $this->u_action . '&action=edit&id=' . $row['link_id'], - 'U_DELETE' => $this->u_action . '&action=delete&id=' . $row['link_id'], - 'U_MOVE_UP' => $this->u_action . '&action=move_up&id=' . $row['link_id'], - 'U_MOVE_DOWN' => $this->u_action . '&action=move_down&id=' . $row['link_id'], - - 'S_LINK_IS_CAT' => ($row['link_is_cat']) ? true : false, - )); - } - $db->sql_freeresult($result); - } -} - -?> \ No newline at end of file diff --git a/root/language/de/mods/portal/portal_forumlist_module.php b/root/language/de/mods/portal/portal_forumlist_module.php new file mode 100644 index 00000000..99bac99c --- /dev/null +++ b/root/language/de/mods/portal/portal_forumlist_module.php @@ -0,0 +1,37 @@ + 'Forumliste', +)); + +?> \ No newline at end of file diff --git a/root/language/en/mods/portal/portal_forumlist_module.php b/root/language/en/mods/portal/portal_forumlist_module.php new file mode 100644 index 00000000..3d679fc0 --- /dev/null +++ b/root/language/en/mods/portal/portal_forumlist_module.php @@ -0,0 +1,37 @@ + 'Forumlist', +)); + +?> \ No newline at end of file diff --git a/root/portal/modules/portal_forumlist.php b/root/portal/modules/portal_forumlist.php new file mode 100644 index 00000000..a93226a8 --- /dev/null +++ b/root/portal/modules/portal_forumlist.php @@ -0,0 +1,106 @@ +lang}/mods/portal/" + */ + var $language = 'portal_forumlist_module'; + + /** + * custom acp template + * file must be in "adm/style/portal/" + */ + var $custom_acp_tpl = ''; + + function get_template_center($module_id) + { + global $config, $template, $user, $auth, $phpbb_root_path, $phpEx; + + display_forums('', $config['load_moderators'], false); + + $template->assign_vars(array( + 'FORUM_IMG' => $user->img('forum_read', 'NO_NEW_POSTS'), + 'FORUM_NEW_IMG' => $user->img('forum_unread', 'NEW_POSTS'), + 'FORUM_LOCKED_IMG' => $user->img('forum_read_locked', 'NO_NEW_POSTS_LOCKED'), + 'FORUM_NEW_LOCKED_IMG' => $user->img('forum_unread_locked', 'NO_NEW_POSTS_LOCKED'), + 'S_DISPLAY_PORTAL_FORUM_INDEX' => true, + 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&mark=forums') : '', + 'U_MCP' => ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&mode=front', true, $user->session_id) : '', + )); + + return 'forumlist.html'; + } + + function get_template_acp($module_id) + { + return array( + 'title' => 'PORTAL_FORUMLIST', + 'vars' => array(), + ); + } + + /** + * API functions + */ + function install($module_id) + { + set_config('portal_' . $module_id . '_configname', 'Hello World!'); + set_config('portal_' . $module_id . '_configname2', 1337); + return true; + } + + function uninstall($module_id) + { + global $db; + + $del_config = array( + 'portal_' . $module_id . '_configname', + 'portal_' . $module_id . '_configname2', + ); + $sql = 'DELETE FROM ' . CONFIG_TABLE . ' + WHERE ' . $db->sql_in_set('config_name', $del_config); + return $db->sql_query($sql); + } +} + +?> \ No newline at end of file diff --git a/root/styles/prosilver/template/portal/modules/forumlist.html b/root/styles/prosilver/template/portal/modules/forumlist.html new file mode 100644 index 00000000..20242aeb --- /dev/null +++ b/root/styles/prosilver/template/portal/modules/forumlist.html @@ -0,0 +1,11 @@ + + + + + +
\ No newline at end of file