Example #1
0
/**
 * Helper function for *_text_file
 *
 * @param  string				The file name (without .txt)
 * @param  ?LANGUAGE_NAME	The language to load from (NULL: none) (blank: search)
 * @return string				The path to the file
 */
function _find_text_file_path($codename, $lang)
{
    if (is_null($lang)) {
        $langs = array('');
    } elseif ($lang != '') {
        $langs = array($lang);
    } else {
        $langs = array(user_lang());
        if (get_site_default_lang() != user_lang()) {
            $langs[] = get_site_default_lang();
        }
        if (fallback_lang() != get_site_default_lang()) {
            $langs[] = fallback_lang();
        }
    }
    $i = 0;
    $path = '';
    do {
        $lang = $langs[$i];
        $path = get_custom_file_base() . '/text_custom/' . $lang . '/' . $codename . '.txt';
        if (!file_exists($path)) {
            $path = get_file_base() . '/text/' . $lang . '/' . $codename . '.txt';
        }
        $i++;
    } while (!file_exists($path) && array_key_exists($i, $langs));
    if (!file_exists($path)) {
        $path = '';
    }
    return $path;
}
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 do_next_menu hooks. They find links to put on standard navigation menus of the system.
  *
  * @return array			Array of links and where to show
  */
 function run()
 {
     $has_langs = false;
     $_dir = opendir(get_file_base() . '/lang/');
     $_langs = array();
     while (false !== ($file = readdir($_dir))) {
         if ($file == fallback_lang()) {
             continue;
         }
         if (!should_ignore_file('lang/' . $file, IGNORE_ACCESS_CONTROLLERS) && strlen($file) <= 5) {
             if (is_dir(get_file_base() . '/lang/' . $file)) {
                 $has_langs = true;
             }
         }
     }
     closedir($_dir);
     if (!in_safe_mode()) {
         $_dir = @opendir(get_custom_file_base() . '/lang_custom/');
         if ($_dir !== false) {
             while (false !== ($file = readdir($_dir))) {
                 if ($file == fallback_lang()) {
                     continue;
                 }
                 if (!should_ignore_file('lang_custom/' . $file, IGNORE_ACCESS_CONTROLLERS) && strlen($file) <= 5) {
                     if (is_dir(get_custom_file_base() . '/lang_custom/' . $file)) {
                         $has_langs = true;
                     }
                 }
             }
             closedir($_dir);
         }
         if (get_custom_file_base() != get_file_base()) {
             $_dir = opendir(get_file_base() . '/lang_custom/');
             while (false !== ($file = readdir($_dir))) {
                 if ($file == fallback_lang()) {
                     continue;
                 }
                 if (!should_ignore_file('lang_custom/' . $file, IGNORE_ACCESS_CONTROLLERS) && strlen($file) <= 5) {
                     $has_langs = true;
                 }
             }
             closedir($_dir);
         }
     }
     return array(array('style', 'language', array('admin_lang', array('type' => 'misc'), get_module_zone('admin_lang')), do_lang_tempcode('TRANSLATE_CODE'), 'DOC_TRANSLATE'), multi_lang() ? array('style', 'language', array('admin_lang', array('type' => 'content'), get_module_zone('admin_lang')), do_lang_tempcode('TRANSLATE_CONTENT'), 'DOC_TRANSLATE_CONTENT') : NULL, !$has_langs ? NULL : array('style', 'criticise_language', array('admin_lang', array('type' => 'criticise'), get_module_zone('admin_lang')), do_lang_tempcode('CRITICISE_LANGUAGE_PACK'), 'DOC_CRITICISE_LANGUAGE_PACK'));
 }
Example #4
0
/**
 * Compile a template into a list of appendable outputs, for the closure-style Tempcode implementation.
 *
 * @param  string			The template file contents
 * @param  ID_TEXT		The name of the template
 * @param  ID_TEXT		The name of the theme
 * @param  ID_TEXT		The language it is for
 * @param  boolean		Whether to tolerate errors
 * @return array			A pair: array Compiled result structure, array preprocessable bits (special stuff needing attention that is referenced within the template)
 */
