b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (Version 1.9) [ class tree: plugins ] [ index: plugins ] [ all elements ]

Source for file _bbcode.plugin.php

Documentation is available at _bbcode.plugin.php

  1. <?php
  2. /**
  3.  * This file implements the BBcode plugin for b2evolution
  4.  *
  5.  * BB style formatting, like [b]bold[/b]
  6.  *
  7.  * b2evolution - {@link http://b2evolution.net/}
  8.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  9.  * @copyright (c)2003-2006 by Francois PLANQUE - {@link http://fplanque.net/}
  10.  *
  11.  * @package plugins
  12.  */
  13. if!defined('EVO_MAIN_INIT') ) die'Please, do not access this page directly.' );
  14.  
  15.  
  16. /**
  17.  * @package plugins
  18.  */
  19. class bbcode_plugin extends Plugin
  20. {
  21.     var $code = 'b2evBBco';
  22.     var $name = 'BB code';
  23.     var $priority = 50;
  24.     var $version = '1.9-dev';
  25.     var $apply_rendering = 'opt-in';
  26.     var $group = 'rendering';
  27.     var $short_desc;
  28.     var $long_desc;
  29.  
  30.     /*
  31.      * Internal
  32.      */
  33.     var $post_search_list;
  34.     var $post_replace_list;
  35.     var $comment_search_list;
  36.     var $comment_replace_list;
  37.  
  38.     /**
  39.      * Init
  40.      */
  41.     function PluginInit$params )
  42.     {
  43.         $this->short_desc = T_('BB formatting e-g [b]bold[/b]');
  44.         $this->long_desc = T_('Available tags are: [b] [i] [u] [s] [color=...] [size=...] [font=...] [code] [quote] [list=1] [list=a] [list] [*]');
  45.     }
  46.  
  47.     /**
  48.      * Get the default settings of the plugin.
  49.      *
  50.      * @return array 
  51.      */
  52.     function GetDefaultSettings()
  53.     {
  54.         return array(
  55.             'post_settings_begin' => array(
  56.                 'layout' => 'begin_fieldset',
  57.                 'label' => $this->T_'Settings for posts' ),
  58.             ),
  59.             'post_search_list' => array(
  60.                 'label' => $this->T_'Search list'),
  61.                 'note' => $this->T_'This is the BBcode search array for posts (one per line) ONLY CHANGE THESE IF YOU KNOW WHAT YOU\'RE DOING' ),
  62.                 'type' => 'html_textarea',
  63.                 'rows' => 10,
  64.                 'defaultvalue' => '#\[b](.+?)\[/b]#is
  65. #\[i](.+?)\[/i]#is
  66. #\[u](.+?)\[/u]#is
  67. #\[s](.+?)\[/s]#is
  68. !\[color=(#?[A-Za-z0-9]+?)](.+?)\[/color]!is
  69. #\[size=([0-9]+?)](.+?)\[/size]#is
  70. #\[font=([A-Za-z0-9 ;\-]+?)](.+?)\[/font]#is
  71. #\[code](.+?)\[/code]#is
  72. #\[quote](.+?)\[/quote]#is
  73. #\[list=1](.+?)\[/list]#is
  74. #\[list=a](.+?)\[/list]#is
  75. #\[list](.+?)\[/list]#is
  76. #\[\*](.+?)\n#is
  77. !\[bg=(#?[A-Za-z0-9]+?)](.+?)\[/bg]!is',
  78.             ),
  79.             'post_replace_list' => array(
  80.                 'label' => $this->T_'Replace list'),
  81.                 'note' => $this->T_'This is the replace array for posts (one per line) it must match the exact order of the search array' ),
  82.                 'type' => 'html_textarea',
  83.                 'rows' => 10,
  84.                 'defaultvalue' => '<strong>$1</strong>
  85. <em>$1</em>
  86. <span style="text-decoration:underline">$1</span>
  87. <span style="text-decoration:line-through">$1</span>
  88. <span style="color:$1">$2</span>
  89. <span style="font-size:$1px">$2</span>
  90. <span style="font-family:$1">$2</span>
  91. <pre>$1</pre>
  92. &laquo;&nbsp;$1&nbsp;&raquo;
  93. <ol type="1">$1</ol>
  94. <ol type="a">$1</ol>
  95. <ul>$1</ul>
  96. <li>$1</li>
  97. <span style="background-color:$1">$2</span>',
  98.             ),
  99.             'post_settings_end' => array(
  100.                 'layout' => 'end_fieldset',
  101.             ),
  102.             'comment_settings_begin' => array(
  103.                 'type' => 'layout',
  104.                 'layout' => 'begin_fieldset',
  105.                 'label' => $this->T_'Settings for comments' ),
  106.             ),
  107.             'render_comments' => array(
  108.                 'label' => $this->T_('Render comments' ),
  109.                 'note' => $this->T_('If enabled the BBcode in comments will be rendered'),
  110.                 'defaultvalue' => 0,
  111.                 'type' => 'checkbox',
  112.             ),
  113.             'comment_search_list' => array(
  114.                 'label' => $this->T_'Search list'),
  115.                 'note' => $this->T_'This is the BBcode search array for COMMENTS (one per line) ONLY CHANGE THESE IF YOU KNOW WHAT YOU\'RE DOING' ),
  116.                 'type' => 'html_textarea',
  117.                 'rows' => 10,
  118.                 'defaultvalue' => '#\[b](.+?)\[/b]#is
  119. #\[i](.+?)\[/i]#is
  120. #\[u](.+?)\[/u]#is
  121. #\[s](.+?)\[/s]#is
  122. !\[color=(#?[A-Za-z0-9]+?)](.+?)\[/color]!is
  123. #\[size=([0-9]+?)](.+?)\[/size]#is
  124. #\[font=([A-Za-z0-9 ;\-]+?)](.+?)\[/font]#is
  125. #\[code](.+?)\[/code]#is
  126. #\[quote](.+?)\[/quote]#is
  127. #\[list=1](.+?)\[/list]#is
  128. #\[list=a](.+?)\[/list]#is
  129. #\[list](.+?)\[/list]#is
  130. #\[\*](.+?)\n#is
  131. !\[bg=(#?[A-Za-z0-9]+?)](.+?)\[/bg]!is',
  132.             ),
  133.             'comment_replace_list' => array(
  134.                 'label' => $this->T_'Replace list'),
  135.                 'note' => $this->T_'This is the replace array for COMMENTS (one per line) it must match the exact order of the search array' ),
  136.                 'type' => 'html_textarea',
  137.                 'rows' => 10,
  138.                 'defaultvalue' => '<strong>$1</strong>
  139. <em>$1</em>
  140. <span style="text-decoration:underline">$1</span>
  141. <span style="text-decoration:line-through">$1</span>
  142. <span style="color:$1">$2</span>
  143. <span style="font-size:$1px">$2</span>
  144. <span style="font-family:$1">$2</span>
  145. <pre>$1</pre>
  146. &laquo;&nbsp;$1&nbsp;&raquo;
  147. <ol type="1">$1</ol>
  148. <ol type="a">$1</ol>
  149. <ul>$1</ul>
  150. <li>$1</li>
  151. <span style="background-color:$1">$2</span>',
  152.             ),
  153.             'comment_settings_end' => array(
  154.                 'type' => 'layout',
  155.                 'layout' => 'end_fieldset',
  156.             ),
  157.         );
  158.     }
  159.  
  160.     /**
  161.      * Perform rendering
  162.      *
  163.      * @see Plugin::RenderItemAsHtml()
  164.      */
  165.     function RenderItemAsHtml$params )
  166.     {
  167.         $content $params['data'];
  168.         if!isset$this->post_search_list ) )
  169.             $this->post_search_list = explode"\n"str_replace"\r"''$this->Settings->get'post_search_list' ) ) );
  170.  
  171.         if!isset$this->post_replace_list ) )
  172.             $this->post_replace_list = explode"\n"str_replace"\r"''$this->Settings->get'post_replace_list' ) ) );
  173.  
  174.         $content preg_replace$this->post_search_list$this->post_replace_list$content );
  175.  
  176.         return true;
  177.     }
  178.  
  179.  
  180.     /**
  181.      * Do the same as for HTML.
  182.      *
  183.      * @see RenderItemAsHtml()
  184.      */
  185.     function RenderItemAsXml$params )
  186.     {
  187.         $this->RenderItemAsHtml$params );
  188.     }
  189.  
  190.     /**
  191.      *
  192.      * Render comments if required
  193.      *
  194.      * @see Plugin::FilterCommentContent()
  195.      */
  196.     function FilterCommentContent$params )
  197.     {
  198.         if$this->Settings->get'render_comments' ) )
  199.         {
  200.         $content $params['data'];
  201.         if!isset$this->comment_search_list ) )
  202.             $this->comment_search_list = explode"\n"str_replace"\r"''$this->Settings->get'comment_search_list' ) ) );
  203.  
  204.         if!isset$this->comment_replace_list ) )
  205.             $this->comment_replace_list = explode"\n"str_replace"\r"''$this->Settings->get'comment_replace_list' ) ) );
  206.  
  207.         $content preg_replace$this->comment_search_list$this->comment_replace_list$content );
  208.         }
  209.     }
  210. }
  211.  
  212.  
  213. /*
  214.  * $Log: _bbcode.plugin.php,v $
  215.  * Revision 1.17.2.3  2006/12/26 03:18:50  fplanque
  216.  * assigned a few significant plugin groups
  217.  *
  218.  * Revision 1.17.2.2  2006/11/04 19:55:11  fplanque
  219.  * Reinjected old Log blocks. Removing them from CVS was a bad idea -- especially since Daniel has decided branch 1.9 was his HEAD...
  220.  *
  221.  * Revision 1.17  2006/07/31 16:12:18  yabs
  222.  * Modified 'allow_html' to html_input/html_textarea
  223.  *
  224.  * Revision 1.16  2006/07/31 07:52:03  yabs
  225.  * Moved search and replace arrays to Settings
  226.  * Added new Setting to enable rendering of comments
  227.  * Added 2 new Settings for comment search and replace arrays
  228.  *
  229.  * Revision 1.15  2006/07/10 20:19:30  blueyed
  230.  * Fixed PluginInit behaviour. It now gets called on both installed and non-installed Plugins, but with the "is_installed" param appropriately set.
  231.  *
  232.  * Revision 1.14  2006/07/07 21:26:49  blueyed
  233.  * Bumped to 1.9-dev
  234.  *
  235.  * Revision 1.13  2006/07/06 19:56:29  fplanque
  236.  * no message
  237.  *
  238.  * Revision 1.12  2006/06/16 21:30:57  fplanque
  239.  * Started clean numbering of plugin versions (feel free do add dots...)
  240.  *
  241.  * Revision 1.11  2006/05/30 19:39:55  fplanque
  242.  * plugin cleanup
  243.  *
  244.  * Revision 1.10  2006/04/11 21:22:26  fplanque
  245.  * partial cleanup
  246.  *
  247.  */
  248. ?>

Documentation generated on Tue, 18 Dec 2007 19:10:52 +0100 by phpDocumentor 1.4.0