Example #1
0
/**
 * 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)));
    }
}
Example #2
0
 /**
  * Standard modular install function.
  *
  * @param  ?integer	What version we're upgrading from (NULL: new install)
  * @param  ?integer	What hack version we're upgrading from (NULL: new-install/not-upgrading-from-a-hacked-version)
  */
 function install($upgrade_from = NULL, $upgrade_from_hack = NULL)
 {
     if (is_null($upgrade_from)) {
         $GLOBALS['SITE_DB']->create_table('redirects', array('r_from_page' => '*ID_TEXT', 'r_from_zone' => '*ID_TEXT', 'r_to_page' => 'ID_TEXT', 'r_to_zone' => 'ID_TEXT', 'r_is_transparent' => 'BINARY'));
         $GLOBALS['SITE_DB']->query_insert('redirects', array('r_from_page' => 'rules', 'r_from_zone' => 'site', 'r_to_page' => 'rules', 'r_to_zone' => '', 'r_is_transparent' => 1));
         $GLOBALS['SITE_DB']->query_insert('redirects', array('r_from_page' => 'rules', 'r_from_zone' => 'forum', 'r_to_page' => 'rules', 'r_to_zone' => '', 'r_is_transparent' => 1));
         $GLOBALS['SITE_DB']->query_insert('redirects', array('r_from_page' => 'authors', 'r_from_zone' => 'collaboration', 'r_to_page' => 'authors', 'r_to_zone' => 'site', 'r_is_transparent' => 1));
     }
     if (is_null($upgrade_from) || $upgrade_from < 4) {
         $zones = find_all_zones();
         foreach ($zones as $zone) {
             if (!file_exists(get_file_base() . '/' . $zone . '/pages/comcode/' . fallback_lang() . '/panel_top.txt')) {
                 $GLOBALS['SITE_DB']->query_insert('redirects', array('r_from_page' => 'panel_top', 'r_from_zone' => $zone, 'r_to_page' => 'panel_top', 'r_to_zone' => '', 'r_is_transparent' => 1));
             }
         }
     }
 }
Example #3
0
 /**
  * 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)), '', '');
     }
 }
Example #4
0
/**
 * Find the zone a page is in.
 *
 * @param  ID_TEXT		The page name to find
 * @param  ID_TEXT		The type of the page we are looking for
 * @param  ?string		The special subcategorisation of page we are looking for (e.g. 'EN' for a comcode page) (NULL: none)
 * @param  string			The file extension for the page type
 * @param  boolean		Whether ocPortal should bomb out if the page was not found
 * @return ?ID_TEXT		The zone the page is in (NULL: not found)
 */
function get_module_zone($module_name, $type = 'modules', $dir2 = NULL, $ftype = 'php', $error = true)
{
    global $MODULES_ZONES;
    if (isset($MODULES_ZONES[$module_name]) || !$error && array_key_exists($module_name, $MODULES_ZONES) && $type == 'modules') {
        return $MODULES_ZONES[$module_name];
    }
    $error = false;
    // hack for now
    $zone = get_zone_name();
    if ($module_name == get_page_name() && running_script('index') && $module_name != 'login') {
        $MODULES_ZONES[$module_name] = $zone;
        return $zone;
    }
    if (get_value('allow_admin_in_other_zones') !== '1') {
        if ($type == 'modules' && substr($module_name, 0, 6) == 'admin_') {
            $zone = 'adminzone';
            $MODULES_ZONES[$module_name] = $zone;
            return $zone;
        }
        if ($type == 'modules' && substr($module_name, 0, 4) == 'cms_') {
            $zone = 'cms';
            $MODULES_ZONES[$module_name] = $zone;
            return $zone;
        }
    }
    global $REDIRECT_CACHE;
    $first_zones = array(substr($module_name, 0, 6) == 'admin_' ? 'adminzone' : $zone);
    if ($zone != '') {
        $first_zones[] = '';
    }
    if ($zone != 'site' && get_option('collapse_user_zones') != '1') {
        $first_zones[] = 'site';
    }
    foreach ($first_zones as $zone) {
        if (isset($REDIRECT_CACHE[$zone][$module_name]) && $REDIRECT_CACHE[$zone][$module_name]['r_is_transparent'] == 1) {
            $MODULES_ZONES[$module_name] = $zone;
            if (function_exists('persistant_cache_set')) {
                persistant_cache_set('MODULES_ZONES', $MODULES_ZONES);
            }
            return $zone;
        }
        if (is_file(zone_black_magic_filterer(get_file_base() . '/' . $zone . '/pages/' . $type . '/' . ($dir2 === NULL ? '' : $dir2 . '/') . $module_name . '.' . $ftype)) || is_file(zone_black_magic_filterer(get_file_base() . '/' . $zone . '/pages/' . $type . '_custom/' . ($dir2 === NULL ? '' : $dir2 . '/') . $module_name . '.' . $ftype))) {
            if (isset($REDIRECT_CACHE[$zone][$module_name]) && $REDIRECT_CACHE[$zone][$module_name]['r_is_transparent'] == 0 && $REDIRECT_CACHE[$zone][$module_name]['r_to_page'] == $module_name) {
                $zone = $REDIRECT_CACHE[$zone][$module_name]['r_to_zone'];
            }
            $MODULES_ZONES[$module_name] = $zone;
            if (function_exists('persistant_cache_set')) {
                persistant_cache_set('MODULES_ZONES', $MODULES_ZONES);
            }
            return $zone;
        }
    }
    $zones = find_all_zones();
    foreach ($zones as $zone) {
        if (!in_array($zone, $first_zones)) {
            if (is_file(zone_black_magic_filterer(get_file_base() . '/' . $zone . '/pages/' . $type . '/' . ($dir2 === NULL ? '' : $dir2 . '/') . $module_name . '.' . $ftype)) || is_file(zone_black_magic_filterer(get_file_base() . '/' . $zone . '/pages/' . $type . '_custom/' . ($dir2 === NULL ? '' : $dir2 . '/') . $module_name . '.' . $ftype))) {
                if (isset($REDIRECT_CACHE[$zone][$module_name]) && $REDIRECT_CACHE[$zone][$module_name]['r_is_transparent'] == 0 && $REDIRECT_CACHE[$zone][$module_name]['r_to_page'] == $module_name) {
                    $zone = $REDIRECT_CACHE[$zone][$module_name]['r_to_zone'];
                }
                $MODULES_ZONES[$module_name] = $zone;
                if (function_exists('persistant_cache_set')) {
                    persistant_cache_set('MODULES_ZONES', $MODULES_ZONES);
                }
                return $zone;
            }
        }
    }
    foreach ($zones as $zone) {
        if (isset($REDIRECT_CACHE[$zone][$module_name]) && $REDIRECT_CACHE[$zone][$module_name]['r_is_transparent'] == 1) {
            $MODULES_ZONES[$module_name] = $zone;
            if (function_exists('persistant_cache_set')) {
                persistant_cache_set('MODULES_ZONES', $MODULES_ZONES);
            }
            return $zone;
        }
    }
    if (!$error) {
        $MODULES_ZONES[$module_name] = NULL;
        return NULL;
    }
    warn_exit(do_lang_tempcode('MISSING_MODULE_REFERENCED', $module_name));
    return NULL;
}
Example #5
0
 /**
  * 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));
 }
Example #6
0
 /**
  * Standard PHP XML parser function.
  *
  * @param  object			The parser object (same as 'this')
  */
 function endElement($parser)
 {
     $tag = array_pop($this->tag_stack);
     $tag_attributes = array_pop($this->attribute_stack);
     switch ($tag) {
         case 'substitution':
             list($zone, $attributes, $hash) = page_link_decode($this->substitution_current_match_key);
             if ($zone == '_WILD') {
                 $zone = REGEXP_CODENAME;
             }
             if (!isset($attributes['page'])) {
                 $attributes['page'] = '';
             }
             /*
             Commented for performance. This isn't user-data, so we're safe
             $zone=str_replace('~','\~',preg_quote($zone)); // We are using '~' as deliminators for the regexp, as the usual '/' and '#' feature in URL separators
             $hash=str_replace('~','\~',preg_quote($hash));
             */
             if ($attributes['page'] == '_WILD_NOT_START') {
                 $zones = find_all_zones(false, true);
                 if (isset($zones[$zone])) {
                     $attributes['page'] = '(?!' . $zones[$zone][3] . ')' . REGEXP_CODENAME;
                 } else {
                     $attributes['page'] = '_WILD';
                 }
             }
             if ($attributes['page'] == '_WILD') {
                 $attributes['page'] = REGEXP_CODENAME;
             }
             foreach ($attributes as $key => $val) {
                 $attributes[$key] = $val;
             }
             $_source_url = build_url($attributes, $zone, NULL, false, false, true, $hash);
             $source_url = urldecode(urldecode($_source_url->evaluate()));
             // urldecode because we don't want our regexp syntax mangled. Highly unlikely our sub's are going to really use special characters as parts of the URL
             if (strpos($source_url, '.htm') === false && strpos($source_url, '.php') === false) {
                 $source_url .= '(?:/index\\.php)?';
             }
             $source_url1 = str_replace(array('.htm', '?', '(\\?', ')\\?', '&', get_base_url() . '/' . REGEXP_CODENAME . '/'), array('\\.htm', '\\?', '(?', ')?', '(?:&[^<>]*)*&', get_base_url() . '/?' . REGEXP_CODENAME . '/'), $source_url) . '(?:[&\\?][^<>]*)*';
             $escaped_source_url = escape_html($source_url);
             if ($source_url == $escaped_source_url) {
                 $source_url2 = $source_url1;
             } else {
                 $source_url2 = str_replace(array('.htm', '?', '(\\?', ')\\?', '&', get_base_url() . '/' . REGEXP_CODENAME . '/'), array('\\.htm', '\\?', '(?', ')?', '(?:&[^<>]*)*&', get_base_url() . '/?' . REGEXP_CODENAME . '/'), $escaped_source_url) . '(?:[&\\?][^<>]*)*';
             }
             $from = '^.*<a[^<>]*\\shref="(' . $source_url2 . ')"[^<>]*>(<abbr[^<>]*>)?([^<>]*)(</abbr>)?</a>';
             $regexp = '#^' . $source_url1 . '$#';
             $have_url_match = preg_match($regexp, get_self_url(true)) != 0;
             // we either bind rule via URL match, or finding it in the defined breadcrumb chain
             if ($have_url_match && preg_match('~' . $from . '~Us', $this->current_breadcrumbs) == 0) {
                 // Probably it's a non-link chain in the breadcrumbs, so try to bind to the <span> portion too (possibly nested)
                 $from = '^.*(<span>(<span[^<>]*>)?|<a[^<>]*\\shref="(' . $source_url2 . ')"[^<>]*>)(<abbr[^<>]*>)?([^<>]*)(</abbr>)?((</(span)>)?</(a|span)>)';
                 $from_non_link = true;
             } else {
                 $from_non_link = false;
             }
             $to = '';
             foreach (array_reverse($this->links) as $link) {
                 list($zone, $attributes, $hash) = page_link_decode($link[0]);
                 $target_url = build_url($attributes, $zone, NULL, false, false, false, $hash);
                 $_link_title = $link[1] === NULL ? do_lang('UNKNOWN') : $link[1];
                 $link_title = preg_match('#\\{\\!|\\{\\?|\\{\\$|\\[#', $_link_title) == 0 ? $_link_title : static_evaluate_tempcode(comcode_to_tempcode($_link_title));
                 if ($target_url->evaluate() == '') {
                     $to .= $link_title . $this->breadcrumb_tpl;
                 } else {
                     $to .= '<a title="' . do_lang('GO_BACKWARDS_TO', escape_html(strip_tags($link_title))) . '" href="' . escape_html($target_url->evaluate()) . '">' . $link_title . '</a>' . $this->breadcrumb_tpl;
                 }
             }
             $_target_url = $from_non_link ? '${3}' : '${1}';
             $existing_label = $from_non_link ? '${5}' : '${3}';
             $_link_title = $this->substitution_current_label === NULL ? $existing_label : $this->substitution_current_label;
             $link_title = preg_match('#(\\{\\!)|(\\{\\?)|(\\{\\$)|(\\[)#', $_link_title) == 0 ? $_link_title : static_evaluate_tempcode(comcode_to_tempcode($_link_title));
             if ($from_non_link) {
                 $to .= '${1}' . $link_title . '${7}';
             } else {
                 $to .= '<a title="' . do_lang('GO_BACKWARDS_TO', escape_html(strip_tags($link_title))) . '" href="' . escape_html($_target_url) . '">${2}' . $link_title . '${4}</a>';
             }
             $this->substitutions[$from] = $to;
             break;
         case 'link':
             $text = trim(str_replace('\\n', chr(10), $this->text_so_far));
             $this->links[] = array($text, isset($tag_attributes['label']) ? $tag_attributes['label'] : NULL);
             break;
     }
 }
