From b2c16bf312cd037e252e568974a5523407e42099 Mon Sep 17 00:00:00 2001 From: Jeremy Laine Date: Mon, 15 May 2006 18:20:42 +0000 Subject: [PATCH] rework plugin handling to access parameters via declareParam, getParamValues, setParamValues, getParamNames --- include/Plugin/Editor.php | 6 ++--- include/Plugin/Skel.php | 62 ++++++++++++++++++++++++++++++++++++++--------- plugins/FileList.php | 34 ++++++++++++++++---------- plugins/HtmlHead.php | 18 +++++++++----- plugins/HttpHeader.php | 14 +++++++---- plugins/LinksMagic.php | 17 +++++++++---- plugins/MailForm.php | 20 ++++++++++----- 7 files changed, 122 insertions(+), 49 deletions(-) diff --git a/include/Plugin/Editor.php b/include/Plugin/Editor.php index 9de3b2f..539b8f0 100644 --- a/include/Plugin/Editor.php +++ b/include/Plugin/Editor.php @@ -120,7 +120,7 @@ class Diogenes_Plugin_Editor { } foreach ($available as $plugin) { - $plugentry =& $globals->plugins->cacheGet($cache, $this->plug_barrel, $this->plug_page, $plugin); + $plugentry = $globals->plugins->cacheGet($cache, $this->plug_barrel, $this->plug_page, $plugin); if (!is_array($plugentry) and $this->plug_page) { $plugentry = $globals->plugins->cacheGet($cache, $this->plug_barrel, 0, $plugin); if (is_array($plugentry)) @@ -154,10 +154,10 @@ class Diogenes_Plugin_Editor { } // retrieve parameters from REQUEST - foreach ($plug_h->params as $key => $val) + foreach ($plug_h->getParamNames() as $key) { if (isset($_REQUEST[$plug_h->name."_".$key])) { - $plug_h->params[$key] = $_REQUEST[$plug_h->name."_".$key]; + $plug_h->setParamValue($key, $_REQUEST[$plug_h->name."_".$key]); } } diff --git a/include/Plugin/Skel.php b/include/Plugin/Skel.php index 093000d..7e86546 100644 --- a/include/Plugin/Skel.php +++ b/include/Plugin/Skel.php @@ -67,22 +67,60 @@ class Diogenes_Plugin_Skel { { return ($wperms != 'public'); } - + + /** Declare a plugin parameter. + */ + function declareParam($key, $val) + { + $this->params[$key] = $val; + } + + + /** Return an array of parameter names. + */ + function getParamNames() + { + return array_keys($this->params); + } + + + /** Return the value of a parameter of the plugin. + */ + function getParamValue($key) + { + return isset($this->params[$key]) ? $this->params[$key] : ''; + } + + + /** Set the value of a parameter of the plugin. + */ + function setParamValue($key, $val) + { + if (isset($this->params[$key])) { + //echo "$this->name : Calling setParamValue($key, $val)
\n"; + $this->params[$key] = $val; + } else { + //echo "$this->name : skipping setParamValue($key, $val)
\n"; + } + } + + /** Set plugin parameters. * * @param $params */ function setParams($params) { - $bits = explode("\0", $params); + $bits = explode("\0", $params); foreach ($bits as $bit) { $frags = explode("=", $bit, 2); $key = $frags[0]; - $val = isset($frags[1]) ? $frags[1] : ''; - if (isset($this->params[$key])) { - $this->params[$key] = $val; + if (!empty($key)) + { + $val = isset($frags[1]) ? $frags[1] : ''; + $this->setParamValue($key, $val); } } } @@ -97,14 +135,15 @@ class Diogenes_Plugin_Skel { { global $globals; - //echo $this->name . " : deleteParams($barrel, $page)
\n"; + //echo $this->name . " : eraseParams($barrel, $page)
\n"; $globals->db->query("delete from diogenes_plugin where plugin='{$this->name}' and barrel='$barrel' and page='$page'"); $this->active = 0; unset($this->pos); - foreach ($this->params as $key => $val) + foreach ($this->getParamNames() as $key) { - $this->params[$key] = ''; + //echo "$this->name : erasing param
\n"; + $this->setParamValue($key, ''); } } @@ -123,9 +162,10 @@ class Diogenes_Plugin_Skel { $this->active = 1; $params = ''; - foreach ($this->params as $key => $val) - { - //echo $this->name . " $key=$val
"; + foreach ($this->getParamNames() as $key) + { + $val = $this->getParamValue($key); + //echo "$this->name : $key = $val
\n"; $params .= "$key=$val\0"; } $globals->db->query("replace into diogenes_plugin set plugin='{$this->name}', barrel='$barrel', page='$page', pos='$pos', params='$params'"); diff --git a/plugins/FileList.php b/plugins/FileList.php index f97197a..07acbfd 100644 --- a/plugins/FileList.php +++ b/plugins/FileList.php @@ -35,9 +35,17 @@ class FileList extends Diogenes_Plugin_Filter { /** Plugin description */ var $description = "This plugin allows you to insert a directory listing with icons and modification date. To make use of this plugin, insert {FileList} in your page where the file list should appear."; - /** Plugin parameters */ - var $params = array('dirbase' => "", 'urlbase' => "", 'match' => ""); - + + /** Constructor. + */ + function FileList() + { + global $page; + $this->declareParam('dirbase', ''); + $this->declareParam('urlbase', ''); + $this->declareParam('match', ''); + } + /** Prepare the output for a single file of the list. * @@ -97,21 +105,21 @@ class FileList extends Diogenes_Plugin_Filter { { global $page; $bbarel = $page->barrel; - + // process arguments - $params = array(); - foreach($this->params as $key => $val) { - $params[$key] = isset($args[$key]) ? $args[$key] : $this->params[$key]; + $instance_vals = array(); + foreach($this->getParamNames() as $key) { + $instance_vals[$key] = isset($args[$key]) ? $args[key] : $this->getParamValue($key); } - //print_r($params); - if (empty($params['dirbase'])) { - $params['dirbase'] = $bbarel->spool->spoolPath($page->curpage->props['PID']); + //print_r($instance_vals); + if (empty($instance_vals['dirbase'])) { + $instance_vals['dirbase'] = $bbarel->spool->spoolPath($page->curpage->props['PID']); } // process parameters $output = ''; - $dir = $params['dirbase']; + $dir = $instance_vals['dirbase']; if (is_dir($dir) && ($dh = opendir($dir))) { $output .= ' @@ -125,7 +133,7 @@ class FileList extends Diogenes_Plugin_Filter { /* get the matching files */ while (($fname = readdir($dh)) !== false) { if ( is_file("$dir/$fname") - && preg_match('/^'.$params['match'].'/',$fname) ) + && preg_match('/^'.$instance_vals['match'].'/',$fname) ) $filelist[] = $fname; } closedir($dh); @@ -134,7 +142,7 @@ class FileList extends Diogenes_Plugin_Filter { if (is_array($filelist)) { rsort($filelist); while(list ($key,$val) = each($filelist)) { - $output .= $this->list_file("$dir/$val",$val,$params['urlbase'].$val); + $output .= $this->list_file("$dir/$val",$val,$instance_vals['urlbase'].$val); } } else { $output .= ''; diff --git a/plugins/HtmlHead.php b/plugins/HtmlHead.php index a1be65c..8e53ffa 100644 --- a/plugins/HtmlHead.php +++ b/plugins/HtmlHead.php @@ -30,9 +30,15 @@ class HtmlHead extends Diogenes_Plugin_Filter /** Plugin description */ var $description = "This plugin allows you to add entries to a page's <head> block."; - - /** Plugin parameters */ - var $params = array('contents' => ''); + + + /** Constructor. + */ + function HtmlHead() + { + $this->declareParam('contents', ''); + } + /** Apply filtering to the input and return an output. * @@ -41,10 +47,10 @@ class HtmlHead extends Diogenes_Plugin_Filter function filter($input) { global $page; - - if ($this->params['contents']) + $contents = $this->getParamValue('content'); + if (!empty($contents)) { - array_push($page->head, $this->params['contents']); + array_push($page->head, $contents); } return $input; diff --git a/plugins/HttpHeader.php b/plugins/HttpHeader.php index 9c89fb4..ec9dba4 100644 --- a/plugins/HttpHeader.php +++ b/plugins/HttpHeader.php @@ -31,8 +31,14 @@ class HttpHeader extends Diogenes_Plugin_Filter /** Plugin description */ var $description = "This plugin allows you to add an HTTP header to a page."; - /** Plugin parameters */ - var $params = array('contents' => ''); + + /** Constructor. + */ + function HttpHeader() + { + $this->declareParam('contents', ''); + } + /** Apply filtering to the input and return an output. * @@ -40,13 +46,11 @@ class HttpHeader extends Diogenes_Plugin_Filter */ function filter($input) { - $header = $this->params['contents']; - + $header = $this->getParamValue('contents'); if ($header) { header($header); } - return $input; } diff --git a/plugins/LinksMagic.php b/plugins/LinksMagic.php index 7301c0f..6c1f83c 100644 --- a/plugins/LinksMagic.php +++ b/plugins/LinksMagic.php @@ -31,10 +31,17 @@ class LinksMagic extends Diogenes_Plugin_Filter /** Plugin description */ var $description = "This plugin allows you to mark external and secure (HTTPS) links in your pages."; - - /** Plugin parameters */ - var $params = array('main' => 1, 'sidebar' => 1); + + /** Constructor. + */ + function LinksMagic() + { + $this->declareParam('main', 1); + $this->declareParam('sidebar', 1); + } + + /** Apply filtering to the input and return an output. * * @param $input @@ -43,12 +50,12 @@ class LinksMagic extends Diogenes_Plugin_Filter { global $page; - if ($this->params['sidebar']) + if ($this->getParamValue('sidebar')) { array_unshift($page->head, ''); } - if ($this->params['main']) + if ($this->getParamValue('main')) { array_unshift($page->head, ''); } diff --git a/plugins/MailForm.php b/plugins/MailForm.php index 8125ebb..b87d905 100644 --- a/plugins/MailForm.php +++ b/plugins/MailForm.php @@ -35,8 +35,16 @@ class MailForm extends Diogenes_Plugin_Filter /** Plugin description */ var $description = "This plugin allows you to insert a form to send an e-mail to a fixed recipient. To make use of this plugin, insert {MailForm} in your page where the mail form should appear."; - /** Plugin parameters */ - var $params = array('email' => '', 'title' => '', 'subject_tag' => '[web form] '); + + /** Constructor. + */ + function MailForm() + { + $this->declareParam('email', ''); + $this->declareParam('title', ''); + $this->declareParam('subject_tag', '[web form]'); + } + /** Show an instance of the MailForm plugin. */ @@ -44,9 +52,9 @@ class MailForm extends Diogenes_Plugin_Filter { global $page; - // get params - $to_email = $this->params['email']; - $form_title = $this->params['title']; + // get parameters + $to_email = $this->getParamValue('email'); + $form_title = $this->getParamValue('title'); if (!isvalid_email($to_email)) { return '

You must specify a valid e-mail in the "email" parameter to make use of the MailForm plugin.

'; @@ -80,7 +88,7 @@ class MailForm extends Diogenes_Plugin_Filter $mymail = new HermesMailer(); $mymail->setFrom($from); - $mymail->setSubject($this->params['subject_tag'].$subject); + $mymail->setSubject($this->getParamValue('subject_tag').$subject); $mymail->addTo($to_email); $mymail->setTxtBody($message); $mymail->send(); -- 2.1.4

'.__("no files").'