includes/render.php
author Dan
Fri, 17 Jul 2009 20:28:24 -0400
changeset 1067 4058c844ee38
parent 1066 bead71f28f63
child 1073 b19a9bcb6a45
permissions -rw-r--r--
Admin: query string is now preserved on redirect to login
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
801
eb8b23f11744 Two big commits in one day I know, but redid password storage to use HMAC-SHA1. Consolidated much AES processing to three core methods in session that should handle everything automagically. Installation works; upgrades should. Rebranded as 1.1.6.
Dan
parents: 800
diff changeset
     5
 * Version 1.1.6 (Caoineag beta 1)
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
    
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
    45
    $page = new PageProcessor($page_id, $namespace);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
    46
    $text = $page->fetch_text();
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    47
    
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
    48
    if ( !$render )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
    49
      return $text;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    50
    
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
    51
    $text = self::render($text, $wiki, $smilies, $filter_links);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
    52
    return $text;
1
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
  
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
    55
  public static function getTemplate($id, $parms)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    56
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    57
    global $db, $session, $paths, $template, $plugins; // Common objects
953
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 832
diff changeset
    58
    if ( !isPage($paths->get_pathskey($id, 'Template')) ) 
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    59
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    60
      return '[['.$paths->nslist['Template'].$id.']]';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    61
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    62
    if(isset($paths->template_cache[$id]))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    63
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    64
      $text = $paths->template_cache[$id];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    65
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    66
    else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    67
    {
953
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 832
diff changeset
    68
      $page = new PageProcessor($id, 'Template');
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 832
diff changeset
    69
      $text = $page->fetch_text();
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    70
      $paths->template_cache[$id] = $text;
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
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    73
    $text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    74
    $text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    75
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    76
    preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    77
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    78
    foreach($matchlist[1] as $m)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    79
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    80
      if(isset($parms[((int)$m)+1])) 
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    81
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    82
        $p = $parms[((int)$m)+1];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    83
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    84
      else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    85
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    86
        $p = '<b>Notice:</b> RenderMan::getTemplate(): Parameter '.$m.' is not set';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    87
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    88
      $text = str_replace('(_'.$m.'_)', $p, $text);
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
    89
      $text = str_replace('{{' . ( $m + 1 ) . '}}', $p, $text);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    90
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    91
    $text = RenderMan::include_templates($text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    92
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    93
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    94
  
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
    95
  public static function fetch_template_text($id)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    96
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    97
    global $db, $session, $paths, $template, $plugins; // Common objects
745
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
    98
    $fetch_ns = 'Template';
953
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 832
diff changeset
    99
    if ( !isPage($paths->get_pathskey($id, 'Template')) ) 
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   100
    {
745
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   101
      // Transclusion of another page
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   102
      // 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
   103
      $nssep = substr($paths->nslist['Special'], -1);
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   104
      $nslist = $paths->nslist;
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   105
      foreach ( $nslist as &$ns )
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   106
      {
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   107
        if ( $ns == '' )
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   108
          $ns = $nssep;
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   109
      }
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   110
      $prefixlist = array_flip($nslist);
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   111
      foreach ( $nslist as &$ns )
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   112
      {
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   113
        $ns = preg_quote($ns);
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   114
      }
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   115
      $nslist = implode('|', $nslist);
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   116
      if ( preg_match("/^($nslist)(.*?)$/", $id, $match) )
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   117
      {
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   118
        // 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
   119
        if ( isset($prefixlist[$match[1]]) )
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   120
        {
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   121
          $new_id = $paths->nslist[ $prefixlist[$match[1]] ] . sanitize_page_id($match[2]);
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   122
          if ( !isPage($new_id) )
745
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   123
          {
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   124
            return "[[$new_id]]";
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   125
          }
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   126
          $fetch_ns = $prefixlist[$match[1]];
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   127
          $id = sanitize_page_id($match[2]);
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   128
        }
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   129
      }
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   130
      else
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   131
      {
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   132
        return '[['.$paths->nslist['Template'].$id.']]';
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   133
      }
1
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
    if(isset($paths->template_cache[$id]))
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
      $text = $paths->template_cache[$id];
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
    else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   140
    {
745
0a3866f74faa Added full all-namespace transclusion support in RenderMan
Dan
parents: 717
diff changeset
   141
      $text = RenderMan::getPage($id, $fetch_ns, 0, false, false, false, false);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   142
      $paths->template_cache[$id] = $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   143
    }
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
    if ( is_string($text) )
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 = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   148
      $text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text);
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
    
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
  
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   154
  /**
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   155
   * Renders a glob of text. Note that this is PHP-safe, so if returned text (or rather, "?>" . $returned) has PHP it can be eval'ed.
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   156
   * @param string Text to render
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   157
   * @param int Render parameters - see constants.php
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   158
   * @return string Rendered text
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   159
   */
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   160
  
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   161
  public static function render($text, $flags = RENDER_WIKI_DEFAULT, $smilies = true)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   162
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   163
    global $db, $session, $paths, $template, $plugins; // Common objects
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   164
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   165
    if ( !$smilies )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   166
      $flags |= RENDER_NOSMILIES;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   167
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   168
    if ( $flags & ~RENDER_NOSMILIES )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   169
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   170
      $text = RenderMan::smilieyize($text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   171
    }
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   172
    if ( $flags & RENDER_WIKI_DEFAULT )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   173
    {
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   174
      $text = RenderMan::next_gen_wiki_format($text, $flags);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   175
    }
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   176
    else if ( $flags & RENDER_WIKI_TEMPLATE )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   177
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   178
      $text = $template->tplWikiFormat($text);
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   179
    }           
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   180
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   181
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   182
  
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   183
  private static function next_gen_wiki_format($text, $flags = 0)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   184
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   185
    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
   186
    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
   187
    
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   188
    profiler_log("RenderMan: starting wikitext render");
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   189
    require_once( ENANO_ROOT . '/includes/wikiformat.php' );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   190
    require_once( ENANO_ROOT . '/includes/wikiengine/TagSanitizer.php' );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   191
    require_once( ENANO_ROOT . '/includes/wikiengine/Tables.php' );
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   192
    
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   193
    // this is still needed by parser plugins
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   194
    $random_id = md5( time() . mt_rand() );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   195
    
1044
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1027
diff changeset
   196
    // Strip out <nowiki> sections
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   197
    self::nowiki_strip($text, $nowiki_stripped);
407
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   198
    
1044
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1027
diff changeset
   199
    // Run early parsing plugins
407
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   200
    $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
   201
    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
   202
    {
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   203
      eval($cmd);
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   204
    }
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   205
    
1044
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1027
diff changeset
   206
    // Strip out embedded PHP
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   207
    self::php_strip($text, $php_stripped);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   208
    
1066
bead71f28f63 Fixed some formatter engine errors that were exposed through the wiki edit notice
Dan
parents: 1054
diff changeset
   209
    // Convert newlines for the parser
bead71f28f63 Fixed some formatter engine errors that were exposed through the wiki edit notice
Dan
parents: 1054
diff changeset
   210
    $text = str_replace("\r\n", "\n", $text);
bead71f28f63 Fixed some formatter engine errors that were exposed through the wiki edit notice
Dan
parents: 1054
diff changeset
   211
    
1044
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1027
diff changeset
   212
    // Perform render through the engine
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   213
    $carpenter = new Carpenter();
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   214
    $carpenter->flags = $flags;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   215
    $carpenter->hook(array(__CLASS__, 'hook_pre'), PO_AFTER, 'lang');
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   216
    $carpenter->hook(array(__CLASS__, 'hook_posttemplates'), PO_AFTER, 'templates');
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   217
    if ( $flags & RENDER_WIKI_TEMPLATE )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   218
    {
1044
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1027
diff changeset
   219
      // FIXME: Where is noinclude/nodisplay being processed in the pipeline? (Seems to be processed, but not here)
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   220
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   221
    $text = $carpenter->render($text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   222
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   223
    // For plugin compat
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   224
    $result =& $text;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   225
    
1044
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1027
diff changeset
   226
    // Post processing hook
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   227
    $code = $plugins->setHook('render_wikiformat_post');
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   228
    foreach ( $code as $cmd )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   229
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   230
      eval($cmd);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   231
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   232
    
1044
ad6a22377507 Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents: 1027
diff changeset
   233
    // Add PHP and nowiki back in
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   234
    self::nowiki_unstrip($text, $nowiki_stripped);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   235
    self::php_unstrip($text, $php_stripped);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   236
    
382
2ccb55995aef Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents: 377
diff changeset
   237
    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
   238
    
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   239
    return $text;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   240
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   241
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   242
  public static function hook_pre($text)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   243
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   244
    global $db, $session, $paths, $template, $plugins; // Common objects
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   245
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   246
    $code = $plugins->setHook('render_wikiformat_pre');
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   247
    foreach ( $code as $cmd )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   248
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   249
      eval($cmd);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   250
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   251
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   252
    return $text;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   253
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   254
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   255
  public static function hook_posttemplates($text)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   256
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   257
    global $db, $session, $paths, $template, $plugins; // Common objects
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   258
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   259
    $code = $plugins->setHook('render_wikiformat_posttemplates');
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   260
    foreach ( $code as $cmd )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   261
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   262
      eval($cmd);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   263
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   264
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   265
    return $text;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   266
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   267
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   268
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   269
   * Strip out <nowiki> tags (to bypass parsing on them)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   270
   * @access private
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   271
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   272
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   273
  private static function nowiki_strip(&$text, &$stripdata)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   274
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   275
    self::tag_strip('nowiki', $text, $stripdata);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   276
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   277
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   278
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   279
   * Restore stripped <nowiki> tags.
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   280
   * @access private
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   281
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   282
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   283
  public static function nowiki_unstrip(&$text, &$stripdata)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   284
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   285
    self::tag_unstrip('nowiki', $text, $stripdata);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   286
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   287
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   288
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   289
   * Strip out an arbitrary HTML tag.
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   290
   * @access private
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   291
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   292
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   293
  public static function tag_strip($tag, &$text, &$stripdata)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   294
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   295
    $random_id = md5( time() . mt_rand() );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   296
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   297
    preg_match_all("#<$tag>(.*?)</$tag>#is", $text, $blocks);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   298
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   299
    foreach ( $blocks[0] as $i => $match )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   300
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   301
      $text = str_replace($match, "{{$tag}:{$random_id}:{$i}}", $text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   302
    }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   303
    
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   304
    $stripdata = array(
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   305
        'random_id' => $random_id,
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   306
        'blocks' => $blocks[1]
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   307
      );
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   308
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   309
  
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   310
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   311
   * Restore stripped <nowiki> tags.
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   312
   * @access private
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   313
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   314
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   315
  public static function tag_unstrip($tag, &$text, &$stripdata)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   316
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   317
    $random_id = $stripdata['random_id'];
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   318
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   319
    foreach ( $stripdata['blocks'] as $i => $block )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   320
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   321
      $text = str_replace("{{$tag}:{$random_id}:{$i}}", $block, $text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   322
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   323
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   324
    $stripdata = array();
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   325
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   326
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   327
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   328
   * Strip out PHP code (to prevent it from being sent through the parser). Private because it does not do what you think it does. (The method you are looking for is strip_php.)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   329
   * @access private
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   330
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   331
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   332
  private static function php_strip(&$text, &$stripdata)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   333
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   334
    $random_id = md5( time() . mt_rand() );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   335
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   336
    preg_match_all('#<\?(?:php)?[\s=].+?\?>#is', $text, $blocks);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   337
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   338
    foreach ( $blocks[0] as $i => $match )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   339
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   340
      $text = str_replace($match, "{PHP:$random_id:$i}", $text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   341
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   342
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   343
    $stripdata = array(
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   344
        'random_id' => $random_id,
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   345
        'blocks' => $blocks[0]
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   346
      );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   347
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   348
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   349
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   350
   * Restore stripped PHP code
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   351
   * @access private
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   352
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   353
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   354
  private static function php_unstrip(&$text, &$stripdata)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   355
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   356
    $random_id = $stripdata['random_id'];
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   357
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   358
    foreach ( $stripdata['blocks'] as $i => $block )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   359
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   360
      $text = str_replace("{PHP:$random_id:$i}", $block, $text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   361
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   362
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   363
    $stripdata = array();
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   364
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   365
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   366
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   367
   * Deprecated.
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   368
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   369
  
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
   370
  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
   371
  {
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   372
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   373
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   374
    return RenderMan::next_gen_wiki_format($message, $plaintext, $filter_links, $do_params);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   375
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   376
  
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
   377
  public static function destroy_javascript($message, $_php = false)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   378
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   379
    $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
   380
    $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
   381
    $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
   382
    if ( $_php )
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
      // Left in only for compatibility
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   385
      $message = preg_replace('#&lt;(.*?)>#is', '<\\1>', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   386
      $message = preg_replace('#<(.*?)&gt;#is', '<\\1>', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   387
      $message = preg_replace('#<(\?|\?php|%)(.*?)(\?|%)>#is', '&lt;\\1\\2\\3&gt;', $message);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   388
      // strip <a href="foo" onclick="bar();">-type attacks
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   389
      $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
   390
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   391
    return $message;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   392
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   393
  
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
   394
  public static function strip_php($message)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   395
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   396
    return RenderMan::destroy_javascript($message, true);
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 sanitize_html($text)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   400
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   401
    $text = htmlspecialchars($text);
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   402
    $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
   403
    foreach($allowed_tags as $t)
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
      $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
   406
      $text = preg_replace('#&lt;'.$t.' /&gt;#is', '<'.$t.' />', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   407
      $text = preg_replace('#&lt;'.$t.'&gt;#is', '<'.$t.'>', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   408
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   409
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   410
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   411
  
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   412
  /**
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   413
   * Reverse-renders a blob of text (converts it from XHTML back to wikitext) by using parser hints and educated guesses.
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   414
   * @param string XHTML
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   415
   * @return string Wikitext
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   416
   */
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   417
  
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   418
  public static function reverse_render($text)
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   419
  {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   420
    // convert \r\n to \n
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   421
    $text = str_replace("\r\n", "\n", $text);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   422
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   423
    // Separate certain block level elements onto their own lines. This tidies up the tag
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   424
    // soup that TinyMCE sometimes produces.
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   425
    $block_elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div', 'table', 'ul', 'pre');
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   426
    $block_elements = implode('|', $block_elements);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   427
    $regex = "#(</(?:$block_elements)>)\n?<($block_elements)(>| .+?>)#i";
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   428
    $text = preg_replace($regex, "$1\n\n<$2$3", $text);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   429
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   430
    $text = self::reverse_process_parser_hints($text);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   431
    $text = self::reverse_process_headings($text);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   432
    $text = self::reverse_process_lists($text);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   433
    $text = self::reverse_process_tables($text);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   434
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   435
    // Lastly, strip out paragraph tags.
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   436
    $text = preg_replace('|^ *<p>(.+?)</p> *$|m', "\\1", $text);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   437
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   438
    return $text;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   439
  }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   440
  
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   441
  public static function reverse_process_parser_hints($text)
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   442
  {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   443
    global $db, $session, $paths, $template, $plugins; // Common objects
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   444
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   445
    if ( !preg_match_all('|<!--#([a-z0-9_]+)(?: (.+?))?-->([\w\W]*?)<!--#/\\1-->|s', $text, $matches) )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   446
      return $text;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   447
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   448
    foreach ( $matches[0] as $i => $match )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   449
    {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   450
      $tag =& $matches[1][$i];
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   451
      $attribs =& $matches[2][$i];
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   452
      $inner =& $matches[3][$i];
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   453
      
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   454
      $attribs = self::reverse_process_hint_attribs($attribs);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   455
      switch($tag)
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   456
      {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   457
        case 'smiley':
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   458
        case 'internallink':
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   459
        case 'imagelink':
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   460
          if ( isset($attribs['code']) )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   461
          {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   462
            $text = str_replace($match, $attribs['code'], $text);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   463
          }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   464
          else if ( isset($attribs['src']) )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   465
          {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   466
            $text = str_replace($match, $attribs['src'], $text);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   467
          }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   468
          break;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   469
      }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   470
    }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   471
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   472
    return $text;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   473
  }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   474
  
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   475
  public static function reverse_process_hint_attribs($attribs)
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   476
  {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   477
    $return = array();
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   478
    if ( !preg_match_all('/([a-z0-9_-]+)="([^"]+?)"/', $attribs, $matches) )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   479
      return array();
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   480
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   481
    foreach ( $matches[0] as $i => $match )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   482
    {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   483
      $name =& $matches[1][$i];
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   484
      $value =& $matches[2][$i];
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   485
      
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   486
      $value = base64_decode($value);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   487
      
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   488
      $return[$name] = $value;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   489
    }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   490
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   491
    return $return;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   492
  }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   493
  
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   494
  /**
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   495
   * Escapes a string so that it's safe to use as an attribute in a parser hint.
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   496
   * @param string
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   497
   * @return string
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   498
   */
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   499
  
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   500
  public static function escape_parser_hint_attrib($text)
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   501
  {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   502
    return base64_encode($text);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   503
  }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   504
  
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   505
  public static function reverse_process_headings($text)
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   506
  {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   507
    if ( !preg_match_all('|^<h([1-6])(?: id="toc[0-9]+")?>(.*?)</h\\1>$|m', $text, $matches) )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   508
      return $text;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   509
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   510
    foreach ( $matches[0] as $i => $match )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   511
    {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   512
      // generate heading tag
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   513
      $heading_size = intval($matches[1][$i]);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   514
      $eq = '';
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   515
      for ( $j = 0; $j < $heading_size; $j++ )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   516
        $eq .= '=';
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   517
      
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   518
      $heading =& $matches[2][$i];
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   519
      
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   520
      $tag = "$eq $heading $eq";
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   521
      $text = str_replace($match, $tag, $text);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   522
    }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   523
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   524
    return $text;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   525
  }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   526
  
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   527
  public static function reverse_process_lists($text)
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   528
  {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   529
    if ( !preg_match('!(</?(?:ul|ol|li)>)!', $text) )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   530
      return $text;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   531
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   532
    $split = preg_split('!(</?(?:ul|ol|li)>)!', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   533
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   534
    $stack_height = 0;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   535
    $current_list = '';
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   536
    $old_current_list = '';
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   537
    $spaces = '';
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   538
    $marker = '*';
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   539
    $list_id = 0;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   540
    $just_terminated = false;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   541
    foreach ( $split as $tag )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   542
    {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   543
      switch($tag) 
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   544
      {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   545
        case '<ul>':
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   546
        case '<ol>':
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   547
          $stack_height++;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   548
          $just_terminated = false;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   549
          if ( $stack_height > 1 )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   550
            $spaces .= $marker;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   551
          
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   552
          $marker = ( $tag == 'ol' ) ? '#' : '*';
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   553
          if ( $stack_height > 1 )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   554
            $current_list .= "\n";
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   555
          
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   556
          break;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   557
        case '</ul>':
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   558
        case '</ol>':
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   559
          $stack_height--;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   560
          $spaces = substr($spaces, 1);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   561
          
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   562
          if ( $stack_height == 0 )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   563
          {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   564
            // rotate
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   565
            $text = str_replace_once("{$old_current_list}{$tag}", trim($current_list), $text);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   566
            $current_list = '';
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   567
            $old_current_list = '';
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   568
          }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   569
          $just_terminated = true;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   570
          break;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   571
        case '<li>':
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   572
          if ( $stack_height < 1 )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   573
            break;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   574
          
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   575
          $current_list .= "{$spaces}{$marker} ";
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   576
          break;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   577
        case '</li>':
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   578
          if ( $stack_height < 1 )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   579
            break;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   580
          
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   581
          if ( !$just_terminated )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   582
            $current_list .= "\n";
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   583
          
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   584
          $just_terminated = false;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   585
          break;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   586
        default:
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   587
          if ( $stack_height > 0 )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   588
          {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   589
            $current_list .= trim($tag);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   590
          }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   591
          break;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   592
      }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   593
      if ( $stack_height > 0 )
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   594
      {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   595
        $old_current_list .= $tag;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   596
      }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   597
    }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   598
    
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   599
    return $text;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   600
  }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   601
  
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   602
  public static function reverse_process_tables($text)
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   603
  {
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   604
    return $text;
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   605
  }
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   606
  
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   607
  /**
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   608
   * Parses internal links (wikilinks) in a block of text.
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   609
   * @param string Text to process
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   610
   * @param string Optional. If included will be used as a template instead of using the default syntax.
971
bc8f3ab74e5e Render / Template: No longer does exist checks for wikilinks on sidebar
Dan
parents: 953
diff changeset
   611
   * @param bool If false, does not add wikilink-nonexistent or check for exsistence of pages. Can reduce DB queries; defualts to true.
1003
28e2f75d66fd Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents: 971
diff changeset
   612
   * @param string Page ID. If specified, class="currentpage" will be added to links if they match the given page ID and namespace
28e2f75d66fd Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents: 971
diff changeset
   613
   * @param string Namespace. If specified, class="currentpage" will be added to links if they match the given page ID and namespace
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   614
   * @return string
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   615
   */
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   616
  
1003
28e2f75d66fd Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents: 971
diff changeset
   617
  public static function parse_internal_links($text, $tplcode = false, $do_exist_check = true, $match_page_id = false, $match_namespace = false)
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   618
  {
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
   619
    global $db, $session, $paths, $template, $plugins; // Common objects
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   620
    
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   621
    if ( is_string($tplcode) )
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   622
    {
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   623
      $parser = $template->makeParserText($tplcode);
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   624
    }
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   625
    
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   626
    // stage 1 - links with alternate text
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   627
    preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\|(.+?)\]\]/', $text, $matches);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   628
    foreach ( $matches[0] as $i => $match )
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   629
    {
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   630
      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
   631
      if ( ($pos = strrpos($page_id, '#')) !== false )
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   632
      {
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   633
        $hash = substr($page_id, $pos);
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   634
        $page_id = substr($page_id, 0, $pos);
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   635
      }
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   636
      else
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   637
      {
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   638
        $hash = '';
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   639
      }
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   640
      $pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   641
      
715
29663506e85c Added ability to use hash marks in internal links
Dan
parents: 685
diff changeset
   642
      $url = makeUrl($pid_clean, false, true) . $hash;
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   643
      $inner_text = $matches[2][$i];
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   644
      $quot = '"';
971
bc8f3ab74e5e Render / Template: No longer does exist checks for wikilinks on sidebar
Dan
parents: 953
diff changeset
   645
      $exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"';
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   646
      
1003
28e2f75d66fd Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents: 971
diff changeset
   647
      if ( $match_page_id && $match_namespace && $pid_clean === $paths->get_pathskey($match_page_id, $match_namespace) )
28e2f75d66fd Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents: 971
diff changeset
   648
        $exists .= ' class="currentpage"';
28e2f75d66fd Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents: 971
diff changeset
   649
      
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   650
      if ( $tplcode )
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   651
      {
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   652
        $parser->assign_vars(array(
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   653
            'HREF' => $url,
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   654
            'FLAGS' => $exists,
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   655
            'TEXT' => $inner_text
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   656
          ));
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   657
        $link = $parser->run();
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   658
      }
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   659
      else
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   660
      {
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   661
        $omatch = self::escape_parser_hint_attrib($match);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   662
        $link = "<!--#internallink src=\"$omatch\" --><a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a><!--#/internallink-->";
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   663
      }
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   664
      
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   665
      $text = str_replace($match, $link, $text);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   666
    }
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   667
    
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   668
    // stage 2 - links with no alternate text
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   669
    preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\]\]/', $text, $matches);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   670
    foreach ( $matches[0] as $i => $match )
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   671
    {
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   672
      list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   673
      $pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   674
      
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
   675
      $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
   676
      $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
   677
      $quot = '"';
971
bc8f3ab74e5e Render / Template: No longer does exist checks for wikilinks on sidebar
Dan
parents: 953
diff changeset
   678
      $exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"';
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   679
      
1003
28e2f75d66fd Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents: 971
diff changeset
   680
      if ( $match_page_id && $match_namespace && $pid_clean === $paths->get_pathskey($match_page_id, $match_namespace) )
28e2f75d66fd Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents: 971
diff changeset
   681
        $exists .= ' class="currentpage"';
28e2f75d66fd Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents: 971
diff changeset
   682
      
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   683
      if ( $tplcode )
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   684
      {
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   685
        $parser->assign_vars(array(
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   686
            'HREF' => $url,
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   687
            'FLAGS' => $exists,
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   688
            'TEXT' => $inner_text
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   689
          ));
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   690
        $link = $parser->run();
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   691
      }
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   692
      else
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   693
      {
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   694
        $omatch = self::escape_parser_hint_attrib($match);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   695
        $link = "<!--#internallink src=\"$omatch\" --><a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a><!--#/internallink-->";
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
   696
      }
91
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   697
      
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   698
      $text = str_replace($match, $link, $text);
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   699
    }
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   700
    
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   701
    return $text;
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   702
  }
8079b0288e8e Added ability to detag deleted pages
Dan
parents: 85
diff changeset
   703
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   704
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   705
   * 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
   706
   * @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
   707
   * @example
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   708
   * <code>
63
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   709
   foo = lorem ipsum
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   710
   bar = dolor sit amet
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   711
   * </code>
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   712
   * @return array Example:
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   713
   * [foo] => lorem ipsum
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   714
   * [bar] => dolor sit amet
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
  
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   717
  public static function parse_template_vars($input, $newlinemode = true)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   718
  {
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   719
    $parms = array();
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   720
    $input = trim($input);
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   721
    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
   722
    {
1054
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   723
      // we're going by newlines.
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   724
      // split by parameter, then parse each one individually
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   725
      $input = explode("\n", str_replace("\r", '', $input));
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   726
      $lastparam = '';
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   727
      $i = 0;
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   728
      foreach ( $input as $line )
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   729
      {
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   730
        if ( preg_match('/^ *\|? *([A-z0-9_]+) *= *(.+)$/', $line, $match) )
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   731
        {
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   732
          // new parameter, named
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   733
          $parms[ $match[1] ] = $match[2];
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   734
          $lastparam = $match[1];
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   735
        }
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   736
        else if ( preg_match('/^ *\| *(.+)$/', $line, $match) || $lastparam === '' )
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   737
        {
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   738
          $parms[ $i ] = $match[1];
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   739
          $lastparam = $i;
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   740
          $i++;
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   741
        }
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   742
        else
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   743
        {
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   744
          $parms[ $lastparam ] .= "\n$line";
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   745
        }
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   746
      }
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
   747
    }
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
   748
    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
   749
    {
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   750
      $result = preg_match_all('/
1054
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   751
                                 (?:^|[ ]*)\|         # start of parameter - string start or series of spaces
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   752
                                 [ ]*
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   753
                                 (?:
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   754
                                   ([A-z0-9_]+)       # variable name
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   755
                                   [ ]* = [ ]*        # assignment
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   756
                                 )?                   # name section is optional - if the parameter name is not given, a numerical index is assigned
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   757
                                 ([^\|]+|.+?\n[ ]*\|) # value
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   758
                               /x', trim($input), $matches);
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   759
      if ( $result )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   760
      {
1054
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   761
        $pi = 0;
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   762
        for ( $i = 0; $i < count($matches[0]); $i++ )
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   763
        {
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   764
          $matches[1][$i] = trim($matches[1][$i]);
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   765
          $parmname = !empty($matches[1][$i]) ? $matches[1][$i] : strval(++$pi);
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   766
          $parms[ $parmname ] = $matches[2][$i];
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   767
        }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   768
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   769
    }
1054
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   770
    // die('<pre>' . print_r($parms, true) . '</pre>');
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   771
    return $parms;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   772
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   773
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   774
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   775
   * 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
   776
   * 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
   777
   * @param string The text to process
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   778
   * @return string Formatted text
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   779
   * @example
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   780
   * <code>
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   781
   $text = '{{Template
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   782
       | parm1 = Foo
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   783
       | parm2 = Bar
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   784
     }}';
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
   785
   $text = RenderMan::include_templates($text);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   786
   * </code>
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   787
   */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   788
  
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
   789
  public static function include_templates($text)
1
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
    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
   792
    // $template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   793
    // matches:
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   794
    //  1 - template name
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   795
    //  2 - parameter section
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   796
    $template_regex = "/
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   797
                         \{\{                     # opening
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   798
                           ([^\n\t\a\r]+)         # template name
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   799
                           ((?:(?:[\s]+\|?)[ ]*(?:[A-z0-9_]+)[ ]*=[ ]*?(?:.+))*) # parameters
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   800
                         \}\}                     # closing
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   801
                       /isxU";
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   802
    if ( $count = preg_match_all($template_regex, $text, $matches) )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   803
    {
1054
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   804
      // die('<pre>' . print_r($matches, true) . '</pre>');
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   805
      for ( $i = 0; $i < $count; $i++ )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   806
      {
63
2c57d3018a88 Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents: 37
diff changeset
   807
        $matches[1][$i] = sanitize_page_id($matches[1][$i]);
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   808
        $newlinemode = ( substr($matches[2][$i], 0, 1) == "\n" );
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   809
        $parmsection = trim($matches[2][$i]);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   810
        if ( !empty($parmsection) )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   811
        {
717
236360cf79a0 Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents: 715
diff changeset
   812
          $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
   813
          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
   814
            // 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
   815
            $parms = array();
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   816
        }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   817
        else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   818
        {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   819
          $parms = Array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   820
        }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   821
        if ( $tpl_code = RenderMan::fetch_template_text($matches[1][$i]) )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   822
        {
1054
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   823
          // Intelligent paragraphs.
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   824
          // If:
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   825
          //   * A line is fully wrapped in a <p> tag
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   826
          //   * The line contains a variable
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   827
          //   * The variable contains newlines
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   828
          // Then:
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   829
          //   * Drop the <p> tag, replace it fully paragraph-ized by newlines
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   830
          
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   831
          if ( preg_match_all('/^( *)<p(\s.+)?>(.*?\{([A-z0-9]+)\}.*?)<\/p> *$/m', $tpl_code, $paramatch) )
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   832
          {
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   833
            $parser = new Carpenter();
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   834
            $parser->exclusive_rule('paragraph');
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   835
            
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   836
            foreach ( $paramatch[0] as $j => $match )
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   837
            {
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   838
              // $line is trimmed (the <p> is gone)
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   839
              $spacing =& $paramatch[1][$i];
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   840
              $para_attrs =& $paramatch[2][$j];
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   841
              $para_attrs = str_replace(array('$', '\\'), array('\$', '\\\\'), $para_attrs);
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   842
              $line =& $paramatch[3][$j];
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   843
              $varname =& $paramatch[4][$j];
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   844
              if ( isset($parms[$varname]) && strstr($parms[$varname], "\n") )
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   845
              {
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   846
                $newline = str_replace('{' . $varname . '}', $parms[$varname], $line);
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   847
                $paraized = $parser->render($newline);
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   848
                $paraized = preg_replace('/^<p>/m', "$spacing<p{$para_attrs}>", $paraized);
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   849
                $paraized = $spacing . trim($paraized);
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   850
                $tpl_code = str_replace_once($match, $paraized, $tpl_code);
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   851
              }
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   852
            }
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   853
          }
e6b14d33ac55 Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents: 1044
diff changeset
   854
          
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   855
          $parser = $template->makeParserText($tpl_code);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   856
          $parser->assign_vars($parms);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   857
          $text = str_replace($matches[0][$i], $parser->run(), $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   858
        }
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
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   862
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   863
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   864
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   865
   * Preprocesses an HTML text string prior to being sent to MySQL.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   866
   * @param string $text
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   867
   * @param bool $strip_all_php - if true, strips all PHP regardless of user permissions. Else, strips PHP only if user level < USER_LEVEL_ADMIN. Defaults to true.
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   868
   * @param bool $sqlescape - if true, sends text through $db->escape(). Otherwise returns unescaped text. Defaults to true.
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   869
   * @param bool $reduceheadings - if true, finds HTML headings and replaces them with wikitext. Else, does not touch headings. Defaults to true.
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   870
   */
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   871
  public static function preprocess_text($text, $strip_all_php = true, $sqlescape = true, $reduceheadings = true)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   872
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   873
    global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   874
    $random_id = md5( time() . mt_rand() );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   875
    
407
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   876
    $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
   877
    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
   878
    {
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   879
      eval($cmd);
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   880
    }
1
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
    $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
   883
    $can_do_html = $session->get_permissions('html_in_pages');
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   884
    
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
   885
    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
   886
    {
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
   887
      $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
   888
    }
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
   889
    else if ( !$can_do_html && !$can_do_php )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   890
    {
24
9ecc94c4c7f5 Fixed tons of bugs relating to non-templated pages
Dan
parents: 21
diff changeset
   891
      $text = sanitize_html($text, true);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   892
      // If we can't do PHP, we can't do Javascript either.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   893
      $text = RenderMan::destroy_javascript($text);
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
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   896
    // Strip out <nowiki> sections and PHP code
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   897
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   898
    $php = preg_match_all('#(<|&lt;)\?php(.*?)\?(>|&gt;)#is', $text, $phpsec);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   899
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   900
    //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
   901
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   902
    for($i=0;$i<sizeof($phpsec[1]);$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   903
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   904
      $text = str_replace($phpsec[0][$i], '{PHP:'.$random_id.':'.$i.'}', $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   905
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   906
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   907
    $nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki);
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
    for($i=0;$i<sizeof($nowiki[1]);$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   910
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   911
      $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
   912
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   913
    
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
   914
    $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
   915
    $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
   916
    $text = str_replace('~~~', "[[User:$session->username|$session->username]] ", $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   917
    
407
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   918
    $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
   919
    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
   920
    {
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   921
      eval($cmd);
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   922
    }
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 391
diff changeset
   923
    
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   924
    // gently apply some reverse-processing to allow the parser to do magic with TOCs and stuff
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   925
    if ( $reduceheadings )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 1003
diff changeset
   926
      $text = self::reverse_process_headings($text);
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
   927
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   928
    // Reinsert <nowiki> sections
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   929
    for($i=0;$i<$nw;$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   930
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   931
      $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
   932
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   933
    // Reinsert PHP
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   934
    for($i=0;$i<$php;$i++)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   935
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   936
      $phsec = ''.$phpsec[1][$i].'?php'.$phpsec[2][$i].'?'.$phpsec[3][$i].'';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   937
      if ( $strip_all_php )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   938
        $phsec = htmlspecialchars($phsec);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   939
      $text = str_replace('{PHP:'.$random_id.':'.$i.'}', $phsec, $text);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   940
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   941
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   942
    $text = ( $sqlescape ) ? $db->escape($text) : $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   943
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   944
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   945
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   946
  
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
   947
  public static function smilieyize($text, $complete_urls = false)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   948
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   949
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   950
    $random_id = md5( time() . mt_rand() );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   951
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   952
    // Smileys array - eventually this will be fetched from the database by
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   953
    // 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
   954
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   955
    $smileys = Array(
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   956
      'O:-)'    => 'face-angel.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   957
      'O:)'     => 'face-angel.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   958
      'O=)'     => 'face-angel.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   959
      ':-)'     => 'face-smile.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   960
      ':)'      => 'face-smile.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   961
      '=)'      => 'face-smile-big.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   962
      ':-('     => 'face-sad.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   963
      ':('      => 'face-sad.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   964
      ';('      => 'face-sad.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   965
      ':-O'     => 'face-surprise.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   966
      ';-)'     => 'face-wink.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   967
      ';)'      => 'face-wink.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   968
      '8-)'     => 'face-glasses.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   969
      '8)'      => 'face-glasses.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   970
      ':-D'     => 'face-grin.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   971
      ':D'      => 'face-grin.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   972
      '=D'      => 'face-grin.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   973
      ':-*'     => 'face-kiss.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   974
      ':*'      => 'face-kiss.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   975
      '=*'      => 'face-kiss.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   976
      ':\'('    => 'face-crying.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   977
      ':-|'     => 'face-plain.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   978
      ':-\\'    => 'face-plain.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   979
      ':-/'     => 'face-plain.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   980
      ':joke:'  => 'face-plain.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   981
      ']:-&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
   982
      ']:->'    => 'face-devil-grin.png',
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   983
      ':kiss:'  => 'face-kiss.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   984
      ':-P'     => 'face-tongue-out.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   985
      ':P'      => 'face-tongue-out.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   986
      ':-p'     => 'face-tongue-out.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   987
      ':p'      => 'face-tongue-out.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   988
      ':-X'     => 'face-sick.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   989
      ':X'      => 'face-sick.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   990
      ':sick:'  => 'face-sick.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   991
      ':-]'     => 'face-oops.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   992
      ':]'      => 'face-oops.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   993
      ':oops:'  => 'face-oops.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   994
      ':-['     => 'face-embarassed.png',
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   995
      ':['      => 'face-embarassed.png'
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   996
      );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   997
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   998
    // Strip out <nowiki> sections
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   999
    //return '<pre>'.htmlspecialchars($text).'</pre>';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1000
    $nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1001
    
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1002
    for ( $i = 0; $i < count($nowiki[1]); $i++ )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1003
    {
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1004
      $text = str_replace('<nowiki>' . $nowiki[1][$i] . '</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1005
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1006
    
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1007
    foreach ( $smileys as $smiley => $smiley_path )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1008
    {
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1009
      $hex_smiley = hexencode($smiley, '&#x', ';');
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1010
      $pfx = ( $complete_urls ) ? get_server_url() : '';
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1011
      $text = str_replace(' ' . $smiley,
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1012
          ' <!--#smiley code="' . self::escape_parser_hint_attrib($smiley) . '"--><nowiki>
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1013
           <!-- The above is a reverse-parser hint -->
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1014
             <img title="' . $hex_smiley . '" alt="' . $hex_smiley . '" src="' . $pfx . scriptPath . '/images/smilies/' . $smiley_path . '"
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1015
              style="border: 0;" />
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1016
           </nowiki><!--#/smiley-->', $text);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1017
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1018
    //*/
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1019
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1020
    // Reinsert <nowiki> sections
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1021
    for ( $i = 0; $i < $nw; $i++ )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1022
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1023
      $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
  1024
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1025
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1026
    return $text;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1027
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1028
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1029
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1030
   * 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
  1031
   * @param $str1 string the first block of text
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1032
   * @param $str2 string the second block of text
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1033
   * @return string
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1034
   */
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
  1035
  public static function diff($str1, $str2)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1036
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1037
    global $db, $session, $paths, $template, $plugins; // Common objects
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 569
diff changeset
  1038
    require_once(ENANO_ROOT.'/includes/diff.php');
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1039
    $str1 = explode("\n", $str1);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1040
    $str2 = explode("\n", $str2);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1041
    $diff = new Diff($str1, $str2);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1042
    $renderer = new TableDiffFormatter();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1043
    return '<table class="diff">'.$renderer->format($diff).'</table>';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1044
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1045
  
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1046
  /**
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1047
   * Changes wikitext image tags to HTML.
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1048
   * @param string The wikitext to process
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1049
   * @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
  1050
   * @return string
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
  
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
  1053
  public static function process_image_tags($text, &$taglist)
35
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
    global $db, $session, $paths, $template, $plugins; // Common objects
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1056
    
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1057
    $s_delim = "\xFF";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1058
    $f_delim = "\xFF";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1059
    $taglist = array();
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1060
    
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1061
    // 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
  1062
    $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
  1063
    $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
  1064
           \[\[                                                                  # 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
  1065
           :' . $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
  1066
           (?:(?:\|(?:.+?))*)                                                    # 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
  1067
           \]\]                                                                  # 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
  1068
           /ix';
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1069
    
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1070
    preg_match_all($regex, $text, $matches);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1071
    
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1072
    foreach ( $matches[0] as $i => $match )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1073
    {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1074
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1075
      $full_tag   =& $matches[0][$i];
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1076
      $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
  1077
      
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
  1078
      // 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
  1079
      $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
  1080
      $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
  1081
      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
  1082
      {
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
  1083
        $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
  1084
        $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
  1085
      }
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
  1086
      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
  1087
      {
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
        // 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
  1089
        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
  1090
      }
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
  1091
      
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
  1092
      // 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
  1093
      $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
  1094
      $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
  1095
      $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
  1096
      $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
  1097
      $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
  1098
      $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
  1099
      
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
  1100
      // 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
  1101
      $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
  1102
      // 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
  1103
      $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
  1104
      $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
  1105
      // 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
  1106
      $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
  1107
      
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
  1108
      // 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
  1109
      // 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
  1110
      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
  1111
      {
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
  1112
        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
  1113
        {
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
  1114
          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
  1115
          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
  1116
            $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
  1117
            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
  1118
          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
  1119
            $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
  1120
            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
  1121
          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
  1122
            $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
  1123
            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
  1124
          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
  1125
            // 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
  1126
            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
  1127
            {
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
  1128
              $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
  1129
              $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
  1130
              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
  1131
            }
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
  1132
            // not the height, so see if a plugin took this over
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1133
            // this hook requires plugins to return true if they modified anything
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
            $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
  1135
            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
  1136
            {
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
  1137
              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
  1138
                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
  1139
            }
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
  1140
            // 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
  1141
            // 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
  1142
            $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
  1143
            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
  1144
        }
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
  1145
      }
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1146
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1147
      if ( !isPage( $paths->nslist['File'] . $filename ) )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1148
      {
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1149
        $text = str_replace($full_tag, '[[' . $paths->nslist['File'] . $filename . ']]', $text);
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1150
        continue;
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
      
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
      if ( $scale_type == 'thumb' )
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1154
      {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1155
        $r_width  = 225;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1156
        $r_height = 225;
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
        $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
  1159
      }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1160
      else if ( !empty($width) && !empty($height) )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1161
      {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1162
        $r_width = $width;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1163
        $r_height = $height;
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
        $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
  1166
      }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1167
      else
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1168
      {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1169
        $url = makeUrlNS('Special', 'DownloadFile/' . $filename);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1170
      }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1171
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1172
      $img_tag = '<img src="' . $url . '" ';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1173
      
65
627d0a8a7819 Last-minute change to width/height on embedded images
Dan
parents: 63
diff changeset
  1174
      // 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
  1175
      // {
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
  1176
      //   $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" ';
65
627d0a8a7819 Last-minute change to width/height on embedded images
Dan
parents: 63
diff changeset
  1177
      // }
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1178
      
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
  1179
      $img_tag .= 'style="border-width: 0px; /* background-color: white; */" ';
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1180
      
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
  1181
      $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
  1182
      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
  1183
      {
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
  1184
        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
  1185
      }
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
  1186
      
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1187
      $img_tag .= '/>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1188
      
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1189
      $s_full_tag = self::escape_parser_hint_attrib($full_tag);
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1190
      $complete_tag = '<!--#imagelink src="' . $s_full_tag . '" -->';
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1191
      
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
  1192
      if ( !empty($scale_type) && !$raw_display )
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1193
      {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1194
        $complete_tag .= '<div class="thumbnail" ';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1195
        $clear_text = '';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1196
        if ( !empty($clear) )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1197
        {
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
  1198
          $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
  1199
          $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
  1200
          $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
  1201
          $complete_tag .= 'style="' . $clear_text . '" ';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1202
        }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1203
        $complete_tag .= '>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1204
        
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1205
        $complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1206
        $complete_tag .= $img_tag;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1207
        $complete_tag .= '</a>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1208
        
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1209
        $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
  1210
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1211
        if ( !empty($caption) )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1212
        {
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
  1213
          $complete_tag .= $mag_button . $caption;
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1214
        }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1215
        
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1216
        $complete_tag .= '</div>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1217
      }
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
  1218
      else if ( $raw_display )
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
  1219
      {
67
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
  1220
        $complete_tag .= "$img_tag";
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
  1221
        $taglist[$i] = $complete_tag;
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
  1222
        
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
  1223
        $repl = "{$s_delim}e_img_{$i}{$f_delim}";
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
  1224
        $text = str_replace($full_tag, $repl, $text);
f6454d5fec7a Made raw images + internal/external links work right
Dan
parents: 66
diff changeset
  1225
        continue;
66
52017732bc20 Added "raw" option to embedded images to make complex clickables easier
Dan
parents: 65
diff changeset
  1226
      }
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1227
      else
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1228
      {
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
  1229
        $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
  1230
        $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
  1231
        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
  1232
        {
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
  1233
          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
  1234
        }
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
  1235
        $complete_tag .= '>';
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1236
        $complete_tag .= $img_tag;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1237
        $complete_tag .= '</a>';
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1238
      }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1239
      
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1240
      $complete_tag .= "<!--#/imagelink-->";
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1241
      $taglist[$i] = $complete_tag;
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1242
      
832
7152ca0a0ce9 Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents: 801
diff changeset
  1243
      /*
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1244
      $pos = strpos($text, $full_tag);
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1245
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1246
      while(true)
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1247
      {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1248
        $check1 = substr($text, $pos, 3);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1249
        $check2 = substr($text, $pos, 1);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1250
        if ( $check1 == '<p>' || $pos == 0 || $check2 == "\n" )
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1251
        {
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1252
          // die('found at pos '.$pos);
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1253
          break;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1254
        }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1255
        $pos--;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1256
      }
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
  1257
      */
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1258
      
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
  1259
      /*
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1260
      $repl = "{$s_delim}e_img_{$i}{$f_delim}";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1261
      $text = substr($text, 0, $pos) . $repl . substr($text, $pos);
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1262
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1263
      $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
  1264
      */
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
  1265
      $text = str_replace_once($full_tag, $complete_tag, $text);
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1266
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1267
      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
  1268
      
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1269
    }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1270
    
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
  1271
    // 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
  1272
    //   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
  1273
    
35
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1274
    return $text;
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1275
  }
efae425e9b98 Finally implemented the new image tag code
Dan
parents: 24
diff changeset
  1276
  
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1277
  /**
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1278
   * Finalizes processing of image tags.
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1279
   * @param string The preprocessed text
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1280
   * @param array The list of image tags created by RenderMan::process_image_tags()
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1281
   */
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1282
   
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
  1283
  public static function process_imgtags_stage2($text, $taglist)
37
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1284
  {
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1285
    $s_delim = "\xFF";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1286
    $f_delim = "\xFF";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1287
    foreach ( $taglist as $i => $tag )
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1288
    {
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1289
      $repl = "{$s_delim}e_img_{$i}{$f_delim}";
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1290
      $text = str_replace($repl, $tag, $text);
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1291
    }               
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1292
    return $text;
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1293
  }
7267c2a67a93 More image tag parser fixes
Dan
parents: 35
diff changeset
  1294
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1295
}
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1296
 
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1297
?>