diff options
author | Michael Hamann <michael@content-space.de> | 2013-08-02 23:30:32 +0200 |
---|---|---|
committer | Michael Hamann <michael@content-space.de> | 2013-08-02 23:31:51 +0200 |
commit | 02779b18797b2ee1304613de684d54988815dacb (patch) | |
tree | aab9f1a898c0603e875ecc4d0e086bb0b5086bcb /lib/plugins/extension/helper | |
parent | 1981046ea006031f74fb082960756b3d2919b99e (diff) | |
download | rpg-02779b18797b2ee1304613de684d54988815dacb.tar.gz rpg-02779b18797b2ee1304613de684d54988815dacb.tar.bz2 |
Extension manager: Implement extension table
This uses a lot of code and the whole design from the previous extension
manager implementation.
Diffstat (limited to 'lib/plugins/extension/helper')
-rw-r--r-- | lib/plugins/extension/helper/extension.php | 189 | ||||
-rw-r--r-- | lib/plugins/extension/helper/list.php | 477 |
2 files changed, 633 insertions, 33 deletions
diff --git a/lib/plugins/extension/helper/extension.php b/lib/plugins/extension/helper/extension.php index b80e56a4d..093ee7828 100644 --- a/lib/plugins/extension/helper/extension.php +++ b/lib/plugins/extension/helper/extension.php @@ -65,6 +65,35 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { } /** + * If the extension is bundled + * + * @return bool If the extension is bundled + */ + public function isBundled() { + if (!empty($this->remoteInfo['bundled'])) return $this->remoteInfo['bundled']; + return in_array($this->name, + array('acl', 'info', 'extension', 'test', 'revert', 'popularity', 'config', 'plugin', 'safefnrecode', 'authplain')); + } + + /** + * If the extension is protected + * + * @return bool if the extension is protected + */ + public function isProtected() { + return in_array($this->name, array('acl', 'config', 'info', 'plugin', 'revert', 'usermanager')); + } + + /** + * If the extension is installed in the correct directory + * + * @return bool If the extension is installed in the correct directory + */ + public function isInWrongFolder() { + return $this->name != $this->getBase(); + } + + /** * If the extension is enabled * * @return bool If the extension is enabled @@ -97,6 +126,15 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { return $this->is_template; } + /** + * Get the name of the installation directory + * + * @return string The name of the installation directory + */ + public function getInstallName() { + return $this->name; + } + // Data from plugin.info.txt/template.info.txt or the repo when not available locally /** * Get the basename of the extension @@ -104,6 +142,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return string The basename */ public function getBase() { + if (!empty($this->localInfo['base'])) return $this->localInfo['base']; return $this->name; } @@ -113,20 +152,20 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return string The display name */ public function getName() { - if (isset($this->localInfo['name'])) return $this->localInfo['name']; - if (isset($this->remoteInfo['name'])) return $this->remoteInfo['name']; + if (!empty($this->localInfo['name'])) return $this->localInfo['name']; + if (!empty($this->remoteInfo['name'])) return $this->remoteInfo['name']; return $this->name; } /** * Get the author name of the extension * - * @return string The name of the author + * @return string|bool The name of the author or false if there is none */ public function getAuthor() { - if (isset($this->localInfo['author'])) return $this->localInfo['author']; - if (isset($this->remoteInfo['author'])) return $this->remoteInfo['author']; - return $this->getLang('unknownauthor'); + if (!empty($this->localInfo['author'])) return $this->localInfo['author']; + if (!empty($this->remoteInfo['author'])) return $this->remoteInfo['author']; + return false; } /** @@ -136,7 +175,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { */ public function getEmail() { // email is only in the local data - if (isset($this->localInfo['email'])) return $this->localInfo['email']; + if (!empty($this->localInfo['email'])) return $this->localInfo['email']; return false; } @@ -146,8 +185,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return string|bool The md5sum of the email if there is any, false otherwise */ public function getEmailID() { - if (isset($this->remoteInfo['emailid'])) return $this->remoteInfo['emailid']; - if (isset($this->localInfo['email'])) return md5($this->localInfo['email']); + if (!empty($this->remoteInfo['emailid'])) return $this->remoteInfo['emailid']; + if (!empty($this->localInfo['email'])) return md5($this->localInfo['email']); return false; } @@ -157,8 +196,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return string The description */ public function getDescription() { - if (isset($this->localInfo['desc'])) return $this->localInfo['desc']; - if (isset($this->remoteInfo['description'])) return $this->remoteInfo['description']; + if (!empty($this->localInfo['desc'])) return $this->localInfo['desc']; + if (!empty($this->remoteInfo['description'])) return $this->remoteInfo['description']; return ''; } @@ -168,8 +207,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return string The URL */ public function getURL() { - if (isset($this->localInfo['url'])) return $this->localInfo['url']; - return 'https://www.dokuwiki.org/plugin:'.$this->name; + if (!empty($this->localInfo['url'])) return $this->localInfo['url']; + return 'https://www.dokuwiki.org/'.($this->isTemplate() ? 'template' : 'plugin').':'.$this->getBase(); } /** @@ -178,28 +217,66 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return string|bool The version, usually in the form yyyy-mm-dd if there is any */ public function getInstalledVersion() { - if (isset($this->localInfo['date'])) return $this->localInfo['date']; + if (!empty($this->localInfo['date'])) return $this->localInfo['date']; if ($this->isInstalled()) return $this->getLang('unknownversion'); return false; } /** + * Get the install date of the current version + * + * @return string|bool The date of the last update or false if not available + */ + public function getUpdateDate() { + if (!empty($this->managerData['updated'])) return $this->managerData['updated']; + return false; + } + + /** + * Get the date of the installation of the plugin + * + * @return string|bool The date of the installation or false if not available + */ + public function getInstallDate() { + if (!empty($this->managerData['installed'])) return $this->managerData['installed']; + return false; + } + + /** * Get the names of the dependencies of this extension * * @return array The base names of the dependencies */ public function getDependencies() { - if (isset($this->remoteInfo['dependencies'])) return $this->remoteInfo['dependencies']; + if (!empty($this->remoteInfo['dependencies'])) return $this->remoteInfo['dependencies']; return array(); } /** + * Get the names of the missing dependencies + * + * @return array The base names of the missing dependencies + */ + public function getMissingDependencies() { + /* @var Doku_Plugin_Controller $plugin_controller */ + global $plugin_controller; + $dependencies = $this->getDependencies(); + $missing_dependencies = array(); + foreach ($dependencies as $dependency) { + if ($plugin_controller->isdisabled($dependency)) { + $missing_dependencies[] = $dependency; + } + } + return $missing_dependencies; + } + + /** * Get the names of all conflicting extensions * * @return array The names of the conflicting extensions */ public function getConflicts() { - if (isset($this->remoteInfo['conflicts'])) return $this->remoteInfo['dependencies']; + if (!empty($this->remoteInfo['conflicts'])) return $this->remoteInfo['dependencies']; return array(); } @@ -209,7 +286,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return array The names of similar extensions */ public function getSimilarExtensions() { - if (isset($this->remoteInfo['similar'])) return $this->remoteInfo['similar']; + if (!empty($this->remoteInfo['similar'])) return $this->remoteInfo['similar']; return array(); } @@ -219,17 +296,28 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return array The names of the tags of the extension */ public function getTags() { - if (isset($this->remoteInfo['tags'])) return $this->remoteInfo['tags']; + if (!empty($this->remoteInfo['tags'])) return $this->remoteInfo['tags']; return array(); } /** + * Get the popularity information as floating point number [0,1] + * + * @return float|bool The popularity information or false if it isn't available + */ + public function getPopularity() { + if (!empty($this->remoteInfo['popularity'])) return $this->remoteInfo['popularity']/200.0; + return false; + } + + + /** * Get the text of the security warning if there is any * * @return string|bool The security warning if there is any, false otherwise */ public function getSecurityWarning() { - if (isset($this->remoteInfo['securitywarning'])) return $this->remoteInfo['securitywarning']; + if (!empty($this->remoteInfo['securitywarning'])) return $this->remoteInfo['securitywarning']; return false; } @@ -239,7 +327,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return string|bool The security issue if there is any, false otherwise */ public function getSecurityIssue() { - if (isset($this->remoteInfo['securityissue'])) return $this->remoteInfo['securityissue']; + if (!empty($this->remoteInfo['securityissue'])) return $this->remoteInfo['securityissue']; return false; } @@ -249,17 +337,26 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return string|bool The screenshot URL if there is any, false otherwise */ public function getScreenshotURL() { - if (isset($this->remoteInfo['screenshoturl'])) return $this->remoteInfo['screenshoturl']; + if (!empty($this->remoteInfo['screenshoturl'])) return $this->remoteInfo['screenshoturl']; return false; } /** + * Get the URL of the thumbnail of the extension if there is any + * + * @return string|bool The thumbnail URL if there is any, false otherwise + */ + public function getThumbnailURL() { + if (!empty($this->remoteInfo['thumbnailurl'])) return $this->remoteInfo['thumbnailurl']; + return false; + } + /** * Get the last used download URL of the extension if there is any * * @return string|bool The previously used download URL, false if the extension has been installed manually */ public function getLastDownloadURL() { - if (isset($this->managerData['downloadurl'])) return $this->managerData['downloadurl']; + if (!empty($this->managerData['downloadurl'])) return $this->managerData['downloadurl']; return false; } @@ -269,17 +366,28 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return string|bool The download URL if there is any, false otherwise */ public function getDownloadURL() { - if (isset($this->remoteInfo['downloadurl'])) return $this->remoteInfo['downloadurl']; + if (!empty($this->remoteInfo['downloadurl'])) return $this->remoteInfo['downloadurl']; return false; } /** + * If the download URL has changed since the last download + * + * @return bool If the download URL has changed + */ + public function hasDownloadURLChanged() { + $lasturl = $this->getLastDownloadURL(); + $currenturl = $this->getDownloadURL(); + return ($lasturl && $currenturl && $lasturl != $currenturl); + } + + /** * Get the bug tracker URL of the extension if there is any * * @return string|bool The bug tracker URL if there is any, false otherwise */ public function getBugtrackerURL() { - if (isset($this->remoteInfo['bugtracker'])) return $this->remoteInfo['bugtracker']; + if (!empty($this->remoteInfo['bugtracker'])) return $this->remoteInfo['bugtracker']; return false; } @@ -289,7 +397,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return string|bool The URL of the source repository if there is any, false otherwise */ public function getSourcerepoURL() { - if (isset($this->remoteInfo['sourcerepo'])) return $this->remoteInfo['sourcerepo']; + if (!empty($this->remoteInfo['sourcerepo'])) return $this->remoteInfo['sourcerepo']; return false; } @@ -299,7 +407,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return string|bool The donation URL if there is any, false otherwise */ public function getDonationURL() { - if (isset($this->remoteInfo['donationurl'])) return $this->remoteInfo['donationurl']; + if (!empty($this->remoteInfo['donationurl'])) return $this->remoteInfo['donationurl']; return false; } @@ -309,7 +417,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return array The type(s) as array of strings */ public function getTypes() { - if (isset($this->remoteInfo['types'])) return explode(', ', $this->remoteInfo['types']); + if (!empty($this->remoteInfo['types'])) return $this->remoteInfo['types']; if ($this->isTemplate()) return array(32 => 'template'); return array(); } @@ -320,7 +428,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return array The versions in the form yyyy-mm-dd => ('label' => label, 'implicit' => implicit) */ public function getCompatibleVersions() { - if (isset($this->remoteInfo['compatible'])) return $this->remoteInfo['compatible']; + if (!empty($this->remoteInfo['compatible'])) return $this->remoteInfo['compatible']; return array(); } @@ -330,7 +438,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return string|bool The last available update in the form yyyy-mm-dd if there is any, false otherwise */ public function getLastUpdate() { - if (isset($this->remoteInfo['lastupdate'])) return $this->remoteInfo['lastupdate']; + if (!empty($this->remoteInfo['lastupdate'])) return $this->remoteInfo['lastupdate']; return false; } @@ -392,6 +500,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { $status = 'Error, the requested extension hasn\'t been installed or updated'; } $this->setExtension($this->name, $this->isTemplate()); + $this->purgeCache(); } $this->dir_delete(dirname($path)); } @@ -404,6 +513,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * @return bool If the plugin was sucessfully installed */ public function uninstall() { + $this->purgeCache(); return $this->dir_delete($this->getInstallDir()); } @@ -417,8 +527,9 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { /* @var Doku_Plugin_Controller $plugin_controller */ global $plugin_controller; if (!$this->isInstalled()) return $this->getLang('notinstalled'); - if (!$this->isEnabled()) return $this->getLang('alreadyenabled'); + if ($this->isEnabled()) return $this->getLang('alreadyenabled'); if ($plugin_controller->enable($this->name)) { + $this->purgeCache(); return true; } else { return $this->getLang('pluginlistsaveerror'); @@ -438,6 +549,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { if (!$this->isInstalled()) return $this->getLang('notinstalled'); if (!$this->isEnabled()) return $this->getLang('alreadydisabled'); if ($plugin_controller->disable($this->name)) { + $this->purgeCache(); return true; } else { return $this->getLang('pluginlistsaveerror'); @@ -445,6 +557,17 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { } /** + * Purge the cache by touching the main configuration file + */ + protected function purgeCache() { + global $config_cascade; + + // expire dokuwiki caches + // touching local.php expires wiki page, JS and CSS caches + @touch(reset($config_cascade['main']['local'])); + } + + /** * Read local extension data either from info.txt or getInfo() */ protected function readLocalData() { @@ -463,7 +586,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { foreach($plugin_types as $type) { if(@file_exists($path.$type.'.php')) { - $plugin = plugin_load($type, $this->getBase()); + $plugin = plugin_load($type, $this->name); if ($plugin) break; } @@ -471,7 +594,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { while(false !== ($cp = readdir($dh))) { if($cp == '.' || $cp == '..' || strtolower(substr($cp, -4)) != '.php') continue; - $plugin = plugin_load($type, $this->getBase().'_'.substr($cp, 0, -4)); + $plugin = plugin_load($type, $this->name.'_'.substr($cp, 0, -4)); if ($plugin) break; } if ($plugin) break; @@ -551,7 +674,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { public function download($url, &$path) { // check the url $matches = array(); - if(!preg_match("/[^/]*$/", $url, $matches) || !$matches[0]) { + if(!preg_match("/[^\/]*$/", $url, $matches) || !$matches[0]) { return $this->getLang('baddownloadurl'); } $file = $matches[0]; diff --git a/lib/plugins/extension/helper/list.php b/lib/plugins/extension/helper/list.php new file mode 100644 index 000000000..ffb88114d --- /dev/null +++ b/lib/plugins/extension/helper/list.php @@ -0,0 +1,477 @@ +<?php +/** + * DokuWiki Plugin extension (Helper Component) + * + * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html + * @author Michael Hamann <michael@content-space.de> + */ + +// must be run within Dokuwiki +if(!defined('DOKU_INC')) die(); + +/** + * Class helper_plugin_extension_extension represents a single extension (plugin or template) + */ +class helper_plugin_extension_list extends DokuWiki_Plugin { + protected $form = ''; + + function start_form() { + $this->form .= '<form id="extension__list" accept-charset="utf-8" method="post" action="">'; + $hidden = array( + 'do'=>'admin', + 'page'=>'extension', + 'sectok'=>getSecurityToken() + ); + $this->add_hidden($hidden); + $this->form .= '<ul class="extensionList">'; + } + /** + * Build single row of extension table + * @param helper_plugin_extension_extension $extension The extension that shall be added + * @param bool $showinfo Show the info area + */ + function add_row(helper_plugin_extension_extension $extension, $showinfo = false) { + $this->start_row($extension); + $this->populate_column('legend', $this->make_legend($extension, $showinfo)); + $this->populate_column('actions', $this->make_actions($extension)); + $this->end_row(); + } + + /** + * Adds a header to the form + * + * @param string $id The id of the header + * @param string $header The content of the header + * @param int $level The level of the header + */ + function add_header($id, $header, $level = 2) { + $this->form .='<h'.$level.' id="'.$id.'">'.hsc($header).'</h'.$level.'>'; + } + + /** + * Adds a paragraph to the form + * + * @param string $data The content + */ + function add_p($data) { + $this->form .= '<p>'.hsc($data).'</p>'; + } + + /** + * Add hidden fields to the form with the given data + * @param array $array + */ + function add_hidden(array $array) { + $this->form .= '<div class="no">'; + foreach ($array as $key => $value) { + $this->form .= '<input type="hidden" name="'.hsc($key).'" value="'.hsc($value).'" />'; + } + $this->form .= '</div>'; + } + + /** + * Add closing tags + */ + function end_form() { + $this->form .= '</ul>'; + $this->form .= '</form>'; + } + + /** + * Print the form + */ + function render() { + echo $this->form; + } + + /** + * Start the HTML for the row for the extension + * + * @param helper_plugin_extension_extension $extension The extension + */ + private function start_row(helper_plugin_extension_extension $extension) { + $this->form .= '<li id="extensionplugin__'.hsc($extension->getInstallName()).'" class="'.$this->make_class($extension).'">'; + } + + /** + * Add a column with the given class and content + * @param string $class The class name + * @param string $html The content + */ + private function populate_column($class, $html) { + $this->form .= '<div class="'.$class.' col">'.$html.'</div>'; + } + + /** + * End the row + */ + private function end_row() { + $this->form .= '</li>'.DOKU_LF; + } + + /** + * Generate the link to the plugin homepage + * + * @param helper_plugin_extension_extension $extension The extension + * @return string The HTML code + */ + function make_homepagelink(helper_plugin_extension_extension $extension) { + $text = $this->getLang('homepage_link'); + $url = hsc($extension->getURL()); + return '<a href="'.$url.'" title="'.$url.'" class ="urlextern">'.$text.'</a> '; + } + + /** + * Generate the class name for the row of the extensio + * + * @param helper_plugin_extension_extension $extension The extension object + * @return string The class name + */ + function make_class(helper_plugin_extension_extension $extension) { + $class = ($extension->isTemplate()) ? 'template' : 'plugin'; + if($extension->isInstalled()) { + $class.=' installed'; + $class.= ($extension->isEnabled()) ? ' enabled':' disabled'; + } + if(!$extension->canModify()) $class.= ' notselect'; + if($extension->isProtected()) $class.= ' protected'; + //if($this->showinfo) $class.= ' showinfo'; + return $class; + } + + /** + * Generate a link to the author of the extension + * + * @param helper_plugin_extension_extension $extension The extension object + * @return string The HTML code of the link + */ + function make_author(helper_plugin_extension_extension $extension) { + global $ID; + + if($extension->getAuthor()) { + + $params = array( + 'do'=>'admin', + 'page'=>'extension', + 'tab'=>'search', + 'q'=>'author:'.$extension->getAuthor() + ); + $url = wl($ID, $params); + return '<a href="'.$url.'" title="'.$this->getLang('author_hint').'" >'.hsc($extension->getAuthor()).'</a>'; + } + return "<em>".$this->getLang('unknown_author')."</em>"; + } + + /** + * Get the link and image tag for the screenshot/thumbnail + * + * @param helper_plugin_extension_extension $extension The extension object + * @return string The HTML code + */ + function make_screenshot(helper_plugin_extension_extension $extension) { + if($extension->getScreenshotURL()) { + $img = '<a title="'.hsc($extension->getName()).'" href="'.hsc($extension->getScreenshotURL()).'" target="_blank">'. + '<img alt="'.hsc($extension->getName()).'" width="120" height="70" src="'.hsc($extension->getThumbnailURL()).'" />'. + '</a>'; + } elseif($extension->isTemplate()) { + $img = '<img alt="template" width="120" height="70" src="'.DOKU_BASE.'lib/plugins/extension/images/template.png" />'; + + } else { + $img = '<img alt="plugin" width="120" height="70" src="'.DOKU_BASE.'lib/plugins/extension/images/plugin.png" />'; + } + return '<div class="screenshot" >'.$img.'<span></span></div>'; + } + + /** + * Extension main description + * + * @param helper_plugin_extension_extension $extension The extension object + * @param bool $showinfo Show the info section + * @return string The HTML code + */ + function make_legend(helper_plugin_extension_extension $extension, $showinfo = false) { + $return = '<div>'; + $return .= '<h2>'; + $return .= sprintf($this->getLang('extensionby'), hsc($extension->getName()), $this->make_author($extension)); + $return .= '</h2>'; + + $return .= $this->make_screenshot($extension); + + $popularity = $extension->getPopularity(); + if ($popularity !== false && !$extension->isBundled()) { + $popularityText = sprintf($this->getLang('popularity'), $popularity); + $return .= '<div class="popularity" title="'.$popularityText.'"><div style="width: '.($popularity * 100).'%;"><span></span></div></div>'; + } + + $return .= '<p>'; + if($extension->getDescription()) { + $return .= hsc($extension->getDescription()).' '; + } + $return .= '</p>'; + + $return .= $this->make_linkbar($extension); + $return .= $this->make_action('info', $extension, $showinfo); + if ($showinfo) { + $return .= $this->make_info($extension); + } + $return .= $this->make_noticearea($extension); + $return .= '</div>'; + return $return; + } + + /** + * Generate the link bar HTML code + * + * @param helper_plugin_extension_extension $extension The extension instance + * @return string The HTML code + */ + function make_linkbar(helper_plugin_extension_extension $extension) { + $return = '<span class="linkbar">'; + $return .= $this->make_homepagelink($extension); + if ($extension->getBugtrackerURL()) { + $return .= ' <a href="'.hsc($extension->getBugtrackerURL()).'" title="'.hsc($extension->getBugtrackerURL()).'" class ="interwiki iw_dokubug">'.$this->getLang('bugs_features').'</a> '; + } + foreach ($extension->getTags() as $tag) { + $return .= hsc($tag).' '; //$this->manager->handler->html_taglink($tag); + } + $return .= '</span>'; + return $return; + } + + /** + * Notice area + * + * @param helper_plugin_extension_extension $extension The extension + * @return string The HTML code + */ + function make_noticearea(helper_plugin_extension_extension $extension) { + $return = ''; + $missing_dependencies = $extension->getMissingDependencies(); + if(!empty($missing_dependencies)) { + $return .= '<div class="msg error">'. + sprintf($this->getLang('missing_dependency'), implode(', ', /*array_map(array($this->helper, 'make_extensionsearchlink'),*/ $missing_dependencies)). + '</div>'; + } + if($extension->isInWrongFolder()) { + $return .= '<div class="msg error">'. + sprintf($this->getLang('wrong_folder'), hsc($extension->getInstallName()), hsc($extension->getBase())). + '</div>'; + } + if(($securityissue = $extension->getSecurityIssue()) !== false) { + $return .= '<div class="msg error">'. + sprintf($this->getLang('security_issue'), hsc($securityissue )). + '</div>'; + } + if(($securitywarning = $extension->getSecurityWarning()) !== false) { + $return .= '<div class="msg notify">'. + sprintf($this->getLang('security_warning'), hsc($securitywarning)). + '</div>'; + } + if($extension->updateAvailable()) { + $return .= '<div class="msg notify">'. + sprintf($this->getLang('update_available'), hsc($extension->getLastUpdate())). + '</div>'; + } + if($extension->hasDownloadURLChanged()) { + $return .= '<div class="msg notify">'. + sprintf($this->getLang('url_change'), hsc($extension->getDownloadURL()), hsc($extension->getLastDownloadURL())). + '</div>'; + } + return $return; + } + + /** + * Create a link from the given URL + * + * Shortens the URL for display + * + * @param string $url + * + * @return string HTML link + */ + function shortlink($url){ + $link = parse_url($url); + + $base = $link['host']; + if($link['port']) $base .= $base.':'.$link['port']; + $long = $link['path']; + if($link['query']) $long .= $link['query']; + + $name = shorten($base, $long, 55); + + return '<a href="'.hsc($url).'" class="urlextern">'.hsc($name).'</a>'; + } + + /** + * Plugin/template details + * + * @param helper_plugin_extension_extension $extension The extension + * @return string The HTML code + */ + function make_info(helper_plugin_extension_extension $extension) { + $default = $this->getLang('unknown'); + $return = '<dl class="details">'; + + if (!$extension->isBundled()) { + $return .= '<dt>'.$this->getLang('downloadurl').'</dt>'; + $return .= '<dd>'; + $return .= ($extension->getDownloadURL() ? $this->shortlink($extension->getDownloadURL()) : $default); + $return .= '</dd>'; + + $return .= '<dt>'.$this->getLang('repository').'</dt>'; + $return .= '<dd>'; + $return .= ($extension->getSourcerepoURL() ? $this->shortlink($extension->getSourcerepoURL()) : $default); + $return .= '</dd>'; + } + + if ($extension->isInstalled()) { + if ($extension->getInstalledVersion()) { + $return .= '<dt>'.$this->getLang('installed_version').'</dt>'; + $return .= '<dd>'; + $return .= hsc($extension->getInstalledVersion()); + $return .= '</dd>'; + } else { + $return .= '<dt>'.$this->getLang('install_date').'</dt>'; + $return .= '<dd>'; + $return .= ($extension->getUpdateDate() ? hsc($extension->getUpdateDate()) : $this->getLang('unknown')); + $return .= '</dd>'; + } + } + if (!$extension->isInstalled() || $extension->updateAvailable()) { + $return .= '<dt>'.$this->getLang('available_version').'</dt>'; + $return .= '<dd>'; + $return .= ($extension->getLastUpdate() ? hsc($extension->getLastUpdate()) : $this->getLang('unknown')); + $return .= '</dd>'; + } + + if($extension->getInstallDate()) { + $return .= '<dt>'.$this->getLang('installed').'</dt>'; + $return .= '<dd>'; + $return .= hsc($extension->getInstallDate()); + $return .= '</dd>'; + } + + $return .= '<dt>'.$this->getLang('provides').'</dt>'; + $return .= '<dd>'; + $return .= ($extension->getTypes() ? hsc(implode(', ', $extension->getTypes())) : $default); + $return .= '</dd>'; + + if($extension->getCompatibleVersions()) { + $return .= '<dt>'.$this->getLang('compatible').'</dt>'; + $return .= '<dd>'; + foreach ($extension->getCompatibleVersions() as $date => $version) { + $return .= $version['label'].' ('.$date.'), '; + } + $return .= '</dd>'; + } + if($extension->getDependencies()) { + $return .= '<dt>'.$this->getLang('depends').'</dt>'; + $return .= '<dd>'; + $return .= $this->make_linklist($extension->getDependencies()); + $return .= '</dd>'; + } + + if($extension->getSimilarExtensions()) { + $return .= '<dt>'.$this->getLang('similar').'</dt>'; + $return .= '<dd>'; + $return .= $this->make_linklist($extension->getSimilarExtensions()); + $return .= '</dd>'; + } + + if($extension->getConflicts()) { + $return .= '<dt>'.$this->getLang('conflicts').'</dt>'; + $return .= '<dd>'; + $return .= $this->make_linklist($extension->getConflicts()); + $return .= '</dd>'; + } + if ($extension->getDonationURL()) { + $return .= '<a href="'.hsc($extension->getDonationURL()).'" class="donate" title="'.$this->getLang('donate').'"></a>'; + } + $return .= '</dl>'; + return $return; + } + + /** + * Generate a list of links for extensions + * @param array $links The links + * @return string The HTML code + */ + function make_linklist($links) { + $return = ''; + foreach ($links as $link) { + $dokulink = hsc($link); + if (strpos($link, 'template:') !== 0) $dokulink = 'plugin:'.$dokulink; + $return .= '<a href="http://www.dokuwiki.org/'.$dokulink.'" title="'.$dokulink.'" class="interwiki iw_doku">'.$link.'</a> '; + } + return $return; + } + + /** + * Display the action buttons if they are possible + * + * @param helper_plugin_extension_extension $extension The extension + * @return string The HTML code + */ + function make_actions(helper_plugin_extension_extension $extension) { + $return = ''; + if (!$extension->isInstalled() && $extension->canModify() === true) { + $return .= $this->make_action('install', $extension); + } elseif ($extension->canModify()) { + if (!$extension->isBundled()) { + $return .= $this->make_action('uninstall', $extension); + if ($extension->getDownloadURL()) { + if ($extension->updateAvailable()) { + $return .= $this->make_action('update', $extension); + } else { + $return .= $this->make_action('reinstall', $extension); + } + } + } + if (!$extension->isProtected()) { + if ($extension->isEnabled()) { + $return .= $this->make_action('disable', $extension); + } else { + $return .= $this->make_action('enable', $extension); + } + } + } + + if (!$extension->isInstalled()) { + $return .= ' <span class="version">'.$this->getLang('available_version').' '; + $return .= ($extension->getLastUpdate() ? hsc($extension->getLastUpdate()) : $this->getLang('unknown')).'</span>'; + } + + return $return; + } + + /** + * Display an action button for an extension + * + * @param string $action The action + * @param helper_plugin_extension_extension $extension The extension + * @param bool $showinfo If the info block is shown + * @return string The HTML code + */ + function make_action($action, $extension, $showinfo = false) { + $title = $revertAction = $extraClass = ''; + + switch ($action) { + case 'info': + $title = 'title="'.$this->getLang('btn_info').'"'; + if ($showinfo) { + $revertAction = '-'; + $extraClass = 'close'; + } + break; + case 'install': + case 'reinstall': + $title = 'title="'.$extension->getDownloadURL().'"'; + break; + } + + $classes = 'button '.$action.' '.$extraClass; + $name = 'fn['.$action.']['.$revertAction.hsc($extension->getInstallName()).']'; + + return '<input class="'.$classes.'" name="'.$name.'" type="submit" value="'.$this->getLang('btn_'.$action).'" '.$title.' />'; + } +} |