Changeset 252
- Timestamp:
- 08/06/06 12:04:18 (2 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 modified
-
common/mvblog.php (modified) (7 diffs)
-
common/plugins.php (added)
-
plugins/acronyms.php (modified) (1 diff)
-
plugins/test.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/common/mvblog.php
r247 r252 97 97 */ 98 98 public $webroot = ""; 99 public $plugman; 99 100 /* }}} */ 100 101 … … 143 144 /* populate the categories array */ 144 145 $this->_get_categories(); 146 147 /* plugin handling */ 148 require_once("plugins.php"); 149 $plugman = new MvBlog_pluginmgr("plugins/", $this); 150 #$plugman->activate_plugin("acronyms"); 151 $plugman->set_active_plugins(array("acronyms")); 152 $this->plugman = $plugman; 145 153 } 146 154 /* }}} */ … … 175 183 /* _init_db {{{ */ 176 184 protected function _init_db() { 177 require ("DB.php");178 require ("hosts.php");185 require_once("DB.php"); 186 require_once("hosts.php"); 179 187 180 188 $options = array( … … 523 531 <?php } ?> 524 532 <?php 525 $text = $this->run_plugins($this->strip_invalid_xml(stripslashes($row["body"])), "text_output"); 533 $text = $this->strip_invalid_xml(stripslashes($row["body"])); 534 $text = $this->plugman->run_hooks("text_output", $text); 526 535 if ($this->limit_text($text, 4000)) { 527 536 echo $text; … … 1236 1245 /** 1237 1246 * load all the plugins 1247 * obsoleted by MvBlog_pluginmgr 1238 1248 */ 1239 1249 public function load_plugins() { 1240 /* this should become a setting */ 1241 $plugins = array(); 1242 $plugin_dir = "plugins/"; 1243 if (is_dir($plugin_dir)) { 1244 $plug_fd = opendir($plugin_dir); 1245 while (false !== ($fp = readdir($plug_fd))) { 1246 if (!preg_match("/^\./", $fp)) { 1247 require_once($plugin_dir.$fp); 1248 } 1249 } 1250 } 1250 return true; 1251 1251 } 1252 1252 /* }}} */ … … 1254 1254 /** 1255 1255 * register the plugin in the global plugin array 1256 * obsoleted by MvBlog_pluginmgr 1256 1257 * 1257 1258 * @param string $name the plugin name … … 1260 1261 */ 1261 1262 public function register_plugin($name, $type) { 1262 $this->plugins[$type][] = $name;1263 return true; 1263 1264 } 1264 1265 /* }}} */ -
trunk/plugins/acronyms.php
r83 r252 1 1 <?php 2 register_plugin("acroreplace", "text_output"); 2 Class acronyms extends MvBlog_plugin implements MvBlog_pluginiface { 3 /* variables */ 4 public $name = "Acronyms"; 5 public $author = "Michiel van Baak"; 6 public $license = "GPL"; 7 public $website = "http://www.mvblog.org"; 3 8 4 function plugin_acroreplace($text) { 5 /* get all acronyms from database */ 6 $res =& $GLOBALS["db"]->query("SELECT acronym,description FROM acronyms"); 7 if (PEAR::isError($res)) { 8 die($res->getMessage()); 9 private $_mvblog; 10 private $_acronyms; 11 12 /* methods */ 13 public function __construct(&$mvblog) { 14 $this->addHook("text_output", "acroreplace"); 15 $this->_mvblog =& $mvblog; 9 16 } 10 while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) { 11 $acronyms[$row["acronym"]] = $row["description"]; 17 18 public function activate() { 19 /* get all acronyms from database */ 20 $res =& $this->_mvblog->db->query("SELECT acronym,description FROM acronyms"); 21 if (PEAR::isError($res)) { 22 die($res->getMessage()); 23 } 24 while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) { 25 $this->_acronyms[$row["acronym"]] = $row["description"]; 26 } 12 27 } 13 foreach ($acronyms as $acronym => $description) { 14 //replace all the supplied acronyms 15 $text = preg_replace("|(?!<[^<>]*?)(?<![?./&])\b$acronym\b(?!:)(?![^<>]*?>)|imsU","<acronym class=\"blog_acro\" title=\"$description\">$acronym</acronym>" , $text); 16 //allow user to overwrite acronym replacing by putting the term between $ signs 17 $text = preg_replace("|[$]<acronym class=\"blog_acro\" title=\"$description\">$acronym</acronym>[$]|imsU" , "$acronym" , $text); 28 29 public function deactivate() { 30 unset($this->_acronyms); 18 31 } 19 return trim($text); 32 33 public function acroreplace($text) { 34 foreach ($this->_acronyms as $acronym => $description) { 35 //replace all the supplied acronyms 36 $text = preg_replace("|(?!<[^<>]*?)(?<![?./&])\b$acronym\b(?!:)(?![^<>]*?>)|imsU","<acronym class=\"blog_acro\" title=\"$description\">$acronym</acronym>" , $text); 37 //allow user to overwrite acronym replacing by putting the term between $ signs 38 $text = preg_replace("|[$]<acronym class=\"blog_acro\" title=\"$description\">$acronym</acronym>[$]|imsU" , "$acronym" , $text); 39 } 40 return trim($text); 41 } 20 42 } 21 43 ?> -
trunk/plugins/test.php
r126 r252 1 1 <?php 2 /* 3 * skeleton plugin. 4 */ 5 register_plugin("test", "text_output"); 6 if (function_exists("register_admin_plugin")) { 7 register_admin_plugin("test", "text_output"); 8 } 9 /* function to run when this plugin kicks in */ 10 /* name is plugin_pluginname */ 11 function plugin_test($data) { 12 $output = str_ireplace("michiel", "The MvBlog Projectleader", $data); 13 return $output; 14 } 2 Class test extends MvBlog_plugin implements MvBlog_pluginiface { 3 /* variables */ 4 public $name = "test"; 5 public $author = "Michiel van Baak"; 6 public $license = "GPL"; 7 public $website = "http://www.mvblog.org"; 15 8 16 /* admin functions */ 17 /* edit, save and overview are required */ 18 function plugin_test_edit() { 19 /* code to show a screen to edit settings etc */ 20 } 9 private $_mvblog; 21 10 22 function plugin_test_save() { 23 /* code to save changes */ 24 } 11 /* methods */ 12 public function __construct(&$mvblog) { 13 $this->addHook("text_output", "test"); 14 $this->_mvblog =& $mvblog; 15 } 25 16 26 function plugin_test_overview() { 27 /* code to show screen with items or description of plugin or whatever */ 17 public function activate() { 18 /* get data, do whatever is needed on plugin activation */ 19 } 20 21 public function deactivate() { 22 } 23 24 public function test($text) { 25 $output = str_ireplace("michiel", "The MvBlog Projectleader", $text); 26 $output = str_ireplace("mafkees", "The MvBlog Projectleader", $output); 27 return $output; 28 } 28 29 } 29 30 ?>
