[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/mambots/content/ -> moscode.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @author Mambo Foundation Inc see README.php
   5  * @copyright (C) 2000 - 2009 Mambo Foundation Inc.
   6  * See COPYRIGHT.php for copyright notices and details.
   7  * @license GNU/GPL Version 2, see LICENSE.php
   8  *
   9  * Redistributions of files must retain the above copyright notice.
  10  *
  11  * Mambo is free software; you can redistribute it and/or
  12  * modify it under the terms of the GNU General Public License
  13  * as published by the Free Software Foundation; version 2 of the License.
  14  */
  15  
  16  /** ensure this file is being included by a parent file */
  17  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  18  
  19  $_MAMBOTS->registerFunction( 'onPrepareContent', 'botMosCode' );
  20  
  21  /**
  22  * Code Highlighting Mambot
  23  *
  24  * <strong>Usage:</strong>
  25  * <code>{moscode}...some code...{/moscode}</code>
  26  */
  27  function botMosCode( $published, &$row, &$params, $page=0 ) {
  28      // define the regular expression for the bot
  29      $regex = "#{moscode}(.*?){/moscode}#s";
  30  
  31      if (is_callable(array($row, 'getText'))) $localtext = $row->getText();
  32      else $localtext = $row->text;
  33      if (!$published) {
  34          $localtext = preg_replace( $regex, '', $localtext );
  35          if (is_callable(array($row, 'saveText'))) $row->saveText($localtext);
  36          else $row->text = $localtext;
  37          return;
  38      }
  39  
  40  
  41      // perform the replacement
  42      $localtext = preg_replace_callback( $regex, 'botMosCode_replacer', $localtext );
  43      if (is_callable(array($row, 'saveText'))) $row->saveText($localtext);
  44      else $row->text = $localtext;
  45  
  46      return true;
  47  }
  48  /**
  49  * Replaces the matched tags an image
  50  * @param array An array of matches (see preg_match_all)
  51  * @return string
  52  */
  53  function botMosCode_replacer( &$matches ) {
  54      $html_entities_match = array("#<#", "#>#");
  55      $html_entities_replace = array("&lt;", "&gt;");
  56  
  57      $text = $matches[1];
  58  
  59      $text = preg_replace($html_entities_match, $html_entities_replace, $text );
  60  
  61      // Replace 2 spaces with "&nbsp; " so non-tabbed code indents without making huge long lines.
  62      $text = str_replace("  ", "&nbsp; ", $text);
  63      // now Replace 2 spaces with " &nbsp;" to catch odd #s of spaces.
  64      $text = str_replace("  ", " &nbsp;", $text);
  65  
  66      // Replace tabs with "&nbsp; &nbsp;" so tabbed code indents sorta right without making huge long lines.
  67      $text = str_replace("\t", "&nbsp; &nbsp;", $text);
  68  
  69      $text = str_replace('&lt;', '<', $text);
  70      $text = str_replace('&gt;', '>', $text);
  71  
  72      $text = highlight_string( $text, 1 );
  73  
  74      $text = str_replace('&amp;nbsp;', '&nbsp;', $text);
  75      $text = str_replace('&lt;br/&gt;', '<br />', $text);
  76      $text = str_replace('<font color="#007700">&lt;</font><font color="#0000BB">br</font><font color="#007700">/&gt;','<br />', $text);
  77      $text = str_replace('&amp;</font><font color="#0000CC">nbsp</font><font color="#006600">;', '&nbsp;', $text);
  78      $text = str_replace('&amp;</font><font color="#0000BB">nbsp</font><font color="#007700">;', '&nbsp;', $text);
  79      $text = str_replace('<font color="#007700">;&lt;</font><font color="#0000BB">br</font><font color="#007700">/&gt;','<br />', $text);
  80  
  81      return $text;
  82  }
  83  ?>