1<?php 2/** 3 * This is the Dokuwiki export for FINDOLOGIC. 4 * 5 * If any bugs occur, please submit a new issue 6 * @see https://github.com/findologic/dokuwiki-plugin-findologic-xml-export/issues/new 7 * @author Dominik Brader <support@findologic.com> 8 */ 9 10if (!defined('DOKU_INC')) { 11 die('Must be run within DokuWiki!'); 12} 13 14require_once(__DIR__ . '/vendor/autoload.php'); 15require_once(__DIR__ . '/PageGetter.php'); 16require_once(__DIR__ . '/DokuwikiPage.php'); 17 18class admin_plugin_findologicxmlexport extends DokuWiki_Admin_Plugin 19{ 20 21 // Names 22 const EDIT_IMAGE_URL_NAME = 'editImageUrl'; 23 const PAGES_NAME = 'pages'; 24 const EXPORT_URL_NAME = 'exportUrl'; 25 const STYLESHEET_URL_NAME = 'stylesheetUrl'; 26 const SCRIPT_URL_NAME = 'scriptUrl'; 27 const MAX_PAGES_NAME = 'maxPages'; 28 const TOTAL_PAGES_NAME = 'totalPages'; 29 const LANGUAGE_NAME = 'languageText'; 30 const PAGES_SKIPPED_NAME = 'pagesSkipped'; 31 const INFORMATION_IMAGE_URL_NAME = 'informationImageUrl'; 32 const DOKUWIKI_LANG_NAME = 'lang'; 33 34 // Values 35 const EDIT_IMAGE_URL = DOKU_URL . 'lib/plugins/findologicxmlexport/resources/edit.svg'; 36 const EXPORT_URL = DOKU_URL . 'lib/plugins/findologicxmlexport'; 37 const STYLESHEET_URL = DOKU_URL . 'lib/plugins/findologicxmlexport/resources/style.css'; 38 const SCRIPT_URL = DOKU_URL . 'lib/plugins/findologicxmlexport/resources/script.js'; 39 const INFORMATION_IMAGE_URL = DOKU_URL . 'lib/styles/../images/info.png'; 40 /** 41 * Maximum amount of pages being displayed in the configuration. 42 */ 43 const MAX_PAGES = 5; 44 45 /** 46 * * **true** => You do not to be superuser to access this plugin. 47 * * **false** => You do need to be superuser to access this plugin. 48 */ 49 const ADMINS_ONLY = true; 50 51 /** 52 * Sort plugin in the DokuWiki admin interface. 53 * The lower this value is, the higher it is sorted. 54 */ 55 const MENU_SORT = 1; 56 57 const TEMPLATE_DIR = __DIR__ . '/tpl'; 58 59 /** 60 * Template file name. Directory is set in constant TEMPLATE_DIR. 61 */ 62 const TEMPLATE_FILE = 'admin.twig'; 63 64 /** 65 * @return int sorting of the plugin in the plugin manager. 66 */ 67 public function getMenuSort() 68 { 69 return self::MENU_SORT; 70 } 71 72 /** 73 * * **true** => You do not to be superuser to access this plugin. 74 * * **false** => You do need to be superuser to access this plugin. 75 * 76 * @return bool See method description. 77 * 78 */ 79 public function forAdminOnly() 80 { 81 return self::ADMINS_ONLY; 82 } 83 84 /** 85 * HTML output (gets generated by twig). 86 */ 87 public function html() 88 { 89 // Needs to be called once to initialize $this->lang. 90 $this->setupLocale(); 91 92 $pagesWithoutTitle = [self::PAGES_NAME => PageGetter::getPagesWithoutTitle()]; 93 $totalPages = count($pagesWithoutTitle[self::PAGES_NAME]); 94 95 $variables = [ 96 self::EDIT_IMAGE_URL_NAME => self::EDIT_IMAGE_URL, 97 self::EXPORT_URL_NAME => self::EXPORT_URL, 98 self::STYLESHEET_URL_NAME => self::STYLESHEET_URL, 99 self::SCRIPT_URL_NAME => self::SCRIPT_URL, 100 self::INFORMATION_IMAGE_URL_NAME => self::INFORMATION_IMAGE_URL, 101 self::MAX_PAGES_NAME => self::MAX_PAGES, 102 self::TOTAL_PAGES_NAME => $totalPages, 103 self::LANGUAGE_NAME => $this->lang, 104 self::PAGES_SKIPPED_NAME => ($totalPages - self::MAX_PAGES) 105 ]; 106 107 $variablesForTemplate = array_merge($pagesWithoutTitle, $variables); 108 109 // Set locale according to DokuWiki configuration 110 global $conf; 111 Locale::setDefault($conf[self::DOKUWIKI_LANG_NAME]); 112 113 // Set up loader and environment for twig. 114 $loader = new Twig_Loader_Filesystem(self::TEMPLATE_DIR); 115 $twig = new Twig_Environment($loader); 116 117 $twig->addExtension(new Twig_Extensions_Extension_Intl()); 118 119 echo $twig->render(self::TEMPLATE_FILE, $variablesForTemplate); 120 } 121 122 123 /** 124 * @codeCoverageIgnore Ignored since this method is implemented, but does 125 * nothing. 126 */ 127 public function handle() 128 { 129 // Implements the function. Nothing to do here. 130 } 131} 132