function run($data, $params)
 {
     global $wikilib;
     include_once 'lib/wiki/wikilib.php';
     global $tikilib;
     $aInfoPreset = array_keys($this->aInfoPresetNames);
     $exclude = $params['exclude'];
     $params = $this->getParams($params, true);
     extract($params, EXTR_SKIP);
     if (!$search) {
         return $this->error("You have to define a search");
     }
     // no additional infos in list output
     if (isset($style) && $style == 'list') {
         $info = false;
     }
     //
     /////////////////////////////////
     // Create a valid list for $info
     /////////////////////////////////
     //
     if ($info) {
         $info_temp = array();
         foreach ($info as $sInfo) {
             if (in_array(trim($sInfo), $aInfoPreset)) {
                 $info_temp[] = trim($sInfo);
             }
             $info = $info_temp ? $info_temp : false;
         }
     } else {
         $info = false;
     }
     //
     /////////////////////////////////
     // Process pages
     /////////////////////////////////
     //
     $sOutput = "";
     $aPages = $tikilib->list_pages(0, -1, 'pageName_desc', $search, null, false);
     foreach ($aPages["data"] as $idPage => $aPage) {
         if (in_array($aPage["pageName"], $exclude)) {
             unset($aPages["data"][$idPage]);
             $aPages["cant"]--;
         }
     }
     //
     /////////////////////////////////
     // Start of Output
     /////////////////////////////////
     //
     if (isset($noheader) && !$noheader) {
         // Create header
         $count = $aPages["cant"];
         if (!$count) {
             $sOutput .= tra("No pages found for title search") . " '__" . $search . "__'";
         } elseif ($count == 1) {
             $sOutput .= tra("One page found for title search") . " '__" . $search . "__'";
         } else {
             $sOutput = "{$count} " . tra("pages found for title search") . " '__" . $search . "__'";
         }
         $sOutput .= "\n";
     }
     if (isset($style) && $style == 'list') {
         $sOutput .= PluginsLibUtil::createList($aPages["data"]);
     } else {
         $sOutput .= PluginsLibUtil::createTable($aPages["data"], $info);
     }
     return $sOutput;
 }
	function run($data, $params)
	{
		global $wikilib, $helpurl, $tikilib;
		if (!is_dir(PLUGINS_DIR)) {
			return $this->error('No plugin directory defined');
		}
		if (empty($helpurl)) {
			$helpurl = 'http://doc.tiki.org/';
		}
		
		$params = $this->getParams($params);
		extract($params, EXTR_SKIP);

		if (!empty($module) && !empty($plugin)) {
			return $this->error(tra('The module or plugin parameter must be set, but not both.'));
		} elseif (!empty($module)) {
			$aPrincipalField = array('field' => 'plugin', 'name' => 'Module');
			$helppath = $helpurl . $aPrincipalField['name'] . ' ';
			$filepath = 'mod-func-';
			global $modlib;
			include_once 'lib/modules/modlib.php';
			$aPlugins = $modlib->list_module_files();
			$mod = true;
			$type = ' module';
			$plugin = $module;
		} else {
			$aPrincipalField = array('field' => 'plugin', 'name' => 'Plugin');
			$helppath = $helpurl . $aPrincipalField['name'];
			$filepath = 'wikiplugin_';
			$aPlugins = $wikilib->list_plugins();
			$mod = false;
			$type = ' plugin';
		}
		$all = $aPlugins;
		//if the user set $module, that setting has now been moved to $plugin so that one code set is used
		//$aPlugins and $all now has the complete list of plugin or module file names - the code below modifies $aPlugins
		//if necessary based on user settings
		if (!empty($plugin)) {
			if (strpos($plugin, '|') !== false) {
				$aPlugins = array();
				$userlist = explode('|', $plugin);
				foreach ($userlist as $useritem) {
					$file = $filepath . $useritem . '.php';
					$confirm = in_array($file, $all);
					if ($confirm === false) {
						return '^' . tr('Plugin Manager error: %0%1 not found', $useritem, $type) . '^';
					} else {
						$aPlugins[] = $file;
					}
				}
			} elseif (strpos($plugin, '-') !== false) {
				$userrange = explode('-', $plugin);
				$begin = array_search($filepath . $userrange[0] . '.php', $aPlugins);
				$end = array_search($filepath . $userrange[1] . '.php', $aPlugins);
				$beginerror = '';
				$enderror = '';
				$type2 = $type;
				if ($begin === false || $end === false) {
					if ($begin === false) {
						$beginerror = $userrange[0];
					} 
					if ($end === false) {
						$enderror = $userrange[1];
						if (!empty($beginerror)) {
							$and = ' and ';
						} else {
							$and = '';
							$type = '';
						}
					}
					return '^' . tr('Plugin Manager error: %0%1%2%3%4 not found', $beginerror, $type, $and, $enderror, $type2) . '^';
				} elseif ($end > $begin) {
					$aPlugins = array_slice($aPlugins, $begin, $end-$begin+1);
				} else {
					$aPlugins = array_slice($aPlugins, $end, $begin-$end+1);
				}	 		
			} elseif (!empty($limit)) { 
				$begin = array_search($filepath . $plugin . '.php', $aPlugins); 
				if ($begin === false) {
					return '^' . tr('Plugin Manager error: %0%1 not found', $begin, $type) . '^';
				} else {
					$aPlugins = array_slice($aPlugins, $begin, $limit);
				}
			} elseif ($plugin != 'all') {
				$file = $filepath . $plugin . '.php';
				$confirm = in_array($file, $aPlugins);
				if ($confirm === false) {
					return '^' . tr('Plugin Manager error:  %0%1 not found', $plugin, $type) . '^';
				} else {
					$aPlugins = array();
					$aPlugins[] = $file;
				}
			}
		} else {
			if (!empty($start) || !empty($limit)) {
				if (!empty($start) && !empty($limit)) {
					$aPlugins = array_slice($aPlugins, $start-1, $limit);
				} elseif (!empty($start)) {
					$aPlugins = array_slice($aPlugins, $start-1);
				} else {			
					$aPlugins = array_slice($aPlugins, 0, $limit);
				}
			}
		}
		//Set all data variables needed for separate code used to generate the display table
		$aData=array();
		if ($singletitle == 'table' || count($aPlugins) > 1) {
			foreach ($aPlugins as $sPluginFile) {
				global $sPlugin, $numparams;
				if ($mod) {
					$infoPlugin = get_module_params($sPluginFile);
					$namepath = $sPlugin;
				} else {
					$infoPlugin = get_plugin_info($sPluginFile);
					$namepath = ucfirst($sPlugin);
				}
				if (in_array('description', $info)) {
					if (isset($infoPlugin['description'])) {
						if ($numparams > 1) {
							$aData[$sPlugin]['description']['onekey'] = $infoPlugin['description'];
						} else {
							$aData[$sPlugin]['description'] = $infoPlugin['description'];
						}
					} else {
						$aData[$sPlugin]['description'] = ' --- ';
					}
				}
				if (in_array('parameters', $info)) {
					if ($numparams > 0) {
						if ($aPrincipalField['field'] == 'plugin' && !in_array('options', $info) && $numparams > 1) {
							$aData[$sPlugin][$aPrincipalField['field']]['rowspan'] = $numparams;
							if (in_array('description', $info)) {
								$aData[$sPlugin]['description']['rowspan'] = $numparams;
							}
						}
						foreach ($infoPlugin['params'] as $paramname => $param) {
							if (isset($infoPlugin['params'][$paramname]['description'])) {
								$paramblock = '~np~' . $infoPlugin['params'][$paramname]['description'] . '~/np~';
							}
							if (isset($param['options']) && is_array($param['options'])) {
								$paramblock .= '<br /><em>' . tra('Options:') . '</em> ';
								$i = 0;
								foreach ($param['options'] as $oplist => $opitem) {
									if (isset($opitem['value'])) {
										$paramblock .= $opitem['value'];
									} else {
										$paramblock .=  $opitem['text'];
									}
									$paramblock .= ' | ';
									$i++;
								}
								$paramblock = substr($paramblock, 0, -3);
							}
							if (isset($infoPlugin['params'][$paramname]['required']) && $infoPlugin['params'][$paramname]['required'] == true) {
								$aData[$sPlugin]['parameters']['<b>' . $paramname . '</b>'] = $paramblock;
							} else {
								$aData[$sPlugin]['parameters'][$paramname] = $paramblock;
							}
						}
					} else {
						$aData[$sPlugin]['parameters']['<em>no parameters</em>'] = '<em>' . tra('n/a') . '</em>';
					}
				}
				$aData[$sPlugin]['plugin']['plugin'] = '[' . $helppath . $namepath . '|' . ucfirst($sPlugin) . ']';
			} // Plugins Loop
			return PluginsLibUtil::createTable($aData, $info, $aPrincipalField);
		} else {
			//Replicates a documentation table for parameters for a single plugin or module
			//Not using plugin lib table to avoid making custom modifications
			global $sPlugin, $numparams;
			if ($mod) {
				$infoPlugin = get_module_params($aPlugins[0]);
				$namepath = $sPlugin;
			} else {
				$infoPlugin = get_plugin_info($aPlugins[0]);
				$namepath = ucfirst($sPlugin);
			}
			if ($singletitle == 'top') {
				$title = '<' . $titletag . '>['. $helppath . $namepath 
					. '|' . ucfirst($sPlugin) . ']</' . $titletag . '>';
				$title .= $infoPlugin['description'] . '<br />';
				if (isset($infoPlugin['introduced'])) {
					$title .= '<em>' . tr('Introduced in Tiki version %0', $infoPlugin['introduced']) . '</em><br />';
				}
				$title .= '<br />';
			} else {
				$title = '';
			}
			$headbegin = "\n\t\t" . '<td class="heading">';
			$cellbegin = "\n\t\t" . '<td>';
			$header =  "\n\t" . '<tr class="heading">' . $headbegin . 'Parameters</td>';
			$rows = '';
			if (isset($numparams) && $numparams > 0) {
				$header .= $headbegin . tra('Accepted Values') . '</td>';
 			   	$header .= $headbegin . tra('Description') . '</td>';
				$rowCounter = 1;
				if (!empty($infoPlugin['body'])) {
					$body = array('(body of plugin)' => array('description' => $infoPlugin['body']));
					$infoPlugin['params'] = array_merge($body, $infoPlugin['params']);
				}
				foreach ($infoPlugin['params'] as $paramname => $paraminfo) {
					$class = ($rowCounter%2) ? 'odd' : 'even';
					$rows .= "\n\t" . '<tr class="' . $class . '">' . $cellbegin;
					//Parameters column
					if (isset($paraminfo['required']) && $paraminfo['required'] == true) {
						$rows .= '<b><em>' . $paramname . '</em></b>';
					} elseif ($paramname == '(body of plugin)') {
						$rows .= tra('(body of plugin)');
					} else {
						$rows .= '<em>' . $paramname . '</em>' ;
					}
					$rows .= '</td>';
					$rows .= $cellbegin;
					//Accepted Values column
					if (isset($paraminfo['accepted'])) {
						$rows .= $paraminfo['accepted'] . '</td>';
					} elseif (isset($paraminfo['options'])) {
						$optcounter = 1;
						$numoptions = count($paraminfo['options']);
						foreach ($paraminfo['options'] as $oplist => $opitem) {
							$rows .= strlen($opitem['value']) == 0 ? tra('(blank)') : $opitem['value'];
							if ($optcounter < $numoptions) {
								if ($numoptions > 10) {
									$rows .= ' | ';
								} else {
									$rows .= '<br />';
								}
							}
							$optcounter++;
						}
						$rows .= '</td>';
					} elseif (isset($paraminfo['filter'])) {
						if ($paraminfo['filter'] == 'striptags') {
							$rows .= tra('any string except for HTML and PHP tags');
						} else {
							$rows .= $paraminfo['filter'];
						}
						$rows .= '</td>';
					} else {
						$rows .= '</td>';
					}
					//Description column
					$rows .= $cellbegin . $paraminfo['description'] . '</td>';
					//Default column
					if ($rowCounter == 1) {
						$header .= $headbegin . tra('Default') . '</td>';
					}
					if (!isset($paraminfo['default'])) {
						$paraminfo['default'] = '';
					}
					$rows .= $cellbegin . $paraminfo['default'] . '</td>';
					//Since column
					if ($rowCounter == 1) {
						$header .= $headbegin . tra('Since') . '</td>';
					}
					$rows .= $cellbegin . $paraminfo['since'] . '</td>';
 			   		$rows .= "\n\t" . '</tr>';
 			   		$rowCounter++;
				}
			} else {
				$rows .= "\n\t" . '<tr class="odd">' . $cellbegin . '<em>' . tra('no parameters') . '</em></td>';
			}
			$header .= "\n\t" . '</tr>';
			if (!empty($infoPlugin['prefs'])) {
				$pluginprefs = '<em>' . tra('Preferences required:') . '</em> ' . implode(', ', $infoPlugin['prefs']). '<br/>';
			} else {
				$pluginprefs = '';
			}
			$sOutput = $title . '<em>' . tr('Required parameters are in%0 %1bold%2', '</em>', '<b>', '</b>') . '<br />' . 
						$pluginprefs . '<table class="normal">' . $header . $rows . '</table>' . "\n";
			return $sOutput;
		}
	}
