Beispiel #1
0
 /**
  * Standard modular run function for snippet hooks. Generates XHTML to insert into a page using AJAX.
  *
  * @return tempcode  The snippet
  */
 function run()
 {
     $sup = get_param('block_map_sup', '', true);
     $_map = get_param('block_map', false, true);
     if ($sup != '') {
         $_map .= ',' . $sup;
     }
     require_code('blocks');
     $map = block_params_str_to_arr($_map);
     if (!array_key_exists('block', $map)) {
         return new ocp_tempcode();
     }
     $auth_key = get_param_integer('auth_key');
     // Check permissions
     $test = $GLOBALS['SITE_DB']->query_value_null_ok('temp_block_permissions', 'p_block_constraints', array('p_session_id' => get_session_id(), 'id' => $auth_key));
     if (is_null($test) || !block_signature_check(block_params_str_to_arr($test), $map)) {
         require_lang('permissions');
         return paragraph(do_lang_tempcode('ACCESS_DENIED__ACCESS_DENIED', escape_html($map['block'])));
     }
     // Cleanup
     $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'temp_block_permissions WHERE p_time<' . strval(time() - 60 * 60 * intval(get_option('session_expiry_time'))));
     // Return block snippet
     global $CSSS, $JAVASCRIPTS;
     $CSSS = array();
     $JAVASCRIPTS = array();
     $out = new ocp_tempcode();
     $out->attach(symbol_tempcode('CSS_TEMPCODE'));
     $out->attach(symbol_tempcode('JS_TEMPCODE'));
     $out->attach(do_block($map['block'], $map));
     return $out;
 }
/**
 * 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;
    }
}
Beispiel #3
0
    $msgs = BoincPrivateMessage::enum("userid={$logged_in_user->id}");
    foreach ($msgs as $msg) {
        $x = "pm_select_{$msg->id}";
        if (post_str($x, true)) {
            $msg = BoincPrivateMessage::lookup_id($msg->id);
            $msg->delete();
        }
    }
    Header("Location: pm.php?action=inbox&deleted=1");
}
if ($action == "inbox") {
    do_inbox($logged_in_user);
} elseif ($action == "read") {
    do_read($logged_in_user);
} elseif ($action == "new") {
    do_new($logged_in_user);
} elseif ($action == "delete") {
    do_delete($logged_in_user);
} elseif ($action == "send") {
    do_send($logged_in_user);
} elseif ($action == "block") {
    do_block($logged_in_user);
} elseif ($action == "confirmedblock") {
    do_confirmedblock($logged_in_user);
} elseif ($action == "delete_selected") {
    do_delete_selected($logged_in_user);
} else {
    error_page(tra("Unknown action"));
}
page_tail();
$cvs_version_tracker[] = "\$Id: pm.php 14077 2007-11-03 04:26:47Z davea \$";
Beispiel #4
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;
}
Beispiel #5
0
 /**
  * The UI to view a poll.
  *
  * @return tempcode		The UI
  */
 function view()
 {
     $title = get_page_title('POLL');
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('POLL_ARCHIVE'))));
     $id = get_param_integer('id');
     $_GET['poll_id'] = strval($id);
     $rows = $GLOBALS['SITE_DB']->query_select('poll', array('*'), array('id' => $id), '', 1);
     if (!array_key_exists(0, $rows)) {
         return warn_screen($title, do_lang_tempcode('MISSING_RESOURCE'));
     }
     $myrow = $rows[0];
     // Views
     if (get_db_type() != 'xml') {
         $myrow['poll_views']++;
         $GLOBALS['SITE_DB']->query_update('poll', array('poll_views' => $myrow['poll_views']), array('id' => $id), '', 1, NULL, false, true);
     }
     $date_raw = is_null($myrow['date_and_time']) ? '' : strval($myrow['date_and_time']);
     $add_date_raw = strval($myrow['add_time']);
     $edit_date_raw = is_null($myrow['edit_date']) ? '' : strval($myrow['edit_date']);
     $date = get_timezoned_date($myrow['date_and_time']);
     $add_date = get_timezoned_date($myrow['add_time']);
     $edit_date = get_timezoned_date($myrow['edit_date']);
     $_title = get_translated_text($myrow['question']);
     list($rating_details, $comment_details, $trackback_details) = embed_feedback_systems(get_page_name(), strval($id), $myrow['allow_rating'], $myrow['allow_comments'], $myrow['allow_trackbacks'], is_null($myrow['date_and_time']) ? 0 : 1, $myrow['submitter'], build_url(array('page' => '_SELF', 'type' => 'view', 'id' => $id), '_SELF', NULL, false, false, true), $_title, get_value('comment_forum__polls'));
     if (has_actual_page_access(NULL, 'cms_polls', NULL, NULL) && has_edit_permission('high', get_member(), $myrow['submitter'], 'cms_polls')) {
         $edit_url = build_url(array('page' => 'cms_polls', 'type' => '_ed', 'id' => $id), get_module_zone('cms_polls'));
     } else {
         $edit_url = new ocp_tempcode();
     }
     $poll_details = do_block('main_poll');
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $myrow['add_time']), 'creator' => $GLOBALS['FORUM_DRIVER']->get_username($myrow['submitter']), 'publisher' => '', 'modified' => is_null($myrow['edit_date']) ? '' : date('Y-m-d', $myrow['edit_date']), 'type' => 'Poll', 'title' => $_title, 'identifier' => '_SEARCH:polls:view:' . strval($id), 'description' => '', 'image' => find_theme_image('bigicons/polls'));
     return do_template('POLL_SCREEN', array('_GUID' => '1463a42354c3ad154e2c6bb0c96be3b9', 'TITLE' => $title, 'ID' => strval($id), 'DATE_RAW' => $date_raw, 'ADD_DATE_RAW' => $add_date_raw, 'EDIT_DATE_RAW' => $edit_date_raw, 'DATE' => $date, 'ADD_DATE' => $add_date, 'EDIT_DATE' => $edit_date, 'VIEWS' => integer_format($myrow['poll_views']), 'TRACKBACK_DETAILS' => $trackback_details, 'RATING_DETAILS' => $rating_details, 'COMMENT_DETAILS' => $comment_details, 'EDIT_URL' => $edit_url, 'POLL_DETAILS' => $poll_details));
 }