*/ /** * Class helper_plugin_extension_list takes care of creating a HTML list of extensions */ class helper_plugin_extension_list extends Plugin { protected $form = ''; /** @var helper_plugin_extension_gui */ protected $gui; /** * Constructor * * loads additional helpers */ public function __construct() { $this->gui = plugin_load('helper', 'extension_gui'); } /** * Initialize the extension table form */ public function startForm() { $this->form .= ''; } /** * Show message when no results are found */ public function nothingFound() { global $lang; $this->form .= '
  • ' . $lang['nothingfound'] . '
  • '; } /** * Print the form * * @param bool $returnonly whether to return html or print */ public function render($returnonly = false) { if ($returnonly) return $this->form; echo $this->form; } /** * Start the HTML for the row for the extension * * @param helper_plugin_extension_extension $extension The extension */ private function startRow(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 populateColumn($class, $html) { $this->form .= '
    ' . $html . '
    ' . DOKU_LF; } /** * End the row */ private function endRow() { $this->form .= '
  • ' . DOKU_LF; } /** * Generate the link to the plugin homepage * * @param helper_plugin_extension_extension $extension The extension * @return string The HTML code */ public function makeHomepageLink(helper_plugin_extension_extension $extension) { global $conf; $url = $extension->getURL(); if (strtolower(parse_url($url, PHP_URL_HOST)) == 'www.dokuwiki.org') { $linktype = 'interwiki'; } else { $linktype = 'extern'; } $param = [ 'href' => $url, 'title' => $url, 'class' => ($linktype == 'extern') ? 'urlextern' : 'interwiki iw_doku', 'target' => $conf['target'][$linktype], 'rel' => ($linktype == 'extern') ? 'noopener' : '' ]; if ($linktype == 'extern' && $conf['relnofollow']) { $param['rel'] = implode(' ', [$param['rel'], 'ugc nofollow']); } $html = ' ' . $this->getLang('homepage_link') . ''; return $html; } /** * Generate the class name for the row of the extension * * @param helper_plugin_extension_extension $extension The extension object * @return string The class name */ public function makeClass(helper_plugin_extension_extension $extension) { $class = ($extension->isTemplate()) ? 'template' : 'plugin'; if ($extension->isInstalled()) { $class .= ' installed'; $class .= ($extension->isEnabled()) ? ' enabled' : ' disabled'; if ($extension->updateAvailable()) $class .= ' updatable'; } 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 */ public function makeAuthor(helper_plugin_extension_extension $extension) { if ($extension->getAuthor()) { $mailid = $extension->getEmailID(); if ($mailid) { $url = $this->gui->tabURL('search', ['q' => 'authorid:' . $mailid]); $html = '' . ' ' . hsc($extension->getAuthor()) . ''; } else { $html = '' . hsc($extension->getAuthor()) . ''; } $html = '' . $html . ''; } else { $html = '' . $this->getLang('unknown_author') . '' . DOKU_LF; } return $html; } /** * Get the link and image tag for the screenshot/thumbnail * * @param helper_plugin_extension_extension $extension The extension object * @return string The HTML code */ public function makeScreenshot(helper_plugin_extension_extension $extension) { $screen = $extension->getScreenshotURL(); $thumb = $extension->getThumbnailURL(); if ($screen) { // use protocol independent URLs for images coming from us #595 $screen = str_replace('http://www.dokuwiki.org', '//www.dokuwiki.org', $screen); $thumb = str_replace('http://www.dokuwiki.org', '//www.dokuwiki.org', $thumb); $title = sprintf($this->getLang('screenshot'), hsc($extension->getDisplayName())); $img = '' . '' . $title . '' . ''; } elseif ($extension->isTemplate()) { $img = ''; } else { $img = ''; } $html = '
    ' . $img . '
    ' . DOKU_LF; return $html; } /** * Extension main description * * @param helper_plugin_extension_extension $extension The extension object * @param bool $showinfo Show the info section * @return string The HTML code */ public function makeLegend(helper_plugin_extension_extension $extension, $showinfo = false) { $html = '
    '; $html .= '

    '; $html .= sprintf( $this->getLang('extensionby'), '' . hsc($extension->getDisplayName()) . '', $this->makeAuthor($extension) ); $html .= '

    ' . DOKU_LF; $html .= $this->makeScreenshot($extension); $popularity = $extension->getPopularity(); if ($popularity !== false && !$extension->isBundled()) { $popularityText = sprintf($this->getLang('popularity'), round($popularity * 100, 2)); $html .= '
    ' . '
    ' . '' . $popularityText . '' . '
    ' . DOKU_LF; } if ($extension->getDescription()) { $html .= '

    '; $html .= hsc($extension->getDescription()) . ' '; $html .= '

    ' . DOKU_LF; } $html .= $this->makeLinkbar($extension); if ($showinfo) { $url = $this->gui->tabURL(''); $class = 'close'; } else { $url = $this->gui->tabURL('', ['info' => $extension->getID()]); $class = ''; } $html .= ' ' . $this->getLang('btn_info') . ''; if ($showinfo) { $html .= $this->makeInfo($extension); } $html .= $this->makeNoticeArea($extension); $html .= '
    ' . DOKU_LF; return $html; } /** * Generate the link bar HTML code * * @param helper_plugin_extension_extension $extension The extension instance * @return string The HTML code */ public function makeLinkbar(helper_plugin_extension_extension $extension) { global $conf; $html = '' . DOKU_LF; return $html; } /** * Notice area * * @param helper_plugin_extension_extension $extension The extension * @return string The HTML code */ public function makeNoticeArea(helper_plugin_extension_extension $extension) { $html = ''; $missing_dependencies = $extension->getMissingDependencies(); if (!empty($missing_dependencies)) { $html .= '
    ' . sprintf( $this->getLang('missing_dependency'), '' . implode(', ', $missing_dependencies) . '' ) . '
    '; } if ($extension->isInWrongFolder()) { $html .= '
    ' . sprintf( $this->getLang('wrong_folder'), '' . hsc($extension->getInstallName()) . '', '' . hsc($extension->getBase()) . '' ) . '
    '; } if (($securityissue = $extension->getSecurityIssue()) !== false) { $html .= '
    ' . sprintf($this->getLang('security_issue'), '' . hsc($securityissue) . '') . '
    '; } if (($securitywarning = $extension->getSecurityWarning()) !== false) { $html .= '
    ' . sprintf($this->getLang('security_warning'), '' . hsc($securitywarning) . '') . '
    '; } if (($updateMessage = $extension->getUpdateMessage()) !== false) { $html .= '
    ' . sprintf($this->getLang('update_message'), '' . hsc($updateMessage) . '') . '
    '; } if ($extension->updateAvailable()) { $html .= '
    ' . sprintf($this->getLang('update_available'), hsc($extension->getLastUpdate())) . '
    '; } if ($extension->hasDownloadURLChanged()) { $html .= '
    ' . sprintf( $this->getLang('url_change'), '' . hsc($extension->getDownloadURL()) . '', '' . hsc($extension->getLastDownloadURL()) . '' ) . '
    '; } return $html . DOKU_LF; } /** * Create a link from the given URL * * Shortens the URL for display * * @param string $url * @return string HTML link */ public function shortlink($url) { $link = parse_url($url); $base = $link['host']; if (!empty($link['port'])) $base .= $base . ':' . $link['port']; $long = $link['path']; if (!empty($link['query'])) $long .= $link['query']; $name = shorten($base, $long, 55); $html = '' . hsc($name) . ''; return $html; } /** * Plugin/template details * * @param helper_plugin_extension_extension $extension The extension * @return string The HTML code */ public function makeInfo(helper_plugin_extension_extension $extension) { $default = $this->getLang('unknown'); $html = '
    '; $html .= '
    ' . $this->getLang('status') . '
    '; $html .= '
    ' . $this->makeStatus($extension) . '
    '; if ($extension->getDonationURL()) { $html .= '
    ' . $this->getLang('donate') . '
    '; $html .= '
    '; $html .= ''; $html .= '
    '; } if (!$extension->isBundled()) { $html .= '
    ' . $this->getLang('downloadurl') . '
    '; $html .= '
    '; $html .= ($extension->getDownloadURL() ? $this->shortlink($extension->getDownloadURL()) : $default); $html .= '
    '; $html .= '
    ' . $this->getLang('repository') . '
    '; $html .= '
    '; $html .= ($extension->getSourcerepoURL() ? $this->shortlink($extension->getSourcerepoURL()) : $default); $html .= '
    '; } if ($extension->isInstalled()) { if ($extension->getInstalledVersion()) { $html .= '
    ' . $this->getLang('installed_version') . '
    '; $html .= '
    '; $html .= hsc($extension->getInstalledVersion()); $html .= '
    '; } if (!$extension->isBundled()) { $html .= '
    ' . $this->getLang('install_date') . '
    '; $html .= '
    '; $html .= ($extension->getUpdateDate() ? hsc($extension->getUpdateDate()) : $this->getLang('unknown')); $html .= '
    '; } } if (!$extension->isInstalled() || $extension->updateAvailable()) { $html .= '
    ' . $this->getLang('available_version') . '
    '; $html .= '
    '; $html .= ($extension->getLastUpdate() ? hsc($extension->getLastUpdate()) : $this->getLang('unknown')); $html .= '
    '; } $html .= '
    ' . $this->getLang('provides') . '
    '; $html .= '
    '; $html .= ($extension->getTypes() ? hsc(implode(', ', $extension->getTypes())) : $default); $html .= '
    '; if (!$extension->isBundled() && $extension->getCompatibleVersions()) { $html .= '
    ' . $this->getLang('compatible') . '
    '; $html .= '
    '; foreach ($extension->getCompatibleVersions() as $date => $version) { $html .= '' . $version['label'] . ' (' . $date . '), '; } $html = rtrim($html, ', '); $html .= '
    '; } if ($extension->getDependencies()) { $html .= '
    ' . $this->getLang('depends') . '
    '; $html .= '
    '; $html .= $this->makeLinkList($extension->getDependencies()); $html .= '
    '; } if ($extension->getSimilarExtensions()) { $html .= '
    ' . $this->getLang('similar') . '
    '; $html .= '
    '; $html .= $this->makeLinkList($extension->getSimilarExtensions()); $html .= '
    '; } if ($extension->getConflicts()) { $html .= '
    ' . $this->getLang('conflicts') . '
    '; $html .= '
    '; $html .= $this->makeLinkList($extension->getConflicts()); $html .= '
    '; } $html .= '
    ' . DOKU_LF; return $html; } /** * Generate a list of links for extensions * * @param array $ext The extensions * @return string The HTML code */ public function makeLinkList($ext) { $html = ''; foreach ($ext as $link) { $html .= '' . hsc($link) . ', '; } return rtrim($html, ', '); } /** * Display the action buttons if they are possible * * @param helper_plugin_extension_extension $extension The extension * @return string The HTML code */ public function makeActions(helper_plugin_extension_extension $extension) { global $conf; $html = ''; $errors = ''; if ($extension->isInstalled()) { if (($canmod = $extension->canModify()) === true) { if (!$extension->isProtected()) { $html .= $this->makeAction('uninstall', $extension); } if ($extension->getDownloadURL()) { if ($extension->updateAvailable()) { $html .= $this->makeAction('update', $extension); } else { $html .= $this->makeAction('reinstall', $extension); } } } else { $errors .= '

    ' . $this->getLang($canmod) . '

    '; } if (!$extension->isProtected() && !$extension->isTemplate()) { // no enable/disable for templates if ($extension->isEnabled()) { $html .= $this->makeAction('disable', $extension); } else { $html .= $this->makeAction('enable', $extension); } } if ($extension->isGitControlled()) { $errors .= '

    ' . $this->getLang('git') . '

    '; } if ( $extension->isEnabled() && in_array('Auth', $extension->getTypes()) && $conf['authtype'] != $extension->getID() ) { $errors .= '

    ' . $this->getLang('auth') . '

    '; } } elseif (($canmod = $extension->canModify()) === true) { if ($extension->getDownloadURL()) { $html .= $this->makeAction('install', $extension); } } else { $errors .= '
    ' . $this->getLang($canmod) . '
    '; } if (!$extension->isInstalled() && $extension->getDownloadURL()) { $html .= ' ' . $this->getLang('available_version') . ' '; $html .= ($extension->getLastUpdate() ? hsc($extension->getLastUpdate()) : $this->getLang('unknown')) . ''; } return $html . ' ' . $errors . DOKU_LF; } /** * Display an action button for an extension * * @param string $action The action * @param helper_plugin_extension_extension $extension The extension * @return string The HTML code */ public function makeAction($action, $extension) { $title = ''; if ($action == 'install' || $action == 'reinstall') { $title = 'title="' . hsc($extension->getDownloadURL()) . '"'; } $classes = 'button ' . $action; $name = 'fn[' . $action . '][' . hsc($extension->getID()) . ']'; $html = ' '; return $html; } /** * Plugin/template status * * @param helper_plugin_extension_extension $extension The extension * @return string The description of all relevant statusses */ public function makeStatus(helper_plugin_extension_extension $extension) { $status = []; if ($extension->isInstalled()) { $status[] = $this->getLang('status_installed'); if ($extension->isProtected()) { $status[] = $this->getLang('status_protected'); } else { $status[] = $extension->isEnabled() ? $this->getLang('status_enabled') : $this->getLang('status_disabled'); } } else { $status[] = $this->getLang('status_not_installed'); } if (!$extension->canModify()) $status[] = $this->getLang('status_unmodifiable'); if ($extension->isBundled()) $status[] = $this->getLang('status_bundled'); $status[] = $extension->isTemplate() ? $this->getLang('status_template') : $this->getLang('status_plugin'); return implode(', ', $status); } }