Exemplo n.º 1
0
/**
 * Get information about new versions of ocPortal (or more accurately, what's wrong with this version).
 *
 * @return tempcode		Information about the installed ocPortal version
 */
function get_future_version_information()
{
    require_lang('version');
    $url = 'http://ocportal.com/version.php?version=' . rawurlencode(ocp_version_full()) . '&lang=' . rawurlencode(user_lang());
    $data = http_download_file($url, NULL, false);
    if (!is_null($data)) {
        $data = str_replace('"../upgrader.php"', '"' . get_base_url() . '/upgrader.php"', $data);
        if ($GLOBALS['XSS_DETECT']) {
            ocp_mark_as_escaped($data);
        }
        require_code('character_sets');
        $data = convert_to_internal_encoding($data);
        $table = new ocp_tempcode();
        $lines = explode(chr(10), $data);
        foreach ($lines as $line) {
            if (trim($line) != '') {
                $table->attach(paragraph($line));
            }
        }
        $table = make_string_tempcode(preg_replace('#<p>\\s*</p>#', '', $table->evaluate()));
    } else {
        $table = paragraph(do_lang_tempcode('CANNOT_CONNECT_HOME'), 'dfsdff32ffd');
    }
    require_code('xhtml');
    /*$table->attach('<script type="text/javascript">// <![CDATA[
    		window.open(\''.$url.'\');
    	//]]></script>');*/
    return make_string_tempcode(xhtmlise_html($table->evaluate()));
}
Exemplo n.º 2
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     unset($map);
     require_lang('version');
     require_code('version2');
     require_css('adminzone');
     $table = get_future_version_information();
     return do_template('BLOCK_MAIN_STAFF_NEW_VERSION', array('_GUID' => '43c7b18d3d44e825247579df23a2ad9c', 'VERSION' => ocp_version_full(), 'VERSION_TABLE' => $table));
 }
Exemplo n.º 3
0
 /**
  * Standard modular run function for OcCLE hooks.
  *
  * @param  array	The options with which the command was called
  * @param  array	The parameters with which the command was called
  * @param  array	A reference to the OcCLE filesystem object
  * @return array	Array of stdcommand, stdhtml, stdout, and stderr responses
  */
 function run($options, $parameters, &$occle_fs)
 {
     require_code('version');
     require_code('version2');
     require_lang('version');
     if (array_key_exists('h', $options) || array_key_exists('help', $options)) {
         return array('', do_command_help('version', array('h', 'f', 't', 'v', 'm'), array()), '', '');
     } elseif (array_key_exists('f', $options) || array_key_exists('future', $options)) {
         return array('', get_future_version_information(), '', '');
     } elseif (array_key_exists('t', $options) || array_key_exists('time', $options)) {
         return array('', '', ocp_version_time(), '');
     } elseif ((array_key_exists('v', $options) || array_key_exists('major-version', $options)) && (!array_key_exists('m', $options) && !array_key_exists('minor-version', $options))) {
         return array('', '', ocp_version(), '');
     } elseif ((array_key_exists('m', $options) || array_key_exists('minor-version', $options)) && (!array_key_exists('v', $options) && !array_key_exists('major-version', $options))) {
         return array('', '', ocp_version_minor(), '');
     } elseif ((array_key_exists('g', $options) || array_key_exists('general-version', $options)) && (!array_key_exists('v', $options) && !array_key_exists('major-version', $options))) {
         return array('', '', ocp_version_number(), '');
     } else {
         return array('', '', ocp_version_full(), '');
     }
 }
