/** * Get a splurghified version of the specified item. * * @param string The name of what the key we want to reference is in our array of maps (e.g. 'id') * @param array A row of maps for data we are splurghing; this is probably just the result of $GLOBALS['SITE_DB']->query_select * @param URLPATH The stub that links will be passed through * @param ID_TEXT The page name we will be saving customised HTML under * @param TIME The time we did our last change to the data being splurghed (so it can see if we can simply decache instead of deriving) * @param ?AUTO_LINK The ID that is at the root of our tree (NULL: db_get_first_id) * @return string A string of HTML that represents our splurghing (will desplurgh in the users browser) */ function splurgh_master_build($key_name, $map, $url_stub, $_cache_file, $last_change_time, $first_id = NULL) { if (is_null($first_id)) { $first_id = db_get_first_id(); } if (!array_key_exists($first_id, $map)) { return ''; } if (!has_js()) { warn_exit(do_lang_tempcode('MSG_JS_NEEDED')); } require_javascript('javascript_splurgh'); if (is_browser_decacheing()) { $last_change_time = time(); } $cache_file = zone_black_magic_filterer(get_custom_file_base() . '/' . get_zone_name() . '/pages/html_custom/' . filter_naughty(user_lang()) . '/' . filter_naughty($_cache_file) . '.htm'); if (!file_exists($cache_file) || is_browser_decacheing() || filesize($cache_file) == 0 || $last_change_time > filemtime($cache_file)) { $myfile = @fopen($cache_file, 'wt'); if ($myfile === false) { intelligent_write_error($cache_file); } $fulltable = array(); $splurgh = _splurgh_do_node($map, $first_id, '', $fulltable, 0); $page = do_template('SPLURGH', array('_GUID' => '8775edfc5a386fdf2cec69b0fc889952', 'KEY_NAME' => $key_name, 'URL_STUB' => $url_stub, 'SPLURGH' => str_replace('"', '\'', $splurgh))); $ev = $page->evaluate(); if (fwrite($myfile, $ev) < strlen($ev)) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } fclose($myfile); fix_permissions($cache_file); sync_file($cache_file); return $ev; } return file_get_contents($cache_file, FILE_TEXT); }
/** * An option has dissappeared somehow - find it via searching our code-base for it's install code. It doesn't get returned, just loaded up. This function will produce a fatal error if we cannot find it. * * @param ID_TEXT The name of the value */ function find_lost_option($name) { global $OPTIONS; // In the dark dark past, we'd bomb out... if (function_exists('find_all_zones') && !defined('HIPHOP_PHP')) { // However times are pleasant, the grass is green, the sun high is the summer sky. Let's perform some voodoo magic... $all_zones = find_all_zones(); $search = array(); $types = array('modules_custom', 'modules'); foreach ($all_zones as $zone) { foreach ($types as $type) { $pages = find_all_pages($zone, $type); foreach ($pages as $page => $type2) { $search[] = zone_black_magic_filterer(get_file_base() . '/' . $zone . ($zone != '' ? '/' : '') . 'pages/' . $type2 . '/' . $page . '.php'); } } } require_code('zones2'); require_code('zones3'); $all_blocks = find_all_blocks(); foreach ($all_blocks as $block => $type) { $search[] = get_file_base() . '/' . $type . '/blocks/' . $block . '.php'; } if (file_exists(get_file_base() . '/sources_custom/ocf_install.php')) { $search[] = get_file_base() . '/sources_custom/ocf_install.php'; } $search[] = get_file_base() . '/sources/ocf_install.php'; $matches = array(); foreach ($search as $s) { // echo $s.'<br />'; $code = file_get_contents($s); if (preg_match('#add_config_option\\(\'\\w+\',\'' . str_replace('#', '\\#', preg_quote($name)) . '\',\'\\w+\',\'.+\',\'\\w+\',\'\\w+\'(,1)?\\);#', $code, $matches) > 0) { require_code('database_action'); $upgrade_from = NULL; // In case referenced in add_config_option line eval($matches[0]); load_options(); break; // fatal_exit(do_ lang_tempcode('CONFIG_OPTION_FETCHED',escape_html($name))); CONFIG_OPTION_FETCHED=A config option ({1}) was missing, but has been hunted down and installed. This is an unexpected inconsistency, please refresh the page, and hopefully it has been permanently corrected. } } } if (!array_key_exists($name, $OPTIONS)) { fatal_exit(do_lang_tempcode('_MISSING_OPTION', escape_html($name))); } }
/** * Standard modular run function for OcCLE hooks. * * @param array The options with which the command was called * @param array The parameters with which the command was called * @param array A reference to the OcCLE filesystem object * @return array Array of stdcommand, stdhtml, stdout, and stderr responses */ function run($options, $parameters, &$occle_fs) { if (array_key_exists('h', $options) || array_key_exists('help', $options)) { return array('', do_command_help('find_entry_points', array('h'), array(true)), '', ''); } else { if (!array_key_exists(0, $parameters)) { return array('', '', '', do_lang('MISSING_PARAM', '1', 'find_entry_points')); } // NOTE: this code assumes the search-string is contained within the zone:page portion of the entry point, not any part of the parameterisation $entry_points = array(); $zones = find_all_zones(); require_all_lang(); foreach ($zones as $zone) { $pages = find_all_pages_wrap($zone); foreach ($pages as $page => $type) { if (strpos($zone . ':' . $page, $parameters[0]) !== false) { if ($type == 'modules' || $type == 'modules_custom') { require_code(zone_black_magic_filterer(filter_naughty_harsh($zone) . '/pages/' . filter_naughty_harsh($type) . '/' . filter_naughty_harsh($page) . '.php')); if (class_exists('Mx_' . filter_naughty_harsh($page))) { $object = object_factory('Mx_' . filter_naughty_harsh($page), true); } else { $object = object_factory('Module_' . filter_naughty_harsh($page), true); } if (!is_null($object) && method_exists($object, 'get_entry_points')) { $_entry_points = $object->get_entry_points(); foreach ($_entry_points as $key => $val) { $entry_points[$zone . ':' . $page . ':' . $key] = do_lang($val); } } } else { $entry_points[$zone . ':' . $page] = $page; } } } } return array('', do_template('OCCLE_ENTRY_POINTS', array('_GUID' => 'afaf0b0451ccbdae399dd56e39359c0e', 'ENTRY_POINTS' => $entry_points)), '', ''); } }
/** * Take the specified parameters, and try to find the corresponding page * * @param ID_TEXT The codename of the page to load * @param ID_TEXT The zone the page is being loaded in * @param ?ID_TEXT The type of page - for if you know it (NULL: don't know it) * @param ?LANGUAGE_NAME Language name (NULL: users language) * @param boolean Whether to not check for redirects (normally you would) * @return ~array A list of details (false: page not found) */ function _request_page($codename, $zone, $page_type = NULL, $lang = NULL, $no_redirect_check = false) { if ($lang === NULL) { $lang = user_lang(); } if ($codename == 'login') { $login_zone = get_module_zone('login'); $path = zone_black_magic_filterer($login_zone . ($login_zone == '' ? '' : '/') . 'pages/modules_custom/' . $codename . '.php', true); if (is_file(get_file_base() . '/' . $path)) { return array('MODULES_CUSTOM', $login_zone, $codename, $path); } $path = zone_black_magic_filterer($login_zone . ($login_zone == '' ? '' : '/') . 'pages/modules/' . $codename . '.php', true); if (is_file(get_file_base() . '/' . $path)) { return array('MODULES', $login_zone, $codename, $path); } } // Redirect if (!$no_redirect_check && addon_installed('redirects_editor')) { global $REDIRECT_CACHE; if (array_key_exists($zone, $REDIRECT_CACHE)) { $redirect = array_key_exists($codename, $REDIRECT_CACHE[$zone]) ? array($REDIRECT_CACHE[$zone][$codename]) : array(); } else { $redirect = $GLOBALS['SITE_DB']->query_select('redirects', array('*'), array('r_from_zone' => $zone, 'r_from_page' => $codename), '', 1); } if (array_key_exists(0, $redirect)) { return array('REDIRECT', $redirect[0]); } } //If we know the page type if ($page_type !== NULL) { switch ($page_type) { case 'modules_custom': if (!in_safe_mode()) { $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/modules_custom/' . $codename . '.php', true); if (is_file(get_file_base() . '/' . $path)) { return array('MODULES_CUSTOM', $zone, $codename, $path); } } break; case 'modules': $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/modules/' . $codename . '.php', true); if (is_file(get_file_base() . '/' . $path)) { return array('MODULES', $zone, $codename, $path); } break; case 'comcode_custom': if (!in_safe_mode()) { if (get_param_integer('keep_theme_test', 0) == 1) { $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang . '/' . $GLOBALS['FORUM_DRIVER']->get_theme() . '__' . $codename . '.txt', true); if (is_file(get_custom_file_base() . '/' . $path)) { return array('COMCODE_CUSTOM', $zone, $GLOBALS['FORUM_DRIVER']->get_theme() . '__' . $codename, $lang, $path); } } $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang . '/' . $codename . '.txt', true); if (is_file(get_custom_file_base() . '/' . $path)) { return array('COMCODE_CUSTOM', $zone, $codename, $lang, $path); } if ($GLOBALS['CURRENT_SHARE_USER'] !== NULL) { $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang . '/' . $codename . '.txt', true); if (is_file(get_file_base() . '/' . $path)) { return array('COMCODE_CUSTOM_PURE', $zone, $codename, $lang, $path); } } } //break; //break; case 'comcode': $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode/' . $lang . '/' . $codename . '.txt', true); if (is_file(get_file_base() . '/' . $path)) { return array('COMCODE', $zone, $codename, $lang, $path); } break; case 'html_custom': if (!in_safe_mode()) { $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/html_custom/' . $lang . '/' . $codename . '.htm', true); if (is_file(get_custom_file_base() . '/' . $path)) { return array('HTML_CUSTOM', $zone, $codename, $lang, $path); } } break; case 'html': $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/html/' . $lang . '/' . $codename . '.htm', true); if (is_file(get_file_base() . '/' . $path)) { return array('HTML', $zone, $codename, $lang, $path); } break; case 'minimodules_custom': if (!in_safe_mode()) { $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/minimodules_custom/' . $lang . '/' . $codename . '.php', true); if (is_file(get_file_base() . '/' . $path)) { return array('MINIMODULES_CUSTOM', $zone, $codename, $path); } } break; case 'minimodules': $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/minimodules/' . $lang . '/' . $codename . '.php', true); if (is_file(get_file_base() . '/' . $path)) { return array('MINIMODULES', $zone, $codename, $path); } break; } return false; } // We have a priority list to find our page if (!in_safe_mode()) { $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/modules_custom/' . $codename . '.php', true); if (is_file(get_file_base() . '/' . $path)) { return array('MODULES_CUSTOM', $zone, $codename, $path); } } $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/modules/' . $codename . '.php', true); if (is_file(get_file_base() . '/' . $path)) { return array('MODULES', $zone, $codename, $path); } if (!in_safe_mode()) { if (get_param_integer('keep_theme_test', 0) == 1) { $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang . '/' . $GLOBALS['FORUM_DRIVER']->get_theme() . '__' . $codename . '.txt', true); if (is_file(get_custom_file_base() . '/' . $path)) { return array('COMCODE_CUSTOM', $zone, $GLOBALS['FORUM_DRIVER']->get_theme() . '__' . $codename, $lang, $path); } } $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang . '/' . $codename . '.txt', true); if (is_file(get_custom_file_base() . '/' . $path)) { return array('COMCODE_CUSTOM', $zone, $codename, $lang, $path); } if ($GLOBALS['CURRENT_SHARE_USER'] !== NULL) { $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang . '/' . $codename . '.txt', true); if (is_file(get_file_base() . '/' . $path)) { return array('COMCODE_CUSTOM_PURE', $zone, $codename, $lang, $path); } } } $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode/' . $lang . '/' . $codename . '.txt', true); if (is_file(get_file_base() . '/' . $path)) { return array('COMCODE', $zone, $codename, $lang, $path); } if (!in_safe_mode()) { $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/html_custom/' . $lang . '/' . $codename . '.htm', true); if (is_file(get_custom_file_base() . '/' . $path)) { return array('HTML_CUSTOM', $zone, $codename, $lang, $path); } } $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/html/' . $lang . '/' . $codename . '.htm', true); if (is_file(get_file_base() . '/' . $path)) { return array('HTML', $zone, $codename, $lang, $path); } if (!in_safe_mode()) { $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/minimodules_custom/' . $codename . '.php', true); if (is_file(get_file_base() . '/' . $path)) { return array('MINIMODULES_CUSTOM', $zone, $codename, $path); } } $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/minimodules/' . $codename . '.php', true); if (is_file(get_file_base() . '/' . $path)) { return array('MINIMODULES', $zone, $codename, $path); } // As a last resort, consider it might not yet have been translated $fallback_lang = fallback_lang(); $site_lang = get_site_default_lang(); $langs_to_try = array(); if ($lang != $site_lang) { $langs_to_try[] = $site_lang; } if ($lang != $fallback_lang) { $langs_to_try[] = $fallback_lang; } foreach ($langs_to_try as $fallback_lang) { if (!in_safe_mode()) { $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $fallback_lang . '/' . $codename . '.txt', true); if (is_file(get_custom_file_base() . '/' . $path)) { return array('COMCODE_CUSTOM', $zone, $codename, $fallback_lang, $path); } if ($GLOBALS['CURRENT_SHARE_USER'] !== NULL) { $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $fallback_lang . '/' . $codename . '.txt', true); if (is_file(get_file_base() . '/' . $path)) { return array('COMCODE_CUSTOM_PURE', $zone, $codename, $fallback_lang, $path); } } } $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode/' . $fallback_lang . '/' . $codename . '.txt', true); if (is_file(get_file_base() . '/' . $path)) { return array('COMCODE', $zone, $codename, $fallback_lang, $path); } if (!in_safe_mode()) { $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/html_custom/' . $fallback_lang . '/' . $codename . '.htm', true); if (is_file(get_custom_file_base() . '/' . $path)) { return array('HTML_CUSTOM', $zone, $codename, $fallback_lang, $path); } } $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/html/' . $fallback_lang . '/' . $codename . '.htm', true); if (is_file(get_file_base() . '/' . $path)) { return array('HTML', $zone, $codename, $fallback_lang, $path); } } return false; }
/** * 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); } } } } } } }
/** * 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)); }
/** * 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 modular run function. * * @param array A map of parameters. * @return tempcode The result of execution. */ function run($map) { require_all_lang(); require_code('zones2'); $skip_pages = array_key_exists('skip', $map) ? explode(',', $map['skip']) : array(); $comcode_page_rows = $GLOBALS['SITE_DB']->query_select('comcode_pages', array('*')); $_zones = array(); $zones = find_all_zones(false, true); $GLOBALS['MEMORY_OVER_SPEED'] = true; $low_memory = ini_get('memory_limit') != '-1' && ini_get('memory_limit') != '0' && ini_get('memory_limit') != '' && intval(preg_replace('#M$#', '', ini_get('memory_limit'))) < 26 || get_option('has_low_memory_limit') === '1'; // 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); foreach ($zones2 as $z) { list($zone, $zone_title, , $zone_default_page) = $z; if (has_zone_access(get_member(), $zone)) { $_pages = array(); $pages = find_all_pages_wrap($zone); if (isset($pages[$zone_default_page])) { $default = $pages[$zone_default_page]; $pages = array($zone_default_page => $default) + $pages; } 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($page, $skip_pages)) { continue; } if (in_array($zone . ':' . $page, $skip_pages)) { continue; } if ($page == '404') { continue; } if (strpos($page, '_tree_made') !== false) { continue; } if ($page == 'sitemap') { 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()) { continue; } if (has_page_access(get_member(), $page, $zone)) { $_entrypoints = array(); $__entrypoints = $low_memory ? array(NULL) : 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 ($low_memory && !defined('HIPHOP_PHP') && 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('!')) { $url = build_url(array('page' => $page), $zone, NULL, false, false, true); $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'); if (!is_file($path)) { $path = zone_black_magic_filterer(get_file_base() . '/' . filter_naughty($zone) . '/pages/' . filter_naughty($page_type) . '/' . $page . '.txt'); } $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(); $title_portion = str_replace('{$SITE_NAME}', get_site_name(), substr($page_contents, $start, $end - $start)); if (preg_match('#\\{\\!([\\w:]+)\\}#', $title_portion, $matches) != 0) { $title_portion = str_replace($matches[0], do_lang($matches[1]), $title_portion); } if (preg_match('#^[^<>\\[\\{\\&]*$#', $title_portion, $matches) != 0) { $title = $matches[0]; } elseif (!$low_memory) { $_title = comcode_to_tempcode($title_portion); $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'); $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())); } } $temp = do_template('BLOCK_MAIN_SITEMAP_NEST', array('_GUID' => '92e657f8b9a3642df053f54e724e66f6', 'URL' => $url, 'NAME' => $title, 'CHILDREN' => array())); $_pages[$title] = $temp->evaluate(); // FUDGEFUDGE } elseif (count($entrypoints) != 0) { foreach ($entrypoints as $entrypoint => $title) { if (($entrypoint == 'concede' || $entrypoint == 'invisible' || $entrypoint == 'logout') && is_guest()) { continue; } if ($entrypoint == '!') { $url = build_url(array('page' => $page), $zone, NULL, false, false, true); } else { $url = build_url(array('page' => $page, 'type' => $entrypoint), $zone, NULL, false, false, true); } $_entrypoints[$title] = do_template('BLOCK_MAIN_SITEMAP_NEST', array('_GUID' => 'ae2ed2549644a8e699e0938b3ab98ddb', 'URL' => $url, 'NAME' => do_lang_tempcode($title), 'CHILDREN' => array())); } //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) { $temp_keys = array_keys($_entrypoints); $temp = $_entrypoints[$temp_keys[0]]; } else { $temp = do_template('BLOCK_MAIN_SITEMAP_NEST', array('_GUID' => 'dfc5cc7db0301acd938d3b2e3fceaab8', 'URL' => new ocp_tempcode(), 'NAME' => $title, 'CHILDREN' => $_entrypoints)); } $_pages[$title] = $temp->evaluate(); // FUDGEFUDGE } } } $url = new ocp_tempcode(); if ($_pages != array()) { $keys = array_keys($_pages); $first = $_pages[$keys[0]]; ksort($_pages); $_pages = array($keys[0] => $first) + $_pages; } $temp = do_template('BLOCK_MAIN_SITEMAP_NEST', array('_GUID' => '38abb0a0e5bec968b28b4791320dd0dc', 'URL' => $url, 'NAME' => $zone_title, 'CHILDREN' => $_pages)); $_zones[] = $temp->evaluate(); // FUDGEFUDGE } } // To avoid running out of memory $out = do_template('BLOCK_MAIN_SITEMAP', array('_GUID' => 'd0807b30925e47d10cdb2c36231436ab', 'CHILDREN' => $_zones)); $e = $out->evaluate(); $explode = explode('__keep__', $e); // the URLs are build without keep and the templates tack it on the end if (strpos($e, '__keep__') !== false) { $out = new ocp_tempcode(); foreach ($explode as $i => $bit) { if ($i != 0) { $out->attach(symbol_tempcode('KEEP', NULL, array(ENTITY_ESCAPED))); } if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($bit); } $out->attach($bit); } } $e = $out->evaluate(); if (strpos($e, '__keep1__') !== false) { $explode = explode('__keep1__', $e); $out = new ocp_tempcode(); foreach ($explode as $i => $bit) { if ($i != 0) { $out->attach(symbol_tempcode('KEEP', array('1'), array(ENTITY_ESCAPED))); } if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($bit); } $out->attach($bit); } } return $out; }
/** * The actualiser to edit a zone (via zone editor). * * @return tempcode The UI */ function __editor() { $title = get_page_title('ZONE_EDITOR'); $lang = choose_language($title, true); if (is_object($lang)) { return $lang; } $id = get_param('id', ''); // Edit settings $_title = post_param('title'); $default_page = post_param('default_page'); $header_text = post_param('header_text'); $theme = post_param('theme'); $wide = post_param_integer('wide'); if ($wide == -1) { $wide = NULL; } $require_session = post_param_integer('require_session', 0); $displayed_in_menu = post_param_integer('displayed_in_menu', 0); actual_edit_zone($id, $_title, $default_page, $header_text, $theme, $wide, $require_session, $displayed_in_menu, $id); if ($id != '') { $this->set_permissions($id); } // Edit pages foreach (array('panel_left', 'start', 'panel_right') as $for) { $redirect = post_param('redirect_' . $for, NULL); if (!is_null($redirect)) { if (addon_installed('redirects_editor')) { $GLOBALS['SITE_DB']->query_delete('redirects', array('r_from_page' => $for, 'r_from_zone' => $id), '', 1); if ($redirect != $id) { $GLOBALS['SITE_DB']->query_insert('redirects', array('r_from_page' => $for, 'r_from_zone' => $id, 'r_to_page' => $for, 'r_to_zone' => $redirect, 'r_is_transparent' => 1), false, true); // Avoid problem when same key entered twice } else { $redirect = NULL; } } else { $redirect = NULL; } } $comcode = post_param($for, NULL); if (!is_null($comcode)) { // Where to save to $fullpath = zone_black_magic_filterer(get_custom_file_base() . ((is_null($redirect) ? $id : $redirect) == '' ? '' : '/') . (is_null($redirect) ? $id : $redirect) . '/pages/comcode_custom/' . $lang . '/' . $for . '.txt'); // Make dir if needed if (!file_exists(dirname($fullpath))) { if (@mkdir(dirname($fullpath), 0777) === false) { warn_exit(do_lang_tempcode('WRITE_ERROR_DIRECTORY_REPAIR', escape_html(basename(dirname($fullpath))), escape_html(dirname(dirname($fullpath))))); } fix_permissions(dirname($fullpath), 0777); sync_file(dirname($fullpath)); } // Store revision if (file_exists($fullpath) && get_option('store_revisions') == '1') { $time = time(); @copy($fullpath, $fullpath . '.' . strval($time)) or intelligent_write_error($fullpath . '.' . strval($time)); fix_permissions($fullpath . '.' . strval($time)); sync_file($fullpath . '.' . strval($time)); } // Save $myfile = @fopen($fullpath, 'wt') or intelligent_write_error($fullpath); if (fwrite($myfile, $comcode) < strlen($comcode)) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } fclose($myfile); fix_permissions($fullpath); sync_file($fullpath); // De-cache $caches = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index'), array('the_zone' => is_null($redirect) ? $id : $redirect, 'the_page' => $for)); foreach ($caches as $cache) { delete_lang($cache['string_index']); } $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => is_null($redirect) ? $id : $redirect, 'the_page' => $for)); } } persistant_cache_empty(); // Redirect $url = get_param('redirect'); return redirect_screen($title, $url, do_lang_tempcode('SUCCESS')); }
/** * Tell the user about any modules that need moving again (because the ocp ones haven't moved). * * @return array Pair: HTML list of moved files, raw list */ function move_modules() { $out = ''; $outr = array(); $zones = find_all_zones(); foreach ($zones as $zone) { $pages = find_all_pages($zone, 'modules'); foreach (array_keys($pages) as $page) { // See if this isn't the true home of the module foreach ($zones as $zone2) { $_path_a = $zone2 . '/pages/modules/' . $page . '.php'; // potential true home $_path_b = $zone . '/pages/modules/' . $page . '.php'; // where it is now $path_a = zone_black_magic_filterer(get_file_base() . '/' . $_path_a); $path_b = zone_black_magic_filterer(get_file_base() . '/' . $_path_b); if ($zone2 != $zone && file_exists($path_a) && filemtime($path_a) >= filemtime($path_b)) { if ($page == 'filedump' && $zone2 == 'cms') { continue; } // This has moved between versions $out .= '<li><input type="checkbox" name="' . uniqid('', true) . '" value="move:' . escape_html($_path_a . ':' . $_path_b) . '" /> ' . do_lang('FILE_MOVED', '<kbd>' . escape_html($page) . '</kbd>', '<kbd>' . escape_html($zone2) . '</kbd>', '<kbd>' . escape_html($zone) . '</kbd>') . '</li>'; $outr[] = $path_b; } } } } return array($out, $outr); }
/** * Get tempcode for a gallery adding/editing form. * * @param ID_TEXT The gallery codename * @param SHORT_TEXT The full human-readeable name of the gallery * @param LONG_TEXT The description of the gallery * @param SHORT_TEXT Teaser text for the gallery * @param LONG_TEXT Hidden notes associated with the gallery * @param ID_TEXT The parent gallery (blank: no parent) * @param BINARY Whether images may be put in this gallery * @param BINARY Whether videos may be put in this gallery * @param BINARY Whether the gallery serves as a container for automatically created member galleries * @param ?BINARY Whether the gallery uses the flow mode interface (NULL: pick statistically based on current usage of other galleries) * @param ?URLPATH The representative image of the gallery (NULL: none) * @param ?URLPATH Watermark (NULL: none) * @param ?URLPATH Watermark (NULL: none) * @param ?URLPATH Watermark (NULL: none) * @param ?URLPATH Watermark (NULL: none) * @param ?BINARY Whether rating is allowed (NULL: decide statistically, based on existing choices) * @param ?SHORT_INTEGER Whether comments are allowed (0=no, 1=yes, 2=review style) (NULL: decide statistically, based on existing choices) * @return array A pair: the tempcode for the visible fields, and the tempcode for the hidden fields */ function get_form_fields($name = '', $fullname = '', $description = '', $teaser = '', $notes = '', $parent_id = '', $accept_images = 1, $accept_videos = 1, $is_member_synched = 0, $flow_mode_interface = NULL, $rep_image = NULL, $watermark_top_left = NULL, $watermark_top_right = NULL, $watermark_bottom_left = NULL, $watermark_bottom_right = NULL, $allow_rating = NULL, $allow_comments = NULL) { list($allow_rating, $allow_comments, ) = $this->choose_feedback_fields_statistically($allow_rating, $allow_comments, 1); global $NON_CANONICAL_PARAMS; $NON_CANONICAL_PARAMS[] = 'cat'; $NON_CANONICAL_PARAMS[] = 'validated'; if (is_null($flow_mode_interface)) { $cnt = $GLOBALS['SITE_DB']->query_value('galleries', 'COUNT(*)'); if ($cnt < 5000) { $flow_mode_interface = intval(round($GLOBALS['SITE_DB']->query_value('galleries', 'AVG(flow_mode_interface)'))); // Determine default based on what is 'the norm' currently. Sometimes maths is beautiful :) } else { $flow_mode_interface = intval(round($GLOBALS['SITE_DB']->query_value('galleries', 'AVG(flow_mode_interface)', array('parent_id' => 'root')))); // Determine default based on what is 'the norm' currently. Sometimes maths is beautiful :) } } $fields = new ocp_tempcode(); require_code('form_templates'); $fields->attach(form_input_line(do_lang_tempcode('TITLE'), do_lang_tempcode('DESCRIPTION_TITLE'), 'fullname', $fullname, true)); if ($name != 'root') { $fields->attach(form_input_codename(do_lang_tempcode('CODENAME'), do_lang_tempcode('DESCRIPTION_CODENAME'), 'name', $name, true)); } $fields->attach(form_input_text_comcode(do_lang_tempcode('DESCRIPTION'), do_lang_tempcode('DESCRIPTION_DESCRIPTION'), 'description', $description, false)); if ($parent_id == '') { $parent_id = get_param('cat', ''); } if ($name != 'root') { $fields->attach(form_input_tree_list(do_lang_tempcode('PARENT'), do_lang_tempcode('DESCRIPTION_PARENT'), 'parent_id', NULL, 'choose_gallery', array('filter' => 'only_conventional_galleries', 'purity' => true, 'addable_filter' => true), true, $parent_id)); } $fields->attach(form_input_various_ticks(array(array(do_lang_tempcode('ACCEPT_IMAGES'), 'accept_images', $accept_images == 1, do_lang_tempcode('DESCRIPTION_ACCEPT_IMAGES')), array(do_lang_tempcode('ACCEPT_VIDEOS'), 'accept_videos', $accept_videos == 1, do_lang_tempcode('DESCRIPTION_ACCEPT_VIDEOS'))), new ocp_tempcode(), NULL, do_lang_tempcode('ACCEPTED_MEDIA_TYPES'))); $fields->attach(form_input_tick(do_lang_tempcode('FLOW_MODE_INTERFACE'), do_lang_tempcode('DESCRIPTION_FLOW_MODE_INTERFACE'), 'flow_mode_interface', $flow_mode_interface == 1)); $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => $rep_image == '' && $teaser == '' && $is_member_synched == 0, 'TITLE' => do_lang_tempcode('ADVANCED')))); $fields->attach(form_input_upload(do_lang_tempcode('REPRESENTATIVE_IMAGE'), do_lang_tempcode('DESCRIPTION_REPRESENTATIVE_IMAGE_GALLERY'), 'rep_image', false, $rep_image, NULL, true, str_replace(' ', '', get_option('valid_images')))); // Only show tease option if tease block being used $teaser_shows = false; $zones = find_all_zones(false, true); $pages = array(); foreach ($zones as $_zone) { $pages[$_zone[0]] = find_all_pages_wrap($_zone[0], true); } foreach ($pages as $zone => $under) { foreach ($under as $filename => $type) { if (substr(strtolower($filename), -4) == '.txt') { $matches = array(); $contents = file_get_contents(zone_black_magic_filterer((substr($type, 0, 15) == 'comcode_custom/' ? get_custom_file_base() : get_file_base()) . '/' . ($zone == '' ? '' : $zone . '/') . 'pages/' . $type . '/' . $filename)); $fallback = get_file_base() . '/' . ($zone == '' ? '' : $zone . '/') . 'pages/comcode/' . fallback_lang() . '/' . $filename; if (file_exists($fallback)) { $contents .= file_get_contents($fallback); } if (preg_match('#\\[block[^\\]]*\\]main_gallery_tease\\[/block\\]#', $contents, $matches) != 0) { $teaser_shows = true; } } } } if ($teaser_shows) { $fields->attach(form_input_line_comcode(do_lang_tempcode('TEASER'), do_lang_tempcode('DESCRIPTION_TEASER'), 'teaser', $teaser, false)); } $fields->attach(form_input_tick(do_lang_tempcode('IS_MEMBER_SYNCHED'), do_lang_tempcode('DESCRIPTION_IS_MEMBER_SYNCHED_GALLERY'), 'is_member_synched', $is_member_synched == 1)); $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => is_null($watermark_top_left) && is_null($watermark_top_right) && is_null($watermark_bottom_left) && is_null($watermark_bottom_right), 'TITLE' => do_lang_tempcode('WATERMARKING')))); $fields->attach(form_input_upload(do_lang_tempcode('_WATERMARK', do_lang_tempcode('TOP_LEFT')), do_lang_tempcode('_DESCRIPTION_WATERMARK', do_lang_tempcode('TOP_LEFT')), 'watermark_top_left', false, $watermark_top_left, NULL, true, str_replace(' ', '', get_option('valid_images')))); $fields->attach(form_input_upload(do_lang_tempcode('_WATERMARK', do_lang_tempcode('TOP_RIGHT')), do_lang_tempcode('_DESCRIPTION_WATERMARK', do_lang_tempcode('TOP_RIGHT')), 'watermark_top_right', false, $watermark_top_right, NULL, true, str_replace(' ', '', get_option('valid_images')))); $fields->attach(form_input_upload(do_lang_tempcode('_WATERMARK', do_lang_tempcode('BOTTOM_LEFT')), do_lang_tempcode('_DESCRIPTION_WATERMARK', do_lang_tempcode('BOTTOM_LEFT')), 'watermark_bottom_left', false, $watermark_bottom_left, NULL, true, str_replace(' ', '', get_option('valid_images')))); $fields->attach(form_input_upload(do_lang_tempcode('_WATERMARK', do_lang_tempcode('BOTTOM_RIGHT')), do_lang_tempcode('_DESCRIPTION_WATERMARK', do_lang_tempcode('BOTTOM_RIGHT')), 'watermark_bottom_right', false, $watermark_bottom_right, NULL, true, str_replace(' ', '', get_option('valid_images')))); $hidden = new ocp_tempcode(); handle_max_file_size($hidden, 'image'); require_code('feedback2'); $fields->attach(feedback_fields($allow_rating == 1, $allow_comments == 1, NULL, false, $notes, $allow_comments == 2, true)); // Permissions $fields->attach($this->get_permission_fields($name, NULL, $name == '')); return array($fields, $hidden); }
/** * Extract code to execute the requested functions with the requested parameters from the module requested. * * @param ID_TEXT The zone it is in * @param ID_TEXT The page name * @param array Array of functions to be executing * @param ?array A list of parameters to pass to our functions (NULL: none) * @return array A list of pieces of code to do the equivalent of executing the requested functions with the requested parameters */ function extract_module_functions_page($zone, $page, $functions, $params = NULL) { $path = zone_black_magic_filterer(get_file_base() . '/' . filter_naughty_harsh($zone) . ($zone == '' ? '' : '/') . 'pages/modules_custom/' . filter_naughty_harsh($page) . '.php'); if (file_exists($path)) { $ret = extract_module_functions($path, $functions, $params); if (array_unique(array_values($ret)) != array(NULL)) { return $ret; } } $path = zone_black_magic_filterer(get_file_base() . '/' . filter_naughty_harsh($zone) . ($zone == '' ? '' : '/') . 'pages/modules/' . filter_naughty_harsh($page) . '.php'); if (!file_exists($path)) { $ret = array(); for ($i = 0; $i < count($functions); $i++) { array_push($ret, NULL); } return $ret; } return extract_module_functions($path, $functions, $params); }
/** * Get the path to a module known to be in a certain zone. * * @param ID_TEXT The zone name * @param ID_TEXT The module name * @return PATH The module path */ function _get_module_path($zone, $module) { $module_path = zone_black_magic_filterer($zone == '' ? 'pages/modules_custom/' . filter_naughty_harsh($module) . '.php' : filter_naughty($zone) . '/pages/modules_custom/' . filter_naughty_harsh($module) . '.php', true); if (in_safe_mode() || !is_file(get_file_base() . '/' . $module_path)) { $module_path = zone_black_magic_filterer($zone == '' ? 'pages/modules/' . filter_naughty_harsh($module) . '.php' : filter_naughty($zone) . '/pages/modules/' . filter_naughty_harsh($module) . '.php', true); } return $module_path; }
/** * The UI to manage the modules (or blocks). * * @return tempcode The UI */ function modules_view() { $title = get_page_title('MODULE_MANAGEMENT'); $zone = get_param('id'); $tpl_modules = new ocp_tempcode(); require_code('templates_table_table'); require_code('zones2'); if ($zone != '_block') { $module_rows = list_to_map('module_the_name', $GLOBALS['SITE_DB']->query_select('modules', array('*'))); } else { $module_rows = list_to_map('block_name', $GLOBALS['SITE_DB']->query_select('blocks', array('*'))); } if ($zone == '_block') { require_code('zones3'); $modules = find_all_blocks(); } else { $modules = find_all_modules($zone); } ksort($modules); foreach ($modules as $module => $type) { if ($zone != '_block') { $module_path = zone_black_magic_filterer($zone == '' ? 'pages/' . $type . '/' . filter_naughty_harsh($module) . '.php' : $zone . '/pages/' . $type . '/' . filter_naughty_harsh($module) . '.php', true); $prefix = 'module'; } else { $module_path = $type . '/blocks/' . filter_naughty_harsh($module) . '.php'; $prefix = 'block'; } $info = extract_module_info(get_file_base() . '/' . $module_path); if (is_null($info)) { continue; } if (get_param_integer('keep_module_dangerous', 0) == 1) { $info['locked'] = false; } $author = $info['author']; $organisation = $info['organisation']; $version = $info['version']; $hacked_by = $info['hacked_by']; $hack_version = $info['hack_version']; $actions = new ocp_tempcode(); $status = new ocp_tempcode(); if (array_key_exists($module, $module_rows)) { $row = $module_rows[$module]; if (!$info['locked']) { $hidden = new ocp_tempcode(); $hidden->attach(form_input_hidden('zone', $zone)); $hidden->attach(form_input_hidden('module', $module)); $actions->attach(do_template('TABLE_TABLE_ACTION_DELETE_ENTRY', array('_GUID' => '331afd26f5e62a6a4cdc4e2c520a4114', 'HIDDEN' => $hidden, 'NAME' => $module, 'URL' => build_url(array('page' => '_SELF', 'type' => 'uninstall'), '_SELF')))); } if ($row[$prefix . '_version'] < $version) { $status = do_lang_tempcode('STATUS_TO_UPGRADE'); $hidden = new ocp_tempcode(); $hidden->attach(form_input_hidden('zone', $zone)); $hidden->attach(form_input_hidden('module', $module)); $actions->attach(do_template('TABLE_TABLE_ACTION_UPGRADE_ENTRY', array('_GUID' => 'e5d012cb8c839e0e869f1edfa008dacd', 'HIDDEN' => $hidden, 'NAME' => $module, 'URL' => build_url(array('page' => '_SELF', 'type' => 'upgrade'), '_SELF')))); } elseif (!is_null($hack_version) && $row[$prefix . '_hack_version'] < $hack_version) { $status = do_lang_tempcode('STATUS_TO_HACK'); $hidden = new ocp_tempcode(); $hidden->attach(form_input_hidden('zone', $zone)); $hidden->attach(form_input_hidden('module', $module)); $actions->attach(do_template('TABLE_TABLE_ACTION_UPGRADE_ENTRY', array('_GUID' => '42c4473bf31dfd329e921e443ccc2ec3', 'HIDDEN' => $hidden, 'NAME' => $module, 'URL' => build_url(array('page' => '_SELF', 'type' => 'upgrade'), '_SELF')))); } else { $status = do_lang_tempcode('STATUS_CURRENT'); } if (!$info['locked']) { $hidden = new ocp_tempcode(); $hidden->attach(form_input_hidden('zone', $zone)); $hidden->attach(form_input_hidden('module', $module)); $actions->attach(do_template('TABLE_TABLE_ACTION_REINSTALL_ENTRY', array('_GUID' => 'c2d820af4b9a2f8633f6f5a4e3de76bc', 'HIDDEN' => $hidden, 'NAME' => $module, 'URL' => build_url(array('page' => '_SELF', 'type' => 'reinstall'), '_SELF')))); } } else { $hidden = new ocp_tempcode(); $hidden->attach(form_input_hidden('zone', $zone)); $hidden->attach(form_input_hidden('module', $module)); $actions->attach(do_template('TABLE_TABLE_ACTION_INSTALL_ENTRY', array('_GUID' => '6b438e07cfe154afc21439479fd76978', 'HIDDEN' => $hidden, 'NAME' => $module, 'URL' => build_url(array('page' => '_SELF', 'type' => 'reinstall'), '_SELF')))); } if (is_null($hacked_by)) { $hacked_by = do_lang_tempcode('NA_EM'); } if (is_null($hack_version)) { $hack_version = do_lang_tempcode('NA_EM'); } $tpl_modules->attach(do_template('MODULE_SCREEN_MODULE', array('_GUID' => 'cf19adfd129c44a7ef1d6789002c6535', 'STATUS' => $status, 'NAME' => $module, 'AUTHOR' => $author, 'ORGANISATION' => $organisation, 'VERSION' => strval($version), 'HACKED_BY' => $hacked_by, 'HACK_VERSION' => $hack_version, 'ACTIONS' => $actions))); } breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('ADDONS')), array('_SELF:_SELF:modules', do_lang_tempcode('MODULE_MANAGEMENT')))); return do_template('MODULE_SCREEN', array('_GUID' => '132b23107b49a23e0b11db862de1dd56', 'TITLE' => $title, 'MODULES' => $tpl_modules)); }
/** * Shows an HTML page for making block Comcode. */ function block_helper_script() { require_lang('comcode'); require_lang('blocks'); require_code('zones2'); require_code('zones3'); check_specific_permission('comcode_dangerous'); $title = get_page_title('BLOCK_HELPER'); require_code('form_templates'); require_all_lang(); $type_wanted = get_param('block_type', 'main'); $type = get_param('type', 'step1'); $content = new ocp_tempcode(); if ($type == 'step1') { // Find what addons all our block files are in, and icons if possible $hooks = find_all_hooks('systems', 'addon_registry'); $hook_keys = array_keys($hooks); $hook_files = array(); foreach ($hook_keys as $hook) { $path = get_file_base() . '/sources_custom/hooks/systems/addon_registry/' . filter_naughty_harsh($hook) . '.php'; if (!file_exists($path)) { $path = get_file_base() . '/sources/hooks/systems/addon_registry/' . filter_naughty_harsh($hook) . '.php'; } $hook_files[$hook] = file_get_contents($path); } unset($hook_keys); $addon_icons = array(); $addons_blocks = array(); foreach ($hook_files as $addon_name => $hook_file) { $matches = array(); if (preg_match('#function get_file_list\\(\\)\\s*\\{([^\\}]*)\\}#', $hook_file, $matches) != 0) { if (!defined('HIPHOP_PHP')) { $addon_files = eval($matches[1]); } else { require_code('hooks/systems/addon_registry/' . $addon_name); $hook_ob = object_factory('Hook_addon_registry_' . $addon_name); $addon_files = $hook_ob->get_file_list(); } foreach ($addon_files as $file) { if (substr($file, 0, 31) == 'themes/default/images/bigicons/' && !array_key_exists($addon_name, $addon_icons)) { $addon_icons[$addon_name] = find_theme_image('bigicons/' . basename($file, '.png'), false, true); } if (substr($file, 0, 21) == 'sources_custom/blocks/' || substr($file, 0, 15) == 'sources/blocks/') { if ($addon_name == 'staff_messaging') { $addon_name = 'core_feedback_features'; } $addons_blocks[basename($file, '.php')] = $addon_name; } } } } // Find where blocks have been used $block_usage = array(); $zones = find_all_zones(false, true); foreach ($zones as $_zone) { $zone = $_zone[0]; $pages = find_all_pages_wrap($zone, true); foreach ($pages as $filename => $type) { if (substr(strtolower($filename), -4) == '.txt') { $matches = array(); $contents = file_get_contents(zone_black_magic_filterer((substr($type, 0, 15) == 'comcode_custom/' ? get_custom_file_base() : get_file_base()) . '/' . ($zone == '' ? '' : $zone . '/') . 'pages/' . $type . '/' . $filename)); //$fallback=get_file_base().'/'.(($zone=='')?'':($zone.'/')).'pages/comcode/'.fallback_lang().'/'.$filename; //if (file_exists($fallback)) $contents.=file_get_contents($fallback); $num_matches = preg_match_all('#\\[block[^\\]]*\\](.*)\\[/block\\]#U', $contents, $matches); for ($i = 0; $i < $num_matches; $i++) { $block_used = $matches[1][$i]; if (!array_key_exists($block_used, $block_usage)) { $block_usage[$block_used] = array(); } $block_usage[$block_used][] = $zone . ':' . basename($filename, '.txt'); } } } } // Show block list $links = new ocp_tempcode(); $blocks = find_all_blocks(); $dh = @opendir(get_file_base() . '/sources_custom/miniblocks'); if ($dh !== false) { while (($file = readdir($dh)) !== false) { if (substr($file, -4) == '.php' && preg_match('#^[\\w\\-]*$#', substr($file, 0, strlen($file) - 4)) != 0) { $blocks[substr($file, 0, strlen($file) - 4)] = 'sources_custom'; } } closedir($dh); } $block_types = array(); $block_types_icon = array(); $keep = symbol_tempcode('KEEP'); foreach (array_keys($blocks) as $block) { if (array_key_exists($block, $addons_blocks)) { $addon_name = $addons_blocks[$block]; $addon_icon = array_key_exists($addon_name, $addon_icons) ? $addon_icons[$addon_name] : NULL; $addon_name = preg_replace('#^core\\_#', '', $addon_name); } else { $addon_name = NULL; $addon_icon = NULL; } $this_block_type = is_null($addon_name) || strpos($addon_name, 'block') !== false || $addon_name == 'core' ? substr($block, 0, strpos($block, '_') === false ? strlen($block) : strpos($block, '_')) : $addon_name; if (!array_key_exists($this_block_type, $block_types)) { $block_types[$this_block_type] = new ocp_tempcode(); } if (!is_null($addon_icon)) { $block_types_icon[$this_block_type] = $addon_icon; } $block_description = do_lang('BLOCK_' . $block . '_DESCRIPTION', NULL, NULL, NULL, NULL, false); $block_use = do_lang('BLOCK_' . $block . '_USE', NULL, NULL, NULL, NULL, false); if (is_null($block_description)) { $block_description = ''; } if (is_null($block_use)) { $block_use = ''; } $descriptiont = $block_description == '' && $block_use == '' ? new ocp_tempcode() : do_lang_tempcode('BLOCK_HELPER_1X', $block_description, $block_use); $url = find_script('block_helper') . '?type=step2&block=' . urlencode($block) . '&field_name=' . get_param('field_name') . $keep->evaluate(); if (get_param('utheme', '') != '') { $url .= '&utheme=' . get_param('utheme'); } $url .= '&block_type=' . $type_wanted; $link_caption = do_lang_tempcode('NICE_BLOCK_NAME', escape_html(cleanup_block_name($block)), $block); $usage = array_key_exists($block, $block_usage) ? $block_usage[$block] : array(); $block_types[$this_block_type]->attach(do_template('BLOCK_HELPER_BLOCK_CHOICE', array('USAGE' => $usage, 'DESCRIPTION' => $descriptiont, 'URL' => $url, 'LINK_CAPTION' => $link_caption))); } /*if (array_key_exists($type_wanted,$block_types)) We don't do this now, as we structure by addon name { $x=$block_types[$type_wanted]; unset($block_types[$type_wanted]); $block_types=array_merge(array($type_wanted=>$x),$block_types); }*/ ksort($block_types); // We sort now instead $move_after = $block_types['adminzone_frontpage']; unset($block_types['adminzone_frontpage']); $block_types['adminzone_frontpage'] = $move_after; foreach ($block_types as $block_type => $_links) { switch ($block_type) { case 'side': case 'main': case 'bottom': $type_title = do_lang_tempcode('BLOCKS_TYPE_' . $block_type); $img = NULL; break; default: $type_title = do_lang_tempcode('BLOCKS_TYPE_ADDON', escape_html(cleanup_block_name($block_type))); $img = array_key_exists($block_type, $block_types_icon) ? $block_types_icon[$block_type] : NULL; break; } $links->attach(do_template('BLOCK_HELPER_BLOCK_GROUP', array('IMG' => $img, 'TITLE' => $type_title, 'LINKS' => $_links))); } $content = do_template('BLOCK_HELPER_START', array('_GUID' => 'd2d6837cdd8b19d80ea95ab9f5d09c9a', 'GET' => true, 'TITLE' => $title, 'LINKS' => $links)); } elseif ($type == 'step2') { require_code('comcode_text'); $defaults = parse_single_comcode_tag(get_param('parse_defaults', '', true), 'block'); $block = trim(get_param('block')); $title = get_page_title('_BLOCK_HELPER', true, array(escape_html($block))); $fields = new ocp_tempcode(); $parameters = get_block_parameters($block); $parameters[] = 'failsafe'; $parameters[] = 'cache'; $parameters[] = 'quick_cache'; if (!isset($defaults['cache'])) { $defaults['cache'] = block_cache_default($block); } if (is_null($parameters)) { $parameters = array(); } $advanced_ind = do_lang('BLOCK_IND_ADVANCED'); $param_classes = array('normal' => array(), 'advanced' => array()); foreach ($parameters as $parameter) { $param_class = 'normal'; if ($parameter == 'cache' || $parameter == 'quick_cache' || $parameter == 'failsafe' || strpos(do_lang('BLOCK_' . $block . '_PARAM_' . $parameter), $advanced_ind) !== false) { $param_class = 'advanced'; } $param_classes[$param_class][] = $parameter; } foreach ($param_classes as $param_class => $parameters) { if (count($parameters) == 0) { if ($param_class == 'normal') { $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => false, 'TITLE' => do_lang_tempcode('PARAMETERS'), 'HELP' => protect_from_escaping(paragraph(do_lang_tempcode('BLOCK_HELPER_NO_PARAMETERS'), '', 'nothing_here'))))); } continue; } if ($param_class == 'advanced') { $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => true, 'TITLE' => do_lang_tempcode('ADVANCED')))); } foreach ($parameters as $parameter) { $matches = array(); switch ($parameter) { case 'quick_cache': case 'cache': case 'failsafe': $description = do_lang('BLOCK_PARAM_' . $parameter); break; default: $description = do_lang('BLOCK_' . $block . '_PARAM_' . $parameter); break; } $description = str_replace(do_lang('BLOCK_IND_STRIPPABLE_1'), '', $description); $description = trim(str_replace(do_lang('BLOCK_IND_ADVANCED'), '', $description)); // Work out default value for field $default = ''; if (preg_match('#' . do_lang('BLOCK_IND_DEFAULT') . ': ["\']([^"]*)["\']#Ui', $description, $matches) != 0) { $default = $matches[1]; $has_default = true; $description = preg_replace('#\\s*' . do_lang('BLOCK_IND_DEFAULT') . ': ["\']([^"]*)["\'](?-U)\\.?(?U)#Ui', '', $description); } else { $has_default = false; } if (isset($defaults[$parameter])) { $default = $defaults[$parameter]; $has_default = true; } // Show field if ($block . ':' . $parameter == 'side_stored_menu:type') { $matches = array(); $dh = opendir(get_file_base() . '/themes/default/templates/'); $options = array(); while (($file = readdir($dh)) !== false) { if (preg_match('^MENU\\_([a-z]+)\\.tpl$^', $file, $matches) != 0) { $options[] = $matches[1]; } } closedir($dh); $dh = opendir(get_custom_file_base() . '/themes/default/templates_custom/'); while (($file = readdir($dh)) !== false) { if (preg_match('^MENU\\_([a-z]+)\\.tpl$^', $file, $matches) != 0 && !file_exists(get_file_base() . '/themes/default/templates/' . $file)) { $options[] = $matches[1]; } } closedir($dh); sort($options); $list = new ocp_tempcode(); foreach ($options as $option) { $list->attach(form_input_list_entry($option, $has_default && $option == $default)); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($block . ':' . $parameter == 'side_stored_menu:param') { $list = new ocp_tempcode(); $rows = $GLOBALS['SITE_DB']->query_select('menu_items', array('DISTINCT i_menu'), NULL, 'ORDER BY i_menu'); foreach ($rows as $row) { $list->attach(form_input_list_entry($row['i_menu'], $has_default && $row['i_menu'] == $default)); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($block . ':' . $parameter == 'side_shoutbox:param') { $list = new ocp_tempcode(); $rows = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('id', 'room_name'), array('is_im' => 0), '', 100); foreach ($rows as $row) { $list->attach(form_input_list_entry(strval($row['id']), $has_default && strval($row['id']) == $default, $row['room_name'])); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($block . ':' . $parameter == 'main_poll:param') { $list = new ocp_tempcode(); $rows = $GLOBALS['SITE_DB']->query_select('poll', array('id', 'question'), NULL, 'ORDER BY id DESC', 100); $list->attach(form_input_list_entry('', false, do_lang('NA'))); foreach ($rows as $row) { $list->attach(form_input_list_entry(strval($row['id']), $has_default && strval($row['id']) == $default, get_translated_text($row['question']))); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($block . ':' . $parameter == 'main_awards:param') { $list = new ocp_tempcode(); $rows = $GLOBALS['SITE_DB']->query_select('award_types', array('id', 'a_title')); foreach ($rows as $row) { $list->attach(form_input_list_entry(strval($row['id']), $has_default && strval($row['id']) == $default, get_translated_text($row['a_title']))); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($parameter == 'zone' || $parameter == 'param' && $block == 'main_as_zone_access') { $list = new ocp_tempcode(); $list->attach(form_input_list_entry('_SEARCH', $default == '')); $list->attach(nice_get_zones($default == '' ? NULL : $default)); $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif (($parameter == 'forum' || $parameter == 'param' && in_array($block, array('main_forum_topics'))) && get_forum_type() == 'ocf') { require_code('ocf_forums'); require_code('ocf_forums2'); if (!addon_installed('ocf_forum')) { warn_exit(do_lang_tempcode('NO_FORUM_INSTALLED')); } $list = ocf_get_forum_tree_secure(NULL, NULL, true, explode(',', $default)); $fields->attach(form_input_multi_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list)); } elseif ($parameter == 'param' && in_array($block, array('side_root_galleries', 'main_gallery_tease', 'main_gallery_embed', 'main_image_fader'))) { require_code('galleries'); $list = nice_get_gallery_tree($default); $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($parameter == 'param' && in_array($block, array('main_download_category'))) { require_code('downloads'); $list = nice_get_download_category_tree($default == '' ? NULL : intval($default)); $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($parameter == 'param' && in_array($block, array('main_contact_catalogues')) || $parameter == 'catalogue' && in_array($block, array('main_recent_cc_entries'))) { require_code('catalogues'); $list = nice_get_catalogues($default, false); $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($parameter == 'param' && in_array($block, array('main_cc_embed')) && $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'COUNT(*)') < 500) { $list = new ocp_tempcode(); $categories = $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('id', 'cc_title', 'c_name'), NULL, 'ORDER BY c_name,id'); $last_cat = mixed(); foreach ($categories as $cat) { if (is_null($last_cat) || $cat['c_name'] != $last_cat) { $list->attach(form_input_list_entry($cat['c_name'], $has_default && $cat['c_name'] == $default, $cat['c_name'], false, true)); $last_cat = $cat['c_name']; } $list->attach(form_input_list_entry(strval($cat['id']), $has_default && strval($cat['id']) == $default, get_translated_text($cat['cc_title']))); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($parameter == 'param' && in_array($block, array('main_banner_wave', 'main_topsites'))) { require_code('banners'); $list = nice_get_banner_types($default); $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($parameter == 'param' && in_array($block, array('main_newsletter_signup'))) { $list = new ocp_tempcode(); $rows = $GLOBALS['SITE_DB']->query_select('newsletters', array('id', 'title')); foreach ($rows as $newsletter) { $list->attach(form_input_list_entry(strval($newsletter['id']), $has_default && strval($newsletter['id']) == $default, get_translated_text($newsletter['title']))); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($parameter == 'filter' && in_array($block, array('bottom_news', 'main_news', 'side_news', 'side_news_archive'))) { require_code('news'); $list = nice_get_news_categories($default == '' ? -1 : intval($default)); $fields->attach(form_input_multi_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list)); } elseif ($parameter == 'font') { $fonts = array(); $dh = opendir(get_file_base() . '/data/fonts'); while ($f = readdir($dh)) { if (substr($f, -4) == '.ttf') { $fonts[] = substr($f, 0, strlen($f) - 4); } } closedir($dh); $dh = opendir(get_custom_file_base() . '/data_custom/fonts'); while ($f = readdir($dh)) { if (substr($f, -4) == '.ttf') { $fonts[] = substr($f, 0, strlen($f) - 4); } } closedir($dh); $fonts = array_unique($fonts); sort($fonts); $list = new ocp_tempcode(); foreach ($fonts as $font) { $list->attach(form_input_list_entry($font, $font == $default)); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif (preg_match('#' . do_lang('BLOCK_IND_EITHER') . ' (.+)#i', $description, $matches) != 0) { $description = preg_replace('# \\(' . do_lang('BLOCK_IND_EITHER') . '.*\\)#U', '', $description); $list = new ocp_tempcode(); $matches2 = array(); $num_matches = preg_match_all('#\'([^\']*)\'="([^"]*)"#', $matches[1], $matches2); if ($num_matches != 0) { for ($i = 0; $i < $num_matches; $i++) { $list->attach(form_input_list_entry($matches2[1][$i], $matches2[1][$i] == $default, $matches2[2][$i])); } } else { $num_matches = preg_match_all('#\'([^\']*)\'#', $matches[1], $matches2); for ($i = 0; $i < $num_matches; $i++) { $list->attach(form_input_list_entry($matches2[1][$i], $matches2[1][$i] == $default)); } } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif (preg_match('#\\(' . do_lang('BLOCK_IND_HOOKTYPE') . ': \'([^\'/]*)/([^\'/]*)\'\\)#i', $description, $matches) != 0) { $description = preg_replace('#\\s*\\(' . do_lang('BLOCK_IND_HOOKTYPE') . ': \'([^\'/]*)/([^\'/]*)\'\\)#i', '', $description); $list = new ocp_tempcode(); $hooks = find_all_hooks($matches[1], $matches[2]); ksort($hooks); if ($default == '' && $has_default) { $list->attach(form_input_list_entry('', true)); } foreach (array_keys($hooks) as $hook) { if ($block == 'side_tag_cloud') { if (substr($hook, -1) == 'y') { $hook .= ',' . substr($hook, 0, strlen($hook) - 1) . 'ies'; } elseif (substr($hook, -1) != 's' && $hook != 'quiz') { $hook .= ',' . $hook . 's'; } } $list->attach(form_input_list_entry($hook, $hook == $default)); } if ($block == 'main_search' && $parameter == 'limit_to' || $block == 'side_tag_cloud') { $fields->attach(form_input_multi_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, 0)); } else { $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } } elseif (($default == '0' || $default == '1' || strpos($description, '\'0\'') !== false || strpos($description, '\'1\'') !== false) && do_lang('BLOCK_IND_WHETHER') != '' && strpos(strtolower($description), do_lang('BLOCK_IND_WHETHER')) !== false) { $fields->attach(form_input_tick(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $default == '1')); } elseif (do_lang('BLOCK_IND_NUMERIC') != '' && strpos($description, do_lang('BLOCK_IND_NUMERIC')) !== false) { $fields->attach(form_input_integer(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $default == '' ? NULL : intval($default), false)); } else { $fields->attach(form_input_line(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $default, false)); } } } $keep = symbol_tempcode('KEEP'); $post_url = find_script('block_helper') . '?type=step3&field_name=' . get_param('field_name') . $keep->evaluate(); if (get_param('utheme', '') != '') { $post_url .= '&utheme=' . get_param('utheme'); } $post_url .= '&block_type=' . $type_wanted; if (get_param('save_to_id', '') != '') { $post_url .= '&save_to_id=' . urlencode(get_param('save_to_id')); $submit_name = do_lang_tempcode('SAVE'); // Allow remove option $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => false, 'TITLE' => do_lang_tempcode('ACTIONS'), 'HELP' => ''))); $fields->attach(form_input_tick(do_lang_tempcode('REMOVE'), '', '_delete', false)); } else { $submit_name = do_lang_tempcode('USE'); } $block_description = do_lang('BLOCK_' . $block . '_DESCRIPTION', NULL, NULL, NULL, NULL, false); if (is_null($block_description)) { $block_description = ''; } $block_use = do_lang('BLOCK_' . $block . '_USE', NULL, NULL, NULL, NULL, false); if (is_null($block_use)) { $block_use = ''; } if ($block_description == '' && $block_use == '') { $text = new ocp_tempcode(); } else { $text = do_lang_tempcode('BLOCK_HELPER_2', escape_html(cleanup_block_name($block)), escape_html($block_description), escape_html($block_use)); } $hidden = form_input_hidden('block', $block); $content = do_template('FORM_SCREEN', array('_GUID' => '270058349d048a8be6570bba97c81fa2', 'TITLE' => $title, 'TARGET' => '_self', 'SKIP_VALIDATION' => true, 'FIELDS' => $fields, 'URL' => $post_url, 'TEXT' => $text, 'SUBMIT_NAME' => $submit_name, 'HIDDEN' => $hidden, 'PREVIEW' => true, 'THEME' => $GLOBALS['FORUM_DRIVER']->get_theme())); if ($fields->is_empty()) { $type = 'step3'; } } if ($type == 'step3') { require_javascript('javascript_posting'); require_javascript('javascript_editing'); $field_name = get_param('field_name'); $bparameters = ''; $bparameters_xml = ''; $bparameters_tempcode = ''; $block = trim(either_param('block')); $parameters = get_block_parameters($block); $parameters[] = 'failsafe'; $parameters[] = 'cache'; $parameters[] = 'quick_cache'; if (in_array('param', $parameters)) { $_parameters = array('param'); unset($parameters[array_search('param', $parameters)]); $parameters = array_merge($_parameters, $parameters); } foreach ($parameters as $parameter) { $value = post_param($parameter, NULL); if (is_null($value)) { if (post_param_integer('tick_on_form__' . $parameter, NULL) === NULL) { continue; } // If not on form, continue, otherwise must be 0 $value = '0'; } if ($value != '' && ($parameter != 'failsafe' || $value == '1') && ($parameter != 'cache' || $value != block_cache_default($block)) && ($parameter != 'quick_cache' || $value == '1')) { if ($parameter == 'param') { $bparameters .= '="' . str_replace('"', '\\"', $value) . '"'; } else { $bparameters .= ' ' . $parameter . '="' . str_replace('"', '\\"', $value) . '"'; } $bparameters_xml = '<blockParam key="' . escape_html($parameter) . '" val="' . escape_html($value) . '" />'; $bparameters_tempcode .= ',' . $parameter . '=' . str_replace(',', '\\,', $value); } } $comcode = '[block' . $bparameters . ']' . $block . '[/block]'; $comcode_xml = '<block>' . $bparameters_xml . $block . '</block>'; $tempcode = '{$BLOCK,block=' . $block . $bparameters_tempcode . '}'; if ($type_wanted == 'template') { $comcode = $tempcode; } // This is what will be written in $comcode_semihtml = comcode_to_tempcode($comcode, NULL, false, 60, NULL, NULL, true, false, false); $content = do_template('BLOCK_HELPER_DONE', array('_GUID' => '575d6c8120d6001c8156560be518f296', 'TITLE' => $title, 'FIELD_NAME' => $field_name, 'BLOCK' => $block, 'COMCODE_XML' => $comcode_xml, 'COMCODE' => $comcode, 'COMCODE_SEMIHTML' => $comcode_semihtml)); } global $EXTRA_HEAD; if (!isset($EXTRA_HEAD)) { $EXTRA_HEAD = new ocp_tempcode(); } $EXTRA_HEAD->attach('<meta name="robots" content="noindex" />'); // XHTMLXHTML $echo = do_template('POPUP_HTML_WRAP', array('TITLE' => do_lang_tempcode('BLOCK_HELPER'), 'CONTENT' => $content)); $echo->handle_symbol_preprocessing(); $echo->evaluate_echo(); }
/** * The actualiser to move a page. * * @return tempcode The UI */ function _move() { $title = get_page_title('MOVE_PAGES'); if (get_file_base() != get_custom_file_base()) { warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT')); } $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/move'; $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_structure'; $zone = post_param('zone', NULL); if (is_null($zone)) { $post_url = build_url(array('page' => '_SELF', 'type' => get_param('type')), '_SELF', NULL, true); $hidden = build_keep_form_fields('', true); return do_template('YESNO_SCREEN', array('_GUID' => 'c6e872cc62bdc7cf1c5157fbfdb2dfd6', 'TITLE' => $title, 'TEXT' => do_lang_tempcode('Q_SURE'), 'URL' => $post_url, 'HIDDEN' => $hidden)); } $new_zone = post_param('destination_zone', ''); if (substr($new_zone, -1) == ':') { $new_zone = substr($new_zone, 0, strlen($new_zone) - 1); } //$pages=find_all_pages_wrap($zone); $pages = array(); require_code('site'); foreach ($_POST as $key => $val) { if (substr($key, 0, 6) == 'page__' && $val === '1') { $page = substr($key, 6); $page_details = _request_page($page, $zone, NULL, NULL, true); if ($page_details === false) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $pages[$page] = strtolower($page_details[0]); if (array_key_exists(3, $page_details)) { $pages[$page] .= '/' . $page_details[3]; } } } $afm_needed = false; foreach ($pages as $page => $type) { if (post_param_integer('page__' . $page, 0) == 1) { if ($type != 'comcode_custom') { $afm_needed = true; } } } if ($afm_needed) { require_code('abstract_file_manager'); force_have_afm_details(); } $cannot_move = new ocp_tempcode(); foreach ($pages as $page => $type) { if (!is_string($page)) { $page = strval($page); } if (post_param_integer('page__' . $page, 0) == 1) { if (substr($type, 0, 7) == 'modules') { $_page = $page . '.php'; } elseif (substr($type, 0, 7) == 'comcode') { $_page = $page . '.txt'; } elseif (substr($type, 0, 4) == 'html') { $_page = $page . '.htm'; } if (file_exists(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page))) { if (!$cannot_move->is_empty()) { $cannot_move->attach(do_lang_tempcode('LIST_SEP')); } $cannot_move->attach(do_lang_tempcode('PAGE_WRITE', escape_html($page))); continue; } } } $moved_something = NULL; foreach ($pages as $page => $type) { if (!is_string($page)) { $page = strval($page); } if (post_param_integer('page__' . $page, 0) == 1) { $moved_something = $page; if (substr($type, 0, 7) == 'modules') { $_page = $page . '.php'; } elseif (substr($type, 0, 7) == 'comcode') { $_page = $page . '.txt'; } elseif (substr($type, 0, 4) == 'html') { $_page = $page . '.htm'; } if (file_exists(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page))) { continue; } if (file_exists(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page))) { if ($afm_needed) { afm_move(zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page, true), zone_black_magic_filterer(filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page, true)); } else { rename(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page), zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page)); } } // If a non-overridden one is there too, need to move that too if (strpos($type, '_custom') !== false && file_exists(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page)) && !file_exists(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page))) { if ($afm_needed) { afm_move(zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page, true), zone_black_magic_filterer(filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page, true)); } else { rename(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page), zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page)); } } log_it('MOVE_PAGES', $page); } } if (is_null($moved_something)) { warn_exit(do_lang_tempcode('NOTHING_SELECTED')); } persistant_cache_empty(); require_lang('addons'); if ($cannot_move->is_empty()) { $message = do_lang_tempcode('SUCCESS'); } else { $message = do_lang_tempcode('WOULD_NOT_OVERWRITE_BUT_SUCCESS', $cannot_move); } breadcrumb_set_self(do_lang_tempcode('DONE')); breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('PAGES')), array('_SELF:_SELF:move', do_lang_tempcode('MOVE_PAGES')))); decache('main_sitemap'); if (has_js()) { return inform_screen($title, $message); // Came from site-tree editor, so want to just close this window when done } return $this->do_next_manager($title, $moved_something, $new_zone, new ocp_tempcode()); }
/** * The UI to set privileges. * * @return tempcode The UI */ function interface_specific_permissions() { require_all_lang(); require_code('zones2'); $title = get_page_title('SPECIFIC_PERMISSIONS'); $p_section = get_param('id', NULL); if (is_null($p_section) || $p_section == '') { $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/privileges'; $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_permissions'; $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/privileges'; $fields = new ocp_tempcode(); require_code('form_templates'); $_sections = $this->_get_ordered_sections(); $sections = new ocp_tempcode(); foreach ($_sections as $s) { if (is_null($s)) { $sections->attach(form_input_list_entry('', false, '', false, true)); } else { if (!is_null($s['trans'])) { $sections->attach(form_input_list_entry($s['p_section'], false, $s['trans'])); } } } $fields->attach(form_input_list(do_lang_tempcode('SECTION'), '', 'id', $sections, NULL, true)); $post_url = get_self_url(false, false, NULL, false, true); return do_template('FORM_SCREEN', array('_GUID' => 'e5d457a49a76706afebc92da3d846e74', 'GET' => true, 'SKIP_VALIDATION' => true, 'HIDDEN' => '', 'SUBMIT_NAME' => do_lang_tempcode('CHOOSE'), 'TITLE' => $title, 'FIELDS' => $fields, 'URL' => $post_url, 'TEXT' => '')); } $title = get_page_title('_SPECIFIC_PERMISSIONS', true, array(do_lang_tempcode($p_section))); $url = build_url(array('page' => '_SELF', 'type' => '_specific', 'id' => $p_section), '_SELF'); $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups(); $moderator_groups = $GLOBALS['FORUM_DRIVER']->get_moderator_groups(); $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true); $header_cells = $this->_access_header($admin_groups, $groups); $cols = new ocp_tempcode(); foreach ($groups as $id => $g_name) { if (in_array($id, $admin_groups)) { continue; } $cols->attach(do_template('PERMISSION_COLUMN_SIZER')); } // Find all module permission overrides $all_module_overrides = array(); foreach (find_all_zones() as $zone) { $all_modules = array(); $all_modules += find_all_pages($zone, 'modules_custom', 'php', false); $all_modules += find_all_pages($zone, 'modules', 'php', false); foreach ($all_modules as $module => $module_type) { $functions = extract_module_functions(zone_black_magic_filterer(get_file_base() . '/' . $zone . ($zone == '' ? '' : '/') . 'pages/' . $module_type . '/' . $module . '.php'), array('get_sp_overrides')); if (!is_null($functions[0])) { $overrides = is_array($functions[0]) ? call_user_func_array($functions[0][0], $functions[0][1]) : eval($functions[0]); foreach (array_keys($overrides) as $override) { if (!array_key_exists($override, $all_module_overrides)) { $all_module_overrides[$override] = array(); } $all_module_overrides[$override][] = $module; } } } } $all_page_permission_overridding = $GLOBALS['SITE_DB']->query_select('gsp', array('the_page', 'specific_permission'), array('category_name' => '')); // Rows (pages) $rows = new ocp_tempcode(); $where = array('p_section' => $p_section); // Added in because it was eating up too much memory $_permissions = collapse_2d_complexity('the_name', 'p_section', $GLOBALS['SITE_DB']->query_select('sp_list', array('p_section', 'the_name'), $where, 'ORDER BY p_section,the_name')); $access_rows = $GLOBALS['SITE_DB']->query_select('gsp', array('specific_permission', 'group_id'), array('the_page' => '', 'module_the_name' => '', 'category_name' => '')); $current_section = ''; $sections = new ocp_tempcode(); $_false = do_template('PERMISSION_CELL', array('_GUID' => '61aa7fa739e19caa1efb3695a5e2ab5d', 'CHECKED' => false, 'HUMAN' => '__human__', 'NAME' => '__name__')); $_true = do_template('PERMISSION_CELL', array('_GUID' => '44a888b40d7a34aed6ed2bf8ff47f1de', 'CHECKED' => true, 'HUMAN' => '__human__', 'NAME' => '__name__')); $true = $_true->evaluate(); $false = $_false->evaluate(); // Ad-hoc sorting? $orderings = array('submit_low', 'edit_own_low', 'edit_low', 'delete_own_low', 'delete_low', 'bypass_validation_low', 'submit_mid', 'edit_own_mid', 'edit_mid', 'delete_own_mid', 'delete_mid', 'bypass_validation_mid', 'submit_high', 'edit_own_high', 'edit_high', 'delete_own_high', 'delete_high', 'bypass_validation_high', 'submit_cat_low', 'edit_own_cat_low', 'edit_cat_low', 'delete_own_cat_low', 'delete_cat_low', 'bypass_cat_validation_low', 'submit_cat_mid', 'edit_own_cat_mid', 'edit_cat_mid', 'delete_own_cat_mid', 'delete_cat_mid', 'bypass_cat_validation_mid', 'submit_cat_high', 'edit_own_cat_high', 'edit_cat_high', 'delete_own_cat_high', 'delete_cat_high', 'bypass_cat_validation_high'); $permissions_first = array(); foreach ($orderings as $stub) { foreach ($_permissions as $permission => $section) { if (substr($permission, 0, strlen($stub)) == $stub) { $permissions_first[$permission] = $section; unset($_permissions[$permission]); } } } $_permissions = array_merge($permissions_first, $_permissions); // Display foreach ($_permissions as $permission => $section) { $permission_text = do_lang('PT_' . $permission, NULL, NULL, NULL, NULL, false); if (is_null($permission_text)) { continue; } if ($section != $current_section && $current_section != '') { $sections->attach(do_template('PERMISSION_S_CONFIG_SECTION', array('_GUID' => '36bc9dfbeb7ee3d91f2a18057cd30551', 'HEADER_CELLS' => $header_cells, 'SECTION' => $rows, 'CURRENT_SECTION' => do_lang_tempcode($current_section)))); $rows = new ocp_tempcode(); } $cells = ''; $code = ''; $has = true; foreach ($groups as $id => $g_name) { if (in_array($id, $admin_groups)) { continue; } $has_permission = false; foreach ($access_rows as $access_row) { if ($access_row['specific_permission'] == $permission && $access_row['group_id'] == $id) { $has_permission = true; break; } } if (!$has_permission) { $has = false; } $cells .= str_replace('__human__', escape_html(addslashes(do_lang('PERMISSION_CELL', $permission_text, $g_name))), str_replace('__name__', $permission . '__' . strval($id), $has_permission ? $true : $false)); if (in_array($id, $moderator_groups)) { $code .= 'form.elements[\'' . $permission . '__' . strval($id) . '\'].checked=true;'; } else { $code .= 'form.elements[\'' . $permission . '__' . strval($id) . '\'].checked=this.value==\'+\';'; } } if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($cells); } $tpl_map = array('_GUID' => '075f8855f0fed36b0d0f9c61108dd3de', 'HAS' => $has, 'ABBR' => $permission, 'PERMISSION' => $permission_text, 'CELLS' => $cells, 'CODE' => $code); // See if any modules can override this if (array_key_exists($permission, $all_module_overrides)) { $m_list = ''; $has_actual_overriding = false; foreach ($all_module_overrides[$permission] as $module) { $this_overrides = false; foreach ($all_page_permission_overridding as $po_row) { if ($po_row['the_page'] == $module && $po_row['specific_permission'] == $permission) { $this_overrides = true; break; } } if ($m_list != '') { $m_list .= escape_html(', '); } if ($this_overrides) { $has_actual_overriding = true; $m_list .= '<s>' . escape_html($module) . '</s>'; } else { $m_list .= '<strong>' . escape_html($module) . '</strong>'; } if ($module == 'topics') { $m_list .= ' (' . strtolower(do_lang(strpos($permission, 'lowrange') !== false ? 'FORUM_POSTS' : 'FORUM_TOPICS')) . ')'; } } if (function_exists('ocp_mark_as_escaped')) { ocp_mark_as_escaped($m_list); } $tpl_map['DESCRIPTION'] = do_lang_tempcode($has_actual_overriding ? 'SP_USED_IN_SLASHED' : 'SP_USED_IN', $m_list); } // Render row $rows->attach(do_template('PERMISSION_ROW', $tpl_map)); $current_section = $section; } $sections->attach(do_template('PERMISSION_S_CONFIG_SECTION', array('_GUID' => 'c75a07373f54c0fa31d18e360fcf26f6', 'COLS' => $cols, 'HEADER_CELLS' => $header_cells, 'SECTION' => $rows, 'CURRENT_SECTION' => do_lang_tempcode($current_section)))); breadcrumb_set_parents(array(array('_SELF:_SELF:specific', do_lang_tempcode('CHOOSE')))); return do_template('PERMISSION_S_PERMISSIONS_SCREEN', array('_GUID' => '11974f0a137266a625991d3611b8e587', 'TITLE' => $title, 'URL' => $url, 'SECTIONS' => $sections)); }
/** * Get tempcode for a Comcode tag. This function should always return (errors should be placed in the Comcode output stream), for stability reasons (i.e. if you're submitting something, you can't have the whole submit process die half way through in an unstructured fashion). * * @param string The tag being converted * @param array A map of the attributes (name=>val) for the tag. Val is usually a string, although in select places, the XML parser may pass tempcode. * @param mixed Tempcode of the inside of the tag ([between]THIS[/between]); the XML parser may pass in special stuff here, which is interpreted only for select tags * @param boolean Whether we are allowed to proceed even if this tag is marked as 'dangerous' * @param string A special identifier to mark where the resultant tempcode is going to end up (e.g. the ID of a post) * @param integer The position this tag occurred at in the Comcode * @param MEMBER The member who is responsible for this Comcode * @param boolean Whether to check as arbitrary admin * @param object The database connection to use * @param string The whole chunk of comcode * @param boolean Whether this is for WML output * @param boolean Whether this is only a structure sweep * @param boolean Whether we are in semi-parse-mode (some tags might convert differently) * @param ?array A list of words to highlight (NULL: none) * @param ?MEMBER The member we are running on behalf of, with respect to how attachments are handled; we may use this members attachments that are already within this post, and our new attachments will be handed to this member (NULL: member evaluating) * @param boolean Whether what we have came from inside a semihtml tag * @param boolean Whether what we have came from semihtml mode * @return tempcode The tempcode for the Comcode */ function _do_tags_comcode($tag, $attributes, $embed, $comcode_dangerous, $pass_id, $marker, $source_member, $as_admin, $connection, &$comcode, $wml, $structure_sweep, $semiparse_mode, $highlight_bits = NULL, $on_behalf_of_member = NULL, $in_semihtml = false, $is_all_semihtml = false) { if ($structure_sweep && $tag != 'title') { return new ocp_tempcode(); } $param_given = isset($attributes['param']); if (!isset($attributes['param']) && $tag != 'block') { $attributes['param'] = ''; } global $DANGEROUS_TAGS, $STRUCTURE_LIST, $COMCODE_PARSE_TITLE; if (isset($DANGEROUS_TAGS[$tag]) && !$comcode_dangerous) { $username = $GLOBALS['FORUM_DRIVER']->get_username($source_member); if (is_null($username)) { $username = do_lang('UNKNOWN'); } if ($semiparse_mode) { $params = ''; foreach ($attributes as $key => $val) { $params .= ' ' . $key . '="' . comcode_escape($val) . '"'; } return make_string_tempcode('<input class="ocp_keep_ui_controlled" size="45" title="[' . $tag . '' . escape_html($params) . ']' . ($in_semihtml || $is_all_semihtml ? escape_html($embed->evaluate()) : escape_html($embed->evaluate())) . '[/' . $tag . ']" type="text" value="' . ($tag == 'block' ? do_lang('COMCODE_EDITABLE_BLOCK', escape_html($embed->evaluate())) : do_lang('COMCODE_EDITABLE_TAG', escape_html($tag))) . '" />'); } return do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('comcode:NO_ACCESS_FOR_TAG', escape_html($tag), escape_html($username)))); //return new ocp_tempcode(); } // These are just bbcode compatibility tags.. we will remap to our proper comcode if ($tag == 'php') { $attributes['param'] = 'php'; $tag = 'code'; } elseif ($tag == 'sql') { $attributes['param'] = 'sql'; $tag = 'code'; } elseif ($tag == 'codebox') { $attributes['scroll'] = '1'; $tag = 'code'; } elseif ($tag == 'left') { $attributes['param'] = 'left'; $tag = 'align'; } elseif ($tag == 'center') { $attributes['param'] = 'center'; $tag = 'align'; } elseif ($tag == 'right') { $attributes['param'] = 'right'; $tag = 'align'; } elseif ($tag == 'thread') { $tag = 'topic'; } elseif ($tag == 'internal_table' || $tag == 'external_table') { $tag = 'box'; if (array_key_exists('class', $attributes)) { $attributes['type'] = $attributes['class']; } } if ($semiparse_mode) { $non_text_tags = array('attachment', 'section_controller', 'big_tab_controller', 'currency', 'block', 'contents', 'concepts', 'flash', 'menu', 'email', 'reference', 'upload', 'page', 'exp_thumb', 'exp_ref', 'thumb', 'snapback', 'post', 'thread', 'topic', 'include', 'random', 'jumping', 'shocker'); // Also in JAVASCRIPT_EDITING.tpl if ($tag == 'attachment_safe') { if (preg_match('#^new\\_\\d+$#', $embed->evaluate()) != 0) { $non_text_tags[] = 'attachment_safe'; } } if (in_array($tag, $non_text_tags)) { $params = ''; foreach ($attributes as $key => $val) { $params .= ' ' . $key . '="' . str_replace('"', '\\"', $val) . '"'; } if ($tag != 'block' || !is_file(get_file_base() . '/sources_custom/miniblocks/' . $embed->evaluate() . '.php')) { return make_string_tempcode('<input class="ocp_keep_ui_controlled" size="45" title="[' . $tag . '' . escape_html($params) . ']' . ($in_semihtml || $is_all_semihtml ? escape_html($embed->evaluate()) : escape_html($embed->evaluate())) . '[/' . $tag . ']" type="text" value="' . ($tag == 'block' ? do_lang('comcode:COMCODE_EDITABLE_BLOCK', escape_html($embed->evaluate())) : do_lang('comcode:COMCODE_EDITABLE_TAG', escape_html($tag))) . '" />'); } else { return make_string_tempcode('[block' . escape_html($params) . ']' . ($in_semihtml || $is_all_semihtml ? $embed->evaluate() : escape_html($embed->evaluate())) . '[/block]'); } } } $temp_tpl = new ocp_tempcode(); switch ($tag) { case 'no_parse': $temp_tpl->attach($embed); break; case 'currency': if (addon_installed('ecommerce')) { $bracket = array_key_exists('bracket', $attributes) && $attributes['bracket'] == '1'; if ($attributes['param'] == '') { $attributes['param'] = get_option('currency'); } $temp_tpl = do_template('COMCODE_CURRENCY', array('_GUID' => 'ee1fcdae082af6397ff3bad89006e012', 'AMOUNT' => $embed, 'FROM_CURRENCY' => $attributes['param'], 'BRACKET' => $bracket)); } break; case 'overlay': $x = strval(array_key_exists('x', $attributes) ? intval($attributes['x']) : 100); $y = strval(array_key_exists('y', $attributes) ? intval($attributes['y']) : 100); $width = strval(array_key_exists('width', $attributes) ? intval($attributes['width']) : 300); $height = strval(array_key_exists('height', $attributes) ? intval($attributes['height']) : 300); $timein = strval(array_key_exists('timein', $attributes) ? intval($attributes['timein']) : 0); $timeout = strval(array_key_exists('timeout', $attributes) ? intval($attributes['timeout']) : -1); $temp_tpl = do_template('COMCODE_OVERLAY', array('_GUID' => 'dfd0f7a72cc2bf6b613b28f8165a0034', 'UNIQ_ID' => 'a' . uniqid('', true), 'EMBED' => $embed, 'ID' => $attributes['param'] != '' ? $attributes['param'] : 'rand' . uniqid('', true), 'X' => $x, 'Y' => $y, 'WIDTH' => $width, 'HEIGHT' => $height, 'TIMEIN' => $timein, 'TIMEOUT' => $timeout)); break; case 'code': if ($wml) { $temp_tpl->attach('<b>'); $temp_tpl->attach($embed); $temp_tpl->attach('</b>'); break; } list($_embed, $title) = do_code_box($attributes['param'], $embed, array_key_exists('numbers', $attributes) && $attributes['numbers'] == '1', $in_semihtml, $is_all_semihtml); if (!is_null($_embed)) { $tpl = array_key_exists('scroll', $attributes) && $attributes['scroll'] == '1' ? 'COMCODE_CODE_SCROLL' : 'COMCODE_CODE'; if ($tpl == 'COMCODE_CODE_SCROLL' && substr_count($_embed, chr(10)) < 10) { $style = 'height: auto'; } else { $style = ''; } $temp_tpl = do_template($tpl, array('_GUID' => 'c5d46d0927272fcacbbabcfab0ef6b0c', 'STYLE' => $style, 'TYPE' => $attributes['param'], 'CONTENT' => $_embed, 'TITLE' => $title)); } else { $_embed = ''; } if ($temp_tpl->is_empty()) { if ($in_semihtml || $is_all_semihtml) { require_code('comcode_from_html'); $back_to_comcode = semihtml_to_comcode($embed->evaluate()); // Undo what's happened already //$back_to_comcode=html_entity_decode($back_to_comcode,ENT_QUOTES,get_charset()); // Remove the escaping entities that were inside the code tag $embed = comcode_to_tempcode($back_to_comcode, $source_member, $as_admin, 80, $pass_id, $connection); // Re-parse (with full security) } $_embed = $embed->evaluate(); if (!array_key_exists('scroll', $attributes) && strlen($_embed) > 1000) { $attributes['scroll'] = '1'; } $tpl = array_key_exists('scroll', $attributes) && $attributes['scroll'] == '1' ? 'COMCODE_CODE_SCROLL' : 'COMCODE_CODE'; $title = do_lang_tempcode('CODE'); if ($tpl == 'COMCODE_CODE_SCROLL' && substr_count($_embed, chr(10)) < 10) { $style = 'height: auto'; } else { $style = ''; } $temp_tpl = do_template($tpl, array('CONTENT' => $_embed, 'TITLE' => $title, 'STYLE' => $style, 'TYPE' => $attributes['param'])); } break; case 'list': if (is_array($embed)) { $parts = $embed; } else { $_embed = trim($embed->evaluate()); $_embed = str_replace('[/*]', '', $_embed); $parts = explode('[*]', $_embed); } if (isset($temp_tpl->preprocessable_bits)) { $temp_tpl->preprocessable_bits = array_merge($temp_tpl->preprocessable_bits, $embed->preprocessable_bits); } if ($wml) { foreach ($parts as $i => $part) { if ($i == 0 && str_replace(array(' ', '<br />', ' '), array('', '', ''), trim($part)) == '') { continue; } $temp_tpl->attach('<br />* '); $temp_tpl->attach($part); } $temp_tpl->attach('<br />* '); break; } $type = $attributes['param']; if ($type != '') { if ($type == '1') { $type = 'decimal'; } elseif ($type == 'a') { $type = 'lower-alpha'; } elseif ($type == 'i') { $type = 'lower-roman'; } elseif ($type == 'x') { $type = 'none'; } elseif (!in_array($type, array('circle', 'disc', 'square', 'armenian', 'decimal', 'decimal-leading-zero', 'georgian', 'lower-alpha', 'lower-greek', 'lower-latin', 'lower-roman', 'upper-alpha', 'upper-latin', 'upper-roman'))) { $type = 'disc'; } $tag = in_array($type, array('circle', 'disc', 'square')) ? 'ul' : 'ol'; $temp_tpl->attach('<' . $tag . ' style="list-style-type: ' . $type . '">'); foreach ($parts as $i => $part) { if ($i == 0 && str_replace(array(' ', '<br />', ' '), array('', '', ''), trim($part)) == '') { continue; } $temp_tpl->attach('<li>' . preg_replace('#\\<br /\\>(\\ |\\s)*$#D', '', preg_replace('#^\\<br /\\>(\\ |\\s)*#D', '', $part)) . '</li>'); } $temp_tpl->attach('</' . $tag . '>'); } else { $temp_tpl->attach('<ul>'); foreach ($parts as $i => $part) { if ($i == 0 && str_replace(array(' ', '<br />', ' '), array('', '', ''), trim($part)) == '') { continue; } $temp_tpl->attach('<li>' . preg_replace('#\\<br /\\>(\\ |\\s)*$#D', '', preg_replace('#^\\<br /\\>(\\ |\\s)*#D', '', $part)) . '</li>'); } $temp_tpl->attach('</ul>'); } break; case 'snapback': require_lang('ocf'); $post_id = intval($embed->evaluate()); $s_title = $attributes['param'] == '' ? do_lang_tempcode('FORUM_POST_NUMBERED', integer_format($post_id)) : make_string_tempcode($attributes['param']); $forum = array_key_exists('forum', $attributes) ? $attributes['forum'] : ''; $temp_tpl = do_template('COMCODE_SNAPBACK', array('URL' => $GLOBALS['FORUM_DRIVER']->post_url($post_id, $forum), 'TITLE' => $s_title)); break; case 'post': require_lang('ocf'); $post_id = intval($embed->evaluate()); $s_title = $attributes['param'] == '' ? do_lang_tempcode('FORUM_POST_NUMBERED', integer_format($post_id)) : make_string_tempcode($attributes['param']); $forum = array_key_exists('forum', $attributes) ? $attributes['forum'] : ''; $temp_tpl->attach(hyperlink($GLOBALS['FORUM_DRIVER']->post_url($post_id, $forum), $s_title)); break; case 'topic': require_lang('ocf'); $topic_id = intval($embed->evaluate()); $s_title = $attributes['param'] == '' ? do_lang_tempcode('FORUM_TOPIC_NUMBERED', integer_format($topic_id)) : make_string_tempcode($attributes['param']); $forum = array_key_exists('forum', $attributes) ? $attributes['forum'] : ''; $temp_tpl->attach(hyperlink($GLOBALS['FORUM_DRIVER']->topic_url($topic_id, $forum), $s_title)); break; case 'staff_note': $temp_tpl = new ocp_tempcode(); return $temp_tpl; case 'section': if ($wml) { $temp_tpl = $embed; break; } $name = array_key_exists('param', $attributes) ? $attributes['param'] : 'section' . strval(mt_rand(0, 100)); $default = array_key_exists('default', $attributes) ? $attributes['default'] : '0'; $temp_tpl = do_template('COMCODE_SECTION', array('_GUID' => 'a902962ccdc80046c999d6fed907d105', 'PASS_ID' => 'x' . $pass_id, 'DEFAULT' => $default == '1', 'NAME' => $name, 'CONTENT' => $embed)); break; case 'section_controller': if ($wml) { break; } $sections = explode(',', $embed->evaluate()); $temp_tpl = do_template('COMCODE_SECTION_CONTROLLER', array('_GUID' => '133bf24892e9e3ec2a01146d6ec418fe', 'SECTIONS' => $sections, 'PASS_ID' => 'x' . $pass_id)); break; case 'big_tab': if ($wml) { $temp_tpl = $embed; break; } $name = array_key_exists('param', $attributes) ? $attributes['param'] : 'big_tab' . strval(mt_rand(0, 100)); $default = array_key_exists('default', $attributes) ? $attributes['default'] : '0'; $temp_tpl = do_template('COMCODE_BIG_TABS_TAB', array('PASS_ID' => 'x' . $pass_id, 'DEFAULT' => $default == '1', 'NAME' => $name, 'CONTENT' => $embed)); break; case 'big_tab_controller': if ($wml) { break; } $tabs = explode(',', $embed->evaluate()); if (!array_key_exists('switch_time', $attributes)) { $attributes['switch_time'] = '6000'; } $temp_tpl = do_template('COMCODE_BIG_TABS_CONTROLLER', array('SWITCH_TIME' => $attributes['switch_time'], 'TABS' => $tabs, 'PASS_ID' => 'x' . $pass_id)); break; case 'tab': if ($wml) { $temp_tpl = $embed; break; } $default = array_key_exists('default', $attributes) ? $attributes['default'] : '0'; $temp_tpl = do_template('COMCODE_TAB_BODY', array('DEFAULT' => $default == '1', 'TITLE' => trim($attributes['param']), 'CONTENT' => $embed)); break; case 'tabs': if ($wml) { break; } $heads = new ocp_tempcode(); $tabs = explode(',', $attributes['param']); foreach ($tabs as $i => $tab) { $heads->attach(do_template('COMCODE_TAB_HEAD', array('TITLE' => trim($tab), 'FIRST' => $i == 0, 'LAST' => !array_key_exists($i + 1, $tabs)))); } $temp_tpl = do_template('COMCODE_TAB_CONTROLLER', array('HEADS' => $heads, 'CONTENT' => $embed)); break; case 'carousel': if ($attributes['param'] == '') { $attributes['param'] = '40'; } $temp_tpl = do_template('COMCODE_CAROUSEL', array('CONTENT' => $embed, 'SCROLL_AMOUNT' => $attributes['param'])); break; case 'menu': if ($wml) { break; } $name = array_key_exists('param', $attributes) ? $attributes['param'] : 'mnu' . strval(mt_rand(0, 100)); $type = array_key_exists('type', $attributes) ? $attributes['type'] : 'tree'; require_code('menus'); require_code('menus_comcode'); $temp_tpl = build_comcode_menu($embed->evaluate(), $name, $source_member, $type); break; case 'if_in_group': $groups = ''; $_groups = explode(',', $attributes['param']); $all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(); foreach ($_groups as $group) { $find = array_search($group, $all_groups); if ($find === false) { if ($groups != '') { $groups .= ','; } $groups .= $group; } else { if ($groups != '') { $groups .= ','; } $groups .= strval($find); } } $temp_tpl = do_template('COMCODE_IF_IN_GROUP', array('_GUID' => '761a7cc07f7b4b68508d68ce19b87d2c', 'TYPE' => array_key_exists('type', $attributes) ? $attributes['type'] : '', 'CONTENT' => $embed, 'GROUPS' => $groups)); break; case 'acronym': case 'abbr': $temp_tpl = do_template('COMCODE_ABBR', array('_GUID' => 'acbc4f991dsf03f81b61919b74ac24c91', 'CONTENT' => $embed, 'TITLE' => $attributes['param'])); break; case 'address': $temp_tpl = do_template('COMCODE_ADDRESS', array('_GUID' => 'acbcsdf9910703f81b61919b74ac24c91', 'CONTENT' => $embed)); break; case 'dfn': $temp_tpl = do_template('COMCODE_DFN', array('_GUID' => 'acbc4f9910703f81b61sf19b74ac24c91', 'CONTENT' => $embed)); break; case 'pulse': $min_color = array_key_exists('min', $attributes) ? $attributes['min'] : '0000FF'; $max_color = array_key_exists('max', $attributes) ? $attributes['max'] : 'FF0044'; if (substr($min_color, 0, 1) == '#') { $min_color = substr($min_color, 1); } if (substr($max_color, 0, 1) == '#') { $max_color = substr($max_color, 1); } $speed = $attributes['param'] == '' ? 100 : intval($attributes['param']); $temp_tpl = do_template('COMCODE_PULSE', array('_GUID' => 'adsd4f9910sfd03f81b61919b74ac24c91', 'RAND_ID' => uniqid('', true), 'CONTENT' => $embed, 'MIN_COLOR' => $min_color, 'MAX_COLOR' => $max_color, 'SPEED' => strval($speed))); break; case 'del': $cite = array_key_exists('cite', $attributes) ? $attributes['cite'] : NULL; if (!is_null($cite)) { $temp_tpl = test_url($cite, 'del', $cite, $source_member); } $datetime = array_key_exists('datetime', $attributes) ? $attributes['datetime'] : NULL; $temp_tpl->attach(do_template('COMCODE_DEL', array('_GUID' => 'acsd4f9910sfd03f81b61919b74ac24c91', 'CONTENT' => $embed, 'CITE' => $cite, 'DATETIME' => $datetime))); break; case 'ins': $cite = array_key_exists('cite', $attributes) ? $attributes['cite'] : NULL; if (!is_null($cite)) { $temp_tpl = test_url($cite, 'ins', $cite, $source_member); if (!$temp_tpl->is_empty()) { break; } } $datetime = array_key_exists('datetime', $attributes) ? $attributes['datetime'] : NULL; $temp_tpl->attach(do_template('COMCODE_INS', array('_GUID' => 'asss4f9910703f81b61919bsfc24c91', 'CONTENT' => $embed, 'CITE' => $cite, 'DATETIME' => $datetime))); break; case 'cite': $temp_tpl = do_template('COMCODE_CITE', array('_GUID' => 'acbcsf910703f81b61919b74ac24c91', 'CONTENT' => $embed)); break; case 'b': if ($semiparse_mode) { $temp_tpl = make_string_tempcode('<b>' . $embed->evaluate() . '</b>'); break; } $temp_tpl = do_template('COMCODE_BOLD', array('_GUID' => 'acbc4fds910703f81b619sf74ac24c91', 'CONTENT' => $embed)); break; case 'align': if ($wml) { $temp_tpl = $embed; break; } $align = array_key_exists('param', $attributes) ? $attributes['param'] : 'left'; $temp_tpl = do_template('COMCODE_ALIGN', array('_GUID' => '950b4d9db12cac6bf536860bedd96a36', 'ALIGN' => $align, 'CONTENT' => $embed)); break; case 'indent': if ($wml) { $temp_tpl = $embed; break; } $indent = array_key_exists('param', $attributes) ? $attributes['param'] : '10'; if (!is_numeric($indent)) { $indent = '10'; } $temp_tpl = do_template('COMCODE_INDENT', array('_GUID' => 'd8e69fa17eebd5312e3ad5788e3a1343', 'INDENT' => $indent, 'CONTENT' => $embed)); break; case 'surround': if ($wml) { $temp_tpl = $embed; break; } if ($semiparse_mode && $embed->evaluate() == '') { $temp_tpl = make_string_tempcode('<kbd class="ocp_keep" title="no_parse">[surround="' . comcode_escape(array_key_exists('param', $attributes) ? $attributes['param'] : 'float_surrounder') . '"]' . $embed->evaluate() . '[/surround]</kbd>'); break; } $class = array_key_exists('param', $attributes) && $attributes['param'] != '' ? $attributes['param'] : 'float_surrounder'; $temp_tpl = do_template('COMCODE_SURROUND', array('_GUID' => 'e8e69fa17eebd5312e3ad5788e3a1343', 'CLASS' => $class, 'CONTENT' => $embed)); break; case 'i': if ($semiparse_mode) { $temp_tpl = make_string_tempcode('<i>' . $embed->evaluate() . '</i>'); break; } $temp_tpl = do_template('COMCODE_ITALICS', array('_GUID' => '4321a1fe3825418e57a29410183c0c60', 'CONTENT' => $embed)); break; case 'u': if ($semiparse_mode) { $temp_tpl = make_string_tempcode('<u>' . $embed->evaluate() . '</u>'); break; } $temp_tpl = do_template('COMCODE_UNDERLINE', array('_GUID' => '69cc8e73b17f9e6a35eb1af2bd1dc6ab', 'CONTENT' => $embed)); break; case 's': if ($wml) { $temp_tpl = $embed; break; } if ($semiparse_mode) { $temp_tpl = make_string_tempcode('<strike>' . $embed->evaluate() . '</strike>'); break; } $temp_tpl = do_template('COMCODE_STRIKE', array('_GUID' => 'ed242591cefd365497cc0c63abbb11a9', 'CONTENT' => $embed)); break; case 'tooltip': $param = is_object($attributes['param']) ? $attributes['param'] : comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); if ($wml) { $temp_tpl->attach($embed); $temp_tpl->attach('[ '); $temp_tpl->attach($param); $temp_tpl->attach(' ]'); break; } $temp_tpl = do_template('COMCODE_TOOLTIP', array('_GUID' => 'c9f4793dc0c1a92cd7d08ae1b87c2308', 'URL' => array_key_exists('url', $attributes) ? $attributes['url'] : '', 'TOOLTIP' => $param, 'CONTENT' => $embed)); break; case 'sup': if ($wml) { $temp_tpl->attach('^'); $temp_tpl->attach($embed); break; } $temp_tpl = do_template('COMCODE_SUP', array('_GUID' => '74d2ecfe193dacb6d922bc288828196a', 'CONTENT' => $embed)); break; case 'sub': if ($wml) { $temp_tpl->attach('{'); $temp_tpl->attach($embed); $temp_tpl->attach('}'); break; } $temp_tpl = do_template('COMCODE_SUB', array('_GUID' => '515e310e00a6d7c30f7dca0a5956ebcf', 'CONTENT' => $embed)); break; case 'title': if ($semiparse_mode && strpos($comcode, '[contents') !== false) { $temp_tpl = make_string_tempcode('[title' . reinsert_parameters($attributes) . ']' . $embed->evaluate() . '[/title]'); break; } $level = $attributes['param'] != '' ? intval($attributes['param']) : 1; if ($level == 0) { $level = 1; } // Stop crazy Comcode causing stack errors with the toc $uniq_id = strval(count($STRUCTURE_LIST)); $STRUCTURE_LIST[] = array($level, $embed, $uniq_id); if ($level == 1) { $template = 'SCREEN_TITLE'; } elseif ($level == 2) { $template = 'COMCODE_SECTION_TITLE'; } elseif ($level == 3) { $template = 'COMCODE_MINOR_TITLE'; } elseif ($level == 4) { $template = 'COMCODE_VERY_MINOR_TITLE'; } else { $template = 'COMCODE_VERY_MINOR_TITLE'; } if ($level == 1) { if (is_null($COMCODE_PARSE_TITLE)) { $COMCODE_PARSE_TITLE = $embed->evaluate(); if (is_object($COMCODE_PARSE_TITLE)) { $COMCODE_PARSE_TITLE = $COMCODE_PARSE_TITLE->evaluate(); } } } $base = array_key_exists('base', $attributes) ? intval($attributes['base']) : 2; if (array_key_exists('number', $attributes) && $level >= $base) { $list_types = $attributes['number'] == '' ? array() : explode(',', $attributes['number']); $list_types = array_merge($list_types, array('decimal', 'lower-alpha', 'lower-roman', 'upper-alpha', 'upper-roman', 'disc')); $numerals = array('i', 'ii', 'iii', 'iv', 'v', 'vi', 'viii', 'ix', 'x', 'xi', 'xii', 'xiii', 'xiv', 'xv', 'xvi', 'xvii', 'xviii', 'xix', 'xx'); $symbol_lookup = array('decimal' => range(1, 100), 'lower-alpha' => range('a', 'z'), 'lower-roman' => $numerals, 'upper-alpha' => range('A', 'Z'), 'upper-roman' => str_replace('i', 'I', str_replace('v', 'V', str_replace('x', 'X', $numerals)))); $level_text = ''; $list_pos = count($STRUCTURE_LIST) - 2; for ($j = $level; $j >= $base; $j--) { $num_before = 0; for ($i = $list_pos; $i >= 0; $i--) { $list_pos--; if ($STRUCTURE_LIST[$i][0] == $j - 1) { break; } if ($STRUCTURE_LIST[$i][0] == $j) { $num_before++; } } $level_number = @strval($symbol_lookup[$list_types[$j - $base]][$num_before]); $level_text = $level_number . ($level_text != '' ? '.' : '') . $level_text; } $old_embed = $embed; $embed = make_string_tempcode($level_text . ' – '); $embed->attach($old_embed); } if ($wml) { if ($level == 1) { $temp_tpl->attach('<br /><p><big><u><b>'); $temp_tpl->attach($embed); $temp_tpl->attach('</b></u></big></p><br />'); } elseif ($level == 2) { $temp_tpl->attach('<br /><p><big><u>'); $temp_tpl->attach($embed); $temp_tpl->attach('</u></big></p><br />'); } elseif ($level == 3) { $temp_tpl->attach('<br /><p><big>'); $temp_tpl->attach($embed); $temp_tpl->attach('</big></p><br />'); } elseif ($level == 4) { $temp_tpl->attach('<br /><p>'); $temp_tpl->attach($embed); $temp_tpl->attach('</p><br />'); } break; } if ($semiparse_mode) { $temp_tpl = make_string_tempcode('<h' . strval($level) . ($level == 1 ? ' class="main_page_title"' : '') . '><span class="inner">' . $embed->evaluate() . '</span></h' . strval($level) . '>'); break; } $tpl_map = array('ID' => substr($pass_id, 0, 5) == 'panel' ? NULL : $uniq_id, 'TITLE' => $embed, 'HELP_URL' => '', 'HELP_TERM' => ''); if (array_key_exists('sub', $attributes)) { $tpl_map['SUB'] = protect_from_escaping(comcode_to_tempcode($attributes['sub'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member)); } $temp_tpl = do_template($template, $tpl_map); break; case 'attachment': case 'attachment2': // legacy // legacy case 'attachment_safe': if ($wml) { break; } require_code('attachments'); if (is_null($on_behalf_of_member)) { $on_behalf_of_member = $source_member; } $id = $embed->evaluate(); global $COMCODE_ATTACHMENTS; if (!is_numeric($id) && !$as_admin && !has_specific_permission($source_member, 'exceed_filesize_limit')) { // We work all this out before we do any downloads, to make sure orphaned files aren't dumped on the file system (possible hack method) if (get_forum_type() == 'ocf') { require_lang('ocf'); require_code('ocf_groups'); $daily_quota = ocf_get_member_best_group_property($source_member, 'max_daily_upload_mb'); } else { $daily_quota = 5; // 5 is a hard coded default for non-OCF forums } if (!is_null($daily_quota)) { $_size_uploaded_today = $connection->query('SELECT SUM(a_file_size) AS the_answer FROM ' . $connection->get_table_prefix() . 'attachments WHERE a_member_id=' . strval((int) $source_member) . ' AND a_add_time>' . strval(time() - 60 * 60 * 24)); if (is_null($_size_uploaded_today[0]['the_answer'])) { $_size_uploaded_today[0]['the_answer'] = 0; } $size_uploaded_today = ceil((double) $_size_uploaded_today[0]['the_answer'] / 1024.0 / 1024.0); $attach_size = 0; require_code('uploads'); is_swf_upload(true); foreach ($_FILES as $_file) { $attach_size += floatval($_file['size']) / 1024.0 / 1024.0; } if ($size_uploaded_today + $attach_size > floatval($daily_quota)) { $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('OVER_DAILY_QUOTA', integer_format($daily_quota), float_format($size_uploaded_today)))); break; } } } $thumb_url = array_key_exists('thumb_url', $attributes) ? $attributes['thumb_url'] : ''; // Embedded attachments if (!is_numeric($id) && substr($id, 0, 4) != 'new_' && substr($id, 0, 4) != 'url_') { $file = base64_decode(str_replace(chr(10), '', $id)); if ($file === false) { $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('comcode:CORRUPT_ATTACHMENT'))); break; } $md5 = md5(substr($file, 0, 30)); $original_filename = array_key_exists('filename', $attributes) ? $attributes['filename'] : $md5 . '.dat'; if (get_file_extension($original_filename) != 'dat') { require_code('files2'); check_extension($original_filename, true); $new_filename = $md5 . '.' . get_file_extension($original_filename) . '.dat'; } else { $new_filename = $md5 . '.' . get_file_extension($original_filename); } $path = get_custom_file_base() . '/uploads/attachments/' . $new_filename; $myfile = @fopen($path, 'wb'); if ($myfile === false) { $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => intelligent_write_error_inline($path))); break; } if (fwrite($myfile, $file) < strlen($file)) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } fclose($myfile); fix_permissions($path); sync_file($path); $_size = strlen($file); $url = 'uploads/attachments/' . $new_filename; if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) { $url = get_custom_base_url() . '/' . $url; } // Thumbnail if ($thumb_url == '') { require_code('images'); if (is_image($original_filename)) { $gd = get_option('is_on_gd') == '1' && function_exists('imagetypes'); if ($gd) { require_code('images'); if (!is_saveable_image($url)) { $ext = '.png'; } else { $ext = '.' . get_file_extension($original_filename); } $thumb_url = 'uploads/attachments_thumbs/' . $md5 . $ext; convert_image(get_custom_base_url() . '/' . $url, get_custom_file_base() . '/' . $thumb_url, -1, -1, intval(get_option('thumb_width')), true, NULL, false, true); if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) { $thumb_url = get_custom_base_url() . '/' . $thumb_url; } } else { $thumb_url = $url; } } } if (addon_installed('galleries')) { require_code('images'); if (is_video($url) && $connection->connection_read == $GLOBALS['SITE_DB']->connection_read) { require_code('transcoding'); $url = transcode_video($url, 'attachments', 'a_url', 'a_original_filename', NULL, NULL); } } $attachment = array('a_member_id' => $on_behalf_of_member, 'a_file_size' => $_size, 'a_url' => $url, 'a_thumb_url' => $thumb_url, 'a_original_filename' => $original_filename, 'a_num_downloads' => 0, 'a_last_downloaded_time' => NULL, 'a_add_time' => time()); $attachment['a_description'] = array_key_exists('description', $attributes) ? is_object($attributes['description']) ? '[html]' . $attributes['description']->evaluate() . '[/html]' : $attributes['description'] : ''; $attach_id = $connection->query_insert('attachments', $attachment, true); $attachment['id'] = $attach_id; // Create and document attachment if (!array_key_exists('type', $attributes)) { $attributes['type'] = 'auto'; } $COMCODE_ATTACHMENTS[$pass_id][] = array('tag_type' => $tag, 'type' => 'new', 'attachmenttype' => $attributes['type'], 'description' => $attachment['a_description'], 'id' => intval($attach_id), 'marker' => $marker, 'comcode' => $comcode); // Marker will allow us to search back and replace this with the added id } elseif (!is_numeric($id)) { require_code('uploads'); if (substr($id, 0, 4) == 'new_') { $_id = substr($id, 4); if (!is_numeric($_id)) { $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('comcode:INVALID_ATTACHMENT'))); break; } $attributes['type'] = post_param('attachmenttype' . $_id, array_key_exists('type', $attributes) ? $attributes['type'] : 'auto'); if (substr($attributes['type'], -8) == '_extract') { $attributes['type'] = substr($attributes['type'], 0, strlen($attributes['type']) - 8); } $urls = get_url('', 'file' . $_id, 'uploads/attachments', 2, OCP_UPLOAD_ANYTHING, (!array_key_exists('thumb', $attributes) || $attributes['thumb'] != '0') && $thumb_url == '', '', '', true, true, true); if ($urls[0] == '') { return new ocp_tempcode(); } //warn_exit(do_lang_tempcode('ERROR_UPLOADING')); Can't do this, because this might not be post-calculated if something went wrong once is_swf_upload(true); $_size = $_FILES['file' . $_id]['size']; $original_filename = $_FILES['file' . $_id]['name']; if (get_magic_quotes_gpc()) { $original_filename = stripslashes($original_filename); } } elseif (substr($id, 0, 4) == 'url_') { if (!has_specific_permission($source_member, 'draw_to_server') && !$as_admin) { break; } $_id = '!'; $attributes['type'] = post_param('attachmenttype' . $_id, array_key_exists('type', $attributes) ? $attributes['type'] : 'auto'); $url = remove_url_mistakes(substr($id, 4)); $_POST['_specify_url'] = $url; // Little hack, as we need to read it from a POST if (get_magic_quotes_gpc()) { $_POST['_specify_url'] = addslashes($_POST['_specify_url']); } $urls = get_url('_specify_url', '', 'uploads/filedump', 1, OCP_UPLOAD_ANYTHING, (!array_key_exists('thumb', $attributes) || $attributes['thumb'] != '0') && $thumb_url == '', '', '', true, true); if ($urls[0] == '') { return new ocp_tempcode(); } $original_filename = rawurldecode(substr($url, strrpos($url, '/') + 1)); if (url_is_local($urls[0])) { $_size = @filesize(get_custom_file_base() . '/' . rawurldecode($urls[0])); if ($_size === false) { $_size = filesize(get_file_base() . '/' . rawurldecode($urls[0])); } } else { $_size = 0; } } else { $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('comcode:INVALID_ATTACHMENT'))); break; } if ($urls[0] == '') { require_code('images'); require_code('files2'); $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('ATTACHMENT_WOULD_NOT_UPLOAD', float_format(get_max_file_size() / 1024 / 1024), float_format(get_max_image_size() / 1024 / 1024)))); break; } $url = $urls[0]; if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) { $url = get_custom_base_url() . '/' . $url; } if ($thumb_url == '') { $thumb_url = array_key_exists(1, $urls) ? $urls[1] : ''; } if ($thumb_url != '' && $connection != $GLOBALS['SITE_DB']) { $thumb_url = get_custom_base_url() . '/' . $thumb_url; } $num_downloads = 0; $last_downloaded_time = NULL; $add_time = time(); $member_id = $on_behalf_of_member; if (addon_installed('galleries')) { require_code('images'); if (is_video($url) && $connection->connection_read == $GLOBALS['SITE_DB']->connection_read) { require_code('transcoding'); $url = transcode_video($url, 'attachments', 'a_url', 'a_original_filename', NULL, NULL); } } $attachment = array('a_member_id' => $member_id, 'a_file_size' => $_size, 'a_url' => $url, 'a_thumb_url' => $thumb_url, 'a_original_filename' => $original_filename, 'a_num_downloads' => $num_downloads, 'a_last_downloaded_time' => $last_downloaded_time, 'a_add_time' => $add_time); $attachment['a_description'] = post_param('caption' . $_id, array_key_exists('description', $attributes) ? is_object($attributes['description']) ? '[html]' . $attributes['description']->evaluate() . '[/html]' : $attributes['description'] : ''); $attach_id = $connection->query_insert('attachments', $attachment, true); $attachment['id'] = $attach_id; if ($tag == 'attachment2' || $tag == 'attachment_safe' || substr($id, 0, 4) == 'url_') { $connection->query_delete('attachment_refs', array('r_referer_type' => 'null', 'r_referer_id' => '', 'a_id' => $attachment['id']), '', 1); $connection->query_insert('attachment_refs', array('r_referer_type' => 'null', 'r_referer_id' => '', 'a_id' => $attachment['id'])); } // Create and document attachment $COMCODE_ATTACHMENTS[$pass_id][] = array('tag_type' => $tag, 'time' => time(), 'type' => substr($id, 0, 4) == 'new_' ? 'new' : 'url', 'attachmenttype' => $attributes['type'], 'description' => $attachment['a_description'], 'id' => intval($attach_id), 'marker' => $marker, 'comcode' => $comcode); // Marker will allow us to search back and replace this with the added id // Existing attachments } else { $__id = intval($id); // Check we have permission to re-use this $owner = $connection->query_value_null_ok('attachments', 'a_member_id', array('id' => $__id)); if (is_null($owner)) { $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('MISSING_RESOURCE_COMCODE', 'attachment', escape_html(strval($__id))))); if (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe')) { require_code('failure'); relay_error_notification(do_lang('MISSING_RESOURCE_COMCODE', 'attachment', strval($__id)), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference'); } break; } $_attachment = $connection->query_select('attachments', array('*'), array('id' => $__id), '', 1); $attachment = $_attachment[0]; $already_referenced = array_key_exists($__id, $GLOBALS['ATTACHMENTS_ALREADY_REFERENCED']); if ($already_referenced || $as_admin || $source_member === $owner || (has_specific_permission($source_member, 'reuse_others_attachments') || $owner == $source_member) && has_attachment_access($source_member, $__id)) { if (!array_key_exists('type', $attributes)) { $attributes['type'] = 'auto'; } $COMCODE_ATTACHMENTS[$pass_id][] = array('tag_type' => $tag, 'time' => $attachment['a_add_time'], 'type' => 'existing', 'id' => $__id, 'attachmenttype' => $attributes['type'], 'marker' => $marker, 'comcode' => $comcode); } else { require_lang('permissions'); $username = $GLOBALS['FORUM_DRIVER']->get_username($source_member); if (is_null($username)) { $username = do_lang('DELETED'); } $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('permissions:ACCESS_DENIED__REUSE_ATTACHMENT', $username))); break; //access_denied('REUSE_ATTACHMENT'); } if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) { if (url_is_local($attachment['a_url'])) { $attachment['a_url'] = get_custom_base_url() . '/' . $attachment['a_url']; } if (url_is_local($attachment['a_url'])) { $attachment['a_thumb_url'] = get_custom_base_url() . '/' . $attachment['a_thumb_url']; } } $attachment['a_description'] = array_key_exists('description', $attributes) ? is_object($attributes['description']) ? '[html]' . $attributes['description']->evaluate() . '[/html]' : $attributes['description'] : $attachment['a_description']; } // Now, render it // ============== $temp_tpl = render_attachment($tag, $attributes, $attachment, $pass_id, $source_member, $as_admin, $connection, $highlight_bits, $on_behalf_of_member, $semiparse_mode); if (array_key_exists('float', $attributes)) { $temp_tpl = do_template('FLOATER', array('_GUID' => '802fe29019be80993296de7cc8b5cc5e', 'FLOAT' => $attributes['float'], 'CONTENT' => $temp_tpl)); } break; case 'include': $codename = $embed->evaluate(); $zone = $attributes['param']; if ($zone == '_SEARCH') { $zone = get_comcode_zone($codename); } if ($zone == '_SELF') { $zone = get_zone_name(); } $temp_comcode_parse_title = $COMCODE_PARSE_TITLE; $temp = request_page($codename, false, $zone, NULL, true); $COMCODE_PARSE_TITLE = $temp_comcode_parse_title; if ($temp->is_empty()) { $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('MISSING_RESOURCE_COMCODE', 'include', hyperlink(build_url(array('page' => 'cms_comcode_pages', 'type' => '_ed', 'page_link' => $zone . ':' . $codename), get_module_zone('cms_comcode_pages')), $zone . ':' . $codename, false, true)))); if (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe')) { require_code('failure'); relay_error_notification(do_lang('MISSING_RESOURCE_COMCODE', 'include', $zone . ':' . $codename), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference'); } } else { $temp_tpl = symbol_tempcode('LOAD_PAGE', array($codename, $zone)); } break; case 'random': unset($attributes['param']); if ($wml) { $top_attribute = array_pop($attributes); $temp_tpl = is_object($top_attribute) ? $top_attribute : comcode_to_tempcode($top_attribute, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); break; } $max = $embed->evaluate() == '' ? intval($embed->evaluate()) : 0; foreach ($attributes as $num => $val) { $_temp = is_object($val) ? $val : comcode_to_tempcode($val, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); $attributes[$num] = $_temp->evaluate(); if (intval($num) > $max) { $max = intval($num); } } $_parts = new ocp_tempcode(); krsort($attributes); foreach ($attributes as $num => $val) { $_parts->attach(do_template('COMCODE_RANDOM_PART', array('_GUID' => '5fa49a916304f9caa0ddedeb01531142', 'NUM' => strval($num), 'VAL' => $val))); } $temp_tpl = do_template('COMCODE_RANDOM', array('_GUID' => '9b77aaf593b12c763fb0c367fab415b6', 'UNIQID' => uniqid('', true), 'FULL' => $embed, 'MAX' => strval($max), 'PARTS' => $_parts)); break; case 'jumping': unset($attributes['param']); if ($wml) { $top_attribute = array_pop($attributes); $temp_tpl = is_object($top_attribute) ? $top_attribute : comcode_to_tempcode($top_attribute, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); break; } $_parts = new ocp_tempcode(); foreach ($attributes as $val) { $_temp = is_object($val) ? $val : comcode_to_tempcode($val, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); $_parts->attach(do_template('COMCODE_JUMPING_PART', array('_GUID' => 'd163bd11920f39f0cb8ff2f6ba48bc80', 'PART' => $_temp->evaluate()))); } $embed = $embed->evaluate(); $temp_tpl = do_template('COMCODE_JUMPING', array('_GUID' => '85e9f83ed134868436a7db7692f56047', 'UNIQID' => uniqid('', true), 'FULL' => implode(', ', $attributes), 'TIME' => strval((int) $embed), 'PARTS' => $_parts)); break; case 'shocker': if ($wml) { $top_attribute = array_pop($attributes); $temp_tpl = is_object($top_attribute) ? $top_attribute : comcode_to_tempcode($top_attribute, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); break; } $_parts = new ocp_tempcode(); foreach ($attributes as $key => $val) { if (substr($key, 0, 5) == 'left_') { $left = $val; $right = array_key_exists('right_' . substr($key, 5), $attributes) ? $attributes['right_' . substr($key, 5)] : ''; $left = is_object($left) ? $left : comcode_to_tempcode($left, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); $right = is_object($right) ? $right : comcode_to_tempcode($right, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); $_parts->attach(do_template('COMCODE_SHOCKER_PART', array('LEFT' => $left, 'RIGHT' => $right))); } } $min_color = array_key_exists('min', $attributes) ? $attributes['min'] : '0000FF'; $max_color = array_key_exists('max', $attributes) ? $attributes['max'] : 'FF0044'; if (substr($min_color, 0, 1) == '#') { $min_color = substr($min_color, 1); } if (substr($max_color, 0, 1) == '#') { $max_color = substr($max_color, 1); } $embed = $embed->evaluate(); $temp_tpl = do_template('COMCODE_SHOCKER', array('UNIQID' => uniqid('', true), 'MIN_COLOR' => $min_color, 'MAX_COLOR' => $max_color, 'FULL' => implode(', ', $attributes), 'TIME' => strval(intval($embed)), 'PARTS' => $_parts)); break; case 'ticker': if ($wml) { $temp_tpl = $embed; break; } $width = $attributes['param']; if (!is_numeric($width)) { $width = '300'; } $fspeed = array_key_exists('speed', $attributes) ? float_to_raw_string(floatval($attributes['speed'])) : '1'; $temp_tpl = do_template('COMCODE_TICKER', array('_GUID' => 'e48893cda61995261577f0556443c537', 'UNIQID' => uniqid('', true), 'SPEED' => $fspeed, 'WIDTH' => $width, 'TEXT' => $embed)); break; case 'highlight': if ($wml) { $temp_tpl->attach('<i>'); $temp_tpl->attach($embed); $temp_tpl->attach('</i>'); break; } $temp_tpl = do_template('COMCODE_HIGHLIGHT', array('_GUID' => '695d041b6605f06ec2aeee1e82f87185', 'CONTENT' => $embed)); break; case 'size': $size = array_key_exists('param', $attributes) ? $attributes['param'] : '1'; if ($wml) { if (floatval($size) >= 1.5) { $temp_tpl->attach('<big>'); $temp_tpl->attach($embed); $temp_tpl->attach('</big>'); } elseif (floatval($size) < 0.8) { $temp_tpl->attach('<small>'); $temp_tpl->attach($embed); $temp_tpl->attach('</small>'); } else { $temp_tpl->attach($embed); } break; } if (is_numeric($size)) { $size = 'font-size: ' . $size . 'em;'; } elseif (substr($size, 0, 1) == '+') { $size = 'font-size: ' . substr($size, 1) . 'em'; } elseif (substr($size, -1) == '%') { $size = 'font-size: ' . float_to_raw_string(floatval(substr($size, 0, strlen($size) - 1)) / 100.0) . 'em'; } elseif (substr($size, -2) == 'of') { $new_size = '1em'; switch ($size) { case '1of': $new_size = '8pt'; break; case '2of': $new_size = '10pt'; break; case '3of': $new_size = '12pt'; break; case '4of': $new_size = '14pt'; break; case '5of': $new_size = '18pt'; break; case '6of': $new_size = '24pt'; break; case '7of': $new_size = '36pt'; break; } $size = 'font-size: ' . $new_size; } else { $size = 'font-size: ' . $size; } $size_len = strlen($size); filter_html($as_admin, $source_member, 0, $size_len, $size, false, false); $temp_tpl = do_template('COMCODE_FONT', array('_GUID' => 'fb23fdcb45aabdfeca9f37ed8098948e', 'CONTENT' => $embed, 'SIZE' => $size, 'COLOR' => '', 'FACE' => '')); break; case 'color': if ($wml) { $temp_tpl = $embed; break; } $color = array_key_exists('param', $attributes) ? 'color: ' . $attributes['param'] . ';' : ''; $temp_tpl = do_template('COMCODE_FONT', array('_GUID' => 'bd146414c9239ba2076f4b683df437d7', 'CONTENT' => $embed, 'SIZE' => '', 'COLOR' => $color, 'FACE' => '')); $color_len = strlen($color); filter_html($as_admin, $source_member, 0, $color_len, $color, false, false); break; case 'tt': if ($wml) { $temp_tpl->attach('<i>'); $temp_tpl->attach($embed); $temp_tpl->attach('</i>'); break; } $temp_tpl = do_template('COMCODE_TELETYPE', array('CONTENT' => $embed)); break; case 'samp': if ($wml) { $temp_tpl->attach('<i>'); $temp_tpl->attach($embed); $temp_tpl->attach('</i>'); break; } $temp_tpl = do_template('COMCODE_SAMP', array('CONTENT' => $embed)); break; case 'q': if ($wml) { $temp_tpl->attach('<i>'); $temp_tpl->attach($embed); $temp_tpl->attach('</i>'); break; } $temp_tpl = do_template('COMCODE_Q', array('CONTENT' => $embed)); break; case 'var': if ($wml) { $temp_tpl->attach('<i>'); $temp_tpl->attach($embed); $temp_tpl->attach('</i>'); break; } $temp_tpl = do_template('COMCODE_VAR', array('CONTENT' => $embed)); break; case 'font': $face = $attributes['param']; if ($face == '' && array_key_exists('face', $attributes)) { $face = $attributes['face']; } $color = array_key_exists('color', $attributes) ? $attributes['color'] : ''; $size = array_key_exists('size', $attributes) ? $attributes['size'] : ''; if ($face == '/') { $face = ''; } if ($color == '/') { $color = ''; } if ($size == '/') { $size = ''; } if ($wml) { $before = ''; $after = ''; if ($size != '') { if (floatval($size) >= 1.5) { $before = '<big>'; $after = '</big>'; } elseif (floatval($size) < 0.8) { $before = '<small>'; $after = '</small>'; } } $temp_tpl->attach($before); $temp_tpl->attach($embed); $temp_tpl->attach($after); break; } if ($color != '') { $color = 'color: ' . $color . ';'; } if ($size != '') { if (is_numeric($size)) { $size = 'font-size: ' . $size . 'em;'; } elseif (substr($size, 0, 1) == '+') { $size = 'font-size: ' . substr($size, 1) . 'em'; } elseif (substr($size, -1) == '%') { $size = 'font-size: ' . float_to_raw_string(floatval(substr($size, 0, strlen($size) - 1)) / 100.0) . 'em'; } elseif (substr($size, -2) == 'of') { $new_size = '1em'; switch ($size) { case '1of': $new_size = '8pt'; break; case '2of': $new_size = '10pt'; break; case '3of': $new_size = '12pt'; break; case '4of': $new_size = '14pt'; break; case '5of': $new_size = '18pt'; break; case '6of': $new_size = '24pt'; break; case '7of': $new_size = '36pt'; break; } $size = 'font-size: ' . $new_size; } else { $size = 'font-size: ' . $size; } } if ($face != '') { $face = 'font-family: ' . str_replace('\'', '', $face) . ';'; } $size_len = strlen($size); filter_html($as_admin, $source_member, 0, $size_len, $size, false, false); $color_len = strlen($color); filter_html($as_admin, $source_member, 0, $color_len, $color, false, false); $face_len = strlen($face); filter_html($as_admin, $source_member, 0, $face_len, $face, false, false); $temp_tpl = do_template('COMCODE_FONT', array('_GUID' => 'f5fcafe737b8fdf466a6a51773e09c9b', 'CONTENT' => $embed, 'SIZE' => $size, 'COLOR' => $color, 'FACE' => $face)); break; case 'box': if ($wml) { $temp_tpl->attach('<br /><p>'); if ($attributes['param'] != '') { $temp_tpl->attach('<big>'); $temp_tpl->attach($attributes['param']); $temp_tpl->attach('</big><br /><br />'); } $temp_tpl->attach($embed); $temp_tpl->attach('</p></br />'); break; } // Legacy parameter. There used to be 'place' and 'nowrap' and 'class', but these are now gone. $breadth = array_key_exists('breadth', $attributes) ? $attributes['breadth'] : '100%'; if ($breadth == 'WIDE') { $breadth = '100%'; } if ($breadth == 'WIDE_HIGH') { $breadth = '100%'; } if ($breadth == 'THIN') { $breadth = 'auto'; } // The new versions $dimensions = array_key_exists('dimensions', $attributes) ? comcode_to_tempcode($attributes['dimensions'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member) : make_string_tempcode($breadth); $type = array_key_exists('type', $attributes) ? $attributes['type'] : ''; $options = array_key_exists('options', $attributes) ? $attributes['options'] : ''; $meta = $comcode_dangerous && array_key_exists('meta', $attributes) ? $attributes['meta'] : ''; //Insecure, unneeded here $links = $comcode_dangerous && array_key_exists('links', $attributes) ? $attributes['links'] : ''; //Insecure, unneeded here $converted = is_object($attributes['param']) ? $attributes['param'] : comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); $temp_tpl = directive_tempcode('BOX', $embed, array($converted, $dimensions, make_string_tempcode($type), make_string_tempcode($options), make_string_tempcode($meta), make_string_tempcode($links))); if (array_key_exists('float', $attributes)) { $temp_tpl = do_template('FLOATER', array('_GUID' => '54e8fc9ec1e16cfc5c8824e22f1e8745', 'FLOAT' => $attributes['float'], 'CONTENT' => $temp_tpl)); } break; case 'concept': if ($wml) { $temp_tpl = $embed; break; } if (!array_key_exists('param', $attributes) || $attributes['param'] == '') { $key = $embed->evaluate(); $temp_tpl = symbol_tempcode('DISPLAY_CONCEPT', array($key)); } else { $temp_tpl = do_template('COMCODE_CONCEPT_INLINE', array('_GUID' => '381a59de4d6f8967446c12bf4641a9ce', 'TEXT' => $embed, 'FULL' => $attributes['param'])); } break; case 'concepts': if ($wml) { break; } $title = $embed->evaluate(); $concepts = new ocp_tempcode(); foreach ($attributes as $_key => $_value) { if (substr($_key, -4) == '_key') { $key = $_value; $cid = substr($_key, 0, strlen($_key) - 4); $to_parse = array_key_exists($cid . '_value', $attributes) ? $attributes[$cid . '_value'] : new ocp_tempcode(); $value = is_object($to_parse) ? $to_parse : comcode_to_tempcode($to_parse, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); $concepts->attach(do_template('COMCODE_CONCEPTS_CONCEPT', array('_GUID' => '4baf6dabc32146c594c7fd922791b6b2', 'A' => 'concept___' . preg_replace('#[^\\w]#', '_', $key), 'KEY' => $key, 'VALUE' => $value))); } } $temp_tpl = do_template('COMCODE_CONCEPTS', array('_GUID' => '4c7a1d70753dc1d209b9951aa10f361a', 'TITLE' => $title, 'CONCEPTS' => $concepts)); break; case 'exp_ref': if ($wml) { break; } $_embed = $embed->evaluate(); if (strpos($_embed, '.') !== false) { break; } $stub = get_file_base() . '/data_custom/images/' . get_zone_name() . '/'; $stub2 = get_base_url() . '/data_custom/images/' . get_zone_name() . '/'; if (!file_exists($stub)) { $stub = get_file_base() . '/data/images/' . get_zone_name() . '/'; $stub2 = get_base_url() . '/data/images/' . get_zone_name() . '/'; } if (!file_exists($stub)) { $stub = get_file_base() . '/data_custom/images/'; $stub2 = get_base_url() . '/data_custom/images/'; } if (!file_exists($stub)) { $stub = get_file_base() . '/data/images/'; $stub2 = get_base_url() . '/data/images/'; } if (substr($_embed, 0, 1) == '/') { $_embed = substr($_embed, 1); } if (file_exists($stub . $_embed . '.png')) { $url = $stub2 . $_embed . '.png'; } elseif (file_exists($stub . $_embed . '.gif')) { $url = $stub2 . $_embed . '.gif'; } elseif (file_exists($stub . $_embed . '.jpg')) { $url = $stub2 . $_embed . '.jpg'; } elseif (file_exists($stub . $_embed . '.jpeg')) { $url = $stub2 . $_embed . '.jpeg'; } else { $stub = get_file_base() . '/data/images/docs/'; $stub2 = get_base_url() . '/data/images/docs/'; if (substr($_embed, 0, 1) == '/') { $_embed = substr($_embed, 1); } if (file_exists($stub . $_embed . '.png')) { $url = $stub2 . $_embed . '.png'; } elseif (file_exists($stub . $_embed . '.gif')) { $url = $stub2 . $_embed . '.gif'; } elseif (file_exists($stub . $_embed . '.jpg')) { $url = $stub2 . $_embed . '.jpg'; } elseif (file_exists($stub . $_embed . '.jpeg')) { $url = $stub2 . $_embed . '.jpeg'; } else { $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('MISSING_RESOURCE_COMCODE', 'exp_ref', escape_html($_embed)))); if (array_key_exists('COMCODE_BROKEN_URLS', $GLOBALS)) { $GLOBALS['COMCODE_BROKEN_URLS'][] = array($_embed, NULL); } elseif (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe')) { require_code('failure'); relay_error_notification(do_lang('MISSING_RESOURCE_COMCODE', 'exp_ref', $_embed), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference'); } break; } } $text = make_string_tempcode($attributes['param']); if ($text->is_empty()) { $text = do_lang_tempcode('EXAMPLE'); } $temp_tpl = do_template('COMCODE_EXP_REF', array('_GUID' => '89e7f528e72096e3458d6acb70734d0b', 'TEXT' => $text, 'URL' => $url)); break; case 'exp_thumb': if ($wml) { break; } $_embed = $embed->evaluate(); if (strpos($_embed, '.') !== false) { break; } $stub = get_file_base() . '/data/images/' . get_zone_name() . '/'; $stub2 = get_base_url() . '/data/images/' . get_zone_name() . '/'; if (substr($_embed, 0, 1) == '/') { $_embed = substr($_embed, 1); } if (file_exists($stub . $_embed . '.png')) { $url_full = $stub2 . $_embed . '.png'; } elseif (file_exists($stub . $_embed . '.gif')) { $url_full = $stub2 . $_embed . '.gif'; } elseif (file_exists($stub . $_embed . '.jpg')) { $url_full = $stub2 . $_embed . '.jpg'; } elseif (file_exists($stub . $_embed . '.jpeg')) { $url_full = $stub2 . $_embed . '.jpeg'; } else { $stub = get_file_base() . '/data/images/docs/'; $stub2 = get_base_url() . '/data/images/docs/'; if (substr($_embed, 0, 1) == '/') { $_embed = substr($_embed, 1); } if (file_exists($stub . $_embed . '.png')) { $url_full = $stub2 . $_embed . '.png'; } elseif (file_exists($stub . $_embed . '.gif')) { $url_full = $stub2 . $_embed . '.gif'; } elseif (file_exists($stub . $_embed . '.jpg')) { $url_full = $stub2 . $_embed . '.jpg'; } elseif (file_exists($stub . $_embed . '.jpeg')) { $url_full = $stub2 . $_embed . '.jpeg'; } else { $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('MISSING_RESOURCE_COMCODE', 'exp_thumb', escape_html($_embed)))); if (array_key_exists('COMCODE_BROKEN_URLS', $GLOBALS)) { $GLOBALS['COMCODE_BROKEN_URLS'][] = $_embed; } elseif (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe')) { require_code('failure'); relay_error_notification(do_lang('MISSING_RESOURCE_COMCODE', 'exp_thumb', $_embed), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference'); } break; } } $float = array_key_exists('float', $attributes) ? $attributes['float'] : 'right'; $text = $attributes['param']; if (get_option('is_on_gd') == '0' || !function_exists('imagetypes')) { $url_thumb = $url_full; } else { $new_name = $_embed . '_thumb.png'; $file_thumb = $stub . $new_name; if (file_exists($file_thumb)) { $url_thumb = $stub2 . rawurlencode($new_name); } else { $new_name = $_embed . '.png'; $file_thumb = get_custom_file_base() . '/uploads/auto_thumbs/' . $new_name; if (!file_exists($file_thumb)) { require_code('images'); convert_image($url_full, $file_thumb, -1, -1, 150, false); } $url_thumb = get_custom_base_url() . '/uploads/auto_thumbs/' . rawurlencode($new_name); } } if (get_param_integer('wide_print', 0) == 1) { $temp_tpl = do_template('COMCODE_EXP_THUMB_PRINT', array('_GUID' => 'de7f8a7fa29c2335f381a0beb3da9406', 'FLOAT' => $float, 'TEXT' => $text, 'URL_THUMB' => $url_thumb, 'URL_FULL' => $url_full)); } else { $temp_tpl = do_template('COMCODE_EXP_THUMB', array('_GUID' => 'ce7f8a7fa29c2335f381a0beb3da9406', 'FLOAT' => $float, 'TEXT' => $text, 'URL_THUMB' => $url_thumb, 'URL_FULL' => $url_full)); } break; case 'thumb': if ($wml) { break; } $_embed = $embed->evaluate(); $_embed = remove_url_mistakes($_embed); $_embed = check_naughty_javascript_url($source_member, $_embed, $as_admin); if (substr($_embed, 0, 1) == '/') { $_embed = substr($_embed, 1); } if (url_is_local($_embed)) { if (file_exists(get_file_base() . '/' . $_embed) && !file_exists(get_custom_file_base() . '/' . $_embed)) { $url_full = get_base_url() . '/' . $_embed; } else { $url_full = get_custom_base_url() . '/' . $_embed; } } else { $url_full = $_embed; } $align = array_key_exists('align', $attributes) ? $attributes['align'] : 'bottom'; if (get_option('is_on_gd') == '0' || !function_exists('imagetypes') || !has_specific_permission($source_member, 'draw_to_server') && !$as_admin) { $url_thumb = $url_full; } else { if ($attributes['param'] != '') { $url_thumb = url_is_local($attributes['param']) ? get_custom_base_url() . '/' . $attributes['param'] : $attributes['param']; } if ($attributes['param'] == '' || url_is_local($attributes['param']) && !file_exists(get_custom_file_base() . '/' . rawurldecode($attributes['param']))) { $new_name = url_to_filename($url_full); require_code('images'); if (!is_saveable_image($new_name)) { $new_name .= '.png'; } if (is_null($new_name)) { $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('URL_THUMB_TOO_LONG'))); break; } $file_thumb = get_custom_file_base() . '/uploads/auto_thumbs/' . $new_name; if (!file_exists($file_thumb) && strpos($file_thumb, '{$') === false) { convert_image($url_full, $file_thumb, -1, -1, intval(get_option('thumb_width')), false); } $url_thumb = get_custom_base_url() . '/uploads/auto_thumbs/' . rawurlencode($new_name); } } $caption = array_key_exists('caption', $attributes) ? $attributes['caption'] : ''; $temp_tpl = do_template('COMCODE_THUMB', array('_GUID' => '1b0d25f72ef5f816091269e29c586d60', 'CAPTION' => $caption, 'RAND' => strval(mt_rand(0, 32000)), 'ALIGN' => $align, 'PASS_ID' => intval($pass_id) < 0 ? strval(mt_rand(0, 10000)) : $pass_id, 'URL_THUMB' => $url_thumb, 'URL_FULL' => $url_full)); if (array_key_exists('float', $attributes)) { $temp_tpl = do_template('FLOATER', array('_GUID' => 'cbc56770714a44f56676f43da282cc7a', 'FLOAT' => $attributes['float'], 'CONTENT' => $temp_tpl)); } break; case 'img': if ($wml) { break; } if ($semiparse_mode && array_key_exists('rollover', $attributes)) { $temp_tpl = make_string_tempcode('[img' . reinsert_parameters($attributes) . ']' . $embed->evaluate() . '[/img]'); break; } $_embed = $embed->evaluate(); $given_url = $_embed; $_embed = remove_url_mistakes($_embed); if (substr($_embed, 0, 1) == '/') { $_embed = substr($_embed, 1); } $_embed = check_naughty_javascript_url($source_member, $_embed, $as_admin); if (url_is_local($_embed)) { if (file_exists(get_file_base() . '/' . $_embed) && !file_exists(get_custom_file_base() . '/' . $_embed)) { $url_full = get_base_url() . '/' . $_embed; } else { $url_full = get_custom_base_url() . '/' . $_embed; } } else { $url_full = $_embed; } $temp_tpl = test_url($url_full, 'img', @html_entity_decode($given_url, ENT_QUOTES, get_charset()), $source_member); $align = array_key_exists('align', $attributes) ? $attributes['align'] : ''; $caption = is_object($attributes['param']) ? $attributes['param'] : comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); if (array_key_exists('title', $attributes)) { $tooltip = is_object($attributes['title']) ? $attributes['title'] : comcode_to_tempcode($attributes['title'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); } else { $tooltip = $caption; } $rollover = array_key_exists('rollover', $attributes) ? $attributes['rollover'] : NULL; if (!is_null($rollover) && url_is_local($rollover)) { if (file_exists(get_file_base() . '/' . $rollover) && !file_exists(get_custom_file_base() . '/' . $rollover)) { $rollover = get_base_url() . '/' . $rollover; } else { $rollover = get_custom_base_url() . '/' . $rollover; } } $refresh_time = array_key_exists('refresh_time', $attributes) ? strval(intval($attributes['refresh_time'])) : '0'; $temp_tpl->attach(do_template('COMCODE_IMG', array('_GUID' => '70166d8dbb0aff064b99c0dd30ed77a8', 'RAND' => uniqid('', true), 'REFRESH_TIME' => $refresh_time, 'ROLLOVER' => $rollover, 'ALIGN' => $align, 'URL' => $url_full, 'TOOLTIP' => $tooltip, 'CAPTION' => $caption))); if (array_key_exists('float', $attributes)) { $temp_tpl = do_template('FLOATER', array('_GUID' => '918162250c80e10212efd9a051545b9b', 'FLOAT' => $attributes['float'], 'CONTENT' => $temp_tpl)); } break; case 'flash': if ($wml) { break; } $_embed = $embed->evaluate(); $given_url = $_embed; $_embed = remove_url_mistakes($_embed); if (substr($_embed, 0, 1) == '/') { $_embed = substr($_embed, 1); } $_embed = check_naughty_javascript_url($source_member, $_embed, $as_admin); $url_full = url_is_local($_embed) ? get_custom_base_url() . '/' . $_embed : $_embed; $temp_tpl = test_url($url_full, 'flash', @html_entity_decode($given_url, ENT_QUOTES, get_charset()), $source_member); if ($attributes['param'] == '' || strpos($attributes['param'], 'x') === false) { if (!array_key_exists('width', $attributes)) { $attributes['width'] = '300'; } if (!array_key_exists('height', $attributes)) { $attributes['height'] = '300'; } $attributes['param'] = $attributes['width'] . 'x' . $attributes['height']; } list($width, $height) = explode('x', $attributes['param'], 2); if (addon_installed('jwplayer') && (substr($url_full, -4) == '.flv' || substr($url_full, -4) == '.mp4' || substr($url_full, -4) == '.mp3' || substr($url_full, -4) == '.webm')) { $temp_tpl->attach(do_template('COMCODE_FLV', array('_GUID' => '4746684d9e098709cc6671e1b00ce47e', 'URL' => $url_full, 'WIDTH' => $width, 'HEIGHT' => $height))); } else { $temp_tpl->attach(do_template('COMCODE_SWF', array('_GUID' => '8bc61ad75977a5a85eff96454af31fe8', 'URL' => $url_full, 'WIDTH' => $width, 'HEIGHT' => $height))); } break; case 'url': // Make them both HTML strings $url = $embed->evaluate(); if (is_object($attributes['param'])) { $switch_over = true; // We know if must be Comcode XML $attributes['param'] = $attributes['param']->evaluate(); } else { $switch_over = !looks_like_url($url) && looks_like_url($attributes['param'], true); if (strpos($attributes['param'], '[') !== false || strpos($attributes['param'], '{') !== false) { $param_temp = comcode_to_tempcode(escape_html($attributes['param']), $source_member, $as_admin, 60, NULL, $connection, false, false, true, false, false, $highlight_bits, $on_behalf_of_member); global $ADVERTISING_BANNERS; $temp_ab = $ADVERTISING_BANNERS; $ADVERTISING_BANNERS = array(); $caption = $param_temp; $ADVERTISING_BANNERS = $temp_ab; } else { $caption = make_string_tempcode(escape_html($attributes['param'])); // Consistency of escaping } } // Do we need to switch around? if ($switch_over) { $url = $attributes['param']; $caption = $embed; } // If we weren't given a caption, use the URL, but crop if necessary if ($caption->evaluate() == '') { $_caption = $url; // Shorten the URL if it is too long $max_link_length = 50; if (strlen($_caption) > $max_link_length) { $_caption = escape_html(substr(@html_entity_decode($_caption, ENT_QUOTES, get_charset()), 0, intval($max_link_length / 2 - 3))) . '…' . escape_html(substr(@html_entity_decode($_caption, ENT_QUOTES, get_charset()), intval(-$max_link_length / 2))); } $caption = make_string_tempcode($_caption); } // Tidy up the URL now $url = @html_entity_decode($url, ENT_QUOTES, get_charset()); $url = fixup_protocolless_urls($url); // Integrity and security $url = check_naughty_javascript_url($source_member, $url, $as_admin); // More URL tidying $local = url_is_local($url) || strpos($url, get_domain()) !== false; $given_url = $url; if ($url != '' && $url[0] != '#') { if (substr($url, 0, 1) == '/') { $url = substr($url, 1); } $url_full = url_is_local($url) ? get_base_url() . '/' . $url : $url; if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($url_full); } } else { $url_full = $url; } $striped_base_url = str_replace('www.', '', str_replace('http://', '', get_base_url())); if ($striped_base_url != '' && substr($url, 0, 1) != '%' && strpos($url_full, $striped_base_url) === false) { $temp_tpl = test_url($url_full, 'url', $given_url, $source_member); } // Render if (!array_key_exists('target', $attributes)) { $attributes['target'] = $local ? '_top' : '_blank'; } if ($attributes['target'] == 'blank') { $attributes['target'] = '_blank'; } $rel = $as_admin || has_specific_permission($source_member, 'search_engine_links') ? '' : 'nofollow'; if ($attributes['target'] == '_blank') { $title = (is_object($caption) ? static_evaluate_tempcode($caption) : $caption) . ' ' . do_lang('LINK_NEW_WINDOW'); } else { $title = ''; } $temp_tpl->attach(do_template('COMCODE_URL', array('_GUID' => 'd1657530e6d3d57e6a4791fb3bfa0dd7', 'TITLE' => $title, 'REL' => $rel, 'TARGET' => $attributes['target'], 'URL' => $url_full, 'CAPTION' => $caption))); break; case 'email': $_embed = $embed->evaluate(); require_code('type_validation'); require_code('obfuscate'); // If we need to switch if (is_object($attributes['param']) || !is_valid_email_address($_embed) && is_valid_email_address($attributes['param'])) { $temp = $embed; // Is tempcode $_embed = $attributes['param']; $attributes['param'] = $temp; } else { $attributes['param'] = comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); // Becomes tempcode } if ($attributes['param']->is_empty()) { $attributes['param'] = obfuscate_email_address($_embed); } $subject = array_key_exists('subject', $attributes) ? $attributes['subject'] : ''; $body = array_key_exists('body', $attributes) ? $attributes['body'] : ''; $title = ''; if (array_key_exists('title', $attributes)) { $title = $attributes['title']; } $temp_tpl = do_template('COMCODE_EMAIL', array('_GUID' => '5f6ade8fe07701b6858575153d78f4e9', 'TITLE' => $title, 'ADDRESS' => obfuscate_email_address($_embed), 'SUBJECT' => $subject, 'BODY' => $body, 'CAPTION' => $attributes['param'])); break; case 'reference': if ($wml) { break; } if (array_key_exists('type', $attributes) && $attributes['type'] == 'url') { $_embed = $embed->evaluate(); $_embed = check_naughty_javascript_url($source_member, $_embed, $as_admin); if (!array_key_exists('title', $attributes)) { $attributes['title'] = $attributes['param']; } if (is_object($attributes['title']) || $attributes['title'] != '') { $_title = is_object($attributes['title']) ? make_string_tempcode(escape_html($attributes['title'])) : comcode_to_tempcode($attributes['title'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); $title = $_title->evaluate(); } else { $title = $_embed; } $embed = hyperlink($_embed, $title, true); } $temp_tpl = do_template('COMCODE_REFERENCE', array_merge($attributes, array('SOURCE' => $embed))); break; case 'upload': // This points to a file path, not a URL $_embed = $embed->evaluate(); $type = array_key_exists('type', $attributes) ? $attributes['type'] : 'downloads'; if (is_object($attributes['param']) || $attributes['param'] != '') { $_caption = is_object($attributes['param']) ? make_string_tempcode(escape_html($attributes['param'])) : comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); $__caption = $_caption->evaluate(); } else { $__caption = $_embed; } $url = get_custom_base_url() . '/' . $type . '/' . rawurlencode($_embed); $url = check_naughty_javascript_url($source_member, $url, $as_admin); $temp_tpl = test_url($url, 'upload', $_embed, $source_member); $temp_tpl->attach(hyperlink($url, $__caption)); break; case 'page': $ignore_if_hidden = array_key_exists('ignore_if_hidden', $attributes) && $attributes['ignore_if_hidden'] == '1'; unset($attributes['ignore_if_hidden']); // Two sets of parameters: simple style and complex style; both are completely incompatible $hash = ''; if ($attributes == array('param' => '')) { $zone = '_SEARCH'; $caption = $embed; $attributes = array('page' => $caption->evaluate()); } elseif (array_keys($attributes) == array('param')) { $caption = $embed; if ($wml) { $temp_tpl = $embed; break; } else { if (strpos($attributes['param'], ':') !== false) { global $OVERRIDE_SELF_ZONE; $page_link = $attributes['param']; list($zone, $attributes, $hash) = page_link_decode($page_link); if (!array_key_exists('page', $attributes)) { $attributes['page'] = ''; } if ($zone == '_SELF' && !is_null($OVERRIDE_SELF_ZONE)) { $zone = $OVERRIDE_SELF_ZONE; } } else { $zone = '_SEARCH'; // Changed in v3 from '_SELF', to allow context-sensitivity $attributes = array_merge(array('page' => $attributes['param']), $attributes); } } } else { $caption = array_key_exists('caption', $attributes) ? comcode_to_tempcode($attributes['caption'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member) : $embed; if ($wml) { $temp_tpl = $caption; break; } else { $zone = $param_given ? $attributes['param'] : '_SEARCH'; // Changed in v3 from '_SELF', to allow context-sensitivity unset($attributes['caption']); if (!array_key_exists('page', $attributes)) { $attributes = array_merge(array('page' => $embed->evaluate()), $attributes); } } } unset($attributes['param']); foreach ($attributes as $key => $val) { if (is_object($val)) { $attributes[$key] = $val->evaluate(); } } if ($zone == '_SEARCH') { $zone = get_page_zone($attributes['page'], false); if (is_null($zone)) { $zone = ''; } } $pl_url = build_url($attributes, $zone, NULL, false, false, false, $hash); $temp_tpl = hyperlink($pl_url, $caption); $page = $attributes['page']; if ($page != '') { if ($zone == '_SELF') { $zone = get_zone_name(); } if ($zone == '_SEARCH') { $zone = get_page_zone($page, false); if (is_null($zone)) { $zone = ''; } // Oh dear, well it will be correctly identified as not found anyway } $ptest = _request_page($page, $zone); if ($ptest !== false) { if ($page == 'topicview' && array_key_exists('id', $attributes)) { if (!is_numeric($attributes['id'])) { $attributes['id'] = $GLOBALS['SITE_DB']->query_value_null_ok('url_id_monikers', 'm_resource_id', array('m_resource_page' => $page, 'm_moniker' => $attributes['id'])); } if (!is_null($attributes['id'])) { $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_topics', 'id', array('id' => $attributes['id'])); if (is_null($test)) { $ptest = false; } } else { $ptest = false; } } } if ($ptest === false) { //$temp_tpl->attach(' ['.do_lang('MISSING_RESOURCE').']'); // Don't want this as we might be making the page immediately if (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !in_array($page, $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe')) { if ($ignore_if_hidden) { $temp_tpl = do_template('COMCODE_DEL', array('CONTENT' => $caption)); } else { require_code('failure'); relay_error_notification(do_lang('MISSING_RESOURCE_COMCODE', 'page_link', $page_link), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference'); } } } } break; case 'hide': if ($wml) { $temp_tpl = $embed; break; } if (array_key_exists('param', $attributes)) { $text = is_object($attributes['param']) ? $attributes['param'] : comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member); } else { $text = do_lang_tempcode('EXPAND'); } $temp_tpl = do_template('COMCODE_HIDE', array('_GUID' => 'a591a0d1e6bb3dde0f22cebb9c7ab93e', 'TEXT' => $text, 'CONTENT' => $embed)); break; case 'quote': if ($wml) { $temp_tpl->attach('<br /><br />' . $attributes['param'] . ':'); $temp_tpl->attach($embed); break; } $cite = array_key_exists('cite', $attributes) ? $attributes['cite'] : NULL; if (!is_null($cite)) { $temp_tpl = test_url($cite, 'quote', $cite, $source_member); } if ($attributes['param'] == '' && isset($attributes['author'])) { $attributes['param'] = $attributes['author']; } // Compatibility with SMF if ($attributes['param'] != '') { if (is_numeric($attributes['param'])) { $attributes['param'] = $GLOBALS['FORUM_DRIVER']->get_username($attributes['param']); if (is_null($attributes['param'])) { $attributes['param'] = do_lang('UNKNOWN'); } } else { $attributes['param'] = protect_from_escaping(comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member)); } $temp_tpl->attach(do_template('COMCODE_QUOTE_BY', array('_GUID' => '18f55a548892ad08b0b50b3b586b5b95', 'CITE' => $cite, 'CONTENT' => $embed, 'BY' => $attributes['param'], 'SAIDLESS' => array_key_exists('saidless', $attributes) ? $attributes['saidless'] : '0'))); } else { $temp_tpl->attach(do_template('COMCODE_QUOTE', array('_GUID' => 'fa275de59433c17da19b22814c17fdc5', 'CITE' => $cite, 'CONTENT' => $embed))); } break; case 'html': if ($wml) { break; } $temp_tpl = $embed; // Plain HTML. But it's been filtered already break; case 'semihtml': $temp_tpl = $embed; // Hybrid HTML. But it's been filtered already break; case 'block': if ($wml) { break; } $attributes['block'] = trim($embed->evaluate()); if (preg_match('#^[\\w\\-]*$#', $attributes['block']) == 0) { $temp_tpl = paragraph(do_lang_tempcode('MISSING_BLOCK_FILE', escape_html($attributes['block'])), '90dfdlksds8d7dyddssddxs', 'error_marker'); break; // Avoids a suspected hack attempt by just filtering early } $_attributes = array(); foreach ($attributes as $key => $val) { $_attributes[] = $key . '=' . $val; } $temp_tpl = symbol_tempcode('BLOCK', $_attributes); break; case 'contents': if ($wml) { break; } // Do structure sweep $urls_for = array(); $old_structure_list = $STRUCTURE_LIST; $STRUCTURE_LIST = array(); // reset for e.g. comcode_text_to_tempcode calls (which don't itself reset it, although _comcode_to_tempcode does for top level parses) if (array_key_exists('files', $attributes) && $comcode_dangerous) { $s_zone = array_key_exists('zone', $attributes) ? $attributes['zone'] : get_zone_name(); $pages = find_all_pages($s_zone, 'comcode_custom/' . get_site_default_lang(), 'txt') + find_all_pages($s_zone, 'comcode/' . get_site_default_lang(), 'txt'); $prefix = $attributes['files']; foreach ($pages as $pg_name => $pg_type) { if (substr($pg_name, 0, strlen($prefix)) == $prefix) { $i = count($STRUCTURE_LIST); comcode_to_tempcode(file_get_contents(zone_black_magic_filterer(get_file_base() . '/' . $s_zone . '/pages/' . $pg_type . '/' . $pg_name . '.txt'), FILE_TEXT), $source_member, $as_admin, 60, NULL, $connection, false, false, false, true, false, NULL, $on_behalf_of_member); $page_url = build_url(array('page' => $pg_name), $s_zone); while (array_key_exists($i, $STRUCTURE_LIST)) { $urls_for[] = $page_url; $i++; } } } $base = array_key_exists('base', $attributes) ? intval($attributes['base']) : 1; } else { if (substr($comcode, 0, 8) == '<comcode') { require_code('comcode_xml'); if (!$as_admin) { check_specific_permission('comcode_dangerous', NULL, $source_member); } $_ = new comcode_xml_to_tempcode($comcode, $source_member, 60, NULL, $connection, false, false, false, true, false, $on_behalf_of_member); } else { require_code('comcode_text'); comcode_text_to_tempcode($comcode, $source_member, $as_admin, 60, NULL, $connection, false, false, false, true, false, NULL, $on_behalf_of_member); } $base = array_key_exists('base', $attributes) ? intval($attributes['base']) : 1; } $list_types = $embed->evaluate() == '' ? array() : explode(',', $embed->evaluate()); $list_types += array('decimal', 'lower-alpha', 'lower-roman', 'upper-alpha', 'upper-roman', 'disc'); $levels_allowed = array_key_exists('levels', $attributes) ? intval($attributes['levels']) : NULL; // Convert the list structure into a tree structure $past_level_stack = array(1); $subtree_stack = array(array()); $levels = 1; foreach ($STRUCTURE_LIST as $i => $struct) { $level = $struct[0]; $title = $struct[1]; $uniq_id = $struct[2]; $url = array_key_exists($i, $urls_for) ? $urls_for[$i] : ''; if ($level > $levels_allowed && !is_null($levels_allowed)) { continue; } // Going down the tree if ($level > $past_level_stack[$levels - 1]) { array_push($past_level_stack, $level); array_push($subtree_stack, array(array($uniq_id, $title->evaluate(), $url))); $levels++; } else { // Going back up the tree, destroying levels that must have now closed off while ($level < $past_level_stack[$levels - 1] && $levels > 2) { array_pop($past_level_stack); $subtree = array_pop($subtree_stack); $levels--; // Alter the last of the next level on stack so it is actually taking the closed off level as children, and changing from a property list to a pair: property list & children $subtree_stack[$levels - 1][count($subtree_stack[$levels - 1]) - 1] = array($subtree_stack[$levels - 1][count($subtree_stack[$levels - 1]) - 1], $subtree); } // Store the title where we are $subtree_stack[$levels - 1][] = array($uniq_id, $title->evaluate(), $url); } } // Clean up... going up until we're with 1 while ($levels > 1) { array_pop($past_level_stack); $subtree = array_pop($subtree_stack); $levels--; $parent_level_start_index = count($subtree_stack[$levels - 1]) - 1; if ($parent_level_start_index < 0) { $subtree_stack[$levels - 1] = $subtree; } else { $subtree_stack[$levels - 1][$parent_level_start_index] = array($subtree_stack[$levels - 1][$parent_level_start_index], $subtree); } } // Now we have the structure to display $levels_t = _do_contents_level($subtree_stack[0], $list_types, $base); $temp_tpl = do_template('COMCODE_CONTENTS', array('_GUID' => 'ca2f5320fa930e2257a2e74e4f98e5a0', 'LEVELS' => $levels_t)); $STRUCTURE_LIST = $old_structure_list; // Restore, so subsequent 'title' tags have correct numbering break; } // Last ditch effort: custom tags if ($temp_tpl->is_definitely_empty() && !$wml) { global $REPLACE_TARGETS; if (array_key_exists($tag, $REPLACE_TARGETS)) { $replace = $REPLACE_TARGETS[$tag]['replace']; $parameters = explode(',', $REPLACE_TARGETS[$tag]['parameters']); $binding = array('CONTENT' => $embed, 'RAND' => uniqid('', true)); foreach ($parameters as $parameter) { $parameter = trim($parameter); $parts = explode('=', $parameter); if (count($parts) == 1) { $parts[] = ''; } if (count($parts) != 2) { continue; } list($parameter, $default) = $parts; if (!array_key_exists($parameter, $attributes) || $attributes[$parameter] == '') { $attributes[$parameter] = $default; } $binding[strtoupper($parameter)] = $attributes[$parameter]; $replace = str_replace('{' . $parameter . '}', '{' . strtoupper($parameter) . '*}', $replace); } $replace = str_replace('{content}', array_key_exists($tag, $GLOBALS['TEXTUAL_TAGS']) ? '{CONTENT}' : '{CONTENT*}', $replace); require_code('tempcode_compiler'); $temp_tpl = template_to_tempcode($replace); $temp_tpl = $temp_tpl->bind($binding, '(custom comcode: ' . $tag . ')'); } } return $temp_tpl; }
/** * Standard modular run function for search results. * * @param string Search string * @param boolean Whether to only do a META (tags) search * @param ID_TEXT Order direction * @param integer Start position in total results * @param integer Maximum results to return in total * @param boolean Whether only to search titles (as opposed to both titles and content) * @param string Where clause that selects the content according to the main search string (SQL query fragment) (blank: full-text search) * @param SHORT_TEXT Username/Author to match for * @param ?MEMBER Member-ID to match for (NULL: unknown) * @param TIME Cutoff date * @param string The sort type (gets remapped to a field in this function) * @set title add_date * @param integer Limit to this number of results * @param string What kind of boolean search to do * @set or and * @param string Where constraints known by the main search code (SQL query fragment) * @param string Comma-separated list of categories to search under * @param boolean Whether it is a boolean search * @return array List of maps (template, orderer) */ function run($content, $only_search_meta, $direction, $max, $start, $only_titles, $content_where, $author, $author_id, $cutoff, $sort, $limit_to, $boolean_operator, $where_clause, $search_under, $boolean_search) { $remapped_orderer = ''; switch ($sort) { case 'title': $remapped_orderer = 'the_page'; break; case 'add_date': $remapped_orderer = 'the_zone'; // Stucked break; } load_up_all_self_page_permissions(get_member()); $sq = build_search_submitter_clauses('p_submitter', $author_id, $author); if (is_null($sq)) { return array(); } else { $where_clause .= $sq; } if (!$GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())) { $where_clause .= ' AND '; $where_clause .= 'z.zone_name IS NOT NULL'; } if (strpos($content, 'panel_') === false) { $where_clause .= ' AND '; $where_clause .= '(r.the_page NOT LIKE \'' . db_encode_like('panel\\_%') . '\') AND (r.the_page NOT LIKE \'' . db_encode_like('\\_%') . '\')'; } if (!is_null($search_under) && $search_under != '!') { $where_clause .= ' AND '; $where_clause .= '(' . db_string_equal_to('r.the_zone', $search_under) . ')'; } if (!has_specific_permission(get_member(), 'see_unvalidated')) { $where_clause .= ' AND '; $where_clause .= 'p_validated=1'; } require_lang('zones'); $g_or = _get_where_clause_groups(get_member(), false); // Calculate and perform query if ($g_or == '') { $rows = get_search_rows('comcode_page', 'the_zone:the_page', $content, $boolean_search, $boolean_operator, $only_search_meta, $direction, $max, $start, $only_titles, 'cached_comcode_pages r LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'comcode_pages q ON (q.the_zone=r.the_zone AND q.the_page=r.the_page)', array('r.cc_page_title', 'r.string_index'), $where_clause, $content_where, $remapped_orderer, 'r.*'); } else { $rows = get_search_rows('comcode_page', 'the_zone:the_page', $content, $boolean_search, $boolean_operator, $only_search_meta, $direction, $max, $start, $only_titles, 'cached_comcode_pages r LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'comcode_pages q ON (q.the_zone=r.the_zone AND q.the_page=r.the_page) LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'group_zone_access z ON (z.zone_name=r.the_zone AND (' . str_replace('group_id', 'z.group_id', $g_or) . '))', array('r.cc_page_title', 'r.string_index'), $where_clause, $content_where, $remapped_orderer, 'r.*'); } if (addon_installed('redirects_editor')) { $redirects = $GLOBALS['SITE_DB']->query_select('redirects', array('*')); } else { $redirects = array(); } $out = array(); $pages_found = array(); foreach ($rows as $i => $row) { foreach ($redirects as $redirect) { if ($redirect['r_from_page'] == $row['the_page'] && $redirect['r_from_zone'] == $row['the_zone']) { continue 2; } } if ($row['the_zone'] == '!') { continue; } if (array_key_exists($row['the_zone'] . ':' . $row['the_page'], $pages_found)) { continue; } $pages_found[$row['the_zone'] . ':' . $row['the_page']] = 1; $out[$i]['data'] = $row + array('extra' => array($row['the_zone'], $row['the_page'], $limit_to)); if ($remapped_orderer != '' && array_key_exists($remapped_orderer, $row)) { $out[$i]['orderer'] = $row[$remapped_orderer]; } elseif (substr($remapped_orderer, 0, 7) == '_rating') { $out[$i]['orderer'] = $row['compound_rating']; } if (!has_page_access(get_member(), $row['the_page'], $row['the_zone'])) { $out[$i]['restricted'] = true; } } if ($author == '') { // Make sure we record that for all cached Comcode pages, we know of them (only those not cached would not have been under the scope of the current search) $all_pages = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('the_zone', 'the_page')); foreach ($all_pages as $row) { $pages_found[$row['the_zone'] . ':' . $row['the_page']] = 1; } // Now, look on disk for non-cached comcode pages $zones = find_all_zones(); $i = count($out); if (!is_null($search_under) && $search_under != '!') { $zones = array($search_under); } foreach ($zones as $zone) { if (!has_zone_access(get_member(), $zone)) { continue; } $pages = find_all_pages($zone, 'comcode/' . user_lang(), 'txt') + find_all_pages($zone, 'comcode_custom/' . user_lang(), 'txt') + find_all_pages($zone, 'comcode/' . get_site_default_lang(), 'txt') + find_all_pages($zone, 'comcode_custom/' . get_site_default_lang(), 'txt'); foreach ($pages as $page => $dir) { if (!is_string($page)) { $page = strval($page); } if (!array_key_exists($zone . ':' . $page, $pages_found)) { if (!has_page_access(get_member(), $page, $zone)) { continue; } if (strpos($content, 'panel_') === false) { if (substr($page, 0, 6) == 'panel_') { continue; } } if (substr($page, 0, 1) == '_') { continue; } foreach ($redirects as $redirect) { if ($redirect['r_from_page'] == $page && $redirect['r_from_zone'] == $zone) { continue 2; } } $path = zone_black_magic_filterer(($dir == 'comcode_custom' ? get_custom_file_base() : get_file_base()) . '/' . $zone . '/pages/' . $dir . '/' . $page . '.txt'); if (!is_null($cutoff) && filemtime($path) < $cutoff) { continue; } $contents = file_get_contents($path, FILE_TEXT); if ($only_titles) { $contents = preg_replace('#^.*\\[title(="1")?\\](.*)\\[/title\\].*$#Us', '${2}', $contents); } if (in_memory_search_match(array('content' => $content, 'conjunctive_operator' => $boolean_operator), $contents)) { $out[$i]['data'] = array('the_zone' => $zone, 'the_page' => $page) + array('extra' => array($zone, $page, $limit_to)); if ($remapped_orderer == 'the_page') { $out[$i]['orderer'] = $page; } elseif ($remapped_orderer == 'the_zone') { $out[$i]['orderer'] = $zone; } $i++; $GLOBALS['TOTAL_RESULTS']++; // Let it cache for next time if (get_option('is_on_comcode_page_cache') == '1') { request_page($page, false, $zone, $dir, false, true); } } } } } } return $out; }
/** * The actualiser to edit a comcode page. * * @return tempcode The UI */ function __ed() { $simple_add = get_param_integer('simple_add', 0) == 1; $title = get_page_title($simple_add ? 'COMCODE_PAGE_ADD' : 'COMCODE_PAGE_EDIT'); $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/comcode_page_edit'; $file = filter_naughty(post_param('file')); $lang = filter_naughty(post_param('lang')); $zone = filter_naughty(post_param('zone')); if (addon_installed('page_management')) { $new_file = filter_naughty(has_actual_page_access(get_member(), 'admin_sitetree') ? post_param('title', $file) : $file); } else { $new_file = filter_naughty($file); } if ($file == '') { $file = $new_file; } require_code('type_validation'); if (!is_alphanumeric($file, true)) { warn_exit(do_lang_tempcode('BAD_CODENAME')); } $fullpath = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . $lang . '/' . $file . '.txt'); $renaming_page = $new_file != $file; if ($renaming_page) { if (!is_alphanumeric($new_file, true)) { warn_exit(do_lang_tempcode('BAD_CODENAME')); } $langs = find_all_langs(true); $rename_map = array(); $afm_needed = false; // Actually will stay false as we don't allow renaming original-pages at the moment foreach (array_keys($langs) as $lang) { $path = zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/comcode_custom/' . $lang . '/' . $file . '.txt', true); if (is_file(get_file_base() . '/' . $path)) { $new_path = zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/comcode_custom/' . $lang . '/' . $new_file . '.txt', true); if (is_file($new_path)) { warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($zone . ':' . $new_file))); } $rename_map[$path] = $new_path; } if (is_file(get_file_base() . '/' . str_replace('/comcode_custom/', '/comcode/', $path))) { $completion_text = do_lang_tempcode('ORIGINAL_PAGE_NO_RENAME'); } } if ($afm_needed) { require_code('abstract_file_manager'); force_have_afm_details(); } } $validated = post_param_integer('validated', 0); if (!has_specific_permission(get_member(), 'bypass_validation_highrange_content')) { $validated = 0; } $parent_page = post_param('parent_page', ''); $show_as_edit = post_param_integer('show_as_edit', 0); $resource_owner = $GLOBALS['SITE_DB']->query_value_null_ok('comcode_pages', 'p_submitter', array('the_zone' => $zone, 'the_page' => $file)); check_edit_permission('high', $resource_owner); if ($GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())) { $_owner = post_param('owner', $GLOBALS['FORUM_DRIVER']->get_username(get_member())); $owner = $GLOBALS['FORUM_DRIVER']->get_member_from_username($_owner); if (is_null($owner)) { $owner = get_member(); } } else { $owner = get_member(); } if (is_null($resource_owner)) { check_submit_permission('high'); require_code('submit'); give_submit_points('COMCODE_PAGE_ADD'); if (!addon_installed('unvalidated')) { $validated = 1; } $GLOBALS['SITE_DB']->query_insert('comcode_pages', array('the_zone' => $zone, 'the_page' => $file, 'p_parent_page' => $parent_page, 'p_validated' => $validated, 'p_edit_date' => NULL, 'p_add_date' => time(), 'p_submitter' => $owner, 'p_show_as_edit' => 0)); } else { if (!has_actual_page_access(get_member(), $file, $zone)) { access_denied('PAGE_ACCESS'); } require_code('submit'); $just_validated = !content_validated('comcode_page', $zone . ':' . $file) && $validated == 1; if ($just_validated) { send_content_validated_notification('comcode_page', $zone . ':' . $file); } if (!addon_installed('unvalidated')) { $validated = 1; } $GLOBALS['SITE_DB']->query_update('comcode_pages', array('p_parent_page' => $parent_page, 'p_validated' => $validated, 'p_edit_date' => time(), 'p_submitter' => $owner, 'p_show_as_edit' => $show_as_edit), array('the_zone' => $zone, 'the_page' => $file), '', 1); } if ($validated == 0) { require_code('submit'); $edit_url = build_url(array('page' => '_SELF', 'type' => '_ed', 'page_link' => $zone . ':' . $new_file), '_SELF', NULL, false, false, true); if (addon_installed('unvalidated')) { send_validation_request('COMCODE_PAGE_EDIT', 'comcode_pages', true, $zone . ':' . $new_file, $edit_url); } } $new = post_param('post'); require_code('attachments2'); $_new = do_comcode_attachments($new, 'comcode_page', $zone . ':' . $file); $new = $_new['comcode']; if (!file_exists($fullpath) || $new != file_get_contents($fullpath, FILE_TEXT)) { $myfile = @fopen($fullpath, 'wt'); if ($myfile === false) { intelligent_write_error($fullpath); } final_attachments_from_preview($zone . ':' . $file); if (fwrite($myfile, $new) < strlen($new)) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } fclose($myfile); sync_file($fullpath); $file_changed = true; } else { $file_changed = false; } require_code('seo2'); $new_keywords = post_param('meta_keywords', ''); $new_description = post_param('meta_description', ''); if ($new_keywords == '' && $new_description == '') { seo_meta_set_for_implicit('comcode_page', $zone . ':' . $file, array($new), $new); } else { seo_meta_set_for_explicit('comcode_page', $zone . ':' . $file, $new_keywords, $new_description); } $completion_text = $validated == 0 ? do_lang_tempcode('SUBMIT_UNVALIDATED') : do_lang_tempcode('SUCCESS'); // Update cache NO WE CAN'T - THEY'RE MULTI-THEME NOW /* $string_index=$GLOBALS['SITE_DB']->query_value_null_ok('cached_comcode_pages','string_index',array('the_zone'=>$zone,'the_page'=>$file)); if (!is_null($string_index)) { lang_remap_comcode($string_index,$new); } else { $string_index=insert_lang_comcode($new,1,NULL,false,NULL,NULL,false,NULL,NULL,60,true,true); $GLOBALS['SITE_DB']->query_insert('cached_comcode_pages',array('the_zone'=>$zone,'the_page'=>$file,'string_index'=>$string_index)); }*/ require_code('permissions2'); set_page_permissions_from_environment($zone, $file); $caches = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index'), array('the_zone' => $zone, 'the_page' => $file)); $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => $zone, 'the_page' => $file)); foreach ($caches as $cache) { delete_lang($cache['string_index']); } persistant_cache_empty(); persistant_cache_delete(array('PAGE_INFO')); decache('main_comcode_page_children'); fix_permissions($fullpath); if (is_file($fullpath) && get_option('store_revisions') == '1' && $file_changed) { $time = time(); @copy($fullpath, $fullpath . '.' . strval($time)) or intelligent_write_error($fullpath . '.' . strval($time)); fix_permissions($fullpath . '.' . strval($time)); sync_file($fullpath . '.' . strval($time)); } log_it('COMCODE_PAGE_EDIT', $file, $zone); require_code('autosave'); clear_ocp_autosave(); if ($renaming_page) { $GLOBALS['SITE_DB']->query_delete('comcode_pages', array('the_zone' => $zone, 'the_page' => $new_file), '', 1); $GLOBALS['SITE_DB']->query_update('comcode_pages', array('the_page' => $new_file), array('the_zone' => $zone, 'the_page' => $file), '', 1); $GLOBALS['SITE_DB']->query_update('comcode_pages', array('p_parent_page' => $new_file), array('the_zone' => $zone, 'p_parent_page' => $file)); foreach ($rename_map as $path => $new_path) { if ($afm_needed) { afm_move($path, $new_path); } else { rename(get_custom_file_base() . '/' . $path, get_custom_file_base() . '/' . $new_path); } } if (addon_installed('awards')) { $types = $GLOBALS['SITE_DB']->query_select('award_types', array('id'), array('a_content_type' => 'comcode_page')); foreach ($types as $type) { $GLOBALS['SITE_DB']->query_update('award_archive', array('content_id' => $new_file), array('content_id' => $file, 'a_type_id' => $type['id'])); } } $file = $new_file; } if (post_param_integer('delete', 0) == 1) { unlink(get_custom_file_base() . '/' . $path); } if (addon_installed('awards')) { require_code('awards'); handle_award_setting('comcode_page', $zone . ':' . $file); } decache('main_sitemap'); breadcrumb_set_self(do_lang_tempcode('DONE')); // Look for bad title semantics $_new['html'] = $_new['tempcode']->evaluate(); if (substr($file, 0, 1) != '_' && substr($file, 0, 6) != 'panel_' && trim($_new['html']) != '') { if (strpos($_new['html'], '<h1') === false && strpos($_new['comcode'], '[title]') === false && strpos($_new['comcode'], '[title="1"]') === false) { attach_message(do_lang_tempcode('NO_LEVEL_1_HEADERS'), 'notice'); } $matches = array(); if (strpos($_new['html'], '<h2') === false && preg_match_all('#\\n\\[(b|font|size)\\][^\\.]+\\[/(b|font|size)\\]\\n#', $_new['comcode'], $matches) >= 2) { attach_message(do_lang_tempcode('NO_LEVEL_2_HEADERS'), 'inform'); } } // Show it worked / Refresh $url = post_param('redirect', ''); if ($url != '') { return redirect_screen($title, $url, $completion_text); } return $this->do_next_manager($title, $file, $zone, $completion_text); }
/** * 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>'; }
/** * Standard modular run function. * * @return tempcode Results */ function run() { $found = array(); $found_404 = array(); if (function_exists('set_time_limit')) { @set_time_limit(600); } global $COMCODE_BROKEN_URLS; $checked_already = array(); $skip_hooks = find_all_hooks('systems', 'non_active_urls'); $dbs_bak = $GLOBALS['NO_DB_SCOPE_CHECK']; $GLOBALS['NO_DB_SCOPE_CHECK'] = true; $urlpaths = $GLOBALS['SITE_DB']->query('SELECT m_name,m_table FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'db_meta WHERE m_type LIKE \'' . db_encode_like('%URLPATH%') . '\''); foreach ($urlpaths as $urlpath) { if ($urlpath['m_table'] == 'hackattack') { continue; } if ($urlpath['m_table'] == 'url_title_cache') { continue; } if ($urlpath['m_table'] == 'theme_images') { continue; } if (array_key_exists($urlpath['m_table'], $skip_hooks)) { continue; } $ofs = $GLOBALS['SITE_DB']->query_select($urlpath['m_table'], array('*')); foreach ($ofs as $of) { $url = $of[$urlpath['m_name']]; $this->check_url($url, $urlpath['m_table'], $urlpath['m_name'], array_key_exists('id', $of) ? strval($of['id']) : (array_key_exists('name', $of) ? $of['name'] : do_lang('UNKNOWN')), $checked_already, $found_404, $found); } } $possible_comcode_fields = $GLOBALS['SITE_DB']->query('SELECT m_name,m_table FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'db_meta WHERE m_type LIKE \'' . db_encode_like('%LONG_TRANS%') . '\''); global $LAX_COMCODE; $temp = $LAX_COMCODE; $LAX_COMCODE = true; foreach ($possible_comcode_fields as $field) { if ($field['m_table'] == 'seo_meta') { continue; } if ($field['m_table'] == 'cached_comcode_pages') { continue; } $ofs = $GLOBALS['SITE_DB']->query_select($field['m_table'] . ' x LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND t.id=x.' . $field['m_name'], array('x.' . $field['m_name'], 't.text_original', 't.source_user')); foreach ($ofs as $of) { if (is_null($of['text_original'])) { $of['text_original'] = get_translated_text($of[$field['m_name']]); } $comcode = $of['text_original']; comcode_to_tempcode($comcode, $of['source_user']); if (array_key_exists('COMCODE_BROKEN_URLS', $GLOBALS) && !is_null($COMCODE_BROKEN_URLS)) { foreach ($COMCODE_BROKEN_URLS as $i => $_url) { list($url, $spot) = $_url; if (is_null($spot)) { $_url[$i][1] = 'translate#' . strval($i) . ' (text_original)'; } } } } } $LAX_COMCODE = $temp; if (addon_installed('catalogues')) { $catalogue_fields = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id'), array('cf_type' => 'url')); $or_list = ''; foreach ($catalogue_fields as $field) { if ($or_list != '') { $or_list .= ' OR '; } $or_list .= 'cf_id=' . strval($field['id']); } if ($or_list != '') { $values = $GLOBALS['SITE_DB']->query('SELECT id,cv_value,ce_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_efv_short WHERE ' . $or_list); foreach ($values as $value) { $url = $value['cv_value']; $this->check_url($url, 'catalogue_efv_short', 'cv_value', strval($value['ce_id']), $checked_already, $found_404, $found); } } } $COMCODE_BROKEN_URLS = array(); $zones = find_all_zones(); $temp = $LAX_COMCODE; $LAX_COMCODE = true; foreach ($zones as $zone) { $pages = find_all_pages($zone, 'comcode_custom/' . get_site_default_lang(), 'txt', true) + find_all_pages($zone, 'comcode/' . get_site_default_lang(), 'txt', true); foreach ($pages as $page => $type) { $file_path = zone_black_magic_filterer((strpos($type, '_custom') !== false ? get_custom_file_base() : get_file_base()) . '/' . $zone . '/pages/' . $type . '/' . $page); $comcode = file_get_contents($file_path); comcode_to_tempcode($comcode, NULL, true); if (array_key_exists('COMCODE_BROKEN_URLS', $GLOBALS) && !is_null($COMCODE_BROKEN_URLS)) { foreach ($COMCODE_BROKEN_URLS as $i => $_url) { list($url, $spot) = $_url; if (is_null($spot)) { $_url[$i][1] = $zone . ':' . $page; } } } } } $lax_comcode = $temp; if (array_key_exists('COMCODE_BROKEN_URLS', $GLOBALS) && !is_null($COMCODE_BROKEN_URLS)) { foreach ($COMCODE_BROKEN_URLS as $_url) { list($url, $spot) = $_url; if (!array_key_exists($url, $checked_already)) { $found_404[] = array('URL' => $url, 'SPOT' => $spot); } } } $GLOBALS['NO_DB_SCOPE_CHECK'] = $dbs_bak; return do_template('BROKEN_URLS', array('_GUID' => '7b60d02e1b95f8d9053fb0a49f45d892', 'FOUND' => $found, 'FOUND_404' => $found_404)); }
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'); $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 = 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'); $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())); } } $temp = '<DT><A HREF="' . escape_html($url->evaluate()) . '">' . escape_html($title) . '</A>'; $_pages[$title] = $temp; } elseif (count($entrypoints) != 0) { foreach ($entrypoints as $entrypoint => $title) { if ($entrypoint == '!') { $url = build_url(array('page' => $page), $zone, NULL, false, false, true); } else {
/** * 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); } } }