includes/render.php
author Dan
Fri, 09 Nov 2007 23:36:49 -0500
changeset 250 acb9d021b860
parent 189 fd0e9c7a7b28
child 193 ebe99e82a59a
child 195 eec079676fe7
child 207 861807631f70
permissions -rw-r--r--
Database name can now contain dashes (as per requested at http://forum.enanocms.org/viewtopic.php?f=5&t=14); corrected some installer behavior issues with connecting as root and setting up permissions resulting in logs not being flushed, configs not being inserted, and what have you.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     1
<?php
73
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 67
diff changeset
     2
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     3
/*
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
142
ca9118d9c0f2 Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
parents: 136
diff changeset
     5
 * Version 1.0.2 (Coblynau)
73
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 67
diff changeset
     6
 * Copyright (C) 2006-2007 Dan Fuhry
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     7
 * render.php - handles fetching pages and parsing them into HTML
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     8
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     9
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    10
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    11
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    13
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    14
 */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    15
 
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    16
class RenderMan {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    17
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    18
  function strToPageID($string)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    19
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    20
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    21
    $k = array_keys($paths->nslist);
136
f2ee42f026f7 Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents: 133
diff changeset
    22
    $proj_alt = 'Project:';
f2ee42f026f7 Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents: 133
diff changeset
    23
    if ( substr($string, 0, (strlen($proj_alt))) == $proj_alt )
f2ee42f026f7 Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents: 133
diff changeset
    24
    {
f2ee42f026f7 Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents: 133
diff changeset
    25
      $ns = 'Project';
f2ee42f026f7 Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents: 133
diff changeset
    26
      $pg = substr($string, strlen($proj_alt), strlen($string));
f2ee42f026f7 Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents: 133
diff changeset
    27
      return Array($pg, $ns);
f2ee42f026f7 Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents: 133
diff changeset
    28
    }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    29
    for($i=0;$i<sizeof($paths->nslist);$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    30
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    31
      $ln = strlen($paths->nslist[$k[$i]]);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    32
      if(substr($string, 0, $ln) == $paths->nslist[$k[$i]])
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    33
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    34
        $ns = $k[$i];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    35
        $pg = substr($string, strlen($paths->nslist[$ns]), strlen($string));
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    36
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    37
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    38
    return Array($pg, $ns);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    39
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    40
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    41
  function getPage($page_id, $namespace, $wiki = 1, $smilies = true, $filter_links = true, $redir = true, $render = true)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    42
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    43
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    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);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    45
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    46
    $perms =& $session;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    47
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    48
    if ( $page_id != $paths->cpage['urlname_nons'] || $namespace != $paths->namespace )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    49
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    50
      unset($perms);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    51
      unset($perms); // PHP <5.1.5 Zend bug
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    52
      $perms = $session->fetch_page_acl($page_id, $namespace);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    53
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    54
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    55
    if(!$perms->get_permissions('read'))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    56
      return 'Access denied ('.$paths->nslist[$namespace].$page_id.')';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    57
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    58
    if($wiki == 0 || $render == false)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    59
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    60
      if(!$perms->get_permissions('view_source'))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    61
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    62
        return 'Access denied ('.$paths->nslist[$namespace].$page_id.')';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    63
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    64
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    65
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    66
    $q = $db->sql_query('SELECT page_text,char_tag FROM '.table_prefix.'page_text WHERE page_id=\''.$db->escape($page_id).'\' AND namespace=\''.$db->escape($namespace).'\';');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    67
    if ( !$q )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    68
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    69
      $db->_die('Method called was: RenderMan::getPage(\''.$page_id.'\', \''.$namespace.'\');.');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    70
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    71
    if ( $db->numrows() < 1 )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    72
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    73
      return false;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    74
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    75
    $row = $db->fetchrow();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    76
    $db->free_result();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    77
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    78
    $message = $row['page_text'];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    79
    $chartag = $row['char_tag'];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    80
    unset($row); // Free some memory
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    81
    
133
af0f6ec48de3 Fully implemented password complexity enforcement; added encryption for passwords on registration form; some baby steps taken towards supporting international usernames - this is not working very well, we might need a hackish fix; TODO: implement password strength meter into installer UI and get international usernames 100% working
Dan
parents: 91
diff changeset
    82
    if ( preg_match("#^\#redirect \[\[([^\]\r\n\a\t]+?)\]\]#", $message, $m) && $redir && ( !isset($_GET['redirect']) || ( isset($_GET['redirect']) && $_GET['redirect'] != 'no' ) ) )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    83
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    84
      dc_here('render: looks like a redirect page to me...');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    85
      $old = $paths->cpage;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    86
      $a = RenderMan::strToPageID($m[1]);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    87
      $a[0] = str_replace(' ', '_', $a[0]);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    88
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    89
      $pageid = str_replace(' ', '_', $paths->nslist[$a[1]] . $a[0]);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    90
      $paths->page = $pageid;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    91
      $paths->cpage = $paths->pages[$pageid];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    92
      //die('<pre>'.print_r($paths->cpage,true).'</pre>');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    93
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    94
      dc_here('render: wreckin\' $template, and reloading the theme vars to match the new page<br />This might get messy!');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    95
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    96
      unset($template);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    97
      unset($GLOBALS['template']);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    98
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    99
      $GLOBALS['template'] = new template();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   100
      global $template;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   101
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   102
      $template->template(); // Tear down and rebuild the template parser
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   103
      $template->load_theme($session->theme, $session->style);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   104
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   105
      $data = '<div><small>(Redirected from <a href="'.makeUrlNS($old['namespace'], $old['urlname_nons'], 'redirect=no', true).'">'.$old['name'].'</a>)</small></div>'.RenderMan::getPage($a[0], $a[1], $wiki, $smilies, $filter_links, false /* Enforces a maximum of one redirect */);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   106
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   107
      return $data;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   108
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   109
    else if(preg_match('#^\#redirect \[\[(.+?)\]\]#', $message, $m) && isset($_GET['redirect']) && $_GET['redirect'] == 'no')
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   110
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   111
      dc_here('render: looks like a redirect page to me...');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   112
      dc_here('render: skipping redirect as requested on URI');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   113
      preg_match('#^\#redirect \[\[(.+)\]\]#', $message, $m);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   114
      $m[1] = str_replace(' ', '_', $m[1]);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   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);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   116
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   117
    $session->disallow_password_grab();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   118
    dc_here('render: alright, got the text, formatting...');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   119
    return ($render) ? RenderMan::render($message, $wiki, $smilies, $filter_links) : $message;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   120
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   121
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   122
  function getTemplate($id, $parms)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   123
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   124
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   125
    dc_here('render: template requested: '.$id);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   126
    if(!isset($paths->pages[$paths->nslist['Template'].$id])) 
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   127
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   128
      return '[['.$paths->nslist['Template'].$id.']]';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   129
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   130
    if(isset($paths->template_cache[$id]))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   131
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   132
      $text = $paths->template_cache[$id];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   133
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   134
    else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   135
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   136
      $text = RenderMan::getPage($id, 'Template', 0, true, true, 0);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   137
      $paths->template_cache[$id] = $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   138
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   139
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   140
    $text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   141
    $text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   142
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   143
    preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   144
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   145
    foreach($matchlist[1] as $m)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   146
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   147
      if(isset($parms[((int)$m)+1])) 
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   148
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   149
        $p = $parms[((int)$m)+1];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   150
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   151
      else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   152
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   153
        $p = '<b>Notice:</b> RenderMan::getTemplate(): Parameter '.$m.' is not set';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   154
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   155
      $text = str_replace('(_'.$m.'_)', $p, $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   156
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   157
    $text = RenderMan::include_templates($text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   158
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   159
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   160
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   161
  function fetch_template_text($id)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   162
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   163
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   164
    dc_here('render: template raw data requested: '.$id);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   165
    if(!isset($paths->pages[$paths->nslist['Template'].$id])) 
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   166
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   167
      return '[['.$paths->nslist['Template'].$id.']]';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   168
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   169
    if(isset($paths->template_cache[$id]))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   170
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   171
      $text = $paths->template_cache[$id];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   172
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   173
    else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   174
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   175
      $text = RenderMan::getPage($id, 'Template', 0, false, false, false, false);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   176
      $paths->template_cache[$id] = $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   177
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   178
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   179
    if ( is_string($text) )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   180
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   181
      $text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   182
      $text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   183
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   184
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   185
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   186
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   187
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   188
  function render($text, $wiki = 1, $smilies = true, $filter_links = true)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   189
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   190
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   191
    if($smilies)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   192
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   193
      $text = RenderMan::smilieyize($text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   194
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   195
    if($wiki == 1)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   196
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   197
      $text = RenderMan::next_gen_wiki_format($text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   198
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   199
    elseif($wiki == 2)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   200
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   201
      $text = $template->tplWikiFormat($text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   202
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   203
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   204
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   205
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   206
  function PlainTextRender($text, $wiki = 1, $smilies = false, $filter_links = true)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   207
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   208
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   209
    if($smilies)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   210
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   211
      $text = RenderMan::smilieyize($text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   212
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   213
    if($wiki == 1)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   214
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   215
      $text = RenderMan::next_gen_wiki_format($text, true);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   216
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   217
    elseif($wiki == 2)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   218
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   219
      $text = $template->tplWikiFormat($text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   220
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   221
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   222
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   223
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   224
  function next_gen_wiki_format($text, $plaintext = false, $filter_links = true, $do_params = false)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   225
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   226
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   227
    $random_id = md5( time() . mt_rand() );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   228
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   229
    // Strip out <nowiki> sections and PHP code
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   230
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   231
    $php = preg_match_all('#<\?php(.*?)\?>#is', $text, $phpsec);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   232
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   233
    for($i=0;$i<sizeof($phpsec[1]);$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   234
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   235
      $text = str_replace('<?php'.$phpsec[1][$i].'?>', '{PHP:'.$random_id.':'.$i.'}', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   236
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   237
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   238
    $nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   239
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   240
    for($i=0;$i<sizeof($nowiki[1]);$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   241
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   242
      $text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   243
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   244
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   245
    $text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   246
    if ( $paths->namespace == 'Template' )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   247
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   248
      $text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   249
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   250
    
163
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   251
    $code = $plugins->setHook('render_wikiformat_pre');
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   252
    foreach ( $code as $cmd )
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   253
    {
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   254
      eval($cmd);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   255
    }
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   256
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   257
    if ( !$plaintext )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   258
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   259
      // Process images
142
ca9118d9c0f2 Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
parents: 136
diff changeset
   260
      $text = RenderMan::process_image_tags($text, $taglist);
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
   261
      $text = RenderMan::process_imgtags_stage2($text, $taglist);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   262
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   263
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   264
    if($do_params)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   265
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   266
      preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   267
      foreach($matchlist[1] as $m)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   268
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   269
        $text = str_replace('(_'.$m.'_)', $paths->getParam((int)$m), $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   270
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   271
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   272
    
174
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   273
    //$template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   274
    $template_regex = "/\{\{(.+)((\n|\|[ ]*([A-z0-9]+)[ ]*=[ ]*(.+))*)\}\}/isU";
63
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   275
    $i = 0;
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   276
    while ( preg_match($template_regex, $text) )
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   277
    {
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   278
      $i++;
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   279
      if ( $i == 5 )
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   280
        break;
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   281
      $text = RenderMan::include_templates($text);
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   282
    }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   283
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   284
    $text = process_tables($text);
142
ca9118d9c0f2 Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
parents: 136
diff changeset
   285
    $text = RenderMan::parse_internal_links($text);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   286
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   287
    $wiki =& Text_Wiki::singleton('Mediawiki');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   288
    if($plaintext)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   289
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   290
      $wiki->setRenderConf('Plain', 'wikilink', 'view_url', contentPath);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   291
      $result = $wiki->transform($text, 'Plain');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   292
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   293
    else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   294
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   295
      $wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   296
      $wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   297
      $result = $wiki->transform($text, 'Xhtml');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   298
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   299
    
163
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   300
    // HTML fixes
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   301
    $result = preg_replace('#<tr>([\s]*?)<\/tr>#is', '', $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   302
    $result = preg_replace('#<p>([\s]*?)<\/p>#is', '', $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   303
    $result = preg_replace('#<br />([\s]*?)<table#is', '<table', $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   304
    $result = str_replace("<pre><code>\n", "<pre><code>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   305
    $result = preg_replace("/<p><table([^>]*?)><\/p>/", "<table\\1>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   306
    $result = str_replace("<br />\n</td>", "\n</td>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   307
    $result = str_replace("<p><tr>", "<tr>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   308
    $result = str_replace("<tr><br />", "<tr>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   309
    $result = str_replace("</tr><br />", "</tr>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   310
    $result = str_replace("</table><br />", "</table>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   311
    $result = preg_replace('/<\/table>$/', "</table><br /><br />", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   312
    $result = str_replace("<p></div></p>", "</div>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   313
    $result = str_replace("<p></table></p>", "</table>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   314
    
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   315
    $code = $plugins->setHook('render_wikiformat_post');
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   316
    foreach ( $code as $cmd )
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   317
    {
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   318
      eval($cmd);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   319
    }
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   320
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   321
    // Reinsert <nowiki> sections
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   322
    for($i=0;$i<$nw;$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   323
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   324
      $result = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', $nowiki[1][$i], $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   325
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   326
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   327
    // Reinsert PHP
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   328
    for($i=0;$i<$php;$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   329
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   330
      $result = str_replace('{PHP:'.$random_id.':'.$i.'}', '<?php'.$phpsec[1][$i].'?>', $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   331
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   332
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   333
    return $result;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   334
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   335
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   336
  
163
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   337
  function wikiFormat($message, $filter_links = true, $do_params = false, $plaintext = false)
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   338
  {
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   339
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   340
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   341
    return RenderMan::next_gen_wiki_format($message, $plaintext, $filter_links, $do_params);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   342
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   343
    $random_id = md5( time() . mt_rand() );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   344
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   345
    // Strip out <nowiki> sections
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   346
    $nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $message, $nowiki);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   347
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   348
    if(!$plaintext)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   349
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   350
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   351
      //return '<pre>'.print_r($nowiki,true).'</pre>';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   352
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   353
      for($i=0;$i<sizeof($nowiki[1]);$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   354
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   355
        $message = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   356
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   357
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   358
      $message = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   359
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   360
      //return '<pre>'.htmlspecialchars($message).'</pre>';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   361
      
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   362
      $message = RenderMan::process_image_tags($message);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   363
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   364
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   365
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   366
    if($do_params)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   367
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   368
      preg_match_all('#\(_([0-9]+)_\)#', $message, $matchlist);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   369
      foreach($matchlist[1] as $m)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   370
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   371
        $message = str_replace('(_'.$m.'_)', $paths->getParam((int)$m), $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   372
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   373
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   374
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   375
    $message = RenderMan::include_templates($message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   376
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   377
    // Reinsert <nowiki> sections
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   378
    for($i=0;$i<$nw;$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   379
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   380
      $message = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   381
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   382
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   383
    $message = process_tables($message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   384
    //if($message2 != $message) return '<pre>'.htmlspecialchars($message2).'</pre>';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   385
    //$message = str_replace(array('<table>', '</table>'), array('<nowiki><table>', '</table></nowiki>'), $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   386
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   387
    $wiki =& Text_Wiki::singleton('Mediawiki');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   388
    if($plaintext)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   389
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   390
      $wiki->setRenderConf('Plain', 'wikilink', 'view_url', contentPath);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   391
      $result = $wiki->transform($message, 'Plain');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   392
    } else {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   393
      $wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   394
      $wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   395
      $result = $wiki->transform($message, 'Xhtml');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   396
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   397
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   398
    // HTML fixes
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   399
    $result = preg_replace('#<tr>([\s]*?)<\/tr>#is', '', $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   400
    $result = preg_replace('#<p>([\s]*?)<\/p>#is', '', $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   401
    $result = preg_replace('#<br />([\s]*?)<table#is', '<table', $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   402
    $result = str_replace("<pre><code>\n", "<pre><code>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   403
    $result = preg_replace("/<p><table([^>]*?)><\/p>/", "<table\\1>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   404
    $result = str_replace("<br />\n</td>", "\n</td>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   405
    $result = str_replace("<p><tr>", "<tr>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   406
    $result = str_replace("<tr><br />", "<tr>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   407
    $result = str_replace("</tr><br />", "</tr>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   408
    $result = str_replace("</table></p>", "</table>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   409
    $result = str_replace("</table><br />", "</table>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   410
    $result = preg_replace('/<\/table>$/', "</table><br /><br />", $result);
163
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   411
    $result = str_replace("<p></div></p>", "</div>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   412
    $result = str_replace("<p></table></p>", "</table>", $result);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   413
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   414
    $result = str_replace('<nowiki>',  '&lt;nowiki&gt;',  $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   415
    $result = str_replace('</nowiki>', '&lt;/nowiki&gt;', $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   416
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   417
    return $result;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   418
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   419
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   420
  function destroy_javascript($message, $_php = false)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   421
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   422
    $message = preg_replace('#<(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '&lt;\\1\\2&gt;', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   423
    $message = preg_replace('#</(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '&lt;/\\1\\2&gt;', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   424
    $message = preg_replace('#(javascript|script|activex|chrome|about|applet):#is', '\\1&#058;', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   425
    if ( $_php )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   426
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   427
      // Left in only for compatibility
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   428
      $message = preg_replace('#&lt;(.*?)>#is', '<\\1>', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   429
      $message = preg_replace('#<(.*?)&gt;#is', '<\\1>', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   430
      $message = preg_replace('#<(\?|\?php|%)(.*?)(\?|%)>#is', '&lt;\\1\\2\\3&gt;', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   431
      // strip <a href="foo" onclick="bar();">-type attacks
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   432
      $message = preg_replace('#<([a-zA-Z:\-]+) (.*?)on([A-Za-z]*)=(.*?)>#is', '&lt;\\1\\2on\\3=\\4&gt;', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   433
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   434
    return $message;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   435
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   436
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   437
  function strip_php($message)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   438
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   439
    return RenderMan::destroy_javascript($message, true);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   440
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   441
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   442
  function sanitize_html($text)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   443
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   444
    $text = htmlspecialchars($text);
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   445
    $allowed_tags = Array('b', 'i', 'u', 'pre', 'code', 'tt', 'br', 'p', 'nowiki', '!--([\w\W]+)--');
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   446
    foreach($allowed_tags as $t)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   447
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   448
      $text = preg_replace('#&lt;'.$t.'&gt;(.*?)&lt;/'.$t.'&gt;#is', '<'.$t.'>\\1</'.$t.'>', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   449
      $text = preg_replace('#&lt;'.$t.' /&gt;#is', '<'.$t.' />', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   450
      $text = preg_replace('#&lt;'.$t.'&gt;#is', '<'.$t.'>', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   451
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   452
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   453
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   454
  
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   455
  /**
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   456
   * Parses internal links (wikilinks) in a block of text.
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   457
   * @param string Text to process
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   458
   * @return string
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   459
   */
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   460
  
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   461
  function parse_internal_links($text)
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   462
  {
136
f2ee42f026f7 Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents: 133
diff changeset
   463
    global $db, $session, $paths, $template, $plugins; // Common objects
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   464
    
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   465
    // stage 1 - links with alternate text
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   466
    preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\|(.+?)\]\]/', $text, $matches);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   467
    foreach ( $matches[0] as $i => $match )
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   468
    {
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   469
      list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   470
      $pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   471
      
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   472
      $url = makeUrl($pid_clean, false, true);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   473
      $inner_text = $matches[2][$i];
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   474
      $quot = '"';
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   475
      $exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"';
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   476
      
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   477
      $link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>";
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   478
      
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   479
      $text = str_replace($match, $link, $text);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   480
    }
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   481
    
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   482
    // stage 2 - links with no alternate text
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   483
    preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\]\]/', $text, $matches);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   484
    foreach ( $matches[0] as $i => $match )
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   485
    {
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   486
      list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   487
      $pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   488
      
159
f7e83b6db3be Fixed: RenderMan::parse_internal_links() problems with prepending Project: instead of Site_name: to project page alias-namespace links
Dan
parents: 142
diff changeset
   489
      $url = makeUrl($pid_clean, false, true);
f7e83b6db3be Fixed: RenderMan::parse_internal_links() problems with prepending Project: instead of Site_name: to project page alias-namespace links
Dan
parents: 142
diff changeset
   490
      $inner_text = ( isPage($pid_clean) ) ? htmlspecialchars(get_page_title($pid_clean)) : htmlspecialchars($matches[1][$i]);
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   491
      $quot = '"';
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   492
      $exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"';
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   493
      
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   494
      $link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>";
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   495
      
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   496
      $text = str_replace($match, $link, $text);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   497
    }
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   498
    
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   499
    return $text;
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   500
  }
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   501
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   502
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   503
   * Parses a partial template tag in wikitext, and return an array with the parameters.
63
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   504
   * @param string The portion of the template tag that contains the parameters.
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   505
   * @example
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   506
   * <code>
63
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   507
   foo = lorem ipsum
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   508
   bar = dolor sit amet
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   509
   * </code>
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   510
   * @return array Example:
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   511
   * [foo] => lorem ipsum
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   512
   * [bar] => dolor sit amet
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   513
   */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   514
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   515
  function parse_template_vars($input)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   516
  {
174
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   517
    if ( !preg_match('/^(\|[ ]*([A-z0-9_]+)([ ]*)=([ ]*)(.+?))*$/is', trim($input)) )
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   518
    {
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   519
      $using_pipes = false;
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   520
      $input = explode("\n", trim( $input ));
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   521
    }
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   522
    else
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   523
    {
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   524
      $using_pipes = true;
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   525
      $input = substr($input, 1);
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   526
      $input = explode("|", trim( $input ));
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   527
    }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   528
    $parms = Array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   529
    $current_line = '';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   530
    $current_parm = '';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   531
    foreach ( $input as $num => $line )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   532
    {
174
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   533
      if ( preg_match('/^[ ]*([A-z0-9_]+)([ ]*)=([ ]*)(.+?)$/is', $line, $matches) )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   534
      {
174
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   535
        $parm =& $matches[1];
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   536
        $text =& $matches[4];
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   537
        if ( $parm == $current_parm )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   538
        {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   539
          $current_line .= $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   540
        }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   541
        else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   542
        {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   543
          // New parameter
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   544
          if ( $current_parm != '' )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   545
            $parms[$current_parm] = $current_line;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   546
          $current_line = $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   547
          $current_parm = $parm;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   548
        }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   549
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   550
      else if ( $num == 0 )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   551
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   552
        // Syntax error
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   553
        return false;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   554
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   555
      else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   556
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   557
        $current_line .= "\n$line";
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   558
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   559
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   560
    if ( !empty($current_parm) && !empty($current_line) )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   561
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   562
      $parms[$current_parm] = $current_line;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   563
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   564
    return $parms;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   565
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   566
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   567
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   568
   * Processes all template tags within a block of wikitext.
174
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   569
   * Updated in 1.0.2 to also parse template tags in the format of {{Foo |a = b |b = c |c = therefore, a}}
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   570
   * @param string The text to process
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   571
   * @return string Formatted text
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   572
   * @example
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   573
   * <code>
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   574
   $text = '{{Template
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   575
     parm1 = Foo
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   576
     parm2 = Bar
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   577
     }}';
174
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   578
   $text = RenderMan::include_templates($text);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   579
   * </code>
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   580
   */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   581
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   582
  function include_templates($text)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   583
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   584
    global $db, $session, $paths, $template, $plugins; // Common objects
174
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   585
    // $template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   586
    $template_regex = "/\{\{(.+)(((\n|[ ]*\|)[ ]*([A-z0-9]+)[ ]*=[ ]*(.+))*)\}\}/isU";
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   587
    if ( $count = preg_match_all($template_regex, $text, $matches) )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   588
    {
174
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   589
      //die('<pre>' . print_r($matches, true) . '</pre>');
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   590
      for ( $i = 0; $i < $count; $i++ )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   591
      {
63
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   592
        $matches[1][$i] = sanitize_page_id($matches[1][$i]);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   593
        $parmsection = trim($matches[2][$i]);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   594
        if ( !empty($parmsection) )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   595
        {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   596
          $parms = RenderMan::parse_template_vars($parmsection);
174
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   597
          if ( !is_array($parms) )
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   598
            // Syntax error
4c5c2b66a34d SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents: 163
diff changeset
   599
            $parms = array();
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   600
        }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   601
        else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   602
        {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   603
          $parms = Array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   604
        }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   605
        if ( $tpl_code = RenderMan::fetch_template_text($matches[1][$i]) )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   606
        {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   607
          $parser = $template->makeParserText($tpl_code);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   608
          $parser->assign_vars($parms);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   609
          $text = str_replace($matches[0][$i], $parser->run(), $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   610
        }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   611
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   612
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   613
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   614
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   615
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   616
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   617
   * Preprocesses an HTML text string prior to being sent to MySQL.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   618
   * @param string $text
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   619
   * @param bool $strip_all_php - if true, strips all PHP regardless of user permissions. Else, strips PHP only if user level < USER_LEVEL_ADMIN.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   620
   */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   621
  function preprocess_text($text, $strip_all_php = true, $sqlescape = true)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   622
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   623
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   624
    $random_id = md5( time() . mt_rand() );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   625
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   626
    $can_do_php = ( $session->get_permissions('php_in_pages') && !$strip_all_php );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   627
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   628
    if ( !$can_do_php )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   629
    {
24
9ecc94c4c7f5 Fixed tons of bugs relating to non-templated pages
Dan
parents: 21
diff changeset
   630
      $text = sanitize_html($text, true);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   631
      // If we can't do PHP, we can't do Javascript either.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   632
      $text = RenderMan::destroy_javascript($text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   633
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   634
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   635
    // Strip out <nowiki> sections and PHP code
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   636
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   637
    $php = preg_match_all('#(<|&lt;)\?php(.*?)\?(>|&gt;)#is', $text, $phpsec);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   638
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   639
    //die('<pre>'.htmlspecialchars(print_r($phpsec, true))."\n".htmlspecialchars(print_r($text, true)).'</pre>');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   640
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   641
    for($i=0;$i<sizeof($phpsec[1]);$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   642
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   643
      $text = str_replace($phpsec[0][$i], '{PHP:'.$random_id.':'.$i.'}', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   644
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   645
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   646
    $nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   647
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   648
    for($i=0;$i<sizeof($nowiki[1]);$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   649
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   650
      $text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   651
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   652
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   653
    $text = str_replace('~~~~~', date('G:i, j F Y (T)'), $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   654
    $text = str_replace('~~~~', "[[User:$session->username|$session->username]] ".date('G:i, j F Y (T)'), $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   655
    $text = str_replace('~~~', "[[User:$session->username|$session->username]] ", $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   656
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   657
    // Reinsert <nowiki> sections
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   658
    for($i=0;$i<$nw;$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   659
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   660
      $text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   661
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   662
    // Reinsert PHP
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   663
    for($i=0;$i<$php;$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   664
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   665
      $phsec = ''.$phpsec[1][$i].'?php'.$phpsec[2][$i].'?'.$phpsec[3][$i].'';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   666
      if ( $strip_all_php )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   667
        $phsec = htmlspecialchars($phsec);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   668
      $text = str_replace('{PHP:'.$random_id.':'.$i.'}', $phsec, $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   669
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   670
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   671
    $text = ( $sqlescape ) ? $db->escape($text) : $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   672
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   673
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   674
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   675
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   676
  function smilieyize($text, $complete_urls = false)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   677
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   678
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   679
    $random_id = md5( time() . mt_rand() );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   680
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   681
    // Smileys array - eventually this will be fetched from the database by
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   682
    // RenderMan::initSmileys during initialization, but it will all be hardcoded for beta 2
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   683
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   684
    $smileys = Array(
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   685
      'O:-)'    => 'face-angel.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   686
      'O:)'     => 'face-angel.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   687
      'O=)'     => 'face-angel.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   688
      ':-)'     => 'face-smile.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   689
      ':)'      => 'face-smile.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   690
      '=)'      => 'face-smile-big.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   691
      ':-('     => 'face-sad.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   692
      ':('      => 'face-sad.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   693
      ';('      => 'face-sad.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   694
      ':-O'     => 'face-surprise.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   695
      ';-)'     => 'face-wink.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   696
      ';)'      => 'face-wink.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   697
      '8-)'     => 'face-glasses.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   698
      '8)'      => 'face-glasses.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   699
      ':-D'     => 'face-grin.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   700
      ':D'      => 'face-grin.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   701
      '=D'      => 'face-grin.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   702
      ':-*'     => 'face-kiss.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   703
      ':*'      => 'face-kiss.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   704
      '=*'      => 'face-kiss.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   705
      ':\'('    => 'face-crying.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   706
      ':-|'     => 'face-plain.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   707
      ':-\\'    => 'face-plain.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   708
      ':-/'     => 'face-plain.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   709
      ':joke:'  => 'face-plain.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   710
      ']:-&gt;' => 'face-devil-grin.png',
189
fd0e9c7a7b28 Automatic set of state on Oxygen sidebar portlets should work now; reimplemented parts of the template parser (again) to workaround some PHP/PCRE issues and add support for parser plugins
Dan
parents: 174
diff changeset
   711
      ']:->'    => 'face-devil-grin.png',
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   712
      ':kiss:'  => 'face-kiss.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   713
      ':-P'     => 'face-tongue-out.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   714
      ':P'      => 'face-tongue-out.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   715
      ':-p'     => 'face-tongue-out.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   716
      ':p'      => 'face-tongue-out.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   717
      ':-X'     => 'face-sick.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   718
      ':X'      => 'face-sick.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   719
      ':sick:'  => 'face-sick.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   720
      ':-]'     => 'face-oops.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   721
      ':]'      => 'face-oops.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   722
      ':oops:'  => 'face-oops.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   723
      ':-['     => 'face-embarassed.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   724
      ':['      => 'face-embarassed.png'
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   725
      );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   726
    /*
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   727
    $keys = array_keys($smileys);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   728
    foreach($keys as $k)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   729
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   730
      $regex1 = '#([\W]+)'.preg_quote($k).'([\s\n\r\.]+)#s';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   731
      $regex2 = '\\1<img alt="'.$k.'" title="'.$k.'" src="'.scriptPath.'/images/smilies/'.$smileys[$k].'" style="border: 0;" />\\2';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   732
      $text = preg_replace($regex1, $regex2, $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   733
    }                                                                      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   734
    */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   735
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   736
    // Strip out <nowiki> sections
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   737
    //return '<pre>'.htmlspecialchars($text).'</pre>';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   738
    $nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   739
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   740
    for($i=0;$i<sizeof($nowiki[1]);$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   741
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   742
      $text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   743
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   744
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   745
    $keys = array_keys($smileys);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   746
    foreach($keys as $k)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   747
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   748
      $t = str_hex($k);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   749
      $t = explode(' ', $t);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   750
      $s = '';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   751
      foreach($t as $b)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   752
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   753
        $s.='&#x'.$b.';';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   754
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   755
      $pfx = ( $complete_urls ) ? 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://'.$_SERVER['HTTP_HOST'] : '';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   756
      $text = str_replace(' '.$k, ' <nowiki><img title="'.$s.'" alt="'.$s.'" src="'.$pfx.scriptPath.'/images/smilies/'.$smileys[$k].'" style="border: 0;" /></nowiki>', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   757
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   758
    //*/
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   759
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   760
    // Reinsert <nowiki> sections
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   761
    for($i=0;$i<$nw;$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   762
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   763
      $text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   764
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   765
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   766
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   767
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   768
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   769
  /*
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   770
   * **** DEPRECATED ****
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   771
   * Replaces some critical characters in a string with MySQL-safe equivalents
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   772
   * @param $text string the text to escape
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   773
   * @return array key 0 is the escaped text, key 1 is the character tag
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   774
   * /
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   775
   
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   776
  function escape_page_text($text)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   777
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   778
    $char_tag = md5(microtime() . mt_rand());
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   779
    $text = str_replace("'",  "{APOS:$char_tag}",  $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   780
    $text = str_replace('"',  "{QUOT:$char_tag}",  $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   781
    $text = str_replace("\\", "{SLASH:$char_tag}", $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   782
    return Array($text, $char_tag);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   783
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   784
  */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   785
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   786
  /* **** DEPRECATED ****
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   787
   * Reverses the result of RenderMan::escape_page_text().
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   788
   * @param $text string the text to unescape
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   789
   * @param $char_tag string the character tag
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   790
   * @return string
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   791
   * /
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   792
   
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   793
  function unescape_page_text($text, $char_tag)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   794
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   795
    $text = str_replace("{APOS:$char_tag}",  "'",  $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   796
    $text = str_replace("{QUOT:$char_tag}",  '"',  $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   797
    $text = str_replace("{SLASH:$char_tag}", "\\", $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   798
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   799
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   800
  */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   801
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   802
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   803
   * Generates a summary of the differences between two texts, and formats it as XHTML.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   804
   * @param $str1 string the first block of text
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   805
   * @param $str2 string the second block of text
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   806
   * @return string
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   807
   */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   808
  function diff($str1, $str2)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   809
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   810
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   811
    $str1 = explode("\n", $str1);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   812
    $str2 = explode("\n", $str2);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   813
    $diff = new Diff($str1, $str2);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   814
    $renderer = new TableDiffFormatter();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   815
    return '<table class="diff">'.$renderer->format($diff).'</table>';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   816
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   817
  
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   818
  /**
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   819
   * Changes wikitext image tags to HTML.
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   820
   * @param string The wikitext to process
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   821
   * @param array Will be overwritten with the list of HTML tags (the system uses tokens for TextWiki compatibility)
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   822
   * @return string
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   823
   */
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   824
  
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   825
  function process_image_tags($text, &$taglist)
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   826
  {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   827
    global $db, $session, $paths, $template, $plugins; // Common objects
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   828
    
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   829
    $s_delim = "\xFF";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   830
    $f_delim = "\xFF";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   831
    $taglist = array();
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   832
    
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   833
    // Wicked huh?
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
   834
    $regex = '/\[\[:' . $paths->nslist['File'] . '([\w\s0-9_\(\)!@%\^\+\|\.-]+?)((\|thumb)|(\|([0-9]+)x([0-9]+)))?(\|left|\|right)?(\|raw|\|(.+))?\]\]/i';
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   835
    
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   836
    preg_match_all($regex, $text, $matches);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   837
    
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   838
    foreach ( $matches[0] as $i => $match )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   839
    {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   840
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   841
      $full_tag   =& $matches[0][$i];
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   842
      $filename   =& $matches[1][$i];
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   843
      $scale_type =& $matches[2][$i];
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   844
      $width      =& $matches[5][$i];
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   845
      $height     =& $matches[6][$i];
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   846
      $clear      =& $matches[7][$i];
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   847
      $caption    =& $matches[8][$i];
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   848
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   849
      if ( !isPage( $paths->nslist['File'] . $filename ) )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   850
      {
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
   851
        $text = str_replace($full_tag, '[[' . makeUrlNS('File', $filename) . ']]', $text);
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   852
        continue;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   853
      }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   854
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   855
      if ( $scale_type == '|thumb' )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   856
      {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   857
        $r_width  = 225;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   858
        $r_height = 225;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   859
        
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   860
        $url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   861
      }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   862
      else if ( !empty($width) && !empty($height) )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   863
      {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   864
        $r_width = $width;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   865
        $r_height = $height;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   866
        
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   867
        $url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   868
      }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   869
      else
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   870
      {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   871
        $url = makeUrlNS('Special', 'DownloadFile/' . $filename);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   872
      }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   873
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   874
      $img_tag = '<img src="' . $url . '" ';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   875
      
65
627d0a8a7819 Last-minute change to width/height on embedded images
Dan
parents: 63
diff changeset
   876
      // if ( isset($r_width) && isset($r_height) && $scale_type != '|thumb' )
627d0a8a7819 Last-minute change to width/height on embedded images
Dan
parents: 63
diff changeset
   877
      // {
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
   878
      //   $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" ';
65
627d0a8a7819 Last-minute change to width/height on embedded images
Dan
parents: 63
diff changeset
   879
      // }
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   880
      
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
   881
      $img_tag .= 'style="border-width: 0px; /* background-color: white; */" ';
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   882
      
85
7c68a18a27be AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents: 73
diff changeset
   883
      $code = $plugins->setHook('img_tag_parse_img');
7c68a18a27be AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents: 73
diff changeset
   884
      foreach ( $code as $cmd )
7c68a18a27be AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents: 73
diff changeset
   885
      {
7c68a18a27be AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents: 73
diff changeset
   886
        eval($cmd);
7c68a18a27be AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents: 73
diff changeset
   887
      }
7c68a18a27be AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents: 73
diff changeset
   888
      
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   889
      $img_tag .= '/>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   890
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   891
      $complete_tag = '';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   892
      
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
   893
      if ( !empty($scale_type) && $caption != '|raw' )
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   894
      {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   895
        $complete_tag .= '<div class="thumbnail" ';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   896
        $clear_text = '';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   897
        if ( !empty($clear) )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   898
        {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   899
          $side = ( $clear == '|left' ) ? 'left' : 'right';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   900
          $opposite = ( $clear == '|left' ) ? 'right' : 'left';
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   901
          $clear_text .= "float: $side; margin-$opposite: 20px;";
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   902
          $complete_tag .= 'style="' . $clear_text . '" ';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   903
        }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   904
        $complete_tag .= '>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   905
        
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   906
        $complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   907
        $complete_tag .= $img_tag;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   908
        $complete_tag .= '</a>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   909
        
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   910
        $mag_button = '<a href="' . makeUrlNS('File', $filename) . '" style="display: block; float: right; clear: right; margin: 0 0 10px 10px;"><img alt="[ + ]" src="' . scriptPath . '/images/thumbnail.png" style="border-width: 0px;" /></a>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   911
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   912
        if ( !empty($caption) )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   913
        {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   914
          $cap = substr($caption, 1);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   915
          $complete_tag .= $mag_button . $cap;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   916
        }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   917
        
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   918
        $complete_tag .= '</div>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   919
      }
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
   920
      else if ( $caption == '|raw' )
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
   921
      {
67
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
   922
        $complete_tag .= "$img_tag";
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
   923
        $taglist[$i] = $complete_tag;
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
   924
        
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
   925
        $repl = "{$s_delim}e_img_{$i}{$f_delim}";
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
   926
        $text = str_replace($full_tag, $repl, $text);
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
   927
        continue;
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
   928
      }
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   929
      else
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   930
      {
85
7c68a18a27be AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents: 73
diff changeset
   931
        $complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;"';
7c68a18a27be AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents: 73
diff changeset
   932
        $code = $plugins->setHook('img_tag_parse_link');
7c68a18a27be AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents: 73
diff changeset
   933
        foreach ( $code as $cmd )
7c68a18a27be AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents: 73
diff changeset
   934
        {
7c68a18a27be AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents: 73
diff changeset
   935
          eval($cmd);
7c68a18a27be AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents: 73
diff changeset
   936
        }
7c68a18a27be AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents: 73
diff changeset
   937
        $complete_tag .= '>';
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   938
        $complete_tag .= $img_tag;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   939
        $complete_tag .= '</a>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   940
      }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   941
      
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   942
      $complete_tag .= "\n\n";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   943
      $taglist[$i] = $complete_tag;
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   944
      
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   945
      $pos = strpos($text, $full_tag);
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   946
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   947
      while(true)
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   948
      {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   949
        $check1 = substr($text, $pos, 3);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   950
        $check2 = substr($text, $pos, 1);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   951
        if ( $check1 == '<p>' || $pos == 0 || $check2 == "\n" )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   952
        {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   953
          // die('found at pos '.$pos);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   954
          break;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   955
        }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   956
        $pos--;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   957
      }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   958
      
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   959
      $repl = "{$s_delim}e_img_{$i}{$f_delim}";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   960
      $text = substr($text, 0, $pos) . $repl . substr($text, $pos);
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   961
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   962
      $text = str_replace($full_tag, '', $text);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   963
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   964
      unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   965
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   966
    }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   967
    
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   968
    return $text;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   969
  }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   970
  
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   971
  /**
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   972
   * Finalizes processing of image tags.
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   973
   * @param string The preprocessed text
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   974
   * @param array The list of image tags created by RenderMan::process_image_tags()
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   975
   */
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   976
   
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   977
  function process_imgtags_stage2($text, $taglist)
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   978
  {
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   979
    $s_delim = "\xFF";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   980
    $f_delim = "\xFF";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   981
    foreach ( $taglist as $i => $tag )
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   982
    {
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   983
      $repl = "{$s_delim}e_img_{$i}{$f_delim}";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   984
      $text = str_replace($repl, $tag, $text);
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   985
    }               
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   986
    return $text;
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   987
  }
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   988
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   989
}
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   990
 
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   991
?>