Exemplo n.º 4
0
    /**
     * The actualiser to create a .po TAR.
     *
     * @return tempcode		The UI
     */
    function export_po()
    {
        $lang = filter_naughty(get_param('id'));
        // Send header
        header('Content-Type: application/octet-stream' . '; authoritative=true;');
        if (strstr(ocp_srv('HTTP_USER_AGENT'), 'MSIE') !== false) {
            header('Content-Disposition: filename="ocportal-' . $lang . '.tar"');
        } else {
            header('Content-Disposition: attachment; filename="ocportal-' . $lang . '.tar"');
        }
        require_code('tar');
        require_code('lang_compile');
        require_code('character_sets');
        $tempfile = ocp_tempnam('po');
        $tar = tar_open($tempfile, 'wb');
        $dh = @opendir(get_custom_file_base() . '/lang_custom/' . $lang);
        if ($dh !== false) {
            $charset = do_lang('charset', NULL, NULL, NULL, $lang);
            $english_charset = do_lang('charset', NULL, NULL, NULL, fallback_lang());
            while (($f = readdir($dh)) !== false) {
                if (substr($f, -4) == '.ini') {
                    $path = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $f;
                    $entries = array();
                    _get_lang_file_map($path, $entries, false, false);
                    $mtime = filemtime($path);
                    $data = '
msgid ""
msgstr ""
"Project-Id-Version: ocportal\\n"
"PO-Revision-Date: ' . gmdate('Y-m-d H:i', $mtime) . '+0000\\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
"Language-Team: FULL NAME <EMAIL@ADDRESS>\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"X-ocPortal-Export-Date: ' . gmdate('Y-m-d H:i', $mtime) . '+0000\\n"
"X-Generator: ocPortal (' . ocp_version_full() . ')\\n"

';
                    $entries2 = array();
                    $en_seen_before = array();
                    foreach ($entries as $key => $val) {
                        $english = do_lang($key, NULL, NULL, NULL, fallback_lang(), false);
                        if (is_null($english)) {
                            continue;
                        }
                        if ($english == '') {
                            continue;
                        }
                        $val = convert_to_internal_encoding($val, $charset, 'utf-8');
                        $val = str_replace(chr(10), '\\n', $val);
                        $english = convert_to_internal_encoding($english, $english_charset, 'utf-8');
                        $english = str_replace(chr(10), '\\n', $english);
                        $seen_before = false;
                        if (isset($en_seen_before[$val])) {
                            $seen_before = true;
                            foreach ($entries2 as $_key => $_val) {
                                if ($entries2[$_key][2] == $val) {
                                    $entries2[$_key][1] = true;
                                }
                            }
                        }
                        $entries2[$key] = array($val, $seen_before, $english);
                        $en_seen_before[$val] = 1;
                    }
                    require_code('support2');
                    foreach ($entries2 as $key => $_val) {
                        list($val, $seen_before, $english) = $_val;
                        $data .= '#: [strings]' . $key . chr(10);
                        if ($seen_before) {
                            $data .= 'msgctxt "[strings]' . $key . '"' . chr(10);
                        }
                        $wrapped = preg_replace('#"\\n"$#', '', ocp_mb_chunk_split(str_replace('"', '\\"', $english), 76, '"' . chr(10) . '"'));
                        if (strpos($wrapped, chr(10)) !== false) {
                            $data .= 'msgid ""' . chr(10) . '"' . $wrapped . '"' . chr(10);
                        } else {
                            $data .= 'msgid "' . $wrapped . '"' . chr(10);
                        }
                        $wrapped = preg_replace('#"\\n"$#', '', ocp_mb_chunk_split(str_replace('"', '\\"', $val), 76, '"' . chr(10) . '"'));
                        if (strpos($wrapped, chr(10)) !== false) {
                            $data .= 'msgstr ""' . chr(10) . '"' . $wrapped . '"' . chr(10);
                        } else {
                            $data .= 'msgstr "' . $wrapped . '"' . chr(10);
                        }
                        $data .= chr(10);
                    }
                    tar_add_file($tar, basename($f, '.ini') . '/' . basename($f, '.ini') . '-' . strtolower($lang) . '.po', $data, 0666, $mtime);
                }
            }
        }
        tar_close($tar);
        readfile($tempfile);
        @unlink($tempfile);
        $GLOBALS['SCREEN_TEMPLATE_CALLED'] = '';
        exit;
        return new ocp_tempcode();
        // For code quality checker
    }
Exemplo n.º 5
0
/**
 * Handle RSS/Atom output.
 */