function compile_template($data, $template_name, $theme, $lang, $tolerate_errors = false)
{
    if (strpos($data, '{$,Parser hint: pure}') !== false) {
        return array(array('"' . php_addslashes(preg_replace('#\\{\\$,.*\\}#U', '/*no minify*/', $data)) . '"'), array());
    }
    $data = preg_replace('#<\\?php(.*)\\?' . '>#sU', '{+START,PHP}${1}{+END}', $data);
    $compilable_symbols = array('"ADDON_INSTALLED"', '"COPYRIGHT"', '"SITE_NAME"', '"BRAND_BASE_URL"', '"BRAND_NAME"', '"IMG_WIDTH"', '"IMG_HEIGHT"', '"LANG"', '"THEME"', '"VALUE_OPTION"', '"CONFIG_OPTION"');
    if (function_exists('get_option') && get_option('enable_https', true) != '1') {
        $compilable_symbols[] = '"BASE_URL"';
    }
    global $SITE_INFO;
    if (isset($SITE_INFO['no_keep_params']) && $SITE_INFO['no_keep_params'] == '1') {
        $compilable_symbols[] = '"PAGE_LINK"';
        $compilable_symbols[] = '"FIND_SCRIPT"';
    }
    require_code('lang');
    require_code('urls');
    $cl = fallback_lang();
    $bits = array_values(preg_split('#(?<!\\\\)(\\{(?=[\\dA-Z\\$\\+\\!\\_]+[\\.`%\\*=\\;\\#\\-~\\^\\|\'&/@]*))|((?<!\\\\)\\,)|((?<!\\\\)\\})#', $data, -1, PREG_SPLIT_DELIM_CAPTURE));
    // One error mail showed on a server it had weird indexes, somehow. Hence the array_values call to reindex it
    $count = count($bits);
    $stack = array();
    $current_level_mode = PARSE_NO_MANS_LAND;
    $current_level_data = array();
    $current_level_params = array();
    $preprocessable_bits = array();
    for ($i = 0; $i < $count; $i++) {
        $next_token = $bits[$i];
        if ($next_token == '') {
            continue;
        }
        if ($i != $count - 1 && $next_token == '{' && preg_match('#^[\\dA-Z\\$\\+\\!\\_]#', $bits[$i + 1]) == 0) {
            $current_level_data[] = '"{}"';
            continue;
        }
        switch ($next_token) {
            case '{':
                // Open a new level
                $stack[] = array($current_level_mode, $current_level_data, $current_level_params, NULL, NULL, NULL);
                ++$i;
                $next_token = isset($bits[$i]) ? $bits[$i] : NULL;
                if (is_null($next_token)) {
                    if ($tolerate_errors) {
                        continue;
                    }
                    warn_exit(do_lang_tempcode('ABRUPTED_DIRECTIVE_OR_BRACE', escape_html($template_name), integer_format(1 + substr_count(substr($data, 0, _length_so_far($bits, $i)), chr(10)))));
                }
                $current_level_data = array();
                switch (substr($next_token, 0, 1)) {
                    case '$':
                        $current_level_mode = PARSE_SYMBOL;
                        $current_level_data[] = '"' . php_addslashes(substr($next_token, 1)) . '"';
                        break;
                    case '+':
                        $current_level_mode = PARSE_DIRECTIVE;
                        $current_level_data[] = '"' . php_addslashes(substr($next_token, 1)) . '"';
                        break;
                    case '!':
                        $current_level_mode = PARSE_LANGUAGE_REFERENCE;
                        $current_level_data[] = '"' . php_addslashes(substr($next_token, 1)) . '"';
                        break;
                    default:
                        $current_level_mode = PARSE_PARAMETER;
                        $current_level_data[] = '"' . php_addslashes($next_token) . '"';
                        break;
                }
                $current_level_params = array();
                break;
            case '}':
                if (count($stack) == 0 || $current_level_mode == PARSE_DIRECTIVE_INNER) {
                    $literal = php_addslashes($next_token);
                    if ($GLOBALS['XSS_DETECT']) {
                        ocp_mark_as_escaped($literal);
                    }
                    $current_level_data[] = '"' . $literal . '"';
                    break;
                }
                $opener_params = array_merge($current_level_params, array($current_level_data));
                $__first_param = array_shift($opener_params);
                $_first_param = implode('.', $__first_param);
                if ($bits[$i - 1] == '') {
                    $current_level_data[] = '""';
                }
                // Return to the previous level
                $past_level_data = $current_level_data;
                $past_level_params = $current_level_params;
                $past_level_mode = $current_level_mode;
                if (count($stack) == 0) {
                    if (!$tolerate_errors) {
                        warn_exit(do_lang_tempcode('TEMPCODE_TOO_MANY_CLOSES', escape_html($template_name), integer_format(1 + _length_so_far($bits, $i))));
                    }
                } else {
                    list($current_level_mode, $current_level_data, $current_level_params, , , ) = array_pop($stack);
                }
                // Handle the level we just closed
                if (function_exists('str_split')) {
                    $_escaped = str_split(preg_replace('#[^:\\.`%\\*=\\;\\#\\-~\\^\\|\'&/@]:?#', '', $_first_param));
                    // :? is so that the ":" in lang strings does not get considered an escape
                } else {
                    $temp = preg_replace('#[^:\\.`%\\*=\\;\\#\\-~\\^\\|\'&/@]:?#', '', $_first_param);
                    $_escaped = array();
                    for ($j = 0; $j < strlen($temp); $j++) {
                        $_escaped[] = $temp[$j];
                    }
                }
                $escaped = array();
                foreach ($_escaped as $e) {
                    switch ($e) {
                        case '`':
                            $escaped[] = NULL_ESCAPED;
                            break;
                        case '%':
                            $escaped[] = NAUGHTY_ESCAPED;
                            break;
                        case '*':
                            $escaped[] = ENTITY_ESCAPED;
                            break;
                        case '=':
                            $escaped[] = FORCIBLY_ENTITY_ESCAPED;
                            break;
                        case ';':
                            $escaped[] = SQ_ESCAPED;
                            break;
                        case '#':
                            $escaped[] = DQ_ESCAPED;
                            break;
                        case '~':
                            $escaped[] = NL_ESCAPED;
                            break;
                        case '^':
                            $escaped[] = NL2_ESCAPED;
                            break;
                        case '|':
                            $escaped[] = ID_ESCAPED;
                            break;
                        case '\'':
                            $escaped[] = CSS_ESCAPED;
                            break;
                        case '&':
                            $escaped[] = UL_ESCAPED;
                            break;
                        case '.':
                            $escaped[] = UL2_ESCAPED;
                            break;
                        case '/':
                            $escaped[] = JSHTML_ESCAPED;
                            break;
                        case '@':
                            $escaped[] = CC_ESCAPED;
                            break;
                            // This is used as a hint to not preprocess
                        // This is used as a hint to not preprocess
                        case '-':
                    }
                }
                $_opener_params = '';
                foreach ($opener_params as $param) {
                    if ($param == array()) {
                        $param = array('""');
                    }
                    if ($_opener_params != '') {
                        $_opener_params .= ',';
                    }
                    $_opener_params .= implode('.', $param);
                }
                $first_param = str_replace(array('`', '%', '*', '=', ';', '#', '-', '~', '^', '|', '\'', '&', '.', '/', '@'), array('', '', '', '', '', '', '', '', '', '', '', '', '', '', ''), $_first_param);
                switch ($past_level_mode) {
                    case PARSE_SYMBOL:
                        $no_preprocess = in_array('-', $_escaped);
                        if (!$no_preprocess) {
                            switch ($first_param) {
                                case '"CSS_INCLUDE"':
                                case '"JAVASCRIPT_INCLUDE"':
                                case '"JS_TEMPCODE"':
                                case '"CSS_TEMPCODE"':
                                case '"SET"':
                                case '"BLOCK"':
                                case '"LOAD_PAGE"':
                                case '"LOAD_PANEL"':
                                    foreach ($stack as $level_test) {
                                        if ($level_test[3] == PARSE_DIRECTIVE && isset($level_test[5][1]) && isset($level_test[5][1][0]) && $level_test[5][1][0] == '"LOOP"') {
                                            $eval = @eval('return array(' . $_opener_params . ');');
                                            if (is_array($eval)) {
                                                $pp_bit = array(array(), TC_SYMBOL, str_replace('"', '', $first_param), $eval);
                                                $preprocessable_bits[] = $pp_bit;
                                            }
                                            break 2;
                                        }
                                    }
                                    $symbol_params = array();
                                    foreach ($opener_params as $param) {
                                        if ($param == array()) {
                                            $param = array('""');
                                        }
                                        $myfunc = 'tcpfunc_' . fast_uniqid();
                                        $funcdef = build_closure_function($myfunc, $param);
                                        $symbol_params[] = new ocp_tempcode(array($funcdef, array(array($myfunc, array(), TC_KNOWN, '', ''))));
                                        // Parameters will be bound in later.
                                    }
                                    $pp_bit = array(array(), TC_SYMBOL, str_replace('"', '', $first_param), $symbol_params);
                                    $preprocessable_bits[] = $pp_bit;
                                    break;
                            }
                        }
                        if ($first_param == '"IMG"' && strpos($_opener_params, ',') === false) {
                            $_opener_params .= ',"0","' . php_addslashes($theme) . '"';
                        }
                        if ($first_param == '"?"') {
                            if (implode('.', $opener_params[0]) == '"1".""') {
                                if (isset($opener_params[1])) {
                                    $current_level_data[] = implode('.', $opener_params[1]);
                                }
                                break;
                            }
                            if (implode('.', $opener_params[0]) == '"0".""' || implode('.', $opener_params[0]) == '""') {
                                if (isset($opener_params[2])) {
                                    $current_level_data[] = implode('.', $opener_params[2]);
                                }
                                break;
                            }
                        }
                        if ($first_param != '""') {
                            $new_line = 'ecv($cl,array(' . implode(',', $escaped) . '),' . strval(TC_SYMBOL) . ',' . $first_param . ',array(' . $_opener_params . '))';
                            if (in_array($first_param, $compilable_symbols) && preg_match('#^[^\\(\\)]*$#', $_opener_params) != 0) {
                                $new_line = '"' . php_addslashes(eval('return ' . $new_line . ';')) . '"';
                            }
                            $current_level_data[] = $new_line;
                        }
                        break;
                    case PARSE_LANGUAGE_REFERENCE:
                        $new_line = 'ecv($cl,array(' . implode(',', $escaped) . '),' . strval(TC_LANGUAGE_REFERENCE) . ',' . $first_param . ',array(' . $_opener_params . '))';
                        if ($_opener_params == '' && count($escaped) == 0) {
                            $looked_up = do_lang(eval('return ' . $first_param . ';'), NULL, NULL, NULL, $lang, false);
                            if (!is_null($looked_up)) {
                                if (apply_tempcode_escaping($escaped, $looked_up) == $looked_up) {
                                    $new_line = '"' . php_addslashes($looked_up) . '"';
                                }
                            }
                        }
                        $current_level_data[] = $new_line;
                        break;
                    case PARSE_PARAMETER:
                        $parameter = str_replace('"', '', str_replace("'", '', $first_param));
                        $parameter = preg_replace('#[^\\w\\_\\d]#', '', $parameter);
                        // security to stop PHP injection
                        $temp = 'output_tempcode_parameter( isset ($bound_' . php_addslashes($parameter) . ')?$bound_' . php_addslashes($parameter) . ':NULL,"' . php_addslashes($parameter) . '","' . php_addslashes($template_name) . '")';
                        if (count($escaped) == 0) {
                            $current_level_data[] = $temp;
                        } else {
                            $s_escaped = '';
                            foreach ($escaped as $esc) {
                                if ($s_escaped != '') {
                                    $s_escaped .= ',';
                                }
                                $s_escaped .= strval($esc);
                            }
                            if ($s_escaped == strval(ENTITY_ESCAPED) && !$GLOBALS['XSS_DETECT']) {
                                $current_level_data[] = '( isset ($bound_' . $parameter . ')?(((isset($bound_' . $parameter . '->preprocessable_bits)) && ($bound_' . $parameter . '->pure_lang))?' . $temp . ':str_replace($GLOBALS[\'HTML_ESCAPE_1_STRREP\'],$GLOBALS[\'HTML_ESCAPE_2\'],' . $temp . ')):attach_message(do_lang_tempcode(\'MISSING_TEMPLATE_PARAMETER\',"' . php_addslashes($parameter) . '","' . php_addslashes($template_name) . '"),"warn"))';
                            } else {
                                if ($s_escaped == strval(ENTITY_ESCAPED)) {
                                    $current_level_data[] = '( isset ($bound_' . $parameter . ')?(((isset($bound_' . $parameter . '->preprocessable_bits)) && ($bound_' . $parameter . '->pure_lang))?' . $temp . ':apply_tempcode_escaping_inline(array(' . $s_escaped . '),' . $temp . ')):attach_message(do_lang_tempcode(\'MISSING_TEMPLATE_PARAMETER\',"' . php_addslashes($parameter) . '","' . php_addslashes($template_name) . '"),"warn"))';
                                } else {
                                    $current_level_data[] = '( isset ($bound_' . $parameter . ')?apply_tempcode_escaping_inline(array(' . $s_escaped . '),' . $temp . '):attach_message(do_lang_tempcode(\'MISSING_TEMPLATE_PARAMETER\',"' . php_addslashes($parameter) . '","' . php_addslashes($template_name) . '"),"warn"))';
                                }
                            }
                        }
                        break;
                }
                // Handle directive nesting
                if ($past_level_mode == PARSE_DIRECTIVE) {
                    $eval = @eval('return ' . $first_param . ';');
                    if (!is_string($eval)) {
                        $eval = '';
                    }
                    if ($eval == 'START') {
                        // Open a new directive level
                        $stack[] = array($current_level_mode, $current_level_data, $current_level_params, $past_level_mode, $past_level_data, $past_level_params);
                        $current_level_data = array();
                        $current_level_params = array();
                        $current_level_mode = PARSE_DIRECTIVE_INNER;
                    } elseif ($eval == 'END') {
                        // Test that the top stack does represent a started directive, and close directive level
                        $past_level_data = $current_level_data;
                        if ($past_level_data == array()) {
                            $past_level_data = array('""');
                        }
                        $past_level_params = $current_level_params;
                        $past_level_mode = $current_level_mode;
                        if (count($stack) == 0) {
                            if ($tolerate_errors) {
                                continue;
                            }
                            warn_exit(do_lang_tempcode('TEMPCODE_TOO_MANY_CLOSES', escape_html($template_name), integer_format(1 + substr_count(substr($data, 0, _length_so_far($bits, $i)), chr(10)))));
                        }
                        list($current_level_mode, $current_level_data, $current_level_params, $directive_level_mode, $directive_level_data, $directive_level_params) = array_pop($stack);
                        if (!is_array($directive_level_params)) {
                            if ($tolerate_errors) {
                                continue;
                            }
                            warn_exit(do_lang_tempcode('UNCLOSED_DIRECTIVE_OR_BRACE', escape_html($template_name), integer_format(1 + substr_count(substr($data, 0, _length_so_far($bits, $i)), chr(10)))));
                        }
                        $directive_opener_params = array_merge($directive_level_params, array($directive_level_data));
                        if ($directive_level_mode != PARSE_DIRECTIVE || $directive_opener_params[0][0] != '"START"') {
                            if ($tolerate_errors) {
                                continue;
                            }
                            warn_exit(do_lang_tempcode('TEMPCODE_TOO_MANY_CLOSES', escape_html($template_name), integer_format(1 + substr_count(substr($data, 0, _length_so_far($bits, $i)), chr(10)))));
                        }
                        // Handle directive
                        if (count($directive_opener_params) == 1) {
                            if ($tolerate_errors) {
                                continue;
                            }
                            warn_exit(do_lang_tempcode('NO_DIRECTIVE_TYPE', escape_html($template_name), integer_format(1 + substr_count(substr($data, 0, _length_so_far($bits, $i)), chr(10)))));
                        }
                        $directive_params = '';
                        $first_directive_param = '""';
                        if ($directive_opener_params[1] == array()) {
                            $directive_opener_params[1] = array('""');
                        }
                        for ($j = 2; $j < count($directive_opener_params); $j++) {
                            if ($directive_opener_params[$j] == array()) {
                                $directive_opener_params[$j] = array('""');
                            }
                            if ($directive_params != '') {
                                $directive_params .= ',';
                            }
                            $directive_params .= implode('.', $directive_opener_params[$j]);
                            if ($j == 2) {
                                $first_directive_param = implode('.', $directive_opener_params[$j]);
                            }
                        }
                        $eval = @eval('return ' . implode('.', $directive_opener_params[1]) . ';');
                        if (!is_string($eval)) {
                            $eval = '';
                        }
                        $directive_name = $eval;
                        switch ($directive_name) {
                            case 'FRACTIONAL_EDITABLE':
                                $pp_bit = array(array(), TC_DIRECTIVE, str_replace('"', '', $directive_name), array());
                                $preprocessable_bits[] = $pp_bit;
                                break;
                        }
                        switch ($directive_name) {
                            case 'IF':
                                if (preg_match('#^ecv\\(\\$cl,array\\(\\),0,"NOT",array\\("1"\\)\\).""$#', $first_directive_param) != 0) {
                                    $first_directive_param = '"0".""';
                                }
                                if (preg_match('#^ecv\\(\\$cl,array\\(\\),0,"NOT",array\\("0"\\)\\).""$#', $first_directive_param) != 0) {
                                    $first_directive_param = '"1".""';
                                }
                                if ($first_directive_param == '"1".""') {
                                    $current_level_data[] = '(' . implode('.', $past_level_data) . ')';
                                } elseif ($first_directive_param != '"0".""') {
                                    $current_level_data[] = '((' . $first_directive_param . '=="1")?(' . implode('.', $past_level_data) . '):\'\')';
                                }
                                break;
                            case 'IF_EMPTY':
                                $current_level_data[] = '((' . $first_directive_param . '==\'\')?(' . implode('.', $past_level_data) . '):\'\')';
                                break;
                            case 'WHILE':
                                $current_level_data[] = 'closure_while_loop(array($parameters,$cl,$last_attach),' . chr(10) . 'create_function(\'$parameters,$cl,$last_attach\',"extract(\\$parameters,EXTR_PREFIX_ALL,\'bound\'); return (' . php_addslashes($first_directive_param) . ')==\\"1\\";"),' . chr(10) . 'create_function(\'$parameters,$cl,$last_attach\',"extract(\\$parameters,EXTR_PREFIX_ALL,\'bound\'); return ' . php_addslashes(implode('.', $past_level_data)) . ';"))';
                                break;
                            case 'PHP':
                                $current_level_data[] = 'closure_eval(' . implode('.', $past_level_data) . ',$parameters)';
                                break;
                            case 'LOOP':
                                $current_level_data[] = 'closure_loop(array(' . $directive_params . ',\'vars\'=>$parameters),array($parameters,$cl,$last_attach),' . chr(10) . 'create_function(\'$parameters,$cl,$last_attach\',"extract(\\$parameters,EXTR_PREFIX_ALL,\'bound\'); return ' . php_addslashes(implode('.', $past_level_data)) . ';"))';
                                break;
                            case 'IF_NON_EMPTY':
                                $current_level_data[] = '((' . $first_directive_param . '!=\'\')?(' . implode('.', $past_level_data) . '):\'\')';
                                break;
                            case 'IF_PASSED':
                                $eval = @eval('return ' . $first_directive_param . ';');
                                if (!is_string($eval)) {
                                    $eval = '';
                                }
                                $current_level_data[] = '(isset($bound_' . preg_replace('#[^\\w\\d\\_]#', '', $eval) . ')?(' . implode('.', $past_level_data) . '):\'\')';
                                break;
                            case 'IF_NON_PASSED':
                                $eval = @eval('return ' . $first_directive_param . ';');
                                if (!is_string($eval)) {
                                    $eval = '';
                                }
                                $current_level_data[] = '(!isset($bound_' . preg_replace('#[^\\w\\d\\_]#', '', $eval) . ')?(' . implode('.', $past_level_data) . '):\'\')';
                                break;
                            case 'IF_ADJACENT':
                                $current_level_data[] = '(($last_attach=="' . php_addslashes($template_name) . '")?(' . implode('.', $past_level_data) . '):\'\')';
                                break;
                            case 'IF_NON_ADJACENT':
                                $current_level_data[] = '(($last_attach!="' . php_addslashes($template_name) . '")?(' . implode('.', $past_level_data) . '):\'\')';
                                break;
                            case 'SHIFT_ENCODE':
                                $eval = @eval('return ' . implode('.', $directive_opener_params[2]) . ';');
                                if (!is_string($eval)) {
                                    $eval = '';
                                }
                                $key = $eval;
                                $set_op = '$GLOBALS[\'SHIFT_VARIABLES\']["' . php_addslashes($key) . '"]=make_string_tempcode(' . implode('.', $past_level_data) . ')';
                                if (array_key_exists(3, $directive_opener_params)) {
                                    $attach_op = '$GLOBALS[\'SHIFT_VARIABLES\']["' . php_addslashes($key) . '"]->attach(' . implode('.', $past_level_data) . ')';
                                    $is_set_check = 'array_key_exists("' . php_addslashes($key) . '",$GLOBALS[\'SHIFT_VARIABLES\'])';
                                    // NB: The "/*SHIFT_ENCODE*/" bit is critical, it's used as a marker for identifying the need for preexecution
                                    $current_level_data[] = '/*SHIFT_ENCODE*/(is_null(((!' . $is_set_check . ') || (' . implode('.', $directive_opener_params[3]) . '==\'0\'))' . '?' . $set_op . ':' . $attach_op . ')?\'\':\'\')';
                                } else {
                                    $current_level_data[] = '/*SHIFT_ENCODE*/(is_null(' . $set_op . ')?\'\':\'\')';
                                }
                                break;
                            case 'INCLUDE':
                                global $FILE_ARRAY;
                                if (count($directive_opener_params) == 3 && $past_level_data == array('""') && !isset($FILE_ARRAY)) {
                                    $eval = @eval('return ' . $first_directive_param . ';');
                                    if (!is_string($eval)) {
                                        $eval = '';
                                    }
                                    $found = find_template_place($eval, '', $theme, '.tpl', 'templates');
                                    $_theme = $found[0];
                                    $fullpath = get_custom_file_base() . '/themes/' . $_theme . $found[1] . $eval . '.tpl';
                                    if (!is_file($fullpath)) {
                                        $fullpath = get_file_base() . '/themes/' . $_theme . $found[1] . $eval . '.tpl';
                                    }
                                    $filecontents = @file_get_contents($fullpath, FILE_TEXT);
                                    if ($filecontents === false) {
                                        $filecontents = '';
                                    }
                                    list($_current_level_data, $_preprocessable_bits) = compile_template($filecontents, $eval, $theme, $lang);
                                    $current_level_data = array_merge($current_level_data, $_current_level_data);
                                    $preprocessable_bits = array_merge($preprocessable_bits, $_preprocessable_bits);
                                    break;
                                }
                            default:
                                if ($directive_params != '') {
                                    $directive_params .= ',';
                                }
                                $directive_params .= implode('.', $past_level_data);
                                if (isset($GLOBALS['DIRECTIVES_NEEDING_VARS'][$directive_name])) {
                                    $current_level_data[] = 'ecv($cl,array(),' . strval(TC_DIRECTIVE) . ',' . implode('.', $directive_opener_params[1]) . ',array(' . $directive_params . ',\'vars\'=>$parameters))';
                                } else {
                                    $current_level_data[] = 'ecv($cl,array(),' . strval(TC_DIRECTIVE) . ',' . implode('.', $directive_opener_params[1]) . ',array(' . $directive_params . '))';
                                }
                                break;
                        }
                    } else {
                        $eval = @eval('return ' . $first_param . ';');
                        if (!is_string($eval)) {
                            $eval = '';
                        }
                        $directive_name = $eval;
                        if (isset($GLOBALS['DIRECTIVES_NEEDING_VARS'][$directive_name])) {
                            $current_level_data[] = 'ecv($cl,array(' . implode(',', $escaped) . '),' . strval(TC_DIRECTIVE) . ',' . $first_param . ',array(' . $_opener_params . ',\'vars\'=>$parameters))';
                        } else {
                            $current_level_data[] = 'ecv($cl,array(' . implode(',', $escaped) . '),' . strval(TC_DIRECTIVE) . ',' . $first_param . ',array(' . $_opener_params . '))';
                        }
                    }
                }
                break;
            case ',':
                switch ($current_level_mode) {
                    case PARSE_NO_MANS_LAND:
                    case PARSE_DIRECTIVE_INNER:
                        $current_level_data[] = '\',\'';
                        break;
                    default:
                        $current_level_params[] = $current_level_data;
                        $current_level_data = array();
                        break;
                }
                break;
            default:
                $literal = php_addslashes(str_replace('\\,', ',', str_replace('\\}', '}', str_replace('\\{', '{', $next_token))));
                if ($GLOBALS['XSS_DETECT']) {
                    ocp_mark_as_escaped($literal);
                }
                $current_level_data[] = '"' . $literal . '"';
                break;
        }
    }
    if (!array_key_exists('LAX_COMCODE', $GLOBALS) || !$GLOBALS['LAX_COMCODE']) {
        if (count($stack) != 0) {
            if (!$tolerate_errors) {
                warn_exit(do_lang_tempcode('UNCLOSED_DIRECTIVE_OR_BRACE', escape_html($template_name), integer_format(1 + substr_count(substr($data, 0, _length_so_far($bits, $i)), chr(10)))));
            }
        }
    }
    return array($current_level_data, $preprocessable_bits);
}
Example #5
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 #6
0
/**
 * Fifth installation step: FTP upload (not used for manual installer).
 *
 * @return array		A pair: progress report/ui, and number of files uploaded so far (or -1 meaning all uploaded)
 */
