Changeset 252 for trunk/plugins
- Timestamp:
- 08/06/06 12:04:18 (2 years ago)
- Location:
- trunk/plugins
- Files:
-
- 2 modified
-
acronyms.php (modified) (1 diff)
-
test.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
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 ?>
