Пример #1
0
/**
 * Get hidden fields for a form representing 'keep_x'. If we are having a GET form instead of a POST form, we need to do this. This function also encodes the page name, as we'll always want that.
 *
 * @param  ID_TEXT		The page for the form to go to (blank: don't attach)
 * @param  boolean		Whether to keep all elements of the current URL represented in this form (rather than just the keep_ fields, and page)
 * @param  ?array			A list of parameters to exclude (NULL: don't exclude any)
 * @return tempcode		The builtup hidden form fields
 */
function _build_keep_form_fields($page = '', $keep_all = false, $exclude = NULL)
{
    if (is_null($exclude)) {
        $exclude = array();
    }
    if ($page == '_SELF') {
        $page = get_page_name();
    }
    $out = new ocp_tempcode();
    if (count($_GET) > 0) {
        foreach ($_GET as $key => $val) {
            if (!is_string($val)) {
                continue;
            }
            if (get_magic_quotes_gpc()) {
                $val = stripslashes($val);
            }
            if ((substr($key, 0, 5) == 'keep_' || $keep_all) && !in_array($key, $exclude) && $key != 'page' && !skippable_keep($key, $val)) {
                $out->attach(form_input_hidden($key, $val));
            }
        }
    }
    if ($page != '') {
        $out->attach(form_input_hidden('page', $page));
    }
    return $out;
}
/**
 * Put the contents of a page inside an iframe. This is typically used when a page is being used to traverse a result-set that spans multiple screens.
 *
 * @param  tempcode		The title
 * @param  ?integer		The time between refreshes (NULL: do not refresh)
 * @param  ?mixed			Data. A refresh will only happen if an AJAX-check indicates this data has changed (NULL: no check)
 * @return ?tempcode		The page output to finish off our current page stream such that it will spawn the iframe (NULL: not internalised)
 */
function internalise_own_screen($title, $refresh_time = NULL, $refresh_if_changed = NULL)
{
    if (get_value('no_frames') === '1' || get_param_integer('no_frames', 0) == 1 || get_param_integer('keep_no_frames', 0) == 1) {
        return NULL;
    }
    if (!has_js()) {
        return NULL;
    }
    // We need JS to make this a seamless process
    if (strpos(ocp_srv('REQUEST_URI'), '/iframe.php') !== false) {
        return NULL;
    }
    // This is already in the iframe
    require_javascript('javascript_ajax');
    require_javascript('javascript_iframe_screen');
    $url = find_script('iframe') . '?zone=' . rawurlencode(get_zone_name()) . '&wide_high=1&utheme=' . rawurlencode($GLOBALS['FORUM_DRIVER']->get_theme());
    foreach (array_merge($_GET, $_POST) as $key => $param) {
        if (!is_string($param)) {
            continue;
        }
        if (substr($key, 0, 5) == 'keep_' && skippable_keep($key, $param)) {
            continue;
        }
        if (get_magic_quotes_gpc()) {
            $param = stripslashes($param);
        }
        $url .= '&' . $key . '=' . urlencode($param);
    }
    if (!is_null($refresh_if_changed)) {
        require_javascript('javascript_sound');
        $change_detection_url = find_script('change_detection') . '?whatever=1';
        foreach ($_GET as $key => $param) {
            if (!is_string($param)) {
                continue;
            }
            if (substr($key, 0, 5) == 'keep_' && skippable_keep($key, $param)) {
                continue;
            }
            if (get_magic_quotes_gpc()) {
                $param = stripslashes($param);
            }
            $change_detection_url .= '&' . $key . '=' . urlencode($param);
        }
    } else {
        $refresh_if_changed = '';
        $change_detection_url = '';
    }
    return do_template('IFRAME_SCREEN', array('_GUID' => '06554eb227428fd5c648dee3c5b38185', 'TITLE' => $title, 'REFRESH_IF_CHANGED' => md5(serialize($refresh_if_changed)), 'CHANGE_DETECTION_URL' => $change_detection_url, 'REFRESH_TIME' => is_null($refresh_time) ? '' : strval($refresh_time), 'IFRAME_URL' => $url));
}
/**
 * Get the tempcode for a results table title row. You would take the output of this, and feed it in as $fields_title, in a results_table function call.
 *
 * @param  array			The array of field titles that define the entries in the results table
 * @param  ?array			A map of sortable code (usually, db field names), to strings giving the human name for the sort order (NULL: no sortables)
 * @param  ID_TEXT		The parameter name used to store our sortable
 * @param  ID_TEXT		The current ordering ("$sortable $sort_order")
 * @param  string			GUID to pass to template
 * @return tempcode		The generated title
 */