function step_5_ftp()
{
    global $FILE_ARRAY, $DIR_ARRAY;
    if (count($_POST) == 0) {
        exit(do_lang('INST_POST_ERROR'));
    }
    if (!is_suexec_like()) {
        if (!function_exists('ftp_connect')) {
            warn_exit(do_lang_tempcode('NO_PHP_FTP'));
        }
        $ftp_domain = trim(post_param('ftp_domain'));
        if (strpos($ftp_domain, 'ftp://') !== false) {
            warn_exit(do_lang_tempcode('FTP_DOMAIN_NOT_LIKE_THIS'));
        }
        $port = 21;
        if (strpos($ftp_domain, ':') !== false) {
            list($ftp_domain, $_port) = explode(':', $ftp_domain, 2);
            $port = intval($_port);
        }
        $conn = false;
        if (function_exists('ftp_ssl_connect')) {
            $conn = @ftp_ssl_connect($ftp_domain, $port);
        }
        $ssl = $conn !== false;
        $username = trim(post_param('ftp_username'));
        $password = trim(post_param('ftp_password'));
        if ($ssl && @ftp_login($conn, $username, $password) === false) {
            $conn = false;
            $ssl = false;
        }
        if ($conn === false) {
            $conn = ftp_connect($ftp_domain, $port);
        }
        if ($conn === false) {
            warn_exit(do_lang_tempcode('NO_FTP_CONNECT'));
        }
        if (!$ssl && !@ftp_login($conn, $username, $password)) {
            warn_exit(do_lang_tempcode('NO_FTP_LOGIN', @strval($php_errormsg)));
        }
        $ftp_folder = post_param('ftp_folder');
        if (substr($ftp_folder, -1) != '/') {
            $ftp_folder .= '/';
        }
        if (!@ftp_chdir($conn, $ftp_folder)) {
            warn_exit(do_lang_tempcode('NO_FTP_DIR', @strval($php_errormsg), '1'));
        }
        $files = @ftp_nlist($conn, '.');
        if ($files === false) {
            $files = array();
            if (@ftp_rename($conn, 'install.php', 'install.php')) {
                $files = array('install.php', 'data.ocp');
            }
        }
        if (!in_array('install.php', $files)) {
            warn_exit(do_lang_tempcode('NO_FTP_DIR', @strval($php_errormsg), '2'));
        }
        $overwrite_ok = !file_exists(get_file_base() . '/ocp_inst_tmp/tmp');
        // Because if the file doesn't exist, the step completed in full - we DON'T want to overwrite if it didn't, because the step probably timed out and by refreshing we complete the step in pieces
        if (!file_exists('ocp_inst_tmp')) {
            // Make temporary directory
            if (!in_array('ocp_inst_tmp', $files) && !is_string(@ftp_mkdir($conn, 'ocp_inst_tmp'))) {
                warn_exit(do_lang_tempcode('NO_FTP_ACCESS'));
            }
            @ftp_site($conn, 'CHMOD 0777 ocp_inst_tmp');
        }
        if (!is_writable_wrap('ocp_inst_tmp')) {
            warn_exit(do_lang_tempcode('MANUAL_CHMOD_TMP_FILE'));
        }
        // Test tmp file isn't currently being used by another iteration of process (race issue, causing horrible corruption)
        $file_size_before = @filesize(get_file_base() . '/ocp_inst_tmp/tmp');
        sleep(1);
        $file_size_after = @filesize(get_file_base() . '/ocp_inst_tmp/tmp');
        if ($file_size_before !== $file_size_after) {
            warn_exit(do_lang_tempcode('DATA_FILE_CONFLICT'));
        }
        // Test tmp file isn't currently being used by another iteration of process (race issue, causing horrible corruption)
        $lock_myfile = fopen(get_file_base() . '/ocp_inst_tmp/tmp', 'ab');
        if (!defined('PHALANGER')) {
            if (!flock($lock_myfile, LOCK_EX)) {
                warn_exit(do_lang_tempcode('DATA_FILE_CONFLICT'));
            }
        }
        $file_size_before = @filesize(get_file_base() . '/ocp_inst_tmp/tmp');
        sleep(1);
        $file_size_after = @filesize(get_file_base() . '/ocp_inst_tmp/tmp');
        if ($file_size_before !== $file_size_after) {
            warn_exit(do_lang_tempcode('DATA_FILE_CONFLICT'));
        }
        fclose($lock_myfile);
    } else {
        $overwrite_ok = true;
        $files = array();
        if (file_exists(get_file_base() . '/info.php')) {
            $files[] = 'info.php';
        }
    }
    // Make folders
    $langs1 = get_dir_contents('lang');
    $langs2 = get_dir_contents('lang_custom');
    $langs = array_merge($langs1, $langs2);
    foreach ($DIR_ARRAY as $dir) {
        if (strpos($dir, '/' . fallback_lang()) !== false) {
            foreach (array_keys($langs) as $lang) {
                if ($lang == fallback_lang() || strpos($lang, '.') !== false) {
                    continue;
                }
                if (is_suexec_like()) {
                    @mkdir(get_file_base() . '/' . str_replace('/' . fallback_lang(), '/' . $lang, $dir), 0777);
                    fix_permissions(get_file_base() . '/' . str_replace('/' . fallback_lang(), '/' . $lang, $dir), 0777);
                } else {
                    @ftp_mkdir($conn, str_replace('/' . fallback_lang(), '/' . $lang, $dir));
                    @ftp_site($conn, 'CHMOD 755 ' . str_replace('/' . fallback_lang(), '/' . $lang, $dir));
                }
            }
        }
        if (is_suexec_like()) {
            @mkdir(get_file_base() . '/' . $dir, 0777);
            fix_permissions(get_file_base() . '/' . $dir, 0777);
        } else {
            @ftp_mkdir($conn, $dir);
            if ($dir == 'exports/mods' && !is_suexec_like()) {
                @ftp_site($conn, 'CHMOD 777 ' . $dir);
            } else {
                @ftp_site($conn, 'CHMOD 755 ' . $dir);
            }
        }
    }
    // Upload files
    $count = file_array_count();
    $php_perms = fileperms(get_file_base() . '/install.php');
    $start_pos = get_param_integer('start_from', 0);
    $done_all = false;
    $time_start = time();
    $max_time = intval(round(floatval(ini_get('max_execution_time')) / 1.5));
    $max = post_param_integer('max', is_suexec_like() ? 5000 : 1000);
    for ($i = $start_pos; $i < $start_pos + $max; $i++) {
        list($filename, $contents) = file_array_get_at($i);
        if (is_string($contents)) {
            $file_size = strlen($contents);
        } else {
            list($file_size, $dump_myfile, $dump_offset) = $contents;
        }
        if ($filename != 'info.php' || !in_array('info.php', $files)) {
            if (($overwrite_ok || !file_exists(get_file_base() . '/' . $filename) || @filemtime(get_file_base() . '/' . $filename) < filemtime(get_file_base() . '/install.php') || filesize(get_file_base() . '/' . $filename) != $file_size) && ($filename != 'forum/index.php' || !file_exists(get_file_base() . '/' . $filename))) {
                if (strpos($filename, '/' . fallback_lang() . '/') !== false && is_string($contents)) {
                    foreach (array_keys($langs) as $lang) {
                        if ($lang == fallback_lang() || strpos($lang, '.') !== false) {
                            continue;
                        }
                        if (is_suexec_like()) {
                            $myfile = fopen(get_file_base() . '/' . str_replace('/' . fallback_lang() . '/', '/' . $lang . '/', $filename), 'wb');
                            fwrite($myfile, $contents);
                            fclose($myfile);
                            fix_permissions(get_file_base() . '/' . str_replace('/' . fallback_lang() . '/', '/' . $lang . '/', $filename), 0666);
                        } else {
                            @ftp_delete($conn, str_replace('/' . fallback_lang() . '/', '/' . $lang . '/', $filename));
                            $tmp = fopen(get_file_base() . '/ocp_inst_tmp/tmp', 'wb');
                            fwrite($tmp, $contents);
                            fclose($tmp);
                            ftp_put($conn, str_replace('/' . fallback_lang() . '/', '/' . $lang . '/', $filename), get_file_base() . '/ocp_inst_tmp/tmp', FTP_BINARY);
                            $mask = 0;
                            if (get_file_extension($filename) == 'php') {
                                if (($php_perms & 0100) == 0100) {
                                    $mask = $mask | 0100;
                                }
                                if (($php_perms & 010) == 010) {
                                    $mask = $mask | 010;
                                }
                                if (($php_perms & 01) == 01) {
                                    $mask = $mask | 01;
                                }
                            }
                            @ftp_site($conn, 'CHMOD 0' . decoct(0644 | $mask) . ' ' . str_replace('/' . fallback_lang() . '/', '/' . $lang . '/', $filename));
                        }
                    }
                }
                if (is_suexec_like()) {
                    $myfile = fopen(get_file_base() . '/' . $filename, 'wb');
                    if (is_string($contents)) {
                        fwrite($myfile, $contents);
                    } else {
                        fseek($dump_myfile, $dump_offset, SEEK_SET);
                        $amount_read = 0;
                        while ($amount_read < $file_size) {
                            $read_amount = min(4096, $file_size - $amount_read);
                            $shuttle_contents = fread($dump_myfile, $read_amount);
                            fwrite($myfile, $shuttle_contents);
                            $amount_read += strlen($shuttle_contents);
                        }
                    }
                    fclose($myfile);
                    fix_permissions(get_file_base() . '/' . $filename, 0666);
                } else {
                    @ftp_delete($conn, $filename);
                    $tmp = fopen(get_file_base() . '/ocp_inst_tmp/tmp', 'wb');
                    if (is_string($contents)) {
                        fwrite($tmp, $contents);
                    } else {
                        fseek($dump_myfile, $dump_offset, SEEK_SET);
                        $amount_read = 0;
                        while ($amount_read < $file_size) {
                            $read_amount = min(4096, $file_size - $amount_read);
                            $shuttle_contents = fread($dump_myfile, $read_amount);
                            fwrite($tmp, $shuttle_contents);
                            $amount_read += strlen($shuttle_contents);
                        }
                    }
                    fclose($tmp);
                    if (!@ftp_put($conn, $filename, get_file_base() . '/ocp_inst_tmp/tmp', FTP_BINARY)) {
                        if (strpos(@strval($php_errormsg), 'bind() failed') !== false) {
                            warn_exit(do_lang_tempcode('FTP_FIREWALL_ERROR'));
                        } else {
                            warn_exit(@strval($php_errormsg));
                        }
                    }
                    $mask = 0;
                    if (get_file_extension($filename) == 'php') {
                        if (($php_perms & 0100) == 0100) {
                            $mask = $mask | 0100;
                        }
                        if (($php_perms & 010) == 010) {
                            $mask = $mask | 010;
                        }
                        if (($php_perms & 01) == 01) {
                            $mask = $mask | 01;
                        }
                    }
                    @ftp_site($conn, 'CHMOD ' . decoct(0644 | $mask) . ' ' . $filename);
                }
            }
        }
        if ($max_time > 0 && time() - $time_start >= $max_time) {
            break;
        }
        if ($i + 1 == $count) {
            $done_all = true;
            break;
            // That's them all
        }
    }
    if (!is_suexec_like()) {
        if (!file_exists(get_file_base() . '/ocp_inst_tmp/tmp')) {
            warn_exit(do_lang_tempcode('DOUBLE_INSTALL_DO'));
        }
        @unlink(get_file_base() . '/ocp_inst_tmp/tmp');
    }
    test_htaccess(is_suexec_like() ? NULL : $conn);
    $log = new ocp_tempcode();
    if ($done_all) {
        // If the file user is different to the FTP user, we need to make it world writeable
        if (!is_suexec_like()) {
            // Chmod
            global $CHMOD_ARRAY;
            $no_chmod = false;
            foreach ($CHMOD_ARRAY as $chmod) {
                if (file_exists($chmod) && !@ftp_site($conn, 'CHMOD 0777 ' . $chmod)) {
                    $no_chmod = true;
                }
            }
            $log->attach(do_template('INSTALLER_DONE_SOMETHING', array('_GUID' => '2e4ccdd5a0b034125ee62403d5a48319', 'SOMETHING' => do_lang_tempcode(!$no_chmod ? 'CHMOD_PASS' : 'CHMOD_FAIL'))));
        }
    }
    if (!is_suexec_like()) {
        if (function_exists('ftp_close')) {
            ftp_close($conn);
        }
    }
    $log->attach(do_template('INSTALLER_DONE_SOMETHING', array('_GUID' => '1b447cee9e9aa3ad8e24530d4dceb03f', 'SOMETHING' => do_lang_tempcode('FILES_TRANSFERRED', strval($i + 1), strval($count)))));
    return array($log, $done_all ? -1 : $i);
}
Example #7
0
    /**
     * Exit with a nicely formatted critical error.
     *
     * @param  string			The error message code
     * @param  ?string		Relayed additional details (NULL: nothing relayed)
     * @param  boolean		Whether to actually exit
     */
    function critical_error($code, $relay = NULL, $exit = true)
    {
        error_reporting(0);
        if (!headers_sent()) {
            if (function_exists('browser_matches') && (is_null($relay) || strpos($relay, 'Allowed memory') === false)) {
                if (!browser_matches('ie') && strpos(ocp_srv('SERVER_SOFTWARE'), 'IIS') === false) {
                    header('HTTP/1.0 500 Internal server error');
                }
            }
        }
        $error = 'Unknown critical error type: this should not happen, so please report this to ocProducts.';
        switch ($code) {
            case 'MISSING_SOURCE':
                $error = 'A source-code (' . $relay . ') file is missing.';
                break;
            case 'PASSON':
                $error = $relay;
                break;
            case 'MEMBER_BANNED':
                $error = 'The member you are masquerading as has been banned. We cannot finish initialising the virtualised environment for this reason.';
                break;
            case 'BANNED':
                $error = 'The IP address you are accessing this website from (' . get_ip_address() . ') has been banished from this website. If you believe this is a mistake, contact the staff to have it resolved (typically, postmaster@' . get_domain() . ' will be able to reach them).</div>' . chr(10) . '<div>If you are yourself staff, you should be able to unban yourself by editing the <kbd>usersubmitban_ip</kbd> table in a database administation tool, by removing rows that qualify against yourself. This error is raised to a critical error to reduce the chance of this IP address being able to further consume server resources.';
                break;
                /*		case 'PHP':
                				$error='<p>This is a PHP error.</div>'.chr(10).'<div style="padding-left: 50px">'.$relay;
                				break;
                	*/
            /*		case 'PHP':
            				$error='<p>This is a PHP error.</div>'.chr(10).'<div style="padding-left: 50px">'.$relay;
            				break;
            	*/
            case 'TEST':
                $error = 'This is a test error.';
                break;
            case 'BUSY':
                $error = 'This is a less-critical error that has been elevated for quick dismissal due to high server load.</div>' . chr(10) . '<div style="padding-left: 50px">' . $relay;
                break;
            case 'EMERGENCY':
                $error = 'This is an error that has been elevated to critical error status because it occurred during the primary error mechanism reporting system itself (possibly due to it occuring within the standard output framework). It may be masking a secondary error that occurred before this, but was never output - if so, it is likely strongly related to this one, thus fixing this will fix the other.</div>' . chr(10) . '<div style="padding-left: 50px">' . $relay;
                break;
            case 'RELAY':
                $error = 'This is a relayed critical error, which means that this less-critical error has occurred during startup, and thus halted startup.</div>' . chr(10) . '<div style="padding-left: 50px">' . $relay;
                break;
            case 'FILE_DOS':
                $error = 'This website was prompted to download a file (' . htmlentities($relay) . ') which seemingly has a never-ending chain of redirections. Because this could be a denial of service attack, execution has been terminated.';
                break;
            case 'DATABASE_FAIL':
                $error = 'The website\'s first database query (checking the page request is not from a banned IP address) has failed. This almost always means that the database is not set up correctly, which in turns means that either backend database configuration has changed (perhaps the database has been emptied), or the configuration file (info.php) has been incorrectly altered (perhaps to point to an empty database), or you have moved servers and not updated your info.php settings properly or placed your database. It could also mean that the <kbd>' . get_table_prefix() . 'usersubmitban_ip</kbd> table or <kbd>' . get_table_prefix() . 'config</kbd> table alone is missing or corrupt, but this is unlikely. As this is an error due to the website\'s environment being externally altered by unknown means, the website cannot continue to function or solve the problem itself.';
                break;
            case 'INFO.PHP':
                $install_url = 'install.php';
                if (!file_exists($install_url)) {
                    $install_url = '../install.php';
                }
                if (file_exists($install_url)) {
                    $likely = 'ocPortal files have been placed, yet installation not completed. To install ocPortal, <a href="' . $install_url . '">run the installer</a>.';
                } else {
                    $likely = 'ocPortal files have been placed by direct copying from a non-standard source that included neither a configuration file nor installation script, or info.php has become corrupt after installation. The installer (install.php) is not present: it is advised that you replace info.php from backup, or if you have not yet installed, use an official ocProducts installation package.';
                }
                $error = 'The top-level configuration file (info.php) is either not-present or empty. This file is created upon installation, and the likely cause of this error is that ' . $likely;
                break;
            case 'INFO.PHP_CORRUPTED':
                $error = 'The top-level configuration file (info.php) appears to be corrupt. Perhaps it was incorrectly uploaded, or a typo was made. It must be valid PHP code.';
                break;
            case 'CRIT_LANG':
                $error = 'The most basic critical error language file (lang/' . fallback_lang() . '/critical_error.ini) is missing. It is likely that other files are also, for whatever reason, missing from this ocPortal installation.';
                break;
        }
        $edit_url = 'config_editor.php';
        if (!file_exists($edit_url)) {
            $edit_url = '../' . $edit_url;
        }
        if (isset($GLOBALS['SITE_INFO']['base_url'])) {
            $edit_url = $GLOBALS['SITE_INFO']['base_url'] . '/config_editor.php';
        }
        $extra = '';
        if (function_exists('debug_backtrace') && strpos($error, 'Allowed memory') === false && (is_null($relay) || strpos($relay, 'Stack trace') === false) && function_exists('ocp_srv') && (ocp_srv('REMOTE_ADDR') == ocp_srv('SERVER_ADDR') && ocp_srv('HTTP_X_FORWARDED_FOR') == '' || preg_match('#^localhost(\\.|\\:|$)#', ocp_srv('HTTP_HOST')) != 0 && function_exists('get_base_url') && substr(get_base_url(), 0, 16) == 'http://localhost')) {
            $_trace = debug_backtrace();
            $extra = '<div class="medborder medborder_box"><h2>Stack trace&hellip;</h2>';
            foreach ($_trace as $stage) {
                $traces = '';
                foreach ($stage as $key => $value) {
                    if (is_object($value) && is_a($value, 'ocp_tempcode') || is_array($value) && strlen(serialize($value)) > 500) {
                        $_value = gettype($value);
                    } else {
                        if (strpos($error, 'Allowed memory') !== false) {
                            $_value = gettype($value);
                            switch ($_value) {
                                case 'integer':
                                    $_value = strval($value);
                                    break;
                                case 'string':
                                    $_value = $value;
                                    break;
                            }
                        } else {
                            @ob_start();
                            if (function_exists('var_export')) {
                                /*var_dump*/
                                var_export($value);
                            }
                            $_value = ob_get_contents();
                            ob_end_clean();
                        }
                    }
                    global $SITE_INFO;
                    if (isset($SITE_INFO['db_site_password']) && strlen($SITE_INFO['db_site_password']) > 4) {
                        $_value = str_replace($SITE_INFO['db_site_password'], '(password removed)', $_value);
                    }
                    if (isset($SITE_INFO['db_forums_password']) && strlen($SITE_INFO['db_forums_password']) > 4) {
                        $_value = str_replace($SITE_INFO['db_forums_password'], '(password removed)', $_value);
                    }
                    $traces .= ucfirst($key) . ' -> ' . htmlentities($_value) . '<br />' . chr(10);
                }
                $extra .= '<p>' . $traces . '</p>' . chr(10);
            }
            $extra .= '</div>';
        }
        $headers_sent = headers_sent();
        if (!$headers_sent) {
            @header('Content-type: text/html');
            echo <<<END
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN">
<head>
\t<title>Critical error</title>
\t<style type="text/css"><![CDATA[
END;
            if (strpos($error, 'Allowed memory') === false) {
                $file_contents = file_get_contents($GLOBALS['FILE_BASE'] . '/themes/default/css/global.css');
            } else {
                $file_contents = '';
                // Can't load files if dying due to memory limit
            }
            $css = preg_replace('#/\\*\\s*\\*/\\s*#', '', str_replace('url(\'\')', 'none', str_replace('url("")', 'none', preg_replace('#\\{\\$[^\\}]*\\}#', '', $file_contents))));
            echo htmlentities($css);
            echo <<<END
\t\t.main_page_title { text-decoration: underline; display: block; min-height: 42px; padding: 3px 0 0 0; }
\t\ta[target="_blank"], a[onclick\$="window.open"] { padding-right: 0; }
\t]]></style>
</head>
<body><div class="global_middle">
END;
        }
        echo '<h1 class="main_page_title">Critical error &ndash; bailing out</h1>' . chr(10) . '<div class="red_alert">' . $error . '</div>' . chr(10);
        flush();
        if (strpos($_SERVER['PHP_SELF'], 'upgrader.php') !== false && strpos($error, 'Allowed memory') === false) {
            require_code('upgrade');
            echo '<div class="medborder medborder_box"><h2>Integrity check</h2><p><strong>If you think this problem could be due to corruption caused by a failed upgrade (e.g. time-out during extraction), check the following integrity check&hellip;</strong></p>', run_integrity_check(true), '</div><br />';
        }
        flush();
        echo $extra, chr(10);
        echo '<p>Details here are intended only for the website/system-administrator, not for regular website users.<br />&raquo; <strong>If you are a regular website user, please let the website staff deal with this problem.</strong></p>' . chr(10) . '<p class="associated_details">Depending on the error, and only if the website installation finished, you may need to <a href="#" onclick="if (!window.confirm(\'Are you staff on this site?\')) return false; this.href=\'' . htmlentities($edit_url) . '\';">edit the installation options</a> (the <kbd>info.php</kbd> file).</p>' . chr(10) . '<p class="associated_details">ocProducts maintains full documentation for all procedures and tools. These may be found on the <a href="http://ocportal.com">ocPortal website</a>. If you are unable to easily solve this problem, we may be contacted from our website and can help resolve it for you.</p>' . chr(10) . '<hr />' . chr(10) . '<p style="font-size: 0.8em"><a href="http://ocportal.com/">ocPortal</a> is a <abbr title="Content Management System">CMS</abbr> for building websites, developed by ocProducts.</p>' . chr(10);
        echo '</div></body>' . chr(10) . '</html>';
        $GLOBALS['SCREEN_TEMPLATE_CALLED'] = '';
        if ($exit) {
            exit;
        }
    }
