/** * Decide how to show a comcode page in the search results. * * @param ID_TEXT The zone for the page * @param ID_TEXT The page name * @param string What search hooks the search is being limited to (blank: not limited) * @return tempcode The tempcode showing the comcode page */ function decide_template($zone, $page, $limit_to) { global $SEARCH__CONTENT_BITS; require_code('xhtml'); $url = build_url(array('page' => $page), $zone); /* if ($limit_to=='') // If we're not limited to searching comcode pages, then we must show it is a Comcode page return put_in_standard_box(hyperlink($url,escape_html($page)),escape_html($page)'COMCODE_PAGE')); else return paragraph(hyperlink($url,$page));*/ // $_summary=request_page($page,true,$zone,NULL,true); // $summary=$_summary->evaluate(); $_summary = seo_meta_get_for('comcode_page', $zone . ':' . $page); $summary = $_summary[1]; if ($summary == '') { $page_request = _request_page($page, $zone); if (strpos($page_request[0], 'COMCODE') === false) { return new ocp_tempcode(); } $comcode_file = $page_request[count($page_request) - 1]; if (file_exists($comcode_file)) { global $LAX_COMCODE; $LAX_COMCODE = true; /*$temp_summary=comcode_to_tempcode(file_get_contents($comcode_file,FILE_TEXT),NULL,true); Tempcode compiler slowed things down so easier just to show full thing $_temp_summary=$temp_summary->evaluate(); if (strlen($_temp_summary)<500) { $summary=$_temp_summary; } else { $entity='…'; if (function_exists('ocp_mark_as_escaped')) ocp_mark_as_escaped($entity); $pos=false;//strpos($_temp_summary,'<span class="comcode_highlight">'); if ($pos===false) $pos=0; $pos2=max(0,$pos-250); $summary=(($pos2==0)?'':$entity).xhtml_substr($_temp_summary,$pos2,500).$entity; }*/ $GLOBALS['OVERRIDE_SELF_ZONE'] = $zone; $backup_search__contents_bits = $SEARCH__CONTENT_BITS; $SEARCH__CONTENT_BITS = NULL; // We do not want highlighting, as it'll result in far too much Comcode being parsed (ok for short snippets, not many full pages!) $temp_summary = request_page($page, true, $zone, strpos($comcode_file, '/comcode_custom/') ? 'comcode_custom' : 'comcode', true); $SEARCH__CONTENT_BITS = $backup_search__contents_bits; $GLOBALS['OVERRIDE_SELF_ZONE'] = NULL; $LAX_COMCODE = false; $_temp_summary = $temp_summary->evaluate(); global $LOADED_PAGES; $LOADED_PAGES = array(); // Decache this, or we'll eat up a tonne of RAM $summary = generate_text_summary($_temp_summary, is_null($SEARCH__CONTENT_BITS) ? array() : $SEARCH__CONTENT_BITS); } } $tpl = do_template('COMCODE_PAGE_PREVIEW', array('_GUID' => '79cd9e7d0b63ee916c4cd74b26c2f652', 'PAGE' => $page, 'ZONE' => $zone, 'URL' => $url, 'SUMMARY' => $summary)); require_lang('comcode'); $title = do_lang_tempcode('_SEARCH_RESULT_COMCODE_PAGE', escape_html($page)); global $LAST_COMCODE_PARSED_TITLE; if ($LAST_COMCODE_PARSED_TITLE != '') { $title = do_lang_tempcode('_SEARCH_RESULT_COMCODE_PAGE_NICE', escape_html($LAST_COMCODE_PARSED_TITLE)); } $tree = comcode_breadcrumbs($page, $zone); if (!$tree->is_empty()) { $tpl->attach(paragraph(do_lang_tempcode('LOCATED_IN', $tree))); } return put_in_standard_box($tpl, $title); }
/** * Get a UI element of a route from a known Comcode page back to the declared root of the tree. * * @param ID_TEXT The Comcode page name * @param ID_TEXT The Comcode page zone * @param ID_TEXT The virtual root * @param boolean Whether not to put a link at this point in the navigation tree (usually, because the viewer is already at it) * @param integer The number of jumps we have gone through so far (cuts out after 10 as a failsafe) * @return tempcode The navigation element */ function comcode_breadcrumbs($the_page, $the_zone, $root = '', $no_link_for_me_sir = true, $jumps = 0) { if ($jumps == 10) { return new ocp_tempcode(); } $map = array('page' => $the_page); if ($jumps == 0) { $map['root'] = $the_page; } elseif ($root != '') { $map['root'] = $root; } $url = build_url($map, $the_zone); if ($the_page == '') { return new ocp_tempcode(); } if ($the_page == $root) { if ($no_link_for_me_sir) { return new ocp_tempcode(); } $_title = $GLOBALS['SITE_DB']->query_value_null_ok('cached_comcode_pages', 'cc_page_title', array('the_page' => $the_page, 'the_zone' => $the_zone)); $title = NULL; if ($_title !== NULL) { $title = get_translated_text($_title, NULL, NULL, true); } if ($_title === NULL) { $title = escape_html($the_page); } return hyperlink($url, $title, false, false, do_lang_tempcode('GO_BACKWARDS_TO', @html_entity_decode(strip_tags($title), ENT_QUOTES, get_charset())), NULL, NULL, 'up'); } global $PT_PAIR_CACHE_CP; if (!array_key_exists($the_page, $PT_PAIR_CACHE_CP)) { $page_rows = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages a JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'comcode_pages b ON (a.the_page=b.the_page AND a.the_zone=b.the_zone)', array('cc_page_title', 'p_parent_page', 'string_index'), array('a.the_page' => $the_page, 'a.the_zone' => $the_zone), '', 1, NULL, false, array('string_index', 'cc_page_title')); if (!array_key_exists(0, $page_rows)) { request_page($the_page, false, $the_zone, NULL, true); // It's not cached, force the issue and then try again... $page_rows = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages a JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'comcode_pages b ON (a.the_page=b.the_page AND a.the_zone=b.the_zone)', array('cc_page_title', 'p_parent_page', 'string_index'), array('a.the_page' => $the_page, 'a.the_zone' => $the_zone), '', 1, NULL, false, array('string_index', 'cc_page_title')); if (!array_key_exists(0, $page_rows)) { $_title = $the_page; $PT_PAIR_CACHE_CP[$the_page] = array(); $PT_PAIR_CACHE_CP[$the_page]['cc_page_title'] = escape_html($_title); $PT_PAIR_CACHE_CP[$the_page]['p_parent_page'] = NULL; } } if (array_key_exists(0, $page_rows)) { $PT_PAIR_CACHE_CP[$the_page] = $page_rows[0]; $_title = get_translated_text($PT_PAIR_CACHE_CP[$the_page]['cc_page_title'], NULL, NULL, true); if ($_title === NULL) { $_title = $the_page; } $PT_PAIR_CACHE_CP[$the_page]['cc_page_title'] = $_title; } } $title = $PT_PAIR_CACHE_CP[$the_page]['cc_page_title']; if ($title === NULL) { $title = $the_page; } if (!$no_link_for_me_sir) { $tpl_url = $PT_PAIR_CACHE_CP[$the_page]['p_parent_page'] == '' ? new ocp_tempcode() : do_template('BREADCRUMB_ESCAPED'); $_title = is_object($title) ? $title->evaluate() : $title; $tooltip = $jumps == 0 ? do_lang_tempcode('VIRTUAL_ROOT') : do_lang_tempcode('GO_BACKWARDS_TO', @html_entity_decode(strip_tags($_title), ENT_QUOTES, get_charset())); $title = symbol_truncator(array($_title, BREADCRUMB_CROP_LENGTH, '1', '1'), 'spread', $tooltip); $tpl_url->attach(hyperlink($url, $title, false, false, strlen($_title) > BREADCRUMB_CROP_LENGTH ? new ocp_tempcode() : $tooltip, NULL, NULL, 'up')); } else { $tpl_url = new ocp_tempcode(); if ($jumps == 0) { $tpl_url = $PT_PAIR_CACHE_CP[$the_page]['p_parent_page'] == '' ? new ocp_tempcode() : do_template('BREADCRUMB_ESCAPED'); $_title = is_object($title) ? $title->evaluate() : $title; if ($_title != '') { $tpl_url->attach('<span>' . $_title . '</span>'); } } } if ($PT_PAIR_CACHE_CP[$the_page]['p_parent_page'] == $the_page) { fatal_exit(do_lang_tempcode('RECURSIVE_TREE_CHAIN', escape_html($the_page))); } $below = comcode_breadcrumbs($PT_PAIR_CACHE_CP[$the_page]['p_parent_page'], $the_zone, $root, false, $jumps + 1); $below->attach($tpl_url); return $below; }