b2evolution

Multilingual multiuser multiblog engine

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

Documentation generated on Sat, 06 Mar 2010 03:27:40 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).