Example #8
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 #9
0
 /**
  * Get a preview(s) of a (group of) template(s), as a full standalone piece of HTML in Tempcode format.
  * Uses sources/lorem.php functions to place appropriate stock-text. Should not hard-code things, as the code is intended to be declaritive.
  * Assumptions: You can assume all Lang/CSS/Javascript files in this addon have been pre-required.
  *
  * @return array			Array of previews, each is Tempcode. Normally we have just one preview, but occasionally it is good to test templates are flexible (e.g. if they use IF_EMPTY, we can test with and without blank data).
  */
 function tpl_preview__administrative__zone_editor_screen()
 {
     require_lang('zones');
     $comcode_editor = do_lorem_template('COMCODE_EDITOR_BUTTON', array('DIVIDER' => true, 'FIELD_NAME' => lorem_word(), 'TITLE' => lorem_word(), 'B' => 'block'));
     $editor = array();
     foreach (array('panel_left', 'panel_middle', 'panel_right') as $i => $for) {
         $editor[$for] = do_lorem_template('ZONE_EDITOR_PANEL', array('CLASS' => '', 'ZONES' => '', 'CURRENT_ZONE' => '', 'ZONE' => '', 'COMCODE' => lorem_phrase(), 'PREVIEW' => lorem_phrase(), 'ID' => $for, 'IS_PANEL' => true, 'TYPE' => lorem_phrase(), 'EDIT_URL' => placeholder_url(), 'SETTINGS' => NULL, 'COMCODE_EDITOR' => $comcode_editor));
     }
     return array(lorem_globalise(do_lorem_template('ZONE_EDITOR_SCREEN', array('PING_URL' => placeholder_url(), 'WARNING_DETAILS' => '', 'TITLE' => lorem_title(), 'ID' => '', 'LANG' => fallback_lang(), 'URL' => placeholder_url(), 'LEFT_EDITOR' => $editor['panel_left'], 'RIGHT_EDITOR' => $editor['panel_right'], 'MIDDLE_EDITOR' => $editor['panel_middle'])), NULL, '', true));
 }
Example #10
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 #11
0
/**
 * Lookup error on ocportal.com, to see if there is more information.
 *
 * @param  mixed				The error message (string or tempcode)
 * @return ?string			The result from the web service (NULL: no result)
 */
