*/ // 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 .= '
'; $hidden = array( 'do'=>'admin', 'page'=>'extension', 'sectok'=>getSecurityToken() ); $this->add_hidden($hidden); $this->form .= ''; $this->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 .= '
  • '; } /** * 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 .= '
    '.$html.'
    '; } /** * End the row */ private function end_row() { $this->form .= '
  • '.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 ''.$text.' '; } /** * 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 ''.hsc($extension->getAuthor()).''; } return "".$this->getLang('unknown_author').""; } /** * 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 = ''. ''.hsc($extension->getName()).''. ''; } elseif($extension->isTemplate()) { $img = 'template'; } else { $img = 'plugin'; } return '
    '.$img.'
    '; } /** * 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 = '
    '; $return .= '

    '; $return .= sprintf($this->getLang('extensionby'), hsc($extension->getName()), $this->make_author($extension)); $return .= '

    '; $return .= $this->make_screenshot($extension); $popularity = $extension->getPopularity(); if ($popularity !== false && !$extension->isBundled()) { $popularityText = sprintf($this->getLang('popularity'), $popularity); $return .= '
    '; } $return .= '

    '; if($extension->getDescription()) { $return .= hsc($extension->getDescription()).' '; } $return .= '

    '; $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 .= '
    '; 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 = ''; $return .= $this->make_homepagelink($extension); if ($extension->getBugtrackerURL()) { $return .= ' '.$this->getLang('bugs_features').' '; } foreach ($extension->getTags() as $tag) { $return .= hsc($tag).' '; //$this->manager->handler->html_taglink($tag); } $return .= ''; 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 .= '
    '. sprintf($this->getLang('missing_dependency'), implode(', ', /*array_map(array($this->helper, 'make_extensionsearchlink'),*/ $missing_dependencies)). '
    '; } if($extension->isInWrongFolder()) { $return .= '
    '. sprintf($this->getLang('wrong_folder'), hsc($extension->getInstallName()), hsc($extension->getBase())). '
    '; } if(($securityissue = $extension->getSecurityIssue()) !== false) { $return .= '
    '. sprintf($this->getLang('security_issue'), hsc($securityissue )). '
    '; } if(($securitywarning = $extension->getSecurityWarning()) !== false) { $return .= '
    '. sprintf($this->getLang('security_warning'), hsc($securitywarning)). '
    '; } if($extension->updateAvailable()) { $return .= '
    '. sprintf($this->getLang('update_available'), hsc($extension->getLastUpdate())). '
    '; } if($extension->hasDownloadURLChanged()) { $return .= '
    '. sprintf($this->getLang('url_change'), hsc($extension->getDownloadURL()), hsc($extension->getLastDownloadURL())). '
    '; } 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 ''.hsc($name).''; } /** * 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 = '
    '; if (!$extension->isBundled()) { $return .= '
    '.$this->getLang('downloadurl').'
    '; $return .= '
    '; $return .= ($extension->getDownloadURL() ? $this->shortlink($extension->getDownloadURL()) : $default); $return .= '
    '; $return .= '
    '.$this->getLang('repository').'
    '; $return .= '
    '; $return .= ($extension->getSourcerepoURL() ? $this->shortlink($extension->getSourcerepoURL()) : $default); $return .= '
    '; } if ($extension->isInstalled()) { if ($extension->getInstalledVersion()) { $return .= '
    '.$this->getLang('installed_version').'
    '; $return .= '
    '; $return .= hsc($extension->getInstalledVersion()); $return .= '
    '; } else { $return .= '
    '.$this->getLang('install_date').'
    '; $return .= '
    '; $return .= ($extension->getUpdateDate() ? hsc($extension->getUpdateDate()) : $this->getLang('unknown')); $return .= '
    '; } } if (!$extension->isInstalled() || $extension->updateAvailable()) { $return .= '
    '.$this->getLang('available_version').'
    '; $return .= '
    '; $return .= ($extension->getLastUpdate() ? hsc($extension->getLastUpdate()) : $this->getLang('unknown')); $return .= '
    '; } if($extension->getInstallDate()) { $return .= '
    '.$this->getLang('installed').'
    '; $return .= '
    '; $return .= hsc($extension->getInstallDate()); $return .= '
    '; } $return .= '
    '.$this->getLang('provides').'
    '; $return .= '
    '; $return .= ($extension->getTypes() ? hsc(implode(', ', $extension->getTypes())) : $default); $return .= '
    '; if($extension->getCompatibleVersions()) { $return .= '
    '.$this->getLang('compatible').'
    '; $return .= '
    '; foreach ($extension->getCompatibleVersions() as $date => $version) { $return .= $version['label'].' ('.$date.'), '; } $return .= '
    '; } if($extension->getDependencies()) { $return .= '
    '.$this->getLang('depends').'
    '; $return .= '
    '; $return .= $this->make_linklist($extension->getDependencies()); $return .= '
    '; } if($extension->getSimilarExtensions()) { $return .= '
    '.$this->getLang('similar').'
    '; $return .= '
    '; $return .= $this->make_linklist($extension->getSimilarExtensions()); $return .= '
    '; } if($extension->getConflicts()) { $return .= '
    '.$this->getLang('conflicts').'
    '; $return .= '
    '; $return .= $this->make_linklist($extension->getConflicts()); $return .= '
    '; } if ($extension->getDonationURL()) { $return .= ''; } $return .= '
    '; 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 .= ''.$link.' '; } 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 .= ' '.$this->getLang('available_version').' '; $return .= ($extension->getLastUpdate() ? hsc($extension->getLastUpdate()) : $this->getLang('unknown')).''; } 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 ''; } /** * Create an URL inside the extension manager * * @param string tab tb to load, empty for current tab * @param array $params associative array of parameter to set * @return string */ static public function tabURL($tab='', $params=array()){ global $ID; global $INPUT; if(!$tab) $tab = $INPUT->str('tab', 'installed', true); $defaults = array( 'do' => 'admin', 'page' => 'extension', 'tab' => $tab, ); return wl($ID, array_merge($defaults, $params)); } }