function results_field_title($values, $sortables = NULL, $order_param = 'sort', $current_ordering = '', $guid = 'fbcaf8b021e3939bfce1dce9ff8ed63a')
{
    if (is_null($sortables)) {
        $sortables = array();
    }
    $cells = new ocp_tempcode();
    foreach ($values as $value) {
        $found = mixed();
        foreach ($sortables as $key => $sortable) {
            $_value = is_object($value) ? $value->evaluate() : $value;
            if (is_string($sortable) && $sortable == $_value || is_object($sortable) && $sortable->evaluate() == $_value) {
                $found = $key;
                break;
            }
        }
        if (!is_null($found)) {
            if (strpos(ocp_srv('REQUEST_URI'), '/iframe.php') !== false) {
                $cat_url = find_script('iframe') . '?zone=' . get_zone_name();
                $url_array = array_merge($_GET, $_POST);
                unset($url_array[$order_param]);
                foreach ($url_array as $key => $param) {
                    if (is_array($param)) {
                        continue;
                    }
                    if ($key == 'wide_high') {
                        continue;
                    }
                    if (substr($key, 0, 5) == 'keep_' && skippable_keep($key, $param)) {
                        continue;
                    }
                    if ($param === '_SELF') {
                        $param = get_page_name();
                    }
                    if (get_magic_quotes_gpc()) {
                        $param = stripslashes($param);
                    }
                    $cat_url .= '&' . $key . '=' . urlencode($param);
                }
                $sort_url_asc = $cat_url . '&' . $order_param . '=' . urlencode($found) . ' ASC';
                $sort_url_desc = $cat_url . '&' . $order_param . '=' . urlencode($found) . ' DESC';
            } else {
                $sort_url_asc = get_self_url(false, false, array($order_param => $found . ' ASC'), true);
                $sort_url_desc = get_self_url(false, false, array($order_param => $found . ' DESC'), true);
            }
            $sort_asc_selected = $current_ordering == $found . ' ASC';
            $sort_desc_selected = $current_ordering == $found . ' DESC';
            $cells->attach(do_template('RESULTS_TABLE_FIELD_TITLE_SORTABLE', array('_GUID' => $guid, 'VALUE' => $value, 'SORT_ASC_SELECTED' => $sort_asc_selected, 'SORT_DESC_SELECTED' => $sort_desc_selected, 'SORT_URL_DESC' => $sort_url_desc, 'SORT_URL_ASC' => $sort_url_asc)));
        } else {
            $cells->attach(do_template('RESULTS_TABLE_FIELD_TITLE', array('_GUID' => $guid, 'VALUE' => $value)));
        }
    }
    return $cells;
}
/**
 * Helper function to work out a results browser URL.
 *
 * @param  array			Map of GET array segments to use (others will be added by this function)
 * @param  array			Map of POST array segments (relayed as GET) to use
 * @param  ?ID_TEXT		The page type this browser is browsing through (e.g. 'category') (NULL: none)
 * @param  ?mixed			The virtual root category this browser uses (NULL: no such concept for our results browser)
 * @param  ?mixed			The category ID we are browsing in (NULL: not applicable)
 * @param  boolean		Whether to keep get data when browsing through
 * @param  ID_TEXT		Hash component to URL
 * @return mixed			The URL
 */
function _build_results_browser_cat_url($url_array, $post_array, $type, $root, $category_id, $keep_all, $hash)
{
    if (!is_null($category_id)) {
        if (!is_string($category_id)) {
            $category_id = strval($category_id);
        }
    }
    $url_array = array_merge($url_array, $post_array);
    if (!is_null($type)) {
        $url_array['type'] = $type;
    }
    if (!is_null($root)) {
        $url_array['root'] = $root;
    }
    if (!is_null($category_id)) {
        $url_array['id'] = $category_id;
        $url_array['kfs' . $category_id] = NULL;
        // For OCF. We don't need this anymore because we're using 'start' explicitly here
    }
    if (strpos(ocp_srv('REQUEST_URI'), '/iframe.php') !== false) {
        $cat_url = make_string_tempcode(find_script('iframe') . '?zone=' . get_zone_name());
        if ($keep_all) {
            $url_array = array_merge($_GET, $_POST, $url_array);
        }
        foreach ($url_array as $key => $param) {
            if ($key == 'wide_high') {
                continue;
            }
            if (is_array($param)) {
                continue;
            }
            if (substr($key, 0, 5) == 'keep_' && skippable_keep($key, $param)) {
                continue;
            }
            if ($param === '_SELF') {
                $param = get_page_name();
            }
            if (get_magic_quotes_gpc()) {
                $param = stripslashes($param);
            }
            if ($key != 'zone') {
                $cat_url->attach('&' . $key . '=' . urlencode($param));
            }
        }
    } else {
        $cat_url = build_url($url_array, '_SELF', NULL, $keep_all, false, false, $hash);
    }
    return $cat_url;
}
Пример #5
0
/**
 * Attempt to use mod_rewrite to improve this URL.
 *
 * @param  ID_TEXT		The name of the zone for this
 * @param  array			A map of variables to include in our URL
 * @param  boolean		Force inclusion of the index.php name into a short URL, so something may tack on extra parameters to the result here
 * @return ?URLPATH		The improved URL (NULL: couldn't do anything)
 */