function get_webservice_result($error_message)
{
    if (get_domain() == 'ocportal.com') {
        return NULL;
    }
    if (!function_exists('has_zone_access') || !has_zone_access(get_member(), 'adminzone')) {
        return NULL;
    }
    require_code('files');
    global $DONE_ONE_WEB_SERVICE;
    if ($GLOBALS['DOWNLOAD_LEVEL'] > 0 || $DONE_ONE_WEB_SERVICE) {
        return NULL;
    }
    $DONE_ONE_WEB_SERVICE = true;
    if (is_object($error_message)) {
        $error_message = $error_message->evaluate();
    }
    if ($GLOBALS['HTTP_STATUS_CODE'] == '401') {
        return NULL;
    }
    // Get message IN ENGLISH
    if (user_lang() != fallback_lang()) {
        global $LANGUAGE;
        foreach ($LANGUAGE as $_) {
            foreach ($_ as $key => $val) {
                $regexp = preg_replace('#\\\\{\\d+\\\\}#', '.*', str_replace('#', '\\#', preg_quote($val)));
                if ($regexp != '.*') {
                    if (preg_match('#' . $regexp . '#', $error_message) != 0) {
                        $_error_message = do_lang($key, '', '', '', fallback_lang(), false);
                        if (!is_null($_error_message)) {
                            $error_message = $_error_message;
                        }
                        break;
                    }
                }
            }
        }
    }
    // Talk to web service
    $brand = get_value('rebrand_name');
    if (is_null($brand)) {
        $brand = 'ocPortal';
    }
    $result = http_download_file('http://ocportal.com/uploads/website_specific/ocportal.com/scripts/errorservice.php?version=' . float_to_raw_string(ocp_version_number()) . '&error_message=' . rawurlencode($error_message) . '&product=' . rawurlencode($brand), NULL, false);
    if ($GLOBALS['HTTP_DOWNLOAD_MIME_TYPE'] != 'text/plain') {
        return NULL;
    }
    if ($result == '') {
        return NULL;
    }
    if (function_exists('ocp_mark_as_escaped')) {
        ocp_mark_as_escaped($result);
    }
    return $result;
}
Example #12
0
function do_work()
{
    $num_wanted = 100000;
    require_code('config2');
    set_option('post_history_days', '0');
    // Needed for a little sanity in recent post retrieval
    set_value('disable_sunk', '1');
    // members (remember to test the username autocompleter, and birthdays)
    // authors (remember to check author autocompleter and popup author list)
    // lots of people getting notifications on a forum
    // lots of people getting notifications on a topic
    require_code('authors');
    require_code('ocf_members_action');
    require_code('notifications');
    for ($i = $GLOBALS['FORUM_DB']->query_value('f_members', 'COUNT(*)'); $i < $num_wanted; $i++) {
        $member_id = ocf_make_member(uniqid('', true), uniqid('', true), uniqid('', true) . '@example.com', array(), intval(date('d')), intval(date('m')), intval(date('Y')), array(), NULL, NULL, 1, NULL, NULL, '', NULL, '', 0, 0, 1, '', '', '', 1, 1, NULL, 1, 1, '', NULL, '', false);
        add_author(random_line(), '', $member_id, random_text(), random_text());
        enable_notifications('ocf_topic', 'forum:' . strval(db_get_first_id()), $member_id);
        enable_notifications('ocf_topic', strval(db_get_first_id()), $member_id);
        // number of friends to a single member
        $GLOBALS['SITE_DB']->query_insert('chat_buddies', array('member_likes' => $member_id, 'member_liked' => db_get_first_id() + 1, 'date_and_time' => time()), false, true);
    }
    $member_id = db_get_first_id() + 2;
    // point earn list / gift points to a single member
    require_code('points2');
    for ($j = $GLOBALS['SITE_DB']->query_value('gifts', 'COUNT(*)'); $j < $num_wanted; $j++) {
        give_points(10, $member_id, mt_rand(db_get_first_id(), min(100, $num_wanted - 1)), random_line(), false, false);
    }
    // number of friends of a single member
    for ($j = intval(floatval($GLOBALS['SITE_DB']->query_value('chat_buddies', 'COUNT(*)')) / 2.0); $j < $num_wanted; $j++) {
        $GLOBALS['SITE_DB']->query_insert('chat_buddies', array('member_likes' => $member_id, 'member_liked' => $j + db_get_first_id(), 'date_and_time' => time()), false, true);
    }
    echo 'done member/authors/points/notifications/friends stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // banners
    require_code('banners2');
    for ($i = $GLOBALS['SITE_DB']->query_value('banners', 'COUNT(*)'); $i < $num_wanted; $i++) {
        add_banner(uniqid('', true), get_logo_url(), random_line(), random_text(), 100, get_base_url(), 3, '', db_get_first_id(), NULL, db_get_first_id() + 1, 1);
    }
    echo 'done banner stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // comcode pages
    require_code('files');
    require_code('files2');
    for ($i = $GLOBALS['SITE_DB']->query_value('comcode_pages', 'COUNT(*)'); $i < $num_wanted; $i++) {
        $file = uniqid('', true);
        /*$path=get_custom_file_base().'/site/pages/comcode_custom/'.fallback_lang().'/'.$file.'.txt';
        		$myfile=fopen($path,'wt');
        		fwrite($myfile,random_text());
        		fclose($myfile);
        		sync_file($path);
        		fix_permissions($path);*/
        $GLOBALS['SITE_DB']->query_insert('comcode_pages', array('the_zone' => 'site', 'the_page' => $file, 'p_parent_page' => '', 'p_validated' => 1, 'p_edit_date' => NULL, 'p_add_date' => time(), 'p_submitter' => db_get_first_id(), 'p_show_as_edit' => 0));
    }
    echo 'done comcode stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // zones
    require_code('zones2');
    require_code('abstract_file_manager');
    for ($i = $GLOBALS['SITE_DB']->query_value('zones', 'COUNT(*)'); $i < min($num_wanted, 1000); $i++) {
        actual_add_zone(uniqid('', true), random_line(), 'start', random_line(), 'default', 0, 0, 0);
    }
    echo 'done zone stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // calendar events
    require_code('calendar2');
    for ($i = $GLOBALS['SITE_DB']->query_value('calendar_events', 'COUNT(*)'); $i < $num_wanted; $i++) {
        add_calendar_event(db_get_first_id(), '', NULL, 0, random_line(), random_text(), 1, 1, intval(date('Y')), intval(date('m')), intval(date('d')), 0, 0);
    }
    echo 'done event stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // chat rooms
    require_code('chat2');
    require_code('chat');
    for ($i = $GLOBALS['SITE_DB']->query_value('chat_rooms', 'COUNT(*)'); $i < $num_wanted; $i++) {
        $room_id = add_chatroom(random_text(), random_line(), mt_rand(db_get_first_id() + 1, $num_wanted - 1), strval(db_get_first_id() + 1), '', '', '', fallback_lang());
    }
    $room_id = db_get_first_id() + 1;
    // messages in chat room
    for ($j = $GLOBALS['SITE_DB']->query_value('chat_messages', 'COUNT(*)'); $j < $num_wanted; $j++) {
        $_message_parsed = insert_lang_comcode(random_text(), 4);
        $GLOBALS['SITE_DB']->query_insert('chat_messages', array('system_message' => 0, 'ip_address' => '', 'room_id' => $room_id, 'user_id' => db_get_first_id(), 'date_and_time' => time(), 'the_message' => $_message_parsed, 'text_colour' => get_option('chat_default_post_colour'), 'font_name' => get_option('chat_default_post_font')));
    }
    echo 'done chat stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // download categories under a subcategory
    require_code('downloads2');
    $subcat_id = add_download_category(random_line(), db_get_first_id(), random_text(), '');
    for ($i = $GLOBALS['SITE_DB']->query_value('download_categories', 'COUNT(*)'); $i < $num_wanted; $i++) {
        add_download_category(random_line(), $subcat_id, random_text(), '');
    }
    // downloads (remember to test content by the single author)
    require_code('downloads2');
    require_code('awards');
    $time = time();
    for ($i = $GLOBALS['SITE_DB']->query_value('download_downloads', 'COUNT(*)'); $i < $num_wanted; $i++) {
        $content_id = add_download(db_get_first_id(), random_line(), get_logo_url(), random_text(), 'admin', random_text(), NULL, 1, 1, 1, 1, '', uniqid('', true) . '.jpg', 100, 110, 1);
        give_award(db_get_first_id(), strval($content_id), $time - $i);
    }
    $content_id = db_get_first_id();
    $content_url = build_url(array('page' => 'downloads', 'type' => 'entry', 'id' => $content_id), 'site');
    for ($j = $GLOBALS['SITE_DB']->query_value('trackbacks', 'COUNT(*)'); $j < $num_wanted; $j++) {
        // trackbacks
        $GLOBALS['SITE_DB']->query_insert('trackbacks', array('trackback_for_type' => 'downloads', 'trackback_for_id' => $content_id, 'trackback_ip' => '', 'trackback_time' => time(), 'trackback_url' => '', 'trackback_title' => random_line(), 'trackback_excerpt' => random_text(), 'trackback_name' => random_line()));
        // ratings
        $GLOBALS['SITE_DB']->query_insert('rating', array('rating_for_type' => 'downloads', 'rating_for_id' => $content_id, 'rating_member' => $j + 1, 'rating_ip' => '', 'rating_time' => time(), 'rating' => 3));
        // posts in a comment topic
        $GLOBALS['FORUM_DRIVER']->make_post_forum_topic(get_option('comments_forum_name'), 'downloads_' . strval($content_id), get_member(), random_text(), random_line(), '', do_lang('COMMENT'), $content_url->evaluate(), NULL, NULL, 1, 1);
    }
    echo 'done download stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // forums under a forum (don't test it can display, just make sure the main index still works)
    require_code('ocf_forums_action');
    for ($i = $GLOBALS['FORUM_DB']->query_value('f_forums', 'COUNT(*)'); $i < $num_wanted; $i++) {
        ocf_make_forum(random_line(), random_text(), db_get_first_id(), array(), db_get_first_id() + 3);
    }
    // forum topics
    require_code('ocf_topics_action');
    require_code('ocf_posts_action');
    require_code('ocf_forums');
    require_code('ocf_topics');
    for ($i = intval(floatval($GLOBALS['FORUM_DB']->query_value('f_topics', 'COUNT(*)')) / 2.0); $i < $num_wanted; $i++) {
        $topic_id = ocf_make_topic(db_get_first_id(), '', '', NULL, 1, 0, 0, 0, NULL, NULL, false);
        ocf_make_post($topic_id, random_line(), random_text(), 0, true, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, false);
    }
    // forum posts in a topic
    require_code('ocf_topics_action');
    require_code('ocf_posts_action');
    $topic_id = ocf_make_topic(db_get_first_id() + 1, '', '', NULL, 1, 0, 0, 0, NULL, NULL, false);
    for ($i = intval(floatval($GLOBALS['FORUM_DB']->query_value('f_posts', 'COUNT(*)')) / 3.0); $i < $num_wanted; $i++) {
        ocf_make_post($topic_id, random_line(), random_text(), 0, true, 0, 0, NULL, NULL, NULL, mt_rand(db_get_first_id(), $num_wanted - 1), NULL, NULL, NULL, false, false);
    }
    echo 'done forum stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // clubs
    require_code('ocf_groups_action');
    require_code('ocf_groups');
    for ($i = $GLOBALS['FORUM_DB']->query_value('f_groups', 'COUNT(*)'); $i < $num_wanted; $i++) {
        ocf_make_group(random_line(), 0, 0, 0, random_line(), '', NULL, NULL, NULL, 5, 0, 70, 50, 100, 100, 30000, 700, 25, 1, 0, 0, 0, $i, 1, 0, 1);
    }
    echo 'done club stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // galleries under a subcategory
    require_code('galleries2');
    $xsubcat_id = uniqid('', true);
    add_gallery($xsubcat_id, random_line(), random_text(), '', '', 'root');
    for ($i = $GLOBALS['SITE_DB']->query_value('galleries', 'COUNT(*)'); $i < $num_wanted; $i++) {
        add_gallery(uniqid('', true), random_line(), random_text(), '', '', $xsubcat_id);
    }
    // images
    require_code('galleries2');
    for ($i = $GLOBALS['SITE_DB']->query_value('images', 'COUNT(*)'); $i < $num_wanted; $i++) {
        add_image('', 'root', random_text(), get_logo_url(), get_logo_url(), 1, 1, 1, 1, '');
    }
    // videos / validation queue
    require_code('galleries2');
    for ($i = $GLOBALS['SITE_DB']->query_value('videos', 'COUNT(*)'); $i < $num_wanted; $i++) {
        add_video('', 'root', random_text(), get_logo_url(), get_logo_url(), 0, 1, 1, 1, '', 0, 0, 0);
    }
    echo 'done galleries stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // newsletter subscribers
    require_code('newsletter');
    for ($i = $GLOBALS['SITE_DB']->query_value('newsletter', 'COUNT(*)'); $i < $num_wanted; $i++) {
        basic_newsletter_join(uniqid('', true) . '@example.com');
    }
    echo 'done newsletter stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // polls (remember to test poll archive)
    require_code('polls');
    for ($i = $GLOBALS['SITE_DB']->query_value('poll', 'COUNT(*)'); $i < $num_wanted; $i++) {
        $poll_id = add_poll(random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), 10, 0, 0, 0, 0, '');
    }
    // votes on a poll
    $poll_id = db_get_first_id();
    for ($j = $GLOBALS['SITE_DB']->query_value('poll_votes', 'COUNT(*)'); $j < $num_wanted; $j++) {
        $cast = mt_rand(1, 6);
        $ip = uniqid('', true);
        $GLOBALS['SITE_DB']->query_insert('poll_votes', array('v_poll_id' => $poll_id, 'v_voter_id' => 2, 'v_voter_ip' => $ip, 'v_vote_for' => $cast));
    }
    echo 'done polls stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // quizzes
    require_code('quiz');
    for ($i = $GLOBALS['SITE_DB']->query_value('quizzes', 'COUNT(*)'); $i < $num_wanted; $i++) {
        add_quiz(random_line(), 0, random_text(), random_text(), random_text(), '', 0, time(), NULL, 3, 300, 'SURVEY', 1, '1) Some question');
    }
    echo 'done quizzes stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // successful searches (to test the search recommender)
    // ACTUALLY: I have manually verified the code, it is an isolated portion
    // cedi pages (do a long descendant tree for some, and orphans for others)
    // cedi posts (remember to test cedi changes screen)
    require_code('cedi');
    for ($i = $GLOBALS['SITE_DB']->query_value('seedy_pages', 'COUNT(*)'); $i < $num_wanted; $i++) {
        $page_id = cedi_add_page(random_line(), random_text(), '', 1);
        cedi_add_post($page_id, random_text(), 1, NULL, false);
    }
    echo 'done cedi stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // iotds
    require_code('iotds');
    for ($i = $GLOBALS['SITE_DB']->query_value('iotd', 'COUNT(*)'); $i < $num_wanted; $i++) {
        add_iotd(get_logo_url(), random_line(), random_text(), get_logo_url(), 1, 0, 0, 0, '');
    }
    echo 'done iotd stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // logged hack attempts
    for ($i = $GLOBALS['SITE_DB']->query_value('hackattack', 'COUNT(*)'); $i < $num_wanted; $i++) {
        $GLOBALS['SITE_DB']->query_insert('hackattack', array('url' => get_base_url(), 'data_post' => '', 'user_agent' => '', 'referer' => '', 'user_os' => '', 'the_user' => db_get_first_id(), 'date_and_time' => time(), 'ip' => uniqid('', true), 'reason' => 'ASCII_ENTITY_URL_HACK', 'reason_param_a' => '', 'reason_param_b' => ''));
    }
    // logged hits in one day
    require_code('site');
    for ($i = $GLOBALS['SITE_DB']->query_value('stats', 'COUNT(*)'); $i < $num_wanted; $i++) {
        log_stats('/testing' . uniqid('', true), mt_rand(100, 2000));
    }
    echo 'done logs stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // blogs and news entries (remember to test both blogs [categories] list, and a list of all news entries)
    require_code('news');
    for ($i = $GLOBALS['SITE_DB']->query_value('news', 'COUNT(*)'); $i < $num_wanted; $i++) {
        add_news(random_line(), random_text(), 'admin', 1, 1, 1, 1, '', random_text(), NULL, NULL, NULL, db_get_first_id() + $i);
    }
    echo 'done news stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // support tickets
    require_code('tickets');
    require_code('tickets2');
    for ($i = intval(floatval($GLOBALS['FORUM_DB']->query_value('f_topics', 'COUNT(*)')) / 2.0); $i < $num_wanted; $i++) {
        ticket_add_post(mt_rand(db_get_first_id(), $num_wanted - 1), uniqid('', true), db_get_first_id(), random_line(), random_text(), '', '');
    }
    echo 'done tickets stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // catalogues
    require_code('catalogues2');
    $root_id = db_get_first_id();
    for ($i = $GLOBALS['SITE_DB']->query_value('catalogues', 'COUNT(*)'); $i < $num_wanted; $i++) {
        $catalogue_name = uniqid('', true);
        $root_id = actual_add_catalogue($catalogue_name, random_line(), random_text(), mt_rand(0, 3), 1, '', 30);
    }
    // catalogue categories under a subcategory (remember to test all catalogue views: atoz, index, and root cat)
    $catalogue_name = 'products';
    $subcat_id = actual_add_catalogue_category($catalogue_name, random_line(), random_text(), '', $root_id);
    for ($j = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'COUNT(*)'); $j < $num_wanted; $j++) {
        actual_add_catalogue_category($catalogue_name, random_line(), random_text(), '', $subcat_id);
    }
    echo 'done catalogue stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    // items in ecommerce store
    require_code('catalogues2');
    $cat_id = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'MIN(id)', array('c_name' => 'products'));
    $fields = collapse_1d_complexity('id', $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id'), array('c_name' => 'products')));
    for ($i = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'COUNT(*)'); $i < $num_wanted; $i++) {
        $map = array($fields[0] => random_line(), $fields[1] => uniqid('', true), $fields[2] => '1.0', $fields[3] => '1', $fields[4] => '0', $fields[5] => '1', $fields[6] => '0%', $fields[7] => get_logo_url(), $fields[8] => '2.0', $fields[9] => random_text());
        $pid = actual_add_catalogue_entry($cat_id, 1, '', 1, 1, 1, $map);
        unset($map);
    }
    // outstanding ecommerce orders
    $pid = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'MIN(id)', array('c_name' => 'products'));
    require_code('shopping');
    for ($j = $GLOBALS['SITE_DB']->query_value('shopping_cart', 'COUNT(*)'); $j < $num_wanted; $j++) {
        $product_det = array('product_id' => $pid, 'product_name' => $fields[0], 'product_code' => $fields[1], 'price' => $fields[2], 'tax' => preg_replace('#[^\\d\\.]#', '', $fields[6]), 'description' => $fields[9], 'quantity' => mt_rand(1, 20), 'product_type' => 'catalogue_items', 'product_weight' => $fields[8]);
        $GLOBALS['SITE_DB']->query_insert('shopping_cart', array('session_id' => mt_rand(0, 1000000), 'ordered_by' => mt_rand(db_get_first_id() + 1, $num_wanted - 1), 'product_id' => $product_det['product_id'], 'product_name' => $product_det['product_name'], 'product_code' => $product_det['product_code'], 'quantity' => $product_det['quantity'], 'price' => round(floatval($product_det['price']), 2), 'price_pre_tax' => $product_det['tax'], 'product_description' => $product_det['description'], 'product_type' => $product_det['product_type'], 'product_weight' => $product_det['product_weight'], 'is_deleted' => 0));
    }
    for ($j = $GLOBALS['SITE_DB']->query_value('shopping_order', 'COUNT(*)'); $j < $num_wanted; $j++) {
        $order_id = $GLOBALS['SITE_DB']->query_insert('shopping_order', array('c_member' => mt_rand(db_get_first_id() + 1, $num_wanted - 1), 'session_id' => mt_rand(0, 1000000), 'add_date' => time(), 'tot_price' => '123.00', 'order_status' => 'ORDER_STATUS_awaiting_payment', 'notes' => '', 'purchase_through' => 'purchase_module', 'transaction_id' => '', 'tax_opted_out' => 0), true);
        $GLOBALS['SITE_DB']->query_insert('shopping_order_details', array('p_id' => 123, 'p_name' => random_line(), 'p_code' => 123, 'p_type' => 'catalogue_items', 'p_quantity' => 1, 'p_price' => '12.00', 'order_id' => $order_id, 'dispatch_status' => '', 'included_tax' => '1.00'));
    }
    echo 'done store stuff' . chr(10);
    if (function_exists('gc_collect_cycles')) {
        gc_enable();
    }
    echo '{{DONE}}' . chr(10);
}
Example #13
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)
 {
     require_code('themes2');
     $themes = find_all_themes();
     // Find all images for all themes
     /*if ($upgrade_from==2)
     		{
     			foreach (array_keys($themes) as $theme)
     			{
     				if ($theme!='default')
     				{
     					// Make it so it'll now import from the default theme to get anything that is currently missing
     					$_dir=opendir(get_file_base().'/themes/default/css');
     					while (false!==($file=readdir($_dir)))
     					{
     						if (strtolower(substr($file,-4,4))=='.css')
     						{
     							$path=get_file_base().'/themes/'.$theme.'/css/'.$file;
     							$new_css_file=(($file=='no_cache.css')?'':"@import url(../../../default/css/$file);\n\n").file_get_contents($path);
     							$myfile=@fopen($path,'wt');
     							if ($myfile===false) intelligent_write_error($path);
     							fwrite($myfile,$new_css_file);
     							fclose($myfile);
     							fix_permissions($path);
     						}
     					}
     					closedir($_dir);
     
     					// Rename all their modified templates, because they've probably changed. They'll need to redo them :(
     					$path=get_file_base().'/themes/'.$theme.'/templates_custom/';
     					$_dir=opendir($path);
     					if ($_dir!==false)
     					{
     						while (false!==($file=readdir($_dir)))
     						{
     							if (substr($file,-4,4)=='.tpl')
     								rename($path.$file,$path.$file.'.from_'.strval($upgrade_from));
     						}
     						closedir($_dir);
     					}
     					$path=get_file_base().'/themes/'.$theme.'/templates/';
     					$_dir=opendir($path);
     					if ($_dir!==false)
     					{
     						while (false!==($file=readdir($_dir)))
     						{
     							if (substr($file,-4,4)=='.tpl')
     								rename($path.$file,$path.$file.'.from_'.strval($upgrade_from));
     						}
     						closedir($_dir);
     					}
     				}
     			}
     		}*/
     if (is_null($upgrade_from)) {
         $GLOBALS['SITE_DB']->create_table('theme_images', array('id' => '*SHORT_TEXT', 'theme' => '*MINIID_TEXT', 'path' => 'URLPATH', 'lang' => '*LANGUAGE_NAME'));
         $GLOBALS['SITE_DB']->create_index('theme_images', 'theme', array('theme', 'lang'));
         add_config_option('STORE_REVISIONS', 'templates_store_revisions', 'tick', 'return \'1\';', 'ADMIN', 'EDIT_TEMPLATES');
         add_config_option('SHOW_REVISIONS', 'templates_number_revisions_show', 'integer', 'return \'5\';', 'ADMIN', 'EDIT_TEMPLATES');
         /*$langs=find_all_langs(true); // Find all images for all themes
         			foreach (array_keys($themes) as $theme)
         			{
         				require_code('themes3');
         				regen_theme_images($theme,$langs);
         			}
         
         			// Now add in any default theme images missing in other themes
         			$images=find_images_do_dir('default','',$langs);
         			foreach (array_keys($themes) as $theme)
         			{
         				foreach ($images as $id=>$path)
         				{
         					foreach (array_keys($langs) as $lang)
         					{
         						$test=$GLOBALS['SITE_DB']->query_value_null_ok('theme_images','path',array('theme'=>$theme,'lang'=>$lang,'id'=>$id));
         						if (is_null($test))
         						{
         							$GLOBALS['SITE_DB']->query_insert('theme_images',array('id'=>$id,'theme'=>$theme,'lang'=>$lang,'path'=>$path));
         						}
         					}
         				}
         			}*/
     }
     if (is_null($upgrade_from) || $upgrade_from < 4) {
         $GLOBALS['SITE_DB']->query_insert('theme_images', array('id' => 'favicon', 'theme' => 'default', 'path' => 'favicon.ico', 'lang' => fallback_lang()), false, true);
         $GLOBALS['SITE_DB']->query_insert('theme_images', array('id' => 'appleicon', 'theme' => 'default', 'path' => 'appleicon.png', 'lang' => fallback_lang()), false, true);
     }
 }
Example #14
0
/**
 * Get an array of all the INI description entries in the specified language.
 *
 * @param  LANGUAGE_NAME	The language
 * @param  ?ID_TEXT			The language file (NULL: all non-custom language files)
 * @return array				The language descriptions
 */
function get_lang_file_descriptions($lang, $file = NULL)
{
    if (is_null($file)) {
        $dh = opendir(get_file_base() . '/lang/' . $lang);
        $descriptions = array();
        while (($f = readdir($dh)) !== false) {
            if (substr($f, -4) == '.ini') {
                $descriptions = array_merge($descriptions, get_lang_file_descriptions($lang, basename($f, '.ini')));
            }
        }
        return $descriptions;
    }
    $a = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $file . '.ini';
    if (get_custom_file_base() != get_file_base() && !is_file($a)) {
        $a = get_file_base() . '/lang_custom/' . $lang . '/' . $file . '.ini';
    }
    $b = is_file($a) ? $a : get_file_base() . '/lang/' . $lang . '/' . $file . '.ini';
    if (!is_file($b)) {
        $b = get_file_base() . '/lang/' . fallback_lang() . '/' . $file . '.ini';
    }
    $target = array();
    require_code('lang_compile');
    _get_lang_file_map($b, $target, true);
    return $target;
}
Example #15
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 #16
0
 /**
  * Get a preview(s) of a (group of) template(s), as a full standalone piece of HTML in Tempcode format.
  * Uses sources/lorem.php functions to place appropriate stock-text. Should not hard-code things, as the code is intended to be declaritive.
  * Assumptions: You can assume all Lang/CSS/Javascript files in this addon have been pre-required.
  *
  * @return array			Array of previews, each is Tempcode. Normally we have just one preview, but occasionally it is good to test templates are flexible (e.g. if they use IF_EMPTY, we can test with and without blank data).
  */
 function tpl_preview__newsletter_default()
 {
     return array(lorem_globalise(do_lorem_template('NEWSLETTER_DEFAULT', array('CONTENT' => lorem_phrase(), 'LANG' => fallback_lang())), NULL, '', true));
 }