Example #7
0
/**
 * Tenth installation step: main.
 *
 * @return tempcode		Progress report / UI
 */
function step_10_populate_database()
{
    $log = new ocp_tempcode();
    // Make sure that any menu items here come after what we have already
    global $ADD_MENU_COUNTER;
    $ADD_MENU_COUNTER = 100;
    $zones = find_all_zones();
    foreach ($zones as $zone) {
        if ($zone != 'site' && $zone != 'adminzone' && $zone != 'forum' && $zone != 'cms') {
            $modules = find_all_modules($zone);
            foreach (array_keys($modules) as $module) {
                if (reinstall_module($zone, $module)) {
                    $log->attach(do_template('INSTALLER_DONE_SOMETHING', array('_GUID' => '25eb1c88fe122ec5a817f334d5f6bc5e', 'SOMETHING' => do_lang_tempcode('INSTALL_MODULE', escape_html($module)))));
                }
            }
        }
    }
    //	$log->attach(do_template('INSTALLER_DONE_SOMETHING',array('_GUID'=>'6a160da6fd9031e90b37a40aea149137','SOMETHING'=>do_lang('TABLES_CREATED','ocPortal'))));
    return $log;
}
Example #8
0
 /**
  * The UI to choose a zone to edit.
  *
  * @param  string			The follow-on type
  * @param  ?tempcode		The title to use (NULL: the EDIT_ZONE title)
  * @return tempcode		The UI
  */
 function edit_zone($type = '_edit', $title = NULL)
 {
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/zones';
     $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_structure';
     if (is_null($title)) {
         $title = get_page_title('EDIT_ZONE');
     }
     $start = get_param_integer('start', 0);
     $max = get_param_integer('max', 50);
     $_zones = find_all_zones(false, true, false, $start, $max);
     $url_map = array('page' => '_SELF', 'type' => $type);
     if ($type == '_editor') {
         $url_map['wide'] = 1;
     }
     require_code('templates_results_table');
     $current_ordering = 'name ASC';
     if (strpos($current_ordering, ' ') === false) {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     list($sortable, $sort_order) = explode(' ', $current_ordering, 2);
     $sortables = array();
     $header_row = results_field_title(array(do_lang_tempcode('NAME'), do_lang_tempcode('TITLE'), do_lang_tempcode('DEFAULT_PAGE'), do_lang_tempcode('THEME'), do_lang_tempcode('DISPLAYED_IN_MENU'), do_lang_tempcode('WIDE'), do_lang_tempcode('REQUIRE_SESSION'), do_lang_tempcode('ACTIONS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     $fields = new ocp_tempcode();
     require_code('form_templates');
     $max_rows = $GLOBALS['SITE_DB']->query_value('zones', 'COUNT(*)');
     foreach ($_zones as $_zone_details) {
         list($zone_name, $zone_title, $zone_show_in_menu, $zone_default_page, $remaining_row) = $_zone_details;
         $edit_link = build_url($url_map + array('id' => $zone_name), '_SELF');
         $fields->attach(results_entry(array(hyperlink(build_url(array('page' => ''), $zone_name), $zone_name == '' ? do_lang_tempcode('NA_EM') : make_string_tempcode(escape_html($zone_name))), $zone_title, $zone_default_page, $remaining_row['zone_theme'] == '-1' ? do_lang_tempcode('NA_EM') : hyperlink(build_url(array('page' => 'admin_themes'), 'adminzone'), escape_html($remaining_row['zone_theme'])), $zone_show_in_menu == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO'), $remaining_row['zone_wide'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO'), $remaining_row['zone_require_session'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO'), protect_from_escaping(hyperlink($edit_link, do_lang_tempcode('EDIT'), false, true, $zone_name))), true));
     }
     $table = results_table(do_lang('ZONES'), get_param_integer('start', 0), 'start', either_param_integer('max', 20), 'max', $max_rows, $header_row, $fields, $sortables, $sortable, $sort_order);
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('ZONES'))));
     breadcrumb_set_self(do_lang_tempcode('CHOOSE'));
     $text = do_lang_tempcode('CHOOSE_EDIT_LIST');
     return do_template('TABLE_TABLE_SCREEN', array('TITLE' => $title, 'TEXT' => $text, 'TABLE' => $table, 'SUBMIT_NAME' => NULL, 'POST_URL' => get_self_url()));
 }
echo <<<END
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file.
     It will be read and overwritten.
     DO NOT EDIT! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks Menu</H1>
<DL><p>
  <DT><H3>{$site_name}</H3>
  <DL><p>
END;
$comcode_page_rows = $GLOBALS['SITE_DB']->query_select('comcode_pages', array('*'));
require_all_lang();
$_zones = array();
$zones = find_all_zones(false, 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);
require_code('zones2');
foreach ($zones2 as $z) {
    list($zone, $zone_title, , ) = $z;
    if (has_zone_access(get_member(), $zone)) {
Example #10
0
/**
 * Upgrade all modules.
 *
 * @return string		List of upgraded/installed modules/blocks
 */
function upgrade_modules()
{
    $out = '';
    require_code('zones2');
    if (file_exists(get_file_base() . '/sources/zones3.php')) {
        require_code('zones3');
    }
    $ret = upgrade_module('adminzone', 'admin_version');
    if ($ret == 1) {
        $out .= '<li>' . do_lang('FU_UPGRADED_MODULE', '<kbd>admin_version</kbd>') . '</li>';
    }
    $zones = find_all_zones();
    if (!in_array('adminzone', $zones)) {
        $zones[] = 'adminzone';
    }
    if (!in_array('cms', $zones)) {
        $zones[] = 'cms';
    }
    if (!in_array('site', $zones)) {
        $zones[] = 'site';
    }
    foreach ($zones as $zone) {
        $modules = find_all_modules($zone);
        foreach ($modules as $module => $type) {
            $ret = upgrade_module($zone, $module);
            if ($ret == 1) {
                $out .= '<li>' . do_lang('FU_UPGRADED_MODULE', '<kbd>' . escape_html($module) . '</kbd>') . '</li>';
            } elseif ($ret == -2) {
                if ($type == 'modules_custom') {
                    continue;
                }
                if (reinstall_module($zone, $module)) {
                    $out .= '<li>' . do_lang('FU_INSTALLED_MODULE', '<kbd>' . escape_html($module) . '</kbd>') . '</li>';
                }
            }
        }
    }
    require_code('zones2');
    if (file_exists(get_file_base() . '/sources/zones3.php')) {
        require_code('zones3');
    }
    $blocks = find_all_blocks();
    foreach ($blocks as $block => $type) {
        $ret = upgrade_block($block);
        if ($ret == 1) {
            $out .= '<li>' . do_lang('FU_UPGRADED_BLOCK', '<kbd>' . escape_html($block) . '</kbd>') . '</li>';
        } elseif ($ret == -2) {
            if ($type == 'sources_custom') {
                continue;
            }
            if (reinstall_block($block)) {
                $out .= '<li>' . do_lang('FU_INSTALLED_BLOCK', '<kbd>' . escape_html($block) . '</kbd>') . '</li>';
            }
        }
    }
    return $out;
}
Example #11
0
 /**
  * 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;
 }
Example #12
0
 /**
  * Standard modular run function for RSS hooks.
  *
  * @param  string			A list of categories we accept from
  * @param  TIME			Cutoff time, before which we do not show results from
  * @param  string			Prefix that represents the template set we use
  * @set    RSS_ ATOM_
  * @param  string			The standard format of date to use for the syndication type represented in the prefix
  * @param  integer		The maximum number of entries to return, ordering by date
  * @return ?array			A pair: The main syndication section, and a title (NULL: error)
  */
 function run($_filters, $cutoff, $prefix, $date_string, $max)
 {
     $filters = explode(',', $_filters);
     $content = new ocp_tempcode();
     $_rows = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('the_page', 'the_zone', 'cc_page_title'));
     $rows = array();
     foreach ($_rows as $row) {
         $rows[$row['the_zone'] . ':' . $row['the_page']] = $row;
     }
     $_rows2 = $GLOBALS['SITE_DB']->query_select('seo_meta', array('*'), array('meta_for_type' => 'comcode_page'));
     $rows2 = array();
     foreach ($_rows2 as $row) {
         $rows2[$row['meta_for_id']] = $row;
     }
     $_rows3 = $GLOBALS['SITE_DB']->query_select('comcode_pages');
     $rows3 = array();
     foreach ($_rows3 as $row) {
         $rows3[$row['the_zone'] . ':' . $row['the_page']] = $row;
     }
     $zones = find_all_zones(false, true);
     foreach ($zones as $zone => $zone_details) {
         if (!has_zone_access(get_member(), $zone)) {
             continue;
         }
         if ($filters != array('')) {
             $ok = false;
             foreach ($filters as $filter) {
                 if ($zone == $filter) {
                     $ok = true;
                 }
             }
             if (!$ok) {
                 continue;
             }
         }
         $pages = find_all_pages($zone, 'comcode_custom/' . get_site_default_lang(), 'txt', false, $cutoff);
         foreach (array_keys($pages) as $i => $page) {
             if ($i == $max) {
                 break;
             }
             if (substr($page, 0, 6) == 'panel_') {
                 continue;
             }
             if (!has_page_access(get_member(), $page, $zone)) {
                 continue;
             }
             $id = $zone . ':' . $page;
             $page_request = _request_page($page, $zone);
             if (strpos($page_request[0], 'COMCODE') === false) {
                 continue;
             }
             $path = $page_request[count($page_request) - 1];
             $news_date = date($date_string, filectime($path));
             $edit_date = date($date_string, filemtime($path));
             if ($news_date == $edit_date) {
                 $edit_date = '';
             }
             $summary = '';
             $news = '';
             $author = '';
             $news_title = xmlentities($page);
             if (array_key_exists($id, $rows)) {
                 $_news_title = get_translated_text($rows[$id]['cc_page_title'], NULL, NULL, true);
                 if (is_null($_news_title)) {
                     $_news_title = '';
                 }
                 $news_title = xmlentities($_news_title);
             }
             if (array_key_exists($id, $rows2)) {
                 $summary = xmlentities(get_translated_text($rows2[$id]['meta_description']));
             }
             if (array_key_exists($id, $rows3)) {
                 if (!has_specific_permission(get_member(), 'see_unvalidated') && $rows3[$id]['p_validated'] == 0) {
                     continue;
                 }
                 $author = $GLOBALS['FORUM_DRIVER']->get_username($rows3[$id]['p_submitter']);
                 $news_date = date($date_string, $rows3[$id]['p_add_date']);
                 $edit_date = date($date_string, $rows3[$id]['p_edit_date']);
                 if ($news_date == $edit_date) {
                     $edit_date = '';
                 }
             }
             if (is_null($author)) {
                 $author = '';
             }
             $category = $zone_details[1];
             $category_raw = $zone;
             $view_url = build_url(array('page' => $page), $zone, NULL, false, false, true);
             $if_comments = new ocp_tempcode();
             $content->attach(do_template($prefix . 'ENTRY', array('VIEW_URL' => $view_url, 'SUMMARY' => $summary, 'EDIT_DATE' => $edit_date, 'IF_COMMENTS' => $if_comments, 'TITLE' => $news_title, 'CATEGORY_RAW' => $category_raw, 'CATEGORY' => $category, 'AUTHOR' => $author, 'ID' => $id, 'NEWS' => $news, 'DATE' => $news_date)));
         }
     }
     require_lang('zones');
     return array($content, do_lang('COMCODE_PAGES'));
 }
Example #13
0
/**
 * Render that the page wasn't found. Show alternate likely candidates based on misspellings.
 *
 * @param  ID_TEXT		The codename of the page to load
 * @param  ID_TEXT		The zone the page is being loaded in
 * @return tempcode		Message
 */
function page_not_found($codename, $zone)
{
    $GLOBALS['HTTP_STATUS_CODE'] = '404';
    if (!headers_sent()) {
        if (!browser_matches('ie') && strpos(ocp_srv('SERVER_SOFTWARE'), 'IIS') === false) {
            header('HTTP/1.0 404 Not Found');
        }
    }
    // Maybe problem with SEO URLs
    if (get_zone_name() == '' && get_option('htm_short_urls') == '1' && has_zone_access(get_member(), 'adminzone')) {
        $self_url = get_self_url_easy();
        $zones = find_all_zones();
        foreach ($zones as $_zone) {
            if ($_zone != '' && $_zone != 'site' && strpos($self_url, '/' . $_zone . '/') !== false) {
                attach_message(do_lang_tempcode('HTACCESS_SEO_PROBLEM'), 'warn');
            }
        }
    }
    // "Did you mean?" support
    $all_pages_in_zone = array_keys(find_all_pages_wrap($zone));
    $did_mean = array();
    foreach ($all_pages_in_zone as $possibility) {
        if (is_integer($possibility)) {
            $possibility = strval($possibility);
        }
        // e.g. '404' page has been converted to integer by PHP, grr
        $from = str_replace('cms_', '', str_replace('admin_', '', $possibility));
        $to = str_replace('cms_', '', str_replace('admin_', '', $codename));
        //$dist=levenshtein($from,$to);  If we use this, change > to < also
        //$threshold=4;
        $dist = 0.0;
        similar_text($from, $to, $dist);
        $threshold = 75.0;
        if ($dist > $threshold && has_page_access(get_member(), $codename, $zone)) {
            $did_mean[$dist] = $possibility;
        }
    }
    ksort($did_mean);
    $_did_mean = array_pop($did_mean);
    if ($_did_mean == '') {
        $_did_mean = NULL;
    }
    if (ocp_srv('HTTP_REFERER') != '' && !handle_has_checked_recently('request-' . $zone . ':' . $codename)) {
        require_code('failure');
        relay_error_notification(do_lang('_MISSING_RESOURCE', $zone . ':' . $codename) . ' ' . do_lang('REFERRER', ocp_srv('HTTP_REFERER'), substr(get_browser_string(), 0, 255)), false, 'error_occurred_missing_page');
    }
    $title = get_page_title('ERROR_OCCURRED');
    $add_access = has_actual_page_access(get_member(), 'cms_comcode_pages', NULL, NULL, 'submit_highrange_content');
    $redirect_access = addon_installed('redirects_editor') && has_actual_page_access(get_member(), 'admin_redirects');
    require_lang('zones');
    $add_url = $add_access ? build_url(array('page' => 'cms_comcode_pages', 'type' => '_ed', 'page_link' => $zone . ':' . $codename), get_module_zone('cms_comcode_pages')) : new ocp_tempcode();
    $add_redirect_url = $redirect_access ? build_url(array('page' => 'admin_redirects', 'type' => 'misc', 'page_link' => $zone . ':' . $codename), get_module_zone('admin_redirects')) : new ocp_tempcode();
    return do_template('MISSING_SCREEN', array('_GUID' => '22f371577cd2ba437e7b0cb241931575', 'TITLE' => $title, 'DID_MEAN' => $_did_mean, 'ADD_URL' => $add_url, 'ADD_REDIRECT_URL' => $add_redirect_url, 'PAGE' => $codename));
}
Example #14
0
 /**
  * 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);
 }
Example #15
0
/**
 * Get a list of zones.
 *
 * @param  ?ID_TEXT		The zone in the list to select by default (NULL: use first)
 * @param  ?array			A list of zone to not put into the list (NULL: none to skip)
 * @param  ?array			A reordering (NULL: no reordering)
 * @return tempcode		The list
 */
function nice_get_zones($sel = NULL, $no_go = NULL, $reorder = NULL)
{
    if (is_null($no_go)) {
        $no_go = array();
    }
    if ($sel === 'site' && get_option('collapse_user_zones') == '1') {
        $sel = '';
    }
    $zones = find_all_zones(false, true);
    $content = new ocp_tempcode();
    if (!is_null($reorder)) {
        $_zones_a = array();
        $_zones_b = array();
        foreach ($zones as $_zone) {
            list($zone, $title, ) = $_zone;
            if (in_array($zone, $reorder)) {
                $_zones_a[] = $_zone;
            } else {
                $_zones_b[] = $_zone;
            }
        }
        $zones = array_merge($_zones_a, $_zones_b);
    }
    foreach ($zones as $_zone) {
        list($zone, $title, ) = $_zone;
        if (has_zone_access(get_member(), $zone) && !in_array($zone, $no_go)) {
            $content->attach(form_input_list_entry($zone, !is_null($sel) && $zone == $sel, $title));
        }
    }
    return $content;
}
Example #16
0
/**
 * Uninstall an addon.
 *
 * @param  string			Name of the addon
 * @param  ?array			The files to install (NULL: all)
 */
function install_addon($file, $files = NULL)
{
    $full = get_custom_file_base() . '/imports/mods/' . $file;
    require_code('zones2');
    require_code('zones3');
    require_code('tar');
    $tar = tar_open($full, 'rb');
    $info_file = tar_get_file($tar, 'mod.inf');
    if (is_null($info_file)) {
        warn_exit(do_lang_tempcode('NOT_ADDON'));
    }
    $info = better_parse_ini_file(NULL, $info_file['data']);
    $directory = tar_get_directory($tar);
    tar_extract_to_folder($tar, '', true, $files, true);
    $addon = $info['name'];
    $author = $info['author'];
    $organisation = $info['organisation'];
    $version = $info['version'];
    if ($version == '(version-synched)') {
        $version = float_to_raw_string(ocp_version_number());
    }
    $dependencies = explode(',', array_key_exists('dependencies', $info) ? $info['dependencies'] : '');
    $incompatibilities = explode(',', array_key_exists('incompatibilities', $info) ? $info['incompatibilities'] : '');
    $description = $info['description'];
    $GLOBALS['SITE_DB']->query_delete('addons', array('addon_name' => $addon), '', 1);
    $GLOBALS['SITE_DB']->query_insert('addons', array('addon_name' => $addon, 'addon_author' => $author, 'addon_organisation' => $organisation, 'addon_version' => $version, 'addon_description' => $description, 'addon_install_time' => time()));
    foreach ($dependencies as $dependency) {
        $GLOBALS['SITE_DB']->query_insert('addons_dependencies', array('addon_name' => $addon, 'addon_name_dependant_upon' => trim($dependency), 'addon_name_incompatibility' => 0));
    }
    foreach ($incompatibilities as $dependency) {
        $GLOBALS['SITE_DB']->query_insert('addons_dependencies', array('addon_name' => $addon, 'addon_name_dependant_upon' => trim($dependency), 'addon_name_incompatibility' => 1));
    }
    foreach ($directory as $dir) {
        $addon_file = $dir['path'];
        if (substr($addon_file, -1) == '/') {
            continue;
        }
        if (is_null($files) || in_array($addon_file, $files)) {
            $GLOBALS['SITE_DB']->query_insert('addons_files', array('addon_name' => $addon, 'filename' => $addon_file));
        }
    }
    // Install new zones
    $zones = array('');
    foreach ($directory as $dir) {
        $addon_file = $dir['path'];
        if (is_null($files) || in_array($addon_file, $files)) {
            $matches = array();
            if (preg_match('#(\\w*)/index.php#', $addon_file, $matches) != 0) {
                $zone = $matches[1];
                $test = $GLOBALS['SITE_DB']->query_value_null_ok('zones', 'zone_name', array('zone_name' => $zone));
                if (is_null($test)) {
                    require_code('menus2');
                    add_menu_item_simple('zone_menu', NULL, $zone, $zone . ':', 0, 1);
                    $GLOBALS['SITE_DB']->query_insert('zones', array('zone_name' => $zone, 'zone_title' => insert_lang($zone, 1), 'zone_default_page' => 'start', 'zone_header_text' => insert_lang('???', 2), 'zone_theme' => 'default', 'zone_wide' => 0, 'zone_require_session' => 0, 'zone_displayed_in_menu' => 1));
                    $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
                    foreach (array_keys($groups) as $group_id) {
                        $GLOBALS['SITE_DB']->query_insert('group_zone_access', array('zone_name' => $zone, 'group_id' => $group_id));
                    }
                }
                $zones[] = $zone;
            }
        }
    }
    // Install new modules
    $zones = array_unique(array_merge(find_all_zones(), $zones));
    if (get_option('collapse_user_zones') == '1') {
        $zones[] = 'site';
    }
    foreach ($zones as $zone) {
        $prefix = $zone == '' ? '' : $zone . '/';
        foreach ($directory as $dir) {
            $addon_file = $dir['path'];
            if (is_null($files) || in_array($addon_file, $files)) {
                if (preg_match('#^' . $prefix . 'pages/(modules|modules\\_custom)/([^/]*)\\.php$#', $addon_file, $matches) != 0) {
                    if (!module_installed($matches[2])) {
                        reinstall_module($zone, $matches[2]);
                    }
                }
            }
        }
    }
    // Install new blocks
    foreach ($directory as $dir) {
        $addon_file = $dir['path'];
        if (is_null($files) || in_array($addon_file, $files)) {
            if (preg_match('#^(sources|sources\\_custom)/blocks/([^/]*)\\.php$#', $addon_file, $matches) != 0) {
                if (!block_installed($matches[2])) {
                    reinstall_block($matches[2]);
                }
            }
        }
    }
    // Clear some cacheing
    require_code('view_modes');
    require_code('zones2');
    require_code('zones3');
    erase_comcode_page_cache();
    erase_tempcode_cache();
    persistant_cache_empty();
    erase_cached_templates();
    erase_cached_language();
    // Load mod.php if it exists
    $_modphp_file = tar_get_file($tar, 'mod.php');
    if (!is_null($_modphp_file)) {
        $modphp_file = trim($_modphp_file['data']);
        if (!defined('HIPHOP_PHP')) {
            if (substr($modphp_file, 0, 5) == '<' . '?php') {
                $modphp_file = substr($modphp_file, 5);
            }
            if (substr($modphp_file, -2) == '?' . '>') {
                $modphp_file = substr($modphp_file, 0, strlen($modphp_file) - 2);
            }
            if (eval($modphp_file) === false) {
                fatal_exit(@strval($php_errormsg));
            }
        } else {
            $matches = array();
            $num_matches = preg_match_all('#\\$GLOBALS[\'SITE_DB\']->query_insert(\'theme_images\',array(\'id\'=>\'([^\']*)\',\'theme\'=>\'([^\']*)\',\'path\'=>\'([^\']*)\',\'lang\'=>\'([^\']*)\'),false,true);#', $modphp_file, $matches);
            for ($i = 0; $i < $num_matches; $i++) {
                $GLOBALS['SITE_DB']->query_insert('theme_images', array('id' => $matches[1][$i], 'theme' => $matches[2][$i], 'path' => $matches[3][$i], 'lang' => $matches[4][$i]), false, true);
            }
        }
    }
    tar_close($tar);
    // Call install script, if it exists
    $path = '/data_custom/' . strtolower(basename($file, '.tar')) . '_install.php';
    if (file_exists(get_file_base() . $path)) {
        require_code('files');
        http_download_file(get_base_url() . $path);
    }
    log_it('INSTALL_ADDON', $addon);
}
Example #17
0
 /**
  * The UI for the add-new-page wizard (choose which menu to add it to, and what title to give it - or choose not to add to a menu).
  *
  * @return tempcode		The UI
  */
 function _page_wizard()
 {
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/addpagewizard';
     $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_comcode_pages';
     $title = get_page_title('PAGE_WIZARD_STEP', true, array(integer_format(2), integer_format(3)));
     $zone = post_param('zone', '');
     breadcrumb_set_parents(array(array('_SELF:_SELF:pagewizard', do_lang_tempcode('PAGE_WIZARD'))));
     breadcrumb_set_self(do_lang_tempcode('DETAILS'));
     require_code('type_validation');
     if (!is_alphanumeric(str_replace(':', '', post_param('name')), true)) {
         warn_exit(do_lang_tempcode('BAD_CODENAME'));
     }
     $zones = find_all_zones(false, true);
     $pages = array();
     foreach ($zones as $_zone) {
         $pages[$_zone[0]] = find_all_pages_wrap($_zone[0], true);
     }
     require_code('form_templates');
     $rows = $GLOBALS['SITE_DB']->query_select('menu_items', array('DISTINCT i_menu'), NULL, 'ORDER BY i_menu');
     $list = new ocp_tempcode();
     $list2 = new ocp_tempcode();
     $list->attach(form_input_list_entry(STRING_MAGIC_NULL, false, do_lang_tempcode('NA_EM')));
     $list->attach(form_input_list_entry('', false, '', false, true));
     // See if we can discern nice names for the menus, to help relate them
     foreach ($rows as $row) {
         $menu_name = make_string_tempcode(escape_html($row['i_menu']));
         $found = false;
         foreach ($pages as $zone_under => $under) {
             foreach ($under as $filename => $type) {
                 if (substr(strtolower($filename), -4) == '.txt') {
                     $matches = array();
                     $path = zone_black_magic_filterer((substr($type, 0, 15) == 'comcode_custom/' ? get_custom_file_base() : get_file_base()) . '/' . ($zone_under == '' ? '' : $zone_under . '/') . 'pages/' . $type . '/' . $filename);
                     if (!file_exists($path)) {
                         $path = zone_black_magic_filterer(get_file_base() . '/' . ($zone_under == '' ? '' : $zone_under . '/') . 'pages/' . $type . '/' . $filename);
                     }
                     $contents = '';
                     if (file_exists($path)) {
                         $contents .= file_get_contents($path);
                     } else {
                         $fallback = zone_black_magic_filterer(get_file_base() . '/' . ($zone_under == '' ? '' : $zone_under . '/') . 'pages/comcode/' . fallback_lang() . '/' . $filename);
                         if (file_exists($fallback)) {
                             $contents .= file_get_contents($fallback);
                         }
                     }
                     if (preg_match('#\\[block="' . str_replace('#', '\\#', preg_quote($row['i_menu'])) . '"[^\\]]* caption="([^"]*)"[^\\]]*\\]side_stored_menu\\[/block\\]#', $contents, $matches) != 0) {
                         $zone_title = preg_replace('# ' . str_replace('#', '\\#', preg_quote(do_lang('ZONE'))) . '$#', '', $zones[$zone_under][1]);
                         $menu_name = do_lang_tempcode('MENU_FULL_DETAILS', $menu_name, make_string_tempcode(escape_html($matches[1])), make_string_tempcode(escape_html($zone_title)));
                         $found = true;
                         break 2;
                     }
                 }
             }
         }
         $selected = $zone == 'forum' && $row['i_menu'] == 'forum_features' || $zone == 'collaboration' && $row['i_menu'] == 'collab_website' || ($zone == 'site' || $zone == '' && get_option('collapse_user_zones') == '1') && ($row['i_menu'] == 'site' || $row['i_menu'] == 'main_website') || $zone == '' && $row['i_menu'] == 'root_website';
         if ($found) {
             $list->attach(form_input_list_entry($row['i_menu'], $selected, $menu_name));
         } else {
             $list2->attach(form_input_list_entry($row['i_menu'], false, $row['i_menu'] == 'zone_menu' ? $menu_name : do_lang('MENU_UNUSED', $menu_name)));
         }
     }
     if (!$list2->is_empty()) {
         $list->attach(form_input_list_entry('', false, '', false, true));
         $list->attach($list2);
     }
     // Now see if there are any menus pending creation
     foreach ($pages as $zone_under => $under) {
         foreach ($under as $filename => $type) {
             if (substr(strtolower($filename), -4) == '.txt') {
                 $matches = array();
                 $path = zone_black_magic_filterer((substr($type, 0, 15) == 'comcode_custom/' ? get_custom_file_base() : get_file_base()) . '/' . ($zone_under == '' ? '' : $zone_under . '/') . 'pages/' . $type . '/' . $filename);
                 if (!file_exists($path)) {
                     $path = zone_black_magic_filterer(get_file_base() . '/' . ($zone_under == '' ? '' : $zone_under . '/') . 'pages/' . $type . '/' . $filename);
                 }
                 $contents = '';
                 if (file_exists($path)) {
                     $contents .= file_get_contents($path);
                 } else {
                     $fallback = zone_black_magic_filterer(get_file_base() . '/' . ($zone_under == '' ? '' : $zone_under . '/') . 'pages/comcode/' . fallback_lang() . '/' . $filename);
                     if (file_exists($fallback)) {
                         $contents .= file_get_contents($fallback);
                     }
                 }
                 $num_matches = preg_match_all('#\\[block="([^"]*)"[^\\]]* caption="([^"]*)"[^\\]]*\\]side_stored_menu\\[/block\\]#', $contents, $matches);
                 for ($i = 0; $i < $num_matches; $i++) {
                     $menu_name = $matches[1][$i];
                     foreach ($rows as $row) {
                         if ($row['i_menu'] == $menu_name) {
                             continue 2;
                         }
                     }
                     $zone_title = $zones[$zone_under][1];
                     $menu_name = do_lang_tempcode('MENU_FULL_DETAILS', $menu_name, make_string_tempcode(escape_html($matches[2][$i])), make_string_tempcode(escape_html($zone_title)));
                     $list->attach(form_input_list_entry($matches[1][$i], $selected, $menu_name));
                 }
             }
         }
     }
     $fields = new ocp_tempcode();
     $fields->attach(form_input_list(do_lang_tempcode('MENU'), do_lang_tempcode('MENU_TO_ADD_TO'), 'menu', $list, NULL, true));
     $fields->attach(form_input_line(do_lang_tempcode('TITLE'), do_lang_tempcode('DESCRIPTION_MENU_TITLE'), 'title', ucwords(str_replace('_', ' ', post_param('name'))), true));
     $post_url = build_url(array('page' => 'cms_comcode_pages', 'type' => '_ed', 'simple_add' => 1), get_module_zone('cms_comcode_pages'));
     $submit_name = do_lang_tempcode('PROCEED');
     $hidden = new ocp_tempcode();
     $hidden->attach(form_input_hidden('page_link', $zone . ':' . post_param('name')));
     return do_template('FORM_SCREEN', array('_GUID' => '3281970772c410cf071c422792d1571d', 'GET' => true, 'SKIP_VALIDATION' => true, 'TITLE' => $title, 'HIDDEN' => $hidden, 'TEXT' => '', 'FIELDS' => $fields, 'URL' => $post_url, 'SUBMIT_NAME' => $submit_name));
 }
Example #18
0
 /**
  * The UI to choose a page to edit.
  *
  * @return tempcode		The UI
  */
 function ed()
 {
     $title = get_page_title('COMCODE_PAGE_EDIT');
     $lang = choose_language($title, true);
     if (is_object($lang)) {
         return $lang;
     }
     require_code('form_templates');
     $add_new_permission = has_specific_permission(get_member(), 'submit_highrange_content');
     if (!$add_new_permission && !has_specific_permission(get_member(), 'edit_highrange_content') && !has_specific_permission(get_member(), 'edit_own_highrange_content')) {
         check_edit_permission('high', NULL);
     }
     $fields = new ocp_tempcode();
     if ($add_new_permission) {
         $fields->attach(form_input_line(do_lang_tempcode('NEW'), do_lang_tempcode('DESCRIPTION_NEW_COMCODE_PAGE'), 'page_link_2', '', true));
         $submit_name = do_lang_tempcode('ADD');
     } else {
         $submit_name = NULL;
     }
     $hidden = new ocp_tempcode();
     $hidden->attach(form_input_hidden('lang', $lang));
     $hidden->attach(form_input_hidden('type', '_ed'));
     $hidden->attach(build_keep_form_fields('_SELF'));
     $map = array('page' => '_SELF', 'type' => '_ed', 'lang' => $lang);
     $post_url = build_url($map, '_SELF', NULL, false, true);
     breadcrumb_set_self(do_lang_tempcode('CHOOSE'));
     $search_url = build_url(array('page' => 'search', 'id' => 'comcode_pages'), get_module_zone('search'));
     $sitemap_zone = get_page_zone('sitemap', false);
     if ($sitemap_zone !== NULL) {
         $archive_url = build_url(array('page' => 'sitemap'), $sitemap_zone);
     } else {
         $archive_url = build_url(array('page' => ''), '');
     }
     $text = paragraph(do_lang_tempcode('CHOOSE_EDIT_LIST_EXTRA', escape_html($search_url->evaluate()), escape_html($archive_url->evaluate())));
     if (addon_installed('page_management')) {
         if (has_actual_page_access(get_member(), 'admin_sitetree')) {
             $page_wizard = build_url(array('page' => 'admin_sitetree', 'type' => 'pagewizard'), get_module_zone('admin_sitetree'));
             $site_tree_editor = build_url(array('page' => 'admin_sitetree', 'type' => 'site_tree'), get_module_zone('admin_sitetree'));
             attach_message(do_lang_tempcode('SUGGEST_PAGE_WIZARD', escape_html($page_wizard->evaluate()), escape_html($site_tree_editor->evaluate())), 'inform');
         }
     }
     require_code('templates_results_table');
     $current_ordering = get_param('sort', 'page_title ASC');
     if (strpos($current_ordering, ' ') === false) {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     list($sortable, $sort_order) = explode(' ', $current_ordering, 2);
     $sortables = array('page_title' => do_lang_tempcode('TITLE'), 'page' => do_lang_tempcode('PAGE'), 'zone_name' => do_lang_tempcode('ZONE'), 'pagelink' => do_lang_tempcode('PAGE_LINK'));
     if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     $header_row = results_field_title(array(do_lang_tempcode('TITLE'), do_lang_tempcode('PAGE'), do_lang_tempcode('ZONE'), do_lang_tempcode('PAGE_LINK'), do_lang_tempcode('ACTIONS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     $all_zones = find_all_zones(false, true);
     $number_pages_parsed_for_titles = 0;
     $GLOBALS['NO_QUERY_LIMIT'] = true;
     $start = get_param_integer('start', 0);
     $max = get_param_integer('max', 50);
     $filesarray = $this->get_comcode_files_array($lang);
     if (count($filesarray) >= 300) {
         $orderer = 'p_add_date ASC';
         switch ($sortable) {
             case 'page_title':
                 $orderer = 't.text_original ' . $sort_order;
                 break;
             case 'page':
                 $orderer = 'c.the_page ' . $sort_order;
                 break;
             case 'zone_name':
                 $orderer = 'c.the_zone ' . $sort_order;
                 break;
             case 'pagelink':
                 $orderer = 'c.the_zone ' . $sort_order . ',c.the_page ' . $sort_order;
                 break;
         }
         $group_by = '';
         if (can_arbitrary_groupby()) {
             $group_by = 'GROUP BY c.the_zone,c.the_page';
         }
         $where_map = '(' . db_string_equal_to('language', $lang) . ' OR language IS NULL)';
         if (!has_specific_permission(get_member(), 'edit_highrange_content')) {
             $where_map .= ' AND submitter=' . strval(get_member());
         }
         $ttable = get_table_prefix() . 'comcode_pages c LEFT JOIN ' . get_table_prefix() . 'cached_comcode_pages a ON c.the_page=a.the_page AND c.the_zone=a.the_zone LEFT JOIN ' . get_table_prefix() . 'translate t ON t.id=a.cc_page_title';
         $page_rows = $GLOBALS['SITE_DB']->query('SELECT c.*,cc_page_title FROM ' . $ttable . ' WHERE ' . $where_map . $group_by . ' ORDER BY ' . $orderer, $max, $start);
         $max_rows = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(DISTINCT c.the_zone,c.the_page) FROM ' . $ttable . ' WHERE ' . $where_map);
         $filesarray = array();
         foreach ($page_rows as $row) {
             $located = _request_page($row['the_page'], $row['the_zone'], NULL, $lang);
             if ($located !== false) {
                 $filesarray[$row['the_zone'] . ':' . $row['the_page']] = array($row['the_zone'] . '/pages/' . strtolower($located[0]) . '/' . $row['the_page'], NULL, $row);
             }
         }
         $found_via_query = true;
     } else {
         $max_rows = 0;
         ksort($filesarray);
         $found_via_query = false;
     }
     // Render table rows
     $_table_rows = array();
     foreach ($filesarray as $pagelink => $path_bits) {
         list($zone, $page) = explode(':', $pagelink, 2);
         if (!is_string($page)) {
             $page = strval($page);
         }
         $edit_link = build_url(array('page' => '_SELF', 'type' => '_ed', 'page_link' => $pagelink, 'lang' => $lang), '_SELF');
         $clone_link = build_url(array('page' => '_SELF', 'type' => '_ed', 'page_link' => $zone . ':', 'restore_from' => $path_bits[0] . '.txt', 'lang' => $lang), '_SELF');
         $zone_name = array_key_exists($zone, $all_zones) ? $all_zones[$zone][1] : $zone;
         // We need to separately read from DB to work out meta data?
         $row = mixed();
         if (!array_key_exists(2, $path_bits)) {
             $rows = $GLOBALS['SITE_DB']->query_select('comcode_pages c LEFT JOIN ' . get_table_prefix() . 'cached_comcode_pages a ON c.the_page=a.the_page AND c.the_zone=a.the_zone', array('c.*', 'cc_page_title'), array('c.the_zone' => $zone, 'c.the_page' => $page), '', 1);
             if (!array_key_exists(0, $rows) && $number_pages_parsed_for_titles < 15) {
                 $result = request_page($page, false, $zone, 'comcode_custom', true);
                 $rows = $GLOBALS['SITE_DB']->query_select('comcode_pages c LEFT JOIN ' . get_table_prefix() . 'cached_comcode_pages a ON c.the_page=a.the_page AND c.the_zone=a.the_zone', array('c.*', 'cc_page_title'), array('c.the_zone' => $zone, 'c.the_page' => $page), '', 1);
                 $number_pages_parsed_for_titles++;
             }
             $row = array_key_exists(0, $rows) ? $rows[0] : NULL;
         } else {
             $row = $path_bits[2];
         }
         // Work out meta data
         $page_title = do_lang_tempcode('NA_EM');
         if (!is_null($row)) {
             $username = protect_from_escaping($GLOBALS['FORUM_DRIVER']->member_profile_hyperlink($row['p_submitter']));
             $parent_page = $row['p_parent_page'];
             $add_date = get_timezoned_date($row['p_add_date']);
             $validated = $row['p_validated'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('YES');
             if (!is_null($row['cc_page_title'])) {
                 $_page_title = get_translated_text($row['cc_page_title'], NULL, NULL, true);
                 if (!is_null($_page_title)) {
                     if ($_page_title != '') {
                         $page_title = make_string_tempcode($_page_title);
                     }
                 }
             }
         } else {
             $username = do_lang('UNKNOWN');
             $parent_page = '';
             $add_date = get_timezoned_date(filectime(get_file_base() . '/index.php'));
             $validated = do_lang_tempcode('YES');
         }
         $wrappable_pagelink = preg_replace('#([^ ]):([\\w\\-]{10,})$#', '${1}: ${2}', preg_replace('#(^[\\w\\-]{10,}):#', '${1}: ', $pagelink));
         $actions = do_template('COMCODE_PAGE_EDIT_ACTIONS', array('EDIT_URL' => $edit_link, 'CLONE_URL' => $clone_link));
         $_table_rows[] = array('page_title' => $page_title, 'page' => $page, 'zone' => $zone, 'zone_name' => $zone_name, 'pagelink' => $pagelink, 'wrappable_pagelink' => $wrappable_pagelink, 'actions' => $actions);
     }
     // Manual sorting
     global $M_SORT_KEY;
     $M_SORT_KEY = $sortable;
     usort($_table_rows, 'multi_sort');
     if ($sort_order == 'DESC') {
         $_table_rows = array_reverse($_table_rows);
     }
     $table_rows = new ocp_tempcode();
     if (!$found_via_query) {
         $max_rows = count($_table_rows);
     }
     foreach ($_table_rows as $i => $table_row) {
         if (!$found_via_query) {
             if ($i < $start) {
                 continue;
             }
             if ($i > $max + $start) {
                 break;
             }
         }
         $table_rows->attach(results_entry(array(protect_from_escaping(hyperlink(build_url(array('page' => $table_row['page']), $table_row['zone']), $table_row['page_title'])), protect_from_escaping(do_template('COMCODE_TELETYPE', array('CONTENT' => preg_replace('#([\\w\\d\\_]{22})#', '${1}<br />', escape_html($table_row['page']))))), protect_from_escaping(hyperlink(build_url(array('page' => ''), $table_row['zone']), $table_row['zone_name'], false, true)), protect_from_escaping(do_template('COMCODE_TELETYPE', array('CONTENT' => preg_replace('#([\\w\\d\\_]{22})#', '${1}<br />', escape_html($table_row['wrappable_pagelink']))))), protect_from_escaping($table_row['actions'])), true));
     }
     $table = results_table(do_lang('COMCODE_PAGES'), $start, 'start', $max, 'max', $max_rows, $header_row, $table_rows, $sortables, $sortable, $sort_order, 'sort', NULL, NULL, NULL, 8, 'fdgfdfdfdggfd', true);
     return do_template('TABLE_TABLE_SCREEN', array('TITLE' => $title, 'TEXT' => $text, 'TABLE' => $table, 'FIELDS' => $fields, 'POST_URL' => $post_url, 'GET' => true, 'HIDDEN' => $hidden, 'SUBMIT_NAME' => $submit_name));
 }
Example #19
0
 /**
  * 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));
 }
Example #20
0
 /**
  * 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));
 }
Example #21
0
/**
 * Build zone menu.
 *
 * @return array			Faked database rows
 */
function build_zone_menu()
{
    $_zones = find_all_zones(false, true);
    $zones = array();
    $zones2 = array();
    // Some adhoc reordering
    $zone_reorder_list = array('welcome', 'site', 'forum', 'collaboration', 'cms', 'adminzone', 'docs');
    foreach ($zone_reorder_list as $zone_reorder) {
        foreach ($_zones as $i => $_zone) {
            list($zone, , ) = $_zone;
            if ($zone == $zone_reorder) {
                $zones[] = $_zone;
                unset($_zones[$i]);
                break;
            }
        }
    }
    if (count($_zones) < 40) {
        $zones = array_merge($zones, $_zones);
    }
    $items = array();
    $i = 1;
    foreach ($zones as $_zone) {
        list($zone, $title, $display_in_menu) = $_zone;
        if (has_zone_access(get_member(), $zone) && $display_in_menu == 1) {
            $items[] = array('id' => $i, 'i_parent' => NULL, 'cap' => escape_html($title), 'i_url' => $zone . ':', 'i_check_permissions' => 0, 'i_expanded' => 0, 'i_new_window' => 0, 'i_page_only' => '');
        }
        $i++;
    }
    return $items;
}
Example #22
0
 /**
  * The UI to manage themes.
  *
  * @return tempcode		The UI
  */
 function manage_themes()
 {
     $title = get_page_title('MANAGE_THEMES');
     $GLOBALS['HELPER_PANEL_TEXT'] = comcode_lang_string('DOC_THEMES');
     $zones = $GLOBALS['SITE_DB']->query_select('zones', array('*'), NULL, 'ORDER BY zone_title', 50);
     // Show all themes
     $_themes = find_all_themes(true);
     $site_default_theme = $GLOBALS['FORUM_DRIVER']->_get_theme(true);
     $themes = new ocp_tempcode();
     $theme_default_reason = do_lang_tempcode('DEFAULT_THEME_BY_DEFAULT');
     foreach ($_themes as $theme => $details) {
         if (is_integer($theme)) {
             $theme = strval($theme);
         }
         // Get URLs
         $css_url = build_url(array('page' => '_SELF', 'type' => 'choose_css', 'theme' => $theme), '_SELF');
         $templates_url = build_url(array('page' => '_SELF', 'type' => 'edit_templates', 'theme' => $theme), '_SELF');
         $images_url = build_url(array('page' => '_SELF', 'type' => 'manage_images', 'theme' => $theme), '_SELF');
         $deletable = $theme != 'default';
         $edit_url = build_url(array('page' => '_SELF', 'type' => 'edit_theme', 'theme' => $theme), '_SELF');
         $delete_url = build_url(array('page' => '_SELF', 'type' => 'delete_theme', 'theme' => $theme), '_SELF');
         $screen_preview_url = build_url(array('page' => '_SELF', 'type' => 'list', 'keep_theme' => $theme), '_SELF');
         // Theme date
         $date = filemtime($theme == 'default' ? get_file_base() . '/themes/default' : get_custom_file_base() . '/themes/' . $theme);
         $_date = $theme == 'default' ? do_lang_tempcode('NA_EM') : protect_from_escaping(escape_html(get_timezoned_date($date, false)));
         // Where the theme is used
         $zone_list = new ocp_tempcode();
         if ($theme == $site_default_theme) {
             $zone_list->attach(do_lang_tempcode('THEME_DEFAULT_FOR_SITE'));
             // Why is this the site-default theme?
             if ($theme == preg_replace('#[^\\w\\-\\.\\d]#', '_', get_site_name())) {
                 $theme_default_reason = do_lang_tempcode('DEFAULT_THEME_BY_SITENAME');
             } elseif ($theme != 'default') {
                 $theme_default_reason = do_lang_tempcode('DEFAULT_THEME_BY_FORUM');
             }
         }
         foreach ($zones as $zone) {
             if ($zone['zone_theme'] == $theme) {
                 if (get_option('collapse_user_zones') == '1' && $zone['zone_name'] == 'site') {
                     continue;
                 }
                 if (!$zone_list->is_empty()) {
                     $zone_list->attach(do_lang_tempcode('LIST_SEP'));
                 }
                 $zone_list->attach($zone['zone_name']);
             }
         }
         if (!$zone_list->is_empty()) {
             $theme_usage = do_lang_tempcode('THEME_USED_ON', $zone_list);
         } else {
             $theme_usage = new ocp_tempcode();
         }
         // Render
         $seed = NULL;
         if (addon_installed('themewizard')) {
             require_code('themewizard');
             $seed = find_theme_seed($theme);
         }
         $themes->attach(do_template('THEME_MANAGE', array('_GUID' => 'c65c7f3f87d62ad425c7a104a6018840', 'SEED' => $seed, 'THEME_USAGE' => $theme_usage, 'DATE' => $_date, 'RAW_DATE' => strval($date), 'NAME' => $theme, 'DESCRIPTION' => $details['description'], 'AUTHOR' => $details['author'], 'TITLE' => $details['title'], 'CSS_URL' => $css_url, 'TEMPLATES_URL' => $templates_url, 'IMAGES_URL' => $images_url, 'DELETABLE' => $deletable, 'EDIT_URL' => $edit_url, 'DELETE_URL' => $delete_url, 'SCREEN_PREVIEW_URL' => $screen_preview_url)));
     }
     $zones = find_all_zones(false, true);
     require_lang('zones');
     return do_template('THEME_MANAGE_SCREEN', array('_GUID' => '1dc277f18562976f6a23facec56a98e8', 'TITLE' => $title, 'THEMES' => $themes, 'THEME_DEFAULT_REASON' => $theme_default_reason, 'ZONES' => $zones));
 }
Example #23
0
 /**
  * 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;
 }
Example #24
0
    /**
     * 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);
            }
        }
    }
Example #25
0
/**
 * Get all html files.
 *
 * @return array		List of htmls.
 */
function find_html()
{
    $zones = find_all_zones();
    $files = array();
    foreach ($zones as $zone) {
        $z = $zone == '' ? 'pages' : $zone;
        $files[$z] = find_all_pages($zone, 'html/' . fallback_lang(), 'htm');
        //$files[$z] += find_all_pages($zone,'html_custom/'.fallback_lang(),'htm');
    }
    return $files;
}
Example #26
0
/**
 * 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();
}
Example #27
0
 /**
  * The UI to translate code.
  *
  * @return tempcode		The UI
  */
 function interface_code()
 {
     $lang = filter_naughty_harsh(get_param('lang', ''));
     $lang_new = get_param('lang_new', $lang);
     if ($lang_new != '') {
         require_code('type_validation');
         if (!is_alphanumeric($lang_new, true)) {
             warn_exit(do_lang_tempcode('BAD_CODENAME'));
         }
         if (strlen($lang_new) > 5) {
             warn_exit(do_lang_tempcode('INVALID_LANG_CODE'));
         }
         $lang = $lang_new;
     }
     if ($lang == '') {
         $title = get_page_title('TRANSLATE_CODE');
         $GLOBALS['HELPER_PANEL_TEXT'] = comcode_lang_string('DOC_FIND_LANG_STRING_TIP');
         return $this->choose_lang($title, true, true, do_lang_tempcode('CHOOSE_EDIT_LIST_LANG_FILE'));
     }
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('CHOOSE'))));
     breadcrumb_set_self(do_lang_tempcode('TRANSLATE_CODE'));
     $base_lang = fallback_lang();
     $map_a = get_file_base() . '/lang/langs.ini';
     $map_b = get_custom_file_base() . '/lang_custom/langs.ini';
     $search = get_param('search', '', true);
     if ($search != '') {
         $title = get_page_title('TRANSLATE_CODE');
         require_code('form_templates');
         $fields = new ocp_tempcode();
         global $LANGUAGE;
         foreach ($LANGUAGE[user_lang()] as $key => $value) {
             if (strpos(strtolower($value), strtolower($search)) !== false) {
                 $fields->attach(form_input_text($key, '', 'l_' . $key, str_replace('\\n', chr(10), $value), false));
             }
         }
         if ($fields->is_empty()) {
             inform_exit(do_lang_tempcode('NO_ENTRIES'));
         }
         $post_url = build_url(array('page' => '_SELF', 'type' => '_code2'), '_SELF');
         $hidden = new ocp_tempcode();
         $hidden->attach(form_input_hidden('redirect', get_self_url(true)));
         $hidden->attach(form_input_hidden('lang', $lang));
         return do_template('FORM_SCREEN', array('_GUID' => '2d7356fd2c4497ceb19450e65331c9c5', 'TITLE' => $title, 'HIDDEN' => $hidden, 'FIELDS' => $fields, 'URL' => $post_url, 'TEXT' => '', 'SUBMIT_NAME' => do_lang('TRANSLATE_CODE')));
     }
     $lang_file = get_param('lang_file');
     if (!file_exists($map_b)) {
         $map_b = $map_a;
     }
     $map = better_parse_ini_file($map_b);
     $title = get_page_title('_TRANSLATE_CODE', true, array(escape_html($lang_file), escape_html(array_key_exists($lang, $map) ? $map[$lang] : $lang)));
     // Upgrade to custom if not there yet (or maybe we are creating a new lang - same difference)
     $custom_dir = get_custom_file_base() . '/lang_custom/' . $lang;
     if (!file_exists($custom_dir)) {
         require_code('abstract_file_manager');
         force_have_afm_details();
         afm_make_directory('lang_custom/' . $lang, true);
         $cached_dir = get_custom_file_base() . '/lang_cached/' . $lang;
         if (!file_exists($cached_dir)) {
             afm_make_directory('lang_cached/' . $lang, true);
         }
         // Make comcode page dirs
         $zones = find_all_zones();
         foreach ($zones as $zone) {
             $_special_dir = get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . $lang;
             if (!file_exists($_special_dir)) {
                 afm_make_directory($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang, true);
             }
             $_special_dir = get_custom_file_base() . '/' . $zone . '/pages/html_custom/' . $lang;
             if (!file_exists($_special_dir)) {
                 afm_make_directory($zone . ($zone == '' ? '' : '/') . 'pages/html_custom/' . $lang, true);
             }
         }
         // Make templates_cached dirs
         require_code('themes2');
         $themes = find_all_themes();
         foreach (array_keys($themes) as $theme) {
             $_special_dir = get_custom_file_base() . '/themes/' . $theme . '/templates_cached/' . $lang;
             if (!file_exists($_special_dir)) {
                 afm_make_directory('themes/' . $theme . '/templates_cached/' . $lang, true);
             }
         }
     }
     // Get some stuff
     $for_lang = get_lang_file_map($lang, $lang_file);
     $for_base_lang = get_lang_file_map($base_lang, $lang_file, true);
     $descriptions = get_lang_file_descriptions($base_lang, $lang_file);
     // Make our translation page
     $lines = '';
     $intertrans = $this->get_intertran_conv($lang);
     $actions = new ocp_tempcode();
     $next = 0;
     $trans_lot = '';
     $delimit = chr(10) . '=-=-=-=-=-=-=-=-' . chr(10);
     foreach ($for_base_lang as $name => $old) {
         if (array_key_exists($name, $for_lang)) {
             $current = $for_lang[$name];
         } else {
             $current = '';
             //$this->find_lang_matches($old,$lang); Too slow / useless for code translation
         }
         if ($current == '' && strtolower($name) != $name) {
             $trans_lot .= str_replace('\\n', chr(10), str_replace(array('{', '}'), array('(((', ')))'), $old)) . $delimit;
         }
     }
     $translated_stuff = array();
     if ($trans_lot != '' && $intertrans != '') {
         $result = http_download_file('http://translate.google.com/translate_t', NULL, false, false, 'ocPortal', array('text' => $trans_lot, 'langpair' => 'en|' . $intertrans));
         if (!is_null($result)) {
             require_code('character_sets');
             $result = convert_to_internal_encoding($result);
             $matches = array();
             if (preg_match('#<div id=result_box dir="ltr">(.*)</div>#Us', convert_to_internal_encoding($result), $matches) != 0) {
                 $result2 = $matches[1];
                 $result2 = @html_entity_decode($result2, ENT_QUOTES, get_charset());
                 $result2 = preg_replace('#\\s?<br>\\s?#', chr(10), $result2);
                 $result2 = str_replace('> ', '>', str_replace(' <', ' <', str_replace('</ ', '</', str_replace(array('(((', ')))'), array('{', '}'), $result2))));
                 $translated_stuff = explode(trim($delimit), $result2 . chr(10));
             }
         }
     }
     foreach ($for_base_lang + $for_lang as $name => $old) {
         if (array_key_exists($name, $for_lang)) {
             $current = $for_lang[$name];
         } else {
             $current = '';
             //$this->find_lang_matches($old,$lang); Too slow / useless for code translation
         }
         $description = array_key_exists($name, $descriptions) ? $descriptions[$name] : '';
         if ($current == '' && strtolower($name) != $name && array_key_exists($next, $translated_stuff)) {
             $_current = '';
             $translate_auto = trim($translated_stuff[$next]);
             $next++;
         } else {
             $_current = str_replace('\\n', chr(10), $current);
             $translate_auto = NULL;
         }
         if ($_current == '') {
             $_current = str_replace('\\n', chr(10), $old);
         }
         if ($intertrans != '' && get_value('google_translate_api_key') !== NULL) {
             $actions = do_template('TRANSLATE_ACTION', array('_GUID' => '9e9a68cb2c1a1e23a901b84c9af2280b', 'LANG_FROM' => get_site_default_lang(), 'LANG_TO' => $lang, 'NAME' => 'trans_' . $name, 'OLD' => $_current));
         }
         $temp = do_template('TRANSLATE_LINE', array('_GUID' => '9cb331f5852ee043e6ad30b45aedc43b', 'TRANSLATE_AUTO' => $translate_auto, 'DESCRIPTION' => $description, 'NAME' => $name, 'OLD' => str_replace('\\n', chr(10), $old), 'CURRENT' => $_current, 'ACTIONS' => $actions));
         $lines .= $temp->evaluate();
     }
     $url = build_url(array('page' => '_SELF', 'type' => '_code', 'lang_file' => $lang_file, 'lang' => $lang), '_SELF');
     return do_template('TRANSLATE_SCREEN', array('_GUID' => 'b3429f8bd0b4eb79c33709ca43e3207c', 'PAGE' => $lang_file, 'INTERTRANS' => get_value('google_translate_api_key') !== NULL ? $intertrans : '', 'LANG' => $lang, 'LINES' => $lines, 'TITLE' => $title, 'URL' => $url));
 }
Example #28
0
/**
 * Find the URL to a certain external handler script (ocPortal allows these to be moved around between zones, to suit site .htaccess requirements).
 *
 * @param  string			The codename of the needed script
 * @param  boolean		Whether to append keep variables
 * @param  integer		Code representing what base URL type to use (0=guess, 1=http, 2=https)
 * @set 0 1 2
 * @return URLPATH		The URL to the script
 */
function find_script($name, $append_keep = false, $base_url_code = 0)
{
    $append = '';
    if ($append_keep) {
        $keep = symbol_tempcode('KEEP', array('1'));
        $append .= $keep->evaluate();
    }
    global $CACHE_FIND_SCRIPT;
    if ($CACHE_FIND_SCRIPT === array()) {
        if (function_exists('persistant_cache_get')) {
            $CACHE_FIND_SCRIPT = persistant_cache_get('SCRIPT_PLACES');
        }
        if ($CACHE_FIND_SCRIPT === NULL) {
            $CACHE_FIND_SCRIPT = array();
        }
    }
    if (isset($CACHE_FIND_SCRIPT[$name][$append_keep][$base_url_code])) {
        return $CACHE_FIND_SCRIPT[$name][$append_keep][$base_url_code] . $append;
    }
    $zones = array(get_zone_name());
    if (!in_safe_mode()) {
        $zones[] = 'data_custom';
    }
    $zones[] = 'data';
    $zones = array_merge($zones, find_all_zones());
    foreach ($zones as $zone) {
        if (is_file(get_file_base() . '/' . $zone . '/' . $name . '.php')) {
            $ret = get_base_url() . '/' . $zone . ($zone != '' ? '/' : '') . $name . '.php';
            $CACHE_FIND_SCRIPT[$name][$append_keep][$base_url_code] = $ret;
            if (function_exists('persistant_cache_set')) {
                persistant_cache_set('SCRIPT_PLACES', $CACHE_FIND_SCRIPT, true);
            }
            return $ret . $append;
        }
    }
    $ret = get_base_url($base_url_code == 0 ? NULL : $base_url_code == 2) . '/site/' . $name . '.php';
    $CACHE_FIND_SCRIPT[$name][$append_keep][$base_url_code] = $ret;
    if (function_exists('persistant_cache_set')) {
        persistant_cache_set('SCRIPT_PLACES', $CACHE_FIND_SCRIPT, true);
    }
    return $ret . $append;
}
Example #29
0
/**
 * Convert a local URL to a page-link.
 *
 * @param  URLPATH		The URL to convert. Note it may not be a short URL, and it must be based on the local base URL (else failure WILL occur).
 * @param  boolean		Whether to only convert absolute URLs. Turn this on if you're not sure what you're passing is a URL not and you want to be extra safe.
 * @param  boolean		Whether to only allow perfect conversions.
 * @return string			The page link (blank: could not convert).
 */
function _url_to_pagelink($url, $abs_only = false, $perfect_only = true)
{
    if ($abs_only && substr($url, 0, 7) != 'http://' && substr($url, 0, 8) != 'https://') {
        return '';
    }
    // Try and strip any variants of the base URL from our $url variable, to make it relative
    $non_www_base_url = str_replace('http://www.', 'http://', get_base_url());
    $www_base_url = str_replace('http://', 'http://www.', get_base_url());
    $url = preg_replace('#^' . str_replace('#', '\\#', preg_quote(get_base_url() . '/')) . '#', '', $url);
    $url = preg_replace('#^' . str_replace('#', '\\#', preg_quote($non_www_base_url . '/')) . '#', '', $url);
    $url = preg_replace('#^' . str_replace('#', '\\#', preg_quote($www_base_url . '/')) . '#', '', $url);
    if (substr($url, 0, 7) == 'http://') {
        return '';
    }
    if (substr($url, 0, 8) == 'https://') {
        return '';
    }
    if (substr($url, 0, 1) != '/') {
        $url = '/' . $url;
    }
    // Parse the URL
    if (strpos($url, '&') !== false && strpos($url, '?') === false) {
        $url = preg_replace('#&#', '?', $url, 1);
    }
    // Old-style short URLs workl like this (no first ?, just &)
    $parsed_url = @parse_url($url);
    if ($parsed_url === false) {
        require_code('site');
        attach_message(do_lang_tempcode('HTTP_DOWNLOAD_BAD_URL', escape_html($url)), 'warn');
        return '';
    }
    // Work out the zone
    $slash_pos = strpos($parsed_url['path'], '/', 1);
    $zone = $slash_pos !== false ? substr($parsed_url['path'], 1, $slash_pos - 1) : '';
    if (!in_array($zone, find_all_zones())) {
        $zone = '';
        $slash_pos = false;
    }
    $parsed_url['path'] = $slash_pos === false ? substr($parsed_url['path'], 1) : substr($parsed_url['path'], $slash_pos + 1);
    // everything AFTER the zone
    $parsed_url['path'] = preg_replace('#/index\\.php$#', '', $parsed_url['path']);
    $attributes = array();
    $attributes['page'] = '';
    // hopefully will get overwritten with a real one
    // Convert short URL path info into extra implied attribute data
    require_code('url_remappings');
    foreach (array(false, true) as $method) {
        $mappings = get_remappings($method);
        foreach ($mappings as $mapping) {
            if (is_null($mapping)) {
                continue;
            }
            list($params, $match_string, ) = $mapping;
            $match_string_pattern = preg_replace('#[A-Z]+#', '[^\\&\\?]+', preg_quote($match_string));
            $zones = find_all_zones();
            if (preg_match('#^' . $match_string_pattern . '$#', $parsed_url['path']) != 0) {
                $attributes = array_merge($attributes, $params);
                $bits_pattern = explode('/', preg_replace('#\\.htm$#', '', $match_string));
                $bits_real = explode('/', preg_replace('#\\.htm$#', '', $parsed_url['path']), count($bits_pattern));
                foreach ($bits_pattern as $i => $bit) {
                    if (array_key_exists(strtolower($bit), $params) && strtoupper($bit) == $bit && is_null($params[strtolower($bit)])) {
                        $attributes[strtolower($bit)] = $bits_real[$i];
                    }
                }
                break;
            }
        }
    }
    if ($attributes == array('page' => '') && $parsed_url['path'] != '') {
        if (strpos($parsed_url['path'], '/pg/') === false && strpos($parsed_url['path'], '.htm') === false && $parsed_url['path'] != 'index.php') {
            return '';
        }
    }
    // Parse query string component into the waiting (and partly-filled-already) attribute data array
    if (array_key_exists('query', $parsed_url)) {
        $bits = explode('&', $parsed_url['query']);
        foreach ($bits as $bit) {
            $_bit = explode('=', $bit, 2);
            if (count($_bit) == 2) {
                $attributes[$_bit[0]] = $_bit[1];
                if (strpos($attributes[$_bit[0]], ':') !== false) {
                    if ($perfect_only) {
                        return '';
                    }
                    // Could not convert this URL to a page-link, because it contains a colon
                    unset($attributes[$_bit[0]]);
                }
            }
        }
    }
    // Put it together
    $page_link = $zone . ':' . $attributes['page'];
    if (array_key_exists('type', $attributes)) {
        $page_link .= ':' . $attributes['type'];
    } elseif (array_key_exists('id', $attributes)) {
        $page_link .= ':';
    }
    if (array_key_exists('id', $attributes)) {
        $page_link .= ':' . urldecode($attributes['id']);
    }
    foreach ($attributes as $key => $val) {
        if (!is_string($val)) {
            $val = strval($val);
        }
        if ($key != 'page' && $key != 'type' && $key != 'id') {
            $page_link .= ':' . $key . '=' . urldecode($val);
        }
    }
    // Hash bit?
    if (array_key_exists('fragment', $parsed_url)) {
        $page_link .= '#' . $parsed_url['fragment'];
    }
    return $page_link;
}
Example #30
0
/**
 * Backend function to do a backup (meant to be run as a shutdown function - essentially a background task).
 *
 * @param  ?string		The filename to backup to (NULL: get global)
 * @param  ?string		The type of backup to do (NULL: get global)
 * @set    full incremental
 * @param  ?integer		The maximum size of a file to include in the backup (NULL: get global)
 */
function make_backup_2($file = NULL, $b_type = NULL, $max_size = NULL)
{
    global $STARTED_BACKUP;
    if ($STARTED_BACKUP) {
        return;
    }
    $STARTED_BACKUP = true;
    if (is_null($file)) {
        global $MB2_FILE, $MB2_B_TYPE, $MB2_MAX_SIZE;
        $file = $MB2_FILE;
        $b_type = $MB2_B_TYPE;
        $max_size = $MB2_MAX_SIZE;
    }
    if (function_exists('set_time_limit')) {
        @set_time_limit(0);
    }
    $logfile_path = get_custom_file_base() . '/exports/backups/' . $file . '.txt';
    $logfile = @fopen($logfile_path, 'wt') or intelligent_write_error($logfile_path);
    // .txt file because IIS doesn't allow .log download
    @ini_set('log_errors', '1');
    @ini_set('error_log', $logfile_path);
    fwrite($logfile, 'This is a log file for an ocPortal backup. The backup is not complete unless this log terminates with a completion message.' . "\n\n");
    require_code('tar');
    $myfile = tar_open(get_custom_file_base() . '/exports/backups/' . filter_naughty($file), 'wb');
    // Write readme.txt file
    tar_add_file($myfile, 'readme.txt', do_lang('BACKUP_README', get_timezoned_date(time())), 0664, time());
    // Write restore.php file
    $template = get_custom_file_base() . '/data_custom/modules/admin_backup/restore.php.pre';
    if (!file_exists($template)) {
        $template = get_file_base() . '/data/modules/admin_backup/restore.php.pre';
    }
    $_install_php_file = file_get_contents($template);
    $place = strpos($_install_php_file, '{!!DB!!}');
    $__install_php_file = ocp_tempnam('ocpbak');
    $install_php_file = fopen($__install_php_file, 'wb');
    fwrite($install_php_file, substr($_install_php_file, 0, $place));
    get_table_backup($logfile, 'db_meta', 'db_meta_indices', $install_php_file);
    if (fwrite($install_php_file, substr($_install_php_file, $place + 8)) == 0) {
        warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
    }
    fclose($install_php_file);
    tar_add_file($myfile, 'restore.php', $__install_php_file, 0664, time(), true);
    @unlink($__install_php_file);
    if ($b_type == 'full') {
        set_value('last_backup', strval(time()));
        $original_files = get_param_integer('keep_backup_alien', 0) == 1 ? unserialize(file_get_contents(get_file_base() . '/data/files.dat')) : NULL;
        $root_only_dirs = array_merge(find_all_zones(false, false, true), array('data', 'data_custom', 'exports', 'imports', 'lang', 'lang_custom', 'lang_cached', 'pages', 'persistant_cache', 'safe_mode_temp', 'sources', 'sources_custom', 'text', 'text_custom', 'themes', 'uploads', 'site'));
        tar_add_folder($myfile, $logfile, get_file_base(), $max_size, '', $original_files, $root_only_dirs, !running_script('cron_bridge'), true);
    } elseif ($b_type == 'incremental') {
        $threshold = intval(get_value('last_backup'));
        set_value('last_backup', strval(time()));
        $directory = tar_add_folder_incremental($myfile, $logfile, get_file_base(), $threshold, $max_size);
        $_directory = '';
        foreach ($directory as $d) {
            $a = '';
            foreach ($d as $k => $v) {
                if ($a != '') {
                    $a .= ", ";
                }
                $a .= $k . '=' . $v;
            }
            $_directory .= $a . "\n";
        }
        tar_add_file($myfile, 'DIRECTORY', $_directory, 0664, time());
    } else {
        set_value('last_backup', strval(time()));
    }
    tar_close($myfile);
    if (!file_exists(get_custom_file_base() . '/exports/backups/' . filter_naughty($file))) {
        warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
    }
    rename(get_custom_file_base() . '/exports/backups/' . filter_naughty($file), get_custom_file_base() . '/exports/backups/' . filter_naughty($file) . '.tar');
    sync_file('exports/backups/' . filter_naughty($file) . '.tar');
    fix_permissions('exports/backups/' . filter_naughty($file) . '.tar');
    $url = get_base_url() . '/exports/backups/' . $file . '.tar';
    if (function_exists('gzopen')) {
        if (fwrite($logfile, "\n" . do_lang('COMPRESSING') . "\n") == 0) {
            warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
        }
        $myfile = gzopen(get_custom_file_base() . '/exports/backups/' . $file . '.tar.gz.tmp', 'wb') or intelligent_write_error(get_custom_file_base() . '/exports/backups/' . $file . '.tar.gz.tmp');
        $tar_path = get_custom_file_base() . '/exports/backups/' . filter_naughty($file) . '.tar';
        $fp_in = fopen($tar_path, 'rb');
        while (!feof($fp_in)) {
            $read = fread($fp_in, 8192);
            gzwrite($myfile, $read, strlen($read));
        }
        fclose($fp_in);
        gzclose($myfile);
        rename(get_custom_file_base() . '/exports/backups/' . $file . '.tar.gz.tmp', get_custom_file_base() . '/exports/backups/' . $file . '.tar.gz');
        fix_permissions(get_custom_file_base() . '/exports/backups/' . $file . '.tar.gz');
        sync_file('exports/backups/' . filter_naughty($file) . '.tar.gz');
        $url = get_base_url() . '/exports/backups/' . $file . '.tar.gz';
    }
    if (fwrite($logfile, "\n" . do_lang('SUCCESS') . "\n") == 0) {
        warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
    }
    fclose($logfile);
    sync_file($logfile_path);
    fix_permissions($logfile_path);
    sync_file($logfile_path);
    // Remote backup
    $copy_server = get_option('backup_server_hostname');
    if ($copy_server != '') {
        $path_stub = get_custom_file_base() . '/exports/backups/';
        if (file_exists($path_stub . $file . '.tar.gz')) {
            $_file = $file . '.tar.gz';
        } elseif (file_exists($path_stub . $file . '.tar')) {
            $_file = $file . '.tar';
        } else {
            $file = NULL;
        }
        if (!is_null($file)) {
            $copy_port = get_option('backup_server_port');
            if ($copy_port == '') {
                $copy_port = '21';
            }
            $copy_user = get_option('backup_server_user');
            if ($copy_user == '') {
                $copy_user = '******';
            }
            $copy_password = get_option('backup_server_password');
            if (is_null($copy_password)) {
                $copy_password = get_option('staff_address');
            }
            $copy_path = get_option('backup_server_path');
            if ($copy_path == '') {
                $copy_path = $_file;
            } elseif (substr($copy_path, -1) == '/' || $copy_path == '') {
                $copy_path .= $_file;
            }
            $ftp_connection = @ftp_connect($copy_server, intval($copy_port));
            if ($ftp_connection !== false) {
                if (@ftp_login($ftp_connection, $copy_user, $copy_password)) {
                    @ftp_delete($ftp_connection, $path_stub . $_file);
                    @ftp_put($ftp_connection, $copy_path, $path_stub, FTP_BINARY);
                }
                @ftp_close($ftp_connection);
            }
        }
    }
    require_code('notifications');
    dispatch_notification('backup_finished', NULL, do_lang('BACKUP', NULL, NULL, NULL, get_site_default_lang()), do_lang('BACKUP_FINISHED', comcode_escape($url), get_site_default_lang()), NULL, A_FROM_SYSTEM_PRIVILEGED);
}