/**
 * Certain symbols need preprocessing, before the output stream is made.
 *
 * @param  array			Symbol details
 * @param  array			Where we store children stuff
 */
function handle_symbol_preprocessing($bit, &$children)
{
    switch ($bit[2]) {
        case 'PAGE_LINK':
            if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                return;
            }
            $param = $bit[3];
            if (array_key_exists(0, $param)) {
                if (is_object($param[0])) {
                    $param[0] = $param[0]->evaluate();
                }
                list(, $url_parts, ) = page_link_decode(str_replace(chr(10), '', $param[0]));
                if (!array_key_exists('id', $url_parts)) {
                    return;
                }
                if (!array_key_exists('type', $url_parts)) {
                    $url_parts['type'] = 'misc';
                }
                if (is_null($url_parts['type'])) {
                    $url_parts['type'] = 'misc';
                }
                // NULL means "do not take from environment"; so we default it to 'misc' (even though it might actually be left out when SEO URLs are off, we know it cannot be for SEO URLs)
                if (!array_key_exists('page', $url_parts)) {
                    return;
                }
                if (!is_string($url_parts['id'])) {
                    if (is_null($url_parts['id'])) {
                        $url_parts['id'] = strval(db_get_first_id());
                    }
                }
                // Does this URL arrangement support monikers?
                global $CONTENT_OBS, $LOADED_MONIKERS;
                load_moniker_hooks();
                $found = false;
                $looking_for = '_SEARCH:' . $url_parts['page'] . ':' . $url_parts['type'] . ':_WILD';
                $ob_info = isset($CONTENT_OBS[$looking_for]) ? $CONTENT_OBS[$looking_for] : NULL;
                if (!is_null($ob_info)) {
                    if (!isset($LOADED_MONIKERS[$url_parts['page']][$url_parts['type']][$url_parts['id']])) {
                        $LOADED_MONIKERS[$url_parts['page']][$url_parts['type']][$url_parts['id']] = true;
                    }
                    // Indicator to preload this
                }
            }
            return;
        case 'SET':
            if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                return;
            }
            $param = $bit[3];
            if (array_key_exists(1, $param)) {
                global $TEMPCODE_SETGET;
                $param_copy = array();
                foreach ($param as $i => $x) {
                    if ($i != 0) {
                        $param_copy[] = is_object($x) ? $x->evaluate() : $x;
                    }
                }
                $TEMPCODE_SETGET[is_object($param[0]) ? $param[0]->evaluate() : $param[0]] = implode(',', $param_copy);
            }
            return;
        case 'BLOCK':
            if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                return;
            }
            $param = $bit[3];
            foreach ($param as $i => $p) {
                if (is_object($p)) {
                    $param[$i] = $p->evaluate();
                }
            }
            if (count($param) == 1 && strpos($param[0], ',') !== false) {
                $param = preg_split('#((?<![^\\\\])|(?<!\\\\\\\\)|(?<!^)),#', $param[0]);
            }
            //if (strpos(serialize($param),'side_stored_menu')!==false) { @debug_print_backtrace();exit(); } // Useful for debugging
            global $REQUEST_BLOCK_NEST_LEVEL;
            global $LOADED_BLOCKS;
            if (array_key_exists(serialize($param), $LOADED_BLOCKS)) {
                $REQUEST_BLOCK_NEST_LEVEL--;
                return;
            }
            $REQUEST_BLOCK_NEST_LEVEL++;
            if ($REQUEST_BLOCK_NEST_LEVEL > 20) {
                $REQUEST_BLOCK_NEST_LEVEL = 0;
                $LOADED_BLOCKS[serialize($param)] = do_lang_tempcode('INTERNAL_ERROR');
                attach_message(do_lang_tempcode('STOPPED_RECURSIVE_RESOURCE_INCLUDE', is_string($param[0]) ? $param[0] : 'block'), 'warn');
                return;
            }
            $block_parms = array();
            foreach ($param as $_param) {
                $block_parts = explode('=', $_param, 2);
                if (count($block_parts) != 2) {
                    $LOADED_BLOCKS[serialize($param)] = new ocp_tempcode();
                    continue 2;
                }
                list($key, $val) = $block_parts;
                $block_parms[$key] = $val;
            }
            $b_value = do_block($block_parms['block'], $block_parms);
            if ($GLOBALS['RECORD_TEMPLATES_TREE']) {
                $children[] = array(':block: ' . $block_parms['block'], array(array($b_value->codename, $b_value->children, $b_value->fresh)), true);
            }
            $b_value->handle_symbol_preprocessing();
            $LOADED_BLOCKS[serialize($param)] = $b_value;
            $REQUEST_BLOCK_NEST_LEVEL--;
            return;
        case 'JAVASCRIPT_INCLUDE':
            if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                return;
            }
            $param = $bit[3];
            foreach ($param as $i => $p) {
                if (is_object($p)) {
                    $param[$i] = $p->evaluate();
                }
            }
            require_javascript($param[0]);
            return;
        case 'FACILITATE_AJAX_BLOCK_CALL':
            require_javascript('javascript_ajax');
            return;
        case 'CSS_INCLUDE':
            if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                return;
            }
            $param = $bit[3];
            foreach ($param as $i => $p) {
                if (is_object($p)) {
                    $param[$i] = $p->evaluate();
                }
            }
            require_css($param[0]);
            return;
        case 'LOAD_PANEL':
            if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                return;
            }
            $param = $bit[3];
            foreach ($param as $i => $p) {
                if (is_object($p)) {
                    $param[$i] = $p->evaluate();
                }
            }
            global $LOADED_PANELS;
            if (array_key_exists(serialize($param), $LOADED_PANELS)) {
                return;
            }
            if (array_key_exists(0, $param)) {
                if (substr(get_page_name(), 0, 6) != 'panel_') {
                    if (strpos($param[0], ':') !== false) {
                        $param = array_reverse(explode(':', $param[0], 2));
                    }
                    if (substr($param[0], 0, 6) == 'panel_') {
                        $param[0] = substr($param[0], 6);
                    }
                    global $ZONE;
                    $wide_high = is_wide_high();
                    $wide = is_wide();
                    if (($wide == 0 || $wide_high == 0 && ($param[0] == 'bottom' || $param[0] == 'top')) && (get_option('site_closed') == '0' || $GLOBALS['IS_ACTUALLY_ADMIN'] || has_specific_permission(get_member(), 'access_closed_site'))) {
                        $tp_value = request_page('panel_' . $param[0], false, array_key_exists(1, $param) ? $param[1] : NULL, NULL);
                        $sub_children = array();
                        $tp_value->handle_symbol_preprocessing();
                        if ($GLOBALS['RECORD_TEMPLATES_TREE']) {
                            $children[] = array(':panel: ' . $param[0], $sub_children, isset($tp_value->fresh) ? $tp_value->fresh : false);
                        }
                        $value = $tp_value->evaluate();
                    } else {
                        $value = '';
                    }
                } else {
                    $value = '';
                }
            } else {
                $value = '';
            }
            $LOADED_PANELS[serialize($param)] = $value;
            return;
        case 'JS_TEMPCODE':
            if ($GLOBALS['RECORD_TEMPLATES_TREE']) {
                if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                    return;
                }
                $param = $bit[3];
                foreach ($param as $i => $p) {
                    if (is_object($p)) {
                        $param[$i] = $p->evaluate();
                    }
                }
                $temp = javascript_tempcode(array_key_exists(0, $param) ? $param[0] : NULL);
                $children[] = array(':container', $temp->children, $temp->fresh);
            }
            return;
        case 'CSS_TEMPCODE':
            if ($GLOBALS['RECORD_TEMPLATES_TREE']) {
                if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                    return;
                }
                $temp = css_tempcode();
                $children[] = array(':container', $temp->children, $temp->fresh);
            }
            return;
        case 'LOAD_PAGE':
            if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                return;
            }
            $param = $bit[3];
            foreach ($param as $i => $p) {
                if (is_object($p)) {
                    $param[$i] = $p->evaluate();
                }
            }
            global $LOADED_PAGES;
            if (array_key_exists(serialize($param), $LOADED_PAGES)) {
                return;
            }
            if (array_key_exists(0, $param)) {
                if (strpos($param[0], ':') !== false) {
                    $param = array_reverse(explode(':', $param[0], 2));
                }
                $being_included = !array_key_exists(2, $param) || $param[2] == '1';
                $tp_value = request_page($param[0], false, array_key_exists(1, $param) ? $param[1] : NULL, NULL, $being_included);
                if ($GLOBALS['RECORD_TEMPLATES_TREE']) {
                    $children[] = array(':page: ' . $param[0], $tp_value->children, $tp_value->fresh);
                }
            } else {
                $tp_value = new ocp_tempcode();
            }
            $LOADED_PAGES[serialize($param)] = $tp_value;
            return;
        case 'FRACTIONAL_EDITABLE':
            require_javascript('javascript_fractional_edit');
            return;
    }
}
Exemple #2
0
/**
 * 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;
}