includes/render.php
changeset 1003 28e2f75d66fd
parent 971 bc8f3ab74e5e
child 1027 98c052fc3337
equal deleted inserted replaced
1002:4d1bb8deee88 1003:28e2f75d66fd
   572   /**
   572   /**
   573    * Parses internal links (wikilinks) in a block of text.
   573    * Parses internal links (wikilinks) in a block of text.
   574    * @param string Text to process
   574    * @param string Text to process
   575    * @param string Optional. If included will be used as a template instead of using the default syntax.
   575    * @param string Optional. If included will be used as a template instead of using the default syntax.
   576    * @param bool If false, does not add wikilink-nonexistent or check for exsistence of pages. Can reduce DB queries; defualts to true.
   576    * @param bool If false, does not add wikilink-nonexistent or check for exsistence of pages. Can reduce DB queries; defualts to true.
       
   577    * @param string Page ID. If specified, class="currentpage" will be added to links if they match the given page ID and namespace
       
   578    * @param string Namespace. If specified, class="currentpage" will be added to links if they match the given page ID and namespace
   577    * @return string
   579    * @return string
   578    */
   580    */
   579   
   581   
   580   public static function parse_internal_links($text, $tplcode = false, $do_exist_check = true)
   582   public static function parse_internal_links($text, $tplcode = false, $do_exist_check = true, $match_page_id = false, $match_namespace = false)
   581   {
   583   {
   582     global $db, $session, $paths, $template, $plugins; // Common objects
   584     global $db, $session, $paths, $template, $plugins; // Common objects
   583     
   585     
   584     if ( is_string($tplcode) )
   586     if ( is_string($tplcode) )
   585     {
   587     {
   604       
   606       
   605       $url = makeUrl($pid_clean, false, true) . $hash;
   607       $url = makeUrl($pid_clean, false, true) . $hash;
   606       $inner_text = $matches[2][$i];
   608       $inner_text = $matches[2][$i];
   607       $quot = '"';
   609       $quot = '"';
   608       $exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"';
   610       $exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"';
       
   611       
       
   612       if ( $match_page_id && $match_namespace && $pid_clean === $paths->get_pathskey($match_page_id, $match_namespace) )
       
   613         $exists .= ' class="currentpage"';
   609       
   614       
   610       if ( $tplcode )
   615       if ( $tplcode )
   611       {
   616       {
   612         $parser->assign_vars(array(
   617         $parser->assign_vars(array(
   613             'HREF' => $url,
   618             'HREF' => $url,
   634       
   639       
   635       $url = makeUrl($pid_clean, false, true);
   640       $url = makeUrl($pid_clean, false, true);
   636       $inner_text = ( isPage($pid_clean) ) ? htmlspecialchars(get_page_title($pid_clean)) : htmlspecialchars($matches[1][$i]);
   641       $inner_text = ( isPage($pid_clean) ) ? htmlspecialchars(get_page_title($pid_clean)) : htmlspecialchars($matches[1][$i]);
   637       $quot = '"';
   642       $quot = '"';
   638       $exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"';
   643       $exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"';
       
   644       
       
   645       if ( $match_page_id && $match_namespace && $pid_clean === $paths->get_pathskey($match_page_id, $match_namespace) )
       
   646         $exists .= ' class="currentpage"';
   639       
   647       
   640       if ( $tplcode )
   648       if ( $tplcode )
   641       {
   649       {
   642         $parser->assign_vars(array(
   650         $parser->assign_vars(array(
   643             'HREF' => $url,
   651             'HREF' => $url,