예제 #1
0
/**
 * Calculate OCF notifications and render.
 *
 * @param  string		Cache identifier that we'll use.
 * @return array		A pair: Number of notifications, Rendered notifications.
 */
function generate_notifications($cache_identifier)
{
    $nql_backup = $GLOBALS['NO_QUERY_LIMIT'];
    $GLOBALS['NO_QUERY_LIMIT'] = true;
    $unread_pps = ocf_get_pp_rows();
    $notifications = new ocp_tempcode();
    $num_unread_pps = 0;
    foreach ($unread_pps as $unread_pp) {
        $by_id = is_null($unread_pp['t_cache_first_member_id']) || !is_null($unread_pp['t_forum_id']) ? $unread_pp['p_poster'] : $unread_pp['t_cache_first_member_id'];
        $by = $GLOBALS['OCF_DRIVER']->get_username($by_id);
        if (is_null($by)) {
            $by = do_lang('UNKNOWN');
        }
        $u_title = $unread_pp['t_cache_first_title'];
        if (is_null($unread_pp['t_forum_id'])) {
            $type = do_lang_tempcode($unread_pp['t_cache_first_post_id'] == $unread_pp['id'] ? 'NEW_PT_NOTIFICATION' : 'NEW_PP_NOTIFICATION');
            $num_unread_pps++;
            $reply_url = build_url(array('page' => 'topics', 'type' => 'new_post', 'id' => $unread_pp['p_topic_id'], 'quote' => $unread_pp['id']), get_module_zone('topics'));
            $additional_posts = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*) AS cnt FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE p_topic_id=' . strval($unread_pp['p_topic_id']) . ' AND id>' . strval($unread_pp['id']));
        } else {
            $type = do_lang_tempcode('ADD_INLINE_PERSONAL_POST');
            if ($unread_pp['p_title'] != '') {
                $u_title = $unread_pp['p_title'];
            }
            $reply_url = build_url(array('page' => 'topics', 'type' => 'new_post', 'id' => $unread_pp['p_topic_id'], 'quote' => $unread_pp['id'], 'intended_solely_for' => $unread_pp['p_poster']), get_module_zone('topics'));
            $additional_posts = 0;
        }
        $time_raw = $unread_pp['p_time'];
        $time = get_timezoned_date($unread_pp['p_time']);
        $topic = $GLOBALS['OCF_DRIVER']->post_url($unread_pp['id'], NULL);
        $post = get_translated_tempcode($unread_pp['p_post'], $GLOBALS['FORUM_DB']);
        $description = $unread_pp['t_description'];
        if ($description != '') {
            $description = ' (' . $description . ')';
        }
        $profile_link = is_guest($by_id) ? new ocp_tempcode() : $GLOBALS['OCF_DRIVER']->member_profile_url($by_id, false, true);
        $redirect = get_self_url(true, true);
        $ignore_url = build_url(array('page' => 'topics', 'type' => 'mark_read_topic', 'id' => $unread_pp['p_topic_id'], 'redirect' => $redirect), get_module_zone('topics'));
        $ignore_url_2 = build_url(array('page' => 'topics', 'type' => 'mark_read_topic', 'id' => $unread_pp['p_topic_id'], 'redirect' => $redirect, 'ajax' => 1), get_module_zone('topics'));
        require_javascript('javascript_ajax');
        $notifications->attach(do_template('OCF_NOTIFICATION', array('_GUID' => '3b224ea3f4da2f8f869a505b9756970a', 'ADDITIONAL_POSTS' => integer_format($additional_posts), '_ADDITIONAL_POSTS' => strval($additional_posts), 'ID' => strval($unread_pp['id']), 'U_TITLE' => $u_title, 'IGNORE_URL' => $ignore_url, 'IGNORE_URL_2' => $ignore_url_2, 'REPLY_URL' => $reply_url, 'TOPIC_URL' => $topic, 'POST' => $post, 'DESCRIPTION' => $description, 'TIME' => $time, 'TIME_RAW' => strval($time_raw), 'BY' => $by, 'PROFILE_LINK' => $profile_link, 'TYPE' => $type)));
    }
    require_code('caches2');
    put_into_cache('_new_pp', 60 * 60 * 24, $cache_identifier, array($notifications->to_assembly(), $num_unread_pps));
    $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup;
    return array($notifications, $num_unread_pps);
}
예제 #2
0
/**
 * Get the processed tempcode for the specified block. Please note that you pass multiple parameters in as an array, but single parameters go in as a string or other flat variable.
 *
 * @param  ID_TEXT		The block name
 * @param  ?array			The block parameter map (NULL: no parameters)
 * @param  ?integer		The TTL to use in minutes (NULL: block default)
 * @return tempcode		The generated tempcode
 */
