/** * 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; }
/** * Do the wrapper that fits around OCF module output. * * @param tempcode The title for the module output that we are wrapping. * @param tempcode The module output that we are wrapping. * @param boolean Whether to include the personal bar in the wrap. * @param boolean Whether to include statistics in the wrap. * @param ?AUTO_LINK The forum to make the search link search under (NULL: Users own PT forum/unknown). * @return tempcode The wrapped output. */ function ocf_wrapper($title, $content, $show_personal_bar = true, $show_stats = true, $forum_id = NULL) { global $ZONE; $wide = is_wide(); if ($wide == 0 && get_value('force_forum_bar') !== '1') { $show_personal_bar = false; $show_stats = false; } // Notifications if (!is_guest() && (get_page_name() == 'forumview' || get_page_name() == 'topicview' || get_page_name() == 'vforums')) { $cache_identifier = serialize(array(get_member())); $_notifications = 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('keep_cache', NULL) !== 0 && get_param_integer('cache', NULL) !== 0)) { $_notifications = get_cache_entry('_new_pp', $cache_identifier, 10000); } if (is_null($_notifications)) { require_code('ocf_notifications'); list($notifications, $num_unread_pps) = generate_notifications($cache_identifier); } else { list($__notifications, $num_unread_pps) = $_notifications; $notifications = new ocp_tempcode(); if (!$notifications->from_assembly($__notifications, true)) { require_code('ocf_notifications'); list($notifications, $num_unread_pps) = generate_notifications($cache_identifier); } if (!$notifications->is_empty()) { require_javascript('javascript_ajax'); } } } else { $notifications = new ocp_tempcode(); $num_unread_pps = 0; } if ($show_personal_bar) { if (get_member() != $GLOBALS['OCF_DRIVER']->get_guest_id()) { $member_info = ocf_read_in_member_profile(get_member(), true); $profile_url = $GLOBALS['OCF_DRIVER']->member_profile_url(get_member(), true, true); $_new_topics = $GLOBALS['FORUM_DB']->query('SELECT COUNT(*) AS mycnt FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE NOT t_forum_id IS NULL AND t_cache_first_time>' . strval((int) $member_info['last_visit_time'])); $new_topics = $_new_topics[0]['mycnt']; $_new_posts = $GLOBALS['FORUM_DB']->query('SELECT COUNT(*) AS mycnt FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE NOT p_cache_forum_id IS NULL AND p_time>' . strval((int) $member_info['last_visit_time'])); $new_posts = $_new_posts[0]['mycnt']; $max_avatar_height = ocf_get_member_best_group_property(get_member(), 'max_avatar_height'); // Any unread PT-PPs? $pt_extra = $num_unread_pps == 0 ? new ocp_tempcode() : do_lang_tempcode('NUM_UNREAD', integer_format($num_unread_pps)); $personal_topic_url = build_url(array('page' => 'members', 'type' => 'view', 'id' => get_member()), get_module_zone('members'), NULL, true, false, false, 'tab__pts'); $head = do_template('OCF_MEMBER_BAR', array('_GUID' => 's3kdsadf0p3wsjlcfksdj', 'AVATAR' => array_key_exists('avatar', $member_info) ? $member_info['avatar'] : '', 'PROFILE_URL' => $profile_url, 'USERNAME' => $member_info['username'], 'LOGOUT_URL' => build_url(array('page' => 'login', 'type' => 'logout'), get_module_zone('login')), 'NUM_POINTS_ADVANCE' => array_key_exists('num_points_advance', $member_info) ? make_string_tempcode(integer_format($member_info['num_points_advance'])) : do_lang('NA'), 'NUM_POINTS' => array_key_exists('points', $member_info) ? integer_format($member_info['points']) : '', 'NUM_POSTS' => integer_format($member_info['posts']), 'PRIMARY_GROUP' => $member_info['primary_group_name'], 'LAST_VISIT_DATE_RAW' => strval($member_info['last_visit_time']), 'LAST_VISIT_DATE' => $member_info['last_visit_time_string'], 'PERSONAL_TOPIC_URL' => $personal_topic_url, 'NEW_POSTS_URL' => build_url(array('page' => 'vforums', 'type' => 'misc'), get_module_zone('vforums')), 'UNREAD_TOPICS_URL' => build_url(array('page' => 'vforums', 'type' => 'unread'), get_module_zone('vforums')), 'RECENTLY_READ_URL' => build_url(array('page' => 'vforums', 'type' => 'recently_read'), get_module_zone('vforums')), 'INLINE_PERSONAL_POSTS_URL' => build_url(array('page' => 'topicview'), get_module_zone('topicview')), 'PT_EXTRA' => $pt_extra, 'NEW_TOPICS' => integer_format($new_topics), 'NEW_POSTS' => integer_format($new_posts), 'MAX_AVATAR_HEIGHT' => strval($max_avatar_height))); } else { if (count($_POST) > 0) { $_this_url = build_url(array('page' => 'forumview'), 'forum', array('keep_session' => 1)); } else { $_this_url = build_url(array('page' => '_SELF'), '_SELF', array('keep_session' => 1), true); } $this_url = $_this_url->evaluate(); $login_url = build_url(array('page' => 'login', 'type' => 'login', 'redirect' => $this_url), get_module_zone('login')); $full_link = build_url(array('page' => 'login', 'type' => 'misc', 'redirect' => $this_url), get_module_zone('login')); $join_url = build_url(array('page' => 'join', 'redirect' => $this_url), get_module_zone('join')); $head = do_template('OCF_GUEST_BAR', array('NAVIGATION' => '', 'LOGIN_URL' => $login_url, 'JOIN_LINK' => $join_url, 'FULL_LINK' => $full_link)); } } else { $head = new ocp_tempcode(); } if ($show_stats) { $stats = ocf_get_forums_stats(); // Users online $users_online = new ocp_tempcode(); $count = 0; $members = get_online_members(false, NULL, $count); $groups_seen = array(); if (!is_null($members)) { //$members=collapse_2d_complexity('the_user','cache_username',$members); $guests = 0; foreach ($members as $bits) { $member = $bits['the_user']; $username = $bits['cache_username']; if ($member == $GLOBALS['OCF_DRIVER']->get_guest_id()) { $guests++; continue; } if (is_null($username)) { continue; } $url = $GLOBALS['OCF_DRIVER']->member_profile_url($member, false, true); if (!array_key_exists('m_primary_group', $bits)) { $bits['m_primary_group'] = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member, 'm_primary_group'); } $pgid = $bits['m_primary_group']; //$GLOBALS['FORUM_DRIVER']->get_member_row_field($member,'m_primary_group'); if (is_null($pgid)) { continue; } // Deleted member $groups_seen[$pgid] = 1; $col = get_group_colour($pgid); $usergroup = ocf_get_group_name($pgid); if (get_value('disable_user_online_groups') === '1') { $usergroup = NULL; $col = NULL; $groups_seen = array(); } $users_online->attach(do_template('OCF_USER_MEMBER', array('_GUID' => 'a9cb1af2a04b14edd70749c944495bff', 'COLOUR' => $col, 'PROFILE_URL' => $url, 'USERNAME' => $username, 'USERGROUP' => $usergroup))); } if ($guests != 0) { if (!$users_online->is_empty()) { $users_online->attach(do_lang_tempcode('LIST_SEP')); } $users_online->attach(do_lang_tempcode('NUM_GUESTS', integer_format($guests))); } } // Birthdays $_birthdays = ocf_find_birthdays(); $birthdays = new ocp_tempcode(); foreach ($_birthdays as $_birthday) { $birthday_link = build_url(array('page' => 'topics', 'type' => 'birthday', 'id' => $_birthday['username']), get_module_zone('topics')); $birthday = do_template('OCF_BIRTHDAY_LINK', array('_GUID' => 'a98959187d37d80e134d47db7e3a52fa', 'AGE' => array_key_exists('age', $_birthday) ? integer_format($_birthday['age']) : NULL, 'PROFILE_URL' => $GLOBALS['OCF_DRIVER']->member_profile_url($_birthday['id'], false, true), 'USERNAME' => $_birthday['username'], 'BIRTHDAY_LINK' => $birthday_link)); $birthdays->attach($birthday); } if (!$birthdays->is_empty()) { $birthdays = do_template('OCF_BIRTHDAYS', array('_GUID' => '03da2c0d46e76407d63bff22aac354bd', 'BIRTHDAYS' => $birthdays)); } // Usergroup keys $groups = array(); $all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true, false, false, NULL, NULL, true); foreach ($all_groups as $gid => $gtitle) { if ($gid == db_get_first_id()) { continue; } // Throw out the first, guest if (array_key_exists($gid, $groups_seen)) { $groups[] = array('GCOLOUR' => get_group_colour($gid), 'GID' => strval($gid), 'GTITLE' => $gtitle); } } $foot = do_template('OCF_STATS', array('_GUID' => 'sdflkdlfd303frksdf', 'NEWEST_MEMBER_PROFILE_URL' => $GLOBALS['OCF_DRIVER']->member_profile_url($stats['newest_member_id'], false, true), 'NEWEST_MEMBER_USERNAME' => $stats['newest_member_username'], 'NUM_MEMBERS' => integer_format($stats['num_members']), 'NUM_TOPICS' => integer_format($stats['num_topics']), 'NUM_POSTS' => integer_format($stats['num_posts']), 'BIRTHDAYS' => $birthdays, 'USERS_ONLINE' => $users_online, 'USERS_ONLINE_URL' => has_actual_page_access(get_member(), 'onlinemembers') ? build_url(array('page' => 'onlinemembers'), get_module_zone('onlinemembers')) : new ocp_tempcode(), 'GROUPS' => $groups)); } else { $foot = new ocp_tempcode(); } $wrap = do_template('OCF_WRAPPER', array('_GUID' => '456c21db6c09ae260accfa4c2a59fce7', 'TITLE' => $title, 'NOTIFICATIONS' => $notifications, 'HEAD' => $head, 'FOOT' => $foot, 'CONTENT' => $content)); return $wrap; }
<?php /* ocPortal Copyright (c) ocProducts, 2004-2012 See text/EN/licence.txt for full licencing information. */ require_css('crossword'); require_code('php-crossword/php_crossword.class'); $id = $map['param']; $cols = array_key_exists('cols', $map) ? intval($map['cols']) : 15; $rows = array_key_exists('rows', $map) ? intval($map['rows']) : 15; $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; }