Example #17
0
 /**
  * The UI for managing super debranding.
  *
  * @return tempcode		The UI
  */
 function misc()
 {
     $title = get_page_title('SUPER_DEBRAND');
     require_code('form_templates');
     $rebrand_name = get_value('rebrand_name');
     if (is_null($rebrand_name)) {
         $rebrand_name = 'ocPortal';
     }
     $rebrand_base_url = get_value('rebrand_base_url');
     if (is_null($rebrand_base_url)) {
         $rebrand_base_url = 'http://ocportal.com';
     }
     $company_name = get_value('company_name');
     if (is_null($company_name)) {
         $company_name = 'ocProducts';
     }
     $keyboard_map = file_exists(get_file_base() . '/pages/comcode/' . get_site_default_lang() . '/keymap.txt') ? file_get_contents(get_file_base() . '/pages/comcode/' . get_site_default_lang() . '/keymap.txt') : file_get_contents(get_file_base() . '/pages/comcode/' . fallback_lang() . '/keymap.txt');
     if (file_exists(get_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/keymap.txt')) {
         $keyboard_map = file_get_contents(get_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/keymap.txt');
     }
     if (file_exists(get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang() . '/website.txt')) {
         $adminguide = file_get_contents(get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang() . '/website.txt');
     } else {
         $adminguide = do_lang('ADMINGUIDE_DEFAULT_TRAINING');
     }
     if (file_exists(get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang() . '/start.txt')) {
         $start_page = file_get_contents(get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang() . '/start.txt');
     } elseif (file_exists(get_file_base() . '/adminzone/pages/comcode/' . get_site_default_lang() . '/start.txt')) {
         $start_page = file_exists(get_file_base() . '/adminzone/pages/comcode/' . get_site_default_lang() . '/start.txt') ? file_get_contents(get_file_base() . '/adminzone/pages/comcode/' . get_site_default_lang() . '/start.txt') : file_get_contents(get_file_base() . '/adminzone/pages/comcode/' . fallback_lang() . '/start.txt');
     } else {
         $start_page = do_lang('REBRAND_FRONT_PAGE');
     }
     $fields = new ocp_tempcode();
     $fields->attach(form_input_line(do_lang_tempcode('REBRAND_NAME'), do_lang_tempcode('DESCRIPTION_REBRAND_NAME'), 'rebrand_name', $rebrand_name, true));
     $fields->attach(form_input_line(do_lang_tempcode('REBRAND_BASE_URL'), do_lang_tempcode('DESCRIPTION_BRAND_BASE_URL', escape_html('docs' . strval(ocp_version()))), 'rebrand_base_url', $rebrand_base_url, true));
     $fields->attach(form_input_line(do_lang_tempcode('COMPANY_NAME'), '', 'company_name', $company_name, true));
     $fields->attach(form_input_text_comcode(do_lang_tempcode('ADMINGUIDE'), do_lang_tempcode('DESCRIPTION_ADMINGUIDE'), 'adminguide', $adminguide, true));
     $fields->attach(form_input_text_comcode(do_lang_tempcode('ADMINSTART_PAGE'), do_lang_tempcode('DESCRIPTION_ADMINSTART_PAGE'), 'start_page', $start_page, true));
     $fields->attach(form_input_text_comcode(do_lang_tempcode('KEYBOARD_MAP'), '', 'keyboard_map', $keyboard_map, true));
     $fields->attach(form_input_tick(do_lang_tempcode('DELETE_UN_PC'), do_lang_tempcode('DESCRIPTION_DELETE_UN_PC'), 'churchy', false));
     $fields->attach(form_input_tick(do_lang_tempcode('SHOW_DOCS'), do_lang_tempcode('DESCRIPTION_SHOW_DOCS'), 'show_docs', get_option('show_docs') == '1'));
     $fields->attach(form_input_upload(do_lang_tempcode('FAVICON'), do_lang_tempcode('DESCRIPTION_FAVICON'), 'favicon', false, find_theme_image('favicon'), NULL, true, str_replace(' ', '', get_option('valid_images'))));
     $fields->attach(form_input_upload(do_lang_tempcode('APPLEICON'), do_lang_tempcode('DESCRIPTION_APPLEICON'), 'appleicon', false, find_theme_image('appleicon'), NULL, true, str_replace(' ', '', get_option('valid_images'))));
     if (addon_installed('ocf_avatars')) {
         $fields->attach(form_input_upload(do_lang_tempcode('SYSTEM_AVATAR'), do_lang_tempcode('DESCRIPTION_SYSTEM_AVATAR'), 'system_avatar', false, find_theme_image('ocf_default_avatars/default_set/ocp_fanatic'), NULL, true, str_replace(' ', '', get_option('valid_images'))));
     }
     $post_url = build_url(array('page' => '_SELF', 'type' => 'actual'), '_SELF');
     $submit_name = do_lang_tempcode('SUPER_DEBRAND');
     return do_template('FORM_SCREEN', array('HIDDEN' => '', 'TITLE' => $title, 'URL' => $post_url, 'FIELDS' => $fields, 'TEXT' => do_lang_tempcode('WARNING_SUPER_DEBRAND_MAJOR_CHANGES'), 'SUBMIT_NAME' => $submit_name));
 }
Example #18
0
 /**
  * The actualiser to translate code (called externally, and may operate on many lang files).
  *
  * @return tempcode		The UI
  */
 function set_lang_code_2()
 {
     $lang = post_param('lang');
     $lang_files = get_lang_files(fallback_lang());
     foreach (array_keys($lang_files) as $lang_file) {
         $for_base_lang = get_lang_file_map(fallback_lang(), $lang_file, true);
         $for_base_lang_2 = get_lang_file_map($lang, $lang_file, false);
         $descriptions = get_lang_file_descriptions(fallback_lang(), $lang_file);
         $out = '';
         foreach ($for_base_lang_2 + $for_base_lang as $key => $now_val) {
             $val = post_param('l_' . $key, array_key_exists($key, $for_base_lang_2) ? $for_base_lang_2[$key] : $now_val);
             if (str_replace(chr(10), '\\n', $val) != $now_val || !array_key_exists($key, $for_base_lang) || $for_base_lang[$key] != $val || !file_exists(get_file_base() . '/lang/' . fallback_lang() . '/' . $lang_file . '.ini')) {
                 // if it's changed from default ocPortal, or not in default ocPortal, or was already changed in language file, or whole file is not in default ocPortal
                 $out .= $key . '=' . str_replace(chr(10), '\\n', $val) . "\n";
             }
         }
         if ($out != '') {
             $path = get_custom_file_base() . '/lang_custom/' . filter_naughty($lang) . '/' . filter_naughty($lang_file) . '.ini';
             $path_backup = $path . '.' . strval(time());
             if (file_exists($path)) {
                 @copy($path, $path_backup) or intelligent_write_error($path_backup);
                 sync_file($path_backup);
             }
             $myfile = @fopen($path, 'wt');
             if ($myfile === false) {
                 intelligent_write_error($path);
             }
             fwrite($myfile, "[descriptions]\n");
             foreach ($descriptions as $key => $description) {
                 if (fwrite($myfile, $key . '=' . $description . "\n") == 0) {
                     warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                 }
             }
             fwrite($myfile, "\n[strings]\n");
             fwrite($myfile, $out);
             fclose($myfile);
             fix_permissions($path);
             sync_file($path);
             $path_backup2 = $path . '.latest_in_ocp_edit';
             @copy($path, $path_backup2) or intelligent_write_error($path_backup2);
             sync_file($path_backup2);
         }
     }
     $title = get_page_title('TRANSLATE_CODE');
     log_it('TRANSLATE_CODE');
     require_code('view_modes');
     erase_cached_language();
     erase_cached_templates();
     // Show it worked / Refresh
     $url = post_param('redirect', '');
     if ($url == '') {
         return inform_screen($title, do_lang_tempcode('SUCCESS'));
     }
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
     } else {
         $full_img_set[] = $expression;
     }
 }
 $temp_all_ids = collapse_2d_complexity('id', 'path', $GLOBALS['SITE_DB']->query_select('theme_images', array('id', 'path'), array('theme' => $theme)));
 foreach ($full_img_set as $image_code) {
     if (!in_array($image_code, $THEME_WIZARD_IMAGES_NO_WILD)) {
         if (array_key_exists($image_code, $temp_all_ids) && strpos($temp_all_ids[$image_code], $theme . '/images_custom/') !== false && (!url_is_local($temp_all_ids[$image_code]) || file_exists(get_custom_file_base() . '/' . $temp_all_ids[$image_code]))) {
             continue;
         }
         $orig_path = find_theme_image($image_code, true, true, 'default', 'EN');
         if ($orig_path == '') {
             continue;
         }
         // Theme has specified non-existent image as themewizard-compatible
         if (strpos($orig_path, '/' . fallback_lang() . '/') !== false) {
             $composite = 'themes/' . filter_naughty($theme) . '/images/EN/';
         } else {
             $composite = 'themes/' . filter_naughty($theme) . '/images/';
         }
         afm_make_directory($composite, true);
         $saveat = get_custom_file_base() . '/' . $composite . $image_code . '.png';
         $saveat_url = $composite . $image_code . '.png';
         if (!file_exists($saveat)) {
             $image = calculate_theme($seed, 'default', 'equations', $image_code, $dark, $theme_map, $theme_landscape, 'EN');
             if (!is_null($image)) {
                 $pos = strpos($image_code, '/');
                 if ($pos !== false || strpos($orig_path, '/EN/') !== false) {
                     afm_make_directory($composite . substr($image_code, 0, $pos), true, true);
                 }
                 @imagepng($image, $saveat) or intelligent_write_error($saveat);
Example #20
0
 /**
  * Standard modular run function.
  *
  * @return tempcode	The result of execution.
  */
 function run()
 {
     require_code('form_templates');
     require_code('feedback');
     require_code('autosave');
     require_code('permissions2');
     if (get_value('xhtml_strict') === '1') {
         $this->second_stage_preview = true;
     }
     // Load lang file if it exists
     $this->module_type = get_class($this);
     if (strtolower(substr($this->module_type, 0, 11)) == 'module_cms_') {
         $this->module_type = substr($this->module_type, 11);
     }
     if (strtolower(substr($this->module_type, 0, 13)) == 'module_admin_') {
         $this->module_type = substr($this->module_type, 13);
     }
     if (strtolower(substr($this->module_type, 0, 7)) == 'module_') {
         $this->module_type = substr($this->module_type, 7);
     }
     if (substr($this->module_type, 0, 4) == 'ocf_') {
         $this->module_type = substr($this->module_type, 2);
     }
     if (file_exists(get_file_base() . '/lang/' . fallback_lang() . '/' . $this->module_type . '.ini') || file_exists(get_custom_file_base() . '/lang_custom/' . fallback_lang() . '/' . $this->module_type . '.ini')) {
         require_lang($this->module_type);
     }
     if (!is_null($this->code_require)) {
         require_code($this->code_require);
     }
     if (!is_null($this->javascript_require)) {
         require_javascript($this->javascript_require);
     }
     if (is_null($this->default_type)) {
         $this->default_type = method_exists($this, 'misc') ? 'misc' : 'ad';
     }
     $type = get_param('type', $this->default_type);
     if (method_exists($this, 'misc') && $type != 'misc') {
         if ($this->special_edit_frontend && ($type == '_ed' || $type == '_ec')) {
             breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode(is_null($this->menu_label) ? 'MENU' : $this->menu_label)), array('_SELF:_SELF:' . substr($type, 1), do_lang_tempcode('CHOOSE'))));
         } else {
             if ($this->catalogue && either_param('catalogue_name', '') != '') {
                 $catalogue_title = get_translated_text($GLOBALS['SITE_DB']->query_value('catalogues', 'c_title', array('c_name' => either_param('catalogue_name'))));
                 breadcrumb_set_parents(array(array('_SELF:_SELF:misc:catalogue_name=' . either_param('catalogue_name', ''), $catalogue_title)));
             } else {
                 breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode(is_null($this->menu_label) ? 'MENU' : $this->menu_label))));
             }
         }
     } else {
         if ($this->special_edit_frontend && ($type == '_ed' || $type == '_ec')) {
             breadcrumb_set_parents(array(array('_SELF:_SELF:' . substr($type, 1), do_lang_tempcode('CHOOSE'))));
         }
     }
     if (method_exists($this, 'run_start')) {
         $ret = $this->run_start($type);
         if (!is_null($ret) && !$ret->is_empty()) {
             return $ret;
         }
     }
     if (!is_null($this->cat_aed_module)) {
         $this->cat_aed_module->type_code = 'd';
     }
     if ($type == 'ad') {
         return $this->ad();
     }
     if ($type == '_ad') {
         return $this->_ad();
     }
     if ($type == 'ed') {
         return $this->ed();
     }
     if ($type == '_ed') {
         return $this->_ed();
     }
     if ($type == '__ed') {
         return $this->__ed();
     }
     if (!is_null($this->cat_aed_module)) {
         $this->cat_aed_module->type_code = 'c';
         if ($type == 'ac') {
             return $this->cat_aed_module->ad();
         }
         if ($type == '_ac') {
             return $this->cat_aed_module->_ad();
         }
         if ($type == 'ec') {
             return $this->cat_aed_module->ed();
         }
         if ($type == '_ec') {
             return $this->cat_aed_module->_ed();
         }
         if ($type == '__ec') {
             return $this->cat_aed_module->__ed();
         }
     }
     if (!is_null($this->alt_aed_module)) {
         $this->alt_aed_module->type_code = 'v';
         if ($type == 'av') {
             return $this->alt_aed_module->ad();
         }
         if ($type == '_av') {
             return $this->alt_aed_module->_ad();
         }
         if ($type == 'ev') {
             return $this->alt_aed_module->ed();
         }
         if ($type == '_ev') {
             return $this->alt_aed_module->_ed();
         }
         if ($type == '__ev') {
             return $this->alt_aed_module->__ed();
         }
     }
     // These ones are for catalogues only...
     if ($type == 'add_entry') {
         return $this->ad();
     }
     if ($type == '_add_entry') {
         return $this->_ad();
     }
     if ($type == 'edit_entry') {
         return $this->ed();
     }
     if ($type == '_edit_entry') {
         return $this->_ed();
     }
     if ($type == '__edit_entry') {
         return $this->__ed();
     }
     if (!is_null($this->cat_aed_module)) {
         $this->cat_aed_module->type_code = 'c';
         if ($type == 'add_category') {
             return $this->cat_aed_module->ad();
         }
         if ($type == '_add_category') {
             return $this->cat_aed_module->_ad();
         }
         if ($type == 'edit_category') {
             return $this->cat_aed_module->ed();
         }
         if ($type == '_edit_category') {
             return $this->cat_aed_module->_ed();
         }
         if ($type == '__edit_category') {
             return $this->cat_aed_module->__ed();
         }
     }
     if (!is_null($this->alt_aed_module)) {
         $this->alt_aed_module->type_code = 'v';
         if ($type == 'add_catalogue') {
             return $this->alt_aed_module->ad();
         }
         if ($type == '_add_catalogue') {
             return $this->alt_aed_module->_ad();
         }
         if ($type == 'edit_catalogue') {
             return $this->alt_aed_module->ed();
         }
         if ($type == '_edit_catalogue') {
             return $this->alt_aed_module->_ed();
         }
         if ($type == '__edit_catalogue') {
             return $this->alt_aed_module->__ed();
         }
     }
     return new ocp_tempcode();
 }
