From: <ni...@us...> - 2007-09-02 09:48:03
|
Update of /cvsroot/tikiwiki/tiki/components In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv26823/components Modified Files: comp-wiki.php comp-iframe.php Log Message: [DEV] mypage: updated component API to a better one Index: comp-wiki.php =================================================================== RCS file: /cvsroot/tikiwiki/tiki/components/comp-wiki.php,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- comp-wiki.php 9 Aug 2007 21:29:05 -0000 1.6 +++ comp-wiki.php 25 Aug 2007 13:20:52 -0000 1.7 @@ -1,20 +1,49 @@ <?php class Comp_wiki { - var $page; + var $mypagewin; /* - * construct a simple wiki component (only display wiki content, not edit) - * here, the $content is the wiki page name + * construct a simple wiki component (viewable only) */ - function Comp_wiki($content) { - $this->page=$content; + function Comp_wiki($mypagewin) { + $this->mypagewin=$mypagewin; } + + /* + * called when the user create a new component on the mypage + */ + function create() { + /* + * if you use a different sql table for exemple, + * you should create you're new entry here. + * you can get the mypagewin like this: + * $id=$this->mypagewin->id; + */ + } + + /* + * called when the user destroy this component from his mypage + */ + function destroy() { + /* + * if you use a different sql table for exemple, + * you should destroy you're entry here + * you can get the mypagewin like this: + * $id=$this->mypagewin->id; + */ + } + + + /* + * called for displaying the component content + */ function getHTMLContent() { global $tikilib; - $pageinfo=$tikilib->get_page_info($this->page); + $wiki_page_name=$this->mypagewin->getParam('config'); + $pageinfo=$tikilib->get_page_info($wiki_page_name); return $tikilib->parse_data($pageinfo['data'], $pageinfo['is_html']); } @@ -25,20 +54,53 @@ global $tikilib; switch($for) { case 'view': - $ps = $tikilib->get_perm_object($this->page, 'wiki page', false); + $wiki_page_name=$this->mypagewin->getParam('config'); + $ps = $tikilib->get_perm_object($wiki_page_name, 'wiki page', false); return (isset($ps['tiki_p_view']) && ($ps['tiki_p_view'] == 'y')); default: return false; } } + /* + * This function must return the HTML code to be displayed for configuring + * this component + */ + /* static or not static */ function getConfigureDiv() { - return "Title: <input name='pagename' type='text' value='' />"; + /* + * If we call this function by the static method, + * this is because we are creating a new component, + * so the component don't exist yet + * If not, we have to display the configure div with + * previous values + */ + + if (isset($this)) { + $wiki_page_name=$this->mypagewin->getParam('config'); + } else { + $wiki_page_name=''; + } + return "Wiki page name: <input name='pagename' type='text' value='".htmlspecialchars($wiki_page_name, ENT_QUOTES)."' />"; } + + /* + * This function is called when the user configure his component + * The $form is an array of values like a $_REQUEST would be + * Return true if you want the component to be redisplayed + */ function configure($form) { - $this->page=$form['pagename']; - return $this->page; + /* + * The 'config' parameter is provided for component use facility + * for storing config datas about this component. + * This is an optional field that we can use instead of storing + * you're configs datas somewhere else, but this have some limitations: + * this is only one field of type 'BLOB'. + */ + $this->mypagewin->setParam('config', $form['pagename']); + + return true; } } Index: comp-iframe.php =================================================================== RCS file: /cvsroot/tikiwiki/tiki/components/comp-iframe.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- comp-iframe.php 9 Aug 2007 21:29:05 -0000 1.3 +++ comp-iframe.php 25 Aug 2007 13:20:52 -0000 1.4 @@ -1,19 +1,46 @@ <?php class Comp_iframe { - var $page; + var $mypagewin; /* * construct a simple iframe component - * here, the $content is the iframe url */ - function Comp_iframe($content) { - $this->page=$content; + function Comp_iframe($mypagewin) { + $this->mypagewin=$mypagewin; + } + + /* + * called when the user create a new component on the mypage + */ + function create() { + /* + * if you use a different sql table for exemple, + * you should create you're new entry here. + * you can get the mypagewin like this: + * $id=$this->mypagewin->id; + */ } + /* + * called when the user destroy this component from his mypage + */ + function destroy() { + /* + * if you use a different sql table for exemple, + * you should destroy you're entry here + * you can get the mypagewin like this: + * $id=$this->mypagewin->id; + */ + } + + + /* + * called for displaying the component content + */ function getHTMLContent() { - // iframe is a special case and this fonction - // should be never call + // iframe is a special case of mypage and this fonction + // will be never call } /* @@ -23,13 +50,45 @@ return true; } + /* + * This function must return the HTML code to be displayed for configuring + * this component + */ + /* static or not static */ function getConfigureDiv() { - return "URL: <input name='url' type='text' value='' />"; + /* + * If we call this function by the static method, + * this is because we are creating a new component, + * so the component don't exist yet + * If not, we have to display the configure div with + * previous values + */ + + $configs=array('url' => 'http://'); + + if (isset($this)) { + $configs['url']=$this->mypagewin->getParam('config'); + } + + return "URL: <input name='url' type='text' value='".htmlspecialchars($configs['url'], ENT_QUOTES)."' />"; } + /* + * This function is called when the user configure his component + * The $form is an array of values like a $_REQUEST would be + * Return true if you want the component to be redisplayed + */ function configure($form) { - $this->page=$form['url']; - return $this->page; + /* + * The 'config' parameter is provided for component use facility + * for storing config datas about this component. + * This is an optional field that we can use instead of storing + * you're configs datas somewhere else, but this have some limitations: + * this is only one field of type 'BLOB'. + */ + $this->mypagewin->setParam('config', $form['url']); + + return true; } } |