diff options
| author | modela bitweaver <spiderr@bitweaver.org> | 2021-02-01 22:47:37 -0500 |
|---|---|---|
| committer | modela bitweaver <spiderr@bitweaver.org> | 2021-02-01 22:47:37 -0500 |
| commit | 8e8fb7e46c83f9c66d88cedbbd30c67f87c7a2d4 (patch) | |
| tree | 73b12aeffe22e27aa75634dfc5034627322af365 /includes | |
| parent | 3de7b595a6e01676ec80317e647baf2176aee6b4 (diff) | |
| download | wiki-8e8fb7e46c83f9c66d88cedbbd30c67f87c7a2d4.tar.gz wiki-8e8fb7e46c83f9c66d88cedbbd30c67f87c7a2d4.tar.bz2 wiki-8e8fb7e46c83f9c66d88cedbbd30c67f87c7a2d4.zip | |
move _inc and _lib to includes/ and use PKG_INCLUDE_PATH constants
Diffstat (limited to 'includes')
| -rw-r--r-- | includes/classes/BitPage.php | 2 | ||||
| -rw-r--r-- | includes/copyrights_lib.php | 77 | ||||
| -rw-r--r-- | includes/display_bitpage_inc.php | 169 | ||||
| -rw-r--r-- | includes/export_lib.php | 81 | ||||
| -rw-r--r-- | includes/lookup_page_inc.php | 93 | ||||
| -rw-r--r-- | includes/plugins_lib.php | 208 |
6 files changed, 629 insertions, 1 deletions
diff --git a/includes/classes/BitPage.php b/includes/classes/BitPage.php index 7a3680b..48e2f84 100644 --- a/includes/classes/BitPage.php +++ b/includes/classes/BitPage.php @@ -484,7 +484,7 @@ class BitPage extends LibertyMime implements BitCacheable { * @return the fully specified path to file to be included */ function getRenderFile() { - return WIKI_PKG_PATH."display_bitpage_inc.php"; + return WIKI_PKG_INCLUDE_PATH."display_bitpage_inc.php"; } diff --git a/includes/copyrights_lib.php b/includes/copyrights_lib.php new file mode 100644 index 0000000..ef8d1be --- /dev/null +++ b/includes/copyrights_lib.php @@ -0,0 +1,77 @@ +<?php +/** + * Copyright (c) 2004 bitweaver.org + * Copyright (c) 2003 tikwiki.org + * Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al. + * All Rights Reserved. See below for details and a complete list of authors. + * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details + * + * @package wiki + */ + +/** + * @package wiki + * @subpackage CopyrightsLib + */ +class CopyrightsLib extends BitBase { + function list_copyrights( $pPageId ) { + $query = "select * from `".BIT_DB_PREFIX."liberty_copyrights` WHERE `page_id`=? order by ".$this->mDb->convertSortmode( "copyright_order_asc" ); + $query_cant = "select count(*) from `".BIT_DB_PREFIX."liberty_copyrights` WHERE `page_id`=?"; + $result = $this->mDb->query($query, array( $pPageId )); + $cant = $this->mDb->getOne($query_cant, array( $pPageId )); + $ret = array(); + while ($res = $result->fetchRow()) { + $ret[] = $res; + } + $retval = array(); + $retval["data"] = $ret; + $retval["cant"] = $cant; + return $retval; + } + function top_copyright_order( $pPageId ) { + $query = "select MAX(`copyright_order`) from `".BIT_DB_PREFIX."liberty_copyrights` where `page_id` = ?"; + return $this->mDb->getOne($query, array( $pPageId )); + } + function unique_copyright( $pPageId , $title) { + $query = "select `copyrightID` from `".BIT_DB_PREFIX."liberty_copyrights` where `page_id`=? and `title`=?"; + return $this->mDb->getOne($query, array( $pPageId ,$title)); + } + function add_copyright( $pPageId , $title, $year, $authors, $pUserId) { + //$unique = $this->unique_copyright( $pPageId ,$title); + //if($unique != 0) { + // security here? + //$this->edit_copyright($unique,$title,$year,$authors,$pUserId); + //return; + //} + $top = $this->top_copyright_order( $pPageId ); + $order = $top + 1; + $query = "insert into `".BIT_DB_PREFIX."liberty_copyrights` (`page_id`, `title`, `copyright_year`, `authors`, `copyright_order`, `user_id`) values (?,?,?,?,?,?)"; + $this->mDb->query($query,array( $pPageId ,$title,$year,$authors,$order,$pUserId)); + return true; + } + function edit_copyright($id, $title, $year, $authors, $pUserId) { + $query = "update `".BIT_DB_PREFIX."liberty_copyrights` SET `copyright_year`=?, `title`=?, `authors`=?, `user_id`=? where `copyright_id`=?"; + $this->mDb->query($query,array($year,$title,$authors,$pUserId,(int)$id)); + return true; + } + function remove_copyright($id) { + $query = "delete from `".BIT_DB_PREFIX."liberty_copyrights` where `copyright_id`=?"; + $this->mDb->query($query,array((int)$id)); + return true; + } + function up_copyright($id) { + $query = "update `".BIT_DB_PREFIX."liberty_copyrights` set `copyright_order`=`copyright_order`-1 where `copyright_id`=?"; + $result = $this->mDb->query($query,array((int)$id)); + return true; + } + function down_copyright($id) { + $query = "update `".BIT_DB_PREFIX."liberty_copyrights` set `copyright_order`=`copyright_order`+1 where `copyright_id`=?"; + $result = $this->mDb->query($query,array((int)$id)); + return true; + } +} + +global $copyrightslib; +$copyrightslib = new CopyrightsLib(); + +?> diff --git a/includes/display_bitpage_inc.php b/includes/display_bitpage_inc.php new file mode 100644 index 0000000..a8c92f6 --- /dev/null +++ b/includes/display_bitpage_inc.php @@ -0,0 +1,169 @@ +<?php +/** + * Copyright (c) 2004 bitweaver.org + * Copyright (c) 2003 tikwiki.org + * Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al. + * All Rights Reserved. See below for details and a complete list of authors. + * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details + * + * @package wiki + * @subpackage functions + */ + +/** + * required setup + */ +include_once( WIKI_PKG_CLASS_PATH.'BitBook.php'); + +$gBitSystem->verifyPackage( 'wiki' ); + +$gContent->verifyViewPermission(); + +// Check permissions to access this page +if( !$gContent->isValid() || !is_a( $gContent, 'BitPage' ) ) { + $gBitSystem->fatalError( tra( 'Page cannot be found' ), NULL, NULL, HttpStatusCodes::HTTP_GONE ); +} + +$displayHash = array( 'perm_name' => 'p_wiki_view_page' ); +$gContent->invokeServices( 'content_display_function', $displayHash ); + +// Let creator set permissions +// does this work with setPreference()??? - xing - Tuesday Oct 07, 2008 17:51:38 CEST +if( $gBitSystem->isFeatureActive( 'wiki_creator_admin' ) && $gContent->isOwner() ) { + $gBitUser->setPreference( 'p_wiki_admin', TRUE ); +} + +// doesn't seem to be used - xing - Tuesday Oct 07, 2008 17:52:42 CEST +//if( isset( $_REQUEST["copyrightpage"] )) { +// $gBitSmarty->assignByRef( 'copyrightpage', $_REQUEST["copyrightpage"] ); +//} + +// Get the backlinks for the page "page" +if( $gBitSystem->isFeatureActive( 'wiki_backlinks' )) { + $gBitSmarty->assign( 'backlinks', $gContent->getBacklinks() ); +} + +// Now increment page hits since we are visiting this page +$gContent->addHit(); + +// Check if we have to lock / unlock this page +if( !empty( $_REQUEST["action"] ) && ( $_REQUEST["action"] == 'lock' || $_REQUEST["action"] == 'unlock' ) + && ( $gContent->hasAdminPermission() || ($gContent->hasUserPermission( 'p_wiki_lock_page' ) && $gBitSystem->isFeatureActive( 'wiki_usrlock' )) ) ) { + $gContent->setLock( $_REQUEST["action"] == 'lock' ? 'L' : NULL ); +} + +// Process an undo here +if( !empty( $_REQUEST["undo"] ) && !$gContent->isLocked() && ( $gContent->hasUpdatePermission() || $gContent->hasUserPermission( 'p_wiki_rollback' ))) { + // Remove the last version + $gContent->removeLastVersion(); +} + +// work out if this page has slides +if( $gBitSystem->isFeatureActive( 'wiki_uses_slides' )) { + $slides = split( "-=[^=]+=-", $gContent->mInfo["data"] ); + if( count( $slides ) <= 1 ) { + $slides = explode( defined( 'PAGE_SEP' ) ? PAGE_SEP : "...page...", $gContent->mInfo["data"] ); + } + + // if we have more than on slide, we let the templates know about it + if( count( $slides ) > 1 ) { + $gBitSmarty->assign( 'show_slideshow', 'y' ); + } +} + +// ...page... stuff - TODO: this is cumbersome and should be cleaned up +$pages = $gContent->countSubPages( $gContent->getField( 'parsed_data' ) ); +if( $pages > 1 ) { + if( !isset( $_REQUEST['pagenum'] )) { + $_REQUEST['pagenum'] = 1; + } + $gContent->mInfo['parsed_data'] = $gContent->getSubPage( $gContent->mInfo['parsed_data'], $_REQUEST['pagenum'] ); + $gBitSmarty->assign( 'pages', $pages ); + if( $pages > $_REQUEST['pagenum'] ) { + $gBitSmarty->assign('next_page', $_REQUEST['pagenum'] + 1 ); + } else { + $gBitSmarty->assign( 'next_page', $_REQUEST['pagenum'] ); + } + if( $_REQUEST['pagenum'] > 1 ) { + $gBitSmarty->assign( 'prev_page', $_REQUEST['pagenum'] - 1 ); + } else { + $gBitSmarty->assign( 'prev_page', 1 ); + } + $gBitSmarty->assign( 'first_page', 1 ); + $gBitSmarty->assign( 'last_page', $pages ); + $gBitSmarty->assign( 'pagenum', $_REQUEST['pagenum'] ); +} + +// Comments engine! +if( $gBitSystem->isFeatureActive( 'wiki_comments' )) { + $comments_vars = array( 'page' ); + $comments_prefix_var = 'wiki page:'; + $comments_object_var = 'page'; + $commentsParentId = $gContent->mContentId; + $comments_return_url = WIKI_PKG_URL.'index.php?page_id='.$gContent->mPageId; + # Support displaying comments on their own page instead of on content page + if( isset( $_REQUEST["comments_page"] ) && ( $_REQUEST["comments_page"] == '1' ) || !empty( $_REQUEST['view_comment_id'] )) { + $gBitSmarty->assign( 'comments_page', 1 ); + $comments_on_separate_page = 1; + $comments_return_url = WIKI_PKG_URL.'index.php?page_id='.$gContent->mPageId.'&comments_page=1'; + if ( !empty($_REQUEST['view_comment_id']) ) { + $comments_return_url .= '&comments_maxComments=1'; + } + } + include_once( LIBERTY_PKG_PATH.'comments_inc.php' ); +} + +// Footnotes +if( $gBitSystem->isFeatureActive( 'wiki_footnotes' ) && $gBitUser->isValid() ) { + if( $footnote = $gContent->getFootnote( $gBitUser->mUserId ) ) { + $gBitSmarty->assign( 'footnote', LibertyContent::parseDataHash( $footnote ) ); + } +} + +// Copyrights +if( $gBitSystem->isFeatureActive( 'wiki_copyrights' ) ) { + require_once( WIKI_PKG_INCLUDE_PATH.'copyrights_lib.php' ); + $copyrights = $copyrightslib->list_copyrights( $gContent->mPageId ); + $gBitSmarty->assign('pageCopyrights', $copyrights["data"]); +} + +// Watches +if( $gBitSystem->isFeatureActive( 'users_watches' ) ) { + if( !empty( $_REQUEST['watch_event'] ) ) { + if( $gBitUser->isRegistered() ) { + if( $_REQUEST['watch_action']=='add' ) { + $gBitUser->storeWatch( $_REQUEST['watch_event'], $_REQUEST['watch_object'], $gContent->mContentTypeGuid, $gContent->mPageName, $gContent->getDisplayUrl() ); + } else { + $gBitUser->expungeWatch( $_REQUEST['watch_event'], $_REQUEST['watch_object'] ); + } + } else { + $gBitSystem->fatalError( tra( "This feature requires a registered user. ").": users_watches" ); + } + } + + if( $watch = $gBitUser->getEventWatches( 'wiki_page_changed', $gContent->mPageId ) ) { + $gBitSmarty->assign( 'user_watching_page', 'y' ); + } +} + +if( $gContent->isValid() && $gBitSystem->isPackageActive( 'stickies' ) ) { + require_once( STICKIES_PKG_PATH.'BitSticky.php' ); + global $gNote; + $gNote = new BitSticky( NULL, NULL, $gContent->mContentId ); + $gNote->load(); + $gBitSmarty->assignByRef( 'stickyInfo', $gNote->mInfo ); +} + +$pageInfo = $gContent->mInfo; +$pageInfo['title'] = $gContent->getTitle(); + +// Display the Index Template +$gBitSmarty->assignByRef( 'pageInfo', $pageInfo ); + +// S5 slideshows +if( isset( $_REQUEST['s5'] )) { + include_once( WIKI_PKG_PATH.'s5.php'); +} + +$gBitSystem->display( 'bitpackage:wiki/show_page.tpl', $pageInfo['title'], array( 'display_mode' => 'display' )); +?> diff --git a/includes/export_lib.php b/includes/export_lib.php new file mode 100644 index 0000000..e63877c --- /dev/null +++ b/includes/export_lib.php @@ -0,0 +1,81 @@ +<?php +/** + * Copyright (c) 2004 bitweaver.org + * Copyright (c) 2003 tikwiki.org + * Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al. + * All Rights Reserved. See below for details and a complete list of authors. + * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details + * + * @package wiki + */ + +/** + * required setup + */ +require_once( KERNEL_PKG_PATH.'BitBase.php' ); +require_once( WIKI_PKG_CLASS_PATH.'BitPage.php' ); +/** + * @package wiki + * @subpackage ExportLib + */ +class ExportLib extends BitBase { + + function MakeWikiZip( $pExportFile ) { + global $gBitUser,$gBitSystem; + include_once (UTIL_PKG_INC."tar.class.php"); + $tar = new tar(); + $query = "SELECT wp.`page_id` from `".BIT_DB_PREFIX."wiki_pages` wp INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (lc.`content_id` = wp.`content_id`) + ORDER BY lc.".$this->mDb->convertSortmode("title_asc"); + $result = $this->mDb->query($query,array()); + while ($res = $result->fetchRow()) { + $page_id = $res["page_id"]; + $content = $this->export_wiki_page($page_id, 0); + $tar->addData($page_id, $content, $gBitSystem->getUTCTime()); + } + $tar->toTar( $pExportFile, FALSE); + return ''; + } + + function export_wiki_page($page_id, $nversions = 1) { + global $gBitSystem; + $head = ''; + $head .= "Date: " . $gBitSystem->mServerTimestamp->get_rfc2822_datetime(). "\r\n"; + $head .= sprintf("Mime-Version: 1.0 (Produced by Tiki)\r\n"); + $iter = $this->get_page_history($page_id); + $gWikiPage = new BitPage( $page_id ); + $gWikiPage->load(); + $info = $gWikiPage->mInfo; + $parts = array(); + $parts[] = MimeifyPageRevision($info); + if ($nversions > 1 || $nversions == 0) { + foreach ($iter as $revision) { + $parts[] = MimeifyPageRevision($revision); + if ($nversions > 0 && count($parts) >= $nversions) + break; + } + } + if (count($parts) > 1) + return $head . MimeMultipart($parts); + assert ($parts); + return $head . $parts[0]; + } + + // Returns all the versions for this page + // without the data itself + function get_page_history($page_id) { + $query = "SELECT lc.`title`, th.`description`, th.`version`, th.`last_modified`, th.`user_id`, th.`ip`, th.`data`, th.`history_comment`, uu.`login` as `creator_user`, uu.`real_name` " . + "FROM `".BIT_DB_PREFIX."wiki_pages` wp " . + "INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (lc.`content_id` = wp.`content_id`) " . + "INNER JOIN `".BIT_DB_PREFIX."liberty_content_history` th ON (th.`page_id` = th.`page_id`) " . + "INNER JOIN `".BIT_DB_PREFIX."users_users` uu ON (uu.`user_id` = th.`user_id`) " . + "WHERE wp.`page_id`=? order by th.".$this->mDb->convertSortmode("version_desc"); + $result = $this->mDb->query($query,array($page_id)); + $ret = array(); + while ($res = $result->fetchRow()) { + array_push( $ret, $res ); + } + return $ret; + } +} +$exportlib = new ExportLib(); +?> diff --git a/includes/lookup_page_inc.php b/includes/lookup_page_inc.php new file mode 100644 index 0000000..0fd5e17 --- /dev/null +++ b/includes/lookup_page_inc.php @@ -0,0 +1,93 @@ +<?php +/** + * Copyright (c) 2004 bitweaver.org + * Copyright (c) 2003 tikwiki.org + * Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al. + * All Rights Reserved. See below for details and a complete list of authors. + * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details + * + * @package wiki + * @subpackage functions + */ + +/** + * required setup + */ +require_once( WIKI_PKG_CLASS_PATH.'BitBook.php'); + +global $gContent; +include_once( LIBERTY_PKG_PATH.'lookup_content_inc.php' ); + +// this is needed when the center module is applied to avoid abusing $_REQUEST +if( empty( $lookupHash )) { + $lookupHash = &$_REQUEST; +} + +// if we already have a gContent, we assume someone else created it for us, and has properly loaded everything up. +if( empty( $gContent ) || !is_object( $gContent ) || strtolower( get_class( $gContent ) ) != 'bitpage' ) { + if( !empty( $lookupHash['page_id'] ) ) { + $loadContentId = BitPage::findContentIdByPageId( $lookupHash['page_id'] ); + } elseif( !empty( $lookupHash['content_id'] ) ) { + $loadContentId = $lookupHash['content_id']; + } elseif( !empty( $lookupHash['page'] ) ) { + //handle legacy forms that use plain 'page' form variable name + + //if page had some special enities they were changed to HTML for for security reasons. + //now we deal only with string so convert it back - so we can support this case: + //You&Me --(detoxify in kernel)--> You&Me --(now)--> You&Me + //we could do htmlspecialchars_decode but it allows <> marks here, so we just transform & to & - it's not so scary. + $loadPage = str_replace("&", "&", $lookupHash['page'] ); + // Fix nignx mapping of '+' sign when doing rewrite + $loadPage = str_replace("+", " ", $loadPage ); + + if( $loadPage && $existsInfo = BitPage::pageExists( $loadPage ) ) { + if (count($existsInfo)) { + if (count($existsInfo) > 1) { + // Display page so user can select which wiki page they want (there are multiple that share this name) + $gBitSmarty->assign( 'choose', $lookupHash['page'] ); + $gBitSmarty->assign('dupePages', $existsInfo); + $gBitSystem->display('bitpackage:wiki/page_select.tpl', NULL, array( 'display_mode' => 'display' )); + die; + } else { + $loadPageId = $existsInfo[0]['page_id']; + $loadContentId = $existsInfo[0]['content_id']; + } + } + } elseif( $loadPage ) { + $gBitSmarty->assign('page', $loadPage);//to have the create page link in the error + } + } + + if( !empty( $loadContentId ) ) { + $gContent = BitPage::getLibertyObject( $loadContentId ); + } + + if( empty( $gContent ) || !is_object( $gContent ) ) { + $gContent = new BitPage(); + } +} + +// we weren't passed a structure, but maybe this page belongs to one. let's check... +if( $gContent->isValid() && empty( $gStructure ) ) { + //Get the structures this page is a member of + if( !empty($lookupHash['structure']) ) { + $structure=$lookupHash['structure']; + } else { + $structure=''; + } + $structs = $gContent->getStructures(); + if (count($structs)==1) { + $gStructure = new LibertyStructure( $structs[0]['structure_id'] ); + if( $gStructure->load() ) { + $gStructure->loadNavigation(); + $gStructure->loadPath(); + $gBitSmarty->assign( 'structureInfo', $gStructure->mInfo ); + } + } else { + $gBitSmarty->assign('showstructs', $structs); + } +} + +$gBitSmarty->clearAssign( 'gContent' ); +$gBitSmarty->assignByRef( 'gContent', $gContent ); +?> diff --git a/includes/plugins_lib.php b/includes/plugins_lib.php new file mode 100644 index 0000000..61ffe41 --- /dev/null +++ b/includes/plugins_lib.php @@ -0,0 +1,208 @@ +<?php + /** + * Plugin Lib + * + * A port of PhpWiki WikiPlugin class + * Principal use is port PhpWiki plugins, but can be used to make new ones. + * Use: + * - Extends PluginsLib with your class + * - add the lines + * <code> + * include "pluginslib.php"; + * + * function wikiplugin_backlinks($data, $params) { + * $plugin = new BackLinks(); + * return $plugin->run($data, $params); + * } + * function wikiplugin_backlinks_help() { + * $plugin = new BackLinks(); + * return $plugin->getDescription(); + * } * </code> + * @package wiki + */ + + /** + * @package wiki + * @subpackage PluginsLib + * @author Claudio Bustos + * @version $Revision$ + */ + class PluginsLib extends BitBase { + public $_errors; + public $_data; + public $_params; + /** + * Array of params to be expanded as arrays. Explode the string with {@link $separator} + * @var array + */ + public $expanded_params = array(); + /** + * Separator used to explote params listed on {@link $expanded_params} + * @var string + */ + public $separator = "|"; + /** + * List of fields retrieved from {@link BitBase::list_pages()} + * Keys are the name of the fields and values the names for tra(); + * @var array + */ + public $aInfoPresetNames = array( + "hits" => "Hits", "last_modified" => "Last mod", "user" => "Last author", "len" => "Size", "comment" => "Com", "creator" => "Creator", "version" => "Last ver", "flag" => "Status", "versions" => "Vers", "links" => "Links", "backlinks" => "Backlinks"); + + /** + * Process the params, in this order: + * - default values, asigned on {@link PluginsLib::getDefaultArguments()} + * - request values, sended by GET or POST method, if $request is put to true + * - explicit values, asigned on the Wiki + * @param array sended to wikiplugin_name($data, $params) + * @param bool if set to true, accept values from $_REQUEST + * @param bool if set to true, assign default values from {@link PluginsLib::getDefaultArguments()} + * @return array list of params + */ + function getParams($params, $request = false, $defaults = false) { + if ($defaults === false) { + $defaults = $this->getDefaultArguments(); + } + $args = array(); + foreach ($defaults as $arg => $default_val) { + if (isset($params[$arg])) { + $args[$arg] = $params[$arg]; + } elseif(isset($_REQUEST[$arg])) { + $args[$arg] = $_REQUEST[$arg]; + } else { + // maybe this kind of transformation can be grouped on a external function + if ($default_val==="[pagename]") { + $default_val=$_REQUEST["page"]; + } + $args[$arg] = $default_val; + } + if (in_array($arg, $this->expanded_params)) { + if ($args[$arg]) { + $args[$arg] = explode($this->separator, $args[$arg]); + foreach($args[$arg] as $id=>$value) { + $args[$arg][$id]=trim($value); + } + } else { + $args[$arg]=array(); + } + } + } + return $args; + } + /** + * Returns the name of the Plugin + * By default, erase the first 'WikiPlugin' + * Made for overload it. + * @return string + */ + function getName() { + return preg_replace('/^WikiPlugin/', '', get_class($this)); + } + /** + * Returns a description of the Plugin + * Made for overload it. + * @return string + */ + function getDescription() { + return $this->getName(); + } + /** + * Returns the version of the version + * Made for overload it. + * @return string + */ + function getVersion() { + return tra("No version indicated"); + //return preg_replace("/[Revision: $]/", '', + // "\$Revision$"); + } + /** + * Returns the default arguments for the plugin + * Use keys as the arguments and values as ... the default values + * @return array + */ + function getDefaultArguments() { + return array('description' => $this->getDescription()); + } + /** + * Run the plugin + * For sake of God, overload it! + * @param string + * @param array + */ + function run ($data, $params) { + /** + * UGLY ERROR!. + */ + return $this->error("PluginsLib::run: pure virtual function. Don't be so lazy!"); + } + function error ($message) { + return "~np~<span class='warn'>Plugin ".$this->getName()." ".tra("failed")." : ".tra($message)."</span>~/np~"; + } + function getErrorDetail() { + return $this->_errors; + } + function _error($message) { + $this->_errors = $message; + return false; + } + } + /** + * Class with utilities for Plugins + * + * @package wiki + * @subpackage PluginsLib + * @author Claudio Bustos + * @version $Revision$ + */ + class PluginsLibUtil { + /** + * Create a table with information from pages + * @param array key ["data"] from one of the functions that retrieve información about pages + * @param array list of keys to show. + * @param array definition of the principal field. By default: + * array("field"=>"title","name"=>"Page") + * @return string + */ + function createTable($aData,$aInfo=false,$aPrincipalField=false) { + // contract + if (!$aPrincipalField or !is_array($aPrincipalField)) { + $aPrincipalField=array("field"=>"title","name"=>"Page"); + } + if (!is_array($aInfo)) { + $aInfo=false; + } + // ~contract + $sOutput=""; + if ($aInfo) { + $iNumCol=count($aInfo)+1; + $sStyle=" style='width:".(floor(100/$iNumCol))."%' "; + // Header for info + $sOutput .= "<table class='normal'><tr><td class='heading' $sStyle>".tra($aPrincipalField["name"])."</td>"; + foreach($aInfo as $iInfo => $sHeader) { + $sOutput .= "<td class='heading' $sStyle >".tra($sHeader)."</td>"; + } + $sOutput .= "</tr>"; + } + $iCounter=1; + foreach($aData as $aPage) { + $sClass=($iCounter%2)?"odd":"even"; + if (!$aInfo) { + $sOutput .= "*((".$aPage[$aPrincipalField["field"]]."))\n"; + } else { + $sOutput .= "<tr><td class='$sClass'>((".$aPage[$aPrincipalField["field"]]."))</td>"; + foreach($aInfo as $sInfo) { + if (isset($aPage[$sInfo])) { + $sOutput .= "<td class='$sClass'>".$aPage[$sInfo]."</td>"; + } + } + } + $iCounter++; + } + if ($aInfo) { + $sOutput .= "</table>"; + } + return $sOutput; + } + } +?> |