function do_block($codename, $map = NULL, $ttl = NULL)
{
    global $LANGS_REQUESTED, $JAVASCRIPTS, $CSSS, $DO_NOT_CACHE_THIS;
    if (is_null($map)) {
        $map = array();
    }
    if (!array_key_exists('cache', $map)) {
        $map['cache'] = block_cache_default($codename);
    }
    $DO_NOT_CACHE_THIS = $map['cache'] == '0';
    $object = NULL;
    if ((get_option('is_on_block_cache') == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache', 0) == 1 || get_param_integer('cache_blocks', 0) == 1) && (get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache_blocks', NULL) !== 0 && get_param_integer('cache', NULL) !== 0) && strpos(get_param('special_page_type', ''), 't') === false) {
        // See if the block may be cached (else cannot, or is yet unknown)
        if ($map['cache'] == '0') {
            $row = NULL;
        } else {
            $row = find_cache_on($codename);
            if ($row === NULL) {
                $object = do_block_hunt_file($codename, $map);
                if (is_object($object) && method_exists($object, 'cacheing_environment')) {
                    $info = $object->cacheing_environment($map);
                    if ($info !== NULL) {
                        $row = array('cached_for' => $codename, 'cache_on' => $info['cache_on'], 'cache_ttl' => $info['ttl']);
                    }
                }
            }
            if ($row === NULL && isset($map['quick_cache']) && $map['quick_cache'] == '1') {
                $row = array('cached_for' => $codename, 'cache_on' => 'array($map,$GLOBALS[\'FORUM_DRIVER\']->get_members_groups(get_member()))', 'cache_ttl' => 60);
            }
        }
        if ($row !== NULL) {
            $cache_identifier = do_block_get_cache_identifier($row['cache_on'], $map);
            // See if it actually is cached
            if ($cache_identifier !== NULL) {
                if ($ttl === NULL) {
                    $ttl = $row['cache_ttl'];
                }
                $cache = get_cache_entry($codename, $cache_identifier, $ttl, true, array_key_exists('cache', $map) && $map['cache'] == '2', $map);
                if ($cache === NULL) {
                    $nql_backup = $GLOBALS['NO_QUERY_LIMIT'];
                    $GLOBALS['NO_QUERY_LIMIT'] = true;
                    if ($object !== NULL) {
                        $object = do_block_hunt_file($codename, $map);
                    }
                    if (!is_object($object)) {
                        // This probably happened as we uninstalled a block, and now we're getting a "missing block" message back.
                        if (!defined('HIPHOP_PHP')) {
                            // Removed outdated cache-on information
                            $GLOBALS['SITE_DB']->query_delete('cache_on', array('cached_for' => $codename), '', 1);
                            persistant_cache_delete('CACHE_ON');
                        }
                        $out = new ocp_tempcode();
                        $out->attach($object);
                        return $out;
                    }
                    $backup_langs_requested = $LANGS_REQUESTED;
                    $backup_javascripts = $JAVASCRIPTS;
                    $backup_csss = $CSSS;
                    $LANGS_REQUESTED = array();
                    $JAVASCRIPTS = array('javascript' => 1, 'javascript_thumbnails' => 1);
                    $CSSS = array('no_cache' => 1, 'global' => 1);
                    if (isset($map['quick_cache']) && $map['quick_cache'] == '1') {
                        global $MEMORY_OVER_SPEED;
                        $MEMORY_OVER_SPEED = true;
                        // Let this eat up some CPU in order to let it save RAM,
                        disable_php_memory_limit();
                        if (function_exists('set_time_limit')) {
                            @set_time_limit(200);
                        }
                    }
                    $cache = $object->run($map);
                    $cache->handle_symbol_preprocessing();
                    if (!$DO_NOT_CACHE_THIS) {
                        require_code('caches2');
                        if (isset($map['quick_cache']) && $map['quick_cache'] == '1' && has_cookies()) {
                            $cache = make_string_tempcode(preg_replace('#((\\?)|(&(amp;)?))keep\\_[^="]*=[^&"]*#', '\\2', $cache->evaluate()));
                        }
                        put_into_cache($codename, $ttl, $cache_identifier, $cache, array_keys($LANGS_REQUESTED), array_keys($JAVASCRIPTS), array_keys($CSSS), true);
                    } elseif ($ttl != -1 && $cache->is_empty()) {
                        $LANGS_REQUESTED += $backup_langs_requested;
                        $JAVASCRIPTS += $backup_javascripts;
                        $CSSS += $backup_csss;
                        return do_block($codename, $map, -1);
                    }
                    $LANGS_REQUESTED += $backup_langs_requested;
                    $JAVASCRIPTS += $backup_javascripts;
                    $CSSS += $backup_csss;
                    $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup;
                }
                return $cache;
            }
        }
    }
    // NB: If we've got this far cache="2" is ignored. But later on (for normal expiries, different contexts, etc) cache_on will be known so not an issue.
    // We will need to load the actual file
    if (is_null($object)) {
        $object = do_block_hunt_file($codename, $map);
    }
    if (is_object($object)) {
        $nql_backup = $GLOBALS['NO_QUERY_LIMIT'];
        $GLOBALS['NO_QUERY_LIMIT'] = true;
        $backup_langs_requested = $LANGS_REQUESTED;
        $backup_javascripts = $JAVASCRIPTS;
        $backup_csss = $CSSS;
        $LANGS_REQUESTED = array();
        $JAVASCRIPTS = array('javascript' => 1, 'javascript_thumbnails' => 1);
        $CSSS = array('no_cache' => 1, 'global' => 1);
        $cache = $object->run($map);
        $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup;
    } else {
        $out = new ocp_tempcode();
        $out->attach($object);
        return $out;
    }
    // May it be added to cache_on?
    if (!$DO_NOT_CACHE_THIS && method_exists($object, 'cacheing_environment') && (get_option('is_on_block_cache') == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache_blocks', 0) == 1 || get_param_integer('cache', 0) == 1) && (get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache_blocks', NULL) !== 0 && get_param_integer('cache', NULL) !== 0)) {
        $info = $object->cacheing_environment($map);
        if ($info !== NULL) {
            $cache_identifier = do_block_get_cache_identifier($info['cache_on'], $map);
            if ($cache_identifier !== NULL) {
                require_code('caches2');
                put_into_cache($codename, $info['ttl'], $cache_identifier, $cache, array_keys($LANGS_REQUESTED), array_keys($JAVASCRIPTS), array_keys($CSSS), true);
                if (!defined('HIPHOP_PHP') && !is_array($info['cache_on'])) {
                    $GLOBALS['SITE_DB']->query_insert('cache_on', array('cached_for' => $codename, 'cache_on' => $info['cache_on'], 'cache_ttl' => $info['ttl']), false, true);
                    // Allow errors in case of race conditions
                }
            }
        }
    }
    $LANGS_REQUESTED += $backup_langs_requested;
    $JAVASCRIPTS += $backup_javascripts;
    $CSSS += $backup_csss;
    return $cache;
}
예제 #3
0
 /**
  * Standard modular run function for CRON hooks. Searches for tasks to perform.
  */
 function run()
 {
     if (get_param('keep_lang', NULL) === NULL || get_param('keep_theme', NULL) === NULL) {
         // We need to run this for each language and for each theme
         $langs = find_all_langs();
         require_code('themes2');
         $themes = find_all_themes();
         foreach (array_keys($langs) as $lang) {
             foreach (array_keys($themes) as $theme) {
                 if ($theme == 'default' || has_category_access(get_member(), 'theme', $theme)) {
                     $where = array('c_theme' => $theme, 'c_lang' => $lang);
                     $count = $GLOBALS['SITE_DB']->query_value('cron_caching_requests', 'COUNT(*)', $where);
                     if ($count > 0) {
                         $url = get_base_url() . '/data/cron_bridge.php?limit_hook=block_caching&keep_lang=' . urlencode($lang) . '&keep_theme=' . urlencode($theme);
                         http_download_file($url, NULL, false);
                     }
                 }
             }
         }
         // Force re-loading of values that we use to mark progress (as above calls probably resulted in changes happening)
         global $VALUES;
         $VALUES = $GLOBALS['SITE_DB']->query_select('values', array('*'));
         $VALUES = list_to_map('the_name', $VALUES);
         return;
     }
     $where = array('c_theme' => $GLOBALS['FORUM_DRIVER']->get_theme(), 'c_lang' => user_lang());
     $requests = $GLOBALS['SITE_DB']->query_select('cron_caching_requests', array('id', 'c_codename', 'c_map', 'c_timezone', 'c_is_bot', 'c_in_panel', 'c_interlock', 'c_store_as_tempcode'), $where);
     foreach ($requests as $request) {
         $GLOBALS['NO_QUERY_LIMIT'] = true;
         $codename = $request['c_codename'];
         $map = unserialize($request['c_map']);
         $object = do_block_hunt_file($codename, $map);
         if (is_object($object)) {
             global $LANGS_REQUESTED, $JAVASCRIPTS, $CSSS, $LANGS_REQUESTED, $DO_NOT_CACHE_THIS, $TIMEZONE_MEMBER_CACHE;
             $backup_langs_requested = $LANGS_REQUESTED;
             $backup_javascripts = $JAVASCRIPTS;
             $backup_csss = $CSSS;
             get_users_timezone();
             $backup_timezone = $TIMEZONE_MEMBER_CACHE[get_member()];
             $LANGS_REQUESTED = array();
             $JAVASCRIPTS = array('javascript' => 1, 'javascript_thumbnails' => 1);
             $CSSS = array('no_cache' => 1, 'global' => 1);
             $cache = $object->run($map);
             $TIMEZONE_MEMBER_CACHE[get_member()] = $backup_timezone;
             $cache->handle_symbol_preprocessing();
             if (!$DO_NOT_CACHE_THIS) {
                 if (method_exists($object, 'cacheing_environment')) {
                     $info = $object->cacheing_environment();
                 } else {
                     $info = array();
                     $info['cache_on'] = 'array($map,$GLOBALS[\'FORUM_DRIVER\']->get_members_groups(get_member()))';
                     $info['ttl'] = 60 * 24;
                 }
                 $ttl = $info['ttl'];
                 $_cache_identifier = array();
                 $cache_on = $info['cache_on'];
                 if (is_array($cache_on)) {
                     $_cache_identifier = call_user_func($cache_on[0], $map);
                 } else {
                     if ($cache_on != '' && !defined('HIPHOP_PHP')) {
                         $_cache_on = eval('return ' . $cache_on . ';');
                         // NB: This uses $map, as $map is referenced inside $cache_on
                         if (is_null($_cache_on)) {
                             return NULL;
                         }
                         foreach ($_cache_on as $on) {
                             $_cache_identifier[] = $on;
                         }
                     } elseif (defined('HIPHOP_PHP')) {
                         return NULL;
                     }
                 }
                 $_cache_identifier[] = $request['c_timezone'];
                 $_cache_identifier[] = $request['c_is_bot'] == 0;
                 $_cache_identifier[] = strval($request['c_in_panel']);
                 $_cache_identifier[] = strval($request['c_interlock']);
                 $cache_identifier = serialize($_cache_identifier);
                 require_code('caches2');
                 if ($request['c_store_as_tempcode'] == 1) {
                     $cache = make_string_tempcode($cache->evaluate());
                 }
                 put_into_cache($codename, $ttl, $cache_identifier, $cache, array_keys($LANGS_REQUESTED), array_keys($JAVASCRIPTS), array_keys($CSSS), true);
             }
             $LANGS_REQUESTED += $backup_langs_requested;
             $JAVASCRIPTS += $backup_javascripts;
             $CSSS += $backup_csss;
         }
         $GLOBALS['SITE_DB']->query_delete('cron_caching_requests', $request);
     }
 }
