/** * @license http://opensource.org/licenses/cpal_1.0 Common Public Attribution License * @copyright ocProducts Ltd * @package locations */ function init__locations_install() { disable_php_memory_limit(); if (function_exists('set_time_limit')) { @set_time_limit(0); } }
/** * Standard modular run function. * * @param array A map of parameters. * @return tempcode The result of execution. */ function run($map) { require_code('type_validation'); require_lang('phpdoc'); require_code('php'); require_css('adminzone'); disable_php_memory_limit(); $filename = (array_key_exists('param', $map) ? $map['param'] : 'sources/global2') . '.php'; if (substr($filename, -8) == '.php.php') { $filename = substr($filename, 0, strlen($filename) - 4); } $full_path = (get_file_base() != '' ? get_file_base() . '/' : '') . filter_naughty($filename); if (!file_exists($full_path)) { return paragraph(do_lang_tempcode('MISSING_RESOURCE')); } $_classes = get_php_file_api($filename); $classes = new ocp_tempcode(); foreach ($_classes as $class) { if ($class['name'] == '__global') { $class['name'] = do_lang('GLOBAL_FUNCTIONS') . '_' . basename($filename); } $function_summaries = new ocp_tempcode(); $functions = new ocp_tempcode(); foreach ($class['functions'] as $function) { $ret = render_php_function($function, $class); $functions->attach($ret[0]); $function_summaries->attach($ret[1]); } $classes->attach(do_template('PHP_CLASS', array('_GUID' => '5d58fc42c5fd3a5dd190f3f3699610c2', 'CLASS_NAME' => $class['name'], 'FUNCTION_SUMMARIES' => $function_summaries, 'FUNCTIONS' => $functions))); } return do_template('PHP_FILE', array('_GUID' => '6f422e6a6e846d49864d7325b212109f', 'FILENAME' => $filename, 'CLASSES' => $classes)); }
/** * Initialise state variables for the special page type being requested. * * @param ID_TEXT The special page type. * @set query templates tree lang */ function initialise_special_page_types($special_page_type) { disable_php_memory_limit(); if ($special_page_type == 'templates') { global $RECORD_TEMPLATES_USED; $RECORD_TEMPLATES_USED = true; } elseif ($special_page_type == 'tree') { global $RECORD_TEMPLATES_TREE; $RECORD_TEMPLATES_TREE = true; } elseif (substr($special_page_type, 0, 12) == 'lang_content') { global $RECORD_LANG_STRINGS_CONTENT; $RECORD_LANG_STRINGS_CONTENT = true; } elseif (substr($special_page_type, 0, 4) == 'lang') { global $RECORD_LANG_STRINGS; $RECORD_LANG_STRINGS = true; } elseif ($special_page_type == 'theme_images') { global $RECORD_IMG_CODES; $RECORD_IMG_CODES = true; } elseif ($special_page_type == 'ide_linkage') { global $RECORD_TEMPLATES_USED; $RECORD_TEMPLATES_USED = true; } }
/** * 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>'; }
/** * Handle hooks supported bot commands. Note multiple bots may support the same commands, and all respond. It is recommended all bots support the command 'help'. * * @param AUTO_LINK The ID of the chat room * @param string The command used. This is just the chat message, so you can encode and recognise your own parameter scheme if you like. * @return ?string Bot reply (NULL: bot does not handle the command) */ function handle_commands($room_id, $string) { require_code('developer_tools'); destrictify(); if ($string == '((SHAKE))') { return NULL; } if (file_exists(get_custom_file_base() . '/sources_custom/programe')) { if (get_value('octavius_installed') !== '1') { disable_php_memory_limit(); if (function_exists('set_time_limit')) { @set_time_limit(600); } $GLOBALS['SITE_DB']->query("DROP TABLE bot", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE bots", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE conversationlog", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE dstore", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE gmcache", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE gossip", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE patterns", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE templates", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE thatindex", NULL, NULL, true); $GLOBALS['SITE_DB']->query("DROP TABLE thatstack", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE bot (\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t bot tinyint(4) NOT NULL default '0',\n\t\t\t\t name varchar(255) NOT NULL default '',\n\t\t\t\t value text NOT NULL,\n\t\t\t\t PRIMARY KEY (id),\n\t\t\t\t KEY botname (bot,name)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE bots (\n\t\t\t\t id tinyint(3) unsigned NOT NULL auto_increment,\n\t\t\t\t botname varchar(255) NOT NULL default '',\n\t\t\t\t PRIMARY KEY (botname),\n\t\t\t\t KEY id (id)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE conversationlog (\n\t\t\t\t bot tinyint(3) unsigned NOT NULL default '0',\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t input text,\n\t\t\t\t response text,\n\t\t\t\t uid varchar(255) default NULL,\n\t\t\t\t enteredtime timestamp(14) NOT NULL,\n\t\t\t\t PRIMARY KEY (id),\n\t\t\t\t KEY botid (bot)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE dstore (\n\t\t\t\t uid varchar(255) default NULL,\n\t\t\t\t name text,\n\t\t\t\t value text,\n\t\t\t\t enteredtime timestamp(14) NOT NULL,\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t PRIMARY KEY (id),\n\t\t\t\t KEY nameidx (name(40))\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE gmcache (\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t bot tinyint(3) unsigned NOT NULL default '0',\n\t\t\t\t template int(11) NOT NULL default '0',\n\t\t\t\t inputstarvals text,\n\t\t\t\t thatstarvals text,\n\t\t\t\t topicstarvals text,\n\t\t\t\t patternmatched text,\n\t\t\t\t inputmatched text,\n\t\t\t\t combined text NOT NULL,\n\t\t\t\t PRIMARY KEY (id),\n\t\t\t\t KEY combined (bot,combined(255))\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE gossip (\n\t\t\t\t bot tinyint(3) unsigned NOT NULL default '0',\n\t\t\t\t gossip text,\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t PRIMARY KEY (id),\n\t\t\t\t KEY botidx (bot)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE patterns (\n\t\t\t\t bot tinyint(3) unsigned NOT NULL default '0',\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t word varchar(255) default NULL,\n\t\t\t\t ordera tinyint(4) NOT NULL default '0',\n\t\t\t\t parent int(11) NOT NULL default '0',\n\t\t\t\t isend tinyint(4) NOT NULL default '0',\n\t\t\t\t PRIMARY KEY (id),\n\t\t\t\t KEY wordparent (parent,word),\n\t\t\t\t KEY botid (bot)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE templates (\n\t\t\t\t bot tinyint(3) unsigned NOT NULL default '0',\n\t\t\t\t id int(11) NOT NULL default '0',\n\t\t\t\t template text NOT NULL,\n\t\t\t\t pattern varchar(255) default NULL,\n\t\t\t\t that varchar(255) default NULL,\n\t\t\t\t topic varchar(255) default NULL,\n\t\t\t\t PRIMARY KEY (id),\n\t\t\t\t KEY bot (id)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE thatindex (\n\t\t\t\t uid varchar(255) default NULL,\n\t\t\t\t enteredtime timestamp(14) NOT NULL,\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t PRIMARY KEY (id)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $GLOBALS['SITE_DB']->query("CREATE TABLE thatstack (\n\t\t\t\t thatid int(11) NOT NULL default '0',\n\t\t\t\t id int(11) NOT NULL auto_increment,\n\t\t\t\t value varchar(255) default NULL,\n\t\t\t\t enteredtime timestamp(14) NOT NULL,\n\t\t\t\t PRIMARY KEY (id)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true); $fp = ""; $templatesinserted = 0; $depth = array(); $whaton = ""; $pattern = ""; $topic = ""; $that = ""; $template = ""; $startupwhich = ""; $splitterarray = array(); $inputarray = array(); $genderarray = array(); $personarray = array(); $person2array = array(); require_code('programe/botloaderfuncs'); loadstartup(); makesubscode(); set_value('octavius_installed', '1'); } require_code('programe/respond'); $response = replybotname(str_replace('?', '.', $string), get_session_id(), 'octavius'); restrictify(); if (is_null($response) || $response->response == '') { return NULL; } return '[html]' . $response->response . '[/html]'; } // Eliza... // setup initial variables and values $kwarray = array(); $vararray = array(); $resparray = array(); $priarray = array(); $wordarray = array(); $kwcount = 0; $varcount = 0; $respcount = 0; $syncount = 0; mt_srand((double) microtime() * 1000000); // load knowledge file $lines_array = file(get_custom_file_base() . "/sources_custom/hooks/modules/chat_bots/knowledge.txt"); $count = count($lines_array); // This for loop goes through the entire knowledge file and places // the elements into arrays. This later allows us to pull the information // (ie. key words, variances on the keywords, and responses) out of the // arrays. for ($x = 0; $x < $count; $x++) { $lines_array[$x] = trim($lines_array[$x]); $lines_array[$x] = ereg_replace("[\\]", "", $lines_array[$x]); if (strstr($lines_array[$x], "key:")) { eregi("key: (.*)", $lines_array[$x], $kw); $kwarray[$kwcount] = strtoupper($kw[1]); $currentkw = $kwcount; $kwcount++; $varcount = 0; // reset varcount to null $respcount = 0; // reset respcount to null $pricount = 0; // reset pricount to null } else { if (strstr($lines_array[$x], "var:")) { eregi("var: (.*)", $lines_array[$x], $variance); $vararray[$currentkw][$varcount] = strtoupper($variance[1]); $varcurrent = $varcount; $varcount++; $respcount = 0; } else { if (strstr($lines_array[$x], "pri:")) { eregi("pri: (.*)", $lines_array[$x], $priority); $priarray[$currentkw] = $priority[1]; } else { if (strstr($lines_array[$x], "resp:")) { eregi("resp: (.*)", $lines_array[$x], $response); $resparray[$currentkw][$varcurrent][$respcount] = $response[1]; $respcount++; } else { if (strstr($lines_array[$x], "syn:")) { eregi("syn: (.*)", $lines_array[$x], $synonym); $synonymarray[$syncount] = strtoupper($synonym[1]); $syncount++; } else { if (strstr($lines_array[$x], "goto:")) { eregi("goto: (.*)", $lines_array[$x], $goto); $goto = strtoupper($goto[1]); // find the keyword for ($zcount = 0; $zcount < count($kwarray); $zcount++) { // if the keyword already exists if (eregi($goto, $kwarray[$zcount])) { // then we assign properties of the keyword $vararray[$currentkw][0] = $kwarray[$currentkw]; $resparray[$currentkw] = $resparray[$zcount]; } } } } } } } } } $y = 0; $z = 0; $v = 0; $bestpriority = -2; $originalstring = $string; if (!$string) { $string = "hello"; } $string = strtoupper($string); // Figures out what word in the string has the most priority. // It can then check words to the left/right of this word depending // upon settings in the knowledge.txt file. while ($y < count($kwarray)) { // remove beginning and trailing white space, breaks, etc $string = trim($string); // remove puncuation from string $string = ereg_replace('[!?,.]', '', $string); // split the string up into seperate words $wordarray = explode(" ", $string); while ($v < count($wordarray)) { if (eregi($wordarray[$v] . "\$", $kwarray[$y])) { // find which word holds the most weight in the sentance if ($bestpriority == -2) { $bestpriority = $y; } else { if ($priarray[$bestpriority] < $priarray[$y]) { $bestpriority = $y; } } } $v++; } $v = 0; $y++; } // find the variance with the most matching words $vcount = 0; while ($vcount < count($vararray[$bestpriority])) { if (strstr($vararray[$bestpriority][$vcount], "@")) { eregi("@(.*)", $vararray[$bestpriority][$vcount], $syn); // fix this $syn = $syn[1]; for ($x = 0; $x < count($synonymarray); $x++) { if (eregi($syn, strtoupper($synonymarray[$x]))) { $sarray = explode(" ", $synonymarray[$x]); for ($f = 0; $f < count($sarray); $f++) { $newstring = ereg_replace("@(.*)\$", $sarray[$f], $vararray[$bestpriority][$vcount]); // works to this point if (eregi($newstring . "\$", $string)) { $varray = explode(" ", $vararray[$bestpriority][$vcount]); if (count($varray) > $pvarray) { $bestvariance = $vcount; $pvarray = count($varray); } } } } } } else { if (ereg($vararray[$bestpriority][$vcount], $string)) { $varray = explode(" ", $vararray[$bestpriority][$vcount]); if (count($varray) > $pvarray) { $bestvariance = $vcount; $pvarray = count($varray); } } } $vcount++; } // Using the bestpriority (aka the keyword (key:) with the most weight in the sentence) // and the bestvariance (aka, the variance (var:) phrase that most fits the context of // the original sentence, we form a response. if (count($resparray[$bestpriority][$bestvariance]) > 1) { $random = mt_rand(0, count($resparray[$bestpriority][$bestvariance]) - 1); } else { $random = 0; } $response = $resparray[$bestpriority][$bestvariance][$random]; if ($response == "") { $response = "Sorry, I don't understand what you're trying to say."; } $originalstring = ereg_replace("[\\]", "", $originalstring); restrictify(); return $response; }
/** * Standard modular run function. * * @return tempcode The result of execution. */ function run() { $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/importdata'; $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_importer'; if (defined('HIPHOP_PHP')) { warn_exit(do_lang_tempcode('NO_HIPHOP')); } if (get_file_base() != get_custom_file_base()) { warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT')); } disable_php_memory_limit(); require_all_lang(); require_code('import'); require_code('config2'); require_code('ocf_moderation_action'); require_code('ocf_posts_action'); require_code('ocf_polls_action'); require_code('ocf_members_action'); require_code('ocf_groups_action'); require_code('ocf_general_action'); require_code('ocf_forums_action'); require_code('ocf_topics_action'); require_code('ocf_moderation_action2'); require_code('ocf_posts_action2'); require_code('ocf_polls_action2'); require_code('ocf_members_action2'); require_code('ocf_groups_action2'); require_code('ocf_general_action2'); require_code('ocf_forums_action2'); require_code('ocf_topics_action2'); // Decide what we're doing $type = get_param('type', 'misc'); $GLOBALS['LAX_COMCODE'] = true; if ($type == 'misc') { return $this->choose_importer(); } if ($type == 'session') { return $this->choose_session(); } if ($type == 'session2') { return $this->choose_session2(); } if ($type == 'hook') { return $this->choose_actions(); } if ($type == 'import') { return $this->do_import(); } /*if ($type=='advanced_hook') return $this->advanced_choose_actions(); if ($type=='advanced_import') return $this->advanced_do_import();*/ return new ocp_tempcode(); }
/** * Actualiser to perform Admin Zone search. * * @return tempcode Interface. */ function search() { require_all_lang(); require_code('zones2'); disable_php_memory_limit(); if (function_exists('set_time_limit')) { @set_time_limit(100); } $n = mixed(); $default_theme = $GLOBALS['FORUM_DRIVER']->get_theme(''); // Mess around to find our search keywords (takes synonyms into account, and generally tidies up) $raw_search_string = get_param('search_content', false, true); // Work out our keywords $keyword_string = $raw_search_string; $_keywords = array(); $current_word = ''; $in_quotes = false; for ($xi = 0; $xi < strlen($keyword_string); $xi++) { if ($in_quotes || trim($keyword_string[$xi]) != '') { if ($keyword_string[$xi] == '"') { $in_quotes = !$in_quotes; } else { $current_word .= $keyword_string[$xi]; } } else { if ($current_word != '') { $_keywords[] = $current_word; } $current_word = ''; } } if ($current_word != '') { $_keywords[] = $current_word; } $_keywords = $this->_strip_junk_words($_keywords); if (count($_keywords) == 0) { return do_template('INDEX_SCREEN_FANCIER_SCREEN', array('TITLE' => get_page_title('ADMIN_ZONE_SEARCH_RESULTS'), 'EMPTY' => true, 'ARRAY' => true, 'CONTENT' => '', 'PRE' => '', 'POST' => '')); } $keywords = array(); $synonym_rows = $this->_synonyms(); // Only in English by default. To do for another language, override this file using inheritance $section_limitations = array(); foreach ($_keywords as $xi => $keyword) { $_keywords = array(); $keyword = trim($keyword); if ($keyword == '') { continue; } if (substr($keyword, 0, 1) == '@') { $section_limitations[] = substr($keyword, 1); continue; } foreach ($synonym_rows as $synonyms) { if (in_array(strtolower($keyword), $synonyms) || array_key_exists($xi + 1, $_keywords) && in_array(strtolower($_keywords[$xi] . ' ' . $_keywords[$xi + 1]), $synonyms)) { $_keywords = array_merge($_keywords, $synonyms); } } $_keywords[] = $keyword; $keywords[] = $_keywords; } // Stemming, if available (needs Stemmer class like http://www.chuggnutt.com/stemmer-source.php which we can't redistribute due to it being GPL not LGPL) if (file_exists(get_file_base() . '/sources_custom/stemmer_' . user_lang() . '.php') && !in_safe_mode()) { require_code('stemmer_' . user_lang()); $stemmer = object_factory('Stemmer_' . user_lang()); foreach ($keywords as $i => $keyword_group) { $_keyword_group = $keyword_group; foreach ($keyword_group as $keyword) { // Special stemmer exceptions if ($keyword == 'news') { continue; } if ($keyword == 'defaultness') { continue; } $_keyword_group[] = $stemmer->stem($keyword); } $keywords[$i] = array_unique($_keyword_group); } } else { foreach ($keywords as $i => $keyword_group) { $_keyword_group = $keyword_group; foreach ($keyword_group as $keyword) { if (strlen($keyword) > 3 && substr($keyword, -1) == 's') { $_keyword_group[] = substr($keyword, 0, strlen($keyword) - 1); } else { $_keyword_group[] = $keyword . 's'; } } $keywords[$i] = array_unique($_keyword_group); } } $this->keywords = $keywords; $content = array(); // Admin/CMS menu icons $current_results_type = do_lang('ADMIN_MODULES'); if ($this->_section_match($section_limitations, $current_results_type)) { $content[$current_results_type] = new ocp_tempcode(); $hooks = find_all_hooks('systems', 'do_next_menus'); foreach (array_keys($hooks) as $hook) { require_code('hooks/systems/do_next_menus/' . filter_naughty_harsh($hook)); $object = object_factory('Hook_do_next_menus_' . filter_naughty_harsh($hook), true); if (is_null($object)) { continue; } $info = $object->run(true); foreach ($info as $i) { if (is_null($i)) { continue; } $n = $i[3]; if ($i[0] != '' && $this->_keyword_match(is_object($n) ? $n->evaluate() : $n) && has_actual_page_access(get_member(), $i[2][0], $i[2][2])) { $_url = build_url(array('page' => $i[2][0]) + $i[2][1], $i[2][2]); $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => 'admin', 'type' => $i[0]), 'adminzone'), do_lang(strtoupper($i[0])))); $sup = do_lang_tempcode('LOCATED_IN', $tree); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $_url, 'TITLE' => '', 'DESCRIPTION' => '', 'SUP' => $sup))); } } } } // Module entry points $current_results_type = do_lang('SCREENS'); if ($this->_section_match($section_limitations, $current_results_type)) { $content[$current_results_type] = new ocp_tempcode(); foreach (find_all_zones(false, true) as $zone => $zone_details) { $modules = find_all_modules($zone); foreach (array_keys($modules) as $page) { $_entrypoints = extract_module_functions_page($zone, $page, array('get_entry_points')); if (!is_null($_entrypoints[0])) { if (is_array($_entrypoints[0]) || strpos($_entrypoints[0], '::') === false) { $entry_points = is_array($_entrypoints[0]) ? call_user_func_array($_entrypoints[0][0], $_entrypoints[0][1]) : eval($_entrypoints[0]); } else { $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); } if (!defined('HIPHOP_PHP') && (ini_get('memory_limit') != '-1' && ini_get('memory_limit') != '0' || get_option('has_low_memory_limit') === '1') && strpos(file_get_contents(get_file_base() . '/' . $path), ' extends standard_aed_module') !== false) { $new_code = str_replace(',parent::get_entry_points()', '', str_replace('parent::get_entry_points(),', '', $_entrypoints[0])); if (strpos($new_code, 'parent::') !== false) { continue; } $entry_points = eval($new_code); } else { 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)); } $entry_points = $object->get_entry_points(); } } if ($page == 'admin_themes') { $entry_points['!themes'] = 'EDIT_CSS'; $entry_points['!!themes'] = 'EDIT_TEMPLATES'; $entry_points['!!!themes'] = 'MANAGE_THEME_IMAGES'; } if (is_null($entry_points)) { $entry_points = array(); } foreach ($entry_points as $type => $lang) { $type = str_replace('!', '', $type); // The ! was a hackerish thing just to multiply-up possibilities for the single entry-point $n = do_lang_tempcode($lang); if ($this->_keyword_match($n->evaluate()) && has_actual_page_access(get_member(), $page, $zone)) { $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => ''), $zone), $zone_details[1])); if ($zone == 'cms' || $zone == 'adminzone') { if ($page != 'admin' && $page != 'cms') { $hooks = find_all_hooks('systems', 'do_next_menus'); foreach (array_keys($hooks) as $hook) { require_code('hooks/systems/do_next_menus/' . filter_naughty_harsh($hook)); $object = object_factory('Hook_do_next_menus_' . filter_naughty_harsh($hook), true); if (is_null($object)) { continue; } $info = $object->run(); foreach ($info as $i) { if (is_null($i)) { 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']) && $zone == $i[2][2]) { if ($i[0] == 'cms') { $_url = build_url(array('page' => 'cms', 'type' => $i[0]), 'cms'); } else { $_url = build_url(array('page' => 'admin', 'type' => $i[0]), 'adminzone'); } require_lang('menus'); require_lang('security'); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink($_url, do_lang_tempcode(strtoupper($i[0])))); if ($type != 'misc') { $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => $page, 'type' => 'misc'), $zone), $i[3])); } break 2; } } } } else { $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => $page), $zone), $page)); } } $_url = build_url(array('page' => $page, 'type' => $type), $zone); $sup = $tree->is_empty() ? NULL : do_lang_tempcode('LOCATED_IN', $tree); $site_tree_editor_url = build_url(array('page' => 'admin_sitetree', 'type' => 'site_tree', 'id' => $zone . ':' . $page), 'adminzone'); $permission_tree_editor_url = build_url(array('page' => 'admin_permissions', 'id' => $zone . ':' . $page), 'adminzone'); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $_url, 'TITLE' => '', 'DESCRIPTION' => do_lang_tempcode('FIND_IN_SITE_TREE_EDITOR', escape_html($site_tree_editor_url->evaluate()), escape_html($permission_tree_editor_url->evaluate())), 'SUP' => $sup))); } } } } } } $current_results_type = do_lang('IMPORT'); if ($this->_section_match($section_limitations, $current_results_type) && has_actual_page_access(get_member(), 'admin_import')) { // Importers $content[$current_results_type] = new ocp_tempcode(); $hooks = find_all_hooks('modules', 'admin_import'); foreach (array_keys($hooks) as $hook) { if ($this->_keyword_match($hook)) { require_code('hooks/modules/admin_import/' . filter_naughty_harsh($hook)); $_hook = object_factory('Hook_' . filter_naughty_harsh($hook)); $info = $_hook->info(); $name = $info['product']; $_url = build_url(array('page' => 'admin_import', 'type' => 'session', 'importer' => $hook), get_module_zone('admin_import')); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $name, 'URL' => $_url, 'TITLE' => '', 'DESCRIPTION' => '', 'SUP' => ''))); } } } $current_results_type = do_lang('CONFIGURATION'); if (($this->_section_match($section_limitations, $current_results_type) || $this->_section_match($section_limitations, do_lang('OPTION_CATEGORIES')) || $this->_section_match($section_limitations, do_lang('OPTION_GROUPS'))) && has_actual_page_access(get_member(), 'admin_config')) { // Config options- names, descriptions, groups, categories $content[$current_results_type] = new ocp_tempcode(); $map = array(); if (!is_null($GLOBALS['CURRENT_SHARE_USER'])) { $map['shared_hosting_restricted'] = 0; } $all_options = $GLOBALS['SITE_DB']->query_select('config', array('the_name', 'human_name', 'the_page', 'section', 'explanation', 'eval'), $map); $all_options[] = array('the_name' => 'timezone', 'human_name' => 'TIME_ZONE', 'config_value' => '', 'the_type' => 'special', 'eval' => '', 'the_page' => 'SITE', 'section' => 'GENERAL', 'explanation' => '', 'shared_hosting_restricted' => 0); $config_categories = array(); $conf_found_count = 0; foreach ($all_options as $p) { if (defined('HIPHOP_PHP')) { require_code('hooks/systems/config_default/' . $p['the_name']); $hook = object_factory('Hook_config_default_' . $p['the_name']); $null_test = $hook->get_default(); } else { $GLOBALS['REQUIRE_LANG_LOOP'] = 10; // LEGACY Workaround for corrupt webhost installers $null_test = eval($p['eval']); $GLOBALS['REQUIRE_LANG_LOOP'] = 0; // LEGACY } if (!is_null($null_test)) { $n = do_lang_tempcode($p['human_name']); switch ($p['the_name']) { case 'timezone': $t = do_lang('DESCRIPTION_TIMEZONE_SITE'); break; default: $t = do_lang($p['explanation'], NULL, NULL, NULL, NULL, false); break; } if (is_null($n)) { continue; } $config_value = array_key_exists('config_value', $p) ? $p['config_value'] : get_option($p['the_name']); if ($config_value === false) { continue; } if ($this->_keyword_match($p['the_name']) || $this->_keyword_match($n->evaluate()) || $this->_keyword_match($t) || $this->_keyword_match($config_value)) { $_url = build_url(array('page' => 'admin_config', 'type' => 'category', 'id' => $p['the_page']), 'adminzone'); $url = $_url->evaluate(); $url .= '#group_' . $p['section']; if (is_null($t)) { $t = ''; } $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => 'admin', 'type' => 'setup'), 'adminzone'), do_lang_tempcode('SETUP'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_config', 'type' => 'misc'), 'adminzone'), do_lang_tempcode('CONFIGURATION'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_config', 'type' => 'category', 'id' => $p['the_page']), 'adminzone'), do_lang('CONFIG_CATEGORY_' . $p['the_page']))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink($url, do_lang($p['section']))); $sup = do_lang_tempcode('LOCATED_IN', $tree); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $url, 'TITLE' => '', 'DESCRIPTION' => protect_from_escaping($t), 'SUP' => $sup))); if ($conf_found_count > 100) { $content[$current_results_type] = do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => do_lang_tempcode('TOO_MANY_TO_CHOOSE_FROM'), 'URL' => '', 'TITLE' => '', 'DESCRIPTION' => '', 'SUP' => '')); break; } $conf_found_count++; if (!array_key_exists($p['the_page'], $config_categories)) { $config_categories[$p['the_page']] = array(); } $config_categories[$p['the_page']][$p['section']] = 1; } } } $current_results_type = do_lang('OPTION_CATEGORIES'); $content[$current_results_type] = new ocp_tempcode(); $current_results_type_2 = do_lang('OPTION_GROUPS'); $content[$current_results_type_2] = new ocp_tempcode(); foreach ($config_categories as $p => $groups) { $_n = do_lang('CONFIG_CATEGORY_' . $p, NULL, NULL, NULL, NULL, false); if (is_null($_n)) { continue; } $n = do_lang_tempcode('CONFIG_CATEGORY_' . $p); if ($this->_keyword_match($n->evaluate())) { $_url = build_url(array('page' => 'admin_config', 'type' => 'category', 'id' => $p), 'adminzone'); $description = do_lang_tempcode('CONFIG_CATEGORY_DESCRIPTION__' . $p); $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => 'admin', 'type' => 'setup'), 'adminzone'), do_lang_tempcode('SETUP'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_config', 'type' => 'misc'), 'adminzone'), do_lang_tempcode('CONFIGURATION'))); $sup = do_lang_tempcode('LOCATED_IN', $tree); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $_url, 'TITLE' => '', 'DESCRIPTION' => $description, 'SUP' => $sup))); } foreach (array_keys($groups) as $group) { $n2 = do_lang($group, NULL, NULL, NULL, NULL, false); if (is_null($n2)) { continue; } if ($this->_keyword_match($n2)) { $upload_max_filesize = ini_get('upload_max_filesize') == '0' ? do_lang('NA') : clean_file_size(php_return_bytes(ini_get('upload_max_filesize'))); $post_max_size = ini_get('post_max_size') == '0' ? do_lang('NA') : clean_file_size(php_return_bytes(ini_get('post_max_size'))); $_group_description = do_lang('CONFIG_GROUP_DESCRIP_' . $group, escape_html($post_max_size), escape_html($upload_max_filesize), NULL, NULL, false); if (is_null($_group_description)) { $group_description = new ocp_tempcode(); } else { $group_description = do_lang_tempcode('CONFIG_GROUP_DESCRIP_' . $group, escape_html($post_max_size), escape_html($upload_max_filesize), false); } $_url = build_url(array('page' => 'admin_config', 'type' => 'category', 'id' => $p), 'adminzone'); $url = $_url->evaluate(); $url .= '#group_' . $group; $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => 'admin', 'type' => 'setup'), 'adminzone'), do_lang_tempcode('SETUP'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_config', 'type' => 'misc'), 'adminzone'), do_lang_tempcode('CONFIGURATION'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_config', 'type' => 'category', 'id' => $p), 'adminzone'), do_lang('CONFIG_CATEGORY_' . $p))); $sup = do_lang_tempcode('LOCATED_IN', $tree); $content[$current_results_type_2]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n2, 'URL' => $url, 'TITLE' => '', 'DESCRIPTION' => $group_description, 'SUP' => $sup))); } } } } $current_results_type = do_lang('USERGROUPS'); if ($this->_section_match($section_limitations, $current_results_type) && has_actual_page_access(get_member(), 'admin_ocf_groups') && get_forum_type() == 'ocf') { // Usergroups $content[$current_results_type] = new ocp_tempcode(); $map = array('g_is_private_club' => 0); $all_groups = $GLOBALS['FORUM_DB']->query_select('f_groups', array('id', 'g_name'), $map); foreach ($all_groups as $p) { $n = get_translated_text($p['g_name']); if ($this->_keyword_match($n)) { $_url = build_url(array('page' => 'admin_ocf_groups', 'type' => '_ed', 'id' => $p['id']), 'adminzone'); $url = $_url->evaluate(); $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => 'admin', 'type' => 'security'), 'adminzone'), do_lang_tempcode('SECURITY'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_ocf_groups', 'type' => 'misc'), 'adminzone'), do_lang_tempcode('USERGROUPS'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_ocf_groups', 'type' => 'ed'), 'adminzone'), do_lang_tempcode('EDIT_GROUP'))); $sup = do_lang_tempcode('LOCATED_IN', $tree); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $url, 'TITLE' => '', 'DESCRIPTION' => '', 'SUP' => $sup))); } } } $current_results_type = do_lang('THEMES'); if ($this->_section_match($section_limitations, $current_results_type) && has_actual_page_access(get_member(), 'admin_themes')) { // Themes $content[$current_results_type] = new ocp_tempcode(); $map = array(); foreach (array(do_lang('SUPPORTS_WIDE'), do_lang('MOBILE_PAGES')) as $n) { if ($this->_keyword_match($n)) { $_url = build_url(array('page' => 'admin_themes', 'type' => 'edit_theme', 'theme' => $GLOBALS['FORUM_DRIVER']->get_theme('')), 'adminzone'); $url = $_url->evaluate(); $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => 'admin', 'type' => 'style'), 'adminzone'), do_lang_tempcode('STYLE'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_themes', 'type' => 'misc'), 'adminzone'), do_lang_tempcode('THEMES'))); $sup = do_lang_tempcode('LOCATED_IN', $tree); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $url, 'TITLE' => '', 'DESCRIPTION' => '', 'SUP' => $sup))); break; } } } $current_results_type = do_lang('ZONES'); if ($this->_section_match($section_limitations, $current_results_type) && has_actual_page_access(get_member(), 'admin_zones')) { // Zones $content[$current_results_type] = new ocp_tempcode(); $map = array(); $all_groups = $GLOBALS['SITE_DB']->query_select('zones', array('zone_name', 'zone_title', 'zone_header_text'), $map, 'ORDER BY zone_title', 50); foreach ($all_groups as $p) { $n = $p['zone_name']; $t = get_translated_text($p['zone_title']); $ht = get_translated_text($p['zone_header_text']); if ($this->_keyword_match($n) || $this->_keyword_match($t) || $this->_keyword_match($ht)) { $_url = build_url(array('page' => 'admin_zones', 'type' => '_edit', 'id' => $p['zone_name']), 'adminzone'); $url = $_url->evaluate(); $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => 'admin', 'type' => 'setup'), 'adminzone'), do_lang_tempcode('STRUCTURE'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_zones', 'type' => 'misc'), 'adminzone'), do_lang_tempcode('ZONES'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_zones', 'type' => 'edit'), 'adminzone'), do_lang_tempcode('EDIT_ZONE'))); $sup = do_lang_tempcode('LOCATED_IN', $tree); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $url, 'TITLE' => '', 'DESCRIPTION' => escape_html($t), 'SUP' => $sup))); } } } // Blocks $current_results_type = do_lang('_BLOCKS'); if ($this->_section_match($section_limitations, $current_results_type)) { $content[$current_results_type] = new ocp_tempcode(); $map = array(); require_code('zones2'); $all_blocks = find_all_blocks(); foreach (array_keys($all_blocks) as $p) { $t = do_lang('BLOCK_' . $p . '_DESCRIPTION'); if ($this->_keyword_match($p) || $this->_keyword_match($t)) { $url = ''; $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $p, 'URL' => $url, 'TITLE' => '', 'DESCRIPTION' => escape_html($t)))); } } } $current_results_type = do_lang('SPECIFIC_PERMISSIONS'); if ($this->_section_match($section_limitations, $current_results_type) && has_actual_page_access(get_member(), 'admin_permissions')) { // Privileges- sections/names/descriptions $content[$current_results_type] = new ocp_tempcode(); $all_permissions = $GLOBALS['SITE_DB']->query_select('sp_list', array('the_name', 'p_section')); $pt_sections = array(); foreach ($all_permissions as $p) { $n = do_lang('PT_' . $p['the_name'], NULL, NULL, NULL, NULL, false); if (is_null($n)) { continue; } if ($this->_keyword_match($n) || $this->_keyword_match($p['the_name'])) { $_url = build_url(array('page' => 'admin_permissions', 'type' => 'specific', 'id' => $p['p_section']), 'adminzone'); $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => 'admin', 'type' => 'security'), 'adminzone'), do_lang_tempcode('SECURITY'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_permissions', 'type' => 'specific'), 'adminzone'), do_lang_tempcode('SPECIFIC_PERMISSIONS'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink($_url, do_lang($p['p_section']))); $sup = do_lang_tempcode('LOCATED_IN', $tree); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $_url, 'TITLE' => '', 'DESCRIPTION' => '', 'SUP' => $sup))); } $pt_sections[$p['p_section']] = 1; } $current_results_type = do_lang('SPECIFIC_PERMISSION_SECTIONS'); $content[$current_results_type] = new ocp_tempcode(); foreach (array_keys($pt_sections) as $p) { $n = do_lang($p, NULL, NULL, NULL, NULL, false); if (is_null($n)) { continue; } if ($this->_keyword_match($n) || $this->_keyword_match($p)) { $_url = build_url(array('page' => 'admin_permissions', 'type' => 'specific', 'id' => $p), 'adminzone'); $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => 'admin', 'type' => 'security'), 'adminzone'), do_lang_tempcode('SECURITY'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_permissions', 'type' => 'specific'), 'adminzone'), do_lang_tempcode('SPECIFIC_PERMISSIONS'))); $sup = do_lang_tempcode('LOCATED_IN', $tree); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $_url, 'TITLE' => '', 'DESCRIPTION' => '', 'SUP' => $sup))); } } } $current_results_type = do_lang('USERGROUP_SETTINGS'); if ($this->_section_match($section_limitations, $current_results_type) && get_forum_type() == 'ocf' && has_actual_page_access(get_member(), 'admin_ocf_groups', 'adminzone')) { // Usergroup settings $content[$current_results_type] = new ocp_tempcode(); $applicable_langstrings = array(array('ENQUIRE_ON_NEW_IPS', 'DESCRIPTION_ENQUIRE_ON_NEW_IPS'), array('FLOOD_CONTROL_ACCESS_SECS', 'DESCRIPTION_FLOOD_CONTROL_ACCESS_SECS'), array('FLOOD_CONTROL_SUBMIT_SECS', 'DESCRIPTION_FLOOD_CONTROL_SUBMIT_SECS'), array('MAX_ATTACHMENTS_PER_POST', 'DESCRIPTION_MAX_ATTACHMENTS_PER_POST'), array('MAX_DAILY_UPLOAD_MB', 'DESCRIPTION_MAX_DAILY_UPLOAD_MB'), array('MAX_AVATAR_WIDTH', 'DESCRIPTION_MAX_AVATAR_WIDTH'), array('MAX_AVATAR_HEIGHT', 'DESCRIPTION_MAX_AVATAR_HEIGHT'), array('MAX_POST_LENGTH_COMCODE', 'DESCRIPTION_MAX_POST_LENGTH_COMCODE'), array('MAX_SIG_LENGTH_COMCODE', 'DESCRIPTION_MAX_SIG_LENGTH_COMCODE')); if (addon_installed('points')) { $applicable_langstrings = array_merge($applicable_langstrings, array(array('GIFT_POINTS_BASE', 'DESCRIPTION_GIFT_POINTS_BASE'), array('GIFT_POINTS_PER_DAY', 'DESCRIPTION_GIFT_POINTS_PER_DAY'))); } foreach ($applicable_langstrings as $_langstring) { $array = is_array($_langstring) ? $_langstring : array($_langstring); foreach ($array as $langstring) { $n = do_lang($langstring); if ($this->_keyword_match($n)) { $n = do_lang_tempcode($array[0]); $_url = build_url(array('page' => 'admin_ocf_groups', 'type' => 'ed'), 'adminzone'); $descrip = array_key_exists(1, $array) ? do_lang_tempcode($array[1]) : new ocp_tempcode(); $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => 'admin', 'type' => 'security'), 'adminzone'), do_lang_tempcode('SECURITY'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_ocf_groups', 'type' => 'misc'), 'adminzone'), do_lang_tempcode('USERGROUPS'))); $sup = do_lang_tempcode('LOCATED_IN', $tree); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $_url, 'TITLE' => '', 'DESCRIPTION' => $descrip, 'SUP' => $sup))); continue 2; } } } } $current_results_type = do_lang('MEMBER_SETTINGS'); if ($this->_section_match($section_limitations, $current_results_type) && get_forum_type() == 'ocf' && has_actual_page_access(get_member(), 'members')) { // Member settings $content[$current_results_type] = new ocp_tempcode(); $applicable_langstrings = array(array('WIDE', 'DESCRIPTION_WIDE'), array('REVEAL_AGE', 'DESCRIPTION_REVEAL_AGE'), array('PREVIEW_POSTS', 'DESCRIPTION_PREVIEW_POSTS'), array('AUTO_NOTIFICATION_CONTRIB_CONTENT', 'DESCRIPTION_AUTO_NOTIFICATION_CONTRIB_CONTENT'), array('PT_RULES_TEXT', 'PT_RULES_TEXT_DESCRIPTION')); foreach ($applicable_langstrings as $_langstring) { $array = is_array($_langstring) ? $_langstring : array($_langstring); foreach ($array as $langstring) { $n = do_lang($langstring); if ($this->_keyword_match($n)) { $n = do_lang_tempcode($array[0]); $descrip = array_key_exists(1, $array) ? do_lang_tempcode($array[1]) : new ocp_tempcode(); $_url = build_url(array('page' => 'members', 'type' => 'view'), get_module_zone('members'), NULL, false, false, false, 'tab__edit'); $url = $_url->evaluate(); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $url, 'TITLE' => '', 'DESCRIPTION' => $descrip))); continue 2; } } } } // Zone options $current_results_type = do_lang('ZONE_OPTIONS'); if ($this->_section_match($section_limitations, $current_results_type) && has_actual_page_access(get_member(), 'admin_zones', 'adminzone')) { $content[$current_results_type] = new ocp_tempcode(); $applicable_langstrings = array(array('DEFAULT_PAGE', 'DESCRIPTION_DEFAULT_PAGE'), array('HEADER_TEXT', 'DESCRIPTION_HEADER_TEXT'), array('WIDE', 'DESCRIPTION_WIDE'), array('REQUIRE_SESSION', 'DESCRIPTION_REQUIRE_SESSION'), array('DISPLAYED_IN_MENU', 'DESCRIPTION_DISPLAYED_IN_MENU'), array('THEME', get_forum_type() == 'ocf' ? '_DESCRIPTION_THEME_OCF' : '_DESCRIPTION_THEME')); foreach ($applicable_langstrings as $_langstring) { $array = is_array($_langstring) ? $_langstring : array($_langstring); foreach ($array as $langstring) { $n = do_lang($langstring); if ($this->_keyword_match($n)) { $n = do_lang_tempcode($array[0]); $_url = build_url(array('page' => 'admin_zones', 'type' => 'edit'), 'adminzone'); $descrip = array_key_exists(1, $array) ? do_lang_tempcode($array[1]) : new ocp_tempcode(); $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => 'admin', 'type' => 'structure'), 'adminzone'), do_lang_tempcode('STRUCTURE'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_zones', 'type' => 'misc'), 'adminzone'), do_lang_tempcode('ZONES'))); $sup = do_lang_tempcode('LOCATED_IN', $tree); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $_url, 'TITLE' => '', 'DESCRIPTION' => $descrip, 'SUP' => $sup))); continue 2; } } } } // Install options $current_results_type = do_lang('BASE_CONFIGURATION'); if ($this->_section_match($section_limitations, $current_results_type) && $GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())) { $content[$current_results_type] = new ocp_tempcode(); if (file_exists(get_file_base() . '/config_editor.php')) { $file_contents = file_get_contents(get_file_base() . '/config_editor.php'); $matches = array(); $num_matches = preg_match_all('#case \'([^\']+)\':\\n\\s*\\$notes=\'([^\']+)\';#', $file_contents, $matches); for ($i = 0; $i < $num_matches; $i++) { $n = stripslashes($matches[2][$i]); if ($this->_keyword_match($n)) { $url = get_base_url() . '/config_editor.php'; $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => stripslashes($matches[1][$i]), 'URL' => $url, 'TITLE' => '', 'DESCRIPTION' => $n))); } } } } // Language string names and contents $current_results_type = do_lang('MODULE_TRANS_NAME_admin_lang'); if ($this->_section_match($section_limitations, $current_results_type) && has_actual_page_access(get_member(), 'admin_lang', 'adminzone')) { $content[$current_results_type] = new ocp_tempcode(); if (user_lang() != fallback_lang()) { $content[$current_results_type]->attach(paragraph(do_lang_tempcode('SEARCH_LAUNCHPAD', escape_html(urlencode($raw_search_string)), escape_html(urlencode(user_lang()))))); } global $LANGUAGE; $lang_file_contents = array(); $lang_found = array(); foreach ($LANGUAGE[user_lang()] as $n => $n_value) { if ($this->_keyword_match($n) || $this->_keyword_match($n_value)) { $lang_found[$n] = $n_value; if (count($lang_found) > 100) { $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => do_lang_tempcode('TOO_MANY_TO_CHOOSE_FROM'), 'URL' => '', 'TITLE' => '', 'DESCRIPTION' => '', 'SUP' => ''))); $lang_found = array(); break; } } } foreach ($lang_found as $n => $n_value) { // Try and find what lang file it came from $lang_file = 'global'; foreach (array('lang', 'lang_custom') as $lang_dir) { $dh = @opendir(get_file_base() . '/' . $lang_dir . '/' . fallback_lang() . '/'); if ($dh !== false) { while (($file = readdir($dh)) !== false) { if (substr(strtolower($file), -4) == '.ini') { if (!array_key_exists($file, $lang_file_contents)) { $lang_file_contents[$file] = file_get_contents(get_file_base() . '/' . $lang_dir . '/' . fallback_lang() . '/' . $file); } if (preg_match('#^' . str_replace('#', '\\#', preg_quote($n)) . '=#m', $lang_file_contents[$file]) != 0 || file_exists(get_custom_file_base() . '/lang_custom/' . user_lang() . '/' . $file) && preg_match('#^' . str_replace('#', '\\#', preg_quote($n)) . '=#m', file_get_contents(get_custom_file_base() . '/lang_custom/' . user_lang() . '/' . $file)) != 0) { $lang_file = basename($file, '.ini'); break; } } } } } $_url = build_url(array('page' => 'admin_lang', 'type' => 'misc', 'lang' => user_lang(), 'lang_file' => $lang_file), 'adminzone'); $url = $_url->evaluate(); $url .= '#jmp_' . $n; $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => 'admin', 'type' => 'style'), 'adminzone'), do_lang_tempcode('STYLE'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_lang', 'type' => 'misc'), 'adminzone'), do_lang_tempcode('TRANSLATE_CONTENT'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_lang', 'type' => 'misc', 'lang' => user_lang(), 'lang_file' => $lang_file), 'adminzone'), $lang_file)); $sup = do_lang_tempcode('LOCATED_IN', $tree); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $url, 'TITLE' => '', 'DESCRIPTION' => escape_html($n_value), 'SUP' => $sup))); } $lang_file_contents = array(); } // Theme images $current_results_type = do_lang('MANAGE_THEME_IMAGES'); if ($this->_section_match($section_limitations, $current_results_type) && has_actual_page_access(get_member(), 'admin_themes', 'adminzone')) { $content[$current_results_type] = new ocp_tempcode(); $images = $GLOBALS['SITE_DB']->query_select('theme_images', array('id', 'theme', 'lang')); foreach ($images as $image) { $n = $image['id']; if ($this->_keyword_match($n)) { $_url = build_url(array('page' => 'admin_themes', 'type' => 'edit_image', 'theme' => $image['theme'], 'lang' => $image['lang'], 'id' => $n), 'adminzone'); $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => 'admin', 'type' => 'style'), 'adminzone'), do_lang_tempcode('STYLE'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_themes', 'type' => 'misc'), 'adminzone'), do_lang_tempcode('THEMES'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_themes', 'type' => 'edit_css', 'theme' => $image['theme']), 'adminzone'), do_lang_tempcode('EDIT_THEME_IMAGE'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(escape_html($image['theme'])); $sup = do_lang_tempcode('LOCATED_IN', $tree); $lang = $image['lang']; $lang_map = better_parse_ini_file(file_exists(get_file_base() . '/lang_custom/langs.ini') ? get_file_base() . '/lang_custom/langs.ini' : get_file_base() . '/lang/langs.ini'); $lang = array_key_exists($lang, $lang_map) ? $lang_map[$lang] : $lang; $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $_url, 'TITLE' => '', 'DESCRIPTION' => $lang, 'SUP' => $sup))); } } } // Template names $current_results_type = do_lang('TEMPLATES'); if ($this->_section_match($section_limitations, $current_results_type) && has_actual_page_access(get_member(), 'admin_themes', 'adminzone')) { $content[$current_results_type] = new ocp_tempcode(); $tpl_found = array(); foreach (array('templates_custom', 'templates') as $template_dir) { $dh = opendir(get_file_base() . '/themes/default/' . $template_dir . '/'); while (($file = readdir($dh)) !== false) { if (substr(strtolower($file), -4) == '.tpl' && !array_key_exists($file, $tpl_found)) { $n = $file; if ($this->_keyword_match(basename($n, '.tpl')) || $this->_keyword_match($n) || $template_dir == 'templates_custom' && $this->_keyword_match(file_get_contents(get_file_base() . '/themes/default/' . $template_dir . '/' . $n))) { $_url = build_url(array('page' => 'admin_themes', 'type' => '_edit_templates', 'theme' => $default_theme, 'f0file' => $file), 'adminzone'); $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => 'admin', 'type' => 'style'), 'adminzone'), do_lang_tempcode('STYLE'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_themes', 'type' => 'misc'), 'adminzone'), do_lang_tempcode('THEMES'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_themes', 'type' => 'edit_templates', 'theme' => $default_theme), 'adminzone'), do_lang_tempcode('EDIT_TEMPLATES'))); $sup = do_lang_tempcode('LOCATED_IN', $tree); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $_url, 'TITLE' => '', 'DESCRIPTION' => '', 'SUP' => $sup))); $tpl_found[$file] = 1; } } } } } // CSS file contents $current_results_type = 'CSS'; if ($this->_section_match($section_limitations, $current_results_type) && has_actual_page_access(get_member(), 'admin_themes', 'adminzone')) { $content[$current_results_type] = new ocp_tempcode(); $dh = opendir(get_file_base() . '/themes/default/css/'); while (($file = readdir($dh)) !== false) { if (substr(strtolower($file), -4) == '.css') { $n = $file; if ($this->_keyword_match(file_get_contents(get_file_base() . '/themes/default/css/' . $n))) { $_url = build_url(array('page' => 'admin_themes', 'type' => 'edit_css', 'theme' => $default_theme, 'file' => $file), 'adminzone'); $url = $_url->evaluate(); if (isset($keywords[0])) { $url .= '#' . $keywords[0][0]; } $tree = new ocp_tempcode(); $tree->attach(hyperlink(build_url(array('page' => 'admin', 'type' => 'style'), 'adminzone'), do_lang_tempcode('STYLE'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_themes', 'type' => 'misc'), 'adminzone'), do_lang_tempcode('THEMES'))); $tree->attach(do_template('BREADCRUMB_ESCAPED')); $tree->attach(hyperlink(build_url(array('page' => 'admin_themes', 'type' => 'choose_css', 'theme' => $default_theme), 'adminzone'), do_lang_tempcode('EDIT_CSS'))); $sup = do_lang_tempcode('LOCATED_IN', $tree); $content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('NAME' => $n, 'URL' => $url, 'TITLE' => '', 'DESCRIPTION' => '', 'SUP' => $sup))); } } } } //ksort($content); Don't sort, we have an implicit good order in this code file // And show results... if (addon_installed('search')) { $_search_url = build_url(array('page' => 'search', 'type' => 'results', 'content' => $raw_search_string, 'days' => '-1', 'search_comcode_pages' => 1, 'all_defaults' => 1), get_module_zone('search')); $search_url = $_search_url->evaluate(); $software_search_url = brand_base_url() . '/site/index.php?page=search&type=results&search_under=docs&search_comcode_pages=1&days=-1&content=' . urlencode($raw_search_string); $software_search_url_2 = brand_base_url() . '/site/index.php?page=search&type=results&search_ocf_posts=1&days=-1&content=' . urlencode($raw_search_string); $pre = do_lang_tempcode('ADMINZONE_SEARCH_RESULTS', escape_html($raw_search_string), escape_html($search_url), array(escape_html($software_search_url), escape_html($software_search_url_2))); } else { $pre = new ocp_tempcode(); } $found_some = false; foreach ($content as $c) { if (!$c->is_empty()) { $found_some = true; break; } } $post = strpos($raw_search_string, '"') !== false || !$found_some ? new ocp_tempcode() : do_lang_tempcode('ADMINZONE_SEARCH_TIP', escape_html(preg_replace('#\\s@\\w+#', '', $raw_search_string))); if (!$found_some && $this->and_query) { $this->and_query = false; return $this->search(); } return do_template('INDEX_SCREEN_FANCIER_SCREEN', array('TITLE' => get_page_title('ADMIN_ZONE_SEARCH_RESULTS'), 'EMPTY' => $found_some ? NULL : true, 'ARRAY' => true, 'CONTENT' => $content, 'PRE' => $pre, 'POST' => $post)); }
/** * Import wordpress db */ function import_wordpress_db() { disable_php_memory_limit(); $data = get_wordpress_data(); $is_validated = post_param_integer('wp_auto_validate', 0); $to_own_account = post_param_integer('wp_add_to_own', 0); // Create members require_code('ocf_members_action'); require_code('ocf_groups'); $def_grp_id = get_first_default_group(); $cat_id = array(); $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); foreach ($data as $values) { if (get_forum_type() == 'ocf') { $member_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_username' => $values['user_login'])); if (is_null($member_id)) { if (post_param_integer('wp_import_wordpress_users', 0) == 1) { $member_id = ocf_make_member($values['user_login'], $values['user_pass'], '', NULL, NULL, NULL, NULL, array(), NULL, $def_grp_id, 1, time(), time(), '', NULL, '', 0, 0, 1, '', '', '', 1, 0, '', 1, 1, '', NULL, '', false, 'wordpress'); } else { $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username('admin'); // Set admin as owner if (is_null($member_id)) { $member_id = $GLOBALS['FORUM_DRIVER']->get_guest_id() + 1; } } } } else { $member_id = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } // Guest user // If post should go to own account if ($to_own_account == 1) { $member_id = get_member(); } if (array_key_exists('POSTS', $values)) { // Create posts in blog foreach ($values['POSTS'] as $post_id => $post) { if (array_key_exists('category', $post)) { $cat_id = array(); foreach ($post['category'] as $cat_code => $category) { $cat_code = NULL; if ($category == 'Uncategorized') { continue; } // Skip blank category creation foreach ($NEWS_CATS as $id => $existing_cat) { if (get_translated_text($existing_cat['nc_title']) == $category) { $cat_code = $id; } } if (is_null($cat_code)) { $cat_code = add_news_category($category, 'newscats/community', $category); $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*')); $NEWS_CATS = list_to_map('id', $NEWS_CATS); } $cat_id = array_merge($cat_id, array($cat_code)); } } $owner_category_id = $GLOBALS['SITE_DB']->query_value_null_ok('news_categories', 'id', array('nc_owner' => $member_id)); if ($post['post_type'] == 'post') { $id = add_news($post['post_title'], html_to_comcode($post['post_content']), NULL, $is_validated, 1, $post['comment_status'] == 'closed' ? 0 : 1, 1, '', html_to_comcode($post['post_content']), $owner_category_id, $cat_id, NULL, $member_id, 0, time(), NULL, ''); } elseif ($post['post_type'] == 'page') { // If dont have permission to write comcode page, skip the post if (!has_submit_permission('high', get_member(), get_ip_address(), NULL, NULL)) { continue; } require_code('comcode'); // Save articles as new comcode pages $zone = filter_naughty(post_param('zone', 'site')); $lang = filter_naughty(post_param('lang', 'EN')); $file = preg_replace('/[^A-Za-z0-9]/', '_', $post['post_title']); // Filter non alphanumeric charactors $parent_page = post_param('parent_page', ''); $fullpath = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . $lang . '/' . $file . '.txt'); // Check existancy of new page $submiter = $GLOBALS['SITE_DB']->query_value_null_ok('comcode_pages', 'p_submitter', array('the_zone' => $zone, 'the_page' => $file)); if (!is_null($submiter)) { continue; } // Skip existing titled articles - may need change require_code('submit'); give_submit_points('COMCODE_PAGE_ADD'); if (!addon_installed('unvalidated')) { $is_validated = 1; } $GLOBALS['SITE_DB']->query_insert('comcode_pages', array('the_zone' => $zone, 'the_page' => $file, 'p_parent_page' => $parent_page, 'p_validated' => $is_validated, 'p_edit_date' => NULL, 'p_add_date' => strtotime($post['post_date']), 'p_submitter' => $member_id, 'p_show_as_edit' => 0)); if (!file_exists($fullpath)) { $_content = html_to_comcode($post['post_content']); $myfile = @fopen($fullpath, 'wt'); if ($myfile === false) { intelligent_write_error($fullpath); } if (fwrite($myfile, $_content) < strlen($_content)) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } fclose($myfile); sync_file($fullpath); } require_code('seo2'); seo_meta_set_for_explicit('comcode_page', $zone . ':' . $file, post_param('meta_keywords', ''), post_param('meta_description', '')); require_code('permissions2'); set_page_permissions_from_environment($zone, $file); } $content_url = build_url(array('page' => 'news', 'type' => 'view', 'id' => $id), get_module_zone('news'), NULL, false, false, true); $content_title = $post['post_title']; // Add comments if (post_param_integer('wp_import_blog_comments', 0) == 1) { if (array_key_exists('COMMENTS', $post)) { $submitter = NULL; foreach ($post['COMMENTS'] as $comment) { $submitter = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_username' => $comment['comment_author'])); if (is_null($submitter)) { $submitter = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } // If comment is made by a non-member, assign comment to guest account $forum = is_null(get_value('comment_forum__news')) ? get_option('comments_forum_name') : get_value('comment_forum__news'); $result = $GLOBALS['FORUM_DRIVER']->make_post_forum_topic($forum, 'news_' . strval($id), $submitter, $post['post_title'], $comment['comment_content'], $content_title, do_lang('COMMENT'), $content_url, NULL, NULL, 1, 1, false); } } } } } } }
/** * Start up a search for page-links, writing results into the callback. Usually we pass a callback that builds a Sitemap XML file, but we don't need to- it can be anything. * * @param string Callback function to send discovered page-links to. * @param MEMBER The member we are finding stuff for (we only find what the member can view). * @param ?array Page-links to skip (NULL: none). Currently this only works on pages, but may be expanded in the future. * @param integer Code for how deep we are tunnelling down, in terms of what kinds of things we'll go so far as to collect. Use DEPTH__* constants for the values. */ function spawn_page_crawl($callback, $member_id, $extra_filters = NULL, $depth = 1) { require_all_lang(); require_code('zones2'); if (is_null($extra_filters)) { $extra_filters = array(); } $comcode_page_rows = $GLOBALS['SITE_DB']->query_select('comcode_pages', array('*')); $_zones = array(); $zones = find_all_zones(false, true, true); // Reorder a bit $zones2 = array(); foreach (array('', 'site') as $zone_match) { foreach ($zones as $i => $zone) { if ($zone[0] == $zone_match) { $zones2[] = $zone; unset($zones[$i]); } } } $zones2 = array_merge($zones2, $zones); if (function_exists('set_time_limit')) { @set_time_limit(0); } disable_php_memory_limit(); $GLOBALS['MEMORY_OVER_SPEED'] = true; foreach ($zones2 as $z) { list($zone, $zone_title, , $zone_default_page) = $z; if (has_zone_access($member_id, $zone)) { $done_zone_level = false; $_pages = array(); $pages = find_all_pages_wrap($zone, false, false, FIND_ALL_PAGES__ALL); foreach ($pages as $page => $page_type) { if (is_integer($page)) { $page = strval($page); } if (substr($page, 0, 6) == 'panel_') { continue; } if (substr($page, 0, 1) == '_') { continue; } if (in_array($zone . ':' . $page, $extra_filters)) { continue; } if ($page == '404') { continue; } if ($page == 'forums' && substr($page_type, 0, 7) == 'modules' && (get_forum_type() == 'ocf' || get_forum_type() == 'none')) { continue; } if ($page == 'join' && substr($page_type, 0, 7) == 'modules' && !is_guest($member_id)) { continue; } if (has_page_access($member_id, $page, $zone)) { // Page level $_entrypoints = array(); $__entrypoints = extract_module_functions_page($zone, $page, array('get_entry_points')); if (!is_null($__entrypoints[0])) { $entrypoints = is_array($__entrypoints[0]) ? call_user_func_array($__entrypoints[0][0], $__entrypoints[0][1]) : (strpos($__entrypoints[0], '::') !== false ? NULL : eval($__entrypoints[0])); // The strpos thing is a little hack that allows it to work for base-class derived modules if (is_null($entrypoints)) { $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/' . $page_type . '/' . $page . '.php', true); if (!defined('HIPHOP_PHP') && (ini_get('memory_limit') != '-1' && ini_get('memory_limit') != '0' || get_option('has_low_memory_limit') === '1') && strpos(file_get_contents(get_file_base() . '/' . $path), ' extends standard_aed_module') !== false) { $new_code = str_replace(',parent::get_entry_points()', '', str_replace('parent::get_entry_points(),', '', $__entrypoints[0])); if (strpos($new_code, 'parent::') !== false) { continue; } $entrypoints = eval($new_code); } else { 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)); } $entrypoints = $object->get_entry_points(); } } } else { $entrypoints = array('!'); } if (!is_array($entrypoints)) { $entrypoints = array('!'); } if ($entrypoints == array('!')) { if ($zone_default_page == $page) { $done_zone_level = true; } $add_date = NULL; $edit_date = NULL; $pagelink = $zone_default_page == $page ? $zone : $zone . ':' . $page; $title = ucwords(str_replace('_', ' ', $page)); if (substr($page_type, 0, 7) == 'comcode') { foreach ($comcode_page_rows as $page_row) { if ($page_row['p_validated'] == 0 && $page_row['the_page'] == $page && $page_row['the_zone'] == $zone) { continue 2; } } $path = zone_black_magic_filterer((strpos($page_type, '_custom') !== false ? get_custom_file_base() : get_file_base()) . '/' . filter_naughty($zone) . '/pages/' . filter_naughty($page_type) . '/' . $page . '.txt'); $add_date = filectime($path); $edit_date = filemtime($path); $page_contents = file_get_contents($path); $matches = array(); if (preg_match('#\\[title[^\\]]*\\]#', $page_contents, $matches) != 0) { $start = strpos($page_contents, $matches[0]) + strlen($matches[0]); $end = strpos($page_contents, '[/title]', $start); $matches = array(); if (preg_match('#^[^\\[\\{\\&]*$#', substr($page_contents, $start, $end - $start), $matches) != 0) { $title = $matches[0]; } else { $_title = comcode_to_tempcode(substr($page_contents, $start, $end - $start), NULL, true); $title = strip_tags(@html_entity_decode($_title->evaluate(), ENT_QUOTES, get_charset())); } } } elseif (substr($page_type, 0, 4) == 'html') { $path = zone_black_magic_filterer((strpos($page_type, '_custom') !== false ? get_custom_file_base() : get_file_base()) . '/' . filter_naughty($zone) . '/pages/' . filter_naughty($page_type) . '/' . $page . '.htm'); $add_date = filectime($path); $edit_date = filemtime($path); $page_contents = file_get_contents($path); $matches = array(); if (preg_match('#\\<title[^\\>]*\\>#', $page_contents, $matches) != 0) { $start = strpos($page_contents, $matches[0]) + strlen($matches[0]); $end = strpos($page_contents, '</title>', $start); $title = strip_tags(@html_entity_decode(substr($page_contents, $start, $end - $start), ENT_QUOTES, get_charset())); } } // Callback call_user_func_array($callback, array($pagelink, $zone, $add_date, $edit_date, $zone_default_page == $page ? 1.0 : 0.8, $title)); } elseif (count($entrypoints) != 0) { // Entry point level $done_top = false; if ($depth >= DEPTH__ENTRY_POINTS) { foreach ($entrypoints as $entrypoint => $title) { if ($entrypoint == '!') { $pagelink = $zone . ':' . $page; $done_top = true; if ($zone_default_page == $page) { $done_zone_level = true; } } else { $pagelink = $zone . ':' . $page . ':' . $entrypoint; if ($zone_default_page == $page && $entrypoint == 'misc') { $done_zone_level = true; } } // Callback call_user_func_array($callback, array($pagelink, count($_entrypoints) > 1 && $entrypoint != '!' ? $zone . ':' . $page : $zone, NULL, NULL, $entrypoint == '!' || $entrypoint == 'misc' ? 0.8 : 0.7, $title)); } } //ksort($_entrypoints); $title = do_lang('MODULE_TRANS_NAME_' . $page, NULL, NULL, NULL, NULL, false); if (is_null($title)) { $title = ucwords(str_replace('_', ' ', preg_replace('#^ocf\\_#', '', preg_replace('#^' . str_replace('#', '\\#', preg_quote($zone)) . '_#', '', preg_replace('#^' . str_replace('#', '\\#', preg_quote(str_replace('zone', '', $zone))) . '_#', '', $page))))); } if (count($_entrypoints) > 1 && !$done_top) { // Callback call_user_func_array($callback, array($zone . ':' . $page, $zone, NULL, NULL, 0.8, $title, false)); } } // Categories if ($depth >= DEPTH__CATEGORIES) { $__sitemap_pagelinks = extract_module_functions_page($zone, $page, array('get_sitemap_pagelinks'), array($callback, $member_id, $depth, $zone . ':' . $page . ':')); if (!is_null($__sitemap_pagelinks[0])) { if (is_array($__sitemap_pagelinks[0])) { call_user_func_array($__sitemap_pagelinks[0][0], $__sitemap_pagelinks[0][1]); } else { eval($__sitemap_pagelinks[0]); } } } } } // Zone level if (!$done_zone_level) { // Callback call_user_func_array($callback, array($zone, '', filectime(get_file_base() . '/' . $zone), NULL, 1.0, $zone_title)); } } } }
/** * Standard code module initialisation function. */ function init__global2() { global $BOOTSTRAPPING, $CHECKING_SAFEMODE, $BAD_WORD_CHARS, $FIXED_WORD_CHARS, $FIXED_WORD_CHARS_HTML, $BROWSER_DECACHEING, $CHARSET, $TEMP_CHARSET, $RELATIVE_PATH, $CURRENTLY_HTTPS, $RUNNING_SCRIPT_CACHE, $SERVER_TIMEZONE, $HAS_SET_ERROR_HANDLER, $DYING_BADLY, $XSS_DETECT, $SITE_INFO, $JAVASCRIPTS, $JAVASCRIPT, $CSSS, $IN_MINIKERNEL_VERSION, $EXITING, $FILE_BASE, $MOBILE, $CACHE_TEMPLATES, $BASE_URL_HTTP, $BASE_URL_HTTPS, $WORDS_TO_FILTER, $FIELD_RESTRICTIONS, $VALID_ENCODING, $CONVERTED_ENCODING, $MICRO_BOOTUP, $MICRO_AJAX_BOOTUP, $QUERY_LOG, $_CREATED_FILES, $CURRENT_SHARE_USER, $CACHE_FIND_SCRIPT; if (str_replace(array('on', 'true', 'yes'), array('1', '1', '1'), strtolower(ini_get('output_buffering'))) == '1') { @ob_end_clean(); } if (array_key_exists('HTTP_X_REWRITE_URL', $_SERVER)) { foreach ($_GET as $key => $val) { if ($key[0] == '?') { unset($_GET[$key]); $_GET[substr($key, 1)] = $val; } } $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL']; } elseif (!array_key_exists('REQUEST_URI', $_SERVER) && !array_key_exists('REQUEST_URI', $_ENV)) { $_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF']; $first = true; foreach ($_GET as $key => $val) { $_SERVER['REQUEST_URI'] .= $first ? '?' : '&'; $_SERVER['REQUEST_URI'] .= urlencode($key) . '=' . urlencode($val); $first = false; } } if (array_key_exists('SCRIPT_FILENAME', $_SERVER) && !array_key_exists('PHP_SELF', $_SERVER)) { $_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_FILENAME']; } elseif (array_key_exists('SCRIPT_NAME', $_SERVER) && defined('HIPHOP_PHP')) { $_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME']; } @header('Expires: Mon, 20 Dec 1998 01:00:00 GMT'); @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); @header('Cache-Control: no-cache, max-age=0'); @header('Pragma: no-cache'); // for proxies, and also IE if (is_file('closed.html') && get_param_integer('keep_force_open', 0) == 0) { if (strpos($_SERVER['PHP_SELF'], 'upgrader.php') === false && strpos($_SERVER['PHP_SELF'], 'execute_temp.php') === false && (!isset($SITE_INFO['no_extra_closed_file']) || $SITE_INFO['no_extra_closed_file'] == '0')) { if (@strpos($_SERVER['SERVER_SOFTWARE'], 'IIS') === false) { header('HTTP/1.0 503 Service Temporarily Unavailable'); } header('Location: ' . (is_file($RELATIVE_PATH . 'closed.html') ? 'closed.html' : '../closed.html')); exit; } } // Cover up holes in old PHP versions functionality if (!function_exists('str_word_count')) { /** * Isolate the words in the input string. * * @param string String to count words in * @param integer The format * @set 0 1 2 * @return mixed Typically a list - the words of the input string */ function str_word_count($input, $format = 0) { //count words $pattern = "/[^(\\w|\\d|\\'|\"|\\.|\\!|\\?|;|,|\\|\\/|\\-\\-|:|\\&|@)]+/"; $all_words = trim(preg_replace($pattern, ' ', $input)); $a = array(); $pos = 0; while (true) { $old_pos = $pos; $pos = strpos($all_words, ' ', $pos); if ($pos === false) { $a[$old_pos] = substr($all_words, $old_pos); break; } $a[$old_pos] = substr($all_words, $old_pos, $pos - $old_pos); } if ($format == 0) { return count($a); } return $a; } } if (!function_exists('html_entity_decode')) { /** * Decode the HTML entitity encoded input string. * * @param string The text to decode * @param integer The quote style code * @param ?string Character set to decode to (NULL: default) * @return string The decoded text */ function html_entity_decode($input, $quote_style, $charset = NULL) { unset($quote_style); unset($charset); /* // NB:   does not go to <space>. It's not something you use with html escaping, it's for hard-space-formatting. URL's don't contain spaces, but that's due to URL escaping (%20) $replace_array=array( '&'=>'&', '>'=>'>', '<'=>'<', '''=>'\'', '"'=>'"', ); foreach ($replace_array as $from=>$to) { $input=str_replace($from,$to,$input); } return $input;*/ $trans_tbl = get_html_translation_table(HTML_ENTITIES); $trans_tbl = array_flip($trans_tbl); return strtr($input, $trans_tbl); } } if (version_compare(phpversion(), '4.3.0') >= 0) { if (!function_exists('unichrm_hex')) { /** * Convert a unicode character number to a unicode string. Callback for preg_replace. * * @param array Regular expression match array. * @return ~string Converted data (false: could not convert). */ function unichrm_hex($matches) { return unichr(hexdec($matches[1])); } } if (!function_exists('unichrm')) { /** * Convert a unicode character number to a unicode string. Callback for preg_replace. * * @param array Regular expression match array. * @return ~string Converted data (false: could not convert). */ function unichrm($matches) { return unichr(intval($matches[1])); } } if (!function_exists('unichr')) { /** * Convert a unicode character number to a HTML-entity enabled string, using lower ASCII characters where possible. * * @param integer Character number. * @return ~string Converted data (false: could not convert). */ function unichr($c) { if ($c <= 0x7f) { return chr($c); } else { return '#&' . strval($c) . ';'; } } } } $BOOTSTRAPPING = 1; $CHECKING_SAFEMODE = false; $BAD_WORD_CHARS = array(chr(128), chr(130), chr(131), chr(132), chr(133), chr(134), chr(135), chr(136), chr(137), chr(138), chr(139), chr(140), chr(142), chr(145), chr(146), chr(147), chr(148), chr(149), chr(150), chr(151), chr(152), chr(153), chr(154), chr(155), chr(156), chr(158), chr(159)); $FIXED_WORD_CHARS = array('(EUR-)', ',', '{f.}', '"', '...', '-|-', '=|=', '^', '{%o}', '{~S}', '<', 'CE', '{~Z}', "'", "'", '"', '"', '-', '-', '--', '~', '(TM)', '{~s}', '>', 'ce', '{~z}', '{.Y.}'); // some of these are Comcode shortcuts. We can't use entities as we can't assume we're converting into Comcode. $FIXED_WORD_CHARS_HTML = array('€', '‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'Š', '‹', 'Œ', 'Ž', "‘", "’", '“', '”', '•', '–', '—', '˜', '™', 'š', '›', 'œ', 'ž', 'Ÿ'); $RUNNING_SCRIPT_CACHE = array(); $BROWSER_DECACHEING = NULL; $CHARSET = NULL; $TEMP_CHARSET = NULL; $CURRENTLY_HTTPS = NULL; $CACHE_FIND_SCRIPT = array(); error_reporting(E_ALL); @ini_set('html_errors', '1'); @ini_set('docref_root', 'http://www.php.net/manual/en/'); @ini_set('docref_ext', '.php'); $SERVER_TIMEZONE = function_exists('date_default_timezone_get') ? @date_default_timezone_get() : ini_get('date.timezone'); @ini_set('date.timezone', 'UTC'); if (function_exists('date_default_timezone_set')) { date_default_timezone_set('UTC'); } // Needed for HPHP $HAS_SET_ERROR_HANDLER = false; $DYING_BADLY = false; // If ocPortal is bailing out uncontrollably, setting this will make sure the error hander does not try and suppress $XSS_DETECT = function_exists('ocp_mark_as_escaped'); $GLOBALS['DEBUG_MODE'] = (!array_key_exists('debug_mode', $SITE_INFO) || $SITE_INFO['debug_mode'] == '1') && (is_dir(get_file_base() . '/.svn') || is_dir(get_file_base() . '/.git') || function_exists('ocp_mark_as_escaped')) && (!array_key_exists('keep_no_debug_mode', $_GET) || $_GET['keep_no_debug_mode'] == '0'); $GLOBALS['SEMI_DEBUG_MODE'] = (!array_key_exists('debug_mode', $SITE_INFO) || $SITE_INFO['debug_mode'] == '1') && (is_dir(get_file_base() . '/.svn') || is_dir(get_file_base() . '/.git') || function_exists('ocp_mark_as_escaped')); if (function_exists('set_time_limit')) { @set_time_limit(60); } if ($GLOBALS['DEBUG_MODE']) { if (function_exists('set_time_limit')) { @set_time_limit(10); } @ini_set('ocproducts.type_strictness', '1'); @ini_set('ocproducts.xss_detect', '1'); } if ($GLOBALS['DEBUG_MODE']) { require_code('developer_tools'); } $JAVASCRIPTS = array('javascript' => 1, 'javascript_thumbnails' => 1); if ($GLOBALS['CURRENT_SHARE_USER'] !== NULL || get_domain() == 'myocp.com') { $JAVASCRIPTS['javascript_ajax'] = 1; } $CSSS = array('no_cache' => 1, 'global' => 1); // Try and make the PHP environment as we need it if (function_exists('set_magic_quotes_runtime')) { @set_magic_quotes_runtime(0); } // @'d because it's deprecated and PHP 5.3 may give an error @ini_set('auto_detect_line_endings', '0'); @ini_set('include_path', ''); @ini_set('default_socket_timeout', '60'); @ini_set('allow_url_fopen', '0'); @ini_set('suhosin.executor.disable_emodifier', '1'); // Extra security if suhosin is available @ini_set('suhosin.executor.multiheader', '1'); // Extra security if suhosin is available @ini_set('suhosin.executor.disable_eval', '0'); @ini_set('suhosin.executor.eval.whitelist', ''); @ini_set('suhosin.executor.func.whitelist', ''); // Load most basic config $IN_MINIKERNEL_VERSION = 0; $EXITING = 0; if (array_key_exists('use_ocf', $_GET) && running_script('upgrader')) { $SITE_INFO['forum_type'] = 'ocf'; $SITE_INFO['ocf_table_prefix'] = $SITE_INFO['table_prefix']; } $CACHE_TEMPLATES = true; // The URL to our install (no trailing /) $BASE_URL_HTTP = NULL; $BASE_URL_HTTPS = NULL; $WORDS_TO_FILTER = NULL; $FIELD_RESTRICTIONS = NULL; $VALID_ENCODING = false; $CONVERTED_ENCODING = false; if (!isset($MICRO_BOOTUP)) { $MICRO_BOOTUP = 0; } if (!isset($MICRO_AJAX_BOOTUP)) { $MICRO_AJAX_BOOTUP = 0; } require_code_no_override('version'); if ($MICRO_BOOTUP == 0 && $MICRO_AJAX_BOOTUP == 0) { //@header('X-Powered-By: ocPortal '.ocp_version_full().' (PHP '.phpversion().')'); @header('X-Powered-By: ocPortal'); // Better to keep it vague, for security reasons $QUERY_LOG = false; if (isset($_REQUEST['special_page_type']) && $_REQUEST['special_page_type'] == 'query') { $QUERY_LOG = true; } } // Most critical things require_code('support'); // A lot of support code is present in this srand(make_seed()); mt_srand(make_seed()); if ($MICRO_BOOTUP == 0 && $MICRO_AJAX_BOOTUP == 0) { if (running_script('index') && count($_POST) == 0) { $bot_type = get_bot_type(); if ($bot_type !== NULL && isset($SITE_INFO['fast_spider_cache']) && $SITE_INFO['fast_spider_cache'] != '0') { fast_spider_cache(true); } } } require_code('caches'); // Recently taken out of 'support' so makes sense to load it here require_code('database'); // There's nothing without the database if ((!isset($SITE_INFO['known_suexec']) || $SITE_INFO['known_suexec'] == '0') && !is_writable_wrap(get_file_base() . '/.htaccess')) { require_code('support2'); if (ip_banned(get_ip_address())) { critical_error('BANNED'); } } if (running_script('messages') && get_param('action', 'new') == 'new' && get_param_integer('routine_refresh', 0) == 0) { require_code('chat_poller'); chat_poller(); } if ($MICRO_BOOTUP == 0) { load_user_stuff(); } // For any kind of niceness we need these. The order is chosen for complex dependency reasons - don't mess with it if ($MICRO_AJAX_BOOTUP == 0) { require_code('themes'); // Output needs to know about themes require_code('templates'); // So that we can do error templates require_code('tempcode'); // Output is done with tempcode if ($MICRO_BOOTUP == 0) { require_code('comcode'); // Much output goes through comcode } } require_code('zones'); // Zone is needed because zones are where all ocPortal pages reside require_code('config'); // Config is needed for much active stuff if (get_option('collapse_user_zones', true) === '1' && $RELATIVE_PATH == 'site') { get_base_url(); /*force calculation first*/ $RELATIVE_PATH = ''; } require_code('users'); // Users are important due to permissions if ($MICRO_BOOTUP == 0 && $MICRO_AJAX_BOOTUP == 0) { if (running_script('index') && count($_POST) == 0) { if (isset($SITE_INFO['any_guest_cached_too']) && $SITE_INFO['any_guest_cached_too'] == '1' && is_guest(NULL, true)) { fast_spider_cache(false); } } } $CACHE_TEMPLATES = (get_option('is_on_template_cache') == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache', 0) == 1) && get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache', NULL) !== 0; if ($MICRO_AJAX_BOOTUP == 0) { require_code('temporal'); // Date/time functions require_code('files'); // Contains fix_permissions, needed for 'lang' require_code('lang'); // So that we can do language stuff (e.g. errors) convert_data_encodings(); if ($MICRO_BOOTUP == 0) { require_code('permissions'); // So we can check access } } // At this point we can display errors nicely $GLOBALS['SUPPRESS_ERROR_DEATH'] = false; set_error_handler('ocportal_error_handler'); if (function_exists('error_get_last')) { register_shutdown_function('catch_fatal_errors'); } $HAS_SET_ERROR_HANDLER = true; if ($MICRO_BOOTUP == 0) { if (method_exists($GLOBALS['FORUM_DRIVER'], 'forum_layer_initialise')) { $GLOBALS['FORUM_DRIVER']->forum_layer_initialise(); } } if ($MICRO_AJAX_BOOTUP == 0) { $JAVASCRIPT = new ocp_tempcode(); } if ($MICRO_BOOTUP == 0) { if ($IN_MINIKERNEL_VERSION != 1 && $MICRO_AJAX_BOOTUP == 0) { has_cookies(); // Will determine at early point whether we have cookie support get_num_users_site(); // Will kill site if there are too many users } } require_code('urls'); // URL building is crucial @header('Content-type: text/html; charset=' . get_charset()); if ($MICRO_AJAX_BOOTUP == 0 && $MICRO_BOOTUP == 0) { // Before anything gets outputted handle_logins(); require_code('site'); // This powers the site (top level page generation) // Are we installed? get_option('site_name'); } // Our logging (change false to true for temporarily changing it so staff get logging) if (get_option('log_php_errors') == '1') { @ini_set('log_errors', '1'); if (addon_installed('errorlog')) { @ini_set('error_log', get_custom_file_base() . '/data_custom/errorlog.php'); } } if ($MICRO_BOOTUP == 0 && $MICRO_AJAX_BOOTUP == 0 && (get_option('display_php_errors') == '1' || running_script('upgrader') || has_specific_permission(get_member(), 'see_php_errors'))) { @ini_set('display_errors', '1'); } elseif (!$GLOBALS['DEBUG_MODE']) { @ini_set('display_errors', '0'); } // G-zip? @ini_set('zlib.output_compression', get_option('gzip_output') == '1' ? 'On' : 'Off'); if (function_exists('setlocale') && $MICRO_AJAX_BOOTUP == 0) { $locales = explode(',', do_lang('locale')); setlocale(LC_ALL, $locales[0]); @setlocale(LC_ALL, $locales); unset($locales); } if ($MICRO_AJAX_BOOTUP == 0 && $MICRO_BOOTUP == 0 && (!isset($SITE_INFO['no_installer_checks']) || $SITE_INFO['no_installer_checks'] == '0')) { if (is_file(get_file_base() . '/install.php') && !is_file(get_file_base() . '/install_ok') && running_script('index')) { warn_exit(do_lang_tempcode('MUST_DELETE_INSTALLER')); } } if ($MICRO_AJAX_BOOTUP == 0 && $MICRO_BOOTUP == 0) { $changed_base_url = !array_key_exists('base_url', $SITE_INFO) && get_long_value('last_base_url') !== get_base_url(false); if (running_script('index') && (is_browser_decacheing() || $changed_base_url)) { require_code('view_modes'); erase_tempcode_cache(); erase_cached_templates(!$changed_base_url); erase_comcode_cache(); erase_cached_language(); persistant_cache_empty(); if ($changed_base_url) { require_lang('zones'); require_code('zones3'); erase_comcode_page_cache(); set_long_value('last_base_url', get_base_url(false)); } } if (has_zone_access(get_member(), 'adminzone')) { $JAVASCRIPTS['javascript_staff'] = 1; $JAVASCRIPTS['javascript_ajax'] = 1; if (addon_installed('occle')) { $JAVASCRIPTS['javascript_button_occle'] = 1; } } if (addon_installed('realtime_rain') && get_option('bottom_show_realtime_rain_button', true) === '1') { $JAVASCRIPTS['javascript_button_realtime_rain'] = 1; } } /*ocp_memory_profile('startup'); $func=get_defined_functions(); print_r($func['user']);*/ if (tacit_https() || is_page_https(get_zone_name(), get_page_name())) { @header('Cache-Control: private'); @header('Pragma: private'); } $BOOTSTRAPPING = 0; if ($GLOBALS['SEMI_DEBUG_MODE'] && $MICRO_AJAX_BOOTUP == 0) { if ($GLOBALS['SEMI_DEBUG_MODE']) { /*if ((mt_rand(0,2)==1) && ($GLOBALS['DEBUG_MODE']) && (running_script('index'))) We know this works now, so let's stop messing up our development speed { require_code('view_modes'); erase_cached_templates(true); // Stop anything trying to read a template cache item (E.g. CSS, JS) that might not exist! }*/ if (strpos(ocp_srv('HTTP_REFERER'), ocp_srv('HTTP_HOST')) !== false && strpos(ocp_srv('HTTP_REFERER'), 'keep_devtest') !== false && !running_script('attachment') && !running_script('upgrader') && strpos(ocp_srv('HTTP_REFERER'), 'login') === false && is_null(get_param('keep_devtest', NULL))) { $_GET['keep_devtest'] = '1'; fatal_exit('URL not constructed properly: development mode in use but keep_devtest was not specified. This indicates that links have been made without build_url (in PHP) or keep_stub (in Javascript). Whilst not fatal this time, failure to use these functions can cause problems when your site goes live. See the ocPortal codebook for more details.'); } else { $_GET['keep_devtest'] = '1'; } } if (browser_matches('true_xhtml') && get_value('html5') !== '1' && get_value('html5') !== '_true' && get_param_integer('keep_no_xhtml', 0) == 0 && !running_script('upgrader')) { @header('Content-type: application/xhtml+xml; charset=' . get_charset()); } if (isset($_CREATED_FILES)) { /** * Run after-tests for debug mode, to make sure coding standards are met. */ function debug_mode_aftertests() { global $_CREATED_FILES, $_MODIFIED_FILES; // Use the info from ocProduct's custom PHP version to make sure that all files that were created/modified got synched as they should have been. foreach ($_CREATED_FILES as $file) { if (substr($file, 0, strlen(get_file_base())) == get_file_base() && substr($file, -4) != '.log' && basename($file) != 'permissioncheckslog.php') { @exit(escape_html('File not permission-synched: ' . $file)); } } foreach ($_MODIFIED_FILES as $file) { if (strpos($file, '_cache') === false && substr($file, 0, strlen(get_file_base())) == get_file_base() && substr($file, -4) != '.log' && basename($file) != 'permissioncheckslog.php') { @exit(escape_html('File not change-synched: ' . $file)); } } global $TITLE_CALLED, $SCREEN_TEMPLATE_CALLED, $EXITING; if (is_null($SCREEN_TEMPLATE_CALLED) && $EXITING == 0 && strpos(ocp_srv('PHP_SELF'), 'index.php') !== false) { @exit(escape_html('No screen template called.')); } if (!$TITLE_CALLED && (is_null($SCREEN_TEMPLATE_CALLED) || $SCREEN_TEMPLATE_CALLED != '') && $EXITING == 0 && strpos(ocp_srv('PHP_SELF'), 'index.php') !== false) { @exit(escape_html('No title used on screen.')); } } register_shutdown_function('debug_mode_aftertests'); } if (ocp_srv('SCRIPT_FILENAME') != '' && $GLOBALS['DEBUG_MODE'] && strpos(ocp_srv('SCRIPT_FILENAME'), 'data_custom') === false) { if (@strlen(file_get_contents(ocp_srv('SCRIPT_FILENAME'), FILE_TEXT)) > 4500) { fatal_exit('Entry scripts (front controllers) should not be shoved full of code.'); } } } // FirePHP console support, only for administrators if ((get_param_integer('keep_firephp', 0) == 1 || get_param_integer('keep_queries', 0) == 1) && ($GLOBALS['FORUM_DRIVER']->is_super_admin(get_member()) || $GLOBALS['IS_ACTUALLY_ADMIN'])) { require_code('firephp'); } $default_memory_limit = get_value('memory_limit'); if (is_null($default_memory_limit) || $default_memory_limit == '' || $default_memory_limit == '0' || $default_memory_limit == '-1') { $default_memory_limit = '64M'; } @ini_set('memory_limit', $default_memory_limit); if (isset($GLOBALS['FORUM_DRIVER']) && $GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())) { if (get_param_integer('keep_avoid_memory_limit', 0) == 1) { disable_php_memory_limit(); } $memory_test = get_param_integer('keep_memory_limit_test', 0); if ($memory_test != 0 && $memory_test <= 32) { @ini_set('memory_limit', strval($memory_test) . 'M'); } } if (get_option('sitewide_im', true) === '1' && running_script('index') && get_param('type', 'misc', true) != 'room') { require_code('chat'); enter_chat_lobby(); } // Startup hooks if (!running_script('upgrader')) { $startup_hooks = find_all_hooks('systems', 'startup'); foreach (array_keys($startup_hooks) as $hook) { require_code('hooks/systems/startup/' . filter_naughty_harsh($hook)); $ob = object_factory('Hook_startup_' . filter_naughty_harsh($hook), true); if ($ob === NULL) { continue; } $ob->run($MICRO_BOOTUP, $MICRO_AJAX_BOOTUP, 0); } if ($CURRENT_SHARE_USER !== NULL && float_to_raw_string(ocp_version_number()) != get_value('version')) { require_code('upgrade'); clear_caches_2(); version_specific(); upgrade_modules(); ocf_upgrade(); } } }
/** * Get an ordered array of all the entries in the specified catalogue. * * @param ?AUTO_LINK The ID of the category for which the entries are being collected (NULL: entries are [and must be] passed instead) * @param ID_TEXT The name of the catalogue * @param ?array A database row of the catalogue we are working with (NULL: read it in) * @param ID_TEXT The view type we're doing * @set PAGE SEARCH CATEGORY * @param ID_TEXT The template set we are rendering this category using * @param ?integer The maximum number of entries to show on a single page of this this category (NULL: all) * @param ?integer The entry number to start at (NULL: all) * @param ?mixed The entries to show, may be from other categories. Can either be SQL fragment, or array (NULL: use $start and $max) * @param ?AUTO_LINK The virtual root for display of this category (NULL: default) * @param ?SHORT_INTEGER The display type to use (NULL: lookup from $catalogue) * @param boolean Whether to perform sorting * @param ?array A list of entry rows (NULL: select them normally) * @param string Search filter (blank: no filter) * @param ?ID_TEXT Orderer (NULL: read from environment) * @return array An array containing our built up entries (renderable tempcode), our sorting interface, and our entries (entry records from database, with an additional 'map' field), and the max rows */ function get_catalogue_category_entry_buildup($category_id, $catalogue_name, $catalogue, $view_type, $tpl_set, $max, $start, $select, $root, $display_type = NULL, $do_sorting = true, $entries = NULL, $search = '', $_order_by = NULL) { if (addon_installed('ecommerce')) { require_code('ecommerce'); } $is_ecomm = is_ecommerce_catalogue($catalogue_name); if (is_null($catalogue)) { $_catalogues = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $catalogue_name), '', 1); $catalogue = $_catalogues[0]; } $or_list = mixed(); if (is_null($entries) && !is_null($select)) { if (is_array($select) && count($select) == 0 || is_string($select) && $select == '') { $entries = array(); } else { if (!is_array($select)) { $or_list = $select; } else { $or_list = ''; foreach ($select as $s) { if ($or_list != '') { $or_list .= ' OR '; } $or_list .= 'e.id=' . strval($s); } } } } if (is_null($display_type)) { $display_type = get_param_integer('keep_cat_display_type', $catalogue['c_display_type']); } // Find order field global $CAT_FIELDS_CACHE; if (isset($CAT_FIELDS_CACHE[$catalogue_name])) { $fields = $CAT_FIELDS_CACHE[$catalogue_name]; } else { $fields = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $catalogue_name), 'ORDER BY cf_order'); } $CAT_FIELDS_CACHE[$catalogue_name] = $fields; if ($do_sorting) { global $NON_CANONICAL_PARAMS; $NON_CANONICAL_PARAMS[] = 'order'; if (is_null($_order_by)) { $_order_by = get_param('order', ''); } if ($_order_by == '' || strpos($_order_by, ' ') === false) { $order_by = '0'; $direction = 'ASC'; foreach ($fields as $i => $field) { if ($field['cf_defines_order'] != 0) { $order_by = strval($i); $direction = $field['cf_defines_order'] == 1 ? 'ASC' : 'DESC'; $_order_by = strval($field['id']) . ' ' . $direction; break; } } } else { list($order_by, $direction) = explode(' ', $_order_by); if ($direction != 'ASC' && $direction != 'DESC') { log_hack_attack_and_exit('ORDERBY_HACK'); } if ($order_by != 'rating' && $order_by != 'add_date') { $found = false; foreach ($fields as $i => $field) { if ($order_by == strval($field['id'])) { $order_by = strval($i); $found = true; break; } } if (!$found) { $order_by = '0'; } // Could not find } } } else { $order_by = mixed(); $direction = 'ASC'; } // Get entries in this category $map = '1=1'; if (!is_null($category_id)) { $map .= ' AND cc_id=' . strval($category_id); } if (!has_specific_permission(get_member(), 'see_unvalidated')) { $map .= ' AND ce_validated=1'; } if (!is_null($or_list)) { $map .= ' AND (' . $or_list . ')'; } $in_db_sorting = !is_null($order_by) && $do_sorting; require_code('fields'); if (is_null($entries)) { if ($in_db_sorting) { $num_entries = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map); if ($order_by == 'add_date') { $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.* FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map . ' ORDER BY ce_add_date ' . $direction, $max, $start); } elseif ($order_by == 'rating') { $select_rating = '(SELECT AVG(rating) FROM ' . get_table_prefix() . 'rating WHERE ' . db_string_equal_to('rating_for_type', 'catalogues') . ' AND rating_for_id=e.id) AS compound_rating'; $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.*,' . $select_rating . ' FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map . ' ORDER BY compound_rating ' . $direction, $max, $start); } else { $ob = get_fields_hook($fields[intval($order_by)]['cf_type']); list(, , $table) = $ob->get_field_value_row_bits($fields[$order_by]); if (strpos($table, '_trans') !== false) { $join = get_table_prefix() . 'catalogue_entries e LEFT JOIN ' . get_table_prefix() . 'catalogue_efv_' . $table . ' f ON f.ce_id=e.id AND f.cf_id=' . strval($fields[$order_by]['id']) . ' LEFT JOIN ' . get_table_prefix() . 'translate t ON f.cv_value=t.id'; $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.* FROM ' . $join . ' WHERE ' . $map . ' ' . ($num_entries > 300 ? '' : 'ORDER BY t.text_original ' . $direction), $max, $start); } else { $join = get_table_prefix() . 'catalogue_entries e LEFT JOIN ' . get_table_prefix() . 'catalogue_efv_' . $table . ' f ON f.ce_id=e.id AND f.cf_id=' . strval($fields[$order_by]['id']); $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.* FROM ' . $join . ' WHERE ' . $map . ' ORDER BY f.cv_value ' . $direction, $max, $start); } } $start = 0; // To stop it skipping itself } else { if ((is_null($order_by) || !$do_sorting) && !is_null($max)) { $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.* FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map, $max, $start); $num_entries = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map); $start = 0; // To stop it skipping itself } else { $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.* FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map); $num_entries = count($entries); } } } else { $num_entries = count($entries); } if ($num_entries > 300 && !$in_db_sorting) { $in_db_sorting = true; } // Needed to stop huge slow down foreach ($entries as $i => $entry) { $entries[$i]['map'] = get_catalogue_entry_map($entry, $catalogue, $view_type, $tpl_set, $root, $fields, $display_type == 1 && !$is_ecomm && !is_null($order_by) ? array(0, intval($order_by)) : NULL, false, false, intval($order_by)); } // Implement search filter if ($search != '') { $new_entries = array(); for ($i = 0; $i < $num_entries; $i++) { $two_d_list = $entries[$i]['map']['FIELDS_2D']; $all_output = ''; foreach ($two_d_list as $index => $l) { $all_output .= (is_object($l['VALUE']) ? $l['VALUE']->evaluate() : $l['VALUE']) . ' '; } if (strpos(strtolower($all_output), strtolower($search)) !== false) { $new_entries[] = $entries[$i]; } } $entries = $new_entries; } disable_php_memory_limit(); if ($do_sorting) { // Sort entries $selectors = new ocp_tempcode(); foreach ($fields as $i => $field) { if ($field['cf_searchable'] == 1) { $potential_sorter_name = get_translated_text($field['cf_name']); foreach (array('ASC' => '_ASCENDING', 'DESC' => '_DESCENDING') as $dir_code => $dir_lang) { $sort_sel = $order_by == strval($i) && $direction == $dir_code; $_potential_sorter_name = new ocp_tempcode(); $_potential_sorter_name->attach(escape_html($potential_sorter_name)); $_potential_sorter_name->attach(do_lang_tempcode($dir_lang)); $selectors->attach(do_template('RESULTS_BROWSER_SORTER', array('_GUID' => 'dfdsfdsusd0fsd0dsf', 'SELECTED' => $sort_sel, 'NAME' => protect_from_escaping($_potential_sorter_name), 'VALUE' => strval($field['id']) . ' ' . $dir_code))); } } } $extra_sorts = array(); $extra_sorts['add_date'] = '_ADDED'; if (get_option('is_on_rating') == '0') { $has_ratings = false; } else { if (is_null($entries)) { $has_ratings = false; foreach ($entries as $entry) { if ($entry['allow_rating'] == 1) { $has_ratings = true; } } if ($has_ratings) { $extra_sorts['rating'] = 'RATING'; } } else { $has_ratings = true; } } foreach ($extra_sorts as $extra_sort_code => $extra_sort_lang) { foreach (array('ASC' => '_ASCENDING', 'DESC' => '_DESCENDING') as $dir_code => $dir_lang) { $sort_sel = $order_by == $extra_sort_code && $direction == $dir_code; $_potential_sorter_name = new ocp_tempcode(); $_potential_sorter_name->attach(do_lang_tempcode($extra_sort_lang)); $_potential_sorter_name->attach(do_lang_tempcode($dir_lang)); $selectors->attach(do_template('RESULTS_BROWSER_SORTER', array('_GUID' => 'xfdsfdsusd0fsd0dsf', 'SELECTED' => $sort_sel, 'NAME' => protect_from_escaping($_potential_sorter_name), 'VALUE' => $extra_sort_code . ' ' . $dir_code))); } } $sort_url = get_self_url(false, false, array('order' => NULL), false, true); $sorting = do_template('RESULTS_BROWSER_SORT', array('_GUID' => '9fgjfdklgjdfgkjlfdjgd90', 'SORT' => 'order', 'RAND' => uniqid(''), 'URL' => $sort_url, 'SELECTORS' => $selectors)); if (!$in_db_sorting) { for ($i = 0; $i < $num_entries; $i++) { if (!array_key_exists($i, $entries)) { continue; } for ($j = $i + 1; $j < $num_entries; $j++) { if (!array_key_exists($j, $entries)) { continue; } $a = @$entries[$j]['map']['FIELD_' . $order_by]; if (array_key_exists('FIELD_' . $order_by . '_PLAIN', @$entries[$j]['map'])) { $a = @$entries[$j]['map']['FIELD_' . $order_by . '_PLAIN']; } $b = @$entries[$i]['map']['FIELD_' . $order_by]; if (array_key_exists('FIELD_' . $order_by . '_PLAIN', @$entries[$i]['map'])) { $b = @$entries[$i]['map']['FIELD_' . $order_by . '_PLAIN']; } if (is_object($a)) { $a = $a->evaluate(); } if (is_object($b)) { $b = $b->evaluate(); } if ($fields[$order_by]['cf_type'] == 'date') { $bits = explode(' ', $a, 2); $date_bits = explode(strpos($bits[0], '-') !== false ? '-' : '/', $bits[0], 3); if (!array_key_exists(1, $date_bits)) { $date_bits[1] = date('m'); } if (!array_key_exists(2, $date_bits)) { $date_bits[2] = date('Y'); } $time_bits = explode(':', $bits[1], 3); if (!array_key_exists(1, $time_bits)) { $time_bits[1] = '00'; } if (!array_key_exists(2, $time_bits)) { $time_bits[2] = '00'; } $time_a = mktime(intval($time_bits[0]), intval($time_bits[1]), intval($time_bits[2]), intval($date_bits[1]), intval($date_bits[2]), intval($date_bits[0])); $bits = explode(' ', $b, 2); $date_bits = explode(strpos($bits[0], '-') !== false ? '-' : '/', $bits[0], 3); if (!array_key_exists(1, $date_bits)) { $date_bits[1] = date('m'); } if (!array_key_exists(2, $date_bits)) { $date_bits[2] = date('Y'); } $time_bits = explode(':', $bits[1], 3); if (!array_key_exists(1, $time_bits)) { $time_bits[1] = '00'; } if (!array_key_exists(2, $time_bits)) { $time_bits[2] = '00'; } $time_b = mktime(intval($time_bits[0]), intval($time_bits[1]), intval($time_bits[2]), intval($date_bits[1]), intval($date_bits[2]), intval($date_bits[0])); $r = $time_a < $time_b ? -1 : ($time_a == $time_b ? 0 : 1); } else { $r = strnatcmp(strtolower($a), strtolower($b)); } if ($r < 0 && $direction == 'ASC' || $r > 0 && $direction == 'DESC') { $temp = $entries[$i]; $entries[$i] = $entries[$j]; $entries[$j] = $temp; } } } } } else { $sorting = new ocp_tempcode(); } // Build up entries $entry_buildup = new ocp_tempcode(); $extra_map = array(); if ($is_ecomm) { require_lang('shopping'); $i = 0; for ($i = 0; $i < $num_entries; $i++) { if (!array_key_exists($i, $entries)) { break; } $entry = $entries[$i]; $extra_map[$i]['ADD_TO_CART'] = build_url(array('page' => 'shopping', 'type' => 'add_item', 'product_id' => $entry['id'], 'hook' => 'catalogue_items'), get_module_zone('shopping')); } } if ($display_type == 2) { for ($i = 0; $i < $num_entries; $i++) { if (!array_key_exists($i, $entries)) { break; } $entry = $entries[$i]; if (is_null($start) || $in_db_sorting || $i >= $start && $i < $start + $max) { $tab_entry_map = $entry['map'] + (array_key_exists($i, $extra_map) ? $extra_map[$i] : array()); if (get_option('is_on_comments') == '1' && $entry['allow_comments'] >= 1 || get_option('is_on_rating') == '1' && $entry['allow_rating'] == 1 || get_option('is_on_trackbacks') == '1' && $entry['allow_trackbacks'] == 1) { $tab_entry_map['VIEW_URL'] = build_url(array('page' => 'catalogues', 'type' => 'entry', 'id' => $entry['id'], 'root' => $root == -1 ? NULL : $root), get_module_zone('catalogues')); } else { $tab_entry_map['VIEW_URL'] = ''; } $entry_buildup->attach(static_evaluate_tempcode(do_template('CATALOGUE_' . $tpl_set . '_TAB_ENTRY', $tab_entry_map, NULL, false, 'CATALOGUE_DEFAULT_TAB_ENTRY'))); } if (!is_null($start) && $i >= $start + $max) { break; } } if (!$entry_buildup->is_empty()) { $head = new ocp_tempcode(); $field_count = 0; foreach ($fields as $i => $field) { if (($field['cf_put_in_category'] == 1 && $view_type == 'CATEGORY' || $field['cf_put_in_search'] == 1 && $view_type == 'SEARCH') && $field['cf_visible'] == 1) { if ($field['cf_searchable'] == 1) { $sort_url_asc = get_self_url(false, false, array('order' => strval($field['id']) . ' ASC'), true); $sort_url_desc = get_self_url(false, false, array('order' => strval($field['id']) . ' DESC'), true); $sort_asc_selected = $order_by == strval($field['id']) && $direction == 'ASC'; $sort_desc_selected = $order_by == strval($field['id']) && $direction == 'DESC'; } else { $sort_url_asc = ''; $sort_url_desc = ''; $sort_asc_selected = false; $sort_desc_selected = false; } $head->attach(do_template('CATALOGUE_' . $tpl_set . '_TAB_FIELD_HEAD', array('SORT_ASC_SELECTED' => $sort_asc_selected, 'SORT_DESC_SELECTED' => $sort_desc_selected, 'SORT_URL_ASC' => $sort_url_asc, 'SORT_URL_DESC' => $sort_url_desc, 'CATALOGUE' => $catalogue_name, 'FIELDID' => strval($i), '_FIELDID' => strval($field['id']), 'FIELD' => get_translated_text($field['cf_name']), 'FIELDTYPE' => $field['cf_type']), NULL, false, 'CATALOGUE_DEFAULT_TAB_FIELD_HEAD')); $field_count++; } } $entry_buildup = do_template('CATALOGUE_' . $tpl_set . '_TAB_WRAP', array('CATALOGUE' => $catalogue_name, 'HEAD' => $head, 'CONTENT' => $entry_buildup, 'FIELD_COUNT' => strval($field_count)), NULL, false, 'CATALOGUE_DEFAULT_TAB_WRAP'); } } elseif ($display_type == 0) { for ($i = 0; $i < $num_entries; $i++) { if (!array_key_exists($i, $entries)) { break; } $entry = $entries[$i]; if (is_null($max) || $in_db_sorting || (is_null($start) || $i >= $start && $i < $start + $max)) { $entry_buildup->attach(do_template('CATALOGUE_' . $tpl_set . '_ENTRY_EMBED', $entry['map'] + (array_key_exists($i, $extra_map) ? $extra_map[$i] : array()), NULL, false, 'CATALOGUE_DEFAULT_ENTRY_EMBED')); } } } else { for ($i = 0; $i < $num_entries; $i++) { if (!array_key_exists($i, $entries)) { break; } $entry = $entries[$i]; if (is_null($start) || $in_db_sorting || $i >= $start && $i < $start + $max) { $entry_buildup->attach(do_template('CATALOGUE_' . $tpl_set . '_LINE', $entry['map'] + (array_key_exists($i, $extra_map) ? $extra_map[$i] : array()), NULL, false, 'CATALOGUE_DEFAULT_LINE')); } } if (!$entry_buildup->is_empty()) { $entry_buildup = do_template('CATALOGUE_' . $tpl_set . '_LINE_WRAP', $entry['map'] + array('CATALOGUE' => $catalogue_name, 'CONTENT' => $entry_buildup), NULL, false, 'CATALOGUE_DEFAULT_LINE_WRAP'); } } return array($entry_buildup, $sorting, $entries, $num_entries); }
/** * The UI to confirm which subscribers to prune. * * @return tempcode The UI */ function bounce_filter_c() { $title = get_page_title('BOUNCE_FILTER'); disable_php_memory_limit(); // In case of a huge number $username = post_param('username'); $password = post_param('password'); $server = post_param('server'); $port = post_param_integer('port'); $box = post_param('box'); $mbox = @imap_open($box, $username, $password); if ($mbox === false) { warn_exit(do_lang_tempcode('IMAP_ERROR', imap_last_error())); } $fields = ''; //new ocp_tempcode(); require_code('form_templates'); $all_subscribers = array(); $all_subscribers += collapse_2d_complexity('email', 'id', $GLOBALS['SITE_DB']->query_select('newsletter', array('email', 'id'))); if (get_forum_type() == 'ocf') { $all_subscribers += collapse_2d_complexity('m_email_address', 'id', $GLOBALS['FORUM_DB']->query_select('f_members', array('m_email_address', 'id'), array('m_allow_emails_from_staff' => 1))); } $headers = imap_search($mbox, 'UNDELETED'); if ($headers === false) { $headers = array(); } $num = 0; foreach ($headers as $val) { $msg = imap_body($mbox, $val); $matches = array(); $num_matches = preg_match_all("#<([^\n<>@]+@[^\n<>@]+)>#", $msg, $matches); if ($num_matches != 0) { $overview = imap_headerinfo($mbox, $val); $body = imap_body($mbox, $val); $checked = strpos($body, 'X-Failed-Recipients') !== false || strpos($body, '5.1.1') !== false || strpos($body, '5.1.6') !== false || strpos($body, '5.7.1') !== false; for ($i = 0; $i < $num_matches; $i++) { $m = $matches[1][$i]; $m = str_replace('@localhost.localdomain', '', $m); if ($m != get_option('staff_address') && array_key_exists($m, $all_subscribers)) { $tick = form_input_tick($m, $overview->subject . '.', 'email_' . strval($num), $checked, NULL, $m); $fields .= $tick->evaluate(); // HTMLHTML //$fields->attach($tick); $num++; unset($all_subscribers[$m]); // So as to make the list no longer than needed; each subscriber only considered once } } } } imap_close($mbox); if ($num == 0) { warn_exit(do_lang_tempcode('NO_ENTRIES')); } $submit_name = do_lang_tempcode('PROCEED'); $post_url = get_self_url(); $post_url = build_url(array('page' => '_SELF', 'type' => 'bounce_filter_d'), '_SELF'); return do_template('FORM_SCREEN', array('SKIP_VALIDATION' => true, 'HIDDEN' => build_keep_post_fields(), 'TITLE' => $title, 'TEXT' => do_lang_tempcode('BOUNCE_WHICH'), 'FIELDS' => $fields, 'SUBMIT_NAME' => $submit_name, 'URL' => $post_url)); }
/** * The actualiser to import news * * @return tempcode The UI */ function _import_news() { check_specific_permission('mass_import'); $title = get_page_title('IMPORT_NEWS'); require_code('rss'); require_code('news'); require_code('files'); $GLOBALS['LAX_COMCODE'] = true; disable_php_memory_limit(); $rss_url = post_param('rss_feed_url', NULL); require_code('uploads'); if (is_swf_upload(true) && array_key_exists('file_novalidate', $_FILES) || array_key_exists('file_novalidate', $_FILES) && is_uploaded_file($_FILES['file_novalidate']['tmp_name'])) { $rss_url = $_FILES['file_novalidate']['tmp_name']; } if (is_null($rss_url)) { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } $is_validated = post_param_integer('auto_validate', 0); $download_images = post_param_integer('download_images', 0); $rss = new rss($rss_url, true); if (!is_null($rss->error)) { warn_exit($rss->error); } $submitter = get_member(); $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); $extra_post_data = array(); foreach ($rss->gleamed_items as $i => $item) { if (!array_key_exists('category', $item)) { $item['category'] = do_lang('NC_general'); } $extra_post_data[] = $item; $cats_to_process = array($item['category']); if (array_key_exists('extra_categories', $item)) { $cats_to_process = array_merge($cats_to_process, $item['extra_categories']); } $cat_id = mixed(); $extra_categories = array(); foreach ($cats_to_process as $j => $cat) { $_cat_id = mixed(); foreach ($NEWS_CATS as $_cat => $news_cat) { if (get_translated_text($news_cat['nc_title']) == $cat) { $_cat_id = $_cat; } } if (is_null($_cat_id)) { $_cat_id = add_news_category($cat, 'newscats/general', '', NULL); // Need to reload now $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); } if ($j == 0) { $cat_id = $_cat_id; } else { $extra_categories[] = $_cat_id; } } $rep_image = ''; if (array_key_exists('rep_image', $item)) { $rep_image = $item['rep_image']; if ($download_images == 1) { $stem = 'uploads/grepimages/' . basename(urldecode($rep_image)); $target_path = get_custom_file_base() . '/' . $stem; $rep_image = 'uploads/grepimages/' . basename($rep_image); while (file_exists($target_path)) { $uniqid = uniqid(''); $stem = 'uploads/grepimages/' . $uniqid . '_' . basename(urldecode($rep_image)); $target_path = get_custom_file_base() . '/' . $stem; $rep_image = 'uploads/grepimages/' . $uniqid . '_' . basename($rep_image); } $target_handle = fopen($target_path, 'wb') or intelligent_write_error($target_path); $result = http_download_file($item['rep_image'], NULL, false, false, 'ocPortal', NULL, NULL, NULL, NULL, NULL, $target_handle); fclose($target_handle); } } // Add news $ts = array_key_exists('clean_add_date', $item) ? $item['clean_add_date'] : (array_key_exists('add_date', $item) ? strtotime($item['add_date']) : time()); if ($ts === false) { $ts = time(); } // Seen in error email, it's if the add date won't parse by PHP $edit_date = array_key_exists('clean_edit_date', $item) ? $item['clean_edit_date'] : (array_key_exists('edit_date', $item) ? strtotime($item['edit_date']) : NULL); if ($edit_date === false) { $edit_date = NULL; } $news = array_key_exists('news', $item) ? html_to_comcode($item['news']) : ''; $news_article = array_key_exists('news_article', $item) ? html_to_comcode($item['news_article']) : ''; $news_id = add_news($item['title'], $news, array_key_exists('author', $item) ? $item['author'] : $GLOBALS['FORUM_DRIVER']->get_username(get_member()), $is_validated, 1, 1, 1, '', $news_article, $cat_id, $extra_categories, $ts, $submitter, 0, $edit_date, NULL, $rep_image); $rss->gleamed_items[$i]['import_id'] = $news_id; $rss->gleamed_items[$i]['import__news'] = $news; $rss->gleamed_items[$i]['import__news_article'] = $news_article; } foreach ($rss->gleamed_items as $i => $item) { $news = $item['import__news']; $news_article = $item['import__news_article']; $this->_grab_images_and_fix_links($download_images == 1, $news, $rss->gleamed_items); $this->_grab_images_and_fix_links($download_images == 1, $news_article, $rss->gleamed_items); lang_remap_comcode($GLOBALS['SITE_DB']->query_value('news', 'news', array('id' => $item['import_id'])), $news); lang_remap_comcode($GLOBALS['SITE_DB']->query_value('news', 'news_article', array('id' => $item['import_id'])), $news_article); } breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MANAGE_NEWS')), array('_SELF:_SELF:import', do_lang_tempcode('IMPORT_NEWS')))); breadcrumb_set_self(do_lang_tempcode('DONE')); if (url_is_local($rss_url)) { // Means it is a temp file @unlink($rss_url); } return inform_screen($title, do_lang_tempcode('IMPORT_NEWS_DONE')); }
/** * The actualiser of a search. * * @param ID_TEXT Codename for what's being searched (blank: mixed search) * @param string Author name * @param ?AUTO_LINK Author ID (NULL: none given) * @param integer Days to search * @param ID_TEXT Sort key * @param ID_TEXT Sort direction * @set ASC DESC * @param boolean Whether to only search titles * @param string Comma-separated list of categories to search under * @return array A triple: The results, results browser, the number of results */ function results($id, $author, $author_id, $days, $sort, $direction, $only_titles, $search_under) { $title = get_page_title('RESULTS'); cache_module_installed_status(); $cutoff = $days == -1 ? NULL : time() - $days * 24 * 60 * 60; // What we're searching for $content = get_param('content', false, true); // Search keyword highlighting in any loaded Comcode global $SEARCH__CONTENT_BITS; $_content_bits = explode(' ', str_replace('"', '', preg_replace('#(^|\\s)\\+#', '', preg_replace('#(^|\\s)\\-#', '', $content)))); $SEARCH__CONTENT_BITS = array(); require_code('textfiles'); $too_common_words = explode(chr(10), read_text_file('too_common_words', '', true)); foreach ($_content_bits as $content_bit) { $content_bit = trim($content_bit); if ($content_bit == '') { continue; } if (!in_array(strtolower($content_bit), $too_common_words)) { $SEARCH__CONTENT_BITS[] = $content_bit; } } $start = get_param_integer('start', 0); $default_max = 10; if (ini_get('memory_limit') != '-1' && ini_get('memory_limit') != '0') { if (intval(preg_replace('#M$#', '', ini_get('memory_limit'))) < 20) { $default_max = 5; } } $max = get_param_integer('max', $default_max); // Also see get_search_rows $save_title = get_param('save_title', ''); if (!is_guest() && $save_title != '' && $start == 0) { static $saved_search = false; if (!$saved_search) { $GLOBALS['SITE_DB']->query_insert('searches_saved', array('s_title' => $save_title, 's_member_id' => get_member(), 's_time' => time(), 's_primary' => $content, 's_auxillary' => serialize(array_merge($_POST, $_GET)))); $saved_search = true; } } $boolean_operator = get_param('conjunctive_operator', 'OR'); $boolean_search = $this->_is_boolean_search(); $content_where = build_content_where($content, $boolean_search, $boolean_operator); disable_php_memory_limit(); // Search under all hooks we've asked to search under $results = array(); $_hooks = find_all_hooks('modules', 'search'); foreach (array_keys($_hooks) as $hook) { require_code('hooks/modules/search/' . filter_naughty_harsh($hook)); $object = object_factory('Hook_search_' . filter_naughty_harsh($hook), true); if (is_null($object)) { continue; } $info = $object->info(); if (is_null($info)) { continue; } $test = get_param_integer('search_' . $hook, 0); if (($test == 1 || get_param_integer('all_defaults', 0) == 1 && $info['default'] || $id == $hook) && ($id == '' || $id == $hook)) { // Category filter if ($search_under != '!' && $search_under != '-1' && array_key_exists('category', $info)) { $cats = explode(',', $search_under); $where_clause = '('; foreach ($cats as $cat) { if (trim($cat) == '') { continue; } if ($where_clause != '(') { $where_clause .= ' OR '; } if ($info['integer_category']) { $where_clause .= (strpos($info['category'], '.') !== false ? '' : 'r.') . $info['category'] . '=' . strval((int) $cat); } else { $where_clause .= db_string_equal_to((strpos($info['category'], '.') !== false ? '' : 'r.') . $info['category'], $cat); } } $where_clause .= ')'; } else { $where_clause = ''; } $only_search_meta = get_param_integer('only_search_meta', 0) == 1; $direction = get_param('direction', 'ASC'); if (function_exists('set_time_limit')) { @set_time_limit(5); } // Prevent errant search hooks (easily written!) taking down a server. Each call given 5 seconds (calling set_time_limit resets the timer). $hook_results = $object->run($content, $only_search_meta, $direction, $max, $start, $only_titles, $content_where, $author, $author_id, $cutoff, $sort, $max, $boolean_operator, $where_clause, $search_under, $boolean_search ? 1 : 0); if (is_null($hook_results)) { continue; } foreach ($hook_results as $i => $result) { $result['object'] = $object; $hook_results[$i] = $result; } $results = sort_search_results($hook_results, $results, $direction); } } if (function_exists('set_time_limit')) { @set_time_limit(15); } global $EXTRA_HEAD; $EXTRA_HEAD->attach('<meta name="robots" content="noindex,nofollow" />'); // XHTMLXHTML // Now glue our templates together $out = build_search_results_interface($results, $start, $max, $direction, $id == ''); if ($out->is_empty()) { if ($days != -1 && $GLOBALS['TOTAL_RESULTS'] == 0) { $ret_maybe = $this->results($id, $author, $author_id, -1, $sort, $direction, $only_titles, $search_under); if (!$ret_maybe[0]->is_empty()) { attach_message(do_lang_tempcode('NO_RESULTS_DAYS', escape_html(integer_format($days))), 'notice'); return $ret_maybe; } } return array(new ocp_tempcode(), new ocp_tempcode(), 0); } require_code('templates_results_browser'); $results_browser = results_browser(do_lang_tempcode('RESULTS'), NULL, $start, 'start', $max, 'max', $GLOBALS['TOTAL_RESULTS'], NULL, 'results', true, true); if ($start == 0) { $GLOBALS['SITE_DB']->query_insert('searches_logged', array('s_member_id' => get_member(), 's_time' => time(), 's_primary' => substr($content, 0, 255), 's_auxillary' => serialize(array_merge($_POST, $_GET)), 's_num_results' => count($results))); } return array($out, $results_browser, $GLOBALS['TOTAL_RESULTS']); }
/** * Actually send out the newsletter in the background. */ function newsletter_shutdown_function() { global $NEWSLETTER_SUBJECT, $NEWSLETTER_MESSAGE, $NEWSLETTER_HTML_ONLY, $NEWSLETTER_FROM_EMAIL, $NEWSLETTER_FROM_NAME, $NEWSLETTER_PRIORITY, $NEWSLETTER_SEND_DETAILS, $NEWSLETTER_LANGUAGE, $CSV_DATA, $NEWSLETTER_MAIL_TEMPLATE; //mail_wrap($NEWSLETTER_SUBJECT,$NEWSLETTER_MESSAGE,$NEWSLETTER_ADDRESSES,$NEWSLETTER_USERNAMES,$NEWSLETTER_FROM_EMAIL,$NEWSLETTER_FROM_NAME,3,NULL,true,NULL,true,$NEWSLETTER_HTML_ONLY==1); Not so easy any more as message needs tailoring per subscriber disable_php_memory_limit(); // As PHP can leak memory, or caches can fill, even if we do this carefully $last_cron = get_value('last_cron'); $start = 0; do { list($addresses, $hashes, $usernames, $forenames, $surnames, $ids, ) = newsletter_who_send_to($NEWSLETTER_SEND_DETAILS, $NEWSLETTER_LANGUAGE, $start, 100, false, $CSV_DATA); // Send to all foreach ($addresses as $i => $email_address) { // Variable substitution in body $newsletter_message_substituted = newsletter_variable_substitution($NEWSLETTER_MESSAGE, $NEWSLETTER_SUBJECT, $forenames[$i], $surnames[$i], $usernames[$i], $email_address, $ids[$i], $hashes[$i]); $in_html = false; if (strpos($newsletter_message_substituted, '<html') === false) { if ($NEWSLETTER_HTML_ONLY == 1) { $_m = comcode_to_tempcode($newsletter_message_substituted, get_member(), true); $newsletter_message_substituted = $_m->evaluate($NEWSLETTER_LANGUAGE); $in_html = true; } } else { require_code('tempcode_compiler'); $_m = template_to_tempcode($newsletter_message_substituted); $newsletter_message_substituted = $_m->evaluate($NEWSLETTER_LANGUAGE); $in_html = true; } if (!is_null($last_cron)) { $GLOBALS['SITE_DB']->query_insert('newsletter_drip_send', array('d_inject_time' => time(), 'd_subject' => $NEWSLETTER_SUBJECT, 'd_message' => $newsletter_message_substituted, 'd_html_only' => $NEWSLETTER_HTML_ONLY, 'd_to_email' => $email_address, 'd_to_name' => $usernames[$i], 'd_from_email' => $NEWSLETTER_FROM_EMAIL, 'd_from_name' => $NEWSLETTER_FROM_NAME, 'd_priority' => $NEWSLETTER_PRIORITY, 'd_template' => $NEWSLETTER_MAIL_TEMPLATE)); } else { mail_wrap($NEWSLETTER_SUBJECT, $newsletter_message_substituted, array($email_address), array($usernames[$i]), $NEWSLETTER_FROM_EMAIL, $NEWSLETTER_FROM_NAME, $NEWSLETTER_PRIORITY, NULL, true, NULL, true, $in_html, false, $NEWSLETTER_MAIL_TEMPLATE); } } $start += 100; } while (array_key_exists(0, $addresses)); }
/** * The UI to show a member's profile. * * @return tempcode The UI */ function profile() { breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MEMBERS')))); disable_php_memory_limit(); $username = get_param('id', strval(get_member())); if ($username == '') { $username = strval(get_member()); } if (is_numeric($username)) { $member_id = get_param_integer('id', get_member()); if (is_guest($member_id)) { access_denied('NOT_AS_GUEST'); } $username = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id, 'm_username'); if (is_null($username) || is_guest($member_id)) { warn_exit(do_lang_tempcode('USER_NO_EXIST')); } } else { $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username($username); if (is_null($member_id)) { warn_exit(do_lang_tempcode('_USER_NO_EXIST', escape_html($username))); } } require_code('ocf_profiles'); return render_profile_tabset($member_id, get_member(), $username); }
/** * Get the processed tempcode for the specified block. Please note that you pass multiple parameters in as an array, but single parameters go in as a string or other flat variable. * * @param ID_TEXT The block name * @param ?array The block parameter map (NULL: no parameters) * @param ?integer The TTL to use in minutes (NULL: block default) * @return tempcode The generated tempcode */ function do_block($codename, $map = NULL, $ttl = NULL) { global $LANGS_REQUESTED, $JAVASCRIPTS, $CSSS, $DO_NOT_CACHE_THIS; if (is_null($map)) { $map = array(); } if (!array_key_exists('cache', $map)) { $map['cache'] = block_cache_default($codename); } $DO_NOT_CACHE_THIS = $map['cache'] == '0'; $object = NULL; if ((get_option('is_on_block_cache') == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache', 0) == 1 || get_param_integer('cache_blocks', 0) == 1) && (get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache_blocks', NULL) !== 0 && get_param_integer('cache', NULL) !== 0) && strpos(get_param('special_page_type', ''), 't') === false) { // See if the block may be cached (else cannot, or is yet unknown) if ($map['cache'] == '0') { $row = NULL; } else { $row = find_cache_on($codename); if ($row === NULL) { $object = do_block_hunt_file($codename, $map); if (is_object($object) && method_exists($object, 'cacheing_environment')) { $info = $object->cacheing_environment($map); if ($info !== NULL) { $row = array('cached_for' => $codename, 'cache_on' => $info['cache_on'], 'cache_ttl' => $info['ttl']); } } } if ($row === NULL && isset($map['quick_cache']) && $map['quick_cache'] == '1') { $row = array('cached_for' => $codename, 'cache_on' => 'array($map,$GLOBALS[\'FORUM_DRIVER\']->get_members_groups(get_member()))', 'cache_ttl' => 60); } } if ($row !== NULL) { $cache_identifier = do_block_get_cache_identifier($row['cache_on'], $map); // See if it actually is cached if ($cache_identifier !== NULL) { if ($ttl === NULL) { $ttl = $row['cache_ttl']; } $cache = get_cache_entry($codename, $cache_identifier, $ttl, true, array_key_exists('cache', $map) && $map['cache'] == '2', $map); if ($cache === NULL) { $nql_backup = $GLOBALS['NO_QUERY_LIMIT']; $GLOBALS['NO_QUERY_LIMIT'] = true; if ($object !== NULL) { $object = do_block_hunt_file($codename, $map); } if (!is_object($object)) { // This probably happened as we uninstalled a block, and now we're getting a "missing block" message back. if (!defined('HIPHOP_PHP')) { // Removed outdated cache-on information $GLOBALS['SITE_DB']->query_delete('cache_on', array('cached_for' => $codename), '', 1); persistant_cache_delete('CACHE_ON'); } $out = new ocp_tempcode(); $out->attach($object); return $out; } $backup_langs_requested = $LANGS_REQUESTED; $backup_javascripts = $JAVASCRIPTS; $backup_csss = $CSSS; $LANGS_REQUESTED = array(); $JAVASCRIPTS = array('javascript' => 1, 'javascript_thumbnails' => 1); $CSSS = array('no_cache' => 1, 'global' => 1); if (isset($map['quick_cache']) && $map['quick_cache'] == '1') { global $MEMORY_OVER_SPEED; $MEMORY_OVER_SPEED = true; // Let this eat up some CPU in order to let it save RAM, disable_php_memory_limit(); if (function_exists('set_time_limit')) { @set_time_limit(200); } } $cache = $object->run($map); $cache->handle_symbol_preprocessing(); if (!$DO_NOT_CACHE_THIS) { require_code('caches2'); if (isset($map['quick_cache']) && $map['quick_cache'] == '1' && has_cookies()) { $cache = make_string_tempcode(preg_replace('#((\\?)|(&(amp;)?))keep\\_[^="]*=[^&"]*#', '\\2', $cache->evaluate())); } put_into_cache($codename, $ttl, $cache_identifier, $cache, array_keys($LANGS_REQUESTED), array_keys($JAVASCRIPTS), array_keys($CSSS), true); } elseif ($ttl != -1 && $cache->is_empty()) { $LANGS_REQUESTED += $backup_langs_requested; $JAVASCRIPTS += $backup_javascripts; $CSSS += $backup_csss; return do_block($codename, $map, -1); } $LANGS_REQUESTED += $backup_langs_requested; $JAVASCRIPTS += $backup_javascripts; $CSSS += $backup_csss; $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup; } return $cache; } } } // NB: If we've got this far cache="2" is ignored. But later on (for normal expiries, different contexts, etc) cache_on will be known so not an issue. // We will need to load the actual file if (is_null($object)) { $object = do_block_hunt_file($codename, $map); } if (is_object($object)) { $nql_backup = $GLOBALS['NO_QUERY_LIMIT']; $GLOBALS['NO_QUERY_LIMIT'] = true; $backup_langs_requested = $LANGS_REQUESTED; $backup_javascripts = $JAVASCRIPTS; $backup_csss = $CSSS; $LANGS_REQUESTED = array(); $JAVASCRIPTS = array('javascript' => 1, 'javascript_thumbnails' => 1); $CSSS = array('no_cache' => 1, 'global' => 1); $cache = $object->run($map); $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup; } else { $out = new ocp_tempcode(); $out->attach($object); return $out; } // May it be added to cache_on? if (!$DO_NOT_CACHE_THIS && method_exists($object, 'cacheing_environment') && (get_option('is_on_block_cache') == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache_blocks', 0) == 1 || get_param_integer('cache', 0) == 1) && (get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache_blocks', NULL) !== 0 && get_param_integer('cache', NULL) !== 0)) { $info = $object->cacheing_environment($map); if ($info !== NULL) { $cache_identifier = do_block_get_cache_identifier($info['cache_on'], $map); if ($cache_identifier !== NULL) { require_code('caches2'); put_into_cache($codename, $info['ttl'], $cache_identifier, $cache, array_keys($LANGS_REQUESTED), array_keys($JAVASCRIPTS), array_keys($CSSS), true); if (!defined('HIPHOP_PHP') && !is_array($info['cache_on'])) { $GLOBALS['SITE_DB']->query_insert('cache_on', array('cached_for' => $codename, 'cache_on' => $info['cache_on'], 'cache_ttl' => $info['ttl']), false, true); // Allow errors in case of race conditions } } } } $LANGS_REQUESTED += $backup_langs_requested; $JAVASCRIPTS += $backup_javascripts; $CSSS += $backup_csss; return $cache; }
/** * Delete a zone. * * @param ID_TEXT The name of the zone */ function actual_delete_zone($zone) { if (get_file_base() != get_custom_file_base()) { warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT')); } require_code('abstract_file_manager'); force_have_afm_details(); if (function_exists('set_time_limit')) { @set_time_limit(0); } disable_php_memory_limit(); $pages = find_all_pages_wrap($zone, false, false, FIND_ALL_PAGES__ALL); $bad = array(); foreach (array_keys($pages) as $page) { if (substr($page, 0, 6) != 'panel_' && $page != 'start') { $bad[] = $page; } } if ($bad != array()) { require_lang('zones'); warn_exit(do_lang_tempcode('DELETE_ZONE_ERROR', '<kbd>' . implode('</kbd>, <kbd>', $bad) . '</kbd>')); } actual_delete_zone_lite($zone); if (file_exists(get_custom_file_base() . '/' . filter_naughty($zone))) { afm_delete_directory(filter_naughty($zone), true); } }
/** * Standard modular run function. * * @return tempcode The result of execution. */ function run() { if (get_file_base() != get_custom_file_base()) { warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT')); } require_lang('addons'); require_code('addons'); require_code('menus2'); disable_php_memory_limit(); // Choice of what to export, or tricky import // Decide what we're doing $type = get_param('type', 'misc'); if ($type == 'misc') { return $this->gui(); } if ($type == 'addon_export') { return $this->addon_export(); } if ($type == '_addon_export') { return $this->_addon_export(); } if ($type == '__addon_export') { return $this->__addon_export(); } if ($type == 'addon_import') { return $this->addon_import(); } if ($type == '_addon_import') { return $this->_addon_import(); } if ($type == 'addon_install') { return $this->addon_install(); } if ($type == '_addon_install') { return $this->_addon_install(); } if ($type == 'addon_uninstall') { return $this->addon_uninstall(); } if ($type == '_addon_uninstall') { return $this->_addon_uninstall(); } if ($type == 'multi_action') { return $this->multi_action(); } if ($type == '_multi_action') { return $this->_multi_action(); } if ($type == 'reinstall') { return $this->reinstall_module(); } if ($type == 'uninstall') { return $this->uninstall_module(); } if ($type == 'upgrade') { return $this->upgrade_module(); } if ($type == 'modules') { return $this->modules_interface(); } if ($type == 'view') { return $this->modules_view(); } return new ocp_tempcode(); }
<?php /* ocPortal Copyright (c) ocProducts, 2004-2012 See text/EN/licence.txt for full licencing information. NOTE TO PROGRAMMERS: Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder **** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes **** */ disable_php_memory_limit(); $GLOBALS['NO_DB_SCOPE_CHECK'] = true; $filename = 'ocportal-' . get_site_name() . '.' . date('Y-m-d') . '.sql'; if (!isset($_GET['testing'])) { header('Content-Type: application/octet-stream' . '; authoritative=true;'); if (strstr(ocp_srv('HTTP_USER_AGENT'), 'MSIE') !== false) { header('Content-Disposition: filename="' . str_replace(chr(13), '', str_replace(chr(10), '', addslashes($filename))) . '"'); } else { header('Content-Disposition: attachment; filename="' . str_replace(chr(13), '', str_replace(chr(10), '', addslashes($filename))) . '"'); } } else { header('Content-type: text/plain'); } require_code('xml_dump'); $st = get_sql_dump(); foreach ($st as $s) { echo $s; echo "\n\n"; } $GLOBALS['SCREEN_TEMPLATE_CALLED'] = ''; exit;
/** * Upgrade shared installs. */ function upgrade_sharedinstall_sites() { global $CURRENT_SHARE_USER, $SITE_INFO, $TABLE_LANG_FIELDS; // Find sites $sites = array(); foreach (array_keys($SITE_INFO) as $key) { $matches = array(); if (preg_match('#^custom_user_(.*)#', $key, $matches) != 0) { $sites[] = $matches[1]; } } disable_php_memory_limit(); foreach ($sites as $i => $site) { if (function_exists('set_time_limit')) { @set_time_limit(0); } // Change active site $CURRENT_SHARE_USER = $site; $TABLE_LANG_FIELDS = array(); _general_db_init(); // Reset DB $GLOBALS['SITE_DB'] = new database_driver(get_db_site(), get_db_site_host(), get_db_site_user(), get_db_site_password(), get_table_prefix()); $GLOBALS['FORUM_DB'] = $GLOBALS['SITE_DB']; // NB: File path will be ok // NB: Other internal caching could need changing in the future, but works at time of writing // Go! automate_upgrade(); echo 'Upgraded ' . htmlentities($site) . '<br />'; flush(); } }
/** * Resize an image to the specified size, but retain the aspect ratio. * * @param URLPATH The URL to the image to resize * @param PATH The file path (including filename) to where the resized image will be saved * @param integer The maximum width we want our new image to be (-1 means "don't factor this in") * @param integer The maximum height we want our new image to be (-1 means "don't factor this in") * @param integer This is only considered if both $width and $height are -1. If set, it will fit the image to a box of this dimension (suited for resizing both landscape and portraits fairly) * @param boolean Whether to exit ocPortal if an error occurs * @param ?string The file extension to save with (NULL: same as our input file) * @param boolean Whether $from was in fact a path, not a URL * @param boolean Whether to apply a 'never make the image bigger' rule for thumbnail creation (would affect very small images) * @param ?array This optional parameter allows us to specify cropping or padding for the image. See comments in the function. (NULL: no details passed) * @return boolean Success */ function convert_image($from, $to, $width, $height, $box_width = -1, $exit_on_error = true, $ext2 = NULL, $using_path = false, $only_make_smaller = false, $thumb_options = NULL) { disable_php_memory_limit(); // Load $ext = get_file_extension($from); if ($using_path) { if (!check_memory_limit_for($from, $exit_on_error)) { return false; } $from_file = @file_get_contents($from); } else { $file_path_stub = convert_url_to_path($from); if (!is_null($file_path_stub)) { if (!check_memory_limit_for($file_path_stub, $exit_on_error)) { return false; } $from_file = @file_get_contents($file_path_stub); } else { $from_file = http_download_file($from, 1024 * 1024 * 20, false); if (is_null($from_file)) { $from_file = false; } } } if ($from_file === false) { if ($exit_on_error) { warn_exit(do_lang_tempcode('UPLOAD_PERMISSION_ERROR', escape_html($from))); } require_code('site'); if (!file_exists(get_custom_file_base() . '/uploads/missing_ok')) { attach_message(do_lang_tempcode('UPLOAD_PERMISSION_ERROR', escape_html($from)), 'warn'); } return false; } $source = @imagecreatefromstring($from_file); if (!is_null($thumb_options) || !$only_make_smaller) { unset($from_file); } if ($source === false) { if ($exit_on_error) { warn_exit(do_lang_tempcode('CORRUPT_FILE', escape_html($from))); } require_code('site'); attach_message(do_lang_tempcode('CORRUPT_FILE', escape_html($from)), 'warn'); return false; } // Derive actual width x height, for the given maximum box (maintain aspect ratio) // =============================================================================== $sx = imagesx($source); $sy = imagesy($source); $red = NULL; if (is_null($thumb_options)) { if ($width == 0) { $width = 1; } if ($height == 0) { $height = 1; } // If we're not sure if this is gonna stretch to fit a width or stretch to fit a height if ($width == -1 && $height == -1) { if ($sx > $sy) { $width = $box_width; } else { $height = $box_width; } } if ($width != -1 && $height != -1) { if (floatval($sx) / floatval($width) > floatval($sy) / floatval($height)) { $_width = $width; $_height = intval($sy * ($width / $sx)); } else { $_height = $height; $_width = intval($sx * ($height / $sy)); } } elseif ($height == -1) { $_width = $width; $_height = intval($width / ($sx / $sy)); } elseif ($width == -1) { $_height = $height; $_width = intval($height / ($sy / $sx)); } if ($_width > $sx && $only_make_smaller) { $_width = $sx; $_height = $sy; // We can just escape, nothing to do imagedestroy($source); if ($using_path && $from == $to) { return true; } if ($using_path) { copy($from, $to); } else { $_to = @fopen($to, 'wb') or intelligent_write_error($to); fwrite($_to, $from_file); fclose($_to); } fix_permissions($to); sync_file($to); return true; } if ($_width < 1) { $_width = 1; } if ($_height < 1) { $_height = 1; } // Pad out options for imagecopyresized // $dst_im,$src_im,$dst_x,$dst_y,$src_x,$src_y,$dst_w,$dst_h,$src_w,$src_h $dest_x = 0; $dest_y = 0; $source_x = 0; $source_y = 0; } else { // Thumbnail-specific (for the moment) behaviour. We require the ability // to crop (ie. window-off a section of the image), and pad (ie. provide a // background around the image). We keep this separate to the above code // because that already works well across various aspects of the site. // // Format of the array is 'type'=>'crop' or 'type'=>'pad'; 'where'=>'end', // 'where'=>'start' or 'where'=>'both'. For padding, there is an optional // 'background'=>'RRGGBBAA' or 'background'=>'RRGGBB' for colored padding // with or without transparency. // Grab the dimensions we would get if we didn't crop or scale $wrong_x = intval(round(floatval($sx) / $thumb_options['scale'])); $wrong_y = intval(round(floatval($sy) / $thumb_options['scale'])); // Handle cropping here if ($thumb_options['type'] == 'crop' || $thumb_options['type'] == 'pad_horiz_crop_horiz' && $wrong_x > $width || $thumb_options['type'] == 'pad_vert_crop_vert' && $wrong_y > $height) { // See which direction we're cropping in if (intval(round(floatval($sx) / $thumb_options['scale'])) != $width) { $crop_direction = 'x'; } else { $crop_direction = 'y'; } // We definitely have to crop, since symbols.php only tells us to crop // if it has to. Thus we know we're going to fill the output image, the // only question is with what part of the source image? // Get the amount we'll lose from the source if ($crop_direction == 'x') { $crop_off = intval($sx - $width * $thumb_options['scale']); } elseif ($crop_direction == 'y') { $crop_off = intval($sy - $height * $thumb_options['scale']); } // Now we see how much to chop off the start (we don't care about the // end, as this will be handled by using an appropriate window size) $displacement = 0; if ($thumb_options['where'] == 'start' || $thumb_options['where'] == 'start_if_vertical' && $crop_direction == 'y' || $thumb_options['where'] == 'start_if_horizontal' && $crop_direction == 'x') { $displacement = 0; } elseif ($thumb_options['where'] == 'end' || $thumb_options['where'] == 'end_if_vertical' && $crop_direction == 'y' || $thumb_options['where'] == 'end_if_horizontal' && $crop_direction == 'x') { $displacement = intval(floatval($crop_off)); } else { $displacement = intval(floatval($crop_off) / 2.0); } // Now we convert this to the right x and y start locations for the // window $source_x = $crop_direction == 'x' ? $displacement : 0; $source_y = $crop_direction == 'y' ? $displacement : 0; // Now we set the width and height of our window, which will be scaled // versions of the width and height of the output $sx = intval($width * $thumb_options['scale']); $sy = intval($height * $thumb_options['scale']); // We start at the origin of our output $dest_x = 0; $dest_y = 0; // and it is always the full size it can be (or else we'd be cropping // too much) $_width = $width; $_height = $height; } elseif ($thumb_options['type'] == 'pad' || $thumb_options['type'] == 'pad_horiz_crop_horiz' && $wrong_x < $width || $thumb_options['type'] == 'pad_vert_crop_vert' && $wrong_y < $height) { // Padding code lives here. We definitely need to pad some excess space // because otherwise symbols.php would not call us. Thus we need a // background (can be transparent). Let's see if we've been given one. if (array_key_exists('background', $thumb_options) && !is_null($thumb_options['background'])) { if (substr($thumb_options['background'], 0, 1) == '#') { $thumb_options['background'] = substr($thumb_options['background'], 1); } // We've been given a background, let's find out what it is if (strlen($thumb_options['background']) == 8) { // We've got an alpha channel $using_alpha = true; $red_str = substr($thumb_options['background'], 0, 2); $green_str = substr($thumb_options['background'], 2, 2); $blue_str = substr($thumb_options['background'], 4, 2); $alpha_str = substr($thumb_options['background'], 6, 2); } else { // We've not got an alpha channel $using_alpha = false; $red_str = substr($thumb_options['background'], 0, 2); $green_str = substr($thumb_options['background'], 2, 2); $blue_str = substr($thumb_options['background'], 4, 2); } $red = intval($red_str, 16); $green = intval($green_str, 16); $blue = intval($blue_str, 16); if ($using_alpha) { $alpha = intval($alpha_str, 16); } } else { // We've not got a background, so let's find a representative color // for the image by resampling the whole thing to 1 pixel. $temp_img = imagecreatetruecolor(1, 1); // Make an image to map on to imagecopyresampled($temp_img, $source, 0, 0, 0, 0, 1, 1, $sx, $sy); // Map the source image on to the 1x1 image $rgb_index = imagecolorat($temp_img, 0, 0); // Grab the color index of the single pixel $rgb_array = imagecolorsforindex($temp_img, $rgb_index); // Get the channels for it $red = $rgb_array['red']; // Grab the red $green = $rgb_array['green']; // Grab the green $blue = $rgb_array['blue']; // Grab the blue // Sort out if we're using alpha $using_alpha = false; if (array_key_exists('alpha', $rgb_array)) { $using_alpha = true; } if ($using_alpha) { $alpha = 255 - ($rgb_array['alpha'] * 2 + 1); } // Destroy the temporary image imagedestroy($temp_img); } // Now we need to work out how much padding we're giving, and where // The axis if (intval(round(floatval($sx) / $thumb_options['scale'])) != $width) { $pad_axis = 'x'; } else { $pad_axis = 'y'; } // The amount if ($pad_axis == 'x') { $padding = intval(round(floatval($width) - floatval($sx) / $thumb_options['scale'])); } else { $padding = intval(round(floatval($height) - floatval($sy) / $thumb_options['scale'])); } // The distribution if ($thumb_options['where'] == 'start' || $thumb_options['where'] == 'start_if_vertical' && $pad_axis == 'y' || $thumb_options['where'] == 'start_if_horizontal' && $pad_axis == 'x') { $pad_amount = 0; } else { $pad_amount = intval(floatval($padding) / 2.0); } // Now set all of the parameters needed for blitting our image // $sx and $sy are fine, since they cover the whole image $source_x = 0; $source_y = 0; $_width = $pad_axis == 'x' ? intval(round(floatval($sx) / $thumb_options['scale'])) : $width; $_height = $pad_axis == 'y' ? intval(round(floatval($sy) / $thumb_options['scale'])) : $height; $dest_x = $pad_axis == 'x' ? $pad_amount : 0; $dest_y = $pad_axis == 'y' ? $pad_amount : 0; } } // Resample/copy $gd_version = get_gd_version(); if ($gd_version >= 2.0) { // Set the background if we have one if (!is_null($thumb_options) && !is_null($red)) { $dest = imagecreatetruecolor($width, $height); imagealphablending($dest, false); if (function_exists('imagecolorallocatealpha') && $using_alpha) { $back_col = imagecolorallocatealpha($dest, $red, $green, $blue, 127 - intval(floatval($alpha) / 2.0)); } else { $back_col = imagecolorallocate($dest, $red, $green, $blue); } imagefilledrectangle($dest, 0, 0, $width, $height, $back_col); if (function_exists('imagesavealpha')) { imagesavealpha($dest, true); } } else { $dest = imagecreatetruecolor($_width, $_height); imagealphablending($dest, false); if (function_exists('imagesavealpha')) { imagesavealpha($dest, true); } } imagecopyresampled($dest, $source, $dest_x, $dest_y, $source_x, $source_y, $_width, $_height, $sx, $sy); } else { // Set the background if we have one if (!is_null($thumb_options) && !is_null($red)) { $dest = imagecreate($width, $height); $back_col = imagecolorallocate($dest, $red, $green, $blue); imagefill($dest, 0, 0, $back_col); } else { $dest = imagecreate($_width, $_height); } imagecopyresized($dest, $source, $dest_x, $dest_y, $source_x, $source_y, $_width, $_height, $sx, $sy); } // Clean up imagedestroy($source); // Save if (is_null($ext2)) { $ext2 = get_file_extension($to); } // If we've got transparency then we have to save as PNG if (!is_null($thumb_options) && isset($red) && $using_alpha) { $ext2 = 'png'; } if (function_exists('imagepng') && $ext2 == 'png') { if (strtolower(substr($to, -4)) != '.png') { $to = $to . '.png'; } $test = @imagepng($dest, $to); if (!$test) { if ($exit_on_error) { warn_exit(do_lang_tempcode('ERROR_IMAGE_SAVE', @strval($php_errormsg))); } require_code('site'); attach_message(do_lang_tempcode('ERROR_IMAGE_SAVE', @strval($php_errormsg)), 'warn'); return false; } } elseif (function_exists('imagejpeg') && ($ext2 == 'jpg' || $ext2 == 'jpeg')) { $jpeg_quality = get_value('jpeg_quality'); if ($jpeg_quality !== NULL) { $test = @imagejpeg($dest, $to, intval($jpeg_quality)); } else { $test = @imagejpeg($dest, $to); } if (!$test) { if ($exit_on_error) { warn_exit(do_lang_tempcode('ERROR_IMAGE_SAVE', @strval($php_errormsg))); } require_code('site'); attach_message(do_lang_tempcode('ERROR_IMAGE_SAVE', @strval($php_errormsg)), 'warn'); return false; } } elseif (function_exists('imagegif') && $ext2 == 'gif') { $test = @imagegif($dest, $to); if (!$test) { if ($exit_on_error) { warn_exit(do_lang_tempcode('ERROR_IMAGE_SAVE', @strval($php_errormsg))); } require_code('site'); attach_message(do_lang_tempcode('ERROR_IMAGE_SAVE', @strval($php_errormsg)), 'warn'); return false; } } else { if ($exit_on_error) { warn_exit(do_lang_tempcode('UNKNOWN_FORMAT', escape_html($ext2))); } require_code('site'); attach_message(do_lang_tempcode('UNKNOWN_FORMAT', escape_html($ext2)), 'warn'); return false; } // Clean up imagedestroy($dest); fix_permissions($to); sync_file($to); return true; }
/** * Standard import function. * * @param object The DB connection to import from * @param string The table prefix the target prefix is using * @param PATH The base directory we are importing from */ function import_pages($db, $table_prefix, $file_base) { unset($db); unset($table_prefix); require_code('files2'); $files = @get_directory_contents($file_base); $theme = either_param('theme'); $convert_to_comcode = either_param_integer('convert_to_comcode', 0); $fix_html = either_param_integer('fix_html', 0); $base_url = either_param('base_url'); if (substr($base_url, -1) == '/') { $base_url = substr($base_url, 0, strlen($base_url) - 1); } // Find all htm/html/php files $content_files = array(); foreach ($files as $i => $file) { if (substr(strtolower($file), -4) == '.htm' || substr(strtolower($file), -5) == '.html' || substr(strtolower($file), -4) == '.php') { $content_files[] = $file; unset($files[$i]); } } if (count($content_files) == 0) { warn_exit(do_lang_tempcode('NO_PAGES_FOUND')); } // Discern new zones needed // Note: files in directories in a deep path will be considered in a zone name changed so underscores replace slashes $new_zones = array(); $current_zones = find_all_zones(); foreach ($content_files as $file) { $zone = str_replace('/', '_', dirname($file)); if ($zone == '.') { $zone = ''; } if (!in_array($zone, $current_zones)) { $new_zones[] = $zone; } } $new_zones = array_unique($new_zones); // (Maybe AFM needed here - if zones have to be created, and possibly .htaccess changed to incorporate zone names in the redirects) if (count($new_zones) != 0) { require_code('abstract_file_manager'); force_have_afm_details(); $change_htaccess = get_option('htm_short_urls') == '1'; $htaccess_path = get_file_base() . '/.htaccess'; if ($change_htaccess && file_exists($htaccess_path) && is_writable_wrap($htaccess_path)) { $htaccess = file_get_contents($htaccess_path); $htaccess = preg_replace('#\\(site\\|forum\\|adminzone\\|cms\\|collaboration[^\\)]*#', '${0}|' . implode('|', $new_zones), $htaccess); $myfile = fopen($htaccess_path, 'wt'); fwrite($myfile, $htaccess); fclose($myfile); fix_permissions($htaccess_path); sync_file($htaccess_path); } // Create new zones as needed (and set them to our chosen theme too) require_code('zones2'); foreach ($new_zones as $zone) { actual_add_zone($zone, ucwords(str_replace('_', ' ', $zone)), 'start', '', $theme, 0, 0); } } // Discern cruft in htm/html via looking for best levenshtein to length ratio over a few pages; scan by tag, not by byte $compare_file_contents = array(); shuffle($content_files); for ($i = 0; $i < min(2, count($content_files)); $i++) { $file_contents = file_get_contents($file_base . '/' . $content_files[$i]); $compare_file_contents[$content_files[$i]] = $this->_html_filter($file_contents, $fix_html, $base_url, $files, $file_base); } $cruft = array(); if (count($compare_file_contents) > 1) { $to_find = array(); if (file_exists($file_base . '/header.txt')) { $cruft['HEADER'] = $this->_html_filter(file_get_contents($file_base . '/header.txt'), $fix_html, $base_url, $files, $file_base); } else { $to_find[] = 'HEADER'; } if (file_exists($file_base . '/footer.txt')) { $cruft['FOOTER'] = $this->_html_filter(file_get_contents($file_base . '/footer.txt'), $fix_html, $base_url, $files, $file_base); } else { $to_find[] = 'FOOTER'; } foreach ($to_find as $template_wanted) { $best_ratios = array(); foreach ($compare_file_contents as $i => $reference_file) { if ($template_wanted == 'HEADER') { $last_pos = strpos($reference_file, '<body'); if ($last_pos === false) { $last_pos = 0; } else { $last_pos += 5; } } else { $last_pos = strlen($reference_file) - 1; } $best_av_ratios = mixed(); $ratios = array(); while ($last_pos !== false) { //@print('!'.(strlen($reference_file)-$last_pos).' '.$lv.' '.$ratio.'<br />'.chr(10));flush();if (@$dd++==180) @exit('fini'); // Useful for debugging if ($template_wanted == 'HEADER') { $next_pos = strpos($reference_file, '<', $last_pos); } else { $next_pos = strrpos(substr($reference_file, 0, $last_pos), '<'); } if ($next_pos !== false) { if ($template_wanted == 'HEADER') { $up_to = substr($reference_file, 0, $next_pos); } else { $up_to = substr($reference_file, $next_pos); } $all_ratios_for_pos = array(); foreach ($compare_file_contents as $j => $other_file) { if ($i != $j) { if ($template_wanted == 'HEADER') { $up_to_other_file = substr($other_file, 0, $next_pos); } else { $up_to_other_file = substr($other_file, $next_pos - (strlen($reference_file) - strlen($other_file))); } $lv = fake_levenshtein($up_to, $up_to_other_file); if ($template_wanted == 'HEADER') { $ratio = floatval($lv) * 3 - floatval($next_pos + 1); // We want this number to be as small as possible. We have multiplied the levenshtein distance because we care about that more than length (this number reached by experimentation); HTML has a low entropy which this number is fighting against. } else { $ratio = floatval($lv) * 3 - floatval(strlen($reference_file) - $next_pos); // We want this number to be as small as possible. We have multiplied the levenshtein distance because we care about that more than length (this number reached by experimentation); HTML has a low entropy which this number is fighting against. } $all_ratios_for_pos[] = $ratio; } } $av_ratios = array_sum($all_ratios_for_pos) / floatval(count($all_ratios_for_pos)); if (is_null($best_av_ratios) || $av_ratios < $best_av_ratios) { $best_av_ratios = $av_ratios; } elseif ($av_ratios > $best_av_ratios + 300) { break; } $ratios[$next_pos] = $av_ratios; if ($template_wanted == 'HEADER') { $next_pos++; } else { $next_pos--; } } $last_pos = $next_pos; } asort($ratios); $best_by_pos = array_keys($ratios); $best_ratios[] = array($best_by_pos[0], $ratios[$best_by_pos[0]], $reference_file); } $best = mixed(); $best_pos = NULL; $best_reference_file = NULL; foreach ($best_ratios as $bits) { list($pos, $ratio, $reference_file) = $bits; if (is_null($best) || $ratio < $best) { $best = $ratio; $best_pos = $pos; $best_reference_file = $reference_file; } } if ($template_wanted == 'HEADER') { $cruft[$template_wanted] = substr($best_reference_file, 0, $best_pos); } else { $cruft[$template_wanted] = substr($best_reference_file, $best_pos); } } } else { // We can't find any common consistency when we only have one, so we mark all cruft and then later we will actually assume GLOBAL.tpl does not change and the only header/footer bit is the logical one $cruft['HEADER'] = array_key_exists(0, $compare_file_contents) ? $compare_file_contents[0] : ''; $cruft['FOOTER'] = array_key_exists(1, $compare_file_contents) ? $compare_file_contents[0] : ''; } // Extract header from cruft (<body> and before); SAVE $header = $cruft['HEADER']; // special cases of something with ID or class of header/top going through too $header_cases = array('<div id="header"', '<div id="page_header"', '<div class="header"', '<div class="page_header"'); foreach ($header_cases as $header_case) { $header_start_pos = strpos($header, $header_case); if ($header_start_pos !== false) { $header_start_pos = strpos($header, '>', $header_start_pos) + 1; break; } } if ($header_start_pos !== false) { $div_count = 1; do { $next_start = strpos($header, '<div ', $header_start_pos); $next_end = strpos($header, '</div>', $header_start_pos); $header_start_pos = $next_start !== false && $next_start < $next_end ? $next_start : $next_end; if ($header_start_pos !== false) { $header_start_pos = strpos($header, '>', $header_start_pos) + 1; } $div_count += $next_start !== false && $next_start < $next_end ? 1 : -1; } while ($div_count > 0 && $header_start_pos !== false); } $body_start_pos = strpos($header, '<body'); $head_end_pos = strpos($header, '<link'); if ($head_end_pos === false) { $head_end_pos = strpos($header, '</head'); } if ($header_start_pos === false) { $header_start_pos = strpos($header, '>', $body_start_pos) + 1; } if ($header_start_pos !== false) { $header = substr($header, 0, $header_start_pos); } $path = get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/templates_custom/HEADER.tpl'; $myfile = fopen($path, 'wt'); $header_to_write = substr($header, 0, $head_end_pos) . ' <script type="text/javascript">// <![CDATA[ {+START,IF,{$AND,{$EQ,,{$_GET,keep_has_js}},{$NOT,{$JS_ON}}}} if ((window.location.href.indexOf(\'upgrader.php\')==-1) && (window.location.search.indexOf(\'keep_has_js\')==-1)) {$,Redirect with JS on, and then hopefully we can remove keep_has_js after one click. This code only happens if JS is marked off, no infinite loops can happen.} window.location=window.location.href+((window.location.search==\'\')?(((window.location.href.indexOf(\'.htm\')==-1)&&(window.location.href.indexOf(\'.php\')==-1))?(((window.location.href.substr(window.location.href.length-1)!=\'/\')?\'/\':\'\')+\'index.php?\'):\'?\'):\'&\')+\'keep_has_js=1{+START,IF,{$DEV_MODE}}&keep_devtest=1{+END}\'; {+END} {+START,IF,{$NOT,{$BROWSER_MATCHES,ie}}}{+START,IF,{$HAS_SPECIFIC_PERMISSION,sees_javascript_error_alerts}}window.take_errors=true;{+END}{+END} var {+START,IF,{$CONFIG_OPTION,is_on_timezone_detection}}server_timestamp={$FROM_TIMESTAMP%},{+END}ocp_lang=\'{$LANG;}\',ocp_theme=\'{$THEME;}\'; //]]></script> <meta name="description" content="{+START,IF,{$NEQ,{DESCRIPTION},{!NA}}}{DESCRIPTION*}{+END}" /> <meta name="keywords" content="{KEYWORDS*}" /> {$CSS_TEMPCODE} {+START,IF_PASSED,EXTRA_HEAD} {EXTRA_HEAD} {+END} {$JS_TEMPCODE,header} {REFRESH}' . substr($header, $head_end_pos); $header_to_write = preg_replace('#<title>[^<>]*</title>#', '<title>{+START,IF_NON_EMPTY,{HEADER_TEXT}}{HEADER_TEXT*} - {+END}{$SITE_NAME*}</title>', $header_to_write); $header_to_write = preg_replace('#<meta name="keywords" content="([^"]*)"[^>]*>#', '', $header_to_write); $header_to_write = preg_replace('#<meta name="description" content="([^"]*)"[^>]*>#', '', $header_to_write); fwrite($myfile, $header_to_write); fclose($myfile); fix_permissions($path); sync_file($path); // Extract footer from cruft (</body> and below); SAVE $footer = $cruft['FOOTER']; // special cases of something with ID or class of footer/bottom going through too $footer_cases = array('<div id="footer"', '<div id="page_footer"', '<div class="footer"', '<div class="page_footer"'); foreach ($footer_cases as $footer_case) { $footer_start_pos = strpos($footer, $footer_case); if ($footer_start_pos !== false) { break; } } if ($footer_start_pos === false) { $footer_start_pos = strpos($footer, '</body'); } if ($footer_start_pos !== false) { $footer = substr($footer, $footer_start_pos); } $path = get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/templates_custom/FOOTER.tpl'; $myfile = fopen($path, 'wt'); $footer_to_write = $footer; fwrite($myfile, $footer_to_write); fclose($myfile); fix_permissions($path); sync_file($path); // What remains is saved to GLOBAL (note that we don't try and be clever about panels - this is up to the user, and they don't really need them anyway) if (count($compare_file_contents) > 1) { $global_to_write = substr($cruft['HEADER'], strlen($header)) . "\n{MIDDLE}\n" . substr($cruft['FOOTER'], 0, strlen($cruft['FOOTER']) - strlen($footer)); } else { $cruft['HEADER'] = $header_to_write; $cruft['FOOTER'] = $footer_to_write; $global_to_write = '{MIDDLE}'; } $path = get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/templates_custom/GLOBAL.tpl'; $myfile = fopen($path, 'wt'); fwrite($myfile, $global_to_write); fclose($myfile); fix_permissions($path); sync_file($path); // Extract site name from <title> tag, based on common consistency (largest common substring) $site_name = get_site_name(); if (count($compare_file_contents) > 1) { $titles_in_reference_files = array(); foreach ($compare_file_contents as $reference_file) { $matches = array(); if (preg_match('#<title>(.*)</title>#', $reference_file, $matches) != 0) { $titles_in_reference_files[] = $matches[1]; } } // Find largest common substring $lcs = ''; foreach ($titles_in_reference_files as $title_a) { for ($start = 0; $start < strlen($title_a); $start++) { for ($end = $start + 1; $end < strlen($title_a); $end++) { $current = substr($title_a, $start, $end - $start + 1); foreach ($titles_in_reference_files as $title_b) { if ($title_a != $title_b) { if (strpos(strtolower($title_b), strtolower($current)) === false) { continue 2; } } } if (strpos(strtolower($title_b), strtolower($current)) !== false) { if (strlen($current) > strlen($lcs)) { $lcs = $current; } } } } } // Strip bits $site_name = trim(preg_replace('#^[\\|\\-�,]#', '', preg_replace('#[\\|\\-�,]$#', '', trim($lcs)))); // Save as site name set_option('site_name', $site_name); } // Go and save our pages disable_php_memory_limit(); foreach ($content_files as $content_file) { $file_contents = file_get_contents($file_base . '/' . $content_file); // Find page-link for page $slash_count = substr_count($content_file, '/'); if ($slash_count == 0) { $content_file = '/' . $content_file; } elseif ($slash_count > 1) { $last_slash_pos = strrpos($content_file, '/'); $content_file = str_replace('/', '_', substr($content_file, 0, $last_slash_pos)) . substr($content_file, 0, $last_slash_pos); } list($zone, $page) = explode('/', preg_replace('#\\..*$#', '', $content_file), 2); if ($page == 'index') { $page = 'start'; } if (substr($content_file, -4) == '.php') { $file_path = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/minimodules_custom/' . $page . '.php'); $myfile = fopen($file_path, 'wt'); fwrite($myfile, $file_contents); fclose($myfile); fix_permissions($file_path); sync_file($file_path); } else { $filtered = $this->_html_filter($file_contents, $fix_html, $base_url, $files, $file_base); // Try and work out page title from <title> tag $matches = array(); $page_title = NULL; if (preg_match('#<title>(.*)</title>#', $filtered, $matches) != 0) { $page_title = preg_replace('#( [\\|\\-�] )?' . preg_quote($site_name) . '( [\\|\\-�] )?#', '', $matches[1]); } $page_keywords = NULL; if (preg_match('#<meta name="keywords" content="([^"]*)"#', $filtered, $matches) != 0) { $page_keywords = $matches[1]; } $page_description = NULL; if (preg_match('#<meta name="description" content="([^"]*)"#', $filtered, $matches) != 0) { $page_description = $matches[1]; } require_code('seo2'); seo_meta_set_for_explicit('comcode_page', $zone . ':' . $page, $page_keywords, $page_description); // Strip cruft off for htm/html files $i = strpos($filtered, '</head>'); if ($i === false) { $i = 0; } else { $i += 7; } $filtered = $this->levenshtein_strip_search($cruft['HEADER'], $filtered, false, $i); $filtered = $this->levenshtein_strip_search($cruft['FOOTER'], $filtered, true, 0); // Copy htm/html/php files to correct zone page directories (html_custom/<lang>, or minimodules_custom) if ($convert_to_comcode == 0) { // Insert an <h1> if the h1 is not there if (strpos($filtered, '<h1') === false && !is_null($page_title)) { $filtered = "<h1>" . $page_title . "</h1>\n\n" . $filtered; } $file_path = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/' . $page . '.txt'); $myfile = fopen($file_path, 'wt'); fwrite($myfile, '[semihtml]' . $filtered . '[/semihtml]'); fclose($myfile); fix_permissions($file_path); sync_file($file_path); } else { // Insert an <h1> if the h1 is not there if (strpos($filtered, '[title') === false && !is_null($page_title)) { $filtered = "[title]" . $page_title . "[/title]\n\n" . $filtered; } require_code('comcode_from_html'); $comcode = semihtml_to_comcode($filtered); $file_path = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/' . $page . '.txt'); $myfile = fopen($file_path, 'wt'); fwrite($myfile, $comcode); fclose($myfile); fix_permissions($file_path); sync_file($file_path); } } } // Copy all remaining files to under uploads/website_specific foreach ($files as $file) { if (!file_exists($file_base . '/' . $file)) { continue; } $path = get_custom_file_base() . '/uploads/website_specific/' . $file; $create_path = $path; do { @mkdir(dirname($create_path), 0777); $create_path = dirname($create_path); } while (strlen($create_path) > 1); copy($file_base . '/' . $file, $path); fix_permissions($path); sync_file($path); } // Set the panels to be blank foreach (array('site/', '') as $zone) { $panels = array('panel_left', 'panel_right'); foreach ($panels as $panel) { $path = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . 'pages/comcode_custom/' . filter_naughty(fallback_lang()) . '/' . filter_naughty($panel) . '.txt'); $myfile = fopen($path, 'wt'); fclose($myfile); fix_permissions($path); sync_file($path); } } }
/** * Script handler for downloading a gallery, as specified by GET parameters. */ function download_gallery_script() { if (function_exists('set_time_limit')) { @set_time_limit(0); } require_code('galleries'); // Closed site $site_closed = get_option('site_closed'); if ($site_closed == '1' && !has_specific_permission(get_member(), 'access_closed_site') && !$GLOBALS['IS_ACTUALLY_ADMIN']) { header('Content-Type: text/plain'); @exit(get_option('closed')); } require_lang('galleries'); require_code('zip'); $cat = get_param('cat'); if (!has_category_access(get_member(), 'galleries', $cat)) { access_denied('CATEGORY_ACCESS'); } check_specific_permission('may_download_gallery', array('galleries', $cat)); if (strpos($cat, chr(10)) !== false || strpos($cat, chr(13)) !== false) { log_hack_attack_and_exit('HEADER_SPLIT_HACK'); } $gallery_rows = $GLOBALS['SITE_DB']->query_select('galleries', array('*'), array('name' => $cat), '', 1); if (!array_key_exists(0, $gallery_rows)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $gallery_row = $gallery_rows[0]; // Send header header('Content-Type: application/octet-stream' . '; authoritative=true;'); if (strstr(ocp_srv('HTTP_USER_AGENT'), 'MSIE') !== false) { header('Content-Disposition: filename="gallery-' . $cat . '.zip"'); } else { header('Content-Disposition: attachment; filename="gallery-' . $cat . '.zip"'); } disable_php_memory_limit(); $rows = array_merge($GLOBALS['SITE_DB']->query_select('videos', array('url', 'add_date'), array('cat' => $cat, 'validated' => 1)), $GLOBALS['SITE_DB']->query_select('images', array('url', 'add_date'), array('cat' => $cat, 'validated' => 1))); $array = array(); foreach ($rows as $row) { $full_path = NULL; $data = NULL; if (url_is_local($row['url']) && file_exists(get_file_base() . '/' . urldecode($row['url']))) { $path = urldecode($row['url']); $full_path = get_file_base() . '/' . $path; if (file_exists($full_path)) { $time = filemtime($full_path); $name = $path; } else { continue; } } else { continue; // Actually we won't include them, if they are not local it implies it is not reasonable for them to lead to server load, and they may not even be native files $time = $row['add_date']; $name = basename(urldecode($row['url'])); $data = http_download_file($row['url']); } $array[] = array('name' => preg_replace('#^uploads/galleries/#', '', $name), 'time' => $time, 'data' => $data, 'full_path' => $full_path); } if ($gallery_row['rep_image'] != '') { if (url_is_local($gallery_row['rep_image']) && file_exists(get_file_base() . '/' . urldecode($gallery_row['rep_image']))) { $path = urldecode($gallery_row['rep_image']); $full_path = get_file_base() . '/' . $path; if (file_exists($full_path)) { $time = filemtime($full_path); $name = $path; $data = file_get_contents($full_path); } } else { $time = $gallery_row['add_date']; $name = basename(urldecode($gallery_row['rep_image'])); $data = http_download_file($gallery_row['rep_image']); } $array[] = array('name' => preg_replace('#^uploads/(galleries|grepimages)/#', '', $name), 'time' => $time, 'data' => $data); } @ini_set('zlib.output_compression', 'Off'); //$zip_file=create_zip_file($array); //header('Content-Length: '.strval(strlen($zip_file))); //echo $zip_file; create_zip_file($array, true); }
/** * The actualiser for importing a CSV file. * * @return tempcode The UI */ function _import_csv() { $title = get_page_title('IMPORT_MEMBER_CSV'); disable_php_memory_limit(); // Even though we split into chunks, PHP does leak memory :( $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/import_csv'; if (function_exists('set_time_limit')) { @set_time_limit(0); } require_lang('ocf'); require_code('ocf_members_action'); $default_password = post_param('default_password'); $num_added = 0; $num_edited = 0; $done = 0; $headings = $this->_get_csv_headings(); $all_cpfs = $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('id', 'cf_default', 'cf_type', 'cf_name'), NULL, 'ORDER BY cf_order'); foreach ($all_cpfs as $i => $c) { $c['text_original'] = get_translated_text($c['cf_name'], $GLOBALS['FORUM_DB']); $all_cpfs[$i] = $c; $headings[$c['text_original']] = NULL; } $_all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, false, true); $all_groups = array_flip($_all_groups); $all_members = collapse_2d_complexity('id', 'm_username', $GLOBALS['FORUM_DB']->query_select('f_members', array('id', 'm_username'))); $all_members_flipped = array_flip($all_members); // Import require_code('uploads'); if (is_swf_upload(true) || array_key_exists('file', $_FILES) && is_uploaded_file($_FILES['file']['tmp_name'])) { $_csv_data = array(); $fixed_contents = unixify_line_format(file_get_contents($_FILES['file']['tmp_name'])); $myfile = @fopen($_FILES['file']['tmp_name'], 'wb'); if ($myfile !== false) { fwrite($myfile, $fixed_contents); fclose($myfile); } $myfile = fopen($_FILES['file']['tmp_name'], 'rb'); $del = ','; $csv_header = fgetcsv($myfile, 102400, $del); if ($csv_header === false) { warn_exit(do_lang_tempcode('NO_DATA_IMPORTED')); } if (count($csv_header) == 1 && strpos($csv_header[0], ';') !== false) { $del = ';'; rewind($myfile); $csv_header = fgetcsv($myfile, 102400, $del); } while (($csv_line = fgetcsv($myfile, 102400, $del)) !== false) { $line = array(); foreach ($csv_header as $i => $h) { $extracted_value = trim(unixify_line_format(array_key_exists($i, $csv_line) ? $csv_line[$i] : '')); if (strpos($h, ':') !== false) { $parts = explode(':', $h, 2); $h = trim($parts[0]); if ($extracted_value != '') { $extracted_value = $parts[1] . ': ' . $extracted_value; } } if (array_key_exists($h, $line)) { if ($extracted_value != '') { $line[$h] .= ($line[$h] != '' ? chr(10) : '') . $extracted_value; } } else { $line[$h] = $extracted_value; } } if (!array_key_exists('Username', $line) || $line['Username'] == '') { // Can we auto-generate it $forename = NULL; if (array_key_exists('Forenames', $line)) { $forename = $line['Forenames']; } if (array_key_exists('Forename', $line)) { $forename = $line['Forename']; } if (array_key_exists('First name', $line)) { $forename = $line['First name']; } if (array_key_exists('First Name', $line)) { $forename = $line['First Name']; } $surname = NULL; if (array_key_exists('Surname', $line)) { $surname = $line['Surname']; } if (array_key_exists('Last name', $line)) { $surname = $line['Last name']; } if (array_key_exists('Last Name', $line)) { $surname = $line['Last Name']; } if (!is_null($forename) || !is_null($surname)) { // Can we get a year too? $year = ''; foreach ($line as $tl_key => $tl_val) { if (substr($tl_key, 0, 4) == 'Year') { $year = $tl_val; break; } } if (strlen($year) == 4 && (substr($year, 0, 2) == '19' || substr($year, 0, 2) == '20')) { $year = substr($year, 2); } // Tidy up forename $_forename = preg_replace('#[^\\w]#', '', preg_replace('#[\\s\\.].*#', '', $forename)); // Tidy up surname (last bit strips like 'OBE') $_surname = preg_replace('#[^\\w]#', '', trim(preg_replace('#\\s*[A-Z\\d][A-Z\\d]+#', '', $surname))); // Put it together $line['Username'] = ucfirst($_forename) . ucfirst($_surname) . $year; } else { continue; // This field is needed } } $username = $line['Username']; $linked_id = NULL; if (array_key_exists('ID', $line)) { $linked_id = $line['ID'] != '' && array_key_exists(intval($line['ID']), $all_members) ? intval($line['ID']) : NULL; } if (is_null($linked_id)) { $linked_id = array_key_exists($username, $all_members_flipped) ? $all_members_flipped[$username] : NULL; } $new_member = is_null($linked_id); $email_address_key = 'E-mail address'; if (array_key_exists('Email address', $line)) { $email_address_key = 'Email address'; } if (array_key_exists('E-mail Address', $line)) { $email_address_key = 'E-mail Address'; } if (array_key_exists('Email Address', $line)) { $email_address_key = 'Email Address'; } if (array_key_exists('E-mail', $line)) { $email_address_key = 'E-mail'; } if (array_key_exists('Email', $line)) { $email_address_key = 'Email'; } $dob_key = 'Date of birth'; if (array_key_exists('Date Of Birth', $line)) { $dob_key = 'Date Of Birth'; } if (array_key_exists('DOB', $line)) { $dob_key = 'DOB'; } // If it's an edited member, add in their existing CSV details, so that if it's a partial merge it'll still work without deleting anything! if (!$new_member) { $member_groups = $GLOBALS['FORUM_DB']->query_select('f_group_members', array('gm_member_id', 'gm_group_id'), array('gm_validated' => 1, 'gm_member_id' => $linked_id)); $member_cpfs = list_to_map('mf_member_id', $GLOBALS['FORUM_DB']->query_select('f_member_custom_fields', array('*'), array('mf_member_id' => $linked_id), '', 1)); $this_record = $this->_get_csv_member_record($member_cpfs, $GLOBALS['FORUM_DRIVER']->get_member_row($linked_id), $_all_groups, $headings, $all_cpfs, $member_groups); // Remember "+" in PHP won't overwrite existing keys if (!array_key_exists($email_address_key, $line)) { unset($this_record['E-mail address']); } if (!array_key_exists($dob_key, $line)) { unset($this_record['Date of birth']); } $line += $this_record; } // Set up member row if (array_key_exists('Password', $line) && $line['Password'] != '') { $parts = explode('/', $line['Password']); $password = $parts[0]; $salt = array_key_exists(1, $parts) ? $parts[1] : NULL; $password_compatibility_scheme = array_key_exists(2, $parts) ? $parts[2] : NULL; } else { $password = NULL; $salt = NULL; $password_compatibility_scheme = NULL; } $matches = array(); if (array_key_exists($email_address_key, $line)) { $email_address = $line[$email_address_key]; } else { $email_address = NULL; } if (preg_match('#^([^\\s]*)\\s+\\(.*\\)$#', $email_address, $matches) != 0) { $email_address = $matches[1]; } if (preg_match('#^.*\\s+<(.*)>$#', $email_address, $matches) != 0) { $email_address = $matches[1]; } if (array_key_exists($dob_key, $line)) { $parts = explode('/', $line[$dob_key]); $dob_day = array_key_exists(2, $parts) ? intval($parts[2]) : NULL; $dob_month = array_key_exists(1, $parts) ? intval($parts[1]) : NULL; $dob_year = array_key_exists(0, $parts) ? intval($parts[0]) : NULL; } else { $dob_day = NULL; $dob_month = NULL; $dob_year = NULL; } $validated = array_key_exists('Validated', $line) ? strtoupper($line['Validated']) == 'YES' || $line['Validated'] == '1' || strtoupper($line['Validated']) == 'Y' || strtoupper($line['Validated']) == 'ON' ? 1 : 0 : 1; if (array_key_exists('Join time', $line)) { if (strpos($line['Join time'], '-') !== false) { $parts = explode('-', $line['Join time']); } else { $parts = explode('/', $line['Join time']); } if (!array_key_exists(1, $parts)) { $parts[1] = '1'; } if (!array_key_exists(2, $parts)) { $parts[2] = '1'; } if (strlen($parts[2]) != 4) { $join_time = mktime(0, 0, 0, intval($parts[1]), intval($parts[2]), intval($parts[0])); // yy(yy)-mm-dd } else { $join_time = mktime(0, 0, 0, intval($parts[1]), intval($parts[0]), intval($parts[2])); // dd-mm-yyyy } if ($join_time > time()) { $join_time = time(); } // Fixes MySQL out of range error that could happen } else { $join_time = NULL; } $avatar_url = array_key_exists('Avatar', $line) ? $line['Avatar'] : ''; if (!is_null($avatar_url)) { if (substr($avatar_url, 0, strlen(get_base_url() . '/')) == get_base_url() . '/') { $avatar_url = substr($avatar_url, strlen(get_base_url() . '/')); } } $signature = array_key_exists('Signature', $line) ? $line['Signature'] : ''; $is_perm_banned = array_key_exists('Banned', $line) ? strtoupper($line['Banned']) == 'YES' || $line['Banned'] == '1' || strtoupper($line['Banned']) == 'Y' || strtoupper($line['Banned']) == 'ON' ? 1 : 0 : 0; $reveal_age = array_key_exists('Reveal age', $line) ? strtoupper($line['Reveal age']) == 'YES' || $line['Reveal age'] == '1' || strtoupper($line['Reveal age']) == 'Y' || strtoupper($line['Reveal age']) == 'ON' ? 1 : 0 : 0; $language = array_key_exists('Language', $line) ? $line['Language'] : ''; $allow_emails = array_key_exists('Accept member e-mails', $line) ? strtoupper($line['Accept member e-mails']) == 'YES' || $line['Accept member e-mails'] == '1' || strtoupper($line['Accept member e-mails']) == 'Y' || strtoupper($line['Accept member e-mails']) == 'ON' ? 1 : 0 : 0; $allow_emails_from_staff = array_key_exists('Opt-in', $line) ? strtoupper($line['Opt-in']) == 'YES' || $line['Opt-in'] == '1' || strtoupper($line['Opt-in']) == 'Y' || strtoupper($line['Opt-in']) == 'ON' ? 1 : 0 : 0; $primary_group = NULL; $groups = NULL; if (array_key_exists('Usergroup', $line)) { $parts = explode('/', $line['Usergroup']); foreach ($parts as $p) { if (!array_key_exists($p, $all_groups)) { require_code('ocf_groups_action'); $g_id = ocf_make_group($p, 0, 0, 0, ''); $all_groups[$p] = $g_id; $_group_edit_url = build_url(array('page' => 'admin_ocf_groups', 'type' => '_ed', 'id' => $g_id), get_module_zone('admin_ocf_groups')); $group_edit_url = $_group_edit_url->evaluate(); attach_message(do_lang_tempcode('MEMBER_IMPORT_GROUP_ADDED', escape_html($p), escape_html($group_edit_url)), 'inform'); } } $primary_group = $all_groups[$parts[0]]; unset($parts[0]); $groups = array(); foreach ($parts as $p) { $groups[] = $all_groups[$p]; } } $photo_url = array_key_exists('Photo', $line) ? $line['Photo'] : ''; if ($photo_url != '') { require_code('images'); $photo_thumb_url = 'uploads/ocf_photos_thumbs/' . uniqid('', true) . '.png'; convert_image($photo_url, $photo_thumb_url, -1, -1, intval(get_option('thumb_width')), false); } else { $photo_thumb_url = ''; } $custom_fields = array(); foreach ($all_cpfs as $cpf) { $custom_fields[$cpf['id']] = array_key_exists($cpf['text_original'], $line) ? $line[$cpf['text_original']] : $cpf['cf_default']; if (!array_key_exists($cpf['text_original'], $line) && $cpf['cf_type'] == 'list') { $parts = explode($custom_fields[$cpf['id']], '|'); $custom_fields[$cpf['id']] = $parts[0]; } if ($cpf['cf_type'] == 'integer') { $custom_fields[$cpf['id']] = intval($custom_fields[$cpf['id']]); } elseif ($cpf['cf_type'] == 'tick') { $custom_fields[$cpf['id']] = strtoupper($custom_fields[$cpf['id']]) == 'YES' || strtoupper($custom_fields[$cpf['id']]) == 'Y' || strtoupper($custom_fields[$cpf['id']]) == 'ON' || $custom_fields[$cpf['id']] == '1' ? 1 : 0; } elseif ($cpf['cf_type'] == 'short_text' || $cpf['cf_type'] == 'short_trans') { $custom_fields[$cpf['id']] = substr(str_replace(chr(10), ', ', str_replace(',' . chr(10), chr(10), $custom_fields[$cpf['id']])), 0, 255); } elseif ($cpf['cf_type'] == 'long_text' || $cpf['cf_type'] == 'long_trans') { //$custom_fields[$cpf['id']]=$custom_fields[$cpf['id']]; } elseif ($cpf['cf_type'] == 'float') { if (preg_match('#^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\n(\\d\\d\\d\\d)$#', $custom_fields[$cpf['id']]) != 0) { $parts = explode(chr(10), $custom_fields[$cpf['id']], 2); $month_lookup = array('Jan' => 0.1, 'Feb' => 0.2, 'Mar' => 0.3, 'Apr' => 0.4, 'May' => 0.5, 'Jun' => 0.6, 'Jul' => 0.7, 'Aug' => 0.8, 'Sep' => 0.9, 'Oct' => 0.1, 'Nov' => 0.11, 'Dec' => 0.12); $custom_fields[$cpf['id']] = floatval($parts[1]) + $month_lookup[$parts[0]]; } else { $custom_fields[$cpf['id']] = floatval($custom_fields[$cpf['id']]); } } unset($line[$cpf['text_original']]); } foreach (array_keys($headings) as $h) { unset($line[$h]); } unset($line[$email_address_key]); unset($line[$dob_key]); foreach ($line as $h => $f) { $cf_id = ocf_make_custom_field($h, 0, '', '', 0, 0, 0, 0, 'long_text'); $_cpf_edit_url = build_url(array('page' => 'admin_ocf_customprofilefields', 'type' => '_ed', 'id' => $cf_id), get_module_zone('admin_ocf_customprofilefields')); $cpf_edit_url = $_cpf_edit_url->evaluate(); attach_message(do_lang_tempcode('MEMBER_IMPORT_CPF_ADDED', escape_html($h), escape_html($cpf_edit_url)), 'inform'); $custom_fields[$cf_id] = $f; $all_cpfs[] = array('id' => $cf_id, 'cf_default' => '', 'text_original' => $h, 'cf_type' => 'short_line'); } if ($new_member) { if (is_null($password)) { $password = $default_password; } if (is_null($salt)) { $salt = ''; } if (is_null($password_compatibility_scheme)) { $password_compatibility_scheme = ''; } $linked_id = ocf_make_member($username, $password, is_null($email_address) ? '' : $email_address, $groups, $dob_day, $dob_month, $dob_year, $custom_fields, NULL, $primary_group, $validated, $join_time, NULL, '', $avatar_url, $signature, $is_perm_banned, get_option('default_preview_guests') == '1' ? 1 : 0, $reveal_age, '', $photo_url, $photo_thumb_url, 1, 1, $language, $allow_emails, $allow_emails_from_staff, '', NULL, '', false, $password_compatibility_scheme, $salt, 1, NULL, NULL, 0, '*', ''); $all_members[$linked_id] = $username; $all_members_flipped[$username] = $linked_id; $num_added++; } else { $old_username = $GLOBALS['OCF_DRIVER']->get_member_row_field($linked_id, 'm_username'); if ($old_username == $username) { $username = NULL; } ocf_edit_member($linked_id, $email_address, NULL, $dob_day, $dob_month, $dob_year, NULL, $primary_group, $custom_fields, NULL, $reveal_age, NULL, NULL, $language, $allow_emails, $allow_emails_from_staff, $validated, $username, $password, NULL, NULL, NULL, NULL, NULL, $join_time, $avatar_url, $signature, $is_perm_banned, $photo_url, $photo_thumb_url, $salt, $password_compatibility_scheme, true); $num_edited++; } $done++; } fclose($myfile); } else { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD')); } if ($done == 0) { warn_exit(do_lang_tempcode('NO_DATA_IMPORTED')); } breadcrumb_set_parents(array(array('_SEARCH:admin_ocf_join:menu', do_lang_tempcode('MEMBERS')), array('_SEARCH:admin_ocf_join:import_csv', do_lang_tempcode('IMPORT_MEMBER_CSV')))); breadcrumb_set_self(do_lang_tempcode('DONE')); return inform_screen($title, do_lang_tempcode('NUM_MEMBERS_IMPORTED', escape_html(integer_format($num_added)), escape_html(integer_format($num_edited)))); }