includes/render.php
changeset 311 a007145a0ff6
parent 195 eec079676fe7
child 313 854eecfada20
child 317 f8356d9c3481
equal deleted inserted replaced
309:a1ccf990db6b 311:a007145a0ff6
    39   }
    39   }
    40   
    40   
    41   function getPage($page_id, $namespace, $wiki = 1, $smilies = true, $filter_links = true, $redir = true, $render = true)
    41   function getPage($page_id, $namespace, $wiki = 1, $smilies = true, $filter_links = true, $redir = true, $render = true)
    42   {
    42   {
    43     global $db, $session, $paths, $template, $plugins; // Common objects
    43     global $db, $session, $paths, $template, $plugins; // Common objects
    44     dc_here('render: page requested<br />ID/namespace: '."$page_id, $namespace<br />Wiki mode: $wiki<br />Smilies: ".(string)$smilies."<br />Allow redirects: ".(string)$redir);
       
    45     
    44     
    46     $perms =& $session;
    45     $perms =& $session;
    47     
    46     
    48     if ( $page_id != $paths->cpage['urlname_nons'] || $namespace != $paths->namespace )
    47     if ( $page_id != $paths->cpage['urlname_nons'] || $namespace != $paths->namespace )
    49     {
    48     {
    79     $chartag = $row['char_tag'];
    78     $chartag = $row['char_tag'];
    80     unset($row); // Free some memory
    79     unset($row); // Free some memory
    81     
    80     
    82     if ( preg_match("#^\#redirect \[\[([^\]\r\n\a\t]+?)\]\]#", $message, $m) && $redir && ( !isset($_GET['redirect']) || ( isset($_GET['redirect']) && $_GET['redirect'] != 'no' ) ) )
    81     if ( preg_match("#^\#redirect \[\[([^\]\r\n\a\t]+?)\]\]#", $message, $m) && $redir && ( !isset($_GET['redirect']) || ( isset($_GET['redirect']) && $_GET['redirect'] != 'no' ) ) )
    83     {
    82     {
    84       dc_here('render: looks like a redirect page to me...');
       
    85       $old = $paths->cpage;
    83       $old = $paths->cpage;
    86       $a = RenderMan::strToPageID($m[1]);
    84       $a = RenderMan::strToPageID($m[1]);
    87       $a[0] = str_replace(' ', '_', $a[0]);
    85       $a[0] = str_replace(' ', '_', $a[0]);
    88       
    86       
    89       $pageid = str_replace(' ', '_', $paths->nslist[$a[1]] . $a[0]);
    87       $pageid = str_replace(' ', '_', $paths->nslist[$a[1]] . $a[0]);
    90       $paths->page = $pageid;
    88       $paths->page = $pageid;
    91       $paths->cpage = $paths->pages[$pageid];
    89       $paths->cpage = $paths->pages[$pageid];
    92       //die('<pre>'.print_r($paths->cpage,true).'</pre>');
    90       //die('<pre>'.print_r($paths->cpage,true).'</pre>');
    93       
    91       
    94       dc_here('render: wreckin\' $template, and reloading the theme vars to match the new page<br />This might get messy!');
       
    95       
       
    96       unset($template);
    92       unset($template);
    97       unset($GLOBALS['template']);
    93       unset($GLOBALS['template']);
    98       
    94       
    99       $GLOBALS['template'] = new template();
    95       $GLOBALS['template'] = new template();
   100       global $template;
    96       global $template;
   106       
   102       
   107       return $data;
   103       return $data;
   108     }
   104     }
   109     else if(preg_match('#^\#redirect \[\[(.+?)\]\]#', $message, $m) && isset($_GET['redirect']) && $_GET['redirect'] == 'no')
   105     else if(preg_match('#^\#redirect \[\[(.+?)\]\]#', $message, $m) && isset($_GET['redirect']) && $_GET['redirect'] == 'no')
   110     {
   106     {
   111       dc_here('render: looks like a redirect page to me...');
       
   112       dc_here('render: skipping redirect as requested on URI');
       
   113       preg_match('#^\#redirect \[\[(.+)\]\]#', $message, $m);
   107       preg_match('#^\#redirect \[\[(.+)\]\]#', $message, $m);
   114       $m[1] = str_replace(' ', '_', $m[1]);
   108       $m[1] = str_replace(' ', '_', $m[1]);
   115       $message = preg_replace('#\#redirect \[\[(.+)\]\]#', '<nowiki><div class="mdg-infobox"><table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td valign="top"><img alt="Cute wet-floor icon" src="'.scriptPath.'/images/redirector.png" /></td><td valign="top" style="padding-left: 10px;"><b>This page is a <i>redirector</i>.</b><br />This means that this page will not show its own content by default. Instead it will display the contents of the page it redirects to.<br /><br />To create a redirect page, make the <i>first characters</i> in the page content <tt>#redirect [[Page_ID]]</tt>. For more information, see the Enano <a href="http://enanocms.org/Help:Wiki_formatting">Wiki formatting guide</a>.<br /><br />This page redirects to <a href="'.makeUrl($m[1]).'">'.$paths->pages[$m[1]]['name'].'</a>.</td></tr></table></div><br /><hr style="margin-left: 1em; width: 200px;" /></nowiki>', $message);
   109       $message = preg_replace('#\#redirect \[\[(.+)\]\]#', '<nowiki><div class="mdg-infobox"><table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td valign="top"><img alt="Cute wet-floor icon" src="'.scriptPath.'/images/redirector.png" /></td><td valign="top" style="padding-left: 10px;"><b>This page is a <i>redirector</i>.</b><br />This means that this page will not show its own content by default. Instead it will display the contents of the page it redirects to.<br /><br />To create a redirect page, make the <i>first characters</i> in the page content <tt>#redirect [[Page_ID]]</tt>. For more information, see the Enano <a href="http://enanocms.org/Help:Wiki_formatting">Wiki formatting guide</a>.<br /><br />This page redirects to <a href="'.makeUrl($m[1]).'">'.$paths->pages[$m[1]]['name'].'</a>.</td></tr></table></div><br /><hr style="margin-left: 1em; width: 200px;" /></nowiki>', $message);
   116     }
   110     }
   117     $session->disallow_password_grab();
   111     $session->disallow_password_grab();
   118     dc_here('render: alright, got the text, formatting...');
       
   119     return ($render) ? RenderMan::render($message, $wiki, $smilies, $filter_links) : $message;
   112     return ($render) ? RenderMan::render($message, $wiki, $smilies, $filter_links) : $message;
   120   }
   113   }
   121   
   114   
   122   function getTemplate($id, $parms)
   115   function getTemplate($id, $parms)
   123   {
   116   {
   124     global $db, $session, $paths, $template, $plugins; // Common objects
   117     global $db, $session, $paths, $template, $plugins; // Common objects
   125     dc_here('render: template requested: '.$id);
       
   126     if(!isset($paths->pages[$paths->nslist['Template'].$id])) 
   118     if(!isset($paths->pages[$paths->nslist['Template'].$id])) 
   127     {
   119     {
   128       return '[['.$paths->nslist['Template'].$id.']]';
   120       return '[['.$paths->nslist['Template'].$id.']]';
   129     }
   121     }
   130     if(isset($paths->template_cache[$id]))
   122     if(isset($paths->template_cache[$id]))
   159   }
   151   }
   160   
   152   
   161   function fetch_template_text($id)
   153   function fetch_template_text($id)
   162   {
   154   {
   163     global $db, $session, $paths, $template, $plugins; // Common objects
   155     global $db, $session, $paths, $template, $plugins; // Common objects
   164     dc_here('render: template raw data requested: '.$id);
       
   165     if(!isset($paths->pages[$paths->nslist['Template'].$id])) 
   156     if(!isset($paths->pages[$paths->nslist['Template'].$id])) 
   166     {
   157     {
   167       return '[['.$paths->nslist['Template'].$id.']]';
   158       return '[['.$paths->nslist['Template'].$id.']]';
   168     }
   159     }
   169     if(isset($paths->template_cache[$id]))
   160     if(isset($paths->template_cache[$id]))