예제 #4
0
$max_words = array_key_exists('max_words', $map) ? intval($map['max_words']) : 15;
$cache_id = $id . '_' . strval($cols) . '_' . strval($rows) . '_' . strval($max_words);
$cached = get_cache_entry('main_crossword', $cache_id);
if (is_null($cached)) {
    $pc = new PHP_Crossword($rows, $cols);
    $pc->setMaxWords($max_words);
    $charset = get_charset();
    $success = $pc->generate();
    if (!$success) {
        warn_exit('Sorry, unable to generate demo crossword - try with more area or less words.');
    }
    $params = array('colors' => 0, 'fillflag' => 0, 'cellflag' => '');
    $html = $pc->getHTML($params);
    $words = $pc->getWords();
    require_code('caches2');
    put_into_cache('main_crossword', 60 * 60 * 24 * 5000, $cache_id, array($html, $words));
} else {
    list($html, $words) = $cached;
}
echo '<div class="float_surrounder crossword">';
echo <<<END
<table class="questionTable solidborder" border="0" cellpadding="4">
<tr>
\t<th>Num.</th>
\t<th>Question</th>
</tr>
END;
$word_hints = '';
foreach ($words as $key => $word) {
    $_key = escape_html(strval($key + 1));
    $_question = escape_html($word['question']);