From c29849f06ad0768d97c91018ecd25f7404a335e8 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 26 Jan 2016 14:12:43 +0100 Subject: [PATCH] consistent plugin usage - bbcode this and followup commits touches: use load_languiage API class method parenthesis "\n{\n \n}\n", case break switches, consistent boolean usage, append css to eventData and other cleanups --- .../serendipity_event_bbcode.php | 65 ++++++++++++------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/plugins/serendipity_event_bbcode/serendipity_event_bbcode.php b/plugins/serendipity_event_bbcode/serendipity_event_bbcode.php index 8c9aac11..bcf0b599 100644 --- a/plugins/serendipity_event_bbcode/serendipity_event_bbcode.php +++ b/plugins/serendipity_event_bbcode/serendipity_event_bbcode.php @@ -1,4 +1,8 @@ -add('description', PLUGIN_EVENT_BBCODE_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Jez Hancock, Garvin Hicking'); - $propbag->add('version', '2.09'); + $propbag->add('version', '2.10'); $propbag->add('requirements', array( - 'serendipity' => '0.8', + 'serendipity' => '1.6', 'smarty' => '2.6.7', 'php' => '4.1.0' )); $propbag->add('cachable_events', array('frontend_display' => true)); - $propbag->add('event_hooks', array('frontend_display' => true, 'frontend_comment' => true, 'css' => true)); + $propbag->add('event_hooks', array('frontend_display' => true, 'frontend_comment' => true, 'css' => true)); $propbag->add('groups', array('MARKUP')); $this->markup_elements = array( @@ -51,8 +55,8 @@ class serendipity_event_bbcode extends serendipity_event $propbag->add('configuration', $conf_array); } - - function bbcode_callback($matches) { + function bbcode_callback($matches) + { $type = $matches[1]; $input = trim($matches[2], "\r\n"); @@ -102,11 +106,11 @@ class serendipity_event_bbcode extends serendipity_event return($input); } - function generate_content(&$title) { + function generate_content(&$title) + { $title = $this->title; } - function introspect_config_item($name, &$propbag) { switch($name) { @@ -131,16 +135,19 @@ class serendipity_event_bbcode extends serendipity_event return true; } - function install() { + function install() + { serendipity_plugin_api::hook_event('backend_cache_entries', $this->title); } - function uninstall(&$propbag) { + function uninstall(&$propbag) + { serendipity_plugin_api::hook_event('backend_cache_purge', $this->title); serendipity_plugin_api::hook_event('backend_cache_entries', $this->title); } - function bbcode($input) { + function bbcode($input) + { static $bbcodes = null; // Only allow numbers and characters for CSS: "red", "#FF0000", ... @@ -224,39 +231,42 @@ class serendipity_event_bbcode extends serendipity_event } - function event_hook($event, &$bag, &$eventData, $addData = null) { + function event_hook($event, &$bag, &$eventData, $addData = null) + { global $serendipity; $hooks = &$bag->get('event_hooks'); if (isset($hooks[$event])) { + switch($event) { + case 'frontend_display': foreach ($this->markup_elements as $temp) { - if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) && + if (serendipity_db_bool($this->get_config($temp['name'], 'true')) && isset($eventData[$temp['element']]) && !$eventData['properties']['ep_disable_markup_' . $this->instance] && !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) { $element = $temp['element']; $eventData[$element] = $this->bbcode($eventData[$element]); } } - return true; break; case 'frontend_comment': - if (serendipity_db_bool($this->get_config('COMMENT', true))) { + if (serendipity_db_bool($this->get_config('COMMENT', 'true'))) { echo '
' . PLUGIN_EVENT_BBCODE_TRANSFORM . '
'; } - return true; break; case 'css': - if (strpos($eventData, '.bb-code') !== false) { - // class exists in CSS, so a user has customized it and we don't need default - return true; - } -?> + // CSS class does NOT exist by user customized template styles, include default + if (strpos($eventData, '.bb-code') === false) { + $eventData .= ' + + +/* serendipity_event_bbcode start */ + .bb-quote, .bb-code, .bb-php, .bb-code-title, .bb-php-title { margin-left: 20px; margin-right: 20px; @@ -294,18 +304,23 @@ class serendipity_event_bbcode extends serendipity_event .bb-list-ordered-ua { list-style-type: upper-alpha; } - +?> \ No newline at end of file