function _url_rewrite_params($zone_name, $vars, $force_index_php = false)
{
    global $URL_REMAPPINGS;
    if ($URL_REMAPPINGS === NULL) {
        $old_style = get_option('htm_short_urls') != '1';
        require_code('url_remappings');
        $URL_REMAPPINGS = get_remappings($old_style);
    }
    // Find mapping
    foreach ($URL_REMAPPINGS as $_remapping) {
        list($remapping, $target, $require_full_coverage) = $_remapping;
        //		if (count($remapping)!=$num_vars) continue;
        $good = true;
        $last_key_num = count($remapping);
        $loop_cnt = 0;
        foreach ($remapping as $key => $val) {
            $loop_cnt++;
            $last = $loop_cnt == $last_key_num;
            if (!is_string($val) && $val !== NULL) {
                $val = strval($val);
            }
            if (array_key_exists($key, $vars) && is_integer($vars[$key])) {
                $vars[$key] = strval($vars[$key]);
            }
            if (!((isset($vars[$key]) || $val === NULL && $key == 'type' && array_key_exists('id', $vars)) && ($key != 'page' || $vars[$key] != '' || $val === '') && (!array_key_exists($key, $vars) || $vars[$key] != '' || !$last) && ($val === NULL || $vars[$key] == $val))) {
                $good = false;
                break;
            }
        }
        if ($require_full_coverage) {
            foreach ($_GET as $key => $val) {
                if (!is_string($val)) {
                    continue;
                }
                if (substr($key, 0, 5) == 'keep_' && !skippable_keep($key, $val)) {
                    $good = false;
                }
            }
            foreach ($vars as $key => $val) {
                if (!array_key_exists($key, $remapping) && $val !== NULL && ($key != 'page' || $vars[$key] != '')) {
                    $good = false;
                }
            }
        }
        if ($good) {
            // We've found one, now let's sort out the target
            $makeup = $target;
            if ($GLOBALS['DEBUG_MODE']) {
                foreach ($vars as $key => $val) {
                    if (is_integer($val)) {
                        $vars[$key] = strval($val);
                    }
                }
            }
            $extra_vars = array();
            foreach (array_keys($remapping) as $key) {
                if (!isset($vars[$key])) {
                    continue;
                }
                $val = $vars[$key];
                unset($vars[$key]);
                $makeup = str_replace(strtoupper($key), ocp_url_encode_mini($val, true), $makeup);
            }
            if (!$require_full_coverage) {
                $extra_vars += $vars;
            }
            $makeup = str_replace('TYPE', 'misc', $makeup);
            if ($makeup == '') {
                $makeup .= get_zone_default_page($zone_name) . '.htm';
            }
            if ($extra_vars != array() || $force_index_php) {
                if (get_option('htm_short_urls') != '1') {
                    $makeup .= '/index.php';
                }
                $first = true;
                foreach ($extra_vars as $key => $val) {
                    if ($val === NULL) {
                        continue;
                    }
                    if (is_integer($key)) {
                        $key = strval($key);
                    }
                    if ($val === SELF_REDIRECT) {
                        $val = get_self_url(true, true);
                    }
                    $makeup .= ($first ? '?' : '&') . $key . '=' . ocp_url_encode($val, true);
                    $first = false;
                }
            }
            return $makeup;
        }
    }
    return NULL;
}
Пример #6
0
/**
 * String to tack onto URL to keep 'keep_' parameters
 *
 * @param  array			Parameters passed to the symbol (0=whether this starts off the query string, 1=force session append even if it's also available a session cookie e.g. when put into download manager)
 * @return string			The result.
 */
function keep_symbol($param)
{
    $value = '';
    $get_vars = $_GET;
    if (isset($param[1]) && $param[1] == '1' && is_null(get_bot_type()) && !array_key_exists('keep_session', $get_vars)) {
        $get_vars['keep_session'] = strval(get_session_id());
    }
    if (count($get_vars) > 0) {
        $first = false;
        if (isset($param[0]) && $param[0] == '1') {
            $first = true;
        }
        foreach ($get_vars as $key => $val) {
            if (!is_string($key)) {
                $key = strval($key);
            }
            if (get_magic_quotes_gpc() && is_string($val)) {
                $val = stripslashes($val);
            }
            if (substr($key, 0, 5) == 'keep_' && strpos($key, '_expand_') === false && (!skippable_keep($key, $val) || $key == 'keep_session' && is_null(get_bot_type()) && isset($param[1]) && $param[1] == '1') && is_string($val)) {
                $value .= ($first ? '?' : '&') . urlencode($key) . '=' . ocp_url_encode($val);
                $first = false;
            }
        }
    }
    return $value;
}