Annotation of /mambo/branches/4.6/mambots/content/moscode.php
Parent Directory
|
Revision Log
Revision 941 - (view) (download)
| 1 : | root | 1 | <?php |
| 2 : | /** | ||
| 3 : | csouza | 297 | * @package Mambo Open Source |
| 4 : | cauld | 941 | * @copyright (C) 2005 - 2007 Mambo Foundation Inc. |
| 5 : | root | 1 | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL |
| 6 : | csouza | 297 | * |
| 7 : | * Mambo was originally developed by Miro (www.miro.com.au) in 2000. Miro assigned the copyright in Mambo to The Mambo Foundation in 2005 to ensure | ||
| 8 : | * that Mambo remained free Open Source software owned and managed by the community. | ||
| 9 : | root | 1 | * Mambo is Free Software |
| 10 : | csouza | 297 | */ |
| 11 : | root | 1 | |
| 12 : | /** ensure this file is being included by a parent file */ | ||
| 13 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 14 : | |||
| 15 : | $_MAMBOTS->registerFunction( 'onPrepareContent', 'botMosCode' ); | ||
| 16 : | |||
| 17 : | /** | ||
| 18 : | * Code Highlighting Mambot | ||
| 19 : | * | ||
| 20 : | * <b>Usage:</b> | ||
| 21 : | * <code>{moscode}...some code...{/moscode}</code> | ||
| 22 : | */ | ||
| 23 : | function botMosCode( $published, &$row, &$params, $page=0 ) { | ||
| 24 : | // define the regular expression for the bot | ||
| 25 : | $regex = "#{moscode}(.*?){/moscode}#s"; | ||
| 26 : | |||
| 27 : | counterpoi | 213 | t if (is_callable(array($row, 'getText'))) $localtext = $row->getText(); |
| 28 : | t else $localtext = $row->text; | ||
| 29 : | root | 1 | if (!$published) { |
| 30 : | counterpoi | 213 | t $localtext = preg_replace( $regex, '', $localtext ); |
| 31 : | t if (is_callable(array($row, 'saveText'))) $row->saveText($localtext); | ||
| 32 : | t else $row->text = $localtext; | ||
| 33 : | root | 1 | return; |
| 34 : | } | ||
| 35 : | |||
| 36 : | |||
| 37 : | // perform the replacement | ||
| 38 : | counterpoi | 213 | t $localtext = preg_replace_callback( $regex, 'botMosCode_replacer', $localtext ); |
| 39 : | t if (is_callable(array($row, 'saveText'))) $row->saveText($localtext); | ||
| 40 : | t else $row->text = $localtext; | ||
| 41 : | root | 1 | |
| 42 : | return true; | ||
| 43 : | } | ||
| 44 : | /** | ||
| 45 : | * Replaces the matched tags an image | ||
| 46 : | * @param array An array of matches (see preg_match_all) | ||
| 47 : | * @return string | ||
| 48 : | */ | ||
| 49 : | function botMosCode_replacer( &$matches ) { | ||
| 50 : | $html_entities_match = array("#<#", "#>#"); | ||
| 51 : | $html_entities_replace = array("<", ">"); | ||
| 52 : | |||
| 53 : | $text = $matches[1]; | ||
| 54 : | |||
| 55 : | $text = preg_replace($html_entities_match, $html_entities_replace, $text ); | ||
| 56 : | |||
| 57 : | // Replace 2 spaces with " " so non-tabbed code indents without making huge long lines. | ||
| 58 : | $text = str_replace(" ", " ", $text); | ||
| 59 : | // now Replace 2 spaces with " " to catch odd #s of spaces. | ||
| 60 : | $text = str_replace(" ", " ", $text); | ||
| 61 : | |||
| 62 : | // Replace tabs with " " so tabbed code indents sorta right without making huge long lines. | ||
| 63 : | $text = str_replace("\t", " ", $text); | ||
| 64 : | |||
| 65 : | $text = str_replace('<', '<', $text); | ||
| 66 : | $text = str_replace('>', '>', $text); | ||
| 67 : | |||
| 68 : | $text = highlight_string( $text, 1 ); | ||
| 69 : | |||
| 70 : | $text = str_replace('&nbsp;', ' ', $text); | ||
| 71 : | $text = str_replace('<br/>', '<br />', $text); | ||
| 72 : | $text = str_replace('<font color="#007700"><</font><font color="#0000BB">br</font><font color="#007700">/>','<br />', $text); | ||
| 73 : | $text = str_replace('&</font><font color="#0000CC">nbsp</font><font color="#006600">;', ' ', $text); | ||
| 74 : | $text = str_replace('&</font><font color="#0000BB">nbsp</font><font color="#007700">;', ' ', $text); | ||
| 75 : | $text = str_replace('<font color="#007700">;<</font><font color="#0000BB">br</font><font color="#007700">/>','<br />', $text); | ||
| 76 : | |||
| 77 : | return $text; | ||
| 78 : | } | ||
| 79 : | counterpoi | 213 | t ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