Example #21
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 #22
0
 /**
  * Get a preview(s) of a (group of) template(s), as a full standalone piece of HTML in Tempcode format.
  * Uses sources/lorem.php functions to place appropriate stock-text. Should not hard-code things, as the code is intended to be declaritive.
  * Assumptions: You can assume all Lang/CSS/Javascript files in this addon have been pre-required.
  *
  * @return array			Array of previews, each is Tempcode. Normally we have just one preview, but occasionally it is good to test templates are flexible (e.g. if they use IF_EMPTY, we can test with and without blank data).
  */
 function tpl_preview__administrative__installer_step_4()
 {
     require_css('install');
     require_lang('installer');
     require_lang('version');
     $options = new ocp_tempcode();
     $options->attach($this->make_option(lorem_phrase(), new ocp_tempcode(), 'ftp_username', '', false, true));
     $options->attach($this->make_option(lorem_phrase(), new ocp_tempcode(), 'ftp_password', '', true));
     $options->attach($this->make_tick(lorem_word(), lorem_phrase(), 'tick', 1));
     $section = do_lorem_template('INSTALLER_STEP_4_SECTION', array('HIDDEN' => '', 'TITLE' => lorem_word(), 'TEXT' => lorem_sentence_html(), 'OPTIONS' => $options));
     $section->attach(do_lorem_template('INSTALLER_STEP_4_SECTION_HIDE', array('TITLE' => lorem_phrase(), 'CONTENT' => lorem_phrase())));
     $content = do_lorem_template('INSTALLER_STEP_4', array('JS' => '', 'MESSAGE' => '', 'LANG' => fallback_lang(), 'DB_TYPE' => lorem_phrase(), 'FORUM_TYPE' => lorem_phrase(), 'BOARD_PATH' => lorem_phrase(), 'SECTIONS' => $section, 'MAX' => '1000'));
     return array(lorem_globalise(do_lorem_template('INSTALLER_WRAP', array('CSS_NOCACHE' => ".nocss{}", 'DEFAULT_FORUM' => lorem_phrase(), 'PASSWORD_PROMPT' => lorem_phrase(), 'CSS_URL' => get_base_url() . '/themes/default/css/installer.css', 'CSS_URL_2' => get_base_url() . '/themes/default/css/installer.css', 'LOGO_URL' => placeholder_image_url(), 'STEP' => '1', 'CONTENT' => $content, 'VERSION' => lorem_phrase())), NULL, '', true));
 }
Example #23
0
/**
 * Load up a language file, compiling it (it's not cached yet).
 *
 * @param  ID_TEXT			The language file name
 * @param  ?LANGUAGE_NAME	The language (NULL: uses the current language)
 * @param  ?string			The language type (lang_custom, or custom) (NULL: normal priorities are used)
 * @set    lang_custom custom
 * @param  PATH				Where we are cacheing too
 * @param  boolean			Whether to just return if there was a loading error
 * @return boolean			Whether we FAILED to load
 */
function require_lang_compile($codename, $lang, $type, $cache_path, $ignore_errors = false)
{
    global $LANGUAGE, $REQUIRE_LANG_LOOP, $LANG_LOADED_LANG;
    $desire_cache = function_exists('get_option') && (get_option('is_on_lang_cache', true) == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache', 0) == 1) && get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache', NULL) !== 0;
    if ($desire_cache) {
        if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 0) {
            global $DECACHED_COMCODE_LANG_STRINGS;
            // Cleanup language strings
            if (!$DECACHED_COMCODE_LANG_STRINGS) {
                $DECACHED_COMCODE_LANG_STRINGS = true;
                $comcode_lang_strings = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index'), array('the_zone' => '!'), '', NULL, NULL, true);
                if (!is_null($comcode_lang_strings)) {
                    $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => '!'));
                    foreach ($comcode_lang_strings as $comcode_lang_string) {
                        delete_lang($comcode_lang_string['string_index']);
                    }
                }
            }
        }
        $load_target = array();
    } else {
        $load_target =& $LANGUAGE[$lang];
    }
    global $FILE_ARRAY;
    if (@is_array($FILE_ARRAY) && file_array_exists('lang/' . $lang . '/' . $codename . '.ini')) {
        $lang_file = 'lang/' . $lang . '/' . $codename . '.ini';
        $file = file_array_get($lang_file);
        _get_lang_file_map($file, $load_target, NULL, true);
        $bad = true;
    } else {
        $bad = true;
        $dirty = false;
        // Load originals
        $lang_file = get_file_base() . '/lang/' . $lang . '/' . filter_naughty($codename) . '.ini';
        if (file_exists($lang_file)) {
            _get_lang_file_map($lang_file, $load_target, NULL, false);
            $bad = false;
        }
        // Load overrides now if they are there
        if ($type != 'lang') {
            $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini';
            if (!file_exists($lang_file) && get_file_base() != get_custom_file_base()) {
                $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini';
            }
            if (!file_exists($lang_file)) {
                $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.po';
                if (!file_exists($lang_file)) {
                    $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '-' . strtolower($lang) . '.po';
                }
            }
        }
        if ($type != 'lang' && file_exists($lang_file)) {
            _get_lang_file_map($lang_file, $load_target, NULL, false);
            $bad = false;
            $dirty = true;
            // Tainted from the official pack, so can't store server wide
        }
        // NB: Merge op doesn't happen in require_lang. It happens when do_lang fails and then decides it has to force a recursion to do_lang(xx,fallback_lang()) which triggers require_lang(xx,fallback_lang()) when it sees it's not loaded
        if ($bad && $lang != fallback_lang()) {
            require_lang($codename, fallback_lang(), $type, $ignore_errors);
            $REQUIRE_LANG_LOOP--;
            $fallback_cache_path = get_custom_file_base() . '/lang_cached/' . fallback_lang() . '/' . $codename . '.lcd';
            if (file_exists($fallback_cache_path)) {
                require_code('files');
                @copy($fallback_cache_path, $cache_path);
                fix_permissions($cache_path);
            }
            if (!array_key_exists($lang, $LANG_LOADED_LANG)) {
                $LANG_LOADED_LANG[$lang] = array();
            }
            $LANG_LOADED_LANG[$lang][$codename] = 1;
            return $bad;
        }
        if ($bad) {
            if ($ignore_errors) {
                return true;
            }
            if ($codename != 'critical_error' || $lang != get_site_default_lang()) {
                fatal_exit(do_lang_tempcode('MISSING_LANG_FILE', escape_html($codename), escape_html($lang)));
            } else {
                critical_error('CRIT_LANG');
            }
        }
    }
    if (is_null($GLOBALS['MEM_CACHE'])) {
        // Cache
        if ($desire_cache) {
            $file = @fopen($cache_path, 'wt');
            // Will fail if cache dir missing .. e.g. in quick installer
            if ($file) {
                if (fwrite($file, serialize($load_target)) > 0) {
                    // Success
                    fclose($file);
                    require_code('files');
                    fix_permissions($cache_path);
                } else {
                    // Failure
                    fclose($file);
                    @unlink($cache_path);
                }
            }
        }
    } else {
        persistant_cache_set(array('LANG', $lang, $codename), $load_target, !$dirty);
    }
    if ($desire_cache) {
        $LANGUAGE[$lang] += $load_target;
    }
    return $bad;
}
Example #24
0
 /**
  * Handle a PHP command by executing it, dealing with variables from the class.
  */
 function _handle_php_command()
 {
     //NOTE: Variables throughout this function use the $occle_ prefix to avoid conflicts with any created through executing PHP commands from the CL
     if (get_file_base() == get_custom_file_base()) {
         if (array_key_exists('occle_state', $_COOKIE)) {
             if (get_magic_quotes_gpc()) {
                 $_COOKIE['occle_state'] = stripslashes($_COOKIE['occle_state']);
             }
             $occle_state_diff = @unserialize($_COOKIE['occle_state']);
             if (!is_array($occle_state_diff)) {
                 $occle_state_diff = array();
             }
         } else {
             $occle_state_diff = array();
         }
         if (array_key_exists('occle_state_lang', $_COOKIE)) {
             if (get_magic_quotes_gpc()) {
                 $_COOKIE['occle_state_lang'] = stripslashes($_COOKIE['occle_state_lang']);
             }
             $occle_state_lang_diff = @unserialize($_COOKIE['occle_state_lang']);
             if (!is_array($occle_state_lang_diff)) {
                 $occle_state_lang_diff = array();
             }
         } else {
             $occle_state_lang_diff = array();
         }
         if (array_key_exists('occle_state_code', $_COOKIE)) {
             if (get_magic_quotes_gpc()) {
                 $_COOKIE['occle_state_code'] = stripslashes($_COOKIE['occle_state_code']);
             }
             $occle_state_code_diff = @unserialize($_COOKIE['occle_state_code']);
             if (!is_array($occle_state_code_diff)) {
                 $occle_state_code_diff = array();
             }
         } else {
             $occle_state_code_diff = array();
         }
         if (!defined('HIPHOP_PHP')) {
             foreach ($occle_state_diff as $occle_key => $occle_val) {
                 if (!is_scalar($occle_val)) {
                     continue;
                 }
                 if (!is_integer($occle_val) && !is_float($occle_val)) {
                     eval('$' . $occle_key . '=\'' . addslashes($occle_val) . '\';');
                 } else {
                     eval('$' . $occle_key . '=' . strval($occle_val) . ';');
                 }
             }
         }
         foreach ($occle_state_lang_diff as $occle_lang) {
             if (file_exists(get_custom_file_base() . '/lang_custom/' . fallback_lang() . '/' . $occle_lang . '.ini') || file_exists(get_file_base() . '/lang/' . fallback_lang() . '/' . $occle_lang . '.ini')) {
                 require_lang($occle_lang, NULL, NULL, true);
             }
         }
         foreach ($occle_state_code_diff as $occle_code) {
             if (file_exists(get_file_base() . '/sources_custom/' . $occle_code . '.php') || file_exists(get_file_base() . '/sources/' . $occle_code . '.php')) {
                 require_code($occle_code);
             }
         }
         require_code('database_action');
         require_code('config2');
         global $SITE_DB, $FORUM_DB, $FORUM_DRIVER;
         $this->output[STREAM_STDERR] = '';
         @ini_set('ocproducts.xss_detect', '0');
         ob_start();
         if (!defined('HIPHOP_PHP') || @eval('return 1;') === 1) {
             $occle_eval_output = eval($this->parsed_input[SECTION_COMMAND]);
         } else {
             $occle_eval_output = '';
         }
         $occle_output = ob_get_contents();
         if ($occle_output == '' && $occle_eval_output !== false) {
             $occle_output = @strval($occle_eval_output);
         }
         ob_end_clean();
         $occle_env_neglect = array('SITE_DB', 'FORUM_DB', 'FORUM_DRIVER', 'GLOBALS', '_SERVER', '_COOKIE', '_GET', '_POST', '_ENV', '_FILES', '_REQUEST', '_SESSION', 'this', 'php_errormsg');
         $occle_env_after = get_defined_vars();
         $occle_env_changes = array_diff(array_keys($occle_env_after), $occle_env_neglect);
         $occle_state_diff = array();
         foreach ($occle_env_changes as $occle_change) {
             if (substr($occle_change, 0, 6) != 'occle_' && is_scalar($occle_env_after[$occle_change])) {
                 $occle_state_diff[$occle_change] = $occle_env_after[$occle_change];
             }
         }
         ocp_setcookie('occle_state', serialize($occle_state_diff));
         ocp_setcookie('occle_state_code', serialize(array_keys($GLOBALS['_REQUIRED_CODE'])));
         ocp_setcookie('occle_state_lang', serialize(array_keys($GLOBALS['LANGS_REQUESTED'])));
     } else {
         //Fake the PHP evaluation, because it's prohibited by a shared install
         $this->output[STREAM_STDERR] = do_lang('SHARED_INSTALL_PROHIBIT');
         $occle_eval_output = true;
     }
     $this->output[STREAM_STDCOMMAND] = '';
     $this->output[STREAM_STDHTML] = '';
     $this->output[STREAM_STDOUT] = '';
     if (is_object($occle_output)) {
         $this->output[STREAM_STDHTML] = $occle_output->evaluate();
     } elseif (is_array($occle_output)) {
         $this->output[STREAM_STDHTML] = $this->_array_to_html($occle_output);
     } else {
         $this->output[STREAM_STDOUT] = $occle_output;
     }
     if ($occle_eval_output === false) {
         $this->output[STREAM_STDERR] = do_lang('EVAL_ERROR');
     }
     if (is_null($occle_output)) {
         $this->output[STREAM_STDERR] = do_lang('NO_RESULTS');
     }
 }
 /**
  * Get a preview(s) of a (group of) template(s), as a full standalone piece of HTML in Tempcode format.
  * Uses sources/lorem.php functions to place appropriate stock-text. Should not hard-code things, as the code is intended to be declaritive.
  * Assumptions: You can assume all Lang/CSS/Javascript files in this addon have been pre-required.
  *
  * @return array			Array of previews, each is Tempcode. Normally we have just one preview, but occasionally it is good to test templates are flexible (e.g. if they use IF_EMPTY, we can test with and without blank data).
  */
 function tpl_preview__administrative__translate_screen()
 {
     require_lang('lang');
     $lines = '';
     foreach (placeholder_array() as $value) {
         $temp = do_lorem_template('TRANSLATE_LINE', array('TRANSLATE_AUTO' => $value, 'DESCRIPTION' => lorem_sentence(), 'NAME' => placeholder_random(), 'OLD' => str_replace('\\n', chr(10), $value), 'CURRENT' => $value, 'ACTIONS' => new ocp_tempcode()));
         $lines .= $temp->evaluate();
     }
     return array(lorem_globalise(do_lorem_template('TRANSLATE_SCREEN', array('PAGE' => lorem_phrase(), 'INTERTRANS' => lorem_phrase(), 'LANG' => fallback_lang(), 'LINES' => $lines, 'TITLE' => lorem_title(), 'URL' => placeholder_url())), NULL, '', true));
 }
Example #26
0
/**
 * Take the specified parameters, and try to find the corresponding page
 *
 * @param  ID_TEXT			The codename of the page to load
 * @param  ID_TEXT			The zone the page is being loaded in
 * @param  ?ID_TEXT			The type of page - for if you know it (NULL: don't know it)
 * @param  ?LANGUAGE_NAME	Language name (NULL: users language)
 * @param  boolean			Whether to not check for redirects (normally you would)
 * @return ~array				A list of details (false: page not found)
 */
