Esempio n. 1
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();
}
Esempio n. 2
0
/**
 * Get tempcode to tie in (to the HTML, in <head>) all the Javascript files that have been required.
 *
 * @param  ?string		Position to get Javascript for (NULL: all positions)
 * @set NULL header footer
 * @return tempcode		The tempcode to tie in the Javascript files
 */
function javascript_tempcode($position = NULL)
{
    global $JAVASCRIPTS, $JAVASCRIPT;
    $js = new ocp_tempcode();
    $minify = get_param_integer('keep_no_minify', 0) == 0;
    $https = get_option('enable_https', true) == '1' && function_exists('is_page_https') && function_exists('get_zone_name') && (tacit_https() || is_page_https(get_zone_name(), get_page_name()));
    $mobile = is_mobile();
    // Special merge operation for staff. In truth it's to get a better score on Google Page Speed ;)
    $to_merge = array('javascript_staff', 'javascript_button_occle', 'javascript_fractional_edit');
    $good_to_merge = true;
    foreach ($to_merge as $j) {
        if (!array_key_exists($j, $JAVASCRIPTS)) {
            $good_to_merge = false;
        }
    }
    if ($good_to_merge) {
        $j = 'javascript_staff___merged';
        if (!$minify) {
            $j .= '_non_minified';
        }
        if ($https) {
            $j .= '_ssl';
        }
        if ($mobile) {
            $j .= '_mobile';
        }
        $theme = filter_naughty($GLOBALS['FORUM_DRIVER']->get_theme());
        $dir = get_custom_file_base() . '/themes/' . $theme . '/templates_cached/' . filter_naughty(user_lang());
        $write_path = $dir . '/' . filter_naughty_harsh($j);
        $write_path .= '.js';
        /*$rebuild=false;	Performance hit
        		foreach ($to_merge as $j2)
        		{
        			$merge_from=javascript_enforce($j2);
        			if (filemtime($merge_from)==time()) $rebuild=true; // Hmm, just recalculated
        		}*/
        if (!is_file($write_path)) {
            $data = '';
            foreach ($to_merge as $j2) {
                $merge_from = javascript_enforce($j2);
                if (is_file($merge_from)) {
                    $data .= unixify_line_format(file_get_contents($merge_from, FILE_TEXT));
                } else {
                    $good_to_merge = false;
                    break;
                }
            }
            if ($good_to_merge) {
                $myfile = @fopen($write_path, 'wb') or intelligent_write_error($write_path);
                // Intentionally wb to stop line ending conversions on Windows
                fwrite($myfile, $data);
                fclose($myfile);
                fix_permissions($write_path, 0777);
                sync_file($write_path);
            }
        }
        if ($good_to_merge) {
            if ($position != 'header') {
                $js->attach(do_template('JAVASCRIPT_NEED', array('CODE' => $j)));
            }
        }
    }
    // Our main loop
    $bottom_ones = array('javascript_staff' => 1, 'javascript_button_occle' => 1, 'javascript_fractional_edit' => 1, 'javascript_thumbnails' => 1, 'javascript_button_realtime_rain' => 1);
    foreach (array_keys($JAVASCRIPTS) as $j) {
        if ($good_to_merge && in_array($j, $to_merge)) {
            continue;
        }
        if ($position !== NULL) {
            $bottom = isset($bottom_ones[$j]);
            // TODO: progmattic way of saying this at point of calls
            if ($position == 'header' && $bottom) {
                continue;
            }
            if ($position == 'footer' && !$bottom) {
                continue;
            }
        }
        $temp = javascript_enforce($j);
        if ($temp != '') {
            if (!$minify) {
                $j .= '_non_minified';
            }
            if ($https) {
                $j .= '_ssl';
            }
            if ($mobile) {
                $j .= '_mobile';
            }
            $js->attach(do_template('JAVASCRIPT_NEED', array('_GUID' => 'b5886d9dfc4d528b7e1b0cd6f0eb1670', 'CODE' => $j)));
        }
    }
    if (!is_null($JAVASCRIPT)) {
        $js->attach($JAVASCRIPT);
    }
    return $js;
}
Esempio n. 3
0
/**
 * Get the markup required to start a new SVG document
 *
 * @return string			The markup
*/
function _start_svg()
{
    $theme = @method_exists($GLOBALS['FORUM_DRIVER'], 'get_theme') ? $GLOBALS['FORUM_DRIVER']->get_theme() : 'default';
    if (file_exists(get_custom_file_base() . '/themes/' . $theme . '/css_custom/svg.css')) {
        $css_file = get_custom_base_url() . '/themes/' . $theme . '/css_custom/svg.css';
        $css_file_path = get_custom_file_base() . '/themes/' . $theme . '/css_custom/svg.css';
    } elseif (file_exists(get_custom_file_base() . '/themes/' . $theme . '/css/svg.css')) {
        $css_file = get_custom_base_url() . '/themes/' . $theme . '/css/svg.css';
        $css_file_path = get_custom_file_base() . '/themes/' . $theme . '/css/svg.css';
    } elseif (file_exists(get_custom_file_base() . '/themes/default/css_custom/svg.css')) {
        $css_file = get_custom_base_url() . '/themes/default/css_custom/svg.css';
        $css_file_path = get_custom_file_base() . '/themes/default/css_custom/svg.css';
    } else {
        $css_file = get_base_url() . '/themes/default/css/svg.css';
        $css_file_path = get_file_base() . '/themes/default/css/svg.css';
    }
    $js_file = str_replace(get_custom_file_base(), get_custom_base_url(), javascript_enforce('javascript'));
    global $CSS_FILE_CONTENTS;
    $CSS_FILE_CONTENTS = file_get_contents($css_file_path);
    return '<' . '?xml version="1.0" encoding="' . get_charset() . '"?' . '>
<' . '?xml-stylesheet href="' . escape_html($css_file) . '" type="text/css"?' . '>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 ' . float_to_raw_string(VIEWPORT_WIDTH) . ' ' . float_to_raw_string(VIEWPORT_HEIGHT) . '" preserveAspectRatio="xMinYMin meet" width="' . float_to_raw_string(SVG_WIDTH) . '" height="' . float_to_raw_string(SVG_HEIGHT) . '" version="1.1">
<script type="text/javascript">// <![CDATA[
if (typeof window.addEventListenerAbstract==\'undefined\') addEventListenerAbstract=function(element,the_event,command,capture)
{
	if(element)
	{
		if (typeof element.simulated_events==\'undefined\') element.simulated_events=[];
		if (typeof element.simulated_events[the_event]==\'undefined\') element.simulated_events[the_event]=[];
		element.simulated_events[the_event].push(command);

		if(typeof element.addEventListener!=\'undefined\')
		{
			return element.addEventListener(the_event,command,capture);
		}
		else if(typeof element.attachEvent!=\'undefined\')
		{
			return element.attachEvent("on"+the_event,command);
		}
		else return false;
	}
	else return false;
};
//]]></script>
<script xlink:href="' . escape_html($js_file) . '" />' . chr(10);
}
Esempio n. 4
0
    if ($b === false) {
        $b = 0;
    }
    $RELATIVE_PATH = substr($FILE_BASE, ($a > $b ? $a : $b) + 1);
    $FILE_BASE = substr($FILE_BASE, 0, $a > $b ? $a : $b);
} else {
    $RELATIVE_PATH = '';
}
@chdir($FILE_BASE);
global $NON_PAGE_SCRIPT;
$NON_PAGE_SCRIPT = 1;
global $FORCE_INVISIBLE_GUEST;
$FORCE_INVISIBLE_GUEST = 0;
if (!is_file($FILE_BASE . '/sources/global.php')) {
    exit('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . chr(10) . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN"><head><title>Critical startup error</title></head><body><h1>ocPortal startup error</h1><p>The second most basic ocPortal startup file, sources/global.php, could not be located. This is almost always due to an incomplete upload of the ocPortal system, so please check all files are uploaded correctly.</p><p>Once all ocPortal files are in place, ocPortal must actually be installed by running the installer. You must be seeing this message either because your system has become corrupt since installation, or because you have uploaded some but not all files from our manual installer package: the quick installer is easier, so you might consider using that instead.</p><p>ocProducts maintains full documentation for all procedures and tools, especially those for installation. 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><hr /><p style="font-size: 0.8em">ocPortal is a website engine created by ocProducts.</p></body></html>');
}
require $FILE_BASE . '/sources/global.php';
header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// Date in the past
header('Content-Type: text/javascript');
$lang = get_param('lang', '');
if ($lang != '') {
    require_lang($lang);
}
$script = get_param('script');
@ini_set('ocproducts.xss_detect', '0');
if ($script != '') {
    echo file_get_contents(javascript_enforce(strtoupper(filter_naughty_harsh($script))), FILE_TEXT);
}
Esempio n. 5
0
/**
 * Erase all template caches (caches in all themes).
 *
 * @param  boolean	Whether to preserve CSS and JS files that might be linked to between requests
 */
function erase_cached_templates($preserve_some = false)
{
    global $ERASED_TEMPLATES_ONCE;
    $ERASED_TEMPLATES_ONCE = true;
    require_code('themes2');
    $themes = find_all_themes();
    $langs = find_all_langs(true);
    foreach (array_keys($themes) as $theme) {
        foreach (array_keys($langs) as $lang) {
            $path = get_custom_file_base() . '/themes/' . $theme . '/templates_cached/' . $lang . '/';
            $_dir = @opendir($path);
            if ($_dir === false) {
                @mkdir($path, 0777);
                // OR warn_exit(do_lang_tempcode('WRITE_ERROR_DIRECTORY_REPAIR',escape_html($path)));
                fix_permissions($path, 0777);
            } else {
                while (false !== ($file = readdir($_dir))) {
                    if (substr($file, -4) == '.tcd' || substr($file, -4) == '.tcp' || !$preserve_some && (substr($file, -3) == '.js' || substr($file, -4) == '.css')) {
                        $i = 0;
                        while (@unlink($path . $file) === false && $i < 5) {
                            if (!file_exists($path . $file)) {
                                break;
                            }
                            // Race condition, gone already
                            sleep(1);
                            // May be race condition, lock
                            $i++;
                        }
                        if ($i >= 5) {
                            if (file_exists($path . $file)) {
                                @unlink($path . $file) or intelligent_write_error($path . $file);
                            }
                        }
                    }
                }
                closedir($_dir);
            }
        }
    }
    // Often the back button will be used to return to a form, so we need to ensure we have not broken the Javascript
    if (function_exists('get_member')) {
        javascript_enforce('javascript_validation');
        javascript_enforce('javascript_editing');
    }
}