14fd6a1d7SAndreas Gohr<?php 24fd6a1d7SAndreas Gohr 34fd6a1d7SAndreas Gohrnamespace dokuwiki\plugin\extension; 44fd6a1d7SAndreas Gohr 54fd6a1d7SAndreas Gohrclass GuiExtension extends Gui 64fd6a1d7SAndreas Gohr{ 74fd6a1d7SAndreas Gohr const THUMB_WIDTH = 120; 84fd6a1d7SAndreas Gohr const THUMB_HEIGHT = 70; 94fd6a1d7SAndreas Gohr 104fd6a1d7SAndreas Gohr 114fd6a1d7SAndreas Gohr protected Extension $extension; 124fd6a1d7SAndreas Gohr 134fd6a1d7SAndreas Gohr public function __construct(Extension $extension) 144fd6a1d7SAndreas Gohr { 154fd6a1d7SAndreas Gohr parent::__construct(); 164fd6a1d7SAndreas Gohr $this->extension = $extension; 174fd6a1d7SAndreas Gohr } 184fd6a1d7SAndreas Gohr 194fd6a1d7SAndreas Gohr 204fd6a1d7SAndreas Gohr public function render() 214fd6a1d7SAndreas Gohr { 224fd6a1d7SAndreas Gohr 234fd6a1d7SAndreas Gohr $classes = $this->getClasses(); 244fd6a1d7SAndreas Gohr 254fd6a1d7SAndreas Gohr $html = "<section class=\"$classes\">"; 2620db0ca9SAndreas Gohr 2720db0ca9SAndreas Gohr $html .= '<div class="screenshot">'; 284fd6a1d7SAndreas Gohr $html .= $this->thumbnail(); 29*981e70caSAndreas Gohr $html .= '<span class="id">'. hsc($this->extension->getBase()) .'</span>'; 3020db0ca9SAndreas Gohr $html .= '</div>'; 3120db0ca9SAndreas Gohr 3220db0ca9SAndreas Gohr $html .= '<div class="main">'; 33*981e70caSAndreas Gohr $html .= $this->main(); 3420db0ca9SAndreas Gohr $html .= '</div>'; 3520db0ca9SAndreas Gohr 36*981e70caSAndreas Gohr $html .= '<div class="notices">'; 37*981e70caSAndreas Gohr $html .= $this->notices(); 38*981e70caSAndreas Gohr $html .= '</div>'; 3920db0ca9SAndreas Gohr 4020db0ca9SAndreas Gohr $html .= '<div class="details">'; 414fd6a1d7SAndreas Gohr $html .= $this->details(); 4220db0ca9SAndreas Gohr $html .= '</div>'; 4320db0ca9SAndreas Gohr 44*981e70caSAndreas Gohr $html .= '<div class="actions">'; 4520db0ca9SAndreas Gohr // show the available version if there is one 4620db0ca9SAndreas Gohr if ($this->extension->getDownloadURL() && $this->extension->getLastUpdate()) { 4720db0ca9SAndreas Gohr $html .= ' <div class="version">' . $this->getLang('available_version') . ' ' . 4820db0ca9SAndreas Gohr hsc($this->extension->getLastUpdate()) . '</div>'; 4920db0ca9SAndreas Gohr } 5020db0ca9SAndreas Gohr 514fd6a1d7SAndreas Gohr $html .= $this->actions(); 5220db0ca9SAndreas Gohr $html .= '</div>'; 534fd6a1d7SAndreas Gohr 544fd6a1d7SAndreas Gohr 554fd6a1d7SAndreas Gohr $html .= '</section>'; 564fd6a1d7SAndreas Gohr 574fd6a1d7SAndreas Gohr return $html; 584fd6a1d7SAndreas Gohr } 594fd6a1d7SAndreas Gohr 604fd6a1d7SAndreas Gohr // region sections 614fd6a1d7SAndreas Gohr 624fd6a1d7SAndreas Gohr /** 634fd6a1d7SAndreas Gohr * Get the link and image tag for the screenshot/thumbnail 644fd6a1d7SAndreas Gohr * 654fd6a1d7SAndreas Gohr * @return string The HTML code 664fd6a1d7SAndreas Gohr */ 674fd6a1d7SAndreas Gohr protected function thumbnail() 684fd6a1d7SAndreas Gohr { 694fd6a1d7SAndreas Gohr $screen = $this->extension->getScreenshotURL(); 704fd6a1d7SAndreas Gohr $thumb = $this->extension->getThumbnailURL(); 714fd6a1d7SAndreas Gohr 724fd6a1d7SAndreas Gohr $link = []; 734fd6a1d7SAndreas Gohr $img = [ 744fd6a1d7SAndreas Gohr 'width' => self::THUMB_WIDTH, 754fd6a1d7SAndreas Gohr 'height' => self::THUMB_HEIGHT, 764fd6a1d7SAndreas Gohr 'alt' => '', 774fd6a1d7SAndreas Gohr ]; 784fd6a1d7SAndreas Gohr 794fd6a1d7SAndreas Gohr if ($screen) { 804fd6a1d7SAndreas Gohr $link = [ 814fd6a1d7SAndreas Gohr 'href' => $screen, 824fd6a1d7SAndreas Gohr 'target' => '_blank', 834fd6a1d7SAndreas Gohr 'class' => 'extension_screenshot', 844fd6a1d7SAndreas Gohr 'title' => sprintf($this->getLang('screenshot'), $this->extension->getDisplayName()) 854fd6a1d7SAndreas Gohr ]; 864fd6a1d7SAndreas Gohr 874fd6a1d7SAndreas Gohr $img['src'] = $thumb; 884fd6a1d7SAndreas Gohr $img['alt'] = $link['title']; 894fd6a1d7SAndreas Gohr } elseif ($this->extension->isTemplate()) { 904fd6a1d7SAndreas Gohr $img['src'] = DOKU_BASE . 'lib/plugins/extension/images/template.png'; 914fd6a1d7SAndreas Gohr } else { 924fd6a1d7SAndreas Gohr $img['src'] = DOKU_BASE . 'lib/plugins/extension/images/plugin.png'; 934fd6a1d7SAndreas Gohr } 944fd6a1d7SAndreas Gohr 9520db0ca9SAndreas Gohr $html = ''; 964fd6a1d7SAndreas Gohr if ($link) $html .= '<a ' . buildAttributes($link) . '>'; 974fd6a1d7SAndreas Gohr $html .= '<img ' . buildAttributes($img) . ' />'; 984fd6a1d7SAndreas Gohr if ($link) $html .= '</a>'; 994fd6a1d7SAndreas Gohr 1004fd6a1d7SAndreas Gohr return $html; 1014fd6a1d7SAndreas Gohr 1024fd6a1d7SAndreas Gohr } 1034fd6a1d7SAndreas Gohr 1044fd6a1d7SAndreas Gohr /** 1054fd6a1d7SAndreas Gohr * The main information about the extension 1064fd6a1d7SAndreas Gohr * 1074fd6a1d7SAndreas Gohr * @return string 1084fd6a1d7SAndreas Gohr */ 109*981e70caSAndreas Gohr protected function main() 1104fd6a1d7SAndreas Gohr { 111*981e70caSAndreas Gohr $html = ''; 112*981e70caSAndreas Gohr $html .= '<h2>'; 113*981e70caSAndreas Gohr $html .= '<div>'; 114*981e70caSAndreas Gohr $html .= sprintf($this->getLang('extensionby'), hsc($this->extension->getDisplayName()) . $this->popularity(), $this->author()); 115*981e70caSAndreas Gohr $html .= '</div>'; 1164fd6a1d7SAndreas Gohr 117*981e70caSAndreas Gohr $html .= '<div class="version">'; 118*981e70caSAndreas Gohr if ($this->extension->isBundled()) { 119*981e70caSAndreas Gohr $html .= hsc('<' . $this->getLang('status_bundled') . '>'); 120*981e70caSAndreas Gohr } elseif ($this->extension->getInstalledVersion()) { 121*981e70caSAndreas Gohr $html .= hsc($this->extension->getInstalledVersion()); 122*981e70caSAndreas Gohr } 123*981e70caSAndreas Gohr $html .= '</div>'; 124*981e70caSAndreas Gohr $html .= '</h2>'; 1254fd6a1d7SAndreas Gohr 126*981e70caSAndreas Gohr $html .= '<p>' . hsc($this->extension->getDescription()) . '</p>'; 127*981e70caSAndreas Gohr $html .= $this->mainLinks(); 1284fd6a1d7SAndreas Gohr 1294fd6a1d7SAndreas Gohr return $html; 1304fd6a1d7SAndreas Gohr } 1314fd6a1d7SAndreas Gohr 1324fd6a1d7SAndreas Gohr /** 1334fd6a1d7SAndreas Gohr * Display the available notices for the extension 1344fd6a1d7SAndreas Gohr * 1354fd6a1d7SAndreas Gohr * @return string 1364fd6a1d7SAndreas Gohr */ 1374fd6a1d7SAndreas Gohr protected function notices() 1384fd6a1d7SAndreas Gohr { 1394fd6a1d7SAndreas Gohr $notices = Notice::list($this->extension); 1404fd6a1d7SAndreas Gohr 141*981e70caSAndreas Gohr $html = '<ul>'; 1424fd6a1d7SAndreas Gohr foreach ($notices as $type => $messages) { 1434fd6a1d7SAndreas Gohr foreach ($messages as $message) { 1444fd6a1d7SAndreas Gohr $message = hsc($message); 145*981e70caSAndreas Gohr $message = Notice::ICONS[$type] . ' ' . $message; 1464fd6a1d7SAndreas Gohr $message = preg_replace('/`([^`]+)`/', '<bdi>$1</bdi>', $message); 147*981e70caSAndreas Gohr $html .= '<li class="' . $type . '"><div class="li">' . $message . '</div></li>'; 1484fd6a1d7SAndreas Gohr } 1494fd6a1d7SAndreas Gohr } 150*981e70caSAndreas Gohr $html .= '</ul>'; 1514fd6a1d7SAndreas Gohr return $html; 1524fd6a1d7SAndreas Gohr } 1534fd6a1d7SAndreas Gohr 1544fd6a1d7SAndreas Gohr /** 1554fd6a1d7SAndreas Gohr * Generate the link bar HTML code 1564fd6a1d7SAndreas Gohr * 1574fd6a1d7SAndreas Gohr * @return string The HTML code 1584fd6a1d7SAndreas Gohr */ 1594fd6a1d7SAndreas Gohr public function mainLinks() 1604fd6a1d7SAndreas Gohr { 1614fd6a1d7SAndreas Gohr $html = '<div class="linkbar">'; 1624fd6a1d7SAndreas Gohr 1634fd6a1d7SAndreas Gohr 1644fd6a1d7SAndreas Gohr $homepage = $this->extension->getURL(); 1654fd6a1d7SAndreas Gohr if ($homepage) { 1664fd6a1d7SAndreas Gohr $params = $this->prepareLinkAttributes($homepage, 'homepage'); 1674fd6a1d7SAndreas Gohr $html .= ' <a ' . buildAttributes($params, true) . '>' . $this->getLang('homepage_link') . '</a>'; 1684fd6a1d7SAndreas Gohr } 1694fd6a1d7SAndreas Gohr 1704fd6a1d7SAndreas Gohr $bugtracker = $this->extension->getBugtrackerURL(); 1714fd6a1d7SAndreas Gohr if ($bugtracker) { 1724fd6a1d7SAndreas Gohr $params = $this->prepareLinkAttributes($bugtracker, 'bugs'); 1734fd6a1d7SAndreas Gohr $html .= ' <a ' . buildAttributes($params, true) . '>' . $this->getLang('bugs_features') . '</a>'; 1744fd6a1d7SAndreas Gohr } 1754fd6a1d7SAndreas Gohr 1764fd6a1d7SAndreas Gohr if ($this->extension->getDonationURL()) { 1774fd6a1d7SAndreas Gohr $params = $this->prepareLinkAttributes($this->extension->getDonationURL(), 'donate'); 1784fd6a1d7SAndreas Gohr $html .= ' <a ' . buildAttributes($params, true) . '>' . $this->getLang('donate_action') . '</a>'; 1794fd6a1d7SAndreas Gohr } 1804fd6a1d7SAndreas Gohr 1814fd6a1d7SAndreas Gohr 1824fd6a1d7SAndreas Gohr $html .= '</div>'; 1834fd6a1d7SAndreas Gohr 1844fd6a1d7SAndreas Gohr return $html; 1854fd6a1d7SAndreas Gohr } 1864fd6a1d7SAndreas Gohr 1874fd6a1d7SAndreas Gohr /** 1884fd6a1d7SAndreas Gohr * Create the details section 1894fd6a1d7SAndreas Gohr * 1904fd6a1d7SAndreas Gohr * @return string 1914fd6a1d7SAndreas Gohr */ 1924fd6a1d7SAndreas Gohr protected function details() 1934fd6a1d7SAndreas Gohr { 1944fd6a1d7SAndreas Gohr $html = '<details>'; 195*981e70caSAndreas Gohr $html .= '<summary>' . $this->getLang('details') . '</summary>'; 1964fd6a1d7SAndreas Gohr 1974fd6a1d7SAndreas Gohr 1984fd6a1d7SAndreas Gohr $default = $this->getLang('unknown'); 1994fd6a1d7SAndreas Gohr $list = []; 2004fd6a1d7SAndreas Gohr 2014fd6a1d7SAndreas Gohr if (!$this->extension->isBundled()) { 2024fd6a1d7SAndreas Gohr $list['downloadurl'] = $this->shortlink($this->extension->getDownloadURL(), 'download', $default); 2034fd6a1d7SAndreas Gohr $list['repository'] = $this->shortlink($this->extension->getSourcerepoURL(), 'repo', $default); 2044fd6a1d7SAndreas Gohr } 2054fd6a1d7SAndreas Gohr 2064fd6a1d7SAndreas Gohr if ($this->extension->isInstalled()) { 2074fd6a1d7SAndreas Gohr if ($this->extension->isBundled()) { 2084fd6a1d7SAndreas Gohr $list['installed_version'] = $this->getLang('status_bundled'); 2094fd6a1d7SAndreas Gohr } else { 2104fd6a1d7SAndreas Gohr if ($this->extension->getInstalledVersion()) { 2114fd6a1d7SAndreas Gohr $list['installed_version'] = hsc($this->extension->getInstalledVersion()); 2124fd6a1d7SAndreas Gohr } 2134fd6a1d7SAndreas Gohr if (!$this->extension->isBundled()) { 2144fd6a1d7SAndreas Gohr $updateDate = $this->extension->getManager()->getLastUpdate(); 2154fd6a1d7SAndreas Gohr $list['install_date'] = $updateDate ? hsc($updateDate) : $default; 2164fd6a1d7SAndreas Gohr } 2174fd6a1d7SAndreas Gohr } 2184fd6a1d7SAndreas Gohr } 2194fd6a1d7SAndreas Gohr 2204fd6a1d7SAndreas Gohr if (!$this->extension->isInstalled() || $this->extension->isUpdateAvailable()) { 2214fd6a1d7SAndreas Gohr $list['available_version'] = $this->extension->getLastUpdate() 2224fd6a1d7SAndreas Gohr ? hsc($this->extension->getLastUpdate()) 2234fd6a1d7SAndreas Gohr : $default; 2244fd6a1d7SAndreas Gohr } 2254fd6a1d7SAndreas Gohr 2264fd6a1d7SAndreas Gohr 2274fd6a1d7SAndreas Gohr if (!$this->extension->isBundled() && $this->extension->getCompatibleVersions()) { 2284fd6a1d7SAndreas Gohr $list['compatible'] = join(', ', array_map( 2294fd6a1d7SAndreas Gohr function ($date, $version) { 2304fd6a1d7SAndreas Gohr return '<bdi>' . $version['label'] . ' (' . $date . ')</bdi>'; 2314fd6a1d7SAndreas Gohr }, 2324fd6a1d7SAndreas Gohr array_keys($this->extension->getCompatibleVersions()), 2334fd6a1d7SAndreas Gohr array_values($this->extension->getCompatibleVersions()) 2344fd6a1d7SAndreas Gohr )); 2354fd6a1d7SAndreas Gohr } 2364fd6a1d7SAndreas Gohr 2374fd6a1d7SAndreas Gohr $tags = $this->extension->getTags(); 2384fd6a1d7SAndreas Gohr if ($tags) { 2394fd6a1d7SAndreas Gohr $list['tags'] = join(', ', array_map(function ($tag) { 2404fd6a1d7SAndreas Gohr $url = $this->tabURL('search', ['q' => 'tag:' . $tag]); 2414fd6a1d7SAndreas Gohr return '<bdi><a href="' . $url . '">' . hsc($tag) . '</a></bdi>'; 2424fd6a1d7SAndreas Gohr }, $tags)); 2434fd6a1d7SAndreas Gohr } 2444fd6a1d7SAndreas Gohr 2454fd6a1d7SAndreas Gohr if ($this->extension->getDependencyList()) { 2464fd6a1d7SAndreas Gohr $list['depends'] = $this->linkExtensions($this->extension->getDependencyList()); 2474fd6a1d7SAndreas Gohr } 2484fd6a1d7SAndreas Gohr 2494fd6a1d7SAndreas Gohr if ($this->extension->getSimilarList()) { 2504fd6a1d7SAndreas Gohr $list['similar'] = $this->linkExtensions($this->extension->getSimilarList()); 2514fd6a1d7SAndreas Gohr } 2524fd6a1d7SAndreas Gohr 2534fd6a1d7SAndreas Gohr if ($this->extension->getConflictList()) { 2544fd6a1d7SAndreas Gohr $list['conflicts'] = $this->linkExtensions($this->extension->getConflictList()); 2554fd6a1d7SAndreas Gohr } 2564fd6a1d7SAndreas Gohr 25720db0ca9SAndreas Gohr $html .= '<dl>'; 2584fd6a1d7SAndreas Gohr foreach ($list as $key => $value) { 2594fd6a1d7SAndreas Gohr $html .= '<dt>' . $this->getLang($key) . '</dt>'; 2604fd6a1d7SAndreas Gohr $html .= '<dd>' . $value . '</dd>'; 2614fd6a1d7SAndreas Gohr } 26220db0ca9SAndreas Gohr $html .= '</dl>'; 2634fd6a1d7SAndreas Gohr 2644fd6a1d7SAndreas Gohr $html .= '</details>'; 2654fd6a1d7SAndreas Gohr return $html; 2664fd6a1d7SAndreas Gohr } 2674fd6a1d7SAndreas Gohr 2684fd6a1d7SAndreas Gohr /** 2694fd6a1d7SAndreas Gohr * Generate a link to the author of the extension 2704fd6a1d7SAndreas Gohr * 2714fd6a1d7SAndreas Gohr * @return string The HTML code of the link 2724fd6a1d7SAndreas Gohr */ 2734fd6a1d7SAndreas Gohr protected function author() 2744fd6a1d7SAndreas Gohr { 2754fd6a1d7SAndreas Gohr if (!$this->extension->getAuthor()) { 2764fd6a1d7SAndreas Gohr return '<em class="author">' . $this->getLang('unknown_author') . '</em>'; 2774fd6a1d7SAndreas Gohr } 2784fd6a1d7SAndreas Gohr 279*981e70caSAndreas Gohr $names = explode(',', $this->extension->getAuthor()); 280*981e70caSAndreas Gohr $names = array_map('trim', $names); 281*981e70caSAndreas Gohr if (count($names) > 2) { 282*981e70caSAndreas Gohr $names = array_slice($names, 0, 2); 283*981e70caSAndreas Gohr $names[] = '…'; 284*981e70caSAndreas Gohr } 285*981e70caSAndreas Gohr $name = join(', ', $names); 286*981e70caSAndreas Gohr 2874fd6a1d7SAndreas Gohr $mailid = $this->extension->getEmailID(); 2884fd6a1d7SAndreas Gohr if ($mailid) { 2894fd6a1d7SAndreas Gohr $url = $this->tabURL('search', ['q' => 'authorid:' . $mailid]); 2904fd6a1d7SAndreas Gohr $html = '<a href="' . $url . '" class="author" title="' . $this->getLang('author_hint') . '" >' . 2914fd6a1d7SAndreas Gohr '<img src="//www.gravatar.com/avatar/' . $mailid . 2924fd6a1d7SAndreas Gohr '?s=60&d=mm" width="20" height="20" alt="" /> ' . 293*981e70caSAndreas Gohr hsc($name) . '</a>'; 2944fd6a1d7SAndreas Gohr } else { 2954fd6a1d7SAndreas Gohr $html = '<span class="author">' . hsc($this->extension->getAuthor()) . '</span>'; 2964fd6a1d7SAndreas Gohr } 2974fd6a1d7SAndreas Gohr return '<bdi>' . $html . '</bdi>'; 2984fd6a1d7SAndreas Gohr } 2994fd6a1d7SAndreas Gohr 3004fd6a1d7SAndreas Gohr /** 3014fd6a1d7SAndreas Gohr * The popularity bar 3024fd6a1d7SAndreas Gohr * 3034fd6a1d7SAndreas Gohr * @return string 3044fd6a1d7SAndreas Gohr */ 3054fd6a1d7SAndreas Gohr protected function popularity() 3064fd6a1d7SAndreas Gohr { 3074fd6a1d7SAndreas Gohr $popularity = $this->extension->getPopularity(); 3084fd6a1d7SAndreas Gohr if (!$popularity) return ''; 3094fd6a1d7SAndreas Gohr if ($this->extension->isBundled()) return ''; 3104fd6a1d7SAndreas Gohr 311*981e70caSAndreas Gohr if ($popularity > 0.25) { 312*981e70caSAndreas Gohr $title = $this->getLang('popularity_high'); 313*981e70caSAndreas Gohr $emoji = ''; 314*981e70caSAndreas Gohr } else if ($popularity > 0.15) { 315*981e70caSAndreas Gohr $title = $this->getLang('popularity_medium'); 316*981e70caSAndreas Gohr $emoji = ''; 317*981e70caSAndreas Gohr } else if ($popularity > 0.05) { 318*981e70caSAndreas Gohr $title = $this->getLang('popularity_low'); 319*981e70caSAndreas Gohr $emoji = ''; 320*981e70caSAndreas Gohr } else { 321*981e70caSAndreas Gohr return ''; 322*981e70caSAndreas Gohr } 323*981e70caSAndreas Gohr $title .= ' (' . round($popularity * 100) . '%)'; 324*981e70caSAndreas Gohr 325*981e70caSAndreas Gohr return '<span class="popularity" title="' . $title . '">' . $emoji . '</span>'; 3264fd6a1d7SAndreas Gohr 3274fd6a1d7SAndreas Gohr } 3284fd6a1d7SAndreas Gohr 3294fd6a1d7SAndreas Gohr protected function actions() 3304fd6a1d7SAndreas Gohr { 3314fd6a1d7SAndreas Gohr global $conf; 3324fd6a1d7SAndreas Gohr 3334fd6a1d7SAndreas Gohr $html = ''; 3344fd6a1d7SAndreas Gohr $actions = []; 3354fd6a1d7SAndreas Gohr $errors = []; 3364fd6a1d7SAndreas Gohr 3374fd6a1d7SAndreas Gohr // gather available actions and possible errors to show 3384fd6a1d7SAndreas Gohr try { 3394fd6a1d7SAndreas Gohr Installer::ensurePermissions($this->extension); 3404fd6a1d7SAndreas Gohr 3414fd6a1d7SAndreas Gohr if ($this->extension->isInstalled()) { 3424fd6a1d7SAndreas Gohr 3434fd6a1d7SAndreas Gohr if (!$this->extension->isProtected()) $actions[] = 'uninstall'; 3444fd6a1d7SAndreas Gohr if ($this->extension->getDownloadURL()) { 3454fd6a1d7SAndreas Gohr $actions[] = $this->extension->isUpdateAvailable() ? 'update' : 'reinstall'; 3464fd6a1d7SAndreas Gohr } 3474fd6a1d7SAndreas Gohr 3484fd6a1d7SAndreas Gohr if (!$this->extension->isProtected() && !$this->extension->isTemplate()) { // no enable/disable for templates 3494fd6a1d7SAndreas Gohr $actions[] = $this->extension->isEnabled() ? 'disable' : 'enable'; 3504fd6a1d7SAndreas Gohr } 3514fd6a1d7SAndreas Gohr } else { 3524fd6a1d7SAndreas Gohr if ($this->extension->getDownloadURL()) { 3534fd6a1d7SAndreas Gohr $actions[] = 'install'; 3544fd6a1d7SAndreas Gohr } 3554fd6a1d7SAndreas Gohr } 3564fd6a1d7SAndreas Gohr } catch (\Exception $e) { 3574fd6a1d7SAndreas Gohr } 3584fd6a1d7SAndreas Gohr 3594fd6a1d7SAndreas Gohr foreach ($actions as $action) { 3604fd6a1d7SAndreas Gohr $html .= '<button name="fn[' . $action . '][' . $this->extension->getID() . ']" class="button" type="submit">' . 3614fd6a1d7SAndreas Gohr $this->getLang('btn_' . $action) . '</button>'; 3624fd6a1d7SAndreas Gohr } 3634fd6a1d7SAndreas Gohr 3644fd6a1d7SAndreas Gohr foreach ($errors as $error) { 3654fd6a1d7SAndreas Gohr $html .= '<div class="msg error">' . hsc($error) . '</div>'; 3664fd6a1d7SAndreas Gohr } 3674fd6a1d7SAndreas Gohr 3684fd6a1d7SAndreas Gohr return $html; 3694fd6a1d7SAndreas Gohr } 3704fd6a1d7SAndreas Gohr 3714fd6a1d7SAndreas Gohr 3724fd6a1d7SAndreas Gohr // endregion 3734fd6a1d7SAndreas Gohr // region utility functions 3744fd6a1d7SAndreas Gohr 3754fd6a1d7SAndreas Gohr /** 3764fd6a1d7SAndreas Gohr * Create the classes representing the state of the extension 3774fd6a1d7SAndreas Gohr * 3784fd6a1d7SAndreas Gohr * @return string 3794fd6a1d7SAndreas Gohr */ 3804fd6a1d7SAndreas Gohr protected function getClasses() 3814fd6a1d7SAndreas Gohr { 3824fd6a1d7SAndreas Gohr $classes = ['extension', $this->extension->getType()]; 3834fd6a1d7SAndreas Gohr if ($this->extension->isInstalled()) $classes[] = 'installed'; 3844fd6a1d7SAndreas Gohr if ($this->extension->isUpdateAvailable()) $classes[] = 'update'; 3854fd6a1d7SAndreas Gohr $classes[] = $this->extension->isEnabled() ? 'enabled' : 'disabled'; 3864fd6a1d7SAndreas Gohr return implode(' ', $classes); 3874fd6a1d7SAndreas Gohr } 3884fd6a1d7SAndreas Gohr 3894fd6a1d7SAndreas Gohr /** 3904fd6a1d7SAndreas Gohr * Create an attributes array for a link 3914fd6a1d7SAndreas Gohr * 3924fd6a1d7SAndreas Gohr * Handles interwiki links to dokuwiki.org 3934fd6a1d7SAndreas Gohr * 3944fd6a1d7SAndreas Gohr * @param string $url The URL to link to 3954fd6a1d7SAndreas Gohr * @param string $class Additional classes to add 3964fd6a1d7SAndreas Gohr * @return array 3974fd6a1d7SAndreas Gohr */ 3984fd6a1d7SAndreas Gohr protected function prepareLinkAttributes($url, $class) 3994fd6a1d7SAndreas Gohr { 4004fd6a1d7SAndreas Gohr global $conf; 4014fd6a1d7SAndreas Gohr 4024fd6a1d7SAndreas Gohr $attributes = [ 4034fd6a1d7SAndreas Gohr 'href' => $url, 4044fd6a1d7SAndreas Gohr 'class' => 'urlextern', 4054fd6a1d7SAndreas Gohr 'target' => $conf['target']['extern'], 4064fd6a1d7SAndreas Gohr 'rel' => 'noopener', 4074fd6a1d7SAndreas Gohr 'title' => $url, 4084fd6a1d7SAndreas Gohr ]; 4094fd6a1d7SAndreas Gohr 4104fd6a1d7SAndreas Gohr if ($conf['relnofollow']) { 4114fd6a1d7SAndreas Gohr $attributes['rel'] .= ' ugc nofollow'; 4124fd6a1d7SAndreas Gohr } 4134fd6a1d7SAndreas Gohr 4144fd6a1d7SAndreas Gohr if (preg_match('/^https?:\/\/(www\.)?dokuwiki\.org\//i', $url)) { 4154fd6a1d7SAndreas Gohr $attributes['class'] = 'interwiki iw_doku'; 4164fd6a1d7SAndreas Gohr $attributes['target'] = $conf['target']['interwiki']; 4174fd6a1d7SAndreas Gohr $attributes['rel'] = ''; 4184fd6a1d7SAndreas Gohr } 4194fd6a1d7SAndreas Gohr 4204fd6a1d7SAndreas Gohr $attributes['class'] .= ' ' . $class; 4214fd6a1d7SAndreas Gohr return $attributes; 4224fd6a1d7SAndreas Gohr } 4234fd6a1d7SAndreas Gohr 4244fd6a1d7SAndreas Gohr /** 4254fd6a1d7SAndreas Gohr * Create a link from the given URL 4264fd6a1d7SAndreas Gohr * 4274fd6a1d7SAndreas Gohr * Shortens the URL for display 4284fd6a1d7SAndreas Gohr * 4294fd6a1d7SAndreas Gohr * @param string $url 4304fd6a1d7SAndreas Gohr * @param string $class Additional classes to add 4314fd6a1d7SAndreas Gohr * @param string $fallback If URL is empty return this fallback 4324fd6a1d7SAndreas Gohr * @return string HTML link 4334fd6a1d7SAndreas Gohr */ 4344fd6a1d7SAndreas Gohr protected function shortlink($url, $class, $fallback = '') 4354fd6a1d7SAndreas Gohr { 4364fd6a1d7SAndreas Gohr if (!$url) return hsc($fallback); 4374fd6a1d7SAndreas Gohr 4384fd6a1d7SAndreas Gohr $link = parse_url($url); 4394fd6a1d7SAndreas Gohr $base = $link['host']; 4404fd6a1d7SAndreas Gohr if (!empty($link['port'])) $base .= $base . ':' . $link['port']; 4414fd6a1d7SAndreas Gohr $long = $link['path']; 4424fd6a1d7SAndreas Gohr if (!empty($link['query'])) $long .= $link['query']; 4434fd6a1d7SAndreas Gohr 4444fd6a1d7SAndreas Gohr $name = shorten($base, $long, 55); 4454fd6a1d7SAndreas Gohr 4464fd6a1d7SAndreas Gohr $params = $this->prepareLinkAttributes($url, $class); 4474fd6a1d7SAndreas Gohr $html = '<a ' . buildAttributes($params, true) . '>' . hsc($name) . '</a>'; 4484fd6a1d7SAndreas Gohr return $html; 4494fd6a1d7SAndreas Gohr } 4504fd6a1d7SAndreas Gohr 4514fd6a1d7SAndreas Gohr /** 4524fd6a1d7SAndreas Gohr * Generate a list of links for extensions 4534fd6a1d7SAndreas Gohr * 4544fd6a1d7SAndreas Gohr * Links to the search tab with the extension name 4554fd6a1d7SAndreas Gohr * 4564fd6a1d7SAndreas Gohr * @param array $extensions The extension names 4574fd6a1d7SAndreas Gohr * @return string The HTML code 4584fd6a1d7SAndreas Gohr */ 4594fd6a1d7SAndreas Gohr public function linkExtensions($extensions) 4604fd6a1d7SAndreas Gohr { 4614fd6a1d7SAndreas Gohr $html = ''; 4624fd6a1d7SAndreas Gohr foreach ($extensions as $link) { 4634fd6a1d7SAndreas Gohr $html .= '<bdi><a href="' . 4644fd6a1d7SAndreas Gohr $this->tabURL('search', ['q' => 'ext:' . $link]) . '">' . 4654fd6a1d7SAndreas Gohr hsc($link) . '</a></bdi>, '; 4664fd6a1d7SAndreas Gohr } 4674fd6a1d7SAndreas Gohr return rtrim($html, ', '); 4684fd6a1d7SAndreas Gohr } 4694fd6a1d7SAndreas Gohr 4704fd6a1d7SAndreas Gohr // endregion 4714fd6a1d7SAndreas Gohr} 472