function _request_page($codename, $zone, $page_type = NULL, $lang = NULL, $no_redirect_check = false)
{
    if ($lang === NULL) {
        $lang = user_lang();
    }
    if ($codename == 'login') {
        $login_zone = get_module_zone('login');
        $path = zone_black_magic_filterer($login_zone . ($login_zone == '' ? '' : '/') . 'pages/modules_custom/' . $codename . '.php', true);
        if (is_file(get_file_base() . '/' . $path)) {
            return array('MODULES_CUSTOM', $login_zone, $codename, $path);
        }
        $path = zone_black_magic_filterer($login_zone . ($login_zone == '' ? '' : '/') . 'pages/modules/' . $codename . '.php', true);
        if (is_file(get_file_base() . '/' . $path)) {
            return array('MODULES', $login_zone, $codename, $path);
        }
    }
    // Redirect
    if (!$no_redirect_check && addon_installed('redirects_editor')) {
        global $REDIRECT_CACHE;
        if (array_key_exists($zone, $REDIRECT_CACHE)) {
            $redirect = array_key_exists($codename, $REDIRECT_CACHE[$zone]) ? array($REDIRECT_CACHE[$zone][$codename]) : array();
        } else {
            $redirect = $GLOBALS['SITE_DB']->query_select('redirects', array('*'), array('r_from_zone' => $zone, 'r_from_page' => $codename), '', 1);
        }
        if (array_key_exists(0, $redirect)) {
            return array('REDIRECT', $redirect[0]);
        }
    }
    //If we know the page type
    if ($page_type !== NULL) {
        switch ($page_type) {
            case 'modules_custom':
                if (!in_safe_mode()) {
                    $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/modules_custom/' . $codename . '.php', true);
                    if (is_file(get_file_base() . '/' . $path)) {
                        return array('MODULES_CUSTOM', $zone, $codename, $path);
                    }
                }
                break;
            case 'modules':
                $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/modules/' . $codename . '.php', true);
                if (is_file(get_file_base() . '/' . $path)) {
                    return array('MODULES', $zone, $codename, $path);
                }
                break;
            case 'comcode_custom':
                if (!in_safe_mode()) {
                    if (get_param_integer('keep_theme_test', 0) == 1) {
                        $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang . '/' . $GLOBALS['FORUM_DRIVER']->get_theme() . '__' . $codename . '.txt', true);
                        if (is_file(get_custom_file_base() . '/' . $path)) {
                            return array('COMCODE_CUSTOM', $zone, $GLOBALS['FORUM_DRIVER']->get_theme() . '__' . $codename, $lang, $path);
                        }
                    }
                    $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang . '/' . $codename . '.txt', true);
                    if (is_file(get_custom_file_base() . '/' . $path)) {
                        return array('COMCODE_CUSTOM', $zone, $codename, $lang, $path);
                    }
                    if ($GLOBALS['CURRENT_SHARE_USER'] !== NULL) {
                        $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang . '/' . $codename . '.txt', true);
                        if (is_file(get_file_base() . '/' . $path)) {
                            return array('COMCODE_CUSTOM_PURE', $zone, $codename, $lang, $path);
                        }
                    }
                }
                //break;
            //break;
            case 'comcode':
                $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode/' . $lang . '/' . $codename . '.txt', true);
                if (is_file(get_file_base() . '/' . $path)) {
                    return array('COMCODE', $zone, $codename, $lang, $path);
                }
                break;
            case 'html_custom':
                if (!in_safe_mode()) {
                    $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/html_custom/' . $lang . '/' . $codename . '.htm', true);
                    if (is_file(get_custom_file_base() . '/' . $path)) {
                        return array('HTML_CUSTOM', $zone, $codename, $lang, $path);
                    }
                }
                break;
            case 'html':
                $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/html/' . $lang . '/' . $codename . '.htm', true);
                if (is_file(get_file_base() . '/' . $path)) {
                    return array('HTML', $zone, $codename, $lang, $path);
                }
                break;
            case 'minimodules_custom':
                if (!in_safe_mode()) {
                    $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/minimodules_custom/' . $lang . '/' . $codename . '.php', true);
                    if (is_file(get_file_base() . '/' . $path)) {
                        return array('MINIMODULES_CUSTOM', $zone, $codename, $path);
                    }
                }
                break;
            case 'minimodules':
                $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/minimodules/' . $lang . '/' . $codename . '.php', true);
                if (is_file(get_file_base() . '/' . $path)) {
                    return array('MINIMODULES', $zone, $codename, $path);
                }
                break;
        }
        return false;
    }
    // We have a priority list to find our page
    if (!in_safe_mode()) {
        $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/modules_custom/' . $codename . '.php', true);
        if (is_file(get_file_base() . '/' . $path)) {
            return array('MODULES_CUSTOM', $zone, $codename, $path);
        }
    }
    $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/modules/' . $codename . '.php', true);
    if (is_file(get_file_base() . '/' . $path)) {
        return array('MODULES', $zone, $codename, $path);
    }
    if (!in_safe_mode()) {
        if (get_param_integer('keep_theme_test', 0) == 1) {
            $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang . '/' . $GLOBALS['FORUM_DRIVER']->get_theme() . '__' . $codename . '.txt', true);
            if (is_file(get_custom_file_base() . '/' . $path)) {
                return array('COMCODE_CUSTOM', $zone, $GLOBALS['FORUM_DRIVER']->get_theme() . '__' . $codename, $lang, $path);
            }
        }
        $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang . '/' . $codename . '.txt', true);
        if (is_file(get_custom_file_base() . '/' . $path)) {
            return array('COMCODE_CUSTOM', $zone, $codename, $lang, $path);
        }
        if ($GLOBALS['CURRENT_SHARE_USER'] !== NULL) {
            $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang . '/' . $codename . '.txt', true);
            if (is_file(get_file_base() . '/' . $path)) {
                return array('COMCODE_CUSTOM_PURE', $zone, $codename, $lang, $path);
            }
        }
    }
    $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode/' . $lang . '/' . $codename . '.txt', true);
    if (is_file(get_file_base() . '/' . $path)) {
        return array('COMCODE', $zone, $codename, $lang, $path);
    }
    if (!in_safe_mode()) {
        $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/html_custom/' . $lang . '/' . $codename . '.htm', true);
        if (is_file(get_custom_file_base() . '/' . $path)) {
            return array('HTML_CUSTOM', $zone, $codename, $lang, $path);
        }
    }
    $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/html/' . $lang . '/' . $codename . '.htm', true);
    if (is_file(get_file_base() . '/' . $path)) {
        return array('HTML', $zone, $codename, $lang, $path);
    }
    if (!in_safe_mode()) {
        $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/minimodules_custom/' . $codename . '.php', true);
        if (is_file(get_file_base() . '/' . $path)) {
            return array('MINIMODULES_CUSTOM', $zone, $codename, $path);
        }
    }
    $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/minimodules/' . $codename . '.php', true);
    if (is_file(get_file_base() . '/' . $path)) {
        return array('MINIMODULES', $zone, $codename, $path);
    }
    // As a last resort, consider it might not yet have been translated
    $fallback_lang = fallback_lang();
    $site_lang = get_site_default_lang();
    $langs_to_try = array();
    if ($lang != $site_lang) {
        $langs_to_try[] = $site_lang;
    }
    if ($lang != $fallback_lang) {
        $langs_to_try[] = $fallback_lang;
    }
    foreach ($langs_to_try as $fallback_lang) {
        if (!in_safe_mode()) {
            $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $fallback_lang . '/' . $codename . '.txt', true);
            if (is_file(get_custom_file_base() . '/' . $path)) {
                return array('COMCODE_CUSTOM', $zone, $codename, $fallback_lang, $path);
            }
            if ($GLOBALS['CURRENT_SHARE_USER'] !== NULL) {
                $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $fallback_lang . '/' . $codename . '.txt', true);
                if (is_file(get_file_base() . '/' . $path)) {
                    return array('COMCODE_CUSTOM_PURE', $zone, $codename, $fallback_lang, $path);
                }
            }
        }
        $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/comcode/' . $fallback_lang . '/' . $codename . '.txt', true);
        if (is_file(get_file_base() . '/' . $path)) {
            return array('COMCODE', $zone, $codename, $fallback_lang, $path);
        }
        if (!in_safe_mode()) {
            $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/html_custom/' . $fallback_lang . '/' . $codename . '.htm', true);
            if (is_file(get_custom_file_base() . '/' . $path)) {
                return array('HTML_CUSTOM', $zone, $codename, $fallback_lang, $path);
            }
        }
        $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/html/' . $fallback_lang . '/' . $codename . '.htm', true);
        if (is_file(get_file_base() . '/' . $path)) {
            return array('HTML', $zone, $codename, $fallback_lang, $path);
        }
    }
    return false;
}
 /**
  * Get a preview(s) of a (group of) template(s), as a full standalone piece of HTML in Tempcode format.
  * Uses sources/lorem.php functions to place appropriate stock-text. Should not hard-code things, as the code is intended to be declaritive.
  * Assumptions: You can assume all Lang/CSS/Javascript files in this addon have been pre-required.
  *
  * @return array			Array of previews, each is Tempcode. Normally we have just one preview, but occasionally it is good to test templates are flexible (e.g. if they use IF_EMPTY, we can test with and without blank data).
  */
 function tpl_preview__mail()
 {
     return array(lorem_globalise(do_lorem_template('MAIL', array('CSS' => '', 'LOGOURL' => placeholder_image_url(), 'LOGOMAP' => '', 'LANG' => fallback_lang(), 'TITLE' => lorem_phrase(), 'CONTENT' => lorem_paragraph())), NULL, '', true));
 }
Example #28
0
/**
 * Make a theme. Note that this will trigger the AFM.
 *
 * @param  string		Name of the theme.
 * @param  ID_TEXT	The theme it's being generated from
 * @param  ID_TEXT	The algorithm to use
 * @set equations hsv
 * @param  string		Seed colour to use.
 * @param  boolean	Whether to use the theme immediately.
 * @param  ?boolean  Whether it will be a dark theme (NULL: autodetect).
 * @param  boolean	Whether to inherit the CSS, for easier theme upgrading.
 */
function make_theme($themename, $source_theme, $algorithm, $seed, $use, $dark = false, $inherit_css = false)
{
    $GLOBALS['NO_QUERY_LIMIT'] = true;
    load_themewizard_params_from_theme($source_theme, $algorithm == 'hsv');
    if (file_exists(get_custom_file_base() . '/themes/' . $themename)) {
        require_code('abstract_file_manager');
        force_have_afm_details();
        $extending_existing = true;
    } else {
        if ($source_theme == 'default') {
            actual_add_theme($themename);
        } else {
            require_code('themes3');
            actual_copy_theme($source_theme, $themename);
        }
        $extending_existing = false;
    }
    if ($seed != find_theme_seed($source_theme) || $dark != find_theme_dark($source_theme)) {
        list($colours, $landscape) = calculate_theme($seed, $source_theme, $algorithm, 'colours', $dark);
        // Make images
        global $THEME_WIZARD_IMAGES, $THEME_WIZARD_IMAGES_NO_WILD, $IMG_CODES;
        if (function_exists('imagecolorallocatealpha')) {
            require_code('themes2');
            $full_img_set = array();
            foreach ($THEME_WIZARD_IMAGES as $expression) {
                if (substr($expression, -1) == '*') {
                    $expression = substr($expression, 0, strlen($expression) - 2);
                    // remove "/*"
                    $full_img_set = array_merge($full_img_set, array_keys(get_all_image_codes(get_file_base() . '/themes/' . filter_naughty($source_theme) . '/images', $expression)));
                    $full_img_set = array_merge($full_img_set, array_keys(get_all_image_codes(get_file_base() . '/themes/' . filter_naughty($source_theme) . '/images/' . fallback_lang(), $expression)));
                } else {
                    $full_img_set[] = $expression;
                }
            }
            if ($extending_existing) {
                $temp_all_ids = collapse_2d_complexity('id', 'path', $GLOBALS['SITE_DB']->query_select('theme_images', array('id', 'path'), array('theme' => $themename)));
            } else {
                $temp_all_ids = array();
            }
            $_langs = find_all_langs(true);
            foreach ($full_img_set as $image_code) {
                if (!in_array($image_code, $THEME_WIZARD_IMAGES_NO_WILD)) {
                    if ($extending_existing && array_key_exists($image_code, $temp_all_ids) && strpos($temp_all_ids[$image_code], $themename . '/images_custom/') !== false && (!url_is_local($temp_all_ids[$image_code]) || file_exists(get_custom_file_base() . '/' . $temp_all_ids[$image_code]))) {
                        continue;
                    }
                    foreach (array_keys($_langs) as $lang) {
                        $orig_path = find_theme_image($image_code, true, true, $source_theme, $lang);
                        if ($orig_path == '') {
                            continue;
                        }
                        // Theme has specified non-existent image as themewizard-compatible
                        if (strpos($orig_path, '/' . $lang . '/') === false && $lang != fallback_lang()) {
                            continue;
                        }
                        if (strpos($orig_path, '/' . fallback_lang() . '/') !== false) {
                            $composite = 'themes/' . filter_naughty($themename) . '/images/' . $lang . '/';
                        } else {
                            $composite = 'themes/' . filter_naughty($themename) . '/images/';
                        }
                        $saveat = get_custom_file_base() . '/' . $composite . $image_code . '.png';
                        $saveat_url = $composite . $image_code . '.png';
                        // Wipe out ones that might have been copied from source theme
                        if ($source_theme != 'default' && strpos($orig_path, 'images_custom') !== false) {
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.png');
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.jpg');
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.gif');
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.jpeg');
                        }
                        if (!file_exists($saveat) || $source_theme != 'default' || $algorithm == 'hsv') {
                            $image = calculate_theme($seed, $source_theme, $algorithm, $image_code, $dark, $colours, $landscape, $lang);
                            if (!is_null($image)) {
                                $pos = strpos($image_code, '/');
                                if ($pos !== false || strpos($orig_path, '/' . fallback_lang() . '/') !== false) {
                                    afm_make_directory($composite . substr($image_code, 0, $pos), true, true);
                                }
                                @imagepng($image, $saveat) or intelligent_write_error($saveat);
                                imagedestroy($image);
                                fix_permissions($saveat);
                                sync_file($saveat);
                                actual_edit_theme_image($image_code, $themename, $lang, $image_code, $saveat_url, true);
                                //if ($lang==fallback_lang()) $IMG_CODES['site'][$image_code]=$saveat_url;
                            }
                        } else {
                            actual_edit_theme_image($image_code, $themename, $lang, $image_code, $saveat_url, true);
                        }
                    }
                }
            }
        }
        // Make sheets
        $dh = opendir(get_file_base() . '/themes/' . filter_naughty($source_theme) . ($source_theme == 'default' ? '/css/' : '/css_custom/'));
        while (($sheet = readdir($dh)) !== false) {
            if (substr($sheet, -4) == '.css') {
                $saveat = get_custom_file_base() . '/themes/' . filter_naughty($themename) . '/css_custom/' . $sheet;
                if (!file_exists($saveat) || $source_theme != 'default' || $algorithm == 'hsv') {
                    $fp = @fopen($saveat, 'wt') or intelligent_write_error(get_custom_file_base() . '/themes/' . filter_naughty($themename) . '/css_custom/' . $sheet);
                    if ($inherit_css) {
                        $output = '{+START,CSS_INHERIT,' . basename($sheet, '.css') . ',' . filter_naughty($source_theme) . ',' . $seed . ',' . ($dark ? '1' : '0') . ',' . $algorithm . '}{+END}';
                    } else {
                        $output = theme_wizard_colours_to_sheet($sheet, $landscape, $source_theme, $algorithm, $seed);
                    }
                    if (fwrite($fp, $output) < strlen($output)) {
                        warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                    }
                    fclose($fp);
                    fix_permissions($saveat);
                    sync_file($saveat);
                    if (!$inherit_css) {
                        $c_success = @copy(get_file_base() . '/themes/' . filter_naughty($source_theme) . '/css/' . $sheet, $saveat . '.editfrom');
                        if ($c_success !== false) {
                            fix_permissions($saveat . '.editfrom');
                            sync_file($saveat . '.editfrom');
                        }
                    } else {
                        @unlink($saveat . '.editfrom');
                    }
                }
            }
        }
    }
    // Use it, if requested
    if ($use) {
        $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'zones SET zone_theme=\'' . db_escape_string($themename) . '\' WHERE ' . db_string_not_equal_to('zone_name', 'cms') . ' AND ' . db_string_not_equal_to('zone_name', 'adminzone'));
        $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
        $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
        $GLOBALS['SITE_DB']->query_delete('group_category_access', array('module_the_name' => 'theme', 'category_name' => $themename));
        foreach (array_keys($groups) as $group_id) {
            if (in_array($group_id, $admin_groups)) {
                continue;
            }
            $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'theme', 'category_name' => $themename, 'group_id' => $group_id));
        }
        persistant_cache_empty();
    }
}
Example #29
0
 /**
  * Get the site's default language, with support for URL overrides.
  *
  * @return LANGUAGE_NAME  The site's default language
  */
 function get_site_default_lang()
 {
     // Site default then
     global $SITE_INFO;
     if (!array_key_exists('default_lang', $SITE_INFO)) {
         global $IN_MINIKERNEL_VERSION;
         if ($IN_MINIKERNEL_VERSION == 1) {
             if (array_key_exists('lang', $_POST)) {
                 return $_POST['lang'];
             }
             if (array_key_exists('lang', $_GET)) {
                 return $_GET['lang'];
             }
         }
         return fallback_lang();
     }
     return $SITE_INFO['default_lang'];
 }
Example #30
0
/**
 * Find the zone a page is in.
 *
 * @param  ID_TEXT		The page name to find
 * @param  boolean		Whether ocPortal should bomb out if the page was not found
 * @return ?ID_TEXT		The zone the page is in (NULL: missing)
 */
function get_page_zone($page_name, $error = true)
{
    $test = get_module_zone($page_name, 'modules', NULL, 'php', false);
    if (!is_null($test)) {
        return $test;
    }
    $test = get_module_zone($page_name, 'comcode', get_site_default_lang(), 'txt', false);
    if (!is_null($test)) {
        return $test;
    }
    $test = get_module_zone($page_name, 'comcode', fallback_lang(), 'txt', false);
    if (!is_null($test)) {
        return $test;
    }
    $test = get_module_zone($page_name, 'html', get_site_default_lang(), 'htm', false);
    if (!is_null($test)) {
        return $test;
    }
    $test = get_module_zone($page_name, 'html', fallback_lang(), 'htm', false);
    if (!is_null($test)) {
        return $test;
    }
    $test = get_module_zone($page_name, 'minimodules', NULL, 'php', false);
    if (!is_null($test)) {
        return $test;
    }
    if ($error) {
        warn_exit(do_lang_tempcode('MISSING_MODULE_REFERENCED', $page_name));
    }
    return NULL;
}