function backend_script()
{
    // Closed site
    $site_closed = get_option('site_closed');
    if ($site_closed == '1' && !has_specific_permission(get_member(), 'access_closed_site') && get_ip_address() != ocp_srv('SERVER_ADDR') && !$GLOBALS['IS_ACTUALLY_ADMIN']) {
        header('Content-Type: text/plain');
        @exit(get_option('closed'));
    }
    if (get_option('is_on_rss') == '0') {
        return;
    }
    $type = get_param('type', 'RSS2');
    $mode = get_param('mode', 'opml');
    require_lang('rss');
    if ($type == 'xslt-rss') {
        // Feed stylesheet for RSS
        header('Content-Type: text/xsl');
        require_css('rss');
        $js = get_custom_base_url() . substr(javascript_enforce('JAVASCRIPT_XSL_MOPUP'), strlen(get_custom_file_base()));
        $echo = do_template('RSS_XSLT', array('_GUID' => 'c443e0195c935117cf0d9a7bc2730d7a', 'JAVASCRIPT_XSL_MOPUP' => $js));
        $echo->evaluate_echo();
        return;
    }
    if ($type == 'xslt-atom') {
        // Feed stylesheet for Atom
        header('Content-Type: text/xsl');
        require_css('rss');
        $js = get_custom_base_url() . substr(javascript_enforce('JAVASCRIPT_XSL_MOPUP'), strlen(get_custom_file_base()));
        $echo = do_template('ATOM_XSLT', array('_GUID' => '27fec456a6b3144aa847130e74463d99', 'JAVASCRIPT_XSL_MOPUP' => $js));
        $echo->evaluate_echo();
        return;
    }
    if ($type == 'xslt-opml') {
        // Feed stylesheet for Atom
        header('Content-Type: text/xsl');
        require_css('rss');
        $js = get_custom_base_url() . substr(javascript_enforce('JAVASCRIPT_XSL_MOPUP'), strlen(get_custom_file_base()));
        $echo = do_template('OPML_XSLT', array('_GUID' => 'c0c6bd1d7a0e263768a2208061f799f5', 'JAVASCRIPT_XSL_MOPUP' => $js));
        $echo->evaluate_echo();
        return;
    }
    $type = strtoupper($type);
    if ($type != 'RSS2' && $type != 'ATOM') {
        $type = 'RSS2';
    }
    if ($type == 'RSS2') {
        $prefix = 'RSS_';
    } else {
        $prefix = 'ATOM_';
    }
    /*if (get_param_integer('force_text',0)==0)
    	{
    		if ($type=='atom') header('Content-Type: text/xml+atom; charset='.get_charset());
    		else header('Content-Type: text/xml');
    	}
    	header('Content-Disposition: inline');*/
    if ($type == 'RSS2') {
        $date_string = 'r';
    } else {
        $offset_seconds = intval(date('Z'));
        $offset_minutes = abs(intval(round(floatval($offset_seconds) / 60.0)));
        $offset_hours = intval(round(floatval($offset_minutes) / 60.0));
        $offset_minutes -= $offset_hours * 60;
        $offset = sprintf('%02d:%02d', $offset_hours, $offset_minutes);
        $date_string = 'Y-m-d\\TH:i:s';
        if ($offset_seconds >= 0) {
            $date_string .= '+';
        } else {
            $date_string .= '-';
        }
        for ($i = 0; $i < strlen($offset); $i++) {
            $date_string .= '\\' . $offset[$i];
        }
    }
    $date = date($date_string);
    $site_about = xmlentities(get_option('description'));
    $logo_url = xmlentities(find_theme_image('logo/trimmed-logo'));
    $copyright = xmlentities(trim(str_replace('&copy;', '', str_replace('$CURRENT_YEAR', date('Y'), get_option('copyright')))));
    $cutoff = get_param_integer('cutoff', time() - 60 * 60 * 24 * get_param_integer('days', 30));
    $max = get_param_integer('max', 100);
    $filter = get_param('filter', '*');
    if ($filter == '') {
        $filter = '*';
    }
    if ($mode == 'opml') {
        header('Content-Type: text/xml');
        $_feeds = find_all_hooks('systems', 'rss');
        $feeds = array();
        foreach (array_keys($_feeds) as $feed) {
            if (get_forum_type() != 'ocf' && substr($feed, 0, 4) == 'ocf_') {
                continue;
            }
            $feed_title = ucwords(str_replace('_', ' ', $feed));
            // Try and get a better feed title
            require_code('hooks/systems/rss/' . filter_naughty_harsh($feed), true);
            $object = object_factory('Hook_rss_' . $feed);
            require_code('ocfiltering');
            $_content = $object->run('', time(), 'ATOM_', '', 0);
            if (is_array($_content)) {
                list(, $feed_title) = $_content;
            }
            $feeds[] = array('MODE' => $feed, 'TITLE' => $feed_title);
        }
        $echo = do_template('OPML_WRAPPER', array('_GUID' => '712b78d1b4c23aefc8a92603477f84ed', 'FEEDS' => $feeds, 'ABOUT' => $site_about, 'DATE' => $date));
        $echo->evaluate_echo();
        return;
    }
    require_code('hooks/systems/rss/' . filter_naughty_harsh($mode), true);
    $object = object_factory('Hook_rss_' . $mode);
    require_code('ocfiltering');
    $_content = $object->run($filter, $cutoff, $prefix, $date_string, $max);
    $mode_nice = $mode;
    if (is_array($_content)) {
        list($content, $mode_nice) = $_content;
    } else {
        $content = is_null($_content) ? array() : $_content;
    }
    if ($type == 'RSS2' && function_exists('xmlrpc_encode')) {
        // Change a full url into constituent parts
        $base_url = get_base_url();
        $port = 80;
        $end_protocol_pos = strpos($base_url, '://');
        $colon_pos = strpos($base_url, ':', $end_protocol_pos + 1);
        if ($colon_pos !== false) {
            $after_port_pos = strpos($base_url, '/', $colon_pos);
            if ($after_port_pos === false) {
                $after_port_pos = strlen($base_url);
            }
            $port = intval(substr($base_url, $colon_pos, $after_port_pos - $colon_pos));
        }
        $start_path_pos = strpos($base_url, '/', $end_protocol_pos + 4);
        if ($start_path_pos !== false) {
            $local_base_url = substr($base_url, $start_path_pos);
        } else {
            $local_base_url = '';
        }
        $rss_cloud = do_template('RSS_CLOUD', array('_GUID' => 'a47c40a4c137ea1e5abfc71346547313', 'TYPE' => $type == 'news' ? '' : $type, 'PORT' => strval($port), 'LOCAL_BASE_URL' => $local_base_url));
    } else {
        $rss_cloud = new ocp_tempcode();
    }
    // Firefox (and probably other browsers, but I didn't test) doesn't want to display Atom feeds inline if they're sent as text/xml+atom, even if the Content-Disposition is sent to inline :(
    header('Content-Type: text/xml');
    // application/rss+xml ?
    $echo = do_template($prefix . 'WRAPPER', array('FILTER' => $filter, 'CUTOFF' => strval($cutoff), 'MODE' => $mode, 'MODE_NICE' => $mode_nice, 'RSS_CLOUD' => $rss_cloud, 'VERSION' => ocp_version_full(), 'COPYRIGHT' => $copyright, 'DATE' => $date, 'LOGO_URL' => $logo_url, 'ABOUT' => $site_about, 'CONTENT' => $content));
    $echo->evaluate_echo();
}
Exemplo n.º 6
0
/**
 * This is it - the start of rendering of a website page.
 * Take in all inputs, sends them to the correct functions to process, gathers up all the outputs, sticks them together and echoes them.
 */
