| <?php |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| if (!defined('IN_PHPBB')) |
| { |
| exit; |
| } |
| |
| |
| |
| |
| |
| class p_master |
| { |
| var $p_id; |
| var $p_class; |
| var $p_name; |
| var $p_mode; |
| var $p_parent; |
| |
| var $include_path = false; |
| var $active_module = false; |
| var $active_module_row_id = false; |
| var $acl_forum_id = false; |
| var $module_ary = array(); |
| |
| |
| |
| |
| |
| function p_master($include_path = false) |
| { |
| global $phpbb_root_path; |
| |
| $this->include_path = ($include_path !== false) ? $include_path : $phpbb_root_path . 'includes/'; |
| |
| |
| if (substr($this->include_path, -1) !== '/') |
| { |
| $this->include_path .= '/'; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| function set_custom_include_path($include_path) |
| { |
| $this->include_path = $include_path; |
| |
| |
| if (substr($this->include_path, -1) !== '/') |
| { |
| $this->include_path .= '/'; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function list_modules($p_class) |
| { |
| global $auth, $db, $user, $cache; |
| global $config, $phpbb_root_path, $phpEx; |
| |
| |
| $this->p_class = str_replace(array('.', '/', '\\'), '', basename($p_class)); |
| |
| |
| if (($this->module_cache = $cache->get('_modules_' . $this->p_class)) === false) |
| { |
| |
| $sql = 'SELECT * |
| FROM ' . MODULES_TABLE . " |
| WHERE module_class = '" . $db->sql_escape($this->p_class) . "' |
| ORDER BY left_id ASC"; |
| $result = $db->sql_query($sql); |
| |
| $rows = array(); |
| while ($row = $db->sql_fetchrow($result)) |
| { |
| $rows[$row['module_id']] = $row; |
| } |
| $db->sql_freeresult($result); |
| |
| $this->module_cache = array(); |
| foreach ($rows as $module_id => $row) |
| { |
| $this->module_cache['modules'][] = $row; |
| $this->module_cache['parents'][$row['module_id']] = $this->get_parents($row['parent_id'], $row['left_id'], $row['right_id'], $rows); |
| } |
| unset($rows); |
| |
| $cache->put('_modules_' . $this->p_class, $this->module_cache); |
| } |
| |
| if (empty($this->module_cache)) |
| { |
| $this->module_cache = array('modules' => array(), 'parents' => array()); |
| } |
| |
| |
| |
| |
| |
| |
| |
| $right_id = false; |
| foreach ($this->module_cache['modules'] as $key => $row) |
| { |
| |
| if (!$this->module_auth($row['module_auth'])) |
| { |
| unset($this->module_cache['modules'][$key]); |
| continue; |
| } |
| |
| |
| if (!$row['module_basename'] && ($row['left_id'] + 1 == $row['right_id'])) |
| { |
| unset($this->module_cache['modules'][$key]); |
| continue; |
| } |
| |
| |
| if ($right_id !== false) |
| { |
| if ($row['left_id'] < $right_id) |
| { |
| unset($this->module_cache['modules'][$key]); |
| continue; |
| } |
| |
| $right_id = false; |
| } |
| |
| |
| if (!$row['module_enabled']) |
| { |
| |
| unset($this->module_cache['modules'][$key]); |
| $right_id = $row['right_id']; |
| continue; |
| } |
| } |
| |
| |
| $this->module_cache['modules'] = array_merge($this->module_cache['modules']); |
| |
| |
| $this->add_mod_info($this->p_class); |
| |
| |
| $right_id = false; |
| $names = array(); |
| |
| foreach ($this->module_cache['modules'] as $key => $row) |
| { |
| |
| if ($right_id !== false) |
| { |
| if ($row['left_id'] < $right_id) |
| { |
| continue; |
| } |
| |
| $right_id = false; |
| } |
| |
| |
| if (!$row['module_basename']) |
| { |
| $empty_category = true; |
| |
| |
| foreach (array_slice($this->module_cache['modules'], $key + 1) as $temp_row) |
| { |
| if ($temp_row['left_id'] > $row['left_id'] && $temp_row['left_id'] < $row['right_id']) |
| { |
| |
| if ($temp_row['module_basename'] && $temp_row['module_enabled']) |
| { |
| $empty_category = false; |
| break; |
| } |
| continue; |
| } |
| break; |
| } |
| |
| |
| if ($empty_category) |
| { |
| $right_id = $row['right_id']; |
| continue; |
| } |
| } |
| |
| $depth = sizeof($this->module_cache['parents'][$row['module_id']]); |
| |
| |
| |
| |
| $url_func = '_module_' . $row['module_basename'] . '_url'; |
| |
| |
| $lang_func = '_module_' . $row['module_basename'] . '_lang'; |
| |
| |
| $custom_func = '_module_' . $row['module_basename']; |
| |
| $names[$row['module_basename'] . '_' . $row['module_mode']][] = true; |
| |
| $module_row = array( |
| 'depth' => $depth, |
| |
| 'id' => (int) $row['module_id'], |
| 'parent' => (int) $row['parent_id'], |
| 'cat' => ($row['right_id'] > $row['left_id'] + 1) ? true : false, |
| |
| 'is_duplicate' => ($row['module_basename'] && sizeof($names[$row['module_basename'] . '_' . $row['module_mode']]) > 1) ? true : false, |
| |
| 'name' => (string) $row['module_basename'], |
| 'mode' => (string) $row['module_mode'], |
| 'display' => (int) $row['module_display'], |
| |
| 'url_extra' => (function_exists($url_func)) ? $url_func($row['module_mode'], $row) : '', |
| |
| 'lang' => ($row['module_basename'] && function_exists($lang_func)) ? $lang_func($row['module_mode'], $row['module_langname']) : ((!empty($user->lang[$row['module_langname']])) ? $user->lang[$row['module_langname']] : $row['module_langname']), |
| 'langname' => $row['module_langname'], |
| |
| 'left' => $row['left_id'], |
| 'right' => $row['right_id'], |
| ); |
| |
| if (function_exists($custom_func)) |
| { |
| $custom_func($row['module_mode'], $module_row); |
| } |
| |
| $this->module_ary[] = $module_row; |
| } |
| |
| unset($this->module_cache['modules'], $names); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function loaded($module_basename, $module_mode = false) |
| { |
| if (empty($this->loaded_cache)) |
| { |
| $this->loaded_cache = array(); |
| |
| foreach ($this->module_ary as $row) |
| { |
| if (!$row['name']) |
| { |
| continue; |
| } |
| |
| if (!isset($this->loaded_cache[$row['name']])) |
| { |
| $this->loaded_cache[$row['name']] = array(); |
| } |
| |
| if (!$row['mode']) |
| { |
| continue; |
| } |
| |
| $this->loaded_cache[$row['name']][$row['mode']] = true; |
| } |
| } |
| |
| if ($module_mode === false) |
| { |
| return (isset($this->loaded_cache[$module_basename])) ? true : false; |
| } |
| |
| return (!empty($this->loaded_cache[$module_basename][$module_mode])) ? true : false; |
| } |
| |
| |
| |
| |
| function module_auth($module_auth, $forum_id = false) |
| { |
| global $auth, $config; |
| |
| $module_auth = trim($module_auth); |
| |
| |
| if (!$module_auth) |
| { |
| return true; |
| } |
| |
| |
| preg_match_all('/(?: |
| "[^"\\\\]*(?:\\\\.[^"\\\\]*)*" | |
| \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' | |
| [(),] | |
| [^\s(),]+)/x', $module_auth, $match); |
| |
| $tokens = $match[0]; |
| for ($i = 0, $size = sizeof($tokens); $i < $size; $i++) |
| { |
| $token = &$tokens[$i]; |
| |
| switch ($token) |
| { |
| case ')': |
| case '(': |
| case '&&': |
| case '||': |
| case ',': |
| break; |
| |
| default: |
| if (!preg_match('#(?:acl_([a-z0-9_]+)(,\$id)?)|(?:\$id)|(?:aclf_([a-z0-9_]+))|(?:cfg_([a-z0-9_]+))|(?:request_([a-zA-Z0-9_]+))#', $token)) |
| { |
| $token = ''; |
| } |
| break; |
| } |
| } |
| |
| $module_auth = implode(' ', $tokens); |
| |
| |
| $module_auth = str_replace(' , ', ',', $module_auth); |
| |
| $forum_id = ($forum_id === false) ? $this->acl_forum_id : $forum_id; |
| |
| $is_auth = false; |
| eval('$is_auth = (int) (' . preg_replace(array('#acl_([a-z0-9_]+)(,\$id)?#', '#\$id#', '#aclf_([a-z0-9_]+)#', '#cfg_([a-z0-9_]+)#', '#request_([a-zA-Z0-9_]+)#'), array('(int) $auth->acl_get(\'\\1\'\\2)', '(int) $forum_id', '(int) $auth->acl_getf_global(\'\\1\')', '(int) $config[\'\\1\']', '!empty($_REQUEST[\'\\1\'])'), $module_auth) . ');'); |
| |
| return $is_auth; |
| } |
| |
| |
| |
| |
| function set_active($id = false, $mode = false) |
| { |
| $icat = false; |
| $this->active_module = false; |
| |
| if (request_var('icat', '')) |
| { |
| $icat = $id; |
| $id = request_var('icat', ''); |
| } |
| |
| $category = false; |
| foreach ($this->module_ary as $row_id => $item_ary) |
| { |
| |
| |
| |
| |
| if ( |
| (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && (($item_ary['mode'] == $mode && !$item_ary['cat']) || ($icat && $item_ary['cat']))) || |
| ($item_ary['parent'] === $category && !$item_ary['cat'] && !$icat && $item_ary['display']) || |
| (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && !$mode && !$item_ary['cat']) || |
| (!$id && !$mode && !$item_ary['cat'] && $item_ary['display']) |
| ) |
| { |
| if ($item_ary['cat']) |
| { |
| $id = $icat; |
| $icat = false; |
| |
| continue; |
| } |
| |
| $this->p_id = $item_ary['id']; |
| $this->p_parent = $item_ary['parent']; |
| $this->p_name = $item_ary['name']; |
| $this->p_mode = $item_ary['mode']; |
| $this->p_left = $item_ary['left']; |
| $this->p_right = $item_ary['right']; |
| |
| $this->module_cache['parents'] = $this->module_cache['parents'][$this->p_id]; |
| $this->active_module = $item_ary['id']; |
| $this->active_module_row_id = $row_id; |
| |
| break; |
| } |
| else if (($item_ary['cat'] && $item_ary['id'] === (int) $id) || ($item_ary['parent'] === $category && $item_ary['cat'])) |
| { |
| $category = $item_ary['id']; |
| } |
| } |
| } |
| |
| |
| |
| |
| |
| |
| function load_active($mode = false, $module_url = false, $execute_module = true) |
| { |
| global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user; |
| |
| $module_path = $this->include_path . $this->p_class; |
| $icat = request_var('icat', ''); |
| |
| if ($this->active_module === false) |
| { |
| trigger_error('Module not accessible', E_USER_ERROR); |
| } |
| |
| if (!class_exists("{$this->p_class}_$this->p_name")) |
| { |
| if (!file_exists("$module_path/{$this->p_class}_$this->p_name.$phpEx")) |
| { |
| trigger_error("Cannot find module $module_path/{$this->p_class}_$this->p_name.$phpEx", E_USER_ERROR); |
| } |
| |
| include("$module_path/{$this->p_class}_$this->p_name.$phpEx"); |
| |
| if (!class_exists("{$this->p_class}_$this->p_name")) |
| { |
| trigger_error("Module file $module_path/{$this->p_class}_$this->p_name.$phpEx does not contain correct class [{$this->p_class}_$this->p_name]", E_USER_ERROR); |
| } |
| |
| if (!empty($mode)) |
| { |
| $this->p_mode = $mode; |
| } |
| |
| |
| |
| $instance = "{$this->p_class}_$this->p_name"; |
| |
| $this->module = new $instance($this); |
| |
| |
| if (defined('IN_ADMIN')) |
| { |
| |
| if (!$icat && $this->module_ary[$this->active_module_row_id]['is_duplicate']) |
| { |
| $icat = $this->module_ary[$this->active_module_row_id]['parent']; |
| } |
| |
| |
| $this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; |
| } |
| else |
| { |
| |
| if ($module_url !== false) |
| { |
| $this->module->u_action = $module_url; |
| } |
| else |
| { |
| $this->module->u_action = $phpbb_root_path . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name']; |
| } |
| |
| $this->module->u_action = append_sid($this->module->u_action, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; |
| } |
| |
| |
| if (!empty($this->module_ary) && $this->active_module !== false && $this->module_ary[$this->active_module_row_id]['url_extra']) |
| { |
| $this->module->u_action .= $this->module_ary[$this->active_module_row_id]['url_extra']; |
| } |
| |
| |
| $this->module->module_path = $module_path . '/'; |
| |
| |
| |
| if ($execute_module) |
| { |
| $this->module->main($this->p_name, $this->p_mode); |
| } |
| |
| return; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function adjust_url($url_extra) |
| { |
| if (empty($this->module_ary[$this->active_module_row_id])) |
| { |
| return; |
| } |
| |
| $row = &$this->module_ary[$this->active_module_row_id]; |
| |
| |
| if (strpos($row['url_extra'], $url_extra) === false) |
| { |
| $row['url_extra'] .= $url_extra; |
| } |
| } |
| |
| |
| |
| |
| function is_active($id, $mode = false) |
| { |
| |
| foreach ($this->module_ary as $row_id => $item_ary) |
| { |
| if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && $item_ary['display']) |
| { |
| if ($mode === false || $mode === $item_ary['mode']) |
| { |
| return true; |
| } |
| } |
| } |
| |
| return false; |
| } |
| |
| |
| |
| |
| function get_parents($parent_id, $left_id, $right_id, &$all_parents) |
| { |
| global $db; |
| |
| $parents = array(); |
| |
| if ($parent_id > 0) |
| { |
| foreach ($all_parents as $module_id => $row) |
| { |
| if ($row['left_id'] < $left_id && $row['right_id'] > $right_id) |
| { |
| $parents[$module_id] = $row['parent_id']; |
| } |
| |
| if ($row['left_id'] > $left_id) |
| { |
| break; |
| } |
| } |
| } |
| |
| return $parents; |
| } |
| |
| |
| |
| |
| function get_branch($left_id, $right_id, $remaining) |
| { |
| $branch = array(); |
| |
| foreach ($remaining as $key => $row) |
| { |
| if ($row['left_id'] > $left_id && $row['left_id'] < $right_id) |
| { |
| $branch[] = $row; |
| continue; |
| } |
| break; |
| } |
| |
| return $branch; |
| } |
| |
| |
| |
| |
| |
| function build_tree(&$modules, &$parents) |
| { |
| $tree = array(); |
| |
| foreach ($modules as $row) |
| { |
| $branch = &$tree; |
| |
| if ($row['parent_id']) |
| { |
| |
| $parent_tree = $parents[$row['module_id']]; |
| |
| foreach ($parent_tree as $id => $value) |
| { |
| if (!isset($branch[$id]) && isset($branch['child'])) |
| { |
| $branch = &$branch['child']; |
| } |
| $branch = &$branch[$id]; |
| } |
| $branch = &$branch['child']; |
| } |
| |
| $branch[$row['module_id']] = $row; |
| if (!isset($branch[$row['module_id']]['child'])) |
| { |
| $branch[$row['module_id']]['child'] = array(); |
| } |
| } |
| |
| return $tree; |
| } |
| |
| |
| |
| |
| function assign_tpl_vars($module_url) |
| { |
| global $template; |
| |
| $current_id = $right_id = false; |
| |
| |
| $delim = (strpos($module_url, '?') === false) ? '?' : '&'; |
| |
| $current_padding = $current_depth = 0; |
| $linear_offset = 'l_block1'; |
| $tabular_offset = 't_block2'; |
| |
| |
| |
| |
| |
| foreach ($this->module_ary as $row_id => $item_ary) |
| { |
| |
| if (!$item_ary['display']) |
| { |
| continue; |
| } |
| |
| |
| if ($right_id !== false) |
| { |
| if ($item_ary['left'] < $right_id) |
| { |
| continue; |
| } |
| |
| $right_id = false; |
| } |
| |
| |
| if (!$item_ary['name']) |
| { |
| $empty_category = true; |
| |
| |
| foreach (array_slice($this->module_ary, $row_id + 1) as $temp_row) |
| { |
| if ($temp_row['left'] > $item_ary['left'] && $temp_row['left'] < $item_ary['right']) |
| { |
| |
| if ($temp_row['name'] && $temp_row['display']) |
| { |
| $empty_category = false; |
| break; |
| } |
| continue; |
| } |
| break; |
| } |
| |
| |
| if ($empty_category) |
| { |
| $right_id = $item_ary['right']; |
| continue; |
| } |
| } |
| |
| |
| if (!$current_id && (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id)) |
| { |
| $current_id = $item_ary['id']; |
| } |
| |
| $depth = $item_ary['depth']; |
| |
| if ($depth > $current_depth) |
| { |
| $linear_offset = $linear_offset . '.l_block' . ($depth + 1); |
| $tabular_offset = ($depth + 1 > 2) ? $tabular_offset . '.t_block' . ($depth + 1) : $tabular_offset; |
| } |
| else if ($depth < $current_depth) |
| { |
| for ($i = $current_depth - $depth; $i > 0; $i--) |
| { |
| $linear_offset = substr($linear_offset, 0, strrpos($linear_offset, '.')); |
| $tabular_offset = ($i + $depth > 1) ? substr($tabular_offset, 0, strrpos($tabular_offset, '.')) : $tabular_offset; |
| } |
| } |
| |
| $u_title = $module_url . $delim . 'i=' . (($item_ary['cat']) ? $item_ary['id'] : $item_ary['name'] . (($item_ary['is_duplicate']) ? '&icat=' . $current_id : '') . '&mode=' . $item_ary['mode']); |
| |
| |
| $u_title .= (isset($item_ary['url_extra'])) ? $item_ary['url_extra'] : ''; |
| |
| |
| if (!$depth || ($depth && (in_array($item_ary['parent'], array_values($this->module_cache['parents'])) || $item_ary['parent'] == $this->p_parent))) |
| { |
| $use_tabular_offset = (!$depth) ? 't_block1' : $tabular_offset; |
| |
| $tpl_ary = array( |
| 'L_TITLE' => $item_ary['lang'], |
| 'S_SELECTED' => (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id) ? true : false, |
| 'U_TITLE' => $u_title |
| ); |
| |
| $template->assign_block_vars($use_tabular_offset, array_merge($tpl_ary, array_change_key_case($item_ary, CASE_UPPER))); |
| } |
| |
| $tpl_ary = array( |
| 'L_TITLE' => $item_ary['lang'], |
| 'S_SELECTED' => (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id) ? true : false, |
| 'U_TITLE' => $u_title |
| ); |
| |
| $template->assign_block_vars($linear_offset, array_merge($tpl_ary, array_change_key_case($item_ary, CASE_UPPER))); |
| |
| $current_depth = $depth; |
| } |
| } |
| |
| |
| |
| |
| function get_tpl_name() |
| { |
| return $this->module->tpl_name . '.html'; |
| } |
| |
| |
| |
| |
| function get_page_title() |
| { |
| global $user; |
| |
| if (!isset($this->module->page_title)) |
| { |
| return ''; |
| } |
| |
| return (isset($user->lang[$this->module->page_title])) ? $user->lang[$this->module->page_title] : $this->module->page_title; |
| } |
| |
| |
| |
| |
| function load($class, $name, $mode = false) |
| { |
| $this->p_class = $class; |
| $this->p_name = $name; |
| |
| |
| $this->active_module = true; |
| |
| $this->load_active($mode); |
| } |
| |
| |
| |
| |
| function display($page_title, $display_online_list = true) |
| { |
| global $template, $user; |
| |
| |
| if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) |
| { |
| adm_page_header($page_title); |
| } |
| else |
| { |
| page_header($page_title, $display_online_list); |
| } |
| |
| $template->set_filenames(array( |
| 'body' => $this->get_tpl_name()) |
| ); |
| |
| if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) |
| { |
| adm_page_footer(); |
| } |
| else |
| { |
| page_footer(); |
| } |
| } |
| |
| |
| |
| |
| function set_display($id, $mode = false, $display = true) |
| { |
| foreach ($this->module_ary as $row_id => $item_ary) |
| { |
| if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && (!$mode || $item_ary['mode'] === $mode)) |
| { |
| $this->module_ary[$row_id]['display'] = (int) $display; |
| } |
| } |
| } |
| |
| |
| |
| |
| function add_mod_info($module_class) |
| { |
| global $user, $phpEx; |
| |
| if (file_exists($user->lang_path . $user->lang_name . '/mods')) |
| { |
| $add_files = array(); |
| |
| $dir = @opendir($user->lang_path . $user->lang_name . '/mods'); |
| |
| if ($dir) |
| { |
| while (($entry = readdir($dir)) !== false) |
| { |
| if (strpos($entry, 'info_' . strtolower($module_class) . '_') === 0 && substr(strrchr($entry, '.'), 1) == $phpEx) |
| { |
| $add_files[] = 'mods/' . substr(basename($entry), 0, -(strlen($phpEx) + 1)); |
| } |
| } |
| closedir($dir); |
| } |
| |
| if (sizeof($add_files)) |
| { |
| $user->add_lang($add_files); |
| } |
| } |
| } |
| } |
| |
| ?> |