コード例 #1
0
ファイル: urls.php プロジェクト: erico-deh/ocPortal
/**
 * Find the textual moniker for a typical ocPortal URL path. This will be called from inside build_url, based on details learned from a moniker hook (only if a hook exists to hint how to make the requested link SEO friendly).
 *
 * @param  array			The URL component map (must contain 'page', 'type', and 'id' if this function is to do anything).
 * @return ?string		The moniker ID (NULL: could not find)
 */
function find_id_moniker($url_parts)
{
    if (!isset($url_parts['id'])) {
        return NULL;
    }
    if (!isset($url_parts['type'])) {
        $url_parts['type'] = 'misc';
    }
    if ($url_parts['type'] === NULL) {
        $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 (!isset($url_parts['page'])) {
        return NULL;
    }
    if ($url_parts['id'] === NULL) {
        $url_parts['id'] = strval(db_get_first_id());
    }
    if (!is_numeric($url_parts['id'])) {
        return NULL;
    }
    // Does this URL arrangement support monikers?
    global $CONTENT_OBS;
    load_moniker_hooks();
    $looking_for = '_SEARCH:' . $url_parts['page'] . ':' . $url_parts['type'] . ':_WILD';
    $ob_info = isset($CONTENT_OBS[$looking_for]) ? $CONTENT_OBS[$looking_for] : NULL;
    if ($ob_info === NULL) {
        return NULL;
    }
    if ($ob_info['support_url_monikers']) {
        // Has to find existing if already there
        global $LOADED_MONIKERS;
        if (isset($LOADED_MONIKERS[$url_parts['page']][$url_parts['type']][$url_parts['id']])) {
            if (is_bool($LOADED_MONIKERS[$url_parts['page']][$url_parts['type']][$url_parts['id']])) {
                $or_list = '';
                foreach ($LOADED_MONIKERS as $page => $types) {
                    foreach ($types as $type => $ids) {
                        foreach ($ids as $id => $status) {
                            if (!is_bool($status)) {
                                continue;
                            }
                            if (is_integer($id)) {
                                $id = strval($id);
                            }
                            if ($or_list != '') {
                                $or_list .= ' OR ';
                            }
                            $or_list .= '(' . db_string_equal_to('m_resource_page', $page) . ' AND ' . db_string_equal_to('m_resource_type', $type) . ' AND ' . db_string_equal_to('m_resource_id', $id) . ')';
                            $LOADED_MONIKERS[$page][$type][$id] = $id;
                            // Will be replaced with correct value if it is looked up
                        }
                    }
                }
                $bak = $GLOBALS['NO_DB_SCOPE_CHECK'];
                $GLOBALS['NO_DB_SCOPE_CHECK'] = true;
                $query = 'SELECT m_moniker,m_resource_page,m_resource_type,m_resource_id FROM ' . get_table_prefix() . 'url_id_monikers WHERE m_deprecated=0 AND (' . $or_list . ')';
                $results = $GLOBALS['SITE_DB']->query($query);
                $GLOBALS['NO_DB_SCOPE_CHECK'] = $bak;
                foreach ($results as $result) {
                    $LOADED_MONIKERS[$result['m_resource_page']][$result['m_resource_type']][$result['m_resource_id']] = $result['m_moniker'];
                }
            }
            $test = $LOADED_MONIKERS[$url_parts['page']][$url_parts['type']][$url_parts['id']];
        } else {
            $bak = $GLOBALS['NO_DB_SCOPE_CHECK'];
            $GLOBALS['NO_DB_SCOPE_CHECK'] = true;
            $test = $GLOBALS['SITE_DB']->query_value_null_ok('url_id_monikers', 'm_moniker', array('m_deprecated' => 0, 'm_resource_page' => $url_parts['page'], 'm_resource_type' => $url_parts['type'], 'm_resource_id' => is_integer($url_parts['id']) ? strval($url_parts['id']) : $url_parts['id']));
            $GLOBALS['NO_DB_SCOPE_CHECK'] = $bak;
            $LOADED_MONIKERS[$url_parts['page']][$url_parts['type']][$url_parts['id']] = $test;
        }
        if (is_string($test)) {
            return $test;
        }
        // Otherwise try to generate a new one
        require_code('urls2');
        return autogenerate_new_url_moniker($ob_info, $url_parts);
    }
    return NULL;
}
コード例 #2
0
/**
 * 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;
    }
}
コード例 #3
0
ファイル: urls2.php プロジェクト: erico-deh/ocPortal
/**
 * Take a moniker and it's page link details, and make a full path from it.
 *
 * @param  ID_TEXT		Page name.
 * @param  ID_TEXT		Screen type code.
 * @param  ID_TEXT		Resource ID.
 * @param  string			Pathless moniker.
 * @return string			The fully qualified moniker.
 */
function _give_moniker_scope($page, $type, $id, $main)
{
    // Does this URL arrangement support monikers?
    global $CONTENT_OBS;
    load_moniker_hooks();
    $found = false;
    $looking_for = '_SEARCH:' . $page . ':' . $type . ':_WILD';
    $ob_info = isset($CONTENT_OBS[$looking_for]) ? $CONTENT_OBS[$looking_for] : NULL;
    $moniker = $main;
    if (is_null($ob_info)) {
        return $moniker;
    }
    if (!is_null($ob_info['parent_category_field'])) {
        // Lookup DB record so we can discern the category
        $bak = $GLOBALS['NO_DB_SCOPE_CHECK'];
        $GLOBALS['NO_DB_SCOPE_CHECK'] = true;
        $select = array($ob_info['id_field']);
        if (substr($ob_info['title_field'], 0, 5) != 'EVAL:' && substr($ob_info['title_field'], 0, 5) != 'CALL:') {
            $select[] = $ob_info['title_field'];
        }
        if (!is_null($ob_info['parent_category_field'])) {
            $select[] = $ob_info['parent_category_field'];
        }
        $id_flat = mixed();
        if ($ob_info['id_field_numeric']) {
            $id_flat = intval($id);
        } else {
            $id_flat = $id;
        }
        $_moniker_src = $GLOBALS['SITE_DB']->query_select($ob_info['table'], $select, array($ob_info['id_field'] => $id_flat));
        $GLOBALS['NO_DB_SCOPE_CHECK'] = $bak;
        if (!array_key_exists(0, $_moniker_src)) {
            return $moniker;
        }
        // been deleted?
        // Discern the path (will effectively recurse, due to find_id_moniker call)
        $view_category_pagelink_pattern = explode(':', $ob_info['view_category_pagelink_pattern']);
        $parent = $_moniker_src[0][$ob_info['parent_category_field']];
        if (is_integer($parent)) {
            $parent = strval($parent);
        }
        if (is_null($parent) || $parent === 'root' || $parent === '' || $parent == strval(db_get_first_id())) {
            $tree = NULL;
        } else {
            $tree = find_id_moniker(array('page' => $view_category_pagelink_pattern[1], 'type' => $view_category_pagelink_pattern[2], 'id' => $parent));
        }
        // Okay, so our full tree path is as follows
        if (!is_null($tree)) {
            $moniker = $tree . '/' . $main;
        }
    }
    return $moniker;
}