[2147] | 1 | <?php |
---|
[2215] | 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
| 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
| 7 | # Licensed under the GPL version 2.0 license. |
---|
| 8 | # See LICENSE file or |
---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 10 | # |
---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
| 12 | if (!defined('DC_ADMIN_CONTEXT')) { return; } |
---|
[2147] | 13 | |
---|
[2227] | 14 | /** |
---|
| 15 | * @ingroup DC_CORE |
---|
| 16 | * @brief Helper for admin list of modules. |
---|
| 17 | * @since 2.6 |
---|
| 18 | |
---|
| 19 | * Provides an object to parse XML feed of modules from a repository. |
---|
| 20 | */ |
---|
[2147] | 21 | class adminModulesList |
---|
| 22 | { |
---|
[2227] | 23 | public $core; /**< @var object dcCore instance */ |
---|
| 24 | public $modules; /**< @var object dcModules instance */ |
---|
| 25 | public $store; /**< @var object dcStore instance */ |
---|
[2147] | 26 | |
---|
[2227] | 27 | public static $allow_multi_install = false; /**< @var boolean Work with multiple root directories */ |
---|
| 28 | public static $distributed_modules = array(); /**< @var array List of modules distributed with Dotclear */ |
---|
[2149] | 29 | |
---|
[2227] | 30 | protected $list_id = 'unknow'; /**< @var string Current list ID */ |
---|
| 31 | protected $data = array(); /**< @var array Current modules */ |
---|
[2156] | 32 | |
---|
[2227] | 33 | protected $config_module = ''; /**< @var string Module ID to configure */ |
---|
| 34 | protected $config_file = ''; /**< @var string Module path to configure */ |
---|
| 35 | protected $config_content = ''; /**< @var string Module configuration page content */ |
---|
[2182] | 36 | |
---|
[2227] | 37 | protected $path = false; /**< @var string Modules root directory */ |
---|
| 38 | protected $path_writable = false; /**< @var boolean Indicate if modules root directory is writable */ |
---|
| 39 | protected $path_pattern = false; /**< @var string Directory pattern to work on */ |
---|
[2149] | 40 | |
---|
[2227] | 41 | protected $page_url = 'plugins.php'; /**< @var string Page URL */ |
---|
| 42 | protected $page_qs = '?'; /**< @var string Page query string */ |
---|
| 43 | protected $page_tab = ''; /**< @var string Page tab */ |
---|
[2259] | 44 | protected $page_redir = ''; /**< @var string Page redirection */ |
---|
[2147] | 45 | |
---|
[2227] | 46 | public static $nav_indexes = 'abcdefghijklmnopqrstuvwxyz0123456789'; /**< @var string Index list */ |
---|
| 47 | protected $nav_list = array(); /**< @var array Index list with special index */ |
---|
| 48 | protected $nav_special = 'other'; /**< @var string Text for other special index */ |
---|
[2147] | 49 | |
---|
[2227] | 50 | protected $sort_field = 'sname'; /**< @var string Field used to sort modules */ |
---|
| 51 | protected $sort_asc = true; /**< @var boolean Sort order asc */ |
---|
[2147] | 52 | |
---|
[2227] | 53 | /** |
---|
| 54 | * Constructor. |
---|
| 55 | * |
---|
| 56 | * Note that this creates dcStore instance. |
---|
| 57 | * |
---|
| 58 | * @param object $modules dcModules instance |
---|
| 59 | * @param string $modules_root Modules root directories |
---|
| 60 | * @param string $xml_url URL of modules feed from repository |
---|
| 61 | */ |
---|
[2215] | 62 | public function __construct(dcModules $modules, $modules_root, $xml_url) |
---|
[2147] | 63 | { |
---|
[2215] | 64 | $this->core = $modules->core; |
---|
| 65 | $this->modules = $modules; |
---|
[2216] | 66 | $this->store = new dcStore($modules, $xml_url); |
---|
[2215] | 67 | |
---|
[2227] | 68 | $this->setPath($modules_root); |
---|
| 69 | $this->setIndex(__('other')); |
---|
[2147] | 70 | } |
---|
| 71 | |
---|
[2227] | 72 | /** |
---|
| 73 | * Begin a new list. |
---|
| 74 | * |
---|
| 75 | * @param string $id New list ID |
---|
| 76 | * @return adminModulesList self instance |
---|
| 77 | */ |
---|
[2241] | 78 | public function setList($id) |
---|
[2156] | 79 | { |
---|
[2215] | 80 | $this->data = array(); |
---|
[2156] | 81 | $this->page_tab = ''; |
---|
[2227] | 82 | $this->list_id = $id; |
---|
[2156] | 83 | |
---|
| 84 | return $this; |
---|
| 85 | } |
---|
| 86 | |
---|
[2241] | 87 | /** |
---|
| 88 | * Get list ID. |
---|
| 89 | * |
---|
| 90 | * @return List ID |
---|
| 91 | */ |
---|
| 92 | public function getList() |
---|
| 93 | { |
---|
| 94 | return $this->list_id; |
---|
| 95 | } |
---|
| 96 | |
---|
[2227] | 97 | /// @name Modules root directory methods |
---|
| 98 | //@{ |
---|
| 99 | /** |
---|
| 100 | * Set path info. |
---|
| 101 | * |
---|
| 102 | * @param string $root Modules root directories |
---|
| 103 | * @return adminModulesList self instance |
---|
| 104 | */ |
---|
| 105 | protected function setPath($root) |
---|
[2149] | 106 | { |
---|
| 107 | $paths = explode(PATH_SEPARATOR, $root); |
---|
| 108 | $path = array_pop($paths); |
---|
| 109 | unset($paths); |
---|
| 110 | |
---|
| 111 | $this->path = $path; |
---|
| 112 | if (is_dir($path) && is_writeable($path)) { |
---|
| 113 | $this->path_writable = true; |
---|
| 114 | $this->path_pattern = preg_quote($path,'!'); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | return $this; |
---|
| 118 | } |
---|
| 119 | |
---|
[2227] | 120 | /** |
---|
| 121 | * Get modules root directory. |
---|
| 122 | * |
---|
| 123 | * @return Path to work on |
---|
| 124 | */ |
---|
[2149] | 125 | public function getPath() |
---|
| 126 | { |
---|
| 127 | return $this->path; |
---|
| 128 | } |
---|
| 129 | |
---|
[2227] | 130 | /** |
---|
| 131 | * Check if modules root directory is writable. |
---|
| 132 | * |
---|
| 133 | * @return True if directory is writable |
---|
| 134 | */ |
---|
| 135 | public function isWritablePath() |
---|
[2149] | 136 | { |
---|
| 137 | return $this->path_writable; |
---|
| 138 | } |
---|
| 139 | |
---|
[2227] | 140 | /** |
---|
| 141 | * Check if root directory of a module is deletable. |
---|
| 142 | * |
---|
| 143 | * @param string $root Module root directory |
---|
| 144 | * @return True if directory is delatable |
---|
| 145 | */ |
---|
| 146 | public function isDeletablePath($root) |
---|
[2149] | 147 | { |
---|
| 148 | return $this->path_writable |
---|
[2241] | 149 | && (preg_match('!^'.$this->path_pattern.'!', $root) || defined('DC_DEV') && DC_DEV) |
---|
[2149] | 150 | && $this->core->auth->isSuperAdmin(); |
---|
| 151 | } |
---|
[2227] | 152 | //@} |
---|
[2149] | 153 | |
---|
[2227] | 154 | /// @name Page methods |
---|
| 155 | //@{ |
---|
| 156 | /** |
---|
| 157 | * Set page base URL. |
---|
| 158 | * |
---|
| 159 | * @param string $url Page base URL |
---|
| 160 | * @return adminModulesList self instance |
---|
| 161 | */ |
---|
| 162 | public function setURL($url) |
---|
[2147] | 163 | { |
---|
[2327] | 164 | $this->page_qs = strpos('?', $url) ? '&' : '?'; |
---|
[2147] | 165 | $this->page_url = $url; |
---|
| 166 | |
---|
| 167 | return $this; |
---|
| 168 | } |
---|
| 169 | |
---|
[2227] | 170 | /** |
---|
| 171 | * Get page URL. |
---|
| 172 | * |
---|
| 173 | * @param string|array $queries Additionnal query string |
---|
| 174 | * @param booleany $with_tab Add current tab to URL end |
---|
| 175 | * @return Clean page URL |
---|
| 176 | */ |
---|
| 177 | public function getURL($queries='', $with_tab=true) |
---|
[2147] | 178 | { |
---|
| 179 | return $this->page_url. |
---|
[2149] | 180 | (!empty($queries) ? $this->page_qs : ''). |
---|
[2147] | 181 | (is_array($queries) ? http_build_query($queries) : $queries). |
---|
[2149] | 182 | ($with_tab && !empty($this->page_tab) ? '#'.$this->page_tab : ''); |
---|
[2147] | 183 | } |
---|
| 184 | |
---|
[2227] | 185 | /** |
---|
| 186 | * Set page tab. |
---|
| 187 | * |
---|
| 188 | * @param string $tab Page tab |
---|
| 189 | * @return adminModulesList self instance |
---|
| 190 | */ |
---|
| 191 | public function setTab($tab) |
---|
[2147] | 192 | { |
---|
| 193 | $this->page_tab = $tab; |
---|
| 194 | |
---|
| 195 | return $this; |
---|
| 196 | } |
---|
| 197 | |
---|
[2227] | 198 | /** |
---|
| 199 | * Get page tab. |
---|
| 200 | * |
---|
| 201 | * @return Page tab |
---|
| 202 | */ |
---|
| 203 | public function getTab() |
---|
[2147] | 204 | { |
---|
| 205 | return $this->page_tab; |
---|
| 206 | } |
---|
[2259] | 207 | |
---|
| 208 | /** |
---|
| 209 | * Set page redirection. |
---|
| 210 | * |
---|
| 211 | * @param string $default Default redirection |
---|
| 212 | * @return adminModulesList self instance |
---|
| 213 | */ |
---|
| 214 | public function setRedir($default='') |
---|
| 215 | { |
---|
| 216 | $this->page_redir = empty($_REQUEST['redir']) ? $default : $_REQUEST['redir']; |
---|
| 217 | |
---|
| 218 | return $this; |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | /** |
---|
| 222 | * Get page redirection. |
---|
| 223 | * |
---|
| 224 | * @return Page redirection |
---|
| 225 | */ |
---|
| 226 | public function getRedir() |
---|
| 227 | { |
---|
| 228 | return empty($this->page_redir) ? $this->getURL() : $this->page_redir; |
---|
| 229 | } |
---|
[2227] | 230 | //@} |
---|
[2147] | 231 | |
---|
[2227] | 232 | /// @name Search methods |
---|
| 233 | //@{ |
---|
| 234 | /** |
---|
| 235 | * Get search query. |
---|
| 236 | * |
---|
| 237 | * @return Search query |
---|
| 238 | */ |
---|
| 239 | public function getSearch() |
---|
[2147] | 240 | { |
---|
| 241 | $query = !empty($_REQUEST['m_search']) ? trim($_REQUEST['m_search']) : null; |
---|
[2227] | 242 | return strlen($query) > 2 ? $query : null; |
---|
[2147] | 243 | } |
---|
| 244 | |
---|
[2227] | 245 | /** |
---|
| 246 | * Display searh form. |
---|
| 247 | * |
---|
| 248 | * @return adminModulesList self instance |
---|
| 249 | */ |
---|
| 250 | public function displaySearch() |
---|
[2147] | 251 | { |
---|
[2227] | 252 | $query = $this->getSearch(); |
---|
[2163] | 253 | |
---|
[2215] | 254 | if (empty($this->data) && $query === null) { |
---|
[2147] | 255 | return $this; |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | echo |
---|
[2287] | 259 | '<div class="modules-search">'. |
---|
[2291] | 260 | '<form action="'.$this->getURL().'" method="get">'. |
---|
[2157] | 261 | '<p><label for="m_search" class="classic">'.__('Search in repository:').' </label><br />'. |
---|
| 262 | form::field(array('m_search','m_search'), 30, 255, html::escapeHTML($query)). |
---|
[2291] | 263 | '<input type="submit" value="'.__('OK').'" /> '; |
---|
[2287] | 264 | |
---|
| 265 | if ($query) { |
---|
| 266 | echo |
---|
| 267 | ' <a href="'.$this->getURL().'" class="button">'.__('Reset search').'</a>'; |
---|
| 268 | } |
---|
| 269 | |
---|
| 270 | echo |
---|
| 271 | '</p>'. |
---|
| 272 | '<p class="form-note">'. |
---|
| 273 | __('Search is allowed on multiple terms longer than 2 chars, terms must be separated by space.'). |
---|
| 274 | '</p>'. |
---|
[2158] | 275 | '</form>'; |
---|
[2147] | 276 | |
---|
| 277 | if ($query) { |
---|
| 278 | echo |
---|
[2158] | 279 | '<p class="message">'.sprintf( |
---|
[2215] | 280 | __('Found %d result for search "%s":', 'Found %d results for search "%s":', count($this->data)), |
---|
| 281 | count($this->data), html::escapeHTML($query) |
---|
[2158] | 282 | ). |
---|
[2147] | 283 | '</p>'; |
---|
| 284 | } |
---|
[2287] | 285 | echo '</div>'; |
---|
| 286 | |
---|
[2147] | 287 | return $this; |
---|
| 288 | } |
---|
[2227] | 289 | //@} |
---|
[2147] | 290 | |
---|
[2227] | 291 | /// @name Navigation menu methods |
---|
| 292 | //@{ |
---|
| 293 | /** |
---|
| 294 | * Set navigation special index. |
---|
| 295 | * |
---|
| 296 | * @return adminModulesList self instance |
---|
| 297 | */ |
---|
| 298 | public function setIndex($str) |
---|
[2147] | 299 | { |
---|
| 300 | $this->nav_special = (string) $str; |
---|
| 301 | $this->nav_list = array_merge(str_split(self::$nav_indexes), array($this->nav_special)); |
---|
| 302 | |
---|
| 303 | return $this; |
---|
| 304 | } |
---|
| 305 | |
---|
[2227] | 306 | /** |
---|
| 307 | * Get index from query. |
---|
| 308 | * |
---|
| 309 | * @return Query index or default one |
---|
| 310 | */ |
---|
| 311 | public function getIndex() |
---|
[2147] | 312 | { |
---|
| 313 | return isset($_REQUEST['m_nav']) && in_array($_REQUEST['m_nav'], $this->nav_list) ? $_REQUEST['m_nav'] : $this->nav_list[0]; |
---|
| 314 | } |
---|
| 315 | |
---|
[2227] | 316 | /** |
---|
| 317 | * Display navigation by index menu. |
---|
| 318 | * |
---|
| 319 | * @return adminModulesList self instance |
---|
| 320 | */ |
---|
| 321 | public function displayIndex() |
---|
[2147] | 322 | { |
---|
[2227] | 323 | if (empty($this->data) || $this->getSearch() !== null) { |
---|
[2147] | 324 | return $this; |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | # Fetch modules required field |
---|
| 328 | $indexes = array(); |
---|
[2215] | 329 | foreach ($this->data as $id => $module) { |
---|
[2147] | 330 | if (!isset($module[$this->sort_field])) { |
---|
| 331 | continue; |
---|
| 332 | } |
---|
| 333 | $char = substr($module[$this->sort_field], 0, 1); |
---|
| 334 | if (!in_array($char, $this->nav_list)) { |
---|
| 335 | $char = $this->nav_special; |
---|
| 336 | } |
---|
| 337 | if (!isset($indexes[$char])) { |
---|
| 338 | $indexes[$char] = 0; |
---|
| 339 | } |
---|
| 340 | $indexes[$char]++; |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | $buttons = array(); |
---|
| 344 | foreach($this->nav_list as $char) { |
---|
| 345 | # Selected letter |
---|
[2227] | 346 | if ($this->getIndex() == $char) { |
---|
[2147] | 347 | $buttons[] = '<li class="active" title="'.__('current selection').'"><strong> '.$char.' </strong></li>'; |
---|
| 348 | } |
---|
| 349 | # Letter having modules |
---|
| 350 | elseif (!empty($indexes[$char])) { |
---|
| 351 | $title = sprintf(__('%d module', '%d modules', $indexes[$char]), $indexes[$char]); |
---|
[2227] | 352 | $buttons[] = '<li class="btn" title="'.$title.'"><a href="'.$this->getURL('m_nav='.$char).'" title="'.$title.'"> '.$char.' </a></li>'; |
---|
[2147] | 353 | } |
---|
| 354 | # Letter without modules |
---|
| 355 | else { |
---|
| 356 | $buttons[] = '<li class="btn no-link" title="'.__('no module').'"> '.$char.' </li>'; |
---|
| 357 | } |
---|
| 358 | } |
---|
| 359 | # Parse navigation menu |
---|
[2291] | 360 | echo '<div class="pager">'.__('Browse index:').' <ul class="index">'.implode('',$buttons).'</ul></div>'; |
---|
[2147] | 361 | |
---|
| 362 | return $this; |
---|
| 363 | } |
---|
[2227] | 364 | //@} |
---|
[2147] | 365 | |
---|
[2227] | 366 | /// @name Sort methods |
---|
| 367 | //@{ |
---|
| 368 | /** |
---|
| 369 | * Set default sort field. |
---|
| 370 | * |
---|
| 371 | * @return adminModulesList self instance |
---|
| 372 | */ |
---|
| 373 | public function setSort($field, $asc=true) |
---|
[2147] | 374 | { |
---|
| 375 | $this->sort_field = $field; |
---|
| 376 | $this->sort_asc = (boolean) $asc; |
---|
| 377 | |
---|
| 378 | return $this; |
---|
| 379 | } |
---|
| 380 | |
---|
[2227] | 381 | /** |
---|
| 382 | * Get sort field from query. |
---|
| 383 | * |
---|
| 384 | * @return Query sort field or default one |
---|
| 385 | */ |
---|
| 386 | public function getSort() |
---|
[2147] | 387 | { |
---|
| 388 | return !empty($_REQUEST['m_sort']) ? $_REQUEST['m_sort'] : $this->sort_field; |
---|
| 389 | } |
---|
| 390 | |
---|
[2227] | 391 | /** |
---|
| 392 | * Display sort field form. |
---|
| 393 | * |
---|
| 394 | * @note This method is not implemented yet |
---|
| 395 | * @return adminModulesList self instance |
---|
| 396 | */ |
---|
| 397 | public function displaySort() |
---|
[2147] | 398 | { |
---|
[2227] | 399 | // |
---|
| 400 | |
---|
| 401 | return $this; |
---|
[2147] | 402 | } |
---|
[2227] | 403 | //@} |
---|
[2147] | 404 | |
---|
[2227] | 405 | /// @name Modules methods |
---|
| 406 | //@{ |
---|
| 407 | /** |
---|
| 408 | * Set modules and sanitize them. |
---|
| 409 | * |
---|
| 410 | * @return adminModulesList self instance |
---|
| 411 | */ |
---|
[2147] | 412 | public function setModules($modules) |
---|
| 413 | { |
---|
[2215] | 414 | $this->data = array(); |
---|
[2174] | 415 | if (!empty($modules) && is_array($modules)) { |
---|
| 416 | foreach($modules as $id => $module) { |
---|
[2227] | 417 | $this->data[$id] = self::sanitizeModule($id, $module); |
---|
[2174] | 418 | } |
---|
[2147] | 419 | } |
---|
| 420 | return $this; |
---|
| 421 | } |
---|
| 422 | |
---|
[2227] | 423 | /** |
---|
| 424 | * Get modules currently set. |
---|
| 425 | * |
---|
| 426 | * @return Array of modules |
---|
| 427 | */ |
---|
[2147] | 428 | public function getModules() |
---|
| 429 | { |
---|
[2215] | 430 | return $this->data; |
---|
[2147] | 431 | } |
---|
| 432 | |
---|
[2227] | 433 | /** |
---|
| 434 | * Sanitize a module. |
---|
| 435 | * |
---|
| 436 | * This clean infos of a module by adding default keys |
---|
| 437 | * and clean some of them, sanitize module can safely |
---|
| 438 | * be used in lists. |
---|
| 439 | * |
---|
| 440 | * @return Array of the module informations |
---|
| 441 | */ |
---|
| 442 | public static function sanitizeModule($id, $module) |
---|
[2147] | 443 | { |
---|
| 444 | $label = empty($module['label']) ? $id : $module['label']; |
---|
| 445 | $name = __(empty($module['name']) ? $label : $module['name']); |
---|
| 446 | |
---|
| 447 | return array_merge( |
---|
| 448 | # Default values |
---|
| 449 | array( |
---|
| 450 | 'desc' => '', |
---|
| 451 | 'author' => '', |
---|
| 452 | 'version' => 0, |
---|
| 453 | 'current_version' => 0, |
---|
| 454 | 'root' => '', |
---|
| 455 | 'root_writable' => false, |
---|
| 456 | 'permissions' => null, |
---|
| 457 | 'parent' => null, |
---|
| 458 | 'priority' => 1000, |
---|
[2156] | 459 | 'standalone_config' => false, |
---|
| 460 | 'support' => '', |
---|
| 461 | 'section' => '', |
---|
| 462 | 'tags' => '', |
---|
[2171] | 463 | 'details' => '', |
---|
[2222] | 464 | 'sshot' => '', |
---|
[2287] | 465 | 'score' => 0, |
---|
| 466 | 'type' => null |
---|
[2147] | 467 | ), |
---|
| 468 | # Module's values |
---|
| 469 | $module, |
---|
| 470 | # Clean up values |
---|
| 471 | array( |
---|
| 472 | 'id' => $id, |
---|
| 473 | 'sid' => self::sanitizeString($id), |
---|
| 474 | 'label' => $label, |
---|
| 475 | 'name' => $name, |
---|
| 476 | 'sname' => self::sanitizeString($name) |
---|
| 477 | ) |
---|
| 478 | ); |
---|
| 479 | } |
---|
| 480 | |
---|
[2227] | 481 | /** |
---|
| 482 | * Check if a module is part of the distribution. |
---|
| 483 | * |
---|
| 484 | * @param string $id Module root directory |
---|
| 485 | * @return True if module is part of the distribution |
---|
| 486 | */ |
---|
| 487 | public static function isDistributedModule($id) |
---|
[2148] | 488 | { |
---|
[2171] | 489 | $distributed_modules = self::$distributed_modules; |
---|
| 490 | |
---|
[2227] | 491 | return is_array($distributed_modules) && in_array($id, $distributed_modules); |
---|
[2148] | 492 | } |
---|
| 493 | |
---|
[2227] | 494 | /** |
---|
| 495 | * Sort modules list by specific field. |
---|
| 496 | * |
---|
| 497 | * @param string $module Array of modules |
---|
| 498 | * @param string $field Field to sort from |
---|
| 499 | * @param bollean $asc Sort asc if true, else decs |
---|
| 500 | * @return Array of sorted modules |
---|
| 501 | */ |
---|
[2147] | 502 | public static function sortModules($modules, $field, $asc=true) |
---|
| 503 | { |
---|
| 504 | $sorter = array(); |
---|
| 505 | foreach($modules as $id => $module) { |
---|
| 506 | $sorter[$id] = isset($module[$field]) ? $module[$field] : $field; |
---|
| 507 | } |
---|
| 508 | array_multisort($sorter, $asc ? SORT_ASC : SORT_DESC, $modules); |
---|
| 509 | |
---|
| 510 | return $modules; |
---|
| 511 | } |
---|
| 512 | |
---|
[2227] | 513 | /** |
---|
| 514 | * Display list of modules. |
---|
| 515 | * |
---|
| 516 | * @param array $cols List of colones (module field) to display |
---|
| 517 | * @param array $actions List of predefined actions to show on form |
---|
| 518 | * @param boolean $nav_limit Limit list to previously selected index |
---|
| 519 | * @return adminModulesList self instance |
---|
| 520 | */ |
---|
| 521 | public function displayModules($cols=array('name', 'version', 'desc'), $actions=array(), $nav_limit=false) |
---|
[2147] | 522 | { |
---|
| 523 | echo |
---|
| 524 | '<div class="table-outer">'. |
---|
[2156] | 525 | '<table id="'.html::escapeHTML($this->list_id).'" class="modules'.(in_array('expander', $cols) ? ' expandable' : '').'">'. |
---|
| 526 | '<caption class="hidden">'.html::escapeHTML(__('Modules list')).'</caption><tr>'; |
---|
[2163] | 527 | |
---|
[2147] | 528 | if (in_array('name', $cols)) { |
---|
| 529 | echo |
---|
[2149] | 530 | '<th class="first nowrap"'.(in_array('icon', $cols) ? ' colspan="2"' : '').'>'.__('Name').'</th>'; |
---|
[2147] | 531 | } |
---|
| 532 | |
---|
[2227] | 533 | if (in_array('score', $cols) && $this->getSearch() !== null && defined('DC_DEBUG') && DC_DEBUG) { |
---|
[2222] | 534 | echo |
---|
| 535 | '<th class="nowrap">'.__('Score').'</th>'; |
---|
| 536 | } |
---|
| 537 | |
---|
[2147] | 538 | if (in_array('version', $cols)) { |
---|
| 539 | echo |
---|
| 540 | '<th class="nowrap count" scope="col">'.__('Version').'</th>'; |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | if (in_array('current_version', $cols)) { |
---|
| 544 | echo |
---|
| 545 | '<th class="nowrap count" scope="col">'.__('Current version').'</th>'; |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | if (in_array('desc', $cols)) { |
---|
| 549 | echo |
---|
| 550 | '<th class="nowrap" scope="col">'.__('Details').'</th>'; |
---|
| 551 | } |
---|
| 552 | |
---|
[2149] | 553 | if (in_array('distrib', $cols)) { |
---|
| 554 | echo '<th'.(in_array('desc', $cols) ? '' : ' class="maximal"').'></th>'; |
---|
| 555 | } |
---|
| 556 | |
---|
[2147] | 557 | if (!empty($actions) && $this->core->auth->isSuperAdmin()) { |
---|
| 558 | echo |
---|
| 559 | '<th class="minimal nowrap">'.__('Action').'</th>'; |
---|
| 560 | } |
---|
| 561 | |
---|
| 562 | echo |
---|
| 563 | '</tr>'; |
---|
| 564 | |
---|
[2227] | 565 | $sort_field = $this->getSort(); |
---|
[2147] | 566 | |
---|
[2215] | 567 | # Sort modules by $sort_field (default sname) |
---|
[2227] | 568 | $modules = $this->getSearch() === null ? |
---|
[2215] | 569 | self::sortModules($this->data, $sort_field, $this->sort_asc) : |
---|
| 570 | $this->data; |
---|
[2147] | 571 | |
---|
| 572 | $count = 0; |
---|
| 573 | foreach ($modules as $id => $module) |
---|
| 574 | { |
---|
| 575 | # Show only requested modules |
---|
[2227] | 576 | if ($nav_limit && $this->getSearch() === null) { |
---|
[2147] | 577 | $char = substr($module[$sort_field], 0, 1); |
---|
| 578 | if (!in_array($char, $this->nav_list)) { |
---|
| 579 | $char = $this->nav_special; |
---|
| 580 | } |
---|
[2227] | 581 | if ($this->getIndex() != $char) { |
---|
[2147] | 582 | continue; |
---|
| 583 | } |
---|
| 584 | } |
---|
| 585 | |
---|
| 586 | echo |
---|
[2171] | 587 | '<tr class="line" id="'.html::escapeHTML($this->list_id).'_m_'.html::escapeHTML($id).'">'; |
---|
[2163] | 588 | |
---|
[2156] | 589 | if (in_array('icon', $cols)) { |
---|
| 590 | echo |
---|
[2171] | 591 | '<td class="module-icon nowrap">'.sprintf( |
---|
[2156] | 592 | '<img alt="%1$s" title="%1$s" src="%2$s" />', |
---|
| 593 | html::escapeHTML($id), file_exists($module['root'].'/icon.png') ? 'index.php?pf='.$id.'/icon.png' : 'images/module.png' |
---|
| 594 | ).'</td>'; |
---|
| 595 | } |
---|
| 596 | |
---|
[2147] | 597 | # Link to config file |
---|
| 598 | $config = in_array('config', $cols) && !empty($module['root']) && file_exists(path::real($module['root'].'/_config.php')); |
---|
| 599 | |
---|
| 600 | echo |
---|
[2171] | 601 | '<td class="module-name nowrap" scope="row">'.($config ? |
---|
[2327] | 602 | '<a href="'.$this->getURL('module='.$id.'&conf=1').'" title"'.sprintf(__('Configure module "%s"'), html::escapeHTML($module['name'])).'">'.html::escapeHTML($module['name']).'</a>' : |
---|
[2149] | 603 | html::escapeHTML($module['name']) |
---|
[2147] | 604 | ).'</td>'; |
---|
| 605 | |
---|
[2222] | 606 | # Display score only for debug purpose |
---|
[2227] | 607 | if (in_array('score', $cols) && $this->getSearch() !== null && defined('DC_DEBUG') && DC_DEBUG) { |
---|
[2222] | 608 | echo |
---|
| 609 | '<td class="module-version nowrap count"><span class="debug">'.$module['score'].'</span></td>'; |
---|
| 610 | } |
---|
| 611 | |
---|
[2147] | 612 | if (in_array('version', $cols)) { |
---|
| 613 | echo |
---|
[2171] | 614 | '<td class="module-version nowrap count">'.html::escapeHTML($module['version']).'</td>'; |
---|
[2147] | 615 | } |
---|
| 616 | |
---|
[2148] | 617 | if (in_array('current_version', $cols)) { |
---|
[2147] | 618 | echo |
---|
[2171] | 619 | '<td class="module-current-version nowrap count">'.html::escapeHTML($module['current_version']).'</td>'; |
---|
[2147] | 620 | } |
---|
| 621 | |
---|
| 622 | if (in_array('desc', $cols)) { |
---|
| 623 | echo |
---|
[2171] | 624 | '<td class="module-desc maximal">'.html::escapeHTML($module['desc']).'</td>'; |
---|
[2149] | 625 | } |
---|
| 626 | |
---|
| 627 | if (in_array('distrib', $cols)) { |
---|
| 628 | echo |
---|
[2171] | 629 | '<td class="module-distrib">'.(self::isDistributedModule($id) ? |
---|
[2149] | 630 | '<img src="images/dotclear_pw.png" alt="'. |
---|
| 631 | __('Module from official distribution').'" title="'. |
---|
| 632 | __('module from official distribution').'" />' |
---|
| 633 | : '').'</td>'; |
---|
[2147] | 634 | } |
---|
| 635 | |
---|
| 636 | if (!empty($actions) && $this->core->auth->isSuperAdmin()) { |
---|
[2215] | 637 | $buttons = $this->getActions($id, $module, $actions); |
---|
| 638 | |
---|
[2147] | 639 | echo |
---|
[2215] | 640 | '<td class="module-actions nowrap">'. |
---|
[2147] | 641 | |
---|
[2227] | 642 | '<form action="'.$this->getURL().'" method="post">'. |
---|
[2215] | 643 | '<div>'. |
---|
| 644 | $this->core->formNonce(). |
---|
| 645 | form::hidden(array('module'), html::escapeHTML($id)). |
---|
[2147] | 646 | |
---|
[2215] | 647 | implode(' ', $buttons). |
---|
| 648 | |
---|
| 649 | '</div>'. |
---|
| 650 | '</form>'. |
---|
| 651 | |
---|
[2147] | 652 | '</td>'; |
---|
| 653 | } |
---|
| 654 | |
---|
| 655 | echo |
---|
| 656 | '</tr>'; |
---|
| 657 | |
---|
| 658 | $count++; |
---|
| 659 | } |
---|
| 660 | echo |
---|
| 661 | '</table></div>'; |
---|
| 662 | |
---|
[2227] | 663 | if(!$count && $this->getSearch() === null) { |
---|
[2147] | 664 | echo |
---|
[2158] | 665 | '<p class="message">'.__('No module matches your search.').'</p>'; |
---|
[2147] | 666 | } |
---|
[2227] | 667 | |
---|
| 668 | return $this; |
---|
[2147] | 669 | } |
---|
| 670 | |
---|
[2227] | 671 | /** |
---|
| 672 | * Get action buttons to add to modules list. |
---|
| 673 | * |
---|
| 674 | * @param string $id Module ID |
---|
| 675 | * @param array $module Module info |
---|
| 676 | * @param array $actions Actions keys |
---|
| 677 | * @return Array of actions buttons |
---|
| 678 | */ |
---|
[2215] | 679 | protected function getActions($id, $module, $actions) |
---|
[2147] | 680 | { |
---|
| 681 | $submits = array(); |
---|
| 682 | |
---|
[2215] | 683 | # Use loop to keep requested order |
---|
| 684 | foreach($actions as $action) { |
---|
| 685 | switch($action) { |
---|
| 686 | |
---|
| 687 | # Deactivate |
---|
| 688 | case 'activate': if ($module['root_writable']) { |
---|
| 689 | $submits[] = |
---|
| 690 | '<input type="submit" name="activate" value="'.__('Activate').'" />'; |
---|
| 691 | } break; |
---|
| 692 | |
---|
| 693 | # Activate |
---|
| 694 | case 'deactivate': if ($module['root_writable']) { |
---|
| 695 | $submits[] = |
---|
| 696 | '<input type="submit" name="deactivate" value="'.__('Deactivate').'" class="reset" />'; |
---|
| 697 | } break; |
---|
| 698 | |
---|
| 699 | # Delete |
---|
[2227] | 700 | case 'delete': if ($this->isDeletablePath($module['root'])) { |
---|
[2241] | 701 | $dev = !preg_match('!^'.$this->path_pattern.'!', $module['root']) && defined('DC_DEV') && DC_DEV ? ' debug' : ''; |
---|
[2215] | 702 | $submits[] = |
---|
[2241] | 703 | '<input type="submit" class="delete '.$dev.'" name="delete" value="'.__('Delete').'" />'; |
---|
[2215] | 704 | } break; |
---|
| 705 | |
---|
[2216] | 706 | # Install (from store) |
---|
[2215] | 707 | case 'install': if ($this->path_writable) { |
---|
| 708 | $submits[] = |
---|
| 709 | '<input type="submit" name="install" value="'.__('Install').'" />'; |
---|
| 710 | } break; |
---|
| 711 | |
---|
[2216] | 712 | # Update (from store) |
---|
[2215] | 713 | case 'update': if ($this->path_writable) { |
---|
| 714 | $submits[] = |
---|
| 715 | '<input type="submit" name="update" value="'.__('Update').'" />'; |
---|
| 716 | } break; |
---|
[2241] | 717 | |
---|
| 718 | # Behavior |
---|
| 719 | case 'behavior': |
---|
| 720 | |
---|
| 721 | # --BEHAVIOR-- adminModulesListGetActions |
---|
| 722 | $tmp = $this->core->callBehavior('adminModulesListGetActions', $this, $id, $module); |
---|
| 723 | |
---|
| 724 | if (!empty($tmp)) { |
---|
| 725 | $submits[] = $tmp; |
---|
| 726 | } |
---|
| 727 | break; |
---|
[2215] | 728 | } |
---|
[2192] | 729 | } |
---|
| 730 | |
---|
[2241] | 731 | |
---|
[2215] | 732 | return $submits; |
---|
[2147] | 733 | } |
---|
| 734 | |
---|
[2227] | 735 | /** |
---|
| 736 | * Execute POST action. |
---|
| 737 | * |
---|
| 738 | * @note Set a notice on success through dcPage::addSuccessNotice |
---|
| 739 | * @throw Exception Module not find or command failed |
---|
| 740 | * @param string $prefix Prefix used on behaviors |
---|
| 741 | * @return Null |
---|
| 742 | */ |
---|
[2215] | 743 | public function doActions($prefix) |
---|
[2192] | 744 | { |
---|
[2215] | 745 | if (empty($_POST) || !empty($_REQUEST['conf']) |
---|
[2227] | 746 | || !$this->core->auth->isSuperAdmin() || !$this->isWritablePath()) { |
---|
[2149] | 747 | return null; |
---|
| 748 | } |
---|
| 749 | |
---|
[2171] | 750 | # List actions |
---|
| 751 | if (!empty($_POST['module'])) { |
---|
[2149] | 752 | |
---|
[2171] | 753 | $id = $_POST['module']; |
---|
[2149] | 754 | |
---|
[2171] | 755 | if (!empty($_POST['activate'])) { |
---|
| 756 | |
---|
[2215] | 757 | $enabled = $this->modules->getDisabledModules(); |
---|
[2171] | 758 | if (!isset($enabled[$id])) { |
---|
| 759 | throw new Exception(__('No such module.')); |
---|
| 760 | } |
---|
| 761 | |
---|
| 762 | # --BEHAVIOR-- moduleBeforeActivate |
---|
[2192] | 763 | $this->core->callBehavior($prefix.'BeforeActivate', $id); |
---|
[2171] | 764 | |
---|
[2215] | 765 | $this->modules->activateModule($id); |
---|
[2171] | 766 | |
---|
| 767 | # --BEHAVIOR-- moduleAfterActivate |
---|
[2192] | 768 | $this->core->callBehavior($prefix.'AfterActivate', $id); |
---|
[2171] | 769 | |
---|
[2219] | 770 | dcPage::addSuccessNotice(__('Module has been successfully activated.')); |
---|
[2227] | 771 | http::redirect($this->getURL()); |
---|
[2149] | 772 | } |
---|
| 773 | |
---|
[2192] | 774 | elseif (!empty($_POST['deactivate'])) { |
---|
[2149] | 775 | |
---|
[2215] | 776 | if (!$this->modules->moduleExists($id)) { |
---|
[2149] | 777 | throw new Exception(__('No such module.')); |
---|
| 778 | } |
---|
| 779 | |
---|
[2215] | 780 | $module = $this->modules->getModules($id); |
---|
[2149] | 781 | $module['id'] = $id; |
---|
| 782 | |
---|
[2171] | 783 | if (!$module['root_writable']) { |
---|
| 784 | throw new Exception(__('You don\'t have permissions to deactivate this module.')); |
---|
[2149] | 785 | } |
---|
| 786 | |
---|
[2171] | 787 | # --BEHAVIOR-- moduleBeforeDeactivate |
---|
| 788 | $this->core->callBehavior($prefix.'BeforeDeactivate', $module); |
---|
[2149] | 789 | |
---|
[2215] | 790 | $this->modules->deactivateModule($id); |
---|
[2149] | 791 | |
---|
[2171] | 792 | # --BEHAVIOR-- moduleAfterDeactivate |
---|
| 793 | $this->core->callBehavior($prefix.'AfterDeactivate', $module); |
---|
| 794 | |
---|
[2219] | 795 | dcPage::addSuccessNotice(__('Module has been successfully deactivated.')); |
---|
[2227] | 796 | http::redirect($this->getURL()); |
---|
[2171] | 797 | } |
---|
| 798 | |
---|
[2192] | 799 | elseif (!empty($_POST['delete'])) { |
---|
[2171] | 800 | |
---|
[2215] | 801 | $disabled = $this->modules->getDisabledModules(); |
---|
[2171] | 802 | if (!isset($disabled[$id])) { |
---|
| 803 | |
---|
[2215] | 804 | if (!$this->modules->moduleExists($id)) { |
---|
[2171] | 805 | throw new Exception(__('No such module.')); |
---|
| 806 | } |
---|
| 807 | |
---|
[2215] | 808 | $module = $this->modules->getModules($id); |
---|
[2171] | 809 | $module['id'] = $id; |
---|
| 810 | |
---|
[2227] | 811 | if (!$this->isDeletablePath($module['root'])) { |
---|
[2171] | 812 | throw new Exception(__("You don't have permissions to delete this module.")); |
---|
| 813 | } |
---|
| 814 | |
---|
| 815 | # --BEHAVIOR-- moduleBeforeDelete |
---|
| 816 | $this->core->callBehavior($prefix.'BeforeDelete', $module); |
---|
| 817 | |
---|
[2215] | 818 | $this->modules->deleteModule($id); |
---|
[2171] | 819 | |
---|
| 820 | # --BEHAVIOR-- moduleAfterDelete |
---|
| 821 | $this->core->callBehavior($prefix.'AfterDelete', $module); |
---|
| 822 | } |
---|
| 823 | else { |
---|
[2215] | 824 | $this->modules->deleteModule($id, true); |
---|
[2171] | 825 | } |
---|
| 826 | |
---|
[2219] | 827 | dcPage::addSuccessNotice(__('Module has been successfully deleted.')); |
---|
[2227] | 828 | http::redirect($this->getURL()); |
---|
[2171] | 829 | } |
---|
| 830 | |
---|
[2215] | 831 | elseif (!empty($_POST['install'])) { |
---|
| 832 | |
---|
[2216] | 833 | $updated = $this->store->get(); |
---|
[2215] | 834 | if (!isset($updated[$id])) { |
---|
| 835 | throw new Exception(__('No such module.')); |
---|
| 836 | } |
---|
| 837 | |
---|
| 838 | $module = $updated[$id]; |
---|
| 839 | $module['id'] = $id; |
---|
| 840 | |
---|
| 841 | $dest = $this->getPath().'/'.basename($module['file']); |
---|
| 842 | |
---|
| 843 | # --BEHAVIOR-- moduleBeforeAdd |
---|
| 844 | $this->core->callBehavior($prefix.'BeforeAdd', $module); |
---|
| 845 | |
---|
[2216] | 846 | $ret_code = $this->store->process($module['file'], $dest); |
---|
[2215] | 847 | |
---|
| 848 | # --BEHAVIOR-- moduleAfterAdd |
---|
| 849 | $this->core->callBehavior($prefix.'AfterAdd', $module); |
---|
| 850 | |
---|
[2219] | 851 | dcPage::addSuccessNotice($ret_code == 2 ? |
---|
| 852 | __('Module has been successfully updated.') : |
---|
| 853 | __('Module has been successfully installed.') |
---|
| 854 | ); |
---|
[2227] | 855 | http::redirect($this->getURL()); |
---|
[2215] | 856 | } |
---|
| 857 | |
---|
[2192] | 858 | elseif (!empty($_POST['update'])) { |
---|
[2171] | 859 | |
---|
[2269] | 860 | $updated = $this->store->get(true); |
---|
[2171] | 861 | if (!isset($updated[$id])) { |
---|
| 862 | throw new Exception(__('No such module.')); |
---|
| 863 | } |
---|
| 864 | |
---|
[2215] | 865 | if (!$this->modules->moduleExists($id)) { |
---|
[2171] | 866 | throw new Exception(__('No such module.')); |
---|
| 867 | } |
---|
| 868 | |
---|
[2270] | 869 | $tab = count($updated) > 1 ? '' : '#'.$prefix; |
---|
| 870 | |
---|
[2171] | 871 | $module = $updated[$id]; |
---|
| 872 | $module['id'] = $id; |
---|
[2227] | 873 | |
---|
[2171] | 874 | if (!self::$allow_multi_install) { |
---|
| 875 | $dest = $module['root'].'/../'.basename($module['file']); |
---|
| 876 | } |
---|
| 877 | else { |
---|
| 878 | $dest = $this->getPath().'/'.basename($module['file']); |
---|
| 879 | if ($module['root'] != $dest) { |
---|
| 880 | @file_put_contents($module['root'].'/_disabled', ''); |
---|
| 881 | } |
---|
| 882 | } |
---|
| 883 | |
---|
| 884 | # --BEHAVIOR-- moduleBeforeUpdate |
---|
[2192] | 885 | $this->core->callBehavior($prefix.'BeforeUpdate', $module); |
---|
[2171] | 886 | |
---|
[2216] | 887 | $this->store->process($module['file'], $dest); |
---|
[2171] | 888 | |
---|
| 889 | # --BEHAVIOR-- moduleAfterUpdate |
---|
[2192] | 890 | $this->core->callBehavior($prefix.'AfterUpdate', $module); |
---|
[2171] | 891 | |
---|
[2219] | 892 | dcPage::addSuccessNotice(__('Module has been successfully updated.')); |
---|
[2270] | 893 | http::redirect($this->getURL().$tab); |
---|
[2171] | 894 | } |
---|
[2241] | 895 | else { |
---|
| 896 | |
---|
| 897 | # --BEHAVIOR-- adminModulesListDoActions |
---|
| 898 | $this->core->callBehavior('adminModulesListDoActions', $this, $id, $prefix); |
---|
| 899 | |
---|
| 900 | } |
---|
[2171] | 901 | } |
---|
| 902 | # Manual actions |
---|
| 903 | elseif (!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file']) |
---|
| 904 | || !empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url'])) |
---|
| 905 | { |
---|
| 906 | if (empty($_POST['your_pwd']) || !$this->core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY, $_POST['your_pwd']))) { |
---|
| 907 | throw new Exception(__('Password verification failed')); |
---|
| 908 | } |
---|
| 909 | |
---|
| 910 | if (!empty($_POST['upload_pkg'])) { |
---|
| 911 | files::uploadStatus($_FILES['pkg_file']); |
---|
| 912 | |
---|
| 913 | $dest = $this->getPath().'/'.$_FILES['pkg_file']['name']; |
---|
| 914 | if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'], $dest)) { |
---|
| 915 | throw new Exception(__('Unable to move uploaded file.')); |
---|
| 916 | } |
---|
[2149] | 917 | } |
---|
| 918 | else { |
---|
[2171] | 919 | $url = urldecode($_POST['pkg_url']); |
---|
| 920 | $dest = $this->getPath().'/'.basename($url); |
---|
[2216] | 921 | $this->store->download($url, $dest); |
---|
[2149] | 922 | } |
---|
| 923 | |
---|
[2171] | 924 | # --BEHAVIOR-- moduleBeforeAdd |
---|
| 925 | $this->core->callBehavior($prefix.'BeforeAdd', null); |
---|
| 926 | |
---|
[2216] | 927 | $ret_code = $this->store->install($dest); |
---|
[2171] | 928 | |
---|
| 929 | # --BEHAVIOR-- moduleAfterAdd |
---|
| 930 | $this->core->callBehavior($prefix.'AfterAdd', null); |
---|
| 931 | |
---|
[2219] | 932 | dcPage::addSuccessNotice($ret_code == 2 ? |
---|
| 933 | __('Module has been successfully updated.') : |
---|
| 934 | __('Module has been successfully installed.') |
---|
| 935 | ); |
---|
[2227] | 936 | http::redirect($this->getURL().'#'.$prefix); |
---|
[2171] | 937 | } |
---|
[2192] | 938 | |
---|
[2171] | 939 | return null; |
---|
| 940 | } |
---|
| 941 | |
---|
[2227] | 942 | /** |
---|
| 943 | * Display tab for manual installation. |
---|
| 944 | * |
---|
| 945 | * @return adminModulesList self instance |
---|
| 946 | */ |
---|
[2171] | 947 | public function displayManualForm() |
---|
| 948 | { |
---|
[2227] | 949 | if (!$this->core->auth->isSuperAdmin() || !$this->isWritablePath()) { |
---|
[2171] | 950 | return null; |
---|
[2149] | 951 | } |
---|
| 952 | |
---|
[2171] | 953 | # 'Upload module' form |
---|
| 954 | echo |
---|
[2227] | 955 | '<form method="post" action="'.$this->getURL().'" id="uploadpkg" enctype="multipart/form-data" class="fieldset">'. |
---|
[2171] | 956 | '<h4>'.__('Upload a zip file').'</h4>'. |
---|
| 957 | '<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Zip file path:').'</label> '. |
---|
| 958 | '<input type="file" name="pkg_file" id="pkg_file" /></p>'. |
---|
| 959 | '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '. |
---|
| 960 | form::password(array('your_pwd','your_pwd1'),20,255).'</p>'. |
---|
| 961 | '<p><input type="submit" name="upload_pkg" value="'.__('Upload').'" />'. |
---|
| 962 | $this->core->formNonce().'</p>'. |
---|
| 963 | '</form>'; |
---|
[2227] | 964 | |
---|
[2171] | 965 | # 'Fetch module' form |
---|
| 966 | echo |
---|
[2227] | 967 | '<form method="post" action="'.$this->getURL().'" id="fetchpkg" class="fieldset">'. |
---|
[2171] | 968 | '<h4>'.__('Download a zip file').'</h4>'. |
---|
| 969 | '<p class="field"><label for="pkg_url" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Zip file URL:').'</label> '. |
---|
| 970 | form::field(array('pkg_url','pkg_url'),40,255).'</p>'. |
---|
| 971 | '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '. |
---|
| 972 | form::password(array('your_pwd','your_pwd2'),20,255).'</p>'. |
---|
| 973 | '<p><input type="submit" name="fetch_pkg" value="'.__('Download').'" />'. |
---|
| 974 | $this->core->formNonce().'</p>'. |
---|
| 975 | '</form>'; |
---|
[2227] | 976 | |
---|
| 977 | return $this; |
---|
[2149] | 978 | } |
---|
[2227] | 979 | //@} |
---|
[2149] | 980 | |
---|
[2227] | 981 | /// @name Module configuration methods |
---|
| 982 | //@{ |
---|
[2182] | 983 | /** |
---|
[2227] | 984 | * Prepare module configuration. |
---|
[2182] | 985 | * |
---|
| 986 | * We need to get configuration content in three steps |
---|
| 987 | * and out of this class to keep backward compatibility. |
---|
| 988 | * |
---|
[2227] | 989 | * if ($xxx->setConfiguration()) { |
---|
| 990 | * include $xxx->includeConfiguration(); |
---|
[2182] | 991 | * } |
---|
[2227] | 992 | * $xxx->getConfiguration(); |
---|
[2182] | 993 | * ... [put here page headers and other stuff] |
---|
[2227] | 994 | * $xxx->displayConfiguration(); |
---|
[2182] | 995 | * |
---|
[2227] | 996 | * @param string $id Module to work on or it gather through REQUEST |
---|
| 997 | * @return True if config set |
---|
[2182] | 998 | */ |
---|
[2227] | 999 | public function setConfiguration($id=null) |
---|
[2182] | 1000 | { |
---|
| 1001 | if (empty($_REQUEST['conf']) || empty($_REQUEST['module']) && !$id) { |
---|
| 1002 | return false; |
---|
| 1003 | } |
---|
| 1004 | |
---|
| 1005 | if (!empty($_REQUEST['module']) && empty($id)) { |
---|
| 1006 | $id = $_REQUEST['module']; |
---|
| 1007 | } |
---|
| 1008 | |
---|
[2215] | 1009 | if (!$this->modules->moduleExists($id)) { |
---|
[2288] | 1010 | $this->core->error->add(__('Unknow module ID')); |
---|
[2182] | 1011 | return false; |
---|
| 1012 | } |
---|
| 1013 | |
---|
[2215] | 1014 | $module = $this->modules->getModules($id); |
---|
[2227] | 1015 | $module = self::sanitizeModule($id, $module); |
---|
[2182] | 1016 | $file = path::real($module['root'].'/_config.php'); |
---|
| 1017 | |
---|
| 1018 | if (!file_exists($file)) { |
---|
[2288] | 1019 | $this->core->error->add(__('This module has no configuration file.')); |
---|
[2182] | 1020 | return false; |
---|
| 1021 | } |
---|
| 1022 | |
---|
| 1023 | $this->config_module = $module; |
---|
| 1024 | $this->config_file = $file; |
---|
| 1025 | $this->config_content = ''; |
---|
| 1026 | |
---|
| 1027 | if (!defined('DC_CONTEXT_MODULE')) { |
---|
| 1028 | define('DC_CONTEXT_MODULE', true); |
---|
| 1029 | } |
---|
| 1030 | |
---|
| 1031 | return true; |
---|
| 1032 | } |
---|
| 1033 | |
---|
[2227] | 1034 | /** |
---|
| 1035 | * Get path of module configuration file. |
---|
| 1036 | * |
---|
| 1037 | * @note Required previously set file info |
---|
| 1038 | * @return Full path of config file or null |
---|
| 1039 | */ |
---|
| 1040 | public function includeConfiguration() |
---|
[2182] | 1041 | { |
---|
| 1042 | if (!$this->config_file) { |
---|
| 1043 | return null; |
---|
| 1044 | } |
---|
[2259] | 1045 | $this->setRedir($this->getURL().'#plugins'); |
---|
[2182] | 1046 | |
---|
| 1047 | ob_start(); |
---|
| 1048 | |
---|
| 1049 | return $this->config_file; |
---|
| 1050 | } |
---|
| 1051 | |
---|
[2227] | 1052 | /** |
---|
| 1053 | * Gather module configuration file content. |
---|
| 1054 | * |
---|
| 1055 | * @note Required previously file inclusion |
---|
| 1056 | * @return True if content has been captured |
---|
| 1057 | */ |
---|
| 1058 | public function getConfiguration() |
---|
[2182] | 1059 | { |
---|
| 1060 | if ($this->config_file) { |
---|
| 1061 | $this->config_content = ob_get_contents(); |
---|
| 1062 | } |
---|
| 1063 | |
---|
| 1064 | ob_end_clean(); |
---|
| 1065 | |
---|
| 1066 | return !empty($this->file_content); |
---|
| 1067 | } |
---|
| 1068 | |
---|
[2227] | 1069 | /** |
---|
| 1070 | * Display module configuration form. |
---|
| 1071 | * |
---|
| 1072 | * @note Required previously gathered content |
---|
| 1073 | * @return adminModulesList self instance |
---|
| 1074 | */ |
---|
| 1075 | public function displayConfiguration() |
---|
[2182] | 1076 | { |
---|
[2227] | 1077 | if ($this->config_file) { |
---|
| 1078 | |
---|
| 1079 | if (!$this->config_module['standalone_config']) { |
---|
| 1080 | echo |
---|
| 1081 | '<form id="module_config" action="'.$this->getURL('conf=1').'" method="post" enctype="multipart/form-data">'. |
---|
| 1082 | '<h3>'.sprintf(__('Configure plugin "%s"'), html::escapeHTML($this->config_module['name'])).'</h3>'. |
---|
[2259] | 1083 | '<p><a class="back" href="'.$this->getRedir().'">'.__('Back').'</a></p>'; |
---|
[2227] | 1084 | } |
---|
| 1085 | |
---|
| 1086 | echo $this->config_content; |
---|
| 1087 | |
---|
| 1088 | if (!$this->config_module['standalone_config']) { |
---|
| 1089 | echo |
---|
| 1090 | '<p class="clear"><input type="submit" name="save" value="'.__('Save').'" />'. |
---|
| 1091 | form::hidden('module', $this->config_module['id']). |
---|
[2259] | 1092 | form::hidden('redir', $this->getRedir()). |
---|
[2227] | 1093 | $this->core->formNonce().'</p>'. |
---|
| 1094 | '</form>'; |
---|
| 1095 | } |
---|
[2182] | 1096 | } |
---|
| 1097 | |
---|
[2227] | 1098 | return $this; |
---|
| 1099 | } |
---|
| 1100 | //@} |
---|
[2182] | 1101 | |
---|
[2227] | 1102 | /** |
---|
| 1103 | * Helper to sanitize a string. |
---|
| 1104 | * |
---|
| 1105 | * Used for search or id. |
---|
| 1106 | * |
---|
| 1107 | * @param string $str String to sanitize |
---|
| 1108 | * @return Sanitized string |
---|
| 1109 | */ |
---|
[2147] | 1110 | public static function sanitizeString($str) |
---|
| 1111 | { |
---|
| 1112 | return preg_replace('/[^A-Za-z0-9\@\#+_-]/', '', strtolower($str)); |
---|
| 1113 | } |
---|
| 1114 | } |
---|
| 1115 | |
---|
[2227] | 1116 | /** |
---|
| 1117 | * @ingroup DC_CORE |
---|
| 1118 | * @brief Helper to manage list of themes. |
---|
| 1119 | * @since 2.6 |
---|
| 1120 | */ |
---|
[2147] | 1121 | class adminThemesList extends adminModulesList |
---|
| 1122 | { |
---|
[2171] | 1123 | protected $page_url = 'blog_theme.php'; |
---|
[2147] | 1124 | |
---|
[2227] | 1125 | public function displayModules($cols=array('name', 'config', 'version', 'desc'), $actions=array(), $nav_limit=false) |
---|
[2171] | 1126 | { |
---|
| 1127 | echo |
---|
| 1128 | '<div id="'.html::escapeHTML($this->list_id).'" class="modules'.(in_array('expander', $cols) ? ' expandable' : '').' one-box">'; |
---|
| 1129 | |
---|
[2227] | 1130 | $sort_field = $this->getSort(); |
---|
[2171] | 1131 | |
---|
| 1132 | # Sort modules by id |
---|
[2227] | 1133 | $modules = $this->getSearch() === null ? |
---|
[2215] | 1134 | self::sortModules($this->data, $sort_field, $this->sort_asc) : |
---|
| 1135 | $this->data; |
---|
[2171] | 1136 | |
---|
| 1137 | $res = ''; |
---|
| 1138 | $count = 0; |
---|
| 1139 | foreach ($modules as $id => $module) |
---|
| 1140 | { |
---|
| 1141 | # Show only requested modules |
---|
[2227] | 1142 | if ($nav_limit && $this->getSearch() === null) { |
---|
[2171] | 1143 | $char = substr($module[$sort_field], 0, 1); |
---|
| 1144 | if (!in_array($char, $this->nav_list)) { |
---|
| 1145 | $char = $this->nav_special; |
---|
| 1146 | } |
---|
[2227] | 1147 | if ($this->getIndex() != $char) { |
---|
[2171] | 1148 | continue; |
---|
| 1149 | } |
---|
| 1150 | } |
---|
| 1151 | |
---|
[2227] | 1152 | $current = $this->core->blog->settings->system->theme == $id && $this->modules->moduleExists($id); |
---|
[2215] | 1153 | $distrib = self::isDistributedModule($id) ? ' dc-box' : ''; |
---|
[2171] | 1154 | |
---|
| 1155 | $line = |
---|
[2215] | 1156 | '<div class="box '.($current ? 'medium current-theme' : 'small theme').$distrib.'">'; |
---|
[2171] | 1157 | |
---|
| 1158 | if (in_array('name', $cols)) { |
---|
| 1159 | $line .= |
---|
| 1160 | '<h4 class="module-name">'.html::escapeHTML($module['name']).'</h4>'; |
---|
| 1161 | } |
---|
| 1162 | |
---|
[2222] | 1163 | # Display score only for debug purpose |
---|
[2227] | 1164 | if (in_array('score', $cols) && $this->getSearch() !== null && defined('DC_DEBUG') && DC_DEBUG) { |
---|
[2222] | 1165 | $line .= |
---|
| 1166 | '<p class="module-score debug">'.sprintf(__('Score: %s'), $module['score']).'</p>'; |
---|
| 1167 | } |
---|
| 1168 | |
---|
[2195] | 1169 | if (in_array('sshot', $cols)) { |
---|
| 1170 | # Screenshot from url |
---|
| 1171 | if (preg_match('#^http(s)?://#', $module['sshot'])) { |
---|
| 1172 | $sshot = $module['sshot']; |
---|
| 1173 | } |
---|
| 1174 | # Screenshot from installed module |
---|
| 1175 | elseif (file_exists($this->core->blog->themes_path.'/'.$id.'/screenshot.jpg')) { |
---|
[2227] | 1176 | $sshot = $this->getURL('shot='.rawurlencode($id)); |
---|
[2195] | 1177 | } |
---|
| 1178 | # Default screenshot |
---|
| 1179 | else { |
---|
| 1180 | $sshot = 'images/noscreenshot.png'; |
---|
| 1181 | } |
---|
| 1182 | |
---|
| 1183 | $line .= |
---|
[2215] | 1184 | '<div class="module-sshot"><img src="'.$sshot.'" alt="'. |
---|
| 1185 | sprintf(__('%s screenshot.'), html::escapeHTML($module['name'])).'" /></div>'; |
---|
[2195] | 1186 | } |
---|
| 1187 | |
---|
[2171] | 1188 | $line .= |
---|
[2195] | 1189 | '<div class="module-infos toggle-bloc">'. |
---|
[2171] | 1190 | '<p>'; |
---|
| 1191 | |
---|
| 1192 | if (in_array('desc', $cols)) { |
---|
| 1193 | $line .= |
---|
| 1194 | '<span class="module-desc">'.html::escapeHTML($module['desc']).'</span> '; |
---|
| 1195 | } |
---|
| 1196 | |
---|
| 1197 | if (in_array('author', $cols)) { |
---|
| 1198 | $line .= |
---|
| 1199 | '<span class="module-author">'.sprintf(__('by %s'),html::escapeHTML($module['author'])).'</span> '; |
---|
| 1200 | } |
---|
| 1201 | |
---|
| 1202 | if (in_array('version', $cols)) { |
---|
| 1203 | $line .= |
---|
| 1204 | '<span class="module-version">'.sprintf(__('version %s'),html::escapeHTML($module['version'])).'</span> '; |
---|
| 1205 | } |
---|
| 1206 | |
---|
[2222] | 1207 | if (in_array('current_version', $cols)) { |
---|
| 1208 | $line .= |
---|
| 1209 | '<span class="module-current-version">'.sprintf(__('(current version %s)'),html::escapeHTML($module['current_version'])).'</span> '; |
---|
| 1210 | } |
---|
| 1211 | |
---|
[2227] | 1212 | if (in_array('parent', $cols) && !empty($module['parent'])) { |
---|
| 1213 | if ($this->modules->moduleExists($module['parent'])) { |
---|
[2171] | 1214 | $line .= |
---|
[2227] | 1215 | '<span class="module-parent-ok">'.sprintf(__('(built on "%s")'),html::escapeHTML($module['parent'])).'</span> '; |
---|
[2171] | 1216 | } |
---|
| 1217 | else { |
---|
| 1218 | $line .= |
---|
[2227] | 1219 | '<span class="module-parent-missing">'.sprintf(__('(requires "%s")'),html::escapeHTML($module['parent'])).'</span> '; |
---|
[2171] | 1220 | } |
---|
| 1221 | } |
---|
| 1222 | |
---|
[2215] | 1223 | $has_details = in_array('details', $cols) && !empty($module['details']); |
---|
| 1224 | $has_support = in_array('support', $cols) && !empty($module['support']); |
---|
| 1225 | if ($has_details || $has_support) { |
---|
| 1226 | $line .= |
---|
[2260] | 1227 | '<span class="mod-more">'; |
---|
[2215] | 1228 | |
---|
| 1229 | if ($has_details) { |
---|
| 1230 | $line .= |
---|
| 1231 | '<a class="module-details" href="'.$module['details'].'">'.__('Details').'</a>'; |
---|
| 1232 | } |
---|
| 1233 | |
---|
| 1234 | if ($has_support) { |
---|
| 1235 | $line .= |
---|
| 1236 | ' - <a class="module-support" href="'.$module['support'].'">'.__('Support').'</a>'; |
---|
| 1237 | } |
---|
| 1238 | |
---|
| 1239 | $line .= |
---|
| 1240 | '</span>'; |
---|
| 1241 | } |
---|
| 1242 | |
---|
[2171] | 1243 | $line .= |
---|
| 1244 | '</p>'. |
---|
| 1245 | '</div>'; |
---|
| 1246 | |
---|
| 1247 | $line .= |
---|
[2195] | 1248 | '<div class="module-actions toggle-bloc">'; |
---|
[2171] | 1249 | |
---|
| 1250 | # Plugins actions |
---|
| 1251 | if ($current) { |
---|
[2227] | 1252 | |
---|
| 1253 | # _GET actions |
---|
| 1254 | if (file_exists(path::real($this->core->blog->themes_path.'/'.$id).'/style.css')) { |
---|
| 1255 | $theme_url = preg_match('#^http(s)?://#', $this->core->blog->settings->system->themes_url) ? |
---|
| 1256 | http::concatURL($this->core->blog->settings->system->themes_url, '/'.$id) : |
---|
| 1257 | http::concatURL($this->core->blog->url, $this->core->blog->settings->system->themes_url.'/'.$id); |
---|
| 1258 | $line .= |
---|
| 1259 | '<p><a href="'.$theme_url.'/style.css">'.__('View stylesheet').'</a></p>'; |
---|
| 1260 | } |
---|
| 1261 | |
---|
[2260] | 1262 | $line .= '<div class="current-actions">'; |
---|
| 1263 | |
---|
[2227] | 1264 | if (file_exists(path::real($this->core->blog->themes_path.'/'.$id).'/_config.php')) { |
---|
| 1265 | $line .= |
---|
| 1266 | '<p><a href="'.$this->getURL('module='.$id.'&conf=1', false).'" class="button">'.__('Configure theme').'</a></p>'; |
---|
| 1267 | } |
---|
| 1268 | |
---|
[2171] | 1269 | # --BEHAVIOR-- adminCurrentThemeDetails |
---|
| 1270 | $line .= |
---|
| 1271 | $this->core->callBehavior('adminCurrentThemeDetails', $this->core, $id, $module); |
---|
[2260] | 1272 | |
---|
| 1273 | $line .= '</div>'; |
---|
[2171] | 1274 | } |
---|
| 1275 | |
---|
| 1276 | # _POST actions |
---|
[2215] | 1277 | if (!empty($actions)) { |
---|
[2171] | 1278 | $line .= |
---|
[2227] | 1279 | '<form action="'.$this->getURL().'" method="post">'. |
---|
[2215] | 1280 | '<div>'. |
---|
| 1281 | $this->core->formNonce(). |
---|
| 1282 | form::hidden(array('module'), html::escapeHTML($id)). |
---|
| 1283 | |
---|
| 1284 | implode(' ', $this->getActions($id, $module, $actions)). |
---|
| 1285 | |
---|
| 1286 | '</div>'. |
---|
| 1287 | '</form>'; |
---|
[2171] | 1288 | } |
---|
| 1289 | |
---|
| 1290 | $line .= |
---|
| 1291 | '</div>'; |
---|
| 1292 | |
---|
| 1293 | $line .= |
---|
| 1294 | '</div>'; |
---|
| 1295 | |
---|
| 1296 | $count++; |
---|
| 1297 | |
---|
| 1298 | $res = $current ? $line.$res : $res.$line; |
---|
| 1299 | } |
---|
| 1300 | echo |
---|
| 1301 | $res. |
---|
| 1302 | '</div>'; |
---|
| 1303 | |
---|
[2227] | 1304 | if(!$count && $this->getSearch() === null) { |
---|
[2171] | 1305 | echo |
---|
| 1306 | '<p class="message">'.__('No module matches your search.').'</p>'; |
---|
| 1307 | } |
---|
| 1308 | } |
---|
[2192] | 1309 | |
---|
[2215] | 1310 | protected function getActions($id, $module, $actions) |
---|
[2192] | 1311 | { |
---|
| 1312 | $submits = array(); |
---|
| 1313 | |
---|
| 1314 | $this->core->blog->settings->addNamespace('system'); |
---|
[2215] | 1315 | if ($id != $this->core->blog->settings->system->theme) { |
---|
| 1316 | |
---|
| 1317 | # Select theme to use on curent blog |
---|
| 1318 | if (in_array('select', $actions) && $this->path_writable) { |
---|
[2227] | 1319 | $submits[] = |
---|
| 1320 | '<input type="submit" name="select" value="'.__('Use this one').'" />'; |
---|
[2215] | 1321 | } |
---|
[2192] | 1322 | } |
---|
| 1323 | |
---|
[2215] | 1324 | return array_merge( |
---|
| 1325 | $submits, |
---|
| 1326 | parent::getActions($id, $module, $actions) |
---|
| 1327 | ); |
---|
| 1328 | } |
---|
| 1329 | |
---|
| 1330 | public function doActions($prefix) |
---|
| 1331 | { |
---|
[2227] | 1332 | if (!empty($_POST) && empty($_REQUEST['conf']) && $this->isWritablePath()) { |
---|
[2215] | 1333 | |
---|
| 1334 | # Select theme to use on curent blog |
---|
| 1335 | if (!empty($_POST['module']) && !empty($_POST['select'])) { |
---|
| 1336 | $id = $_POST['module']; |
---|
| 1337 | |
---|
| 1338 | if (!$this->modules->moduleExists($id)) { |
---|
| 1339 | throw new Exception(__('No such module.')); |
---|
| 1340 | } |
---|
| 1341 | |
---|
| 1342 | $this->core->blog->settings->addNamespace('system'); |
---|
| 1343 | $this->core->blog->settings->system->put('theme',$id); |
---|
| 1344 | $this->core->blog->triggerBlog(); |
---|
| 1345 | |
---|
[2219] | 1346 | dcPage::addSuccessNotice(__('Module has been successfully selected.')); |
---|
[2227] | 1347 | http::redirect($this->getURL().'#themes'); |
---|
[2215] | 1348 | } |
---|
[2192] | 1349 | } |
---|
| 1350 | |
---|
[2215] | 1351 | return parent::doActions($prefix); |
---|
[2192] | 1352 | } |
---|
[2147] | 1353 | } |
---|