*/ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); /** * Class helper_plugin_extension_list takes care of creating a HTML list of extensions */ class helper_plugin_extension_list extends DokuWiki_Plugin { protected $form = ''; /** @var helper_plugin_extension_gui */ protected $gui; /** * Constructor * * loads additional helpers */ public function __construct(){ $this->gui = plugin_load('helper', 'extension_gui'); } function start_form() { $this->form .= '
'; $hidden = array( 'do'=>'admin', 'page'=>'extension', 'sectok'=>getSecurityToken() ); $this->add_hidden($hidden); $this->form .= ''; $this->form .= '
'.DOKU_LF; } /** * Show message when no results are found */ function nothing_found() { global $lang; $this->form .= '
  • '.$lang['nothingfound'].'
  • '; } /** * 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.'
    '.DOKU_LF; } /** * 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->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 */ function make_author(helper_plugin_extension_extension $extension) { global $ID; if($extension->getAuthor()) { $mailid = $extension->getEmailID(); if($mailid){ $url = $this->gui->tabURL('search', array('q' => 'authorid:'.$mailid)); return ' '.hsc($extension->getAuthor()).''; }else{ return ''.hsc($extension->getAuthor()).''; } } return "".$this->getLang('unknown_author')."".DOKU_LF; } /** * 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) { $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 = ''; } return '
    '.$img.'
    '.DOKU_LF; } /** * 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->getDisplayName()).'', $this->make_author($extension)); $return .= '

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

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

    '.DOKU_LF; } $return .= $this->make_linkbar($extension); if($showinfo){ $url = $this->gui->tabURL(''); $class = 'close'; }else{ $url = $this->gui->tabURL('', array('info' => $extension->getID())); $class = ''; } $return .= ' '.$this->getLang('btn_info').''; if ($showinfo) { $return .= $this->make_info($extension); } $return .= $this->make_noticearea($extension); $return .= '
    '.DOKU_LF; 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 = ''.DOKU_LF; 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.DOKU_LF; } /** * 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 = '
    '; $return .= '
    '.$this->getLang('status').'
    '; $return .= '
    '.$this->make_status($extension).'
    '; if ($extension->getDonationURL()) { $return .= '
    '.$this->getLang('donate').'
    '; $return .= '
    '; $return .= ''; $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 .= '
    '; } if (!$extension->isBundled()) { $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 .= '
    '; } $return .= '
    '.$this->getLang('provides').'
    '; $return .= '
    '; $return .= ($extension->getTypes() ? hsc(implode(', ', $extension->getTypes())) : $default); $return .= '
    '; if(!$extension->isBundled() && $extension->getCompatibleVersions()) { $return .= '
    '.$this->getLang('compatible').'
    '; $return .= '
    '; foreach ($extension->getCompatibleVersions() as $date => $version) { $return .= ''.$version['label'].' ('.$date.'), '; } $return = rtrim($return, ', '); $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 .= '
    '; } $return .= '
    '.DOKU_LF; return $return; } /** * Generate a list of links for extensions * * @param array $ext The extensions * @return string The HTML code */ function make_linklist($ext) { $return = ''; foreach ($ext as $link) { $return .= ''.hsc($link).', '; } return rtrim($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) { global $conf; $return = ''; $errors = ''; if ($extension->isInstalled()) { if (($canmod = $extension->canModify()) === true) { if (!$extension->isProtected()) { $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); } } }else{ $errors .= '

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

    '; } if (!$extension->isProtected() && !$extension->isTemplate()) { // no enable/disable for templates if ($extension->isEnabled()) { $return .= $this->make_action('disable', $extension); } else { $return .= $this->make_action('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').'

    '; } }else{ if (($canmod = $extension->canModify()) === true) { if ($extension->getDownloadURL()) { $return .= $this->make_action('install', $extension); } }else{ $errors .= '
    '.$this->getLang($canmod).'
    '; } } if (!$extension->isInstalled() && $extension->getDownloadURL()) { $return .= ' '.$this->getLang('available_version').' '; $return .= ($extension->getLastUpdate() ? hsc($extension->getLastUpdate()) : $this->getLang('unknown')).''; } return $return.' '.$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 */ function make_action($action, $extension) { $title = ''; switch ($action) { case 'install': case 'reinstall': $title = 'title="'.hsc($extension->getDownloadURL()).'"'; break; } $classes = 'button '.$action; $name = 'fn['.$action.']['.hsc($extension->getID()).']'; return ''; } /** * Plugin/template status * * @param helper_plugin_extension_extension $extension The extension * @return string The description of all relevant statusses */ function make_status(helper_plugin_extension_extension $extension) { $status = array(); 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 join(', ', $status); } }