/** * Extend breadcrumbs for the Admin Zone (called by breadcrumbs_get_default_stub). * * @param tempcode Reference to the breadcrumbs stub we're assembling */ function adminzone_extend_breadcrumbs(&$stub) { global $BREADCRUMB_SET_PARENTS; if (count($BREADCRUMB_SET_PARENTS) > 0 && !is_object($BREADCRUMB_SET_PARENTS[0][0])) { // Works by finding where our oldest ancestor connects on to the do-next menus, and carries from there list($zone, $attributes, ) = page_link_decode($BREADCRUMB_SET_PARENTS[0][0]); $type = array_key_exists('type', $attributes) ? $attributes['type'] : 'misc'; $page = $attributes['page']; if ($page == '_SELF') { $page = get_page_name(); } if ($zone == '_SEARCH') { $zone = get_module_zone($page); } if ($zone == '_SELF') { $zone = get_zone_name(); } } else { // Works by finding where we connect on to the do-next menus, and carries from there $type = get_param('type', 'misc'); $page = get_page_name(); $zone = get_zone_name(); } if ($page != 'admin' && $page != 'cms') { // Loop over menus, hunting for connection $hooks = find_all_hooks('systems', 'do_next_menus'); $_hooks = array(); $page_looking = $page; $page_looking = preg_replace('#^(cms|admin)\\_#', '', $page_looking); if (array_key_exists($page_looking, $hooks)) { $_hooks[$page_looking] = $hooks[$page_looking]; unset($hooks[$page_looking]); $hooks = array_merge($_hooks, $hooks); } foreach ($hooks as $hook => $sources_dir) { $run_function = extract_module_functions(get_file_base() . '/' . $sources_dir . '/hooks/systems/do_next_menus/' . $hook . '.php', array('run')); if ($run_function[0] !== NULL) { $info = is_array($run_function[0]) ? call_user_func_array($run_function[0][0], $run_function[0][1]) : eval($run_function[0]); foreach ($info as $i) { if ($i === NULL) { continue; } if ($page == $i[2][0] && (!array_key_exists('type', $i[2][1]) && $type == 'misc' || array_key_exists('type', $i[2][1]) && ($type == $i[2][1]['type'] || $i[2][1]['type'] == 'misc')) && $zone == $i[2][2]) { if ($i[0] == 'cms') { $url = build_url(array('page' => 'cms', 'type' => $i[0] == 'cms' ? NULL : $i[0]), 'cms'); } else { $url = build_url(array('page' => 'admin', 'type' => $i[0]), 'adminzone'); } require_lang('menus'); require_lang('security'); $stub->attach(hyperlink($url, do_lang_tempcode(strtoupper($i[0])), false, false, do_lang_tempcode('GO_BACKWARDS_TO', @html_entity_decode(strip_tags(do_lang(strtoupper($i[0]))), ENT_QUOTES, get_charset())))); //if ((!array_key_exists('type',$i[2][1])) || ($type==$i[2][1]['type'])) break; return; } } } } } }
/** * AJAX script for dynamically extended sitetree. */ function site_tree_script() { header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past $root_perms = array('submit_cat_highrange_content' => 0, 'edit_cat_highrange_content' => 0, 'edit_own_cat_highrange_content' => 0, 'delete_cat_highrange_content' => 0, 'delete_own_cat_highrange_content' => 0, 'submit_highrange_content' => 1, 'bypass_validation_highrange_content' => 1, 'edit_own_highrange_content' => 1, 'edit_highrange_content' => 1, 'delete_own_highrange_content' => 1, 'delete_highrange_content' => 1, 'submit_cat_midrange_content' => 0, 'edit_cat_midrange_content' => 0, 'edit_own_cat_midrange_content' => 0, 'delete_cat_midrange_content' => 0, 'delete_own_cat_midrange_content' => 0, 'submit_midrange_content' => 1, 'bypass_validation_midrange_content' => 1, 'edit_own_midrange_content' => 1, 'edit_midrange_content' => 1, 'delete_own_midrange_content' => 1, 'delete_midrange_content' => 1, 'submit_cat_lowrange_content' => 0, 'edit_cat_lowrange_content' => 0, 'edit_own_cat_lowrange_content' => 0, 'delete_cat_lowrange_content' => 0, 'delete_own_cat_lowrange_content' => 0, 'submit_lowrange_content' => 1, 'bypass_validation_lowrange_content' => 1, 'edit_own_lowrange_content' => 1, 'edit_lowrange_content' => 1, 'delete_own_lowrange_content' => 1, 'delete_lowrange_content' => 1); require_code('zones2'); require_code('zones3'); // Usergroups we have $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups(); $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true); if (!has_actual_page_access(get_member(), 'admin_site_tree', 'adminzone')) { exit; } if (function_exists('set_time_limit')) { @set_time_limit(30); } disable_php_memory_limit(); // Needed for loading large amount of permissions (potentially) // ====== // Saving // ====== if (get_param_integer('set_perms', 0) == 1) { if (!has_actual_page_access(get_member(), 'admin_permissions', 'adminzone')) { exit; } // Build a map of every page link we are setting permissions for $map = array(); foreach (array_merge($_GET, $_POST) as $i => $page_link) { if (get_magic_quotes_gpc()) { $page_link = stripslashes($page_link); } if (substr($i, 0, 4) == 'map_') { $map[intval(substr($i, 4))] = $page_link; } } // Read it all in foreach ($map as $i => $page_link) { // Decode page link $matches = array(); $type = ''; if ($page_link == '_root') { $type = 'root'; } elseif (preg_match('#^([^:]*):([^:]+):.+$#', $page_link, $matches) != 0) { $type = 'cat'; } elseif (preg_match('#^([^:]*):([^:]+)$#', $page_link, $matches) != 0) { $type = 'page'; } elseif (preg_match('#^([^:]*):?$#', $page_link, $matches) != 0) { $type = 'zone'; } else { $type = 'root'; } // Working out what we're doing with privilege overrides if ($type == 'page' || $type == 'cat') { $zone = $matches[1]; $page = $matches[2]; list($overridables, $sp_page) = get_module_overridables($zone, $page); } if ($type == 'root') { // Insertion foreach ($groups as $group => $group_name) { if (!in_array($group, $admin_groups)) { // SP's foreach (array_keys($root_perms) as $overide) { $val = post_param_integer(strval($i) . 'gsp_' . $overide . '_' . strval($group), -2); if ($val != -2) { $GLOBALS['SITE_DB']->query_delete('gsp', array('specific_permission' => $overide, 'group_id' => $group, 'the_page' => '', 'module_the_name' => '', 'category_name' => '')); if ($val != -1) { $GLOBALS['SITE_DB']->query_insert('gsp', array('specific_permission' => $overide, 'group_id' => $group, 'module_the_name' => '', 'category_name' => '', 'the_page' => '', 'the_value' => $val)); } } } } } } elseif ($type == 'zone') { $zone = $matches[1]; // Insertion foreach ($groups as $group => $group_name) { if (!in_array($group, $admin_groups)) { // View access $view = post_param_integer(strval($i) . 'g_view_' . strval($group), -1); if ($view != -1) { $GLOBALS['SITE_DB']->query_delete('group_zone_access', array('zone_name' => $zone, 'group_id' => $group)); if ($view == 1) { $GLOBALS['SITE_DB']->query_insert('group_zone_access', array('zone_name' => $zone, 'group_id' => $group)); } } } } } elseif ($type == 'page') { // Insertion foreach ($groups as $group => $group_name) { if (!in_array($group, $admin_groups)) { // View access $view = post_param_integer(strval($i) . 'g_view_' . strval($group), -1); if ($view != -1) { $GLOBALS['SITE_DB']->query_delete('group_page_access', array('zone_name' => $zone, 'page_name' => $page, 'group_id' => $group)); if ($view == 0) { // Pages have access by row non-presence, for good reason $GLOBALS['SITE_DB']->query_insert('group_page_access', array('zone_name' => $zone, 'page_name' => $page, 'group_id' => $group)); } } // SP's foreach (array_keys($overridables) as $overide) { $val = post_param_integer(strval($i) . 'gsp_' . $overide . '_' . strval($group), -2); if ($val != -2) { $GLOBALS['SITE_DB']->query_delete('gsp', array('specific_permission' => $overide, 'group_id' => $group, 'the_page' => $sp_page)); if ($val != -1) { $GLOBALS['SITE_DB']->query_insert('gsp', array('specific_permission' => $overide, 'group_id' => $group, 'module_the_name' => '', 'category_name' => '', 'the_page' => $sp_page, 'the_value' => $val)); } } } } } } elseif ($type == 'cat') { $_pagelinks = extract_module_functions_page($zone, $page, array('extract_page_link_permissions'), array($page_link)); list($category, $module) = is_array($_pagelinks[0]) ? call_user_func_array($_pagelinks[0][0], $_pagelinks[0][1]) : eval($_pagelinks[0]); // If $_pagelinks[0] is NULL then it's an error: extract_page_link_permissions is always there when there are cat permissions // Insertion foreach ($groups as $group => $group_name) { if (!in_array($group, $admin_groups)) { // View access $view = post_param_integer(strval($i) . 'g_view_' . strval($group), -1); if ($view != -1) { $GLOBALS['SITE_DB']->query_delete('group_category_access', array('module_the_name' => $module, 'category_name' => $category, 'group_id' => $group)); if ($view == 1) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => $module, 'category_name' => $category, 'group_id' => $group)); } } // SP's foreach ($overridables as $overide => $cat_support) { if (is_array($cat_support)) { $cat_support = $cat_support[0]; } if ($cat_support == 0) { continue; } $val = post_param_integer(strval($i) . 'gsp_' . $overide . '_' . strval($group), -2); if ($val != -2) { $GLOBALS['SITE_DB']->query_delete('gsp', array('specific_permission' => $overide, 'group_id' => $group, 'module_the_name' => $module, 'category_name' => $category, 'the_page' => '')); if ($val != -1) { $new_settings = array('specific_permission' => $overide, 'group_id' => $group, 'module_the_name' => $module, 'category_name' => $category, 'the_page' => '', 'the_value' => $val); $GLOBALS['SITE_DB']->query_insert('gsp', $new_settings); } } } } } } } decache('main_sitemap'); $GLOBALS['SITE_DB']->query_delete('cache'); if (function_exists('persistant_cache_empty')) { persistant_cache_empty(); } // Tra la la tada return; } // ======= // Loading // ======= $default = get_param('default', NULL, true); header('Content-Type: text/xml'); $permissions_needed = get_param_integer('get_perms', 0) == 1; // Whether we are limiting our tree to permission-supporting @ini_set('ocproducts.xss_detect', '0'); echo '<' . '?xml version="1.0" encoding="' . get_charset() . '"?' . '>'; echo '<request><result>'; require_lang('permissions'); require_lang('zones'); $page_link = get_param('id', NULL, true); $_sp_access = $GLOBALS['SITE_DB']->query_select('gsp', array('*')); $sp_access = array(); foreach ($_sp_access as $a) { if (!isset($sp_access[$a['group_id']])) { $sp_access[$a['group_id']] = array(); } $sp_access[$a['group_id']][] = $a; } if (!is_null($page_link) && $page_link != '' && (strpos($page_link, ':') === false || strpos($page_link, ':') === strlen($page_link) - 1)) { if (strpos($page_link, ':') === strlen($page_link) - 1) { $page_link = substr($page_link, 0, strlen($page_link) - 1); } // Pages in the zone $zone = $page_link; $page_type = get_param('page_type', NULL); $pages = find_all_pages_wrap($zone, false, true, FIND_ALL_PAGES__NEWEST, $page_type); ksort($pages); if ($permissions_needed) { $zone_access = $GLOBALS['SITE_DB']->query_select('group_zone_access', array('*'), array('zone_name' => $zone)); $page_access = $GLOBALS['SITE_DB']->query_select('group_page_access', array('*'), array('zone_name' => $zone)); } foreach ($pages as $page => $page_type) { if (!is_string($page)) { $page = strval($page); } $full_page_type = $page_type; $description = ''; if (strpos($full_page_type, '/') !== false) { $full_page_type = substr($full_page_type, 0, strpos($full_page_type, '/')); } if (strpos($full_page_type, ':') !== false) { $full_page_type = substr($full_page_type, 0, strpos($full_page_type, ':')); } switch ($full_page_type) { case 'redirect': list(, $redir_zone, $redir_page) = explode(':', $page_type); $page_title = html_entity_decode(strip_tags(str_replace(array('<kbd>', '</kbd>'), array('"', '"'), do_lang('REDIRECT_PAGE_TO', xmlentities($redir_zone), xmlentities($redir_page)))), ENT_QUOTES) . ': ' . (is_string($page) ? $page : strval($page)); break; case 'comcode': case 'comcode_custom': $page_title = do_lang('COMCODE_PAGE') . ': ' . (is_string($page) ? $page : strval($page)); break; case 'html': case 'html_custom': $page_title = 'HTML: ' . $page; break; case 'modules': case 'modules_custom': $page_title = do_lang('MODULE') . ': ' . $page; $matches = array(); if (preg_match('#@package\\s+(\\w+)#', file_get_contents(zone_black_magic_filterer(get_file_base() . '/' . $zone . '/pages/' . $page_type . '/' . $page . '.php')), $matches) != 0) { $package = $matches[1]; $path = get_file_base() . '/sources_custom/hooks/systems/addon_registry/' . $package . '.php'; if (!file_exists($path)) { $path = get_file_base() . '/sources/hooks/systems/addon_registry/' . $package . '.php'; } if (file_exists($path)) { require_lang('zones'); require_code('zones2'); $functions = extract_module_functions($path, array('get_description')); $description = is_array($functions[0]) ? call_user_func_array($functions[0][0], $functions[0][1]) : eval($functions[0]); $description = do_lang('FROM_ADDON', $package, $description); } } break; case 'minimodules': case 'minimodules_custom': $page_title = do_lang('MINIMODULE') . ': ' . $page; break; default: $page_title = do_lang('PAGE') . ': ' . $page; break; } if ($permissions_needed) { $view_perms = ''; foreach ($groups as $group => $group_name) { if (!in_array($group, $admin_groups)) { $view_perms .= 'g_view_' . strval($group) . '="' . (!in_array(array('zone_name' => $zone, 'page_name' => is_string($page) ? $page : strval($page), 'group_id' => $group), $page_access) ? 'true' : 'false') . '" '; } } $pagelinks = NULL; if (substr($page_type, 0, 7) != 'modules') { $overridables = array(); } else { list($overridables, $sp_page) = get_module_overridables($zone, $page); } $sp_perms = ''; foreach ($overridables as $overridable => $cat_support) { $lang_string = do_lang('PT_' . $overridable); if (is_array($cat_support)) { $lang_string = do_lang($cat_support[1]); } if (strlen($lang_string) > 20 && strpos($lang_string, '(') !== false) { $lang_string = preg_replace('# \\([^\\)]*\\)#', '', $lang_string); } $sp_perms .= 'sp_' . $overridable . '="' . xmlentities($lang_string) . '" '; foreach ($groups as $group => $group_name) { if (!in_array($group, $admin_groups)) { $override_value = -1; foreach ($sp_access[$group] as $test) { if ($test['specific_permission'] == $overridable && $test['the_page'] == $sp_page) { $override_value = $test['the_value']; } } if ($override_value != -1) { $sp_perms .= 'gsp_' . $overridable . '_' . strval($group) . '="' . strval($override_value) . '" '; } } } } if (count($overridables) == 0) { $sp_perms = 'no_sps="1" '; } $has_children = $sp_perms != ''; if (count(array_diff(array_keys($overridables), array('submit_highrange_content', 'submit_midrange_content', 'submit_lowrange_content'))) != 0) { $sp_perms .= 'inherits_something="1" '; } $serverid = $zone . ':' . (is_string($page) ? $page : strval($page)); echo '<category ' . ($serverid == $default ? 'selected="yes" ' : '') . 'description="' . xmlentities($description) . '" img_func_1="permissions_img_func_1" img_func_2="permissions_img_func_2" highlighted="true" ' . $view_perms . $sp_perms . ' id="' . uniqid('', true) . '" serverid="' . xmlentities($serverid) . '" title="' . xmlentities($page_title) . '" has_children="' . ($has_children ? 'true' : 'false') . '" selectable="true">'; } else { $extra = ''; if (strpos($page_type, 'modules') === 0) { $info = extract_module_info(zone_black_magic_filterer(get_file_base() . '/' . $zone . ($zone == '' ? '' : '/') . 'pages/' . $page_type . '/' . $page . '.php')); if (!is_null($info) && array_key_exists('author', $info)) { $extra = 'author="' . xmlentities($info['author']) . '" organisation="' . xmlentities($info['organisation']) . '" version="' . xmlentities(integer_format($info['version'])) . '" '; } } $has_children = false; // For a normal tree, we have children if we have entry points. We have children if we have categories also - but where there are categories there are also entry points if (strpos($page_type, 'modules') === 0) { $_entrypoints = extract_module_functions_page($zone, $page, array('get_entry_points')); if (!is_null($_entrypoints[0])) { $entrypoints = is_string($_entrypoints[0]) && strpos($_entrypoints[0], '::') !== false ? array('whatever' => 1) : (is_array($_entrypoints[0]) ? call_user_func_array($_entrypoints[0][0], $_entrypoints[0][1]) : eval($_entrypoints[0])); // The strpos thing is a little hack that allows it to work for base-class derived modules if (!is_array($entrypoints)) { $entrypoints = array('whatever' => 1); } $has_children = array_keys($entrypoints) != array('!'); } } global $MODULES_ZONES; $not_draggable = array_key_exists($page, $MODULES_ZONES) || $zone == 'adminzone' && substr($page, 0, 6) == 'admin_' && substr($page_type, 0, 6) == 'module'; $serverid = $zone . ':' . $page; echo '<category ' . ($serverid == $default ? 'selected="yes" ' : '') . '' . $extra . 'type="' . xmlentities($page_type) . '" description="' . xmlentities($description) . '" draggable="' . ($not_draggable ? 'false' : 'page') . '" droppable="' . ($page_type == 'zone' ? 'page' : 'false') . '" id="' . uniqid('', true) . '" serverid="' . xmlentities($serverid) . '" title="' . xmlentities($page_title) . '" has_children="' . ($has_children ? 'true' : 'false') . '" selectable="true">'; } echo '</category>'; } } elseif (!is_null($page_link) && $page_link != '') { $matches = array(); preg_match('#^([^:]*):([^:]*)#', $page_link, $matches); $zone = $matches[1]; $page = $matches[2]; if ($permissions_needed) { $category_access = $GLOBALS['SITE_DB']->query_select('group_category_access', array('*')); } $_pagelinks = extract_module_functions_page($zone, $page, array('get_page_links'), array(1, true, $page_link)); if (!is_null($_pagelinks[0])) { $pagelinks = is_array($_pagelinks[0]) ? call_user_func_array($_pagelinks[0][0], $_pagelinks[0][1]) : eval($_pagelinks[0]); if (!is_null($pagelinks[0]) && !is_null($pagelinks[1])) { $_overridables = extract_module_functions_page(get_module_zone($pagelinks[1]), $pagelinks[1], array('get_sp_overrides')); if (!is_null($_overridables[0])) { $overridables = is_array($_overridables[0]) ? call_user_func_array($_overridables[0][0], $_overridables[0][1]) : eval($_overridables[0]); } else { $overridables = array(); } } else { $overridables = array(); } } else { $pagelinks = NULL; } $_pagelinks = extract_module_functions_page($zone, $page, array('extract_page_link_permissions'), array($page_link)); list($category, $module) = is_null($_pagelinks[0]) || strlen($matches[0]) == strlen($page_link) ? array('!', '') : (is_array($_pagelinks[0]) ? call_user_func_array($_pagelinks[0][0], $_pagelinks[0][1]) : eval($_pagelinks[0])); // If $_pagelinks[0] is NULL then it's an error: extract_page_link_permissions is always there when there are cat permissions // Entry points under here if (!$permissions_needed && $zone . ':' . $page == $page_link) { $path = zone_black_magic_filterer(filter_naughty($zone) . ($zone == '' ? '' : '/') . 'pages/modules_custom/' . filter_naughty($page) . '.php', true); if (!file_exists(get_file_base() . '/' . $path)) { $path = zone_black_magic_filterer(filter_naughty($zone) . '/pages/modules/' . filter_naughty($page) . '.php', true); } require_code($path); if (class_exists('Mx_' . filter_naughty_harsh($page))) { $object = object_factory('Mx_' . filter_naughty_harsh($page)); } else { $object = object_factory('Module_' . filter_naughty_harsh($page)); } require_all_lang(); $entrypoints = $object->get_entry_points(); foreach ($entrypoints as $entry_point => $lang_string) { $serverid = $zone . ':' . $page; echo '<category ' . ($serverid == $default ? 'selected="yes" ' : '') . 'type="entry_point" id="' . uniqid('', true) . '" serverid="' . xmlentities($serverid) . ':type=' . $entry_point . '" title="' . xmlentities(do_lang('ENTRY_POINT') . ': ' . do_lang($lang_string)) . '" has_children="false" selectable="true">'; echo '</category>'; } } // Categories under here if (!is_null($pagelinks)) { foreach ($pagelinks[0] as $pagelink) { $keys = array_keys($pagelink); if (is_string($keys[0])) { $module_the_name = array_key_exists(3, $pagelinks) ? $pagelinks[3] : NULL; $category_name = is_string($pagelink['id']) ? $pagelink['id'] : strval($pagelink['id']); $actual_page_link = str_replace('!', $category_name, $pagelinks[2]); $title = $pagelink['title']; $has_children = $pagelink['child_count'] != 0; } else { $cms_module_name = NULL; $module_the_name = $pagelink[1]; $category_name = is_null($pagelink[2]) ? '' : (is_string($pagelink[2]) ? $pagelink[2] : strval($pagelink[2])); $actual_page_link = $pagelink[0]; $title = $pagelink[3]; $has_children = array_key_exists(7, $pagelink) ? $pagelink[7] : NULL; } $cms_module_name = $pagelinks[1]; if ($category_name == $category) { continue; } if ($module_the_name == 'catalogues_category' && $category_name == '') { continue; } if (!is_null($cms_module_name)) { $edit_type = '_ec'; if ($module_the_name == 'catalogues_catalogue') { $edit_type = '_ev'; } $actual_edit_link = preg_replace('#^[\\w\\_]+:[\\w\\_]+:type=[\\w\\_]+:(id|catalogue\\_name)=#', get_module_zone($cms_module_name) . ':' . $cms_module_name . ':' . $edit_type . ':', $actual_page_link); } else { $actual_edit_link = ''; } $actual_page_link = str_replace('_SELF:_SELF', $zone . ':' . $page, $actual_page_link); // Support for lazy notation if ($permissions_needed) { $highlight = $module_the_name == 'catalogues_catalogue' ? 'true' : 'false'; $view_perms = ''; $sp_perms = ''; if (!is_null($module_the_name)) { foreach ($groups as $group => $group_name) { if (!in_array($group, $admin_groups)) { $view_perms .= 'g_view_' . strval($group) . '="' . (in_array(array('module_the_name' => $module_the_name, 'category_name' => $category_name, 'group_id' => $group), $category_access) ? 'true' : 'false') . '" '; } } foreach ($overridables as $overridable => $cat_support) { $lang_string = do_lang('PT_' . $overridable); if (is_array($cat_support)) { $lang_string = do_lang($cat_support[1]); } if (strlen($lang_string) > 20 && strpos($lang_string, '(') !== false) { $lang_string = preg_replace('# \\([^\\)]*\\)#', '', $lang_string); } if (is_array($cat_support)) { $cat_support = $cat_support[0]; } if ($cat_support == 0) { continue; } $sp_perms .= 'sp_' . $overridable . '="' . xmlentities($lang_string) . '" '; foreach ($groups as $group => $group_name) { if (!in_array($group, $admin_groups)) { $override_value = -1; foreach ($sp_access[$group] as $test) { if ($test['specific_permission'] == $overridable && $test['the_page'] == '' && $test['category_name'] == $category_name && $test['module_the_name'] == $module_the_name) { $override_value = $test['the_value']; } } if ($override_value != -1) { $sp_perms .= 'gsp_' . $overridable . '_' . strval($group) . '="' . strval($override_value) . '" '; } } } } } if (count(array_diff(array_keys($overridables), array('submit_highrange_content', 'submit_midrange_content', 'submit_lowrange_content'))) != 0) { $sp_perms .= 'inherits_something="1" '; } $serverid = $actual_page_link; echo '<category ' . ($serverid == $default ? 'selected="yes" ' : '') . 'img_func_1="permissions_img_func_1" img_func_2="permissions_img_func_2" highlighted="' . $highlight . '" ' . $view_perms . $sp_perms . ' id="' . uniqid('', true) . '" serverid="' . xmlentities($serverid) . '" title="' . xmlentities($title) . '" has_children="' . ($has_children ? 'true' : 'false') . '" selectable="' . (!is_null($module_the_name) ? 'true' : 'false') . '">'; } else { $serverid = $actual_page_link; echo '<category ' . ($serverid == $default ? 'selected="yes" ' : '') . 'type="category" id="' . uniqid('', true) . '" edit="' . xmlentities($actual_edit_link) . '" serverid="' . xmlentities($serverid) . '" title="' . xmlentities($title) . '" has_children="' . ($has_children ? 'true' : 'false') . '" selectable="true">'; } echo '</category>'; } } } else { // Start of tree if ($permissions_needed) { $view_perms = ''; foreach ($groups as $group => $group_name) { if (!in_array($group, $admin_groups)) { $view_perms .= 'g_view_' . strval($group) . '="true" '; } // This isn't actually displayed in the editor } $sp_perms = ''; $sp_perms_opera_hack = ''; foreach (array_keys($root_perms) as $overridable) { $sp_perms .= 'sp_' . $overridable . '="' . xmlentities(do_lang('PT_' . $overridable)) . '" '; $sp_perms_opera_hack .= '<attribute key="' . 'sp_' . $overridable . '" value="' . xmlentities(do_lang('PT_' . $overridable)) . '" />'; foreach ($groups as $group => $group_name) { if (!in_array($group, $admin_groups)) { $override_value = 0; foreach ($sp_access[$group] as $test) { if ($test['specific_permission'] == $overridable && $test['the_page'] == '' && $test['module_the_name'] == '' && $test['category_name'] == '') { $override_value = $test['the_value']; } } $sp_perms .= 'gsp_' . $overridable . '_' . strval($group) . '="' . strval($override_value) . '" '; $sp_perms_opera_hack .= '<attribute key="' . 'gsp_' . $overridable . '_' . strval($group) . '" value="' . strval($override_value) . '" />'; } } } echo '<category serverid="_root" expanded="true" title="' . do_lang('ROOT') . '" has_children="true" selectable="true" img_func_1="permissions_img_func_1" img_func_2="permissions_img_func_2" id="' . uniqid('', true) . '" ' . $view_perms . '>'; echo $sp_perms_opera_hack; } else { echo '<category serverid="_root" expanded="true" title="' . do_lang('ROOT') . '" has_children="true" selectable="false" type="root" id="' . uniqid('', true) . '">'; } // Zones $zones = $GLOBALS['SITE_DB']->query_select('zones', array('zone_title', 'zone_name', 'zone_default_page'), NULL, 'ORDER BY zone_title', 50); if ($permissions_needed) { $zone_access = $GLOBALS['SITE_DB']->query_select('group_zone_access', array('*')); $page_access = $GLOBALS['SITE_DB']->query_select('group_page_access', array('*')); } $start_links = get_param_integer('start_links', 0) == 1; foreach ($zones as $_zone) { if (get_option('collapse_user_zones') == '1' && $_zone['zone_name'] == 'site') { continue; } $_zone['text_original'] = get_translated_text($_zone['zone_title']); $zone = $_zone['zone_name']; $zone_title = $_zone['text_original']; $serverid = $zone; if ($start_links) { $serverid = $zone . ':'; } $pages = find_all_pages_wrap($zone, false, true, FIND_ALL_PAGES__NEWEST); if ($permissions_needed) { $view_perms = ''; foreach ($groups as $group => $group_name) { if (!in_array($group, $admin_groups)) { $view_perms .= 'g_view_' . strval($group) . '="' . (in_array(array('zone_name' => $zone, 'group_id' => $group), $zone_access) ? 'true' : 'false') . '" '; } } echo '<category ' . ($serverid == $default ? 'selected="yes" ' : '') . 'img_func_1="permissions_img_func_1" img_func_2="permissions_img_func_2" no_sps="1" highlighted="true" ' . $view_perms . ' id="' . uniqid('', true) . '" serverid="' . xmlentities($serverid) . '" title="' . xmlentities(do_lang('ZONE') . ': ' . $zone_title) . '" has_children="' . (count($pages) != 0 ? 'true' : 'false') . '" selectable="true">'; } else { echo '<category ' . ($serverid == $default ? 'selected="yes" ' : '') . 'type="zone" droppable="page" id="' . uniqid('', true) . '" serverid="' . xmlentities($serverid) . '" title="' . xmlentities(do_lang('ZONE') . ': ' . $zone_title) . '" has_children="' . (count($pages) != 0 ? 'true' : 'false') . '" selectable="true">'; } echo '</category>'; } echo '</category>'; } // Mark parent cats for pre-expansion if (!is_null($default) && $default != '' && strpos($default, ':') !== false) { list($zone, $page) = explode(':', $default, 2); echo "\n" . '<expand>' . $zone . '</expand>'; echo "\n" . '<expand>' . $zone . ':</expand>'; echo "\n" . '<expand>' . $zone . ':' . $page . '</expand>'; } echo '</result></request>'; }
/** * Find the number of icons the member of staff has. * * @return integer The count */ function num_staff_icons() { $allowed_icons = 0; require_all_lang(); load_up_all_self_page_permissions(get_member()); $hooks = find_all_hooks('systems', 'do_next_menus'); foreach ($hooks as $hook => $sources_dir) { $run_function = extract_module_functions(get_file_base() . '/' . $sources_dir . '/hooks/systems/do_next_menus/' . $hook . '.php', array('run')); if (!is_null($run_function[0])) { $info = is_array($run_function[0]) ? call_user_func_array($run_function[0][0], $run_function[0][1]) : eval($run_function[0]); foreach ($info as $i) { if (is_null($i)) { continue; } if ($i[0] == '') { continue; } if (has_actual_page_access(get_member(), $i[2][0], $i[2][2])) { $allowed_icons++; } } } } return $allowed_icons; }
/** * The UI to set privileges. * * @return tempcode The UI */ function interface_specific_permissions() { require_all_lang(); require_code('zones2'); $title = get_page_title('SPECIFIC_PERMISSIONS'); $p_section = get_param('id', NULL); if (is_null($p_section) || $p_section == '') { $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/privileges'; $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_permissions'; $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/privileges'; $fields = new ocp_tempcode(); require_code('form_templates'); $_sections = $this->_get_ordered_sections(); $sections = new ocp_tempcode(); foreach ($_sections as $s) { if (is_null($s)) { $sections->attach(form_input_list_entry('', false, '', false, true)); } else { if (!is_null($s['trans'])) { $sections->attach(form_input_list_entry($s['p_section'], false, $s['trans'])); } } } $fields->attach(form_input_list(do_lang_tempcode('SECTION'), '', 'id', $sections, NULL, true)); $post_url = get_self_url(false, false, NULL, false, true); return do_template('FORM_SCREEN', array('_GUID' => 'e5d457a49a76706afebc92da3d846e74', 'GET' => true, 'SKIP_VALIDATION' => true, 'HIDDEN' => '', 'SUBMIT_NAME' => do_lang_tempcode('CHOOSE'), 'TITLE' => $title, 'FIELDS' => $fields, 'URL' => $post_url, 'TEXT' => '')); } $title = get_page_title('_SPECIFIC_PERMISSIONS', true, array(do_lang_tempcode($p_section))); $url = build_url(array('page' => '_SELF', 'type' => '_specific', 'id' => $p_section), '_SELF'); $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups(); $moderator_groups = $GLOBALS['FORUM_DRIVER']->get_moderator_groups(); $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true); $header_cells = $this->_access_header($admin_groups, $groups); $cols = new ocp_tempcode(); foreach ($groups as $id => $g_name) { if (in_array($id, $admin_groups)) { continue; } $cols->attach(do_template('PERMISSION_COLUMN_SIZER')); } // Find all module permission overrides $all_module_overrides = array(); foreach (find_all_zones() as $zone) { $all_modules = array(); $all_modules += find_all_pages($zone, 'modules_custom', 'php', false); $all_modules += find_all_pages($zone, 'modules', 'php', false); foreach ($all_modules as $module => $module_type) { $functions = extract_module_functions(zone_black_magic_filterer(get_file_base() . '/' . $zone . ($zone == '' ? '' : '/') . 'pages/' . $module_type . '/' . $module . '.php'), array('get_sp_overrides')); if (!is_null($functions[0])) { $overrides = is_array($functions[0]) ? call_user_func_array($functions[0][0], $functions[0][1]) : eval($functions[0]); foreach (array_keys($overrides) as $override) { if (!array_key_exists($override, $all_module_overrides)) { $all_module_overrides[$override] = array(); } $all_module_overrides[$override][] = $module; } } } } $all_page_permission_overridding = $GLOBALS['SITE_DB']->query_select('gsp', array('the_page', 'specific_permission'), array('category_name' => '')); // Rows (pages) $rows = new ocp_tempcode(); $where = array('p_section' => $p_section); // Added in because it was eating up too much memory $_permissions = collapse_2d_complexity('the_name', 'p_section', $GLOBALS['SITE_DB']->query_select('sp_list', array('p_section', 'the_name'), $where, 'ORDER BY p_section,the_name')); $access_rows = $GLOBALS['SITE_DB']->query_select('gsp', array('specific_permission', 'group_id'), array('the_page' => '', 'module_the_name' => '', 'category_name' => '')); $current_section = ''; $sections = new ocp_tempcode(); $_false = do_template('PERMISSION_CELL', array('_GUID' => '61aa7fa739e19caa1efb3695a5e2ab5d', 'CHECKED' => false, 'HUMAN' => '__human__', 'NAME' => '__name__')); $_true = do_template('PERMISSION_CELL', array('_GUID' => '44a888b40d7a34aed6ed2bf8ff47f1de', 'CHECKED' => true, 'HUMAN' => '__human__', 'NAME' => '__name__')); $true = $_true->evaluate(); $false = $_false->evaluate(); // Ad-hoc sorting? $orderings = array('submit_low', 'edit_own_low', 'edit_low', 'delete_own_low', 'delete_low', 'bypass_validation_low', 'submit_mid', 'edit_own_mid', 'edit_mid', 'delete_own_mid', 'delete_mid', 'bypass_validation_mid', 'submit_high', 'edit_own_high', 'edit_high', 'delete_own_high', 'delete_high', 'bypass_validation_high', 'submit_cat_low', 'edit_own_cat_low', 'edit_cat_low', 'delete_own_cat_low', 'delete_cat_low', 'bypass_cat_validation_low', 'submit_cat_mid', 'edit_own_cat_mid', 'edit_cat_mid', 'delete_own_cat_mid', 'delete_cat_mid', 'bypass_cat_validation_mid', 'submit_cat_high', 'edit_own_cat_high', 'edit_cat_high', 'delete_own_cat_high', 'delete_cat_high', 'bypass_cat_validation_high'); $permissions_first = array(); foreach ($orderings as $stub) { foreach ($_permissions as $permission => $section) { if (substr($permission, 0, strlen($stub)) == $stub) { $permissions_first[$permission] = $section; unset($_permissions[$permission]); } } } $_permissions = array_merge($permissions_first, $_permissions); // Display foreach ($_permissions as $permission => $section) { $permission_text = do_lang('PT_' . $permission, NULL, NULL, NULL, NULL, false); if (is_null($permission_text)) { continue; } if ($section != $current_section && $current_section != '') { $sections->attach(do_template('PERMISSION_S_CONFIG_SECTION', array('_GUID' => '36bc9dfbeb7ee3d91f2a18057cd30551', 'HEADER_CELLS' => $header_cells, 'SECTION' => $rows, 'CURRENT_SECTION' => do_lang_tempcode($current_section)))); $rows = new ocp_tempcode(); } $cells = ''; $code = ''; $has = true; foreach ($groups as $id => $g_name) { if (in_array($id, $admin_groups)) { continue; } $has_permission = false; foreach ($access_rows as $access_row) { if ($access_row['specific_permission'] == $permission && $access_row['group_id'] == $id) { $has_permission = true; break; } } if (!$has_permission) { $has = false; } $cells .= str_replace('__human__', escape_html(addslashes(do_lang('PERMISSION_CELL', $permission_text, $g_name))), str_replace('__name__', $permission . '__' . strval($id), $has_permission ? $true : $false)); if (in_array($id, $moderator_groups)) { $code .= 'form.elements[\'' . $permission . '__' . strval($id) . '\'].checked=true;'; } else { $code .= 'form.elements[\'' . $permission . '__' . strval($id) . '\'].checked=this.value==\'+\';'; } } if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($cells); } $tpl_map = array('_GUID' => '075f8855f0fed36b0d0f9c61108dd3de', 'HAS' => $has, 'ABBR' => $permission, 'PERMISSION' => $permission_text, 'CELLS' => $cells, 'CODE' => $code); // See if any modules can override this if (array_key_exists($permission, $all_module_overrides)) { $m_list = ''; $has_actual_overriding = false; foreach ($all_module_overrides[$permission] as $module) { $this_overrides = false; foreach ($all_page_permission_overridding as $po_row) { if ($po_row['the_page'] == $module && $po_row['specific_permission'] == $permission) { $this_overrides = true; break; } } if ($m_list != '') { $m_list .= escape_html(', '); } if ($this_overrides) { $has_actual_overriding = true; $m_list .= '<s>' . escape_html($module) . '</s>'; } else { $m_list .= '<strong>' . escape_html($module) . '</strong>'; } if ($module == 'topics') { $m_list .= ' (' . strtolower(do_lang(strpos($permission, 'lowrange') !== false ? 'FORUM_POSTS' : 'FORUM_TOPICS')) . ')'; } } if (function_exists('ocp_mark_as_escaped')) { ocp_mark_as_escaped($m_list); } $tpl_map['DESCRIPTION'] = do_lang_tempcode($has_actual_overriding ? 'SP_USED_IN_SLASHED' : 'SP_USED_IN', $m_list); } // Render row $rows->attach(do_template('PERMISSION_ROW', $tpl_map)); $current_section = $section; } $sections->attach(do_template('PERMISSION_S_CONFIG_SECTION', array('_GUID' => 'c75a07373f54c0fa31d18e360fcf26f6', 'COLS' => $cols, 'HEADER_CELLS' => $header_cells, 'SECTION' => $rows, 'CURRENT_SECTION' => do_lang_tempcode($current_section)))); breadcrumb_set_parents(array(array('_SELF:_SELF:specific', do_lang_tempcode('CHOOSE')))); return do_template('PERMISSION_S_PERMISSIONS_SCREEN', array('_GUID' => '11974f0a137266a625991d3611b8e587', 'TITLE' => $title, 'URL' => $url, 'SECTIONS' => $sections)); }
/** * Load up hooks needed to detect how to use monikers. */ function load_moniker_hooks() { global $CONTENT_OBS; if ($CONTENT_OBS === NULL) { $CONTENT_OBS = function_exists('persistant_cache_get') ? persistant_cache_get('CONTENT_OBS') : NULL; if ($CONTENT_OBS !== NULL) { foreach ($CONTENT_OBS as $ob_info) { if ($ob_info['title_field'] !== NULL && strpos($ob_info['title_field'], 'CALL:') !== false) { require_code('hooks/systems/content_meta_aware/' . $ob_info['_hook']); } } return; } $CONTENT_OBS = array(); $hooks = find_all_hooks('systems', 'content_meta_aware'); foreach ($hooks as $hook => $sources_dir) { $info_function = extract_module_functions(get_file_base() . '/' . $sources_dir . '/hooks/systems/content_meta_aware/' . $hook . '.php', array('info')); if ($info_function[0] !== NULL) { $ob_info = is_array($info_function[0]) ? call_user_func_array($info_function[0][0], $info_function[0][1]) : eval($info_function[0]); if ($ob_info === NULL) { continue; } $ob_info['_hook'] = $hook; $CONTENT_OBS[$ob_info['view_pagelink_pattern']] = $ob_info; if ($ob_info['title_field'] !== NULL && strpos($ob_info['title_field'], 'CALL:') !== false) { require_code('hooks/systems/content_meta_aware/' . $hook); } } } if (function_exists('persistant_cache_set')) { persistant_cache_set('CONTENT_OBS', $CONTENT_OBS); } } }
/** * Extract the info function from a module at a given path. * * @param PATH The path to the module * @return ?array A module information map (NULL: module contains no info method) */ function extract_module_info($path) { $functions = extract_module_functions($path, array('info')); if (is_null($functions[0])) { return NULL; } return is_array($functions[0]) ? call_user_func_array($functions[0][0], $functions[0][1]) : eval($functions[0]); }
/** * Get info about an addon, simulating an extended version of the traditional ocPortal-addon database row. * * @param string The name of the addon * @return array The map of details */ function read_addon_info($name) { $addon_rows = $GLOBALS['SITE_DB']->query_select('addons', array('*'), array('addon_name' => $name)); if (array_key_exists(0, $addon_rows)) { $addon_row = $addon_rows[0]; $addon_row['addon_files'] = array_unique(collapse_1d_complexity('filename', $GLOBALS['SITE_DB']->query_select('addons_files', array('filename'), array('addon_name' => $name)))); $addon_row['addon_dependencies'] = collapse_1d_complexity('addon_name_dependant_upon', $GLOBALS['SITE_DB']->query_select('addons_dependencies', array('addon_name_dependant_upon'), array('addon_name' => $name, 'addon_name_incompatibility' => 0))); $addon_row['addon_incompatibilities'] = collapse_1d_complexity('addon_name_dependant_upon', $GLOBALS['SITE_DB']->query_select('addons_dependencies', array('addon_name_dependant_upon'), array('addon_name' => $name, 'addon_name_incompatibility' => 1))); $addon_row['addon_dependencies_on_this'] = find_addon_dependencies_on($name); } else { $path = get_file_base() . '/sources_custom/hooks/systems/addon_registry/' . filter_naughty_harsh($name, true) . '.php'; if (!file_exists($path)) { $path = get_file_base() . '/sources/hooks/systems/addon_registry/' . filter_naughty_harsh($name, true) . '.php'; } if (!file_exists($path)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $_hook_bits = extract_module_functions($path, array('get_dependencies', 'get_version', 'get_description', 'get_file_list')); if (is_null($_hook_bits[0])) { $dep = array(); } else { $dep = is_array($_hook_bits[0]) ? call_user_func_array($_hook_bits[0][0], $_hook_bits[0][1]) : @eval($_hook_bits[0]); } $version = is_array($_hook_bits[1]) ? call_user_func_array($_hook_bits[1][0], $_hook_bits[1][1]) : @eval($_hook_bits[1]); $description = is_array($_hook_bits[2]) ? call_user_func_array($_hook_bits[2][0], $_hook_bits[2][1]) : @eval($_hook_bits[2]); if (is_null($_hook_bits[3])) { $file_list = array(); } else { $file_list = is_array($_hook_bits[3]) ? call_user_func_array($_hook_bits[3][0], $_hook_bits[3][1]) : @eval($_hook_bits[3]); } $addon_row = array('addon_name' => $name, 'addon_author' => 'Core Team', 'addon_organisation' => 'ocProducts', 'addon_version' => $version == ocp_version_number() ? ocp_version_full() : float_format($version, 1), 'addon_description' => $description, 'addon_install_time' => filemtime($path), 'addon_files' => make_global_file_list($file_list), 'addon_dependencies' => $dep['requires'], 'addon_dependencies_on_this' => find_addon_dependencies_on($name), 'addon_incompatibilities' => $dep['conflicts_with']); } return $addon_row; }
/** * Extract code to execute the requested functions with the requested parameters from the module at the given path. * We used to actually load up the module, but it ate all our RAM when we did! * * @param PATH The path to the module * @param array Array of functions to be executing * @param ?array A list of parameters to pass to our functions (NULL: none) * @param boolean Whether to do this "properly" (via proper OOP), which will consume more memory * @return array A list of pieces of code to do the equivalent of executing the requested functions with the requested parameters */ function extract_module_functions($path, $functions, $params = NULL, $prefer_direct_code_call = false) { if ($params === NULL) { $params = array(); } global $SITE_INFO; $prefer_direct_code_call = $prefer_direct_code_call || isset($SITE_INFO['prefer_direct_code_call']) && $SITE_INFO['prefer_direct_code_call'] == '1'; $hphp = defined('HIPHOP_PHP'); if ($hphp && !function_exists('quercus_version') || $prefer_direct_code_call) { global $CLASS_CACHE; if (array_key_exists($path, $CLASS_CACHE)) { $new_classes = $CLASS_CACHE[$path]; } else { if (!$hphp) { $classes_before = get_declared_classes(); } require_code(preg_replace('#^' . preg_quote(get_file_base()) . '/#', '', preg_replace('#^' . preg_quote(get_file_base()) . '/((sources)|(sources\\_custom))/(.*)\\.php#', '${4}', $path))); if (!$hphp) { $classes_after = get_declared_classes(); } $new_classes = $hphp ? array() : array_values(array_diff($classes_after, $classes_before)); if (count($new_classes) == 0) { $matches = array(); if (preg_match('#^\\s*class (\\w+)#m', file_get_contents($path), $matches) != 0) { $new_classes = array($matches[1]); } } $CLASS_CACHE[$path] = $new_classes; } if (array_key_exists(0, $new_classes) && $new_classes[0] == 'standard_aed_module') { array_shift($new_classes); } if (array_key_exists(0, $new_classes)) { $c = $new_classes[0]; $new_ob = new $c(); } else { $new_ob = NULL; } $ret = array(); foreach ($functions as $function) { if (method_exists($new_ob, $function)) { $ret[] = array(array(&$new_ob, $function), $params); } else { $ret[] = NULL; } } return $ret; } if (!is_file($path)) { $ret = array(); foreach ($functions as $function) { $ret[] = NULL; } return $ret; } $file = unixify_line_format(file_get_contents($path), NULL, false, true); if (strpos($file, 'class Mx_') !== false) { return extract_module_functions($path, $functions, $params, true); } global $ARB_COUNTER; $r = preg_replace('#[^\\w]#', '', basename($path, '.php')) . strval(mt_rand(0, 100000)) . '_' . strval($ARB_COUNTER); $ARB_COUNTER++; $out = array(); $_params = ''; $pre = substr($file, 5, strpos($file, 'class ') - 5); // FUDGEFUDGE. We assume any functions we need to pre-load precede any classes in the file $pre = preg_replace('#(^|\\n)function (\\w+)\\(.*#s', 'if (!function_exists(\'${1}\')) { ${0} }', $pre); // In case we end up extracting from this file more than once across multiple calls to extract_module_functions if ($params !== NULL) { foreach ($params as $param) { if ($_params != '') { $_params .= ','; } if (is_string($param)) { $_params .= '\'' . str_replace('\'', '\\\'', $param) . '\''; } elseif ($param === NULL) { $_params .= 'NULL'; } elseif (is_bool($param)) { $_params .= $param ? 'true' : 'false'; } else { $_params .= strval($param); } } } foreach ($functions as $function) { $start = strpos($file, 'function ' . $function . '('); $spaces = 1; if ($start === false) { $out[] = NULL; } else { while ($file[$start - $spaces - 1] != chr(10)) { $spaces++; } $end1 = strpos($file, chr(10) . str_repeat(' ', $spaces) . '}' . chr(10), $start); $end2 = strpos($file, chr(10) . str_repeat("\t", $spaces) . '}' . chr(10), $start); if ($end1 === false) { $end1 = $end2; } if ($end2 === false) { $end2 = $end1; } $end = min($end1, $end2) + 2 + $spaces; $func = substr($file, $start, $end - $start); if (strpos($func, '$this->') !== false) { return extract_module_functions($path, $functions, $params, true); } /*if (strpos($func,'function '.$function.'()')===false) Fails for default parameters (e.g. $a=NULL in function definition) { $new_func=preg_replace('#function '.preg_quote($function).'\(([^\n]*)\)#','list(${1})=array('.$_params.');',$func); } else { $new_func=preg_replace('#function '.preg_quote($function).'\(\)#','',$func); }*/ $new_func = str_replace('function ' . $function . '(', 'function ' . $function . $r . '(', $func) . 'return ' . filter_naughty_harsh($function) . $r . '(' . $_params . '); '; $out[] = $pre . "\n\n" . $new_func; $pre = ''; // Can only load that bit once } } return $out; }
/** * UI for a setup wizard step (done). * * @return tempcode The UI */ function step10() { $title = get_page_title('SETUP_WIZARD_STEP', true, array(integer_format(10), integer_format(10))); $GLOBALS['NO_QUERY_LIMIT'] = true; require_code('abstract_file_manager'); force_have_afm_details(); if (function_exists('set_time_limit')) { @set_time_limit(600); } require_code('config2'); require_code('menus2'); require_code('themes2'); require_lang('zones'); $header_text = post_param('header_text'); $name = post_param('site_name'); $theme = substr(preg_replace('#[^A-Za-z\\d]#', '_', $name), 0, 40); $installprofile = post_param('installprofile', ''); if ($installprofile != '') { // Simplify down to a single menu foreach (array('main_community', 'main_content', 'main_features', 'main_website', 'root_website') as $merge_item) { $GLOBALS['SITE_DB']->query_update('menu_items', array('i_menu' => 'site'), array('i_menu' => $merge_item)); } $duplicates = $GLOBALS['SITE_DB']->query_select('menu_items', array('id', 'COUNT(*) AS cnt'), array('i_menu' => 'site'), 'GROUP BY i_url'); foreach ($duplicates as $duplicate) { if ($duplicate['cnt'] > 1) { delete_menu_item($duplicate['id']); } } delete_menu_item_simple('site:'); // Remove panel_top if (addon_installed('redirects_editor')) { $GLOBALS['SITE_DB']->query_delete('redirects', array('r_to_page' => 'panel_top')); } $fullpath = get_custom_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/panel_top.txt'; if (file_exists($fullpath)) { @copy($fullpath, $fullpath . '.' . strval(time())); } $myfile = @fopen($fullpath, 'wt'); if ($myfile !== false) { fwrite($myfile, ''); fclose($myfile); fix_permissions($fullpath); sync_file($fullpath); } // Run any specific code for the profile $object = mixed(); if (is_file(get_file_base() . '/sources/hooks/modules/admin_setupwizard_installprofiles/' . $installprofile . '.php') || is_file(get_file_base() . '/sources_custom/hooks/modules/admin_setupwizard_installprofiles/' . $installprofile . '.php')) { require_code('hooks/modules/admin_setupwizard_installprofiles/' . $installprofile); $object = object_factory('Hook_admin_setupwizard_installprofiles_' . $installprofile, true); } if (!is_null($object)) { $object->install_code(); $installprofileblocks = $object->default_blocks(); } else { $installprofileblocks = array(); } } else { $installprofileblocks = array(); } if (post_param_integer('skip_8', 0) == 0 && function_exists('imagecreatefromstring') && addon_installed('themewizard')) { require_code('themewizard'); // Make theme global $IMG_CODES; $old_img_codes_site = $GLOBALS['SITE_DB']->query_select('theme_images', array('id', 'path'), array('theme' => $GLOBALS['FORUM_DRIVER']->get_theme(), 'lang' => user_lang())); if (!file_exists(get_custom_file_base() . '/themes/' . $theme)) { make_theme($theme, 'default', 'equations', post_param('seed_hex'), true, post_param_integer('dark', 0) == 1); } foreach (array($theme, 'default') as $logo_save_theme) { $logo = generate_logo($name, $header_text, false, $logo_save_theme, 'logo-template'); $path = 'themes/' . $logo_save_theme . '/images_custom/-logo.png'; @imagepng($logo, get_custom_file_base() . '/' . $path) or intelligent_write_error($path); actual_edit_theme_image('logo/-logo', $logo_save_theme, get_site_default_lang(), 'logo/-logo', $path, true); if (addon_installed('collaboration_zone')) { actual_edit_theme_image('logo/collaboration-logo', $logo_save_theme, get_site_default_lang(), 'logo/collaboration-logo', $path, true); } imagedestroy($logo); $logo = generate_logo($name, $header_text, false, $logo_save_theme, 'trimmed-logo-template'); $path = 'themes/' . $logo_save_theme . '/images_custom/trimmed-logo.png'; @imagepng($logo, get_custom_file_base() . '/' . $path) or intelligent_write_error($path); actual_edit_theme_image('logo/trimmed-logo', $logo_save_theme, get_site_default_lang(), 'logo/trimmed-logo', $path, true); imagedestroy($logo); } $myfile = fopen(get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/theme.ini', 'wt'); fwrite($myfile, 'title=' . $name . chr(10)); fwrite($myfile, 'description=' . do_lang('NA') . chr(10)); if (fwrite($myfile, 'author=ocPortal' . chr(10)) == 0) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } fclose($myfile); sync_file(get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/theme.ini'); $IMG_CODES['site'] = $old_img_codes_site; // Just so it renders with the old theme } // Set options if (post_param_integer('skip_3', 0) == 0) { set_option('site_name', $name); set_option('copyright', 'Copyright © ' . $name . ' ' . date('Y')); set_option('description', post_param('description')); set_option('site_scope', post_param('site_scope')); set_option('copyright', post_param('copyright')); set_option('staff_address', post_param('staff_address')); set_option('keywords', post_param('keywords')); set_option('google_analytics', post_param('google_analytics')); set_option('fixed_width', post_param('fixed_width', '0')); $a = $GLOBALS['SITE_DB']->query_value('zones', 'zone_header_text', array('zone_name' => '')); lang_remap($a, $header_text); $b = $GLOBALS['SITE_DB']->query_value_null_ok('zones', 'zone_header_text', array('zone_name' => 'site')); if (!is_null($b)) { lang_remap($b, $header_text); } } if (post_param_integer('skip_9', 0) == 0) { set_option('site_closed', strval(post_param_integer('site_closed', 0))); set_option('closed', post_param('closed', '')); } // Set addons if (post_param_integer('skip_4', 0) == 0 && get_file_base() == get_custom_file_base()) { require_lang('addons'); require_code('addons'); $addons_installed = find_installed_addons(); $uninstalling = array(); foreach ($addons_installed as $addon_row) { if (post_param_integer('addon_' . $addon_row['addon_name'], 0) == 0) { $uninstalling[$addon_row['addon_name']] = $addon_row; } } if (!file_exists(get_file_base() . '/.svn')) { do { $cnt = count($uninstalling); foreach ($addons_installed as $addon_row) { if (array_key_exists($addon_row['addon_name'], $uninstalling)) { $addon_row += read_addon_info($addon_row['addon_name']); $addon_row['addon_author'] = ''; // Fudge, to stop it dying on warnings for official addons // Check dependencies $dependencies = $addon_row['addon_dependencies_on_this']; foreach (array_keys($uninstalling) as $d) { if (in_array($d, $dependencies)) { // Can mark this dependency as irrelevant, as we are uninstalling the addon for it anyway unset($dependencies[array_search($d, $dependencies)]); } } if (count($dependencies) != 0) { unset($uninstalling[$addon_row['addon_name']]); } } } } while ($cnt != count($uninstalling)); // Dependency chains can be complex, so loop until we're stopped finding anything changing foreach ($uninstalling as $addon_row) { // Archive it off to exports/addons if ($addon_row['addon_files'] != '') { $file = preg_replace('#^[\\_\\.\\-]#', 'x', preg_replace('#[^\\w\\.\\-]#', '_', $addon_row['addon_name'])) . '.tar'; create_addon($file, explode(chr(10), $addon_row['addon_files']), $addon_row['addon_name'], implode(',', $addon_row['addon_incompatibilities']), implode(',', $addon_row['addon_dependencies']), $addon_row['addon_author'], $addon_row['addon_organisation'], $addon_row['addon_version'], $addon_row['addon_description'], 'imports/addons'); } uninstall_addon($addon_row['addon_name']); } } } // Set features if (post_param_integer('skip_5', 0) == 0) { $hooks = find_all_hooks('modules', 'admin_setupwizard'); foreach (array_keys($hooks) as $hook) { if (post_param_integer('addon_' . $hook, 0) == 1) { $path = get_file_base() . '/sources_custom/modules/systems/admin_setupwizard/' . filter_naughty_harsh($hook) . '.php'; if (!file_exists($path)) { $path = get_file_base() . '/sources/hooks/modules/admin_setupwizard/' . filter_naughty_harsh($hook) . '.php'; } $_hook_bits = extract_module_functions($path, array('set_fields')); if (is_array($_hook_bits[0])) { call_user_func_array($_hook_bits[0][0], $_hook_bits[0][1]); } else { @eval($_hook_bits[0]); } } } set_option('show_content_tagging', post_param('show_content_tagging', '0')); set_option('show_content_tagging_inline', post_param('show_content_tagging_inline', '0')); set_option('show_screen_actions', post_param('show_screen_actions', '0')); } // Zone structure $collapse_zones = post_param_integer('collapse_user_zones', 0) == 1; if (post_param_integer('skip_5', 0) == 0) { require_code('config2'); set_option('collapse_user_zones', strval($collapse_zones)); /*if (addon_installed('redirects_editor')) Old method { if ($collapse_zones) { $test=$GLOBALS['SITE_DB']->query_value_null_ok('redirects','r_from_page',array('r_from_page'=>'panel_left','r_from_zone'=>'site')); if (is_null($test)) $GLOBALS['SITE_DB']->query_insert('redirects',array('r_from_page'=>'panel_left','r_from_zone'=>'site','r_to_page'=>'panel_left','r_to_zone'=>'','r_is_transparent'=>1)); $test=$GLOBALS['SITE_DB']->query_value_null_ok('redirects','r_from_page',array('r_from_page'=>'panel_right','r_from_zone'=>'site')); if (is_null($test)) $GLOBALS['SITE_DB']->query_insert('redirects',array('r_from_page'=>'panel_right','r_from_zone'=>'site','r_to_page'=>'panel_right','r_to_zone'=>'','r_is_transparent'=>1)); $test=$GLOBALS['SITE_DB']->query_value_null_ok('redirects','r_from_page',array('r_from_page'=>'start','r_from_zone'=>'site')); if (is_null($test)) $GLOBALS['SITE_DB']->query_insert('redirects',array('r_from_page'=>'start','r_from_zone'=>'site','r_to_page'=>'start','r_to_zone'=>'','r_is_transparent'=>1)); } else { $GLOBALS['SITE_DB']->query_delete('redirects',array('r_from_page'=>'panel_left','r_from_zone'=>'site','r_to_page'=>'panel_left','r_to_zone'=>''),'',1); $GLOBALS['SITE_DB']->query_delete('redirects',array('r_from_page'=>'panel_right','r_from_zone'=>'site','r_to_page'=>'panel_right','r_to_zone'=>''),'',1); $GLOBALS['SITE_DB']->query_delete('redirects',array('r_from_page'=>'start','r_from_zone'=>'site','r_to_page'=>'start','r_to_zone'=>''),'',1); } }*/ if (post_param_integer('guest_zone_access', 0) == 1) { $guest_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups($GLOBALS['FORUM_DRIVER']->get_guest_id()); $test = $GLOBALS['SITE_DB']->query_value_null_ok('group_zone_access', 'zone_name', array('zone_name' => 'site', 'group_id' => $guest_groups[0])); if (is_null($test)) { $GLOBALS['SITE_DB']->query_insert('group_zone_access', array('zone_name' => 'site', 'group_id' => $guest_groups[0])); } } } // Rules if (post_param_integer('skip_7', 0) == 0) { $fullpath = get_custom_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/rules.txt'; if (file_exists($fullpath)) { @copy($fullpath, $fullpath . '.' . strval(time())); fix_permissions($fullpath . '.' . strval(time())); sync_file($fullpath . '.' . strval(time())); } $myfile = @fopen($fullpath, 'wt') or intelligent_write_error(get_custom_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/rules.txt'); $rf = $this->get_rules_file(post_param('rules')); if (fwrite($myfile, $rf) < strlen($rf)) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } fclose($myfile); fix_permissions($fullpath); sync_file($fullpath); } $block_options = mixed(); if ($installprofile != '' && !is_null($object)) { $block_options = $object->block_options(); } // Blocks if (post_param_integer('skip_6', 0) == 0) { require_code('setupwizard'); $page_structure = _get_zone_pages($installprofileblocks, $block_options, $collapse_zones, $installprofile); foreach ($page_structure as $zone => $zone_pages) { // Start $fullpath = get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/start.txt'; if (file_exists($fullpath)) { @copy($fullpath, $fullpath . '.' . strval(time())); } $myfile = @fopen($fullpath, 'wt') or intelligent_write_error($fullpath); if ($myfile !== false) { if ($zone_pages['start'] != '') { if (fwrite($myfile, $zone_pages['start']) == 0) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } } fclose($myfile); fix_permissions($fullpath); sync_file($fullpath); } // Left $fullpath = get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/panel_left.txt'; if (file_exists($fullpath)) { @copy($fullpath, $fullpath . '.' . strval(time())); } $myfile = @fopen($fullpath, 'wt'); if ($myfile !== false) { if ($zone_pages['left'] != '') { if (fwrite($myfile, $zone_pages['left']) == 0) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } } fclose($myfile); fix_permissions($fullpath); sync_file($fullpath); } // Right $fullpath = get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/panel_right.txt'; if (file_exists($fullpath)) { @copy($fullpath, $fullpath . '.' . strval(time())); } $myfile = fopen($fullpath, 'wt'); if ($myfile !== false) { if ($zone_pages['right'] != '') { if (fwrite($myfile, $zone_pages['right']) == 0) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } } fclose($myfile); fix_permissions($fullpath); sync_file($fullpath); } } } // We're done set_value('setup_wizard_completed', '1'); // Clear some cacheing require_code('view_modes'); require_code('zones3'); erase_comcode_page_cache(); erase_tempcode_cache(); //persistant_cache_delete('OPTIONS'); Done by set_option persistant_cache_empty(); erase_cached_templates(); //breadcrumb_set_parents(array(array('_SELF:_SELF:misc',do_lang_tempcode('START')))); //breadcrumb_set_self(do_lang_tempcode('SETUP_WIZARD_STEP',integer_format(10),integer_format(10))); $url = build_url(array('page' => '_SELF', 'type' => 'step11'), '_SELF'); return redirect_screen($title, $url, do_lang_tempcode('SUCCESS')); }
/** * Execute some temporary code put into this function. * * @return mixed Arbitrary result to output, if no text has already gone out */ function execute_temp() { require_code('zones'); require_code('zones2'); @var_dump(extract_module_functions(_get_module_path('site', 'chat'), array('install'))); }