includes/render.php
author Dan
Sat, 03 Jan 2009 17:54:26 -0500
changeset 799 4629ad98ee88
parent 798 ddfc1b554a08
child 800 9cdfe82c56cd
permissions -rw-r--r--
Added a couple of hooks for the registration form.
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
685
17ebe24cdf85 Rebranded as 1.1.5 (Caoineag alpha 5) and fixed a couple bugs related to CDN support in template_nodb and installerUI. Updated readme.
Dan
parents: 592
diff changeset
     5
 * Version 1.1.5 (Caoineag alpha 5)
536
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 507
diff changeset
     6
 * Copyright (C) 2006-2008 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
  
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
    18
  public static function strToPageID($string)
1
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
  
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
    41
  public static function getPage($page_id, $namespace, $wiki = 1, $smilies = true, $filter_links = true, $redir = true, $render = true)
1
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
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    45
    $perms =& $session;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    46
    
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
    47
    if ( $page_id != $paths->page_id || $namespace != $paths->namespace )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    48
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    49
      unset($perms);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    50
      unset($perms); // PHP <5.1.5 Zend bug
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    51
      $perms = $session->fetch_page_acl($page_id, $namespace);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    52
    }
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
    if(!$perms->get_permissions('read'))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    55
      return 'Access denied ('.$paths->nslist[$namespace].$page_id.')';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    56
    
457
d823e49e2e4e Fixed: RenderMan::getPage() failing with access denial when fetching template and view_source results in deny
Dan
parents: 322
diff changeset
    57
    if($namespace != 'Template' && ($wiki == 0 || $render == false))
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    58
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    59
      if(!$perms->get_permissions('view_source'))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    60
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    61
        return 'Access denied ('.$paths->nslist[$namespace].$page_id.')';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    62
      }
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
    $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
    66
    if ( !$q )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    67
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    68
      $db->_die('Method called was: RenderMan::getPage(\''.$page_id.'\', \''.$namespace.'\');.');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    69
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    70
    if ( $db->numrows() < 1 )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    71
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    72
      return false;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    73
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    74
    $row = $db->fetchrow();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    75
    $db->free_result();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    76
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    77
    $message = $row['page_text'];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    78
    $chartag = $row['char_tag'];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    79
    unset($row); // Free some memory
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    80
    
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
    81
    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
    82
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    83
      $old = $paths->cpage;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    84
      $a = RenderMan::strToPageID($m[1]);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    85
      $a[0] = str_replace(' ', '_', $a[0]);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    86
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    87
      $pageid = str_replace(' ', '_', $paths->nslist[$a[1]] . $a[0]);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    88
      $paths->page = $pageid;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    89
      $paths->cpage = $paths->pages[$pageid];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    90
      //die('<pre>'.print_r($paths->cpage,true).'</pre>');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    91
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    92
      unset($template);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    93
      unset($GLOBALS['template']);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    94
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    95
      $GLOBALS['template'] = new template();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    96
      global $template;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    97
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    98
      $template->template(); // Tear down and rebuild the template parser
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    99
      $template->load_theme($session->theme, $session->style);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   100
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   101
      $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
   102
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   103
      return $data;
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
    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
   106
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   107
      preg_match('#^\#redirect \[\[(.+)\]\]#', $message, $m);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   108
      $m[1] = str_replace(' ', '_', $m[1]);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   109
      $message = preg_replace('#\#redirect \[\[(.+)\]\]#', '<nowiki><div class="mdg-infobox"><table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td valign="top"><img alt="Cute wet-floor icon" src="'.scriptPath.'/images/redirector.png" /></td><td valign="top" style="padding-left: 10px;"><b>This page is a <i>redirector</i>.</b><br />This means that this page will not show its own content by default. Instead it will display the contents of the page it redirects to.<br /><br />To create a redirect page, make the <i>first characters</i> in the page content <tt>#redirect [[Page_ID]]</tt>. For more information, see the Enano <a href="http://enanocms.org/Help:Wiki_formatting">Wiki formatting guide</a>.<br /><br />This page redirects to <a href="'.makeUrl($m[1]).'">'.$paths->pages[$m[1]]['name'].'</a>.</td></tr></table></div><br /><hr style="margin-left: 1em; width: 200px;" /></nowiki>', $message);
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
    $session->disallow_password_grab();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   112
    return ($render) ? RenderMan::render($message, $wiki, $smilies, $filter_links) : $message;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   113
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   114
  
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   115
  public static function getTemplate($id, $parms)