Example #3
0
 function run($data, $params)
 {
     $wikilib = TikiLib::lib('wiki');
     $exclude = isset($params['exclude']) ? $params['exclude'] : [];
     $params = $this->getParams($params, true);
     $aInfoPreset = array_keys($this->aInfoPresetNames);
     extract($params, EXTR_SKIP);
     if (!isset($page)) {
         $page = null;
     }
     /////////////////////////////////
     // Create a valid list for $info
     /////////////////////////////////
     //
     if ($info) {
         $info_temp = array();
         foreach ($info as $sInfo) {
             if (in_array(trim($sInfo), $aInfoPreset)) {
                 $info_temp[] = trim($sInfo);
             }
             $info = $info_temp ? $info_temp : false;
         }
     }
     $sOutput = "";
     // Verify if the page exists
     if (!$wikilib->page_exists($page)) {
         return $this->error(tra("Page cannot be found") . " : <b>{$page}</b>");
     }
     //
     /////////////////////////////////
     // Process backlinks
     /////////////////////////////////
     //
     $aBackRequest = array();
     $aBackLinks = $wikilib->get_backlinks($page);
     foreach ($aBackLinks as $backlink) {
         if (!in_array($backlink["fromPage"], $exclude)) {
             $aBackRequest[] = $backlink["fromPage"];
         }
     }
     if (isset($include_self) && $include_self) {
         $aBackRequest[] = $page;
     }
     if (!$aBackRequest) {
         return tra("No pages link to") . " (({$page}))";
     } else {
         $aPages = $this->list_pages(0, -1, 'pageName_asc', $aBackRequest);
     }
     //
     /////////////////////////////////
     // Start of Output
     /////////////////////////////////
     //
     if (!isset($noheader) || !$noheader) {
         // Create header
         $count = $aPages["cant"];
         if ($count == 1) {
             $sOutput .= tra("One page links to") . " (({$page}))";
         } else {
             $sOutput = "{$count} " . tra("pages link to") . " (({$page}))";
         }
         $sOutput .= "\n";
     }
     $sOutput .= PluginsLibUtil::createTable($aPages["data"], $info);
     return $sOutput;
 }
 function run($data, $params)
 {
     global $wikilib, $helpurl;
     if (!is_dir(PLUGINS_DIR)) {
         return $this->error("No plugins directory defined");
     }
     $params = $this->getParams($params);
     extract($params, EXTR_SKIP);
     $aPlugins = $wikilib->list_plugins();
     $aData = array();
     foreach ($aPlugins as $sPluginFile) {
         preg_match("/wikiplugin_(.*)\\.php/i", $sPluginFile, $match);
         $sPlugin = $match[1];
         include_once PLUGINS_DIR . '/' . $sPluginFile;
         // First, locate the new format ;)
         if (class_exists("WikiPlugin" . $sPlugin)) {
             $sClassName = "WikiPlugin" . $sPlugin;
             $oClass = new $sClassName();
             if (method_exists($oClass, 'getName')) {
                 $sPlugin = $oClass->getName();
             }
             $aData[$sPlugin]["description"] = $this->processDescription($oClass->getDescription());
             if (method_exists($oClass, 'getVersion')) {
                 $aData[$sPlugin]["version"] = $oClass->getVersion();
             } else {
                 $aData[$sPlugin]["version"] = " -- ";
             }
             $aParams = $oClass->getDefaultArguments();
             $aData[$sPlugin]["arguments"] = "";
             foreach ($aParams as $arg => $default) {
                 if (stristr($default, ' ')) {
                     $default = "'{$default}'";
                 }
                 if ($default === "[pagename]") {
                     $default = "[[pagename]";
                 }
                 $aData[$sPlugin]["arguments"] .= $arg . " => " . $default . "<br \\>";
             }
             unset($oClass);
         } else {
             $sFuncName = "wikiplugin_" . $sPlugin . "_help";
             if (function_exists($sFuncName)) {
                 $sDescription = $this->processDescription($sFuncName());
             } else {
                 $sDescription = " --- ";
             }
             $aData[$sPlugin]["description"] = $sDescription;
             $aData[$sPlugin]["version"] = tra("No version indicated");
             $aData[$sPlugin]["arguments"] = tra("No arguments indicated");
         }
         $aData[$sPlugin]["plugin"] = "[" . $helpurl . "Plugin" . ucfirst($sPlugin) . "|" . strtoupper($sPlugin) . "]";
     }
     // Plugins Loop
     return PluginsLibUtil::createTable($aData, $info, array("field" => "plugin", "name" => "Plugin"));
 }