function do_site()
{
    // More SEO redirection (monikers)
    // Does this URL arrangement support monikers?
    $url_id = get_param('id', NULL, true);
    if ($url_id !== NULL && url_monikers_enabled()) {
        $type = get_param('type', 'misc');
        $looking_for = '_SEARCH:' . get_page_name() . ':' . $type . ':_WILD';
        $hooks = find_all_hooks('systems', 'content_meta_aware');
        $ob_info = NULL;
        foreach (array_keys($hooks) as $hook) {
            require_code('hooks/systems/content_meta_aware/' . filter_naughty($hook));
            $ob = object_factory('Hook_content_meta_aware_' . $hook, true);
            if ($ob === NULL) {
                continue;
            }
            $ob_info = $ob->info();
            $ob_info['view_pagelink_pattern'] = preg_replace('#:[^:]*$#', ':_WILD', $ob_info['view_pagelink_pattern']);
            if ($ob_info['view_pagelink_pattern'] == $looking_for && $ob_info['support_url_monikers']) {
                if (is_numeric($url_id)) {
                    $correct_moniker = find_id_moniker(array('page' => get_page_name(), 'type' => get_param('type', 'misc'), 'id' => $url_id));
                    if ($correct_moniker !== NULL && $correct_moniker != $url_id && count($_POST) == 0) {
                        header('HTTP/1.0 301 Moved Permanently');
                        $_new_url = build_url(array('page' => '_SELF', 'id' => $correct_moniker), '_SELF', NULL, true);
                        $new_url = $_new_url->evaluate();
                        header('Location: ' . $new_url);
                        exit;
                    }
                } else {
                    // See if it is deprecated
                    if (strpos(get_db_type(), 'mysql') !== false) {
                        $monikers = $GLOBALS['SITE_DB']->query_select('url_id_monikers USE INDEX (uim_moniker)', array('m_resource_id', 'm_deprecated'), array('m_resource_page' => get_page_name(), 'm_resource_type' => get_param('type', 'misc'), 'm_moniker' => $url_id));
                    } else {
                        $monikers = $GLOBALS['SITE_DB']->query_select('url_id_monikers', array('m_resource_id', 'm_deprecated'), array('m_resource_page' => get_page_name(), 'm_resource_type' => get_param('type', 'misc'), 'm_moniker' => $url_id));
                    }
                    if (!array_key_exists(0, $monikers)) {
                        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
                    }
                    $deprecated = $monikers[0]['m_deprecated'] == 1;
                    if ($deprecated && count($_POST) == 0) {
                        $correct_moniker = find_id_moniker(array('page' => get_page_name(), 'type' => get_param('type', 'misc'), 'id' => $monikers[0]['m_resource_id']));
                        header('HTTP/1.0 301 Moved Permanently');
                        $_new_url = build_url(array('page' => '_SELF', 'id' => $correct_moniker), '_SELF', NULL, true);
                        $new_url = $_new_url->evaluate();
                        header('Location: ' . $new_url);
                        exit;
                    } else {
                        $_GET['id'] = $monikers[0]['m_resource_id'];
                        // We need to know the ID number rather than the moniker
                    }
                }
                break;
            }
        }
    }
    // Any messages to output?
    if (get_param_integer('redirected', 0) == 1) {
        $messages = $GLOBALS['SITE_DB']->query_select('messages_to_render', array('r_message', 'r_type'), array('r_session_id' => get_session_id()), 'ORDER BY r_time DESC');
        foreach ($messages as $message) {
            if ($GLOBALS['XSS_DETECT']) {
                ocp_mark_as_escaped($message['r_message']);
            }
            attach_message(protect_from_escaping($message['r_message']), $message['r_type']);
        }
        if (count($messages) != 0) {
            $GLOBALS['SITE_DB']->query('DELETE FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'messages_to_render WHERE r_session_id=' . strval((int) get_session_id()) . ' OR r_time<' . strval(time() - 60 * 60));
        }
    }
    if (in_safe_mode()) {
        $disable_safe_mode_url = get_self_url(true, true, array('keep_safe_mode' => NULL));
        attach_message(do_lang_tempcode('CURRENTLY_HAS_KEEP_SAFE_MODE', escape_html($disable_safe_mode_url)), 'notice');
    }
    if (get_param_integer('keep_fatalistic', 0) == 1) {
        $disable_fatalistic_url = get_self_url(true, true, array('keep_fatalistic' => NULL));
        attach_message(do_lang_tempcode('CURRENTLY_HAS_KEEP_FATALISTIC', escape_html($disable_fatalistic_url)), 'notice');
    }
    $special_page_type = get_param('special_page_type', 'view');
    global $ZONE;
    $keep_markers = get_param_integer('keep_markers', 0);
    $show_edit_links = get_param_integer('show_edit_links', 0);
    global $KEEP_MARKERS, $SHOW_EDIT_LINKS;
    $KEEP_MARKERS = $keep_markers == 1 || $special_page_type == 'show_markers';
    if ($KEEP_MARKERS && !headers_sent()) {
        header('Content-type: text/html; charset=' . get_charset());
    }
    $SHOW_EDIT_LINKS = $show_edit_links == 1 || $special_page_type == 'show_edit_links';
    $out_evaluated = NULL;
    if ($special_page_type != 'view' && $special_page_type != 'show_markers') {
        require_code('view_modes');
        initialise_special_page_types($special_page_type);
    }
    // Set up Xdebug profiling
    if ($special_page_type == 'profile') {
        if (function_exists('xdebug_start_profiling')) {
            xdebug_start_profiling();
        }
        // xdebug 1 style
        if (ini_get('xdebug.profiler_enable') != '1') {
            attach_message(escape_html('Profiling must be enabled in php.ini'), 'warn');
        }
        // xdebug 2 style
        if (!is_writable_wrap(ini_get('xdebug.profiler_output_dir'))) {
            attach_message(escape_html('xdebug.profiler_output_dir needs setting to a writable directory'), 'warn');
        }
    }
    // Allow the site to be closed
    $site_closed = get_option('site_closed');
    if ($site_closed == '1' && !has_specific_permission(get_member(), 'access_closed_site') && !$GLOBALS['IS_ACTUALLY_ADMIN']) {
        require_code('site2');
        closed_site();
    }
    // Work out which page we're viewing
    global $PAGE;
    $PAGE = get_page_name();
    $doing_special_page_type = $special_page_type != 'view' && $special_page_type != 'show_markers' && $special_page_type != 'show_edit_links' && $special_page_type != 'memory' && (has_specific_permission(get_member(), 'view_profiling_modes') || $GLOBALS['IS_ACTUALLY_ADMIN']);
    // Load up our frames into strings. Note that the header and the footer are fixed already.
    $middle = request_page($PAGE, true);
    global $CYCLES;
    $CYCLES = array();
    // Here we reset some Tempcode environmental stuff, because template compilation or preprocessing may have dirtied things
    if ($middle === NULL || $middle->is_definitely_empty()) {
        $GLOBALS['HTTP_STATUS_CODE'] = '404';
        if (!headers_sent()) {
            if (!browser_matches('ie') && strpos(ocp_srv('SERVER_SOFTWARE'), 'IIS') === false) {
                header('HTTP/1.0 404 Not Found');
            }
        }
        $title = get_page_title('ERROR_OCCURRED');
        $text = do_lang_tempcode('NO_PAGE_OUTPUT');
        $middle = warn_screen($title, $text, false);
    }
    // Extra stuff we can tag on (like messages)
    $additional = new ocp_tempcode();
    $site_closed = get_option('site_closed');
    // May have been JUST changed in page load - think Setup Wizard
    if ($site_closed == '1' && $PAGE != 'login' && $PAGE != 'join' && get_param_integer('wide_high', 0) == 0) {
        $additional->attach(do_template('ADDITIONAL', array('_GUID' => '03a41a91606b3ad05330e7d6f3e741c1', 'TYPE' => 'notice', 'MESSAGE' => do_lang_tempcode(has_specific_permission(get_member(), 'access_closed_site') ? 'SITE_SPECIAL_ACCESS' : 'SITE_SPECIAL_ACCESS_SU'))));
    }
    if ($GLOBALS['IS_ACTUALLY_ADMIN']) {
        $unsu_link = get_self_url(true, true, array('keep_su' => NULL));
        $su_username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $additional->attach(do_template('ADDITIONAL', array('_GUID' => '13a41a91606b3ad05330e7d6f3e741c1', 'TYPE' => 'notice', 'MESSAGE' => do_lang_tempcode('USING_SU', escape_html($unsu_link), escape_html($su_username)))));
    }
    $out = new ocp_tempcode();
    // This is important - it makes sure the tempcode tree appears nicely
    $middle->handle_symbol_preprocessing();
    // Due to the '->evaluate()' below, plus so that some symbol preprocessing can be passed into header
    $out->attach(do_header());
    if (function_exists('memory_get_usage') && get_param('special_page_type', '') == 'memory') {
        if (function_exists('memory_get_peak_usage')) {
            $memory_usage = memory_get_peak_usage();
        } else {
            $memory_usage = memory_get_usage();
        }
        $additional->attach(do_template('ADDITIONAL', array('_GUID' => 'd605c0d111742a8cd2d4ef270a1e5fe1', 'TYPE' => 'inform', 'MESSAGE' => do_lang_tempcode('MEMORY_USAGE', float_format(round(floatval($memory_usage) / 1024.0 / 1024.0, 2))))));
    }
    // Whack it into our global template
    global $ATTACHED_MESSAGES;
    $global_template = 'GLOBAL';
    if (get_option('show_docs') == '0') {
        $GLOBALS['HELPER_PANEL_TUTORIAL'] = '';
    }
    $helper_panel_pic = $GLOBALS['HELPER_PANEL_PIC'];
    if ($helper_panel_pic != '') {
        if (find_theme_image($helper_panel_pic, true) == '') {
            $helper_panel_pic = '';
        }
    }
    $global = do_template($global_template, array('HELPER_PANEL_TUTORIAL' => $GLOBALS['HELPER_PANEL_TUTORIAL'], 'HELPER_PANEL_HTML' => $GLOBALS['HELPER_PANEL_HTML'], 'HELPER_PANEL_TEXT' => $GLOBALS['HELPER_PANEL_TEXT'], 'HELPER_PANEL_PIC' => $helper_panel_pic, 'MIDDLE' => $doing_special_page_type ? $middle : $middle->evaluate(), 'MESSAGE_TOP' => $ATTACHED_MESSAGES, 'MESSAGE' => $additional, 'BREADCRUMBS' => breadcrumbs()));
    unset($middle);
    $out->attach($global);
    $out->attach(do_footer());
    $out->handle_symbol_preprocessing();
    if (get_value('xhtml_strict') === '1') {
        $out = make_xhtml_strict($out);
    }
    // Validation
    $novalidate = get_param_integer('keep_novalidate', get_param_integer('novalidate', 0));
    $show_edit_links = get_param_integer('show_edit_links', 0);
    if ((in_array(ocp_srv('HTTP_HOST'), array('localhost', 'test.ocportal.com')) || $GLOBALS['FORUM_DRIVER']->is_staff(get_member())) && ($special_page_type == 'code' || $novalidate == 0 && get_option('validation') == '1') && $GLOBALS['REFRESH_URL'][0] == '' && $show_edit_links == 0) {
        require_code('view_modes');
        $out_evaluated = $out->evaluate(NULL, false);
        do_xhtml_validation($out_evaluated, $special_page_type == 'code' && get_param_integer('preview_mode', NULL) === NULL, get_param_integer('preview_mode', 0));
    }
    // Cacheing for spiders
    if (running_script('index') && count($_POST) == 0 && isset($GLOBALS['SITE_INFO']['fast_spider_cache']) && $GLOBALS['SITE_INFO']['fast_spider_cache'] == '1' && is_guest()) {
        $bot_type = get_bot_type();
        if (($bot_type !== NULL || isset($GLOBALS['SITE_INFO']['any_guest_cached_too']) && $GLOBALS['SITE_INFO']['any_guest_cached_too'] == '1') && can_fast_spider_cache()) {
            $fast_cache_path = get_custom_file_base() . '/persistant_cache/' . md5(serialize(get_self_url_easy()));
            if ($bot_type === NULL) {
                $fast_cache_path .= '__non-bot';
            }
            if (!array_key_exists('js_on', $_COOKIE)) {
                $fast_cache_path .= '__no-js';
            }
            if (is_mobile()) {
                $fast_cache_path .= '_mobile';
            }
            $fast_cache_path .= '.gcd';
            if (!is_dir(get_custom_file_base() . '/persistant_cache/')) {
                if (@mkdir(get_custom_file_base() . '/persistant_cache/', 0777)) {
                    fix_permissions(get_custom_file_base() . '/persistant_cache/', 0777);
                    sync_file(get_custom_file_base() . '/persistant_cache/');
                } else {
                    intelligent_write_error($fast_cache_path);
                }
            }
            $out_evaluated = $out->evaluate(NULL, false);
            $myfile = @fopen($fast_cache_path, 'wb') or intelligent_write_error($fast_cache_path);
            if (function_exists('gzencode')) {
                fwrite($myfile, gzencode($out_evaluated, 9));
            } else {
                fwrite($myfile, $out_evaluated);
            }
            fclose($myfile);
            fix_permissions($fast_cache_path);
            sync_file($fast_cache_path);
        }
    }
    if ($doing_special_page_type) {
        special_page_types($special_page_type, $out, $out_evaluated);
    }
    // We calculated the time before outputting so that latency and bandwidth do not adversely affect the result
    global $PAGE_START_TIME, $PAGE_STRING;
    $page_generation_time = microtime_diff($PAGE_START_TIME, microtime(false));
    if (!$GLOBALS['QUICK_REDIRECT']) {
        if ($out_evaluated !== NULL) {
            echo $out_evaluated;
        } else {
            $GLOBALS['FINISHING_OUTPUT'] = true;
            $out->evaluate_echo();
        }
    }
    // Finally, stats
    if ($PAGE_STRING !== NULL) {
        log_stats($PAGE_STRING, intval($page_generation_time));
    }
    // When someone hits the Admin Zone front page.
    if ($ZONE['zone_name'] == 'adminzone' && get_page_name() == 'start') {
        // Security feature admins can turn on
        require_code('notifications');
        $current_username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $subject = do_lang('AFA_NOTIFICATION_MAIL_SUBJECT', $current_username, get_site_name(), get_ip_address());
        $mail = do_lang('AFA_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($current_username), comcode_escape(get_ip_address()));
        dispatch_notification('adminzone_frontpage_accessed', NULL, $subject, $mail);
        // Track very basic details of what sites use ocPortal. You can remove if you like.
        if (preg_match('#^localhost[\\.\\:$]?#', ocp_srv('HTTP_HOST')) == 0) {
            global $EXPIRE, $KEY;
            $timeout_before = @ini_get('default_socket_timeout');
            @ini_set('default_socket_timeout', '3');
            http_download_file('http://ocportal.com/user.php?url=' . urlencode(get_base_url()) . '&name=' . urlencode(get_site_name()) . '&registered=2&key=' . ($KEY === NULL ? '' : strval($KEY)) . '&expire=' . ($EXPIRE === NULL ? '' : strval($EXPIRE)) . '&version=' . urlencode(ocp_version_full()), NULL, false);
            @ini_set('default_socket_timeout', $timeout_before);
        }
    }
    // Little disk space check
    $last_space_check = get_value('last_space_check');
    if ($last_space_check === NULL || intval($last_space_check) < time() - 60 * 60 * 3) {
        set_value('last_space_check', strval(time()));
        $low_space_check = intval(get_option('low_space_check')) * 1024 * 1024;
        $disk_space = @disk_free_space(get_file_base());
        if (is_integer($disk_space) && $disk_space < $low_space_check) {
            require_code('notifications');
            $subject = do_lang('LOW_DISK_SPACE_SUBJECT', NULL, NULL, NULL, get_site_default_lang());
            $message = do_lang('LOW_DISK_SPACE_MAIL', strval(intval(round($disk_space / 1024 / 1024))), NULL, NULL, get_site_default_lang());
            dispatch_notification('low_disk_space', NULL, $subject, $message, NULL, A_FROM_SYSTEM_PRIVILEGED);
        }
    }
    //exit();
}
Exemplo n.º 7
0
/**
 * Relay an error message, if appropriate, to e-mail listeners (sometimes ocProducts, and site staff).
 *
 * @param  string			A error message (in HTML)
 * @param  boolean		Also send to ocProducts
 * @param  ID_TEXT		The notification type
 */
function relay_error_notification($text, $ocproducts = true, $notification_type = 'error_occurred')
{
    // Make sure we don't send too many error emails
    if (function_exists('get_value') && $GLOBALS['BOOTSTRAPPING'] == 0 && array_key_exists('SITE_DB', $GLOBALS) && !is_null($GLOBALS['SITE_DB'])) {
        $num = intval(get_value('num_error_mails_' . date('Y-m-d'))) + 1;
        if ($num == 51) {
            return;
        }
        // We've sent too many error mails today
        $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'values WHERE the_name LIKE \'' . db_encode_like('num\\_error\\_mails\\_%') . '\'');
        persistant_cache_delete('VALUES');
        set_value('num_error_mails_' . date('Y-m-d'), strval($num));
    }
    if (!function_exists('require_lang')) {
        return;
    }
    require_code('urls');
    require_code('tempcode');
    $error_url = running_script('index') ? static_evaluate_tempcode(build_url(array('page' => '_SELF'), '_SELF', NULL, true, false, true)) : get_self_url_easy();
    require_code('notifications');
    require_code('comcode');
    $mail = do_lang('ERROR_MAIL', comcode_escape($error_url), str_replace(array('[html', '[/html'), array('&#91;html', '&#91;/html'), $text), NULL, get_site_default_lang());
    dispatch_notification($notification_type, NULL, do_lang('ERROR_OCCURRED_SUBJECT', get_page_name(), NULL, NULL, get_site_default_lang()), $mail, NULL, A_FROM_SYSTEM_PRIVILEGED);
    if ($ocproducts && get_option('send_error_emails_ocproducts', true) == '1' && !running_script('cron_bridge') && strpos($text, '_custom/') === false && strpos($text, 'data/occle.php') === false && strpos($text, '/mini') === false && strpos($text, 'A transaction for the wrong IPN e-mail went through') === false && strpos($text, 'has been disabled for security reasons') === false && strpos($text, 'max_questions') === false && strpos($text, 'Error at offset') === false && strpos($text, 'Unable to allocate memory for pool') === false && strpos($text, 'Out of memory') === false && strpos($text, 'Disk is full writing') === false && strpos($text, 'Disk quota exceeded') === false && strpos($text, 'from storage engine') === false && strpos($text, 'Lost connection to MySQL server') === false && strpos($text, 'Unable to save result set') === false && strpos($text, '.MYI') === false && strpos($text, 'MySQL server has gone away') === false && strpos($text, 'Incorrect key file') === false && strpos($text, 'Too many connections') === false && strpos($text, 'marked as crashed and should be repaired') === false && strpos($text, 'connect to') === false && strpos($text, 'Access denied for') === false && strpos($text, 'Unknown database') === false && strpos($text, 'headers already sent') === false && preg_match('#Maximum execution time of \\d+ seconds#', $text) == 0 && preg_match('#Out of memory \\(allocated (1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24)\\d{6}\\)#', $text) == 0 && strpos($text, 'is marked as crashed and last') === false && strpos($text, 'failed to open stream: Permission denied') === false && strpos($text, 'phpinfo() has been disabled') === false && (strpos($text, 'Maximum execution time') === false || strpos($text, '/js_') === false && strpos($text, '/caches_filesystem.php') === false && strpos($text, '/files2.php') === false) && (strpos($text, 'doesn\'t exist') === false || strpos($text, 'import') === false) && (strpos($text, 'No such file or directory') === false || strpos($text, 'admin_setupwizard') === false) && strpos($text, 'File(/tmp/) is not within the allowed path') === false) {
        require_code('mail');
        mail_wrap(do_lang('ERROR_OCCURRED_SUBJECT', get_page_name(), NULL, NULL, get_site_default_lang()) . ' ' . ocp_version_full(), $mail, array('errors_final' . strval(ocp_version()) . '@ocportal.com'), '', '', '', 3, NULL, true, NULL, true);
    }
    if ($ocproducts && !is_null(get_value('agency_email_address'))) {
        require_code('mail');
        $agency_email_address = get_value('agency_email_address');
        mail_wrap(do_lang('ERROR_OCCURRED_SUBJECT', get_page_name(), NULL, NULL, get_site_default_lang()) . ' ' . ocp_version_full(), $mail, array($agency_email_address), '', '', '', 3, NULL, true, NULL, true);
    }
}
Exemplo n.º 8
0
/**
 * Get info about an addon, simulating an extended version of the traditional ocPortal-addon database row.
 *
 * @param  string		The name of the addon
 * @return array		The map of details
 */
function read_addon_info($name)
{
    $addon_rows = $GLOBALS['SITE_DB']->query_select('addons', array('*'), array('addon_name' => $name));
    if (array_key_exists(0, $addon_rows)) {
        $addon_row = $addon_rows[0];
        $addon_row['addon_files'] = array_unique(collapse_1d_complexity('filename', $GLOBALS['SITE_DB']->query_select('addons_files', array('filename'), array('addon_name' => $name))));
        $addon_row['addon_dependencies'] = collapse_1d_complexity('addon_name_dependant_upon', $GLOBALS['SITE_DB']->query_select('addons_dependencies', array('addon_name_dependant_upon'), array('addon_name' => $name, 'addon_name_incompatibility' => 0)));
        $addon_row['addon_incompatibilities'] = collapse_1d_complexity('addon_name_dependant_upon', $GLOBALS['SITE_DB']->query_select('addons_dependencies', array('addon_name_dependant_upon'), array('addon_name' => $name, 'addon_name_incompatibility' => 1)));
        $addon_row['addon_dependencies_on_this'] = find_addon_dependencies_on($name);
    } else {
        $path = get_file_base() . '/sources_custom/hooks/systems/addon_registry/' . filter_naughty_harsh($name, true) . '.php';
        if (!file_exists($path)) {
            $path = get_file_base() . '/sources/hooks/systems/addon_registry/' . filter_naughty_harsh($name, true) . '.php';
        }
        if (!file_exists($path)) {
            warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
        }
        $_hook_bits = extract_module_functions($path, array('get_dependencies', 'get_version', 'get_description', 'get_file_list'));
        if (is_null($_hook_bits[0])) {
            $dep = array();
        } else {
            $dep = is_array($_hook_bits[0]) ? call_user_func_array($_hook_bits[0][0], $_hook_bits[0][1]) : @eval($_hook_bits[0]);
        }
        $version = is_array($_hook_bits[1]) ? call_user_func_array($_hook_bits[1][0], $_hook_bits[1][1]) : @eval($_hook_bits[1]);
        $description = is_array($_hook_bits[2]) ? call_user_func_array($_hook_bits[2][0], $_hook_bits[2][1]) : @eval($_hook_bits[2]);
        if (is_null($_hook_bits[3])) {
            $file_list = array();
        } else {
            $file_list = is_array($_hook_bits[3]) ? call_user_func_array($_hook_bits[3][0], $_hook_bits[3][1]) : @eval($_hook_bits[3]);
        }
        $addon_row = array('addon_name' => $name, 'addon_author' => 'Core Team', 'addon_organisation' => 'ocProducts', 'addon_version' => $version == ocp_version_number() ? ocp_version_full() : float_format($version, 1), 'addon_description' => $description, 'addon_install_time' => filemtime($path), 'addon_files' => make_global_file_list($file_list), 'addon_dependencies' => $dep['requires'], 'addon_dependencies_on_this' => find_addon_dependencies_on($name), 'addon_incompatibilities' => $dep['conflicts_with']);
    }
    return $addon_row;
}