1
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
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   118
    if(!isset($paths->pages[$paths->nslist['Template'].$id])) 
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   119
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   120
      return '[['.$paths->nslist['Template'].$id.']]';
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
    if(isset($paths->template_cache[$id]))
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
      $text = $paths->template_cache[$id];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   125
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   126
    else
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
      $text = RenderMan::getPage($id, 'Template', 0, true, true, 0);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   129
      $paths->template_cache[$id] = $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   130
    }
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 = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   133
    $text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   134
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   135
    preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   136
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   137
    foreach($matchlist[1] as $m)
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
      if(isset($parms[((int)$m)+1])) 
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   140
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   141
        $p = $parms[((int)$m)+1];
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
      else
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
        $p = '<b>Notice:</b> RenderMan::getTemplate(): Parameter '.$m.' is not set';
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
      $text = str_replace('(_'.$m.'_)', $p, $text);
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   148
      $text = str_replace('{{' . ( $m + 1 ) . '}}', $p, $text);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   149
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   150
    $text = RenderMan::include_templates($text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   151
    return $text;
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
  
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   154
  public static function fetch_template_text($id)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   155
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   156
    global $db, $session, $paths, $template, $plugins; // Common objects
745
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   157
    $fetch_ns = 'Template';
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   158
    if(!isset($paths->pages[$paths->nslist['Template'].$id])) 
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   159
    {
745
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   160
      // Transclusion of another page
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   161
      // 1.1.5: Now You, Too, Can Be A Template, Even If You're Just A Plain Old Article! (TM)
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   162
      $nssep = substr($paths->nslist['Special'], -1);
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   163
      $nslist = $paths->nslist;
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   164
      foreach ( $nslist as &$ns )
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   165
      {
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   166
        if ( $ns == '' )
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   167
          $ns = $nssep;
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   168
      }
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   169
      $prefixlist = array_flip($nslist);
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   170
      foreach ( $nslist as &$ns )
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   171
      {
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   172
        $ns = preg_quote($ns);
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   173
      }
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   174
      $nslist = implode('|', $nslist);
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   175
      if ( preg_match("/^($nslist)(.*?)$/", $id, $match) )
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   176
      {
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   177
        // in practice this should always be true but just to be safe...
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   178
        if ( isset($prefixlist[$match[1]]) )
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   179
        {
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   180
          $new_id = $paths->nslist[ $prefixlist[$match[1]] ] . sanitize_page_id($match[2]);
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   181
          if ( !isset($paths->pages[$new_id]) )
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   182
          {
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   183
            return "[[$new_id]]";
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   184
          }
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   185
          $fetch_ns = $prefixlist[$match[1]];
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   186
          $id = sanitize_page_id($match[2]);
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   187
        }
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   188
      }
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   189
      else
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   190
      {
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   191
        return '[['.$paths->nslist['Template'].$id.']]';
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   192
      }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   193
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   194
    if(isset($paths->template_cache[$id]))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   195
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   196
      $text = $paths->template_cache[$id];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   197
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   198
    else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   199
    {
745
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   200
      $text = RenderMan::getPage($id, $fetch_ns, 0, false, false, false, false);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   201
      $paths->template_cache[$id] = $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
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   204
    if ( is_string($text) )
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
      $text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   207
      $text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   208
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   209
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   210
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   211
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   212
  
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   213
  public static function render($text, $wiki = 1, $smilies = true, $filter_links = true)
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
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   216
    if($smilies)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   217
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   218
      $text = RenderMan::smilieyize($text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   219
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   220
    if($wiki == 1)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   221
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   222
      $text = RenderMan::next_gen_wiki_format($text);
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
    elseif($wiki == 2)
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
      $text = $template->tplWikiFormat($text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   227
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   228
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   229
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   230
  
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   231
  public static function PlainTextRender($text, $wiki = 1, $smilies = false, $filter_links = true)
1
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
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   234
    if($smilies)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   235
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   236
      $text = RenderMan::smilieyize($text);
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
    if($wiki == 1)
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
      $text = RenderMan::next_gen_wiki_format($text, true);
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
    elseif($wiki == 2)
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
      $text = $template->tplWikiFormat($text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   245
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   246
    return $text;
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
  
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   249
  public static function next_gen_wiki_format($text, $plaintext = false, $filter_links = true, $do_params = false)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   250
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   251
    global $db, $session, $paths, $template, $plugins; // Common objects
377
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   252
    global $lang;
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   253
    
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   254
    require_once(ENANO_ROOT.'/includes/wikiformat.php');
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   255
    require_once(ENANO_ROOT.'/includes/wikiengine/Tables.php');
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   256
    
382
2ccb55995aef Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents: 377
diff changeset
   257
    profiler_log("RenderMan: starting wikitext render");
2ccb55995aef Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents: 377
diff changeset
   258
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   259
    $random_id = md5( time() . mt_rand() );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   260
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   261
    // Strip out <nowiki> sections and PHP code
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   262
    
407
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   263
    $nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki);
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   264
    
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   265
    for($i=0;$i<sizeof($nowiki[1]);$i++)
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   266
    {
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   267
      $text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text);
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   268
    }
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   269
    
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   270
    $code = $plugins->setHook('render_wikiformat_veryearly');
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   271
    foreach ( $code as $cmd )
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   272
    {
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   273
      eval($cmd);
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   274
    }
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   275
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   276
    $php = preg_match_all('#<\?php(.*?)\?>#is', $text, $phpsec);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   277
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   278
    for($i=0;$i<sizeof($phpsec[1]);$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   279
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   280
      $text = str_replace('<?php'.$phpsec[1][$i].'?>', '{PHP:'.$random_id.':'.$i.'}', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   281
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   282
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   283
    $text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   284
    if ( $paths->namespace == 'Template' )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   285
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   286
      $text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   287
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   288
    
798
ddfc1b554a08 Redid error handler (it was causing some problems with gzip enabled)
Dan
parents: 745
diff changeset
   289
    preg_match_all('/<lang (?:code|id)="([a-z0-9_-]+)">([\w\W]+?)<\/lang>/', $text, $langmatch);
377
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   290
    foreach ( $langmatch[0] as $i => $match )
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   291
    {
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   292
      if ( $langmatch[1][$i] == $lang->lang_code )
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   293
      {
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   294
        $text = str_replace_once($match, $langmatch[2][$i], $text);
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   295
      }
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   296
      else
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   297
      {
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   298
        $text = str_replace_once($match, '', $text);
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   299
      }
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   300
    }
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   301
    
163
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   302
    $code = $plugins->setHook('render_wikiformat_pre');
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   303
    foreach ( $code as $cmd )
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   304
    {
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   305
      eval($cmd);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   306
    }
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   307
    
715
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   308
    //$template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   309
    $template_regex = "/\{\{(.+)((\n|\|[ ]*([A-z0-9]+)[ ]*=[ ]*(.+))*)\}\}/isU";
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   310
    $i = 0;
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   311
    while ( preg_match($template_regex, $text) )
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   312
    {
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   313
      $i++;
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   314
      if ( $i == 5 )
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   315
        break;
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   316
      $text = RenderMan::include_templates($text);
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   317
    }
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   318
    
798
ddfc1b554a08 Redid error handler (it was causing some problems with gzip enabled)
Dan
parents: 745
diff changeset
   319
    $code = $plugins->setHook('render_wikiformat_posttemplates');
ddfc1b554a08 Redid error handler (it was causing some problems with gzip enabled)
Dan
parents: 745
diff changeset
   320
    foreach ( $code as $cmd )
ddfc1b554a08 Redid error handler (it was causing some problems with gzip enabled)
Dan
parents: 745
diff changeset
   321
    {
ddfc1b554a08 Redid error handler (it was causing some problems with gzip enabled)
Dan
parents: 745
diff changeset
   322
      eval($cmd);
ddfc1b554a08 Redid error handler (it was causing some problems with gzip enabled)
Dan
parents: 745
diff changeset
   323
    }
ddfc1b554a08 Redid error handler (it was causing some problems with gzip enabled)
Dan
parents: 745
diff changeset
   324
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   325
    if ( !$plaintext )
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
      // 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
   328
      $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
   329
      $text = RenderMan::process_imgtags_stage2($text, $taglist);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   330
    }
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
    if($do_params)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   333
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   334
      preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   335
      foreach($matchlist[1] as $m)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   336
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   337
        $text = str_replace('(_'.$m.'_)', $paths->getParam((int)$m), $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   338
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   339
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   340
    
335
67bd3121a12e Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents: 326
diff changeset
   341
    // Before shipping it out to the renderer, replace spaces in between headings and paragraphs:
67bd3121a12e Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents: 326
diff changeset
   342
    $text = preg_replace('/<\/(h[0-9]|div|p)>([\s]+)<(h[0-9]|div|p)( .+?)?>/i', '</\\1><\\3\\4>', $text);
67bd3121a12e Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents: 326
diff changeset
   343
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   344
    $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
   345
    $text = RenderMan::parse_internal_links($text);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   346
    
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   347
    $wiki = Text_Wiki::singleton('Mediawiki');
1
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
      $wiki->setRenderConf('Plain', 'wikilink', 'view_url', contentPath);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   351
      $result = $wiki->transform($text, 'Plain');
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
    else
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
      $wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   356
      $wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   357
      $result = $wiki->transform($text, 'Xhtml');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   358
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   359
    
163
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   360
    // HTML fixes
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   361
    $result = preg_replace('#<tr>([\s]*?)<\/tr>#is', '', $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   362
    $result = preg_replace('#<p>([\s]*?)<\/p>#is', '', $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   363
    $result = preg_replace('#<br />([\s]*?)<table#is', '<table', $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   364
    $result = str_replace("<pre><code>\n", "<pre><code>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   365
    $result = preg_replace("/<p><table([^>]*?)><\/p>/", "<table\\1>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   366
    $result = str_replace("<br />\n</td>", "\n</td>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   367
    $result = str_replace("<p><tr>", "<tr>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   368
    $result = str_replace("<tr><br />", "<tr>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   369
    $result = str_replace("</tr><br />", "</tr>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   370
    $result = str_replace("</table><br />", "</table>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   371
    $result = preg_replace('/<\/table>$/', "</table><br /><br />", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   372
    $result = str_replace("<p></div></p>", "</div>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   373
    $result = str_replace("<p></table></p>", "</table>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   374
    
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   375
    $code = $plugins->setHook('render_wikiformat_post');
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   376
    foreach ( $code as $cmd )
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   377
    {
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   378
      eval($cmd);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   379
    }
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   380
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   381
    // Reinsert <nowiki> sections
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   382
    for($i=0;$i<$nw;$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   383
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   384
      $result = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', $nowiki[1][$i], $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   385
    }
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
    // Reinsert PHP
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   388
    for($i=0;$i<$php;$i++)
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
      $result = str_replace('{PHP:'.$random_id.':'.$i.'}', '<?php'.$phpsec[1][$i].'?>', $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   391
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   392
    
382
2ccb55995aef Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents: 377
diff changeset
   393
    profiler_log("RenderMan: finished wikitext render");
2ccb55995aef Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents: 377
diff changeset
   394
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   395
    return $result;
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
  
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   399
  public static function wikiFormat($message, $filter_links = true, $do_params = false, $plaintext = false)
163
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   400
  {
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   401
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   402
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   403
    return RenderMan::next_gen_wiki_format($message, $plaintext, $filter_links, $do_params);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   404
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   405
    $random_id = md5( time() . mt_rand() );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   406
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   407
    // Strip out <nowiki> sections
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   408
    $nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $message, $nowiki);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   409
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   410
    if(!$plaintext)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   411
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   412
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   413
      //return '<pre>'.print_r($nowiki,true).'</pre>';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   414
      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   415
      for($i=0;$i<sizeof($nowiki[1]);$i++)
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
        $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
   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
      $message = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $message);
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
      //return '<pre>'.htmlspecialchars($message).'</pre>';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   423
      
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   424
      $message = RenderMan::process_image_tags($message);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   425
    
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
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   428
    if($do_params)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   429
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   430
      preg_match_all('#\(_([0-9]+)_\)#', $message, $matchlist);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   431
      foreach($matchlist[1] as $m)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   432
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   433
        $message = str_replace('(_'.$m.'_)', $paths->getParam((int)$m), $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   434
      }
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
    $message = RenderMan::include_templates($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
    // Reinsert <nowiki> sections
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   440
    for($i=0;$i<$nw;$i++)
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
      $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
   443
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   444
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   445
    $message = process_tables($message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   446
    //if($message2 != $message) return '<pre>'.htmlspecialchars($message2).'</pre>';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   447
    //$message = str_replace(array('<table>', '</table>'), array('<nowiki><table>', '</table></nowiki>'), $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   448
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   449
    $wiki =& Text_Wiki::singleton('Mediawiki');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   450
    if($plaintext)
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
      $wiki->setRenderConf('Plain', 'wikilink', 'view_url', contentPath);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   453
      $result = $wiki->transform($message, 'Plain');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   454
    } else {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   455
      $wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   456
      $wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   457
      $result = $wiki->transform($message, 'Xhtml');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   458
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   459
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   460
    // HTML fixes
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   461
    $result = preg_replace('#<tr>([\s]*?)<\/tr>#is', '', $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   462
    $result = preg_replace('#<p>([\s]*?)<\/p>#is', '', $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   463
    $result = preg_replace('#<br />([\s]*?)<table#is', '<table', $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   464
    $result = str_replace("<pre><code>\n", "<pre><code>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   465
    $result = preg_replace("/<p><table([^>]*?)><\/p>/", "<table\\1>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   466
    $result = str_replace("<br />\n</td>", "\n</td>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   467
    $result = str_replace("<p><tr>", "<tr>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   468
    $result = str_replace("<tr><br />", "<tr>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   469
    $result = str_replace("</tr><br />", "</tr>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   470
    $result = str_replace("</table></p>", "</table>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   471
    $result = str_replace("</table><br />", "</table>", $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   472
    $result = preg_replace('/<\/table>$/', "</table><br /><br />", $result);
163
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   473
    $result = str_replace("<p></div></p>", "</div>", $result);
ad00dc1f8706 Improvements and fixes (hacks?) for HTML sanitization
Dan
parents: 159
diff changeset
   474
    $result = str_replace("<p></table></p>", "</table>", $result);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   475
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   476
    $result = str_replace('<nowiki>',  '&lt;nowiki&gt;',  $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   477
    $result = str_replace('</nowiki>', '&lt;/nowiki&gt;', $result);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   478
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   479
    return $result;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   480
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   481
  
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   482
  public static function destroy_javascript($message, $_php = false)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   483
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   484
    $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
   485
    $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
   486
    $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
   487
    if ( $_php )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   488
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   489
      // Left in only for compatibility
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   490
      $message = preg_replace('#&lt;(.*?)>#is', '<\\1>', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   491
      $message = preg_replace('#<(.*?)&gt;#is', '<\\1>', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   492
      $message = preg_replace('#<(\?|\?php|%)(.*?)(\?|%)>#is', '&lt;\\1\\2\\3&gt;', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   493
      // strip <a href="foo" onclick="bar();">-type attacks
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   494
      $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
   495
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   496
    return $message;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   497
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   498
  
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   499
  public static function strip_php($message)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   500
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   501
    return RenderMan::destroy_javascript($message, true);
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
  
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   504
  public static function sanitize_html($text)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   505
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   506
    $text = htmlspecialchars($text);
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   507
    $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
   508
    foreach($allowed_tags as $t)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   509
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   510
      $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
   511
      $text = preg_replace('#&lt;'.$t.' /&gt;#is', '<'.$t.' />', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   512
      $text = preg_replace('#&lt;'.$t.'&gt;#is', '<'.$t.'>', $text);
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
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   515
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   516
  
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   517
  /**
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   518
   * Parses internal links (wikilinks) in a block of text.
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   519
   * @param string Text to process
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   520
   * @param string Optional. If included will be used as a template instead of using the default syntax.
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   521
   * @return string
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   522
   */
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   523
  
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   524
  public static function parse_internal_links($text, $tplcode = false)
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   525
  {
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
   526
    global $db, $session, $paths, $template, $plugins; // Common objects
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   527
    
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   528
    if ( is_string($tplcode) )
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   529
    {
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   530
      $parser = $template->makeParserText($tplcode);
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   531
    }
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   532
    
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   533
    // stage 1 - links with alternate text
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   534
    preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\|(.+?)\]\]/', $text, $matches);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   535
    foreach ( $matches[0] as $i => $match )
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   536
    {
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   537
      list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
715
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   538
      if ( ($pos = strrpos($page_id, '#')) !== false )
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   539
      {
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   540
        $hash = substr($page_id, $pos);
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   541
        $page_id = substr($page_id, 0, $pos);
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   542
      }
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   543
      else
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   544
      {
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   545
        $hash = '';
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   546
      }
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   547
      $pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   548
      
715
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   549
      $url = makeUrl($pid_clean, false, true) . $hash;
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   550
      $inner_text = $matches[2][$i];
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   551
      $quot = '"';
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   552
      $exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"';
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   553
      
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   554
      if ( $tplcode )
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   555
      {
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   556
        $parser->assign_vars(array(
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   557
            'HREF' => $url,
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   558
            'FLAGS' => $exists,
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   559
            'TEXT' => $inner_text
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   560
          ));
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   561
        $link = $parser->run();
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   562
      }
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   563
      else
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   564
      {
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   565
        $link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>";
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   566
      }
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   567
      
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   568
      $text = str_replace($match, $link, $text);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   569
    }
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   570
    
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   571
    // stage 2 - links with no alternate text
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   572
    preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\]\]/', $text, $matches);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   573
    foreach ( $matches[0] as $i => $match )
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   574
    {
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   575
      list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   576
      $pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   577
      
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
   578
      $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
   579
      $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
   580
      $quot = '"';
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   581
      $exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"';
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   582
      
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   583
      if ( $tplcode )
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   584
      {
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   585
        $parser->assign_vars(array(
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   586
            'HREF' => $url,
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   587
            'FLAGS' => $exists,
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   588
            'TEXT' => $inner_text
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   589
          ));
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   590
        $link = $parser->run();
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   591
      }
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   592
      else
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   593
      {
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   594
        $link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>";
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   595
      }
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   596
      
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   597
      $text = str_replace($match, $link, $text);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   598
    }
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   599
    
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   600
    return $text;
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   601
  }
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   602
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   603
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   604
   * 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
   605
   * @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
   606
   * @example
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   607
   * <code>
63
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   608
   foo = lorem ipsum
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   609
   bar = dolor sit amet
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   610
   * </code>
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   611
   * @return array Example:
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   612
   * [foo] => lorem ipsum
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   613
   * [bar] => dolor sit amet
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
  
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   616
  public static function parse_template_vars($input, $newlinemode = true)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   617
  {
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   618
    $parms = array();
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   619
    $input = trim($input);
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   620
    if ( $newlinemode )
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
   621
    {
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   622
      $result = preg_match_all('/
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   623
                                  (?:^|[\s]*)\|?    # start of parameter - string start or series of spaces
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   624
                                  [ ]*              
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   625
                                  (?:               
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   626
                                    ([A-z0-9_]+)    # variable name
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   627
                                    [ ]* = [ ]*     # assignment
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   628
                                  )?                # this is optional - if the parameter name is not given, a numerical index is assigned
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   629
                                  (.+)              # value
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   630
                                /x', trim($input), $matches);
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
   631
    }
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
   632
    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
   633
    {
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   634
      $result = preg_match_all('/
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   635
                                  (?:^|[ ]*)\|         # start of parameter - string start or series of spaces
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   636
                                  [ ]*
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   637
                                  (?:
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   638
                                    ([A-z0-9_]+)       # variable name
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   639
                                    [ ]* = [ ]*        # assignment
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   640
                                  )?                   # name section is optional - if the parameter name is not given, a numerical index is assigned
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   641
                                  ([^\|]+|.+?\n[ ]*\|) # value
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   642
                                /x', trim($input), $matches);
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   643
    }                   
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   644
    if ( $result )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   645
    {
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   646
      $pi = 0;
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   647
      for ( $i = 0; $i < count($matches[0]); $i++ )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   648
      {
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   649
        $matches[1][$i] = trim($matches[1][$i]);
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   650
        $parmname = !empty($matches[1][$i]) ? $matches[1][$i] : strval(++$pi);
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   651
        $parms[ $parmname ] = $matches[2][$i];
1
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
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   654
    return $parms;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   655
  }
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
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   658
   * 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
   659
   * 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
   660
   * @param string The text to process
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   661
   * @return string Formatted text
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   662
   * @example
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   663
   * <code>
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   664
   $text = '{{Template
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   665
       | parm1 = Foo
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   666
       | parm2 = Bar
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   667
     }}';
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
   668
   $text = RenderMan::include_templates($text);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   669
   * </code>
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
  
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   672
  public static function include_templates($text)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   673
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   674
    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
   675
    // $template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   676
    // matches:
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   677
    //  1 - template name
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   678
    //  2 - parameter section
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   679
    $template_regex = "/
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   680
                         \{\{                     # opening
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   681
                           ([^\n\t\a\r]+)         # template name
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   682
                           ((?:(?:[\s]+\|?)[ ]*(?:[A-z0-9_]+)[ ]*=[ ]*?(?:.+))*) # parameters
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   683
                         \}\}                     # closing
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   684
                       /isxU";
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   685
    if ( $count = preg_match_all($template_regex, $text, $matches) )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   686
    {
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
   687
      //die('<pre>' . print_r($matches, true) . '</pre>');
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   688
      for ( $i = 0; $i < $count; $i++ )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   689
      {
63
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   690
        $matches[1][$i] = sanitize_page_id($matches[1][$i]);
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   691
        $newlinemode = ( substr($matches[2][$i], 0, 1) == "\n" );
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   692
        $parmsection = trim($matches[2][$i]);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   693
        if ( !empty($parmsection) )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   694
        {
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   695
          $parms = RenderMan::parse_template_vars($parmsection, $newlinemode);
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
   696
          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
   697
            // 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
   698
            $parms = array();
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   699
        }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   700
        else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   701
        {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   702
          $parms = Array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   703
        }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   704
        if ( $tpl_code = RenderMan::fetch_template_text($matches[1][$i]) )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   705
        {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   706
          $parser = $template->makeParserText($tpl_code);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   707
          $parser->assign_vars($parms);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   708
          $text = str_replace($matches[0][$i], $parser->run(), $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   709
        }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   710
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   711
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   712
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   713
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   714
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   715
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   716
   * Preprocesses an HTML text string prior to being sent to MySQL.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   717
   * @param string $text
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   718
   * @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
   719
   */
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   720
  public static function preprocess_text($text, $strip_all_php = true, $sqlescape = true)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   721
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   722
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   723
    $random_id = md5( time() . mt_rand() );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   724
    
407
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   725
    $code = $plugins->setHook('render_sanitize_pre');
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   726
    foreach ( $code as $cmd )
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   727
    {
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   728
      eval($cmd);
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   729
    }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   730
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   731
    $can_do_php = ( $session->get_permissions('php_in_pages') && !$strip_all_php );
377
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   732
    $can_do_html = $session->get_permissions('html_in_pages');
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   733
    
377
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   734
    if ( $can_do_html && !$can_do_php )
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   735
    {
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   736
      $text = preg_replace('#<(\?|\?php|%)(.*?)(\?|%)>#is', '&lt;\\1\\2\\3&gt;', $text);
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   737
    }
bb3e6c3bd4f4 Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents: 371
diff changeset
   738
    else if ( !$can_do_html && !$can_do_php )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   739
    {
24
9ecc94c4c7f5 Fixed tons of bugs relating to non-templated pages
Dan
parents: 21
diff changeset
   740
      $text = sanitize_html($text, true);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   741
      // If we can't do PHP, we can't do Javascript either.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   742
      $text = RenderMan::destroy_javascript($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
    // Strip out <nowiki> sections and PHP code
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   746
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   747
    $php = preg_match_all('#(<|&lt;)\?php(.*?)\?(>|&gt;)#is', $text, $phpsec);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   748
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   749
    //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
   750
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   751
    for($i=0;$i<sizeof($phpsec[1]);$i++)
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
      $text = str_replace($phpsec[0][$i], '{PHP:'.$random_id.':'.$i.'}', $text);
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
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   756
    $nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki);
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
    for($i=0;$i<sizeof($nowiki[1]);$i++)
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
      $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
   761
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   762
    
345
4ccdfeee9a11 WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
parents: 335
diff changeset
   763
    $text = str_replace('~~~~~', enano_date('G:i, j F Y (T)'), $text);
4ccdfeee9a11 WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
parents: 335
diff changeset
   764
    $text = str_replace('~~~~', "[[User:$session->username|$session->username]] ".enano_date('G:i, j F Y (T)'), $text);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   765
    $text = str_replace('~~~', "[[User:$session->username|$session->username]] ", $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   766
    
407
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   767
    $code = $plugins->setHook('render_sanitize_post');
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   768
    foreach ( $code as $cmd )
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   769
    {
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   770
      eval($cmd);
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   771
    }
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   772
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   773
    // Reinsert <nowiki> sections
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   774
    for($i=0;$i<$nw;$i++)
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
      $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
   777
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   778
    // Reinsert PHP
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   779
    for($i=0;$i<$php;$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   780
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   781
      $phsec = ''.$phpsec[1][$i].'?php'.$phpsec[2][$i].'?'.$phpsec[3][$i].'';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   782
      if ( $strip_all_php )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   783
        $phsec = htmlspecialchars($phsec);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   784
      $text = str_replace('{PHP:'.$random_id.':'.$i.'}', $phsec, $text);
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
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   787
    $text = ( $sqlescape ) ? $db->escape($text) : $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   788
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   789
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   790
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   791
  
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   792
  public static function smilieyize($text, $complete_urls = false)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   793
  {
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
    $random_id = md5( time() . mt_rand() );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   796
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   797
    // Smileys array - eventually this will be fetched from the database by
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   798
    // 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
   799
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   800
    $smileys = Array(
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   801
      'O:-)'    => 'face-angel.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   802
      'O:)'     => 'face-angel.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   803
      'O=)'     => 'face-angel.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   804
      ':-)'     => 'face-smile.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   805
      ':)'      => 'face-smile.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   806
      '=)'      => 'face-smile-big.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   807
      ':-('     => 'face-sad.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   808
      ':('      => 'face-sad.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   809
      ';('      => 'face-sad.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   810
      ':-O'     => 'face-surprise.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   811
      ';-)'     => 'face-wink.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   812
      ';)'      => 'face-wink.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   813
      '8-)'     => 'face-glasses.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   814
      '8)'      => 'face-glasses.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   815
      ':-D'     => 'face-grin.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   816
      ':D'      => 'face-grin.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   817
      '=D'      => 'face-grin.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   818
      ':-*'     => 'face-kiss.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   819
      ':*'      => 'face-kiss.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   820
      '=*'      => 'face-kiss.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   821
      ':\'('    => 'face-crying.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   822
      ':-|'     => 'face-plain.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   823
      ':-\\'    => 'face-plain.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   824
      ':-/'     => 'face-plain.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   825
      ':joke:'  => 'face-plain.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   826
      ']:-&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
   827
      ']:->'    => 'face-devil-grin.png',
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   828
      ':kiss:'  => 'face-kiss.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   829
      ':-P'     => 'face-tongue-out.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   830
      ':P'      => 'face-tongue-out.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   831
      ':-p'     => 'face-tongue-out.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   832
      ':p'      => 'face-tongue-out.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   833
      ':-X'     => 'face-sick.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   834
      ':X'      => 'face-sick.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   835
      ':sick:'  => 'face-sick.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   836
      ':-]'     => 'face-oops.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   837
      ':]'      => 'face-oops.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   838
      ':oops:'  => 'face-oops.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   839
      ':-['     => 'face-embarassed.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   840
      ':['      => 'face-embarassed.png'
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   841
      );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   842
    /*
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   843
    $keys = array_keys($smileys);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   844
    foreach($keys as $k)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   845
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   846
      $regex1 = '#([\W]+)'.preg_quote($k).'([\s\n\r\.]+)#s';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   847
      $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
   848
      $text = preg_replace($regex1, $regex2, $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   849
    }                                                                      
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   850
    */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   851
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   852
    // Strip out <nowiki> sections
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   853
    //return '<pre>'.htmlspecialchars($text).'</pre>';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   854
    $nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   855
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   856
    for($i=0;$i<sizeof($nowiki[1]);$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   857
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   858
      $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
   859
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   860
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   861
    $keys = array_keys($smileys);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   862
    foreach($keys as $k)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   863
    {
391
85f91037cd4f Localization is FINISHED, DAMN IT HELLAH YEAH! OVER WITH! Man, it feels to get that off my chest. Release is in under 48 hours, folks. And we're ready for it.
Dan
parents: 387
diff changeset
   864
      $t = hexencode($k, ' ', '');
85f91037cd4f Localization is FINISHED, DAMN IT HELLAH YEAH! OVER WITH! Man, it feels to get that off my chest. Release is in under 48 hours, folks. And we're ready for it.
Dan
parents: 387
diff changeset
   865
      $t = trim($t);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   866
      $t = explode(' ', $t);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   867
      $s = '';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   868
      foreach($t as $b)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   869
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   870
        $s.='&#x'.$b.';';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   871
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   872
      $pfx = ( $complete_urls ) ? 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://'.$_SERVER['HTTP_HOST'] : '';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   873
      $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
   874
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   875
    //*/
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   876
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   877
    // Reinsert <nowiki> sections
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   878
    for($i=0;$i<$nw;$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   879
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   880
      $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
   881
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   882
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   883
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   884
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   885
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   886
  /*
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   887
   * **** DEPRECATED ****
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   888
   * Replaces some critical characters in a string with MySQL-safe equivalents
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   889
   * @param $text string the text to escape
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   890
   * @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
   891
   * /
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   892
   
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   893
  public static function escape_page_text($text)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   894
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   895
    $char_tag = md5(microtime() . mt_rand());
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   896
    $text = str_replace("'",  "{APOS:$char_tag}",  $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   897
    $text = str_replace('"',  "{QUOT:$char_tag}",  $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   898
    $text = str_replace("\\", "{SLASH:$char_tag}", $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   899
    return Array($text, $char_tag);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   900
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   901
  */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   902
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   903
  /* **** DEPRECATED ****
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   904
   * Reverses the result of RenderMan::escape_page_text().
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   905
   * @param $text string the text to unescape
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   906
   * @param $char_tag string the character tag
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   907
   * @return string
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   908
   * /
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   909
   
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   910
  public static function unescape_page_text($text, $char_tag)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   911
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   912
    $text = str_replace("{APOS:$char_tag}",  "'",  $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   913
    $text = str_replace("{QUOT:$char_tag}",  '"',  $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   914
    $text = str_replace("{SLASH:$char_tag}", "\\", $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   915
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   916
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   917
  */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   918
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   919
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   920
   * 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
   921
   * @param $str1 string the first block of text
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   922
   * @param $str2 string the second block of text
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   923
   * @return string
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   924
   */
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   925
  public static function diff($str1, $str2)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   926
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   927
    global $db, $session, $paths, $template, $plugins; // Common objects
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   928
    require_once(ENANO_ROOT.'/includes/diff.php');
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   929
    $str1 = explode("\n", $str1);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   930
    $str2 = explode("\n", $str2);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   931
    $diff = new Diff($str1, $str2);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   932
    $renderer = new TableDiffFormatter();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   933
    return '<table class="diff">'.$renderer->format($diff).'</table>';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   934
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   935
  
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   936
  /**
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   937
   * Changes wikitext image tags to HTML.
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   938
   * @param string The wikitext to process
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   939
   * @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
   940
   * @return string
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   941
   */
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   942
  
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
   943
  public static function process_image_tags($text, &$taglist)
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   944
  {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   945
    global $db, $session, $paths, $template, $plugins; // Common objects
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   946
    
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   947
    $s_delim = "\xFF";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   948
    $f_delim = "\xFF";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   949
    $taglist = array();
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
   950
    
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   951
    // Wicked huh?
569
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   952
    $ns_file = str_replace('/', '\\/', preg_quote($paths->nslist['File']));
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   953
    $regex = '/
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   954
           \[\[                                                                  # starting delimiter 
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   955
           :' . $ns_file . '([\w\s0-9_\(\)!@%\^\+\|\.-]+?\.(?:png|gif|jpg|jpeg)) # image filename
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   956
           (?:(?:\|(?:.+?))*)                                                    # parameters
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   957
           \]\]                                                                  # ending delimiter
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   958
           /ix';
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   959
    
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   960
    preg_match_all($regex, $text, $matches);
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
    foreach ( $matches[0] as $i => $match )
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
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   965
      $full_tag   =& $matches[0][$i];
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
   966
      $filename   =& $matches[1][$i];
569
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   967
      
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   968
      // apply recursion (hack? @todo could this be done with (?R) in PCRE?)
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   969
      $tag_pos = strpos($text, $full_tag);
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   970
      $tag_end_pos = $tag_pos + strlen($full_tag);
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   971
      while ( get_char_count($full_tag, ']') < get_char_count($full_tag, '[') && $tag_end_pos < strlen($text) )
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   972
      {
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   973
        $full_tag .= substr($text, $tag_end_pos, 1);
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   974
        $tag_end_pos++;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   975
      }
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   976
      if ( $tag_end_pos > strlen($text) )
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   977
      {
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   978
        // discard tag, not closed fully
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   979
        continue;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   980
      }
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   981
      
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   982
      // init the various image parameters
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   983
      $width = null;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   984
      $height = null;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   985
      $scale_type = null;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   986
      $raw_display = false;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   987
      $clear = null;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   988
      $caption = null;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   989
      
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   990
      // trim tag and parse particles
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   991
      $tag_trim = rtrim(ltrim($full_tag, '['), ']');
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   992
      // trim off the filename from the start of the tag
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   993
      $filepart_len = 1 + strlen($paths->nslist['File']) + strlen($filename) + 1;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   994
      $tag_trim = substr($tag_trim, $filepart_len);
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   995
      // explode and we should have parameters
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   996
      $tag_parts = explode('|', $tag_trim);
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   997
      
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   998
      // for each of the parameters, see if it matches a known option. If so, apply it;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
   999
      // otherwise, see if a plugin reserved that parameter and if not treat it as the caption
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1000
      foreach ( $tag_parts as $param )
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1001
      {
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1002
        switch($param)
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1003
        {
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1004
          case 'left':
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1005
          case 'right':
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1006
            $clear = $param;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1007
            break;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1008
          case 'thumb':
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1009
            $scale_type = 'thumb';
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1010
            break;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1011
          case 'raw':
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1012
            $raw_display = true;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1013
            break;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1014
          default:
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1015
            // height specification
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1016
            if ( preg_match('/^([0-9]+)x([0-9]+)$/', $param, $dims) )
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1017
            {
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1018
              $width = intval($dims[1]);
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1019
              $height = intval($dims[2]);
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1020
              break;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1021
            }
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1022
            // not the height, so see if a plugin took this over
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1023
            // this hook requires plugins to return true if they modified anythin
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1024
            $code = $plugins->setHook('img_tag_parse_params');
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1025
            foreach ( $code as $cmd )
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1026
            {
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1027
              if ( eval($cmd) )
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1028
                break 2;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1029
            }
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1030
            // we would have broken out by now if a plugin properly handled this,
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1031
            // so just set the caption now.
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1032
            $caption = $param;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1033
            break;
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1034
        }
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1035
      }
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1036
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1037
      if ( !isPage( $paths->nslist['File'] . $filename ) )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1038
      {
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
  1039
        $text = str_replace($full_tag, '[[' . makeUrlNS('File', $filename) . ']]', $text);
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1040
        continue;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1041
      }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1042
      
569
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1043
      if ( $scale_type == 'thumb' )
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1044
      {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1045
        $r_width  = 225;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1046
        $r_height = 225;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1047
        
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1048
        $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
  1049
      }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1050
      else if ( !empty($width) && !empty($height) )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1051
      {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1052
        $r_width = $width;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1053
        $r_height = $height;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1054
        
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1055
        $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
  1056
      }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1057
      else
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1058
      {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1059
        $url = makeUrlNS('Special', 'DownloadFile/' . $filename);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1060
      }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1061
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1062
      $img_tag = '<img src="' . $url . '" ';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1063
      
65
627d0a8a7819 Last-minute change to width/height on embedded images
Dan
parents: 63
diff changeset
  1064
      // 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
  1065
      // {
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
  1066
      //   $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" ';
65
627d0a8a7819 Last-minute change to width/height on embedded images
Dan
parents: 63
diff changeset
  1067
      // }
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1068
      
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
  1069
      $img_tag .= 'style="border-width: 0px; /* background-color: white; */" ';
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1070
      
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
  1071
      $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
  1072
      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
  1073
      {
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
  1074
        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
  1075
      }
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
  1076
      
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1077
      $img_tag .= '/>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1078
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1079
      $complete_tag = '';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1080
      
569
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1081
      if ( !empty($scale_type) && !$raw_display )
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1082
      {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1083
        $complete_tag .= '<div class="thumbnail" ';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1084
        $clear_text = '';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1085
        if ( !empty($clear) )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1086
        {
569
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1087
          $side = ( $clear == 'left' ) ? 'left' : 'right';
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1088
          $opposite = ( $clear == 'left' ) ? 'right' : 'left';
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1089
          $clear_text .= "float: $side; margin-$opposite: 20px; width: {$r_width}px;";
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1090
          $complete_tag .= 'style="' . $clear_text . '" ';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1091
        }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1092
        $complete_tag .= '>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1093
        
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1094
        $complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1095
        $complete_tag .= $img_tag;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1096
        $complete_tag .= '</a>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1097
        
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1098
        $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
  1099
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1100
        if ( !empty($caption) )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1101
        {
569
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1102
          $complete_tag .= $mag_button . $caption;
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1103
        }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1104
        
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1105
        $complete_tag .= '</div>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1106
      }
569
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1107
      else if ( $raw_display )
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
  1108
      {
67
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
  1109
        $complete_tag .= "$img_tag";
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
  1110
        $taglist[$i] = $complete_tag;
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
  1111
        
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
  1112
        $repl = "{$s_delim}e_img_{$i}{$f_delim}";
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
  1113
        $text = str_replace($full_tag, $repl, $text);
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
  1114
        continue;
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
  1115
      }
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1116
      else
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1117
      {
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
  1118
        $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
  1119
        $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
  1120
        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
  1121
        {
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
  1122
          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
  1123
        }
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
  1124
        $complete_tag .= '>';
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1125
        $complete_tag .= $img_tag;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1126
        $complete_tag .= '</a>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1127
      }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1128
      
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1129
      $complete_tag .= "\n\n";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1130
      $taglist[$i] = $complete_tag;
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1131
      
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1132
      $pos = strpos($text, $full_tag);
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1133
      
569
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1134
      /*
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1135
      while(true)
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1136
      {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1137
        $check1 = substr($text, $pos, 3);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1138
        $check2 = substr($text, $pos, 1);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1139
        if ( $check1 == '<p>' || $pos == 0 || $check2 == "\n" )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1140
        {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1141
          // die('found at pos '.$pos);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1142
          break;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1143
        }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1144
        $pos--;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1145
      }
569
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1146
      */
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1147
      
569
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1148
      /*
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1149
      $repl = "{$s_delim}e_img_{$i}{$f_delim}";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1150
      $text = substr($text, 0, $pos) . $repl . substr($text, $pos);
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1151
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1152
      $text = str_replace($full_tag, '', $text);
569
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1153
      */
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1154
      $text = str_replace_once($full_tag, $complete_tag, $text);
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1155
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1156
      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
  1157
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1158
    }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1159
    
569
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1160
    // if ( count($matches[0]) > 0 )
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1161
    //   die('<pre>' . htmlspecialchars($text) . '</pre>');
6ba792bc9071 Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents: 536
diff changeset
  1162
    
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1163
    return $text;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1164
  }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1165
  
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1166
  /**
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1167
   * Finalizes processing of image tags.
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1168
   * @param string The preprocessed text
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1169
   * @param array The list of image tags created by RenderMan::process_image_tags()
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1170
   */
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1171
   
371
dc6026376919 Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents: 345
diff changeset
  1172
  public static function process_imgtags_stage2($text, $taglist)
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1173
  {
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1174
    $s_delim = "\xFF";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1175
    $f_delim = "\xFF";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1176
    foreach ( $taglist as $i => $tag )
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1177
    {
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1178
      $repl = "{$s_delim}e_img_{$i}{$f_delim}";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1179
      $text = str_replace($repl, $tag, $text);
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1180
    }               
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1181
    return $text;
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1182
  }
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1183
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1184
}
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1185
 
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1186
?>