[2147] | 1 | <?php |
---|
[3731] | 2 | /** |
---|
| 3 | * @package Dotclear |
---|
| 4 | * @subpackage Backend |
---|
| 5 | * |
---|
| 6 | * @copyright Olivier Meunier & Association Dotclear |
---|
| 7 | * @copyright GPL-2.0-only |
---|
| 8 | */ |
---|
| 9 | |
---|
[3699] | 10 | if (!defined('DC_ADMIN_CONTEXT')) {return;} |
---|
[2147] | 11 | |
---|
[2227] | 12 | /** |
---|
| 13 | * @brief Helper for admin list of modules. |
---|
| 14 | * @since 2.6 |
---|
| 15 | |
---|
| 16 | * Provides an object to parse XML feed of modules from a repository. |
---|
| 17 | */ |
---|
[2147] | 18 | class adminModulesList |
---|
| 19 | { |
---|
[3699] | 20 | public $core; /**< @var object dcCore instance */ |
---|
| 21 | public $modules; /**< @var object dcModules instance */ |
---|
| 22 | public $store; /**< @var object dcStore instance */ |
---|
[2147] | 23 | |
---|
[3699] | 24 | public static $allow_multi_install = false; /**< @var boolean Work with multiple root directories */ |
---|
| 25 | public static $distributed_modules = array(); /**< @var array List of modules distributed with Dotclear */ |
---|
[2149] | 26 | |
---|
[3699] | 27 | protected $list_id = 'unknow'; /**< @var string Current list ID */ |
---|
| 28 | protected $data = array(); /**< @var array Current modules */ |
---|
[2156] | 29 | |
---|
[3699] | 30 | protected $config_module = ''; /**< @var string Module ID to configure */ |
---|
| 31 | protected $config_file = ''; /**< @var string Module path to configure */ |
---|
| 32 | protected $config_content = ''; /**< @var string Module configuration page content */ |
---|
[2182] | 33 | |
---|
[3699] | 34 | protected $path = false; /**< @var string Modules root directory */ |
---|
| 35 | protected $path_writable = false; /**< @var boolean Indicate if modules root directory is writable */ |
---|
| 36 | protected $path_pattern = false; /**< @var string Directory pattern to work on */ |
---|
[2149] | 37 | |
---|
[3699] | 38 | protected $page_url = ''; /**< @var string Page URL */ |
---|
| 39 | protected $page_qs = '?'; /**< @var string Page query string */ |
---|
| 40 | protected $page_tab = ''; /**< @var string Page tab */ |
---|
| 41 | protected $page_redir = ''; /**< @var string Page redirection */ |
---|
[2147] | 42 | |
---|
[3699] | 43 | public static $nav_indexes = 'abcdefghijklmnopqrstuvwxyz0123456789'; /**< @var string Index list */ |
---|
| 44 | protected $nav_list = array(); /**< @var array Index list with special index */ |
---|
| 45 | protected $nav_special = 'other'; /**< @var string Text for other special index */ |
---|
[2147] | 46 | |
---|
[3699] | 47 | protected $sort_field = 'sname'; /**< @var string Field used to sort modules */ |
---|
| 48 | protected $sort_asc = true; /**< @var boolean Sort order asc */ |
---|
[2147] | 49 | |
---|
[3699] | 50 | /** |
---|
| 51 | * Constructor. |
---|
| 52 | * |
---|
| 53 | * Note that this creates dcStore instance. |
---|
| 54 | * |
---|
| 55 | * @param object $modules dcModules instance |
---|
| 56 | * @param string $modules_root Modules root directories |
---|
| 57 | * @param string $xml_url URL of modules feed from repository |
---|
| 58 | */ |
---|
| 59 | public function __construct(dcModules $modules, $modules_root, $xml_url) |
---|
| 60 | { |
---|
| 61 | $this->core = $modules->core; |
---|
| 62 | $this->modules = $modules; |
---|
| 63 | $this->store = new dcStore($modules, $xml_url); |
---|
[2215] | 64 | |
---|
[3699] | 65 | $this->page_url = $this->core->adminurl->get('admin.plugins'); |
---|
[2817] | 66 | |
---|
[3699] | 67 | $this->setPath($modules_root); |
---|
| 68 | $this->setIndex(__('other')); |
---|
| 69 | } |
---|
[2147] | 70 | |
---|
[3699] | 71 | /** |
---|
| 72 | * Begin a new list. |
---|
| 73 | * |
---|
| 74 | * @param string $id New list ID |
---|
| 75 | * @return adminModulesList self instance |
---|
| 76 | */ |
---|
| 77 | public function setList($id) |
---|
| 78 | { |
---|
| 79 | $this->data = array(); |
---|
| 80 | $this->page_tab = ''; |
---|
| 81 | $this->list_id = $id; |
---|
[2156] | 82 | |
---|
[3699] | 83 | return $this; |
---|
| 84 | } |
---|
[2156] | 85 | |
---|
[3699] | 86 | /** |
---|
| 87 | * Get list ID. |
---|
| 88 | * |
---|
| 89 | * @return List ID |
---|
| 90 | */ |
---|
| 91 | public function getList() |
---|
| 92 | { |
---|
| 93 | return $this->list_id; |
---|
| 94 | } |
---|
[2241] | 95 | |
---|
[3699] | 96 | /// @name Modules root directory methods |
---|
| 97 | //@{ |
---|
| 98 | /** |
---|
| 99 | * Set path info. |
---|
| 100 | * |
---|
| 101 | * @param string $root Modules root directories |
---|
| 102 | * @return adminModulesList self instance |
---|
| 103 | */ |
---|
| 104 | protected function setPath($root) |
---|
| 105 | { |
---|
| 106 | $paths = explode(PATH_SEPARATOR, $root); |
---|
| 107 | $path = array_pop($paths); |
---|
| 108 | unset($paths); |
---|
[2149] | 109 | |
---|
[3699] | 110 | $this->path = $path; |
---|
| 111 | if (is_dir($path) && is_writeable($path)) { |
---|
| 112 | $this->path_writable = true; |
---|
| 113 | $this->path_pattern = preg_quote($path, '!'); |
---|
| 114 | } |
---|
[2149] | 115 | |
---|
[3699] | 116 | return $this; |
---|
| 117 | } |
---|
[2149] | 118 | |
---|
[3699] | 119 | /** |
---|
| 120 | * Get modules root directory. |
---|
| 121 | * |
---|
| 122 | * @return Path to work on |
---|
| 123 | */ |
---|
| 124 | public function getPath() |
---|
| 125 | { |
---|
| 126 | return $this->path; |
---|
| 127 | } |
---|
[2149] | 128 | |
---|
[3699] | 129 | /** |
---|
| 130 | * Check if modules root directory is writable. |
---|
| 131 | * |
---|
| 132 | * @return True if directory is writable |
---|
| 133 | */ |
---|
| 134 | public function isWritablePath() |
---|
| 135 | { |
---|
| 136 | return $this->path_writable; |
---|
| 137 | } |
---|
[2149] | 138 | |
---|
[3699] | 139 | /** |
---|
| 140 | * Check if root directory of a module is deletable. |
---|
| 141 | * |
---|
| 142 | * @param string $root Module root directory |
---|
| 143 | * @return True if directory is delatable |
---|
| 144 | */ |
---|
| 145 | public function isDeletablePath($root) |
---|
| 146 | { |
---|
| 147 | return $this->path_writable |
---|
| 148 | && (preg_match('!^' . $this->path_pattern . '!', $root) || defined('DC_DEV') && DC_DEV) |
---|
| 149 | && $this->core->auth->isSuperAdmin(); |
---|
| 150 | } |
---|
| 151 | //@} |
---|
[2149] | 152 | |
---|
[3699] | 153 | /// @name Page methods |
---|
| 154 | //@{ |
---|
| 155 | /** |
---|
| 156 | * Set page base URL. |
---|
| 157 | * |
---|
| 158 | * @param string $url Page base URL |
---|
| 159 | * @return adminModulesList self instance |
---|
| 160 | */ |
---|
| 161 | public function setURL($url) |
---|
| 162 | { |
---|
| 163 | $this->page_qs = strpos('?', $url) ? '&' : '?'; |
---|
| 164 | $this->page_url = $url; |
---|
[2147] | 165 | |
---|
[3699] | 166 | return $this; |
---|
| 167 | } |
---|
[2147] | 168 | |
---|
[3699] | 169 | /** |
---|
| 170 | * Get page URL. |
---|
| 171 | * |
---|
| 172 | * @param string|array $queries Additionnal query string |
---|
| 173 | * @param booleany $with_tab Add current tab to URL end |
---|
| 174 | * @return Clean page URL |
---|
| 175 | */ |
---|
| 176 | public function getURL($queries = '', $with_tab = true) |
---|
| 177 | { |
---|
| 178 | return $this->page_url . |
---|
| 179 | (!empty($queries) ? $this->page_qs : '') . |
---|
| 180 | (is_array($queries) ? http_build_query($queries) : $queries) . |
---|
| 181 | ($with_tab && !empty($this->page_tab) ? '#' . $this->page_tab : ''); |
---|
| 182 | } |
---|
[2147] | 183 | |
---|
[3699] | 184 | /** |
---|
| 185 | * Set page tab. |
---|
| 186 | * |
---|
| 187 | * @param string $tab Page tab |
---|
| 188 | * @return adminModulesList self instance |
---|
| 189 | */ |
---|
| 190 | public function setTab($tab) |
---|
| 191 | { |
---|
| 192 | $this->page_tab = $tab; |
---|
[2147] | 193 | |
---|
[3699] | 194 | return $this; |
---|
| 195 | } |
---|
[2147] | 196 | |
---|
[3699] | 197 | /** |
---|
| 198 | * Get page tab. |
---|
| 199 | * |
---|
| 200 | * @return Page tab |
---|
| 201 | */ |
---|
| 202 | public function getTab() |
---|
| 203 | { |
---|
| 204 | return $this->page_tab; |
---|
| 205 | } |
---|
[2259] | 206 | |
---|
[3699] | 207 | /** |
---|
| 208 | * Set page redirection. |
---|
| 209 | * |
---|
| 210 | * @param string $default Default redirection |
---|
| 211 | * @return adminModulesList self instance |
---|
| 212 | */ |
---|
| 213 | public function setRedir($default = '') |
---|
| 214 | { |
---|
| 215 | $this->page_redir = empty($_REQUEST['redir']) ? $default : $_REQUEST['redir']; |
---|
[2259] | 216 | |
---|
[3699] | 217 | return $this; |
---|
| 218 | } |
---|
[2259] | 219 | |
---|
[3699] | 220 | /** |
---|
| 221 | * Get page redirection. |
---|
| 222 | * |
---|
| 223 | * @return Page redirection |
---|
| 224 | */ |
---|
| 225 | public function getRedir() |
---|
| 226 | { |
---|
| 227 | return empty($this->page_redir) ? $this->getURL() : $this->page_redir; |
---|
| 228 | } |
---|
| 229 | //@} |
---|
[2147] | 230 | |
---|
[3699] | 231 | /// @name Search methods |
---|
| 232 | //@{ |
---|
| 233 | /** |
---|
| 234 | * Get search query. |
---|
| 235 | * |
---|
| 236 | * @return Search query |
---|
| 237 | */ |
---|
| 238 | public function getSearch() |
---|
| 239 | { |
---|
| 240 | $query = !empty($_REQUEST['m_search']) ? trim($_REQUEST['m_search']) : null; |
---|
| 241 | return strlen($query) > 2 ? $query : null; |
---|
| 242 | } |
---|
[2147] | 243 | |
---|
[3699] | 244 | /** |
---|
| 245 | * Display searh form. |
---|
| 246 | * |
---|
| 247 | * @return adminModulesList self instance |
---|
| 248 | */ |
---|
| 249 | public function displaySearch() |
---|
| 250 | { |
---|
| 251 | $query = $this->getSearch(); |
---|
[2163] | 252 | |
---|
[3699] | 253 | if (empty($this->data) && $query === null) { |
---|
| 254 | return $this; |
---|
| 255 | } |
---|
[2147] | 256 | |
---|
[3699] | 257 | echo |
---|
| 258 | '<div class="modules-search">' . |
---|
| 259 | '<form action="' . $this->getURL() . '" method="get">' . |
---|
| 260 | '<p><label for="m_search" class="classic">' . __('Search in repository:') . ' </label><br />' . |
---|
[3725] | 261 | form::field('m_search', 30, 255, html::escapeHTML($query)) . |
---|
[3699] | 262 | '<input type="submit" value="' . __('OK') . '" /> '; |
---|
[2287] | 263 | |
---|
[3699] | 264 | if ($query) { |
---|
| 265 | echo |
---|
| 266 | ' <a href="' . $this->getURL() . '" class="button">' . __('Reset search') . '</a>'; |
---|
| 267 | } |
---|
[2287] | 268 | |
---|
[3699] | 269 | echo |
---|
| 270 | '</p>' . |
---|
| 271 | '<p class="form-note">' . |
---|
| 272 | __('Search is allowed on multiple terms longer than 2 chars, terms must be separated by space.') . |
---|
| 273 | '</p>' . |
---|
| 274 | '</form>'; |
---|
[2147] | 275 | |
---|
[3699] | 276 | if ($query) { |
---|
| 277 | echo |
---|
| 278 | '<p class="message">' . sprintf( |
---|
| 279 | __('Found %d result for search "%s":', 'Found %d results for search "%s":', count($this->data)), |
---|
| 280 | count($this->data), html::escapeHTML($query) |
---|
| 281 | ) . |
---|
| 282 | '</p>'; |
---|
| 283 | } |
---|
| 284 | echo '</div>'; |
---|
[2287] | 285 | |
---|
[3699] | 286 | return $this; |
---|
| 287 | } |
---|
| 288 | //@} |
---|
[2147] | 289 | |
---|
[3699] | 290 | /// @name Navigation menu methods |
---|
| 291 | //@{ |
---|
| 292 | /** |
---|
| 293 | * Set navigation special index. |
---|
| 294 | * |
---|
| 295 | * @return adminModulesList self instance |
---|
| 296 | */ |
---|
| 297 | public function setIndex($str) |
---|
| 298 | { |
---|
| 299 | $this->nav_special = (string) $str; |
---|
| 300 | $this->nav_list = array_merge(str_split(self::$nav_indexes), array($this->nav_special)); |
---|
[2147] | 301 | |
---|
[3699] | 302 | return $this; |
---|
| 303 | } |
---|
[2147] | 304 | |
---|
[3699] | 305 | /** |
---|
| 306 | * Get index from query. |
---|
| 307 | * |
---|
| 308 | * @return Query index or default one |
---|
| 309 | */ |
---|
| 310 | public function getIndex() |
---|
| 311 | { |
---|
| 312 | return isset($_REQUEST['m_nav']) && in_array($_REQUEST['m_nav'], $this->nav_list) ? $_REQUEST['m_nav'] : $this->nav_list[0]; |
---|
| 313 | } |
---|
[2147] | 314 | |
---|
[3699] | 315 | /** |
---|
| 316 | * Display navigation by index menu. |
---|
| 317 | * |
---|
| 318 | * @return adminModulesList self instance |
---|
| 319 | */ |
---|
| 320 | public function displayIndex() |
---|
| 321 | { |
---|
| 322 | if (empty($this->data) || $this->getSearch() !== null) { |
---|
| 323 | return $this; |
---|
| 324 | } |
---|
[2147] | 325 | |
---|
[3699] | 326 | # Fetch modules required field |
---|
| 327 | $indexes = array(); |
---|
| 328 | foreach ($this->data as $id => $module) { |
---|
| 329 | if (!isset($module[$this->sort_field])) { |
---|
| 330 | continue; |
---|
| 331 | } |
---|
| 332 | $char = substr($module[$this->sort_field], 0, 1); |
---|
| 333 | if (!in_array($char, $this->nav_list)) { |
---|
| 334 | $char = $this->nav_special; |
---|
| 335 | } |
---|
| 336 | if (!isset($indexes[$char])) { |
---|
| 337 | $indexes[$char] = 0; |
---|
| 338 | } |
---|
| 339 | $indexes[$char]++; |
---|
| 340 | } |
---|
[2147] | 341 | |
---|
[3699] | 342 | $buttons = array(); |
---|
| 343 | foreach ($this->nav_list as $char) { |
---|
| 344 | # Selected letter |
---|
| 345 | if ($this->getIndex() == $char) { |
---|
| 346 | $buttons[] = '<li class="active" title="' . __('current selection') . '"><strong> ' . $char . ' </strong></li>'; |
---|
| 347 | } |
---|
| 348 | # Letter having modules |
---|
| 349 | elseif (!empty($indexes[$char])) { |
---|
| 350 | $title = sprintf(__('%d result', '%d results', $indexes[$char]), $indexes[$char]); |
---|
| 351 | $buttons[] = '<li class="btn" title="' . $title . '"><a href="' . $this->getURL('m_nav=' . $char) . '" title="' . $title . '"> ' . $char . ' </a></li>'; |
---|
| 352 | } |
---|
| 353 | # Letter without modules |
---|
| 354 | else { |
---|
| 355 | $buttons[] = '<li class="btn no-link" title="' . __('no results') . '"> ' . $char . ' </li>'; |
---|
| 356 | } |
---|
| 357 | } |
---|
| 358 | # Parse navigation menu |
---|
| 359 | echo '<div class="pager">' . __('Browse index:') . ' <ul class="index">' . implode('', $buttons) . '</ul></div>'; |
---|
[2147] | 360 | |
---|
[3699] | 361 | return $this; |
---|
| 362 | } |
---|
| 363 | //@} |
---|
[2147] | 364 | |
---|
[3699] | 365 | /// @name Sort methods |
---|
| 366 | //@{ |
---|
| 367 | /** |
---|
| 368 | * Set default sort field. |
---|
| 369 | * |
---|
| 370 | * @return adminModulesList self instance |
---|
| 371 | */ |
---|
| 372 | public function setSort($field, $asc = true) |
---|
| 373 | { |
---|
| 374 | $this->sort_field = $field; |
---|
| 375 | $this->sort_asc = (boolean) $asc; |
---|
[2147] | 376 | |
---|
[3699] | 377 | return $this; |
---|
| 378 | } |
---|
[2147] | 379 | |
---|
[3699] | 380 | /** |
---|
| 381 | * Get sort field from query. |
---|
| 382 | * |
---|
| 383 | * @return Query sort field or default one |
---|
| 384 | */ |
---|
| 385 | public function getSort() |
---|
| 386 | { |
---|
| 387 | return !empty($_REQUEST['m_sort']) ? $_REQUEST['m_sort'] : $this->sort_field; |
---|
| 388 | } |
---|
[2147] | 389 | |
---|
[3699] | 390 | /** |
---|
| 391 | * Display sort field form. |
---|
| 392 | * |
---|
| 393 | * @note This method is not implemented yet |
---|
| 394 | * @return adminModulesList self instance |
---|
| 395 | */ |
---|
| 396 | public function displaySort() |
---|
| 397 | { |
---|
| 398 | // |
---|
[2227] | 399 | |
---|
[3699] | 400 | return $this; |
---|
| 401 | } |
---|
| 402 | //@} |
---|
[2147] | 403 | |
---|
[3699] | 404 | /// @name Modules methods |
---|
| 405 | //@{ |
---|
| 406 | /** |
---|
| 407 | * Set modules and sanitize them. |
---|
| 408 | * |
---|
| 409 | * @return adminModulesList self instance |
---|
| 410 | */ |
---|
| 411 | public function setModules($modules) |
---|
| 412 | { |
---|
| 413 | $this->data = array(); |
---|
| 414 | if (!empty($modules) && is_array($modules)) { |
---|
| 415 | foreach ($modules as $id => $module) { |
---|
| 416 | $this->data[$id] = self::sanitizeModule($id, $module); |
---|
| 417 | } |
---|
| 418 | } |
---|
| 419 | return $this; |
---|
| 420 | } |
---|
[2147] | 421 | |
---|
[3699] | 422 | /** |
---|
| 423 | * Get modules currently set. |
---|
| 424 | * |
---|
| 425 | * @return Array of modules |
---|
| 426 | */ |
---|
| 427 | public function getModules() |
---|
| 428 | { |
---|
| 429 | return $this->data; |
---|
| 430 | } |
---|
[2147] | 431 | |
---|
[3699] | 432 | /** |
---|
| 433 | * Sanitize a module. |
---|
| 434 | * |
---|
| 435 | * This clean infos of a module by adding default keys |
---|
| 436 | * and clean some of them, sanitize module can safely |
---|
| 437 | * be used in lists. |
---|
| 438 | * |
---|
| 439 | * @return Array of the module informations |
---|
| 440 | */ |
---|
| 441 | public static function sanitizeModule($id, $module) |
---|
| 442 | { |
---|
| 443 | $label = empty($module['label']) ? $id : $module['label']; |
---|
| 444 | $name = __(empty($module['name']) ? $label : $module['name']); |
---|
[2431] | 445 | |
---|
[3699] | 446 | return array_merge( |
---|
| 447 | # Default values |
---|
| 448 | array( |
---|
| 449 | 'desc' => '', |
---|
| 450 | 'author' => '', |
---|
| 451 | 'version' => 0, |
---|
| 452 | 'current_version' => 0, |
---|
| 453 | 'root' => '', |
---|
| 454 | 'root_writable' => false, |
---|
| 455 | 'permissions' => null, |
---|
| 456 | 'parent' => null, |
---|
| 457 | 'priority' => 1000, |
---|
| 458 | 'standalone_config' => false, |
---|
| 459 | 'support' => '', |
---|
| 460 | 'section' => '', |
---|
| 461 | 'tags' => '', |
---|
| 462 | 'details' => '', |
---|
| 463 | 'sshot' => '', |
---|
| 464 | 'score' => 0, |
---|
| 465 | 'type' => null, |
---|
| 466 | 'require' => array(), |
---|
| 467 | 'settings' => array() |
---|
| 468 | ), |
---|
| 469 | # Module's values |
---|
| 470 | $module, |
---|
| 471 | # Clean up values |
---|
| 472 | array( |
---|
| 473 | 'id' => $id, |
---|
| 474 | 'sid' => self::sanitizeString($id), |
---|
| 475 | 'label' => $label, |
---|
| 476 | 'name' => $name, |
---|
| 477 | 'sname' => self::sanitizeString($name) |
---|
| 478 | ) |
---|
| 479 | ); |
---|
| 480 | } |
---|
[2147] | 481 | |
---|
[3699] | 482 | /** |
---|
| 483 | * Check if a module is part of the distribution. |
---|
| 484 | * |
---|
| 485 | * @param string $id Module root directory |
---|
| 486 | * @return True if module is part of the distribution |
---|
| 487 | */ |
---|
| 488 | public static function isDistributedModule($id) |
---|
| 489 | { |
---|
| 490 | $distributed_modules = self::$distributed_modules; |
---|
[2171] | 491 | |
---|
[3699] | 492 | return is_array($distributed_modules) && in_array($id, $distributed_modules); |
---|
| 493 | } |
---|
[2148] | 494 | |
---|
[3699] | 495 | /** |
---|
| 496 | * Sort modules list by specific field. |
---|
| 497 | * |
---|
| 498 | * @param string $module Array of modules |
---|
| 499 | * @param string $field Field to sort from |
---|
| 500 | * @param bollean $asc Sort asc if true, else decs |
---|
| 501 | * @return Array of sorted modules |
---|
| 502 | */ |
---|
| 503 | public static function sortModules($modules, $field, $asc = true) |
---|
| 504 | { |
---|
| 505 | $origin = $sorter = array(); |
---|
[2631] | 506 | |
---|
[3699] | 507 | foreach ($modules as $id => $module) { |
---|
| 508 | $origin[] = $module; |
---|
| 509 | $sorter[] = isset($module[$field]) ? $module[$field] : $field; |
---|
| 510 | } |
---|
[2147] | 511 | |
---|
[3699] | 512 | array_multisort($sorter, $asc ? SORT_ASC : SORT_DESC, $origin); |
---|
[2631] | 513 | |
---|
[3699] | 514 | foreach ($origin as $module) { |
---|
| 515 | $final[$module['id']] = $module; |
---|
| 516 | } |
---|
[2631] | 517 | |
---|
[3699] | 518 | return $final; |
---|
| 519 | } |
---|
[2147] | 520 | |
---|
[3699] | 521 | /** |
---|
| 522 | * Display list of modules. |
---|
| 523 | * |
---|
| 524 | * @param array $cols List of colones (module field) to display |
---|
| 525 | * @param array $actions List of predefined actions to show on form |
---|
| 526 | * @param boolean $nav_limit Limit list to previously selected index |
---|
| 527 | * @return adminModulesList self instance |
---|
| 528 | */ |
---|
| 529 | public function displayModules($cols = array('name', 'version', 'desc'), $actions = array(), $nav_limit = false) |
---|
| 530 | { |
---|
| 531 | echo |
---|
| 532 | '<form action="' . $this->getURL() . '" method="post" class="modules-form-actions">' . |
---|
| 533 | '<div class="table-outer">' . |
---|
| 534 | '<table id="' . html::escapeHTML($this->list_id) . '" class="modules' . (in_array('expander', $cols) ? ' expandable' : '') . '">' . |
---|
| 535 | '<caption class="hidden">' . html::escapeHTML(__('Plugins list')) . '</caption><tr>'; |
---|
[2163] | 536 | |
---|
[3699] | 537 | if (in_array('name', $cols)) { |
---|
| 538 | $colspan = 1; |
---|
| 539 | if (in_array('checkbox', $cols)) { |
---|
| 540 | $colspan++; |
---|
| 541 | } |
---|
| 542 | if (in_array('icon', $cols)) { |
---|
| 543 | $colspan++; |
---|
| 544 | } |
---|
| 545 | echo |
---|
| 546 | '<th class="first nowrap"' . ($colspan > 1 ? ' colspan="' . $colspan . '"' : '') . '>' . __('Name') . '</th>'; |
---|
| 547 | } |
---|
[2147] | 548 | |
---|
[3699] | 549 | if (in_array('score', $cols) && $this->getSearch() !== null && defined('DC_DEBUG') && DC_DEBUG) { |
---|
| 550 | echo |
---|
| 551 | '<th class="nowrap">' . __('Score') . '</th>'; |
---|
| 552 | } |
---|
[2222] | 553 | |
---|
[3699] | 554 | if (in_array('version', $cols)) { |
---|
| 555 | echo |
---|
| 556 | '<th class="nowrap count" scope="col">' . __('Version') . '</th>'; |
---|
| 557 | } |
---|
[2147] | 558 | |
---|
[3699] | 559 | if (in_array('current_version', $cols)) { |
---|
| 560 | echo |
---|
| 561 | '<th class="nowrap count" scope="col">' . __('Current version') . '</th>'; |
---|
| 562 | } |
---|
[2147] | 563 | |
---|
[3699] | 564 | if (in_array('desc', $cols)) { |
---|
| 565 | echo |
---|
[3775] | 566 | '<th class="nowrap module-desc" scope="col">' . __('Details') . '</th>'; |
---|
[3699] | 567 | } |
---|
[2147] | 568 | |
---|
[3699] | 569 | if (in_array('distrib', $cols)) { |
---|
| 570 | echo |
---|
| 571 | '<th' . (in_array('desc', $cols) ? '' : ' class="maximal"') . '></th>'; |
---|
| 572 | } |
---|
[2149] | 573 | |
---|
[3699] | 574 | if (!empty($actions) && $this->core->auth->isSuperAdmin()) { |
---|
| 575 | echo |
---|
| 576 | '<th class="minimal nowrap">' . __('Action') . '</th>'; |
---|
| 577 | } |
---|
[2147] | 578 | |
---|
[3699] | 579 | echo |
---|
| 580 | '</tr>'; |
---|
[2147] | 581 | |
---|
[3699] | 582 | $sort_field = $this->getSort(); |
---|
[2147] | 583 | |
---|
[3699] | 584 | # Sort modules by $sort_field (default sname) |
---|
| 585 | $modules = $this->getSearch() === null ? |
---|
| 586 | self::sortModules($this->data, $sort_field, $this->sort_asc) : |
---|
| 587 | $this->data; |
---|
[2147] | 588 | |
---|
[3699] | 589 | $count = 0; |
---|
| 590 | foreach ($modules as $id => $module) { |
---|
| 591 | # Show only requested modules |
---|
| 592 | if ($nav_limit && $this->getSearch() === null) { |
---|
| 593 | $char = substr($module[$sort_field], 0, 1); |
---|
| 594 | if (!in_array($char, $this->nav_list)) { |
---|
| 595 | $char = $this->nav_special; |
---|
| 596 | } |
---|
| 597 | if ($this->getIndex() != $char) { |
---|
| 598 | continue; |
---|
| 599 | } |
---|
| 600 | } |
---|
[2147] | 601 | |
---|
[3699] | 602 | echo |
---|
[3775] | 603 | '<tr class="line" id="' . html::escapeHTML($this->list_id) . '_m_' . html::escapeHTML($id) . '"' . |
---|
| 604 | (in_array('desc', $cols) ? ' title="' . html::escapeHTML(__($module['desc'])) . '" ' : '') . |
---|
| 605 | '>'; |
---|
[2431] | 606 | |
---|
[3699] | 607 | $tds = 0; |
---|
[2163] | 608 | |
---|
[3699] | 609 | if (in_array('checkbox', $cols)) { |
---|
| 610 | $tds++; |
---|
| 611 | echo |
---|
| 612 | '<td class="module-icon nowrap">' . |
---|
| 613 | form::checkbox(array('modules[' . $count . ']', html::escapeHTML($this->list_id) . '_modules_' . html::escapeHTML($id)), html::escapeHTML($id)) . |
---|
| 614 | '</td>'; |
---|
| 615 | } |
---|
[2487] | 616 | |
---|
[3699] | 617 | if (in_array('icon', $cols)) { |
---|
| 618 | $tds++; |
---|
| 619 | echo |
---|
| 620 | '<td class="module-icon nowrap">' . sprintf( |
---|
| 621 | '<img alt="%1$s" title="%1$s" src="%2$s" />', |
---|
| 622 | html::escapeHTML($id), file_exists($module['root'] . '/icon.png') ? |
---|
| 623 | dcPage::getPF($id . '/icon.png') : 'images/module.png' |
---|
| 624 | ) . '</td>'; |
---|
| 625 | } |
---|
[2156] | 626 | |
---|
[3699] | 627 | $tds++; |
---|
| 628 | echo |
---|
[3762] | 629 | '<th class="module-name nowrap" scope="row">'; |
---|
[3699] | 630 | if (in_array('checkbox', $cols)) { |
---|
| 631 | if (in_array('expander', $cols)) { |
---|
| 632 | echo |
---|
| 633 | html::escapeHTML($module['name']) . ($id != $module['name'] ? sprintf(__(' (%s)'), $id) : ''); |
---|
| 634 | } else { |
---|
| 635 | echo |
---|
| 636 | '<label for="' . html::escapeHTML($this->list_id) . '_modules_' . html::escapeHTML($id) . '">' . |
---|
| 637 | html::escapeHTML($module['name']) . ($id != $module['name'] ? sprintf(__(' (%s)'), $id) : '') . |
---|
| 638 | '</label>'; |
---|
| 639 | } |
---|
| 640 | } else { |
---|
| 641 | echo |
---|
| 642 | html::escapeHTML($module['name']) . ($id != $module['name'] ? sprintf(__(' (%s)'), $id) : '') . |
---|
| 643 | form::hidden(array('modules[' . $count . ']'), html::escapeHTML($id)); |
---|
| 644 | } |
---|
| 645 | echo |
---|
| 646 | $this->core->formNonce() . |
---|
| 647 | '</td>'; |
---|
[2147] | 648 | |
---|
[3699] | 649 | # Display score only for debug purpose |
---|
| 650 | if (in_array('score', $cols) && $this->getSearch() !== null && defined('DC_DEBUG') && DC_DEBUG) { |
---|
| 651 | $tds++; |
---|
| 652 | echo |
---|
| 653 | '<td class="module-version nowrap count"><span class="debug">' . $module['score'] . '</span></td>'; |
---|
| 654 | } |
---|
[2222] | 655 | |
---|
[3699] | 656 | if (in_array('version', $cols)) { |
---|
| 657 | $tds++; |
---|
| 658 | echo |
---|
| 659 | '<td class="module-version nowrap count">' . html::escapeHTML($module['version']) . '</td>'; |
---|
| 660 | } |
---|
[2147] | 661 | |
---|
[3699] | 662 | if (in_array('current_version', $cols)) { |
---|
| 663 | $tds++; |
---|
| 664 | echo |
---|
| 665 | '<td class="module-current-version nowrap count">' . html::escapeHTML($module['current_version']) . '</td>'; |
---|
| 666 | } |
---|
[2147] | 667 | |
---|
[3699] | 668 | if (in_array('desc', $cols)) { |
---|
| 669 | $tds++; |
---|
| 670 | echo |
---|
| 671 | '<td class="module-desc maximal">' . html::escapeHTML(__($module['desc'])); |
---|
| 672 | if (isset($module['cannot_disable']) && $module['enabled']) { |
---|
| 673 | echo |
---|
| 674 | '<br/><span class="info">' . |
---|
| 675 | sprintf(__('This module cannot be disabled nor deleted, since the following modules are also enabled : %s'), |
---|
| 676 | join(',', $module['cannot_disable'])) . |
---|
| 677 | '</span>'; |
---|
| 678 | } |
---|
| 679 | if (isset($module['cannot_enable']) && !$module['enabled']) { |
---|
| 680 | echo |
---|
| 681 | '<br/><span class="info">' . |
---|
| 682 | __('This module cannot be enabled, because of the following reasons :') . |
---|
| 683 | '<ul>'; |
---|
| 684 | foreach ($module['cannot_enable'] as $m => $reason) { |
---|
| 685 | echo '<li>' . $reason . '</li>'; |
---|
| 686 | } |
---|
| 687 | echo '</ul>' . |
---|
| 688 | '</span>'; |
---|
| 689 | } |
---|
| 690 | echo '</td>'; |
---|
[2997] | 691 | |
---|
[3699] | 692 | } |
---|
[2149] | 693 | |
---|
[3699] | 694 | if (in_array('distrib', $cols)) { |
---|
| 695 | $tds++; |
---|
| 696 | echo |
---|
| 697 | '<td class="module-distrib">' . (self::isDistributedModule($id) ? |
---|
| 698 | '<img src="images/dotclear_pw.png" alt="' . |
---|
| 699 | __('Plugin from official distribution') . '" title="' . |
---|
| 700 | __('Plugin from official distribution') . '" />' |
---|
| 701 | : '') . '</td>'; |
---|
| 702 | } |
---|
[2147] | 703 | |
---|
[3699] | 704 | if (!empty($actions) && $this->core->auth->isSuperAdmin()) { |
---|
| 705 | $buttons = $this->getActions($id, $module, $actions); |
---|
[2215] | 706 | |
---|
[3699] | 707 | $tds++; |
---|
| 708 | echo |
---|
| 709 | '<td class="module-actions nowrap">' . |
---|
[2147] | 710 | |
---|
[3699] | 711 | '<div>' . implode(' ', $buttons) . '</div>' . |
---|
[2215] | 712 | |
---|
[3699] | 713 | '</td>'; |
---|
| 714 | } |
---|
[2147] | 715 | |
---|
[3699] | 716 | echo |
---|
| 717 | '</tr>'; |
---|
[2147] | 718 | |
---|
[3699] | 719 | # Other informations |
---|
| 720 | if (in_array('expander', $cols)) { |
---|
| 721 | echo |
---|
| 722 | '<tr class="module-more"><td colspan="' . $tds . '" class="expand">'; |
---|
[2354] | 723 | |
---|
[3699] | 724 | if (!empty($module['author']) || !empty($module['details']) || !empty($module['support'])) { |
---|
| 725 | echo |
---|
| 726 | '<div><ul class="mod-more">'; |
---|
[2354] | 727 | |
---|
[3699] | 728 | if (!empty($module['author'])) { |
---|
| 729 | echo |
---|
| 730 | '<li class="module-author">' . __('Author:') . ' ' . html::escapeHTML($module['author']) . '</li>'; |
---|
| 731 | } |
---|
[2354] | 732 | |
---|
[3699] | 733 | $more = array(); |
---|
| 734 | if (!empty($module['details'])) { |
---|
| 735 | $more[] = '<a class="module-details" href="' . $module['details'] . '">' . __('Details') . '</a>'; |
---|
| 736 | } |
---|
[2354] | 737 | |
---|
[3699] | 738 | if (!empty($module['support'])) { |
---|
| 739 | $more[] = '<a class="module-support" href="' . $module['support'] . '">' . __('Support') . '</a>'; |
---|
| 740 | } |
---|
[2431] | 741 | |
---|
[3699] | 742 | if (!empty($more)) { |
---|
| 743 | echo |
---|
| 744 | '<li>' . implode(' - ', $more) . '</li>'; |
---|
| 745 | } |
---|
[2354] | 746 | |
---|
[3699] | 747 | echo |
---|
| 748 | '</ul></div>'; |
---|
| 749 | } |
---|
[2354] | 750 | |
---|
[3699] | 751 | $config = !empty($module['root']) && file_exists(path::real($module['root'] . '/_config.php')); |
---|
| 752 | $index = !empty($module['root']) && file_exists(path::real($module['root'] . '/index.php')); |
---|
[2354] | 753 | |
---|
[3699] | 754 | if ($config || $index || !empty($module['section']) || !empty($module['tags']) || !empty($module['settings'])) { |
---|
| 755 | echo |
---|
| 756 | '<div><ul class="mod-more">'; |
---|
[2354] | 757 | |
---|
[3699] | 758 | if ($index && $module['enabled']) { |
---|
| 759 | echo '<li><a href="' . $this->core->adminurl->get('admin.plugin.' . $id) . '">' . __('Manage plugin') . '</a></li>'; |
---|
| 760 | } |
---|
[3335] | 761 | |
---|
[3699] | 762 | $settings = $this->getSettingsUrls($this->core, $id); |
---|
| 763 | if (!empty($settings) && $module['enabled']) { |
---|
| 764 | echo '<li>' . implode(' - ', $settings) . '</li>'; |
---|
| 765 | } |
---|
[2354] | 766 | |
---|
[3699] | 767 | if (!empty($module['section'])) { |
---|
| 768 | echo |
---|
| 769 | '<li class="module-section">' . __('Section:') . ' ' . html::escapeHTML($module['section']) . '</li>'; |
---|
| 770 | } |
---|
[2354] | 771 | |
---|
[3699] | 772 | if (!empty($module['tags'])) { |
---|
| 773 | echo |
---|
| 774 | '<li class="module-tags">' . __('Tags:') . ' ' . html::escapeHTML($module['tags']) . '</li>'; |
---|
| 775 | } |
---|
[2354] | 776 | |
---|
[3699] | 777 | echo |
---|
| 778 | '</ul></div>'; |
---|
| 779 | } |
---|
[2354] | 780 | |
---|
[3699] | 781 | echo |
---|
| 782 | '</td></tr>'; |
---|
| 783 | } |
---|
[2354] | 784 | |
---|
[3699] | 785 | $count++; |
---|
| 786 | } |
---|
| 787 | echo |
---|
| 788 | '</table></div>'; |
---|
[2147] | 789 | |
---|
[3699] | 790 | if (!$count && $this->getSearch() === null) { |
---|
| 791 | echo |
---|
| 792 | '<p class="message">' . __('No plugins matched your search.') . '</p>'; |
---|
| 793 | } elseif ((in_array('checkbox', $cols) || $count > 1) && !empty($actions) && $this->core->auth->isSuperAdmin()) { |
---|
| 794 | $buttons = $this->getGlobalActions($actions, in_array('checkbox', $cols)); |
---|
[2227] | 795 | |
---|
[3699] | 796 | if (!empty($buttons)) { |
---|
| 797 | if (in_array('checkbox', $cols)) { |
---|
| 798 | echo |
---|
| 799 | '<p class="checkboxes-helpers"></p>'; |
---|
| 800 | } |
---|
| 801 | echo |
---|
| 802 | '<div>' . implode(' ', $buttons) . '</div>'; |
---|
| 803 | } |
---|
| 804 | } |
---|
| 805 | echo |
---|
| 806 | '</form>'; |
---|
[2428] | 807 | |
---|
[3699] | 808 | return $this; |
---|
| 809 | } |
---|
[2428] | 810 | |
---|
[3699] | 811 | /** |
---|
| 812 | * Get settings URLs if any |
---|
| 813 | * |
---|
| 814 | * @param object $core |
---|
| 815 | * @param string $id module ID |
---|
| 816 | * @param boolean $check check permission |
---|
| 817 | * @param boolean $self include self URL (→ plugin index.php URL) |
---|
| 818 | * @return Array of settings URLs |
---|
| 819 | */ |
---|
| 820 | public static function getSettingsUrls($core, $id, $check = false, $self = true) |
---|
| 821 | { |
---|
| 822 | $st = array(); |
---|
[2147] | 823 | |
---|
[3699] | 824 | $mr = $core->plugins->moduleRoot($id); |
---|
| 825 | $config = !empty($mr) && file_exists(path::real($mr . '/_config.php')); |
---|
| 826 | $settings = $core->plugins->moduleInfo($id, 'settings'); |
---|
| 827 | if ($config || !empty($settings)) { |
---|
| 828 | if ($config) { |
---|
| 829 | if (!$check || |
---|
| 830 | $core->auth->isSuperAdmin() || |
---|
| 831 | $core->auth->check($core->plugins->moduleInfo($id, 'permissions'), $core->blog->id)) { |
---|
| 832 | $params = array('module' => $id, 'conf' => '1'); |
---|
| 833 | if (!$core->plugins->moduleInfo($id, 'standalone_config') && !$self) { |
---|
| 834 | $params['redir'] = $core->adminurl->get('admin.plugin.' . $id); |
---|
| 835 | } |
---|
| 836 | $st[] = '<a class="module-config" href="' . |
---|
| 837 | $core->adminurl->get('admin.plugins', $params) . |
---|
| 838 | '">' . __('Configure plugin') . '</a>'; |
---|
| 839 | } |
---|
| 840 | } |
---|
| 841 | if (is_array($settings)) { |
---|
| 842 | foreach ($settings as $sk => $sv) { |
---|
| 843 | switch ($sk) { |
---|
| 844 | case 'blog': |
---|
| 845 | if (!$check || |
---|
| 846 | $core->auth->isSuperAdmin() || |
---|
| 847 | $core->auth->check('admin', $core->blog->id)) { |
---|
| 848 | $st[] = '<a class="module-config" href="' . |
---|
| 849 | $core->adminurl->get('admin.blog.pref') . $sv . |
---|
| 850 | '">' . __('Plugin settings (in blog parameters)') . '</a>'; |
---|
| 851 | } |
---|
| 852 | break; |
---|
| 853 | case 'pref': |
---|
| 854 | if (!$check || |
---|
| 855 | $core->auth->isSuperAdmin() || |
---|
| 856 | $core->auth->check('usage,contentadmin', $core->blog->id)) { |
---|
| 857 | $st[] = '<a class="module-config" href="' . |
---|
| 858 | $core->adminurl->get('admin.user.preferences') . $sv . |
---|
| 859 | '">' . __('Plugin settings (in user preferences)') . '</a>'; |
---|
| 860 | } |
---|
| 861 | break; |
---|
| 862 | case 'self': |
---|
| 863 | if ($self) { |
---|
| 864 | if (!$check || |
---|
| 865 | $core->auth->isSuperAdmin() || |
---|
| 866 | $core->auth->check($core->plugins->moduleInfo($id, 'permissions'), $core->blog->id)) { |
---|
| 867 | $st[] = '<a class="module-config" href="' . |
---|
| 868 | $core->adminurl->get('admin.plugin.' . $id) . $sv . |
---|
| 869 | '">' . __('Plugin settings') . '</a>'; |
---|
| 870 | } |
---|
| 871 | } |
---|
| 872 | break; |
---|
| 873 | } |
---|
| 874 | } |
---|
| 875 | } |
---|
| 876 | } |
---|
[3333] | 877 | |
---|
[3699] | 878 | return $st; |
---|
| 879 | } |
---|
[3333] | 880 | |
---|
[3699] | 881 | /** |
---|
| 882 | * Get action buttons to add to modules list. |
---|
| 883 | * |
---|
| 884 | * @param string $id Module ID |
---|
| 885 | * @param array $module Module info |
---|
| 886 | * @param array $actions Actions keys |
---|
| 887 | * @return Array of actions buttons |
---|
| 888 | */ |
---|
| 889 | protected function getActions($id, $module, $actions) |
---|
| 890 | { |
---|
| 891 | $submits = array(); |
---|
[3333] | 892 | |
---|
[3699] | 893 | # Use loop to keep requested order |
---|
| 894 | foreach ($actions as $action) { |
---|
| 895 | switch ($action) { |
---|
[2147] | 896 | |
---|
[3699] | 897 | # Deactivate |
---|
| 898 | case 'activate':if ($this->core->auth->isSuperAdmin() && $module['root_writable'] && !isset($module['cannot_enable'])) { |
---|
| 899 | $submits[] = |
---|
| 900 | '<input type="submit" name="activate[' . html::escapeHTML($id) . ']" value="' . __('Activate') . '" />'; |
---|
| 901 | }break; |
---|
[2215] | 902 | |
---|
[3699] | 903 | # Activate |
---|
| 904 | case 'deactivate':if ($this->core->auth->isSuperAdmin() && $module['root_writable'] && !isset($module['cannot_disable'])) { |
---|
| 905 | $submits[] = |
---|
| 906 | '<input type="submit" name="deactivate[' . html::escapeHTML($id) . ']" value="' . __('Deactivate') . '" class="reset" />'; |
---|
| 907 | }break; |
---|
[2215] | 908 | |
---|
[3699] | 909 | # Delete |
---|
| 910 | case 'delete':if ($this->core->auth->isSuperAdmin() && $this->isDeletablePath($module['root']) && !isset($module['cannot_disable'])) { |
---|
| 911 | $dev = !preg_match('!^' . $this->path_pattern . '!', $module['root']) && defined('DC_DEV') && DC_DEV ? ' debug' : ''; |
---|
| 912 | $submits[] = |
---|
| 913 | '<input type="submit" class="delete ' . $dev . '" name="delete[' . html::escapeHTML($id) . ']" value="' . __('Delete') . '" />'; |
---|
| 914 | }break; |
---|
[2215] | 915 | |
---|
[3699] | 916 | # Install (from store) |
---|
| 917 | case 'install':if ($this->core->auth->isSuperAdmin() && $this->path_writable) { |
---|
| 918 | $submits[] = |
---|
| 919 | '<input type="submit" name="install[' . html::escapeHTML($id) . ']" value="' . __('Install') . '" />'; |
---|
| 920 | }break; |
---|
[2215] | 921 | |
---|
[3699] | 922 | # Update (from store) |
---|
| 923 | case 'update':if ($this->core->auth->isSuperAdmin() && $this->path_writable) { |
---|
| 924 | $submits[] = |
---|
| 925 | '<input type="submit" name="update[' . html::escapeHTML($id) . ']" value="' . __('Update') . '" />'; |
---|
| 926 | }break; |
---|
[2215] | 927 | |
---|
[3699] | 928 | # Behavior |
---|
| 929 | case 'behavior': |
---|
[2241] | 930 | |
---|
[3699] | 931 | # --BEHAVIOR-- adminModulesListGetActions |
---|
| 932 | $tmp = $this->core->callBehavior('adminModulesListGetActions', $this, $id, $module); |
---|
[2241] | 933 | |
---|
[3699] | 934 | if (!empty($tmp)) { |
---|
| 935 | $submits[] = $tmp; |
---|
| 936 | } |
---|
| 937 | break; |
---|
| 938 | } |
---|
| 939 | } |
---|
[2241] | 940 | |
---|
[3699] | 941 | return $submits; |
---|
| 942 | } |
---|
[2192] | 943 | |
---|
[3699] | 944 | /** |
---|
| 945 | * Get global action buttons to add to modules list. |
---|
| 946 | * |
---|
| 947 | * @param array $actions Actions keys |
---|
| 948 | * @param boolean $with_selection Limit action to selected modules |
---|
| 949 | * @return Array of actions buttons |
---|
| 950 | */ |
---|
| 951 | protected function getGlobalActions($actions, $with_selection = false) |
---|
| 952 | { |
---|
| 953 | $submits = array(); |
---|
[2428] | 954 | |
---|
[3699] | 955 | # Use loop to keep requested order |
---|
| 956 | foreach ($actions as $action) { |
---|
| 957 | switch ($action) { |
---|
[2428] | 958 | |
---|
[3699] | 959 | # Deactivate |
---|
| 960 | case 'activate':if ($this->core->auth->isSuperAdmin() && $this->path_writable) { |
---|
| 961 | $submits[] = |
---|
| 962 | '<input type="submit" name="activate" value="' . ($with_selection ? |
---|
| 963 | __('Activate selected plugins') : |
---|
| 964 | __('Activate all plugins from this list') |
---|
| 965 | ) . '" />'; |
---|
| 966 | }break; |
---|
[2428] | 967 | |
---|
[3699] | 968 | # Activate |
---|
| 969 | case 'deactivate':if ($this->core->auth->isSuperAdmin() && $this->path_writable) { |
---|
| 970 | $submits[] = |
---|
| 971 | '<input type="submit" name="deactivate" value="' . ($with_selection ? |
---|
| 972 | __('Deactivate selected plugins') : |
---|
| 973 | __('Deactivate all plugins from this list') |
---|
| 974 | ) . '" />'; |
---|
| 975 | }break; |
---|
[2428] | 976 | |
---|
[3699] | 977 | # Update (from store) |
---|
| 978 | case 'update':if ($this->core->auth->isSuperAdmin() && $this->path_writable) { |
---|
| 979 | $submits[] = |
---|
| 980 | '<input type="submit" name="update" value="' . ($with_selection ? |
---|
| 981 | __('Update selected plugins') : |
---|
| 982 | __('Update all plugins from this list') |
---|
| 983 | ) . '" />'; |
---|
| 984 | }break; |
---|
[2428] | 985 | |
---|
[3699] | 986 | # Behavior |
---|
| 987 | case 'behavior': |
---|
[2428] | 988 | |
---|
[3699] | 989 | # --BEHAVIOR-- adminModulesListGetGlobalActions |
---|
| 990 | $tmp = $this->core->callBehavior('adminModulesListGetGlobalActions', $this, $with_selection); |
---|
[2428] | 991 | |
---|
[3699] | 992 | if (!empty($tmp)) { |
---|
| 993 | $submits[] = $tmp; |
---|
| 994 | } |
---|
| 995 | break; |
---|
| 996 | } |
---|
| 997 | } |
---|
[2428] | 998 | |
---|
[3699] | 999 | return $submits; |
---|
| 1000 | } |
---|
[2241] | 1001 | |
---|
[3699] | 1002 | /** |
---|
| 1003 | * Execute POST action. |
---|
| 1004 | * |
---|
| 1005 | * @note Set a notice on success through dcPage::addSuccessNotice |
---|
| 1006 | * @throw Exception Module not find or command failed |
---|
| 1007 | * @return Null |
---|
| 1008 | */ |
---|
| 1009 | public function doActions() |
---|
| 1010 | { |
---|
| 1011 | if (empty($_POST) || !empty($_REQUEST['conf']) |
---|
| 1012 | || !$this->isWritablePath()) { |
---|
| 1013 | return; |
---|
| 1014 | } |
---|
[2147] | 1015 | |
---|
[3699] | 1016 | $modules = !empty($_POST['modules']) && is_array($_POST['modules']) ? array_values($_POST['modules']) : array(); |
---|
[2149] | 1017 | |
---|
[3699] | 1018 | if ($this->core->auth->isSuperAdmin() && !empty($_POST['delete'])) { |
---|
[2149] | 1019 | |
---|
[3699] | 1020 | if (is_array($_POST['delete'])) { |
---|
| 1021 | $modules = array_keys($_POST['delete']); |
---|
| 1022 | } |
---|
[2149] | 1023 | |
---|
[3699] | 1024 | $list = $this->modules->getDisabledModules(); |
---|
[2149] | 1025 | |
---|
[3699] | 1026 | $failed = false; |
---|
| 1027 | $count = 0; |
---|
| 1028 | foreach ($modules as $id) { |
---|
| 1029 | if (!isset($list[$id])) { |
---|
[2149] | 1030 | |
---|
[3699] | 1031 | if (!$this->modules->moduleExists($id)) { |
---|
| 1032 | throw new Exception(__('No such plugin.')); |
---|
| 1033 | } |
---|
[2171] | 1034 | |
---|
[3699] | 1035 | $module = $this->modules->getModules($id); |
---|
| 1036 | $module['id'] = $id; |
---|
[2171] | 1037 | |
---|
[3699] | 1038 | if (!$this->isDeletablePath($module['root'])) { |
---|
| 1039 | $failed = true; |
---|
| 1040 | continue; |
---|
| 1041 | } |
---|
[2171] | 1042 | |
---|
[3699] | 1043 | # --BEHAVIOR-- moduleBeforeDelete |
---|
| 1044 | $this->core->callBehavior('pluginBeforeDelete', $module); |
---|
[2171] | 1045 | |
---|
[3699] | 1046 | $this->modules->deleteModule($id); |
---|
[2171] | 1047 | |
---|
[3699] | 1048 | # --BEHAVIOR-- moduleAfterDelete |
---|
| 1049 | $this->core->callBehavior('pluginAfterDelete', $module); |
---|
| 1050 | } else { |
---|
| 1051 | $this->modules->deleteModule($id, true); |
---|
| 1052 | } |
---|
[2171] | 1053 | |
---|
[3699] | 1054 | $count++; |
---|
| 1055 | } |
---|
[2171] | 1056 | |
---|
[3699] | 1057 | if (!$count && $failed) { |
---|
| 1058 | throw new Exception(__("You don't have permissions to delete this plugin.")); |
---|
| 1059 | } elseif ($failed) { |
---|
| 1060 | dcPage::addWarningNotice(__('Some plugins have not been delete.')); |
---|
| 1061 | } else { |
---|
| 1062 | dcPage::addSuccessNotice( |
---|
| 1063 | __('Plugin has been successfully deleted.', 'Plugins have been successuflly deleted.', $count) |
---|
| 1064 | ); |
---|
| 1065 | } |
---|
| 1066 | http::redirect($this->getURL()); |
---|
| 1067 | } elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['install'])) { |
---|
[2215] | 1068 | |
---|
[3699] | 1069 | if (is_array($_POST['install'])) { |
---|
| 1070 | $modules = array_keys($_POST['install']); |
---|
| 1071 | } |
---|
[2487] | 1072 | |
---|
[3699] | 1073 | $list = $this->store->get(); |
---|
[2487] | 1074 | |
---|
[3699] | 1075 | if (empty($list)) { |
---|
| 1076 | throw new Exception(__('No such plugin.')); |
---|
| 1077 | } |
---|
[2487] | 1078 | |
---|
[3699] | 1079 | $count = 0; |
---|
| 1080 | foreach ($list as $id => $module) { |
---|
[2487] | 1081 | |
---|
[3699] | 1082 | if (!in_array($id, $modules)) { |
---|
| 1083 | continue; |
---|
| 1084 | } |
---|
[2487] | 1085 | |
---|
[3699] | 1086 | $dest = $this->getPath() . '/' . basename($module['file']); |
---|
[2487] | 1087 | |
---|
[3699] | 1088 | # --BEHAVIOR-- moduleBeforeAdd |
---|
| 1089 | $this->core->callBehavior('pluginBeforeAdd', $module); |
---|
[2215] | 1090 | |
---|
[3699] | 1091 | $this->store->process($module['file'], $dest); |
---|
[2215] | 1092 | |
---|
[3699] | 1093 | # --BEHAVIOR-- moduleAfterAdd |
---|
| 1094 | $this->core->callBehavior('pluginAfterAdd', $module); |
---|
[2215] | 1095 | |
---|
[3699] | 1096 | $count++; |
---|
| 1097 | } |
---|
[2215] | 1098 | |
---|
[3699] | 1099 | dcPage::addSuccessNotice( |
---|
| 1100 | __('Plugin has been successfully installed.', 'Plugins have been successuflly installed.', $count) |
---|
| 1101 | ); |
---|
| 1102 | http::redirect($this->getURL()); |
---|
| 1103 | } elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['activate'])) { |
---|
[2215] | 1104 | |
---|
[3699] | 1105 | if (is_array($_POST['activate'])) { |
---|
| 1106 | $modules = array_keys($_POST['activate']); |
---|
| 1107 | } |
---|
[2215] | 1108 | |
---|
[3699] | 1109 | $list = $this->modules->getDisabledModules(); |
---|
| 1110 | if (empty($list)) { |
---|
| 1111 | throw new Exception(__('No such plugin.')); |
---|
| 1112 | } |
---|
[2171] | 1113 | |
---|
[3699] | 1114 | $count = 0; |
---|
| 1115 | foreach ($list as $id => $module) { |
---|
[2487] | 1116 | |
---|
[3699] | 1117 | if (!in_array($id, $modules)) { |
---|
| 1118 | continue; |
---|
| 1119 | } |
---|
[2487] | 1120 | |
---|
[3699] | 1121 | # --BEHAVIOR-- moduleBeforeActivate |
---|
| 1122 | $this->core->callBehavior('pluginBeforeActivate', $id); |
---|
[2487] | 1123 | |
---|
[3699] | 1124 | $this->modules->activateModule($id); |
---|
[2487] | 1125 | |
---|
[3699] | 1126 | # --BEHAVIOR-- moduleAfterActivate |
---|
| 1127 | $this->core->callBehavior('pluginAfterActivate', $id); |
---|
[2171] | 1128 | |
---|
[3699] | 1129 | $count++; |
---|
| 1130 | } |
---|
[2487] | 1131 | |
---|
[3699] | 1132 | dcPage::addSuccessNotice( |
---|
| 1133 | __('Plugin has been successfully activated.', 'Plugins have been successuflly activated.', $count) |
---|
| 1134 | ); |
---|
| 1135 | http::redirect($this->getURL()); |
---|
| 1136 | } elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['deactivate'])) { |
---|
[2487] | 1137 | |
---|
[3699] | 1138 | if (is_array($_POST['deactivate'])) { |
---|
| 1139 | $modules = array_keys($_POST['deactivate']); |
---|
| 1140 | } |
---|
[2487] | 1141 | |
---|
[3699] | 1142 | $list = $this->modules->getModules(); |
---|
| 1143 | if (empty($list)) { |
---|
| 1144 | throw new Exception(__('No such plugin.')); |
---|
| 1145 | } |
---|
[2487] | 1146 | |
---|
[3699] | 1147 | $failed = false; |
---|
| 1148 | $count = 0; |
---|
| 1149 | foreach ($list as $id => $module) { |
---|
[2487] | 1150 | |
---|
[3699] | 1151 | if (!in_array($id, $modules)) { |
---|
| 1152 | continue; |
---|
| 1153 | } |
---|
[2487] | 1154 | |
---|
[3699] | 1155 | if (!$module['root_writable']) { |
---|
| 1156 | $failed = true; |
---|
| 1157 | continue; |
---|
| 1158 | } |
---|
[2487] | 1159 | |
---|
[3699] | 1160 | $module[$id] = $id; |
---|
[2487] | 1161 | |
---|
[3699] | 1162 | # --BEHAVIOR-- moduleBeforeDeactivate |
---|
| 1163 | $this->core->callBehavior('pluginBeforeDeactivate', $module); |
---|
[2487] | 1164 | |
---|
[3699] | 1165 | $this->modules->deactivateModule($id); |
---|
[2171] | 1166 | |
---|
[3699] | 1167 | # --BEHAVIOR-- moduleAfterDeactivate |
---|
| 1168 | $this->core->callBehavior('pluginAfterDeactivate', $module); |
---|
[2270] | 1169 | |
---|
[3699] | 1170 | $count++; |
---|
| 1171 | } |
---|
[2487] | 1172 | |
---|
[3699] | 1173 | if ($failed) { |
---|
| 1174 | dcPage::addWarningNotice(__('Some plugins have not been deactivated.')); |
---|
| 1175 | } else { |
---|
| 1176 | dcPage::addSuccessNotice( |
---|
| 1177 | __('Plugin has been successfully deactivated.', 'Plugins have been successuflly deactivated.', $count) |
---|
| 1178 | ); |
---|
| 1179 | } |
---|
| 1180 | http::redirect($this->getURL()); |
---|
| 1181 | } elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['update'])) { |
---|
[2487] | 1182 | |
---|
[3699] | 1183 | if (is_array($_POST['update'])) { |
---|
| 1184 | $modules = array_keys($_POST['update']); |
---|
| 1185 | } |
---|
[2487] | 1186 | |
---|
[3699] | 1187 | $list = $this->store->get(true); |
---|
| 1188 | if (empty($list)) { |
---|
| 1189 | throw new Exception(__('No such plugin.')); |
---|
| 1190 | } |
---|
[2487] | 1191 | |
---|
[3699] | 1192 | $count = 0; |
---|
| 1193 | foreach ($list as $module) { |
---|
[2487] | 1194 | |
---|
[3699] | 1195 | if (!in_array($module['id'], $modules)) { |
---|
| 1196 | continue; |
---|
| 1197 | } |
---|
[2487] | 1198 | |
---|
[3699] | 1199 | if (!self::$allow_multi_install) { |
---|
| 1200 | $dest = $module['root'] . '/../' . basename($module['file']); |
---|
| 1201 | } else { |
---|
| 1202 | $dest = $this->getPath() . '/' . basename($module['file']); |
---|
| 1203 | if ($module['root'] != $dest) { |
---|
| 1204 | @file_put_contents($module['root'] . '/_disabled', ''); |
---|
| 1205 | } |
---|
| 1206 | } |
---|
[2487] | 1207 | |
---|
[3699] | 1208 | # --BEHAVIOR-- moduleBeforeUpdate |
---|
| 1209 | $this->core->callBehavior('pluginBeforeUpdate', $module); |
---|
[2487] | 1210 | |
---|
[3699] | 1211 | $this->store->process($module['file'], $dest); |
---|
[2487] | 1212 | |
---|
[3699] | 1213 | # --BEHAVIOR-- moduleAfterUpdate |
---|
| 1214 | $this->core->callBehavior('pluginAfterUpdate', $module); |
---|
[2487] | 1215 | |
---|
[3699] | 1216 | $count++; |
---|
| 1217 | } |
---|
[2227] | 1218 | |
---|
[3699] | 1219 | $tab = $count && $count == count($list) ? '#plugins' : '#update'; |
---|
[2171] | 1220 | |
---|
[3699] | 1221 | dcPage::addSuccessNotice( |
---|
| 1222 | __('Plugin has been successfully updated.', 'Plugins have been successuflly updated.', $count) |
---|
| 1223 | ); |
---|
| 1224 | http::redirect($this->getURL() . $tab); |
---|
| 1225 | } |
---|
[2171] | 1226 | |
---|
[3699] | 1227 | # Manual actions |
---|
| 1228 | elseif (!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file']) |
---|
| 1229 | || !empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url'])) { |
---|
| 1230 | if (empty($_POST['your_pwd']) || !$this->core->auth->checkPassword($_POST['your_pwd'])) { |
---|
| 1231 | throw new Exception(__('Password verification failed')); |
---|
| 1232 | } |
---|
[2171] | 1233 | |
---|
[3699] | 1234 | if (!empty($_POST['upload_pkg'])) { |
---|
| 1235 | files::uploadStatus($_FILES['pkg_file']); |
---|
[2171] | 1236 | |
---|
[3699] | 1237 | $dest = $this->getPath() . '/' . $_FILES['pkg_file']['name']; |
---|
| 1238 | if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'], $dest)) { |
---|
| 1239 | throw new Exception(__('Unable to move uploaded file.')); |
---|
| 1240 | } |
---|
| 1241 | } else { |
---|
| 1242 | $url = urldecode($_POST['pkg_url']); |
---|
| 1243 | $dest = $this->getPath() . '/' . basename($url); |
---|
| 1244 | $this->store->download($url, $dest); |
---|
| 1245 | } |
---|
[2428] | 1246 | |
---|
[3699] | 1247 | # --BEHAVIOR-- moduleBeforeAdd |
---|
| 1248 | $this->core->callBehavior('pluginBeforeAdd', null); |
---|
[2428] | 1249 | |
---|
[3699] | 1250 | $ret_code = $this->store->install($dest); |
---|
[2428] | 1251 | |
---|
[3699] | 1252 | # --BEHAVIOR-- moduleAfterAdd |
---|
| 1253 | $this->core->callBehavior('pluginAfterAdd', null); |
---|
[2171] | 1254 | |
---|
[3699] | 1255 | dcPage::addSuccessNotice($ret_code == 2 ? |
---|
| 1256 | __('Plugin has been successfully updated.') : |
---|
| 1257 | __('Plugin has been successfully installed.') |
---|
| 1258 | ); |
---|
| 1259 | http::redirect($this->getURL() . '#plugins'); |
---|
| 1260 | } else { |
---|
[2431] | 1261 | |
---|
[3699] | 1262 | # --BEHAVIOR-- adminModulesListDoActions |
---|
| 1263 | $this->core->callBehavior('adminModulesListDoActions', $this, $modules, 'plugin'); |
---|
[2149] | 1264 | |
---|
[3699] | 1265 | } |
---|
[2171] | 1266 | |
---|
[3699] | 1267 | return; |
---|
| 1268 | } |
---|
[2171] | 1269 | |
---|
[3699] | 1270 | /** |
---|
| 1271 | * Display tab for manual installation. |
---|
| 1272 | * |
---|
| 1273 | * @return adminModulesList self instance |
---|
| 1274 | */ |
---|
| 1275 | public function displayManualForm() |
---|
| 1276 | { |
---|
| 1277 | if (!$this->core->auth->isSuperAdmin() || !$this->isWritablePath()) { |
---|
| 1278 | return; |
---|
| 1279 | } |
---|
[2171] | 1280 | |
---|
[3699] | 1281 | # 'Upload module' form |
---|
| 1282 | echo |
---|
| 1283 | '<form method="post" action="' . $this->getURL() . '" id="uploadpkg" enctype="multipart/form-data" class="fieldset">' . |
---|
| 1284 | '<h4>' . __('Upload a zip file') . '</h4>' . |
---|
| 1285 | '<p class="field"><label for="pkg_file" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Zip file path:') . '</label> ' . |
---|
| 1286 | '<input type="file" name="pkg_file" id="pkg_file" required /></p>' . |
---|
| 1287 | '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Your password:') . '</label> ' . |
---|
| 1288 | form::password(array('your_pwd', 'your_pwd1'), 20, 255, |
---|
| 1289 | array( |
---|
| 1290 | 'extra_html' => 'required placeholder="' . __('Password') . '"', |
---|
| 1291 | 'autocomplete' => 'current-password' |
---|
| 1292 | ) |
---|
| 1293 | ) . '</p>' . |
---|
| 1294 | '<p><input type="submit" name="upload_pkg" value="' . __('Upload') . '" />' . |
---|
| 1295 | $this->core->formNonce() . '</p>' . |
---|
| 1296 | '</form>'; |
---|
[2192] | 1297 | |
---|
[3699] | 1298 | # 'Fetch module' form |
---|
| 1299 | echo |
---|
| 1300 | '<form method="post" action="' . $this->getURL() . '" id="fetchpkg" class="fieldset">' . |
---|
| 1301 | '<h4>' . __('Download a zip file') . '</h4>' . |
---|
| 1302 | '<p class="field"><label for="pkg_url" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Zip file URL:') . '</label> ' . |
---|
[3725] | 1303 | form::field('pkg_url', 40, 255, array( |
---|
| 1304 | 'extra_html' => 'required placeholder="' . __('URL') . '"' |
---|
| 1305 | )) . |
---|
| 1306 | '</p>' . |
---|
[3699] | 1307 | '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Your password:') . '</label> ' . |
---|
| 1308 | form::password(array('your_pwd', 'your_pwd2'), 20, 255, |
---|
| 1309 | array( |
---|
| 1310 | 'extra_html' => 'required placeholder="' . __('Password') . '"', |
---|
| 1311 | 'autocomplete' => 'current-password' |
---|
| 1312 | ) |
---|
| 1313 | ) . '</p>' . |
---|
| 1314 | '<p><input type="submit" name="fetch_pkg" value="' . __('Download') . '" />' . |
---|
| 1315 | $this->core->formNonce() . '</p>' . |
---|
| 1316 | '</form>'; |
---|
[2487] | 1317 | |
---|
[3699] | 1318 | return $this; |
---|
| 1319 | } |
---|
| 1320 | //@} |
---|
[2487] | 1321 | |
---|
[3699] | 1322 | /// @name Module configuration methods |
---|
| 1323 | //@{ |
---|
| 1324 | /** |
---|
| 1325 | * Prepare module configuration. |
---|
| 1326 | * |
---|
| 1327 | * We need to get configuration content in three steps |
---|
| 1328 | * and out of this class to keep backward compatibility. |
---|
| 1329 | * |
---|
| 1330 | * if ($xxx->setConfiguration()) { |
---|
| 1331 | * include $xxx->includeConfiguration(); |
---|
| 1332 | * } |
---|
| 1333 | * $xxx->getConfiguration(); |
---|
| 1334 | * ... [put here page headers and other stuff] |
---|
| 1335 | * $xxx->displayConfiguration(); |
---|
| 1336 | * |
---|
| 1337 | * @param string $id Module to work on or it gather through REQUEST |
---|
| 1338 | * @return True if config set |
---|
| 1339 | */ |
---|
| 1340 | public function setConfiguration($id = null) |
---|
| 1341 | { |
---|
| 1342 | if (empty($_REQUEST['conf']) || empty($_REQUEST['module']) && !$id) { |
---|
| 1343 | return false; |
---|
| 1344 | } |
---|
[2487] | 1345 | |
---|
[3699] | 1346 | if (!empty($_REQUEST['module']) && empty($id)) { |
---|
| 1347 | $id = $_REQUEST['module']; |
---|
| 1348 | } |
---|
[2171] | 1349 | |
---|
[3699] | 1350 | if (!$this->modules->moduleExists($id)) { |
---|
| 1351 | $this->core->error->add(__('Unknow plugin ID')); |
---|
| 1352 | return false; |
---|
| 1353 | } |
---|
[2149] | 1354 | |
---|
[3699] | 1355 | $module = $this->modules->getModules($id); |
---|
| 1356 | $module = self::sanitizeModule($id, $module); |
---|
| 1357 | $file = path::real($module['root'] . '/_config.php'); |
---|
[2227] | 1358 | |
---|
[3699] | 1359 | if (!file_exists($file)) { |
---|
| 1360 | $this->core->error->add(__('This plugin has no configuration file.')); |
---|
| 1361 | return false; |
---|
| 1362 | } |
---|
[2227] | 1363 | |
---|
[3699] | 1364 | $this->config_module = $module; |
---|
| 1365 | $this->config_file = $file; |
---|
| 1366 | $this->config_content = ''; |
---|
[2149] | 1367 | |
---|
[3699] | 1368 | if (!defined('DC_CONTEXT_MODULE')) { |
---|
| 1369 | define('DC_CONTEXT_MODULE', true); |
---|
| 1370 | } |
---|
[2431] | 1371 | |
---|
[3699] | 1372 | return true; |
---|
| 1373 | } |
---|
[2182] | 1374 | |
---|
[3699] | 1375 | /** |
---|
| 1376 | * Get path of module configuration file. |
---|
| 1377 | * |
---|
| 1378 | * @note Required previously set file info |
---|
| 1379 | * @return Full path of config file or null |
---|
| 1380 | */ |
---|
| 1381 | public function includeConfiguration() |
---|
| 1382 | { |
---|
| 1383 | if (!$this->config_file) { |
---|
| 1384 | return; |
---|
| 1385 | } |
---|
| 1386 | $this->setRedir($this->getURL() . '#plugins'); |
---|
[2182] | 1387 | |
---|
[3699] | 1388 | ob_start(); |
---|
[2182] | 1389 | |
---|
[3699] | 1390 | return $this->config_file; |
---|
| 1391 | } |
---|
[2182] | 1392 | |
---|
[3699] | 1393 | /** |
---|
| 1394 | * Gather module configuration file content. |
---|
| 1395 | * |
---|
| 1396 | * @note Required previously file inclusion |
---|
| 1397 | * @return True if content has been captured |
---|
| 1398 | */ |
---|
| 1399 | public function getConfiguration() |
---|
| 1400 | { |
---|
| 1401 | if ($this->config_file) { |
---|
| 1402 | $this->config_content = ob_get_contents(); |
---|
| 1403 | } |
---|
[2182] | 1404 | |
---|
[3699] | 1405 | ob_end_clean(); |
---|
[2182] | 1406 | |
---|
[3699] | 1407 | return !empty($this->file_content); |
---|
| 1408 | } |
---|
[2182] | 1409 | |
---|
[3699] | 1410 | /** |
---|
| 1411 | * Display module configuration form. |
---|
| 1412 | * |
---|
| 1413 | * @note Required previously gathered content |
---|
| 1414 | * @return adminModulesList self instance |
---|
| 1415 | */ |
---|
| 1416 | public function displayConfiguration() |
---|
| 1417 | { |
---|
| 1418 | if ($this->config_file) { |
---|
[2182] | 1419 | |
---|
[3699] | 1420 | if (!$this->config_module['standalone_config']) { |
---|
| 1421 | echo |
---|
| 1422 | '<form id="module_config" action="' . $this->getURL('conf=1') . '" method="post" enctype="multipart/form-data">' . |
---|
| 1423 | '<h3>' . sprintf(__('Configure "%s"'), html::escapeHTML($this->config_module['name'])) . '</h3>' . |
---|
| 1424 | '<p><a class="back" href="' . $this->getRedir() . '">' . __('Back') . '</a></p>'; |
---|
| 1425 | } |
---|
[2182] | 1426 | |
---|
[3699] | 1427 | echo $this->config_content; |
---|
[2182] | 1428 | |
---|
[3699] | 1429 | if (!$this->config_module['standalone_config']) { |
---|
| 1430 | echo |
---|
| 1431 | '<p class="clear"><input type="submit" name="save" value="' . __('Save') . '" />' . |
---|
| 1432 | form::hidden('module', $this->config_module['id']) . |
---|
| 1433 | form::hidden('redir', $this->getRedir()) . |
---|
| 1434 | $this->core->formNonce() . '</p>' . |
---|
| 1435 | '</form>'; |
---|
| 1436 | } |
---|
| 1437 | } |
---|
[2182] | 1438 | |
---|
[3699] | 1439 | return $this; |
---|
| 1440 | } |
---|
| 1441 | //@} |
---|
[2182] | 1442 | |
---|
[3699] | 1443 | /** |
---|
| 1444 | * Helper to sanitize a string. |
---|
| 1445 | * |
---|
| 1446 | * Used for search or id. |
---|
| 1447 | * |
---|
| 1448 | * @param string $str String to sanitize |
---|
| 1449 | * @return Sanitized string |
---|
| 1450 | */ |
---|
| 1451 | public static function sanitizeString($str) |
---|
| 1452 | { |
---|
| 1453 | return preg_replace('/[^A-Za-z0-9\@\#+_-]/', '', strtolower($str)); |
---|
| 1454 | } |
---|
[2147] | 1455 | } |
---|
| 1456 | |
---|
[2227] | 1457 | /** |
---|
| 1458 | * @ingroup DC_CORE |
---|
| 1459 | * @brief Helper to manage list of themes. |
---|
| 1460 | * @since 2.6 |
---|
| 1461 | */ |
---|
[2147] | 1462 | class adminThemesList extends adminModulesList |
---|
| 1463 | { |
---|
[3699] | 1464 | /** |
---|
| 1465 | * Constructor. |
---|
| 1466 | * |
---|
| 1467 | * Note that this creates dcStore instance. |
---|
| 1468 | * |
---|
| 1469 | * @param object $modules dcModules instance |
---|
| 1470 | * @param string $modules_root Modules root directories |
---|
| 1471 | * @param string $xml_url URL of modules feed from repository |
---|
| 1472 | */ |
---|
| 1473 | public function __construct(dcModules $modules, $modules_root, $xml_url) |
---|
| 1474 | { |
---|
| 1475 | parent::__construct($modules, $modules_root, $xml_url); |
---|
| 1476 | $this->page_url = $this->core->adminurl->get('admin.blog.theme'); |
---|
| 1477 | } |
---|
[2147] | 1478 | |
---|
[3699] | 1479 | public function displayModules($cols = array('name', 'config', 'version', 'desc'), $actions = array(), $nav_limit = false) |
---|
| 1480 | { |
---|
| 1481 | echo |
---|
| 1482 | '<form action="' . $this->getURL() . '" method="post" class="modules-form-actions">' . |
---|
| 1483 | '<div id="' . html::escapeHTML($this->list_id) . '" class="modules' . (in_array('expander', $cols) ? ' expandable' : '') . ' one-box">'; |
---|
[2171] | 1484 | |
---|
[3699] | 1485 | $sort_field = $this->getSort(); |
---|
[2171] | 1486 | |
---|
[3699] | 1487 | # Sort modules by id |
---|
| 1488 | $modules = $this->getSearch() === null ? |
---|
| 1489 | self::sortModules($this->data, $sort_field, $this->sort_asc) : |
---|
| 1490 | $this->data; |
---|
[2171] | 1491 | |
---|
[3699] | 1492 | $res = ''; |
---|
| 1493 | $count = 0; |
---|
| 1494 | foreach ($modules as $id => $module) { |
---|
| 1495 | # Show only requested modules |
---|
| 1496 | if ($nav_limit && $this->getSearch() === null) { |
---|
| 1497 | $char = substr($module[$sort_field], 0, 1); |
---|
| 1498 | if (!in_array($char, $this->nav_list)) { |
---|
| 1499 | $char = $this->nav_special; |
---|
| 1500 | } |
---|
| 1501 | if ($this->getIndex() != $char) { |
---|
| 1502 | continue; |
---|
| 1503 | } |
---|
| 1504 | } |
---|
[2171] | 1505 | |
---|
[3699] | 1506 | $current = $this->core->blog->settings->system->theme == $id && $this->modules->moduleExists($id); |
---|
| 1507 | $distrib = self::isDistributedModule($id) ? ' dc-box' : ''; |
---|
[2171] | 1508 | |
---|
[3699] | 1509 | $line = |
---|
| 1510 | '<div class="box ' . ($current ? 'medium current-theme' : 'theme') . $distrib . '">'; |
---|
[2171] | 1511 | |
---|
[3699] | 1512 | if (in_array('name', $cols) && !$current) { |
---|
| 1513 | $line .= |
---|
| 1514 | '<h4 class="module-name">'; |
---|
[2487] | 1515 | |
---|
[3699] | 1516 | if (in_array('checkbox', $cols)) { |
---|
| 1517 | $line .= |
---|
| 1518 | '<label for="' . html::escapeHTML($this->list_id) . '_modules_' . html::escapeHTML($id) . '">' . |
---|
| 1519 | form::checkbox(array('modules[' . $count . ']', html::escapeHTML($this->list_id) . '_modules_' . html::escapeHTML($id)), html::escapeHTML($id)) . |
---|
| 1520 | html::escapeHTML($module['name']) . |
---|
| 1521 | '</label>'; |
---|
[2487] | 1522 | |
---|
[3699] | 1523 | } else { |
---|
| 1524 | $line .= |
---|
| 1525 | form::hidden(array('modules[' . $count . ']'), html::escapeHTML($id)) . |
---|
| 1526 | html::escapeHTML($module['name']); |
---|
| 1527 | } |
---|
[2487] | 1528 | |
---|
[3699] | 1529 | $line .= |
---|
| 1530 | $this->core->formNonce() . |
---|
| 1531 | '</h4>'; |
---|
| 1532 | } |
---|
[2171] | 1533 | |
---|
[3699] | 1534 | # Display score only for debug purpose |
---|
| 1535 | if (in_array('score', $cols) && $this->getSearch() !== null && defined('DC_DEBUG') && DC_DEBUG) { |
---|
| 1536 | $line .= |
---|
| 1537 | '<p class="module-score debug">' . sprintf(__('Score: %s'), $module['score']) . '</p>'; |
---|
| 1538 | } |
---|
[2222] | 1539 | |
---|
[3699] | 1540 | if (in_array('sshot', $cols)) { |
---|
| 1541 | # Screenshot from url |
---|
| 1542 | if (preg_match('#^http(s)?://#', $module['sshot'])) { |
---|
| 1543 | $sshot = $module['sshot']; |
---|
| 1544 | } |
---|
| 1545 | # Screenshot from installed module |
---|
| 1546 | elseif (file_exists($this->core->blog->themes_path . '/' . $id . '/screenshot.jpg')) { |
---|
| 1547 | $sshot = $this->getURL('shot=' . rawurlencode($id)); |
---|
| 1548 | } |
---|
| 1549 | # Default screenshot |
---|
| 1550 | else { |
---|
| 1551 | $sshot = 'images/noscreenshot.png'; |
---|
| 1552 | } |
---|
[2195] | 1553 | |
---|
[3699] | 1554 | $line .= |
---|
| 1555 | '<div class="module-sshot"><img src="' . $sshot . '" alt="' . |
---|
| 1556 | sprintf(__('%s screenshot.'), html::escapeHTML($module['name'])) . '" /></div>'; |
---|
| 1557 | } |
---|
[2195] | 1558 | |
---|
[3699] | 1559 | $line .= |
---|
| 1560 | '<div class="module-infos toggle-bloc">'; |
---|
[2347] | 1561 | |
---|
[3699] | 1562 | if (in_array('name', $cols) && $current) { |
---|
| 1563 | $line .= |
---|
| 1564 | '<h4 class="module-name">'; |
---|
[2487] | 1565 | |
---|
[3699] | 1566 | if (in_array('checkbox', $cols)) { |
---|
| 1567 | $line .= |
---|
| 1568 | '<label for="' . html::escapeHTML($this->list_id) . '_modules_' . html::escapeHTML($id) . '">' . |
---|
| 1569 | form::checkbox(array('modules[' . $count . ']', html::escapeHTML($this->list_id) . '_modules_' . html::escapeHTML($id)), html::escapeHTML($id)) . |
---|
| 1570 | html::escapeHTML($module['name']) . |
---|
| 1571 | '</label>'; |
---|
| 1572 | } else { |
---|
| 1573 | $line .= |
---|
| 1574 | form::hidden(array('modules[' . $count . ']'), html::escapeHTML($id)) . |
---|
| 1575 | html::escapeHTML($module['name']); |
---|
| 1576 | } |
---|
[2487] | 1577 | |
---|
[3699] | 1578 | $line .= |
---|
| 1579 | '</h4>'; |
---|
| 1580 | } |
---|
[2347] | 1581 | |
---|
[3699] | 1582 | $line .= |
---|
| 1583 | '<p>'; |
---|
[2171] | 1584 | |
---|
[3699] | 1585 | if (in_array('desc', $cols)) { |
---|
| 1586 | $line .= |
---|
| 1587 | '<span class="module-desc">' . html::escapeHTML(__($module['desc'])) . '</span> '; |
---|
| 1588 | } |
---|
[2171] | 1589 | |
---|
[3699] | 1590 | if (in_array('author', $cols)) { |
---|
| 1591 | $line .= |
---|
| 1592 | '<span class="module-author">' . sprintf(__('by %s'), html::escapeHTML($module['author'])) . '</span> '; |
---|
| 1593 | } |
---|
[2171] | 1594 | |
---|
[3699] | 1595 | if (in_array('version', $cols)) { |
---|
| 1596 | $line .= |
---|
| 1597 | '<span class="module-version">' . sprintf(__('version %s'), html::escapeHTML($module['version'])) . '</span> '; |
---|
| 1598 | } |
---|
[2171] | 1599 | |
---|
[3699] | 1600 | if (in_array('current_version', $cols)) { |
---|
| 1601 | $line .= |
---|
| 1602 | '<span class="module-current-version">' . sprintf(__('(current version %s)'), html::escapeHTML($module['current_version'])) . '</span> '; |
---|
| 1603 | } |
---|
[2222] | 1604 | |
---|
[3699] | 1605 | if (in_array('parent', $cols) && !empty($module['parent'])) { |
---|
| 1606 | if ($this->modules->moduleExists($module['parent'])) { |
---|
| 1607 | $line .= |
---|
| 1608 | '<span class="module-parent-ok">' . sprintf(__('(built on "%s")'), html::escapeHTML($module['parent'])) . '</span> '; |
---|
| 1609 | } else { |
---|
| 1610 | $line .= |
---|
| 1611 | '<span class="module-parent-missing">' . sprintf(__('(requires "%s")'), html::escapeHTML($module['parent'])) . '</span> '; |
---|
| 1612 | } |
---|
| 1613 | } |
---|
[2171] | 1614 | |
---|
[3699] | 1615 | $has_details = in_array('details', $cols) && !empty($module['details']); |
---|
| 1616 | $has_support = in_array('support', $cols) && !empty($module['support']); |
---|
| 1617 | if ($has_details || $has_support) { |
---|
| 1618 | $line .= |
---|
| 1619 | '<span class="mod-more">'; |
---|
[2215] | 1620 | |
---|
[3699] | 1621 | if ($has_details) { |
---|
| 1622 | $line .= |
---|
| 1623 | '<a class="module-details" href="' . $module['details'] . '">' . __('Details') . '</a>'; |
---|
| 1624 | } |
---|
[2215] | 1625 | |
---|
[3699] | 1626 | if ($has_support) { |
---|
| 1627 | $line .= |
---|
| 1628 | ' - <a class="module-support" href="' . $module['support'] . '">' . __('Support') . '</a>'; |
---|
| 1629 | } |
---|
[2215] | 1630 | |
---|
[3699] | 1631 | $line .= |
---|
| 1632 | '</span>'; |
---|
| 1633 | } |
---|
[2215] | 1634 | |
---|
[3699] | 1635 | $line .= |
---|
| 1636 | '</p>' . |
---|
| 1637 | '</div>'; |
---|
[2171] | 1638 | |
---|
[3699] | 1639 | $line .= |
---|
| 1640 | '<div class="module-actions toggle-bloc">'; |
---|
[2431] | 1641 | |
---|
[3699] | 1642 | # Plugins actions |
---|
| 1643 | if ($current) { |
---|
[2227] | 1644 | |
---|
[3699] | 1645 | # _GET actions |
---|
| 1646 | if (file_exists(path::real($this->core->blog->themes_path . '/' . $id) . '/style.css')) { |
---|
| 1647 | $theme_url = preg_match('#^http(s)?://#', $this->core->blog->settings->system->themes_url) ? |
---|
| 1648 | http::concatURL($this->core->blog->settings->system->themes_url, '/' . $id) : |
---|
| 1649 | http::concatURL($this->core->blog->url, $this->core->blog->settings->system->themes_url . '/' . $id); |
---|
| 1650 | $line .= |
---|
| 1651 | '<p><a href="' . $theme_url . '/style.css">' . __('View stylesheet') . '</a></p>'; |
---|
| 1652 | } |
---|
[2227] | 1653 | |
---|
[3699] | 1654 | $line .= '<div class="current-actions">'; |
---|
[2260] | 1655 | |
---|
[3699] | 1656 | if (file_exists(path::real($this->core->blog->themes_path . '/' . $id) . '/_config.php')) { |
---|
| 1657 | $line .= |
---|
| 1658 | '<p><a href="' . $this->getURL('module=' . $id . '&conf=1', false) . '" class="button submit">' . __('Configure theme') . '</a></p>'; |
---|
| 1659 | } |
---|
[2227] | 1660 | |
---|
[3699] | 1661 | # --BEHAVIOR-- adminCurrentThemeDetails |
---|
| 1662 | $line .= |
---|
| 1663 | $this->core->callBehavior('adminCurrentThemeDetails', $this->core, $id, $module); |
---|
[2260] | 1664 | |
---|
[3699] | 1665 | $line .= '</div>'; |
---|
| 1666 | } |
---|
[2171] | 1667 | |
---|
[3699] | 1668 | # _POST actions |
---|
| 1669 | if (!empty($actions)) { |
---|
| 1670 | $line .= |
---|
| 1671 | '<p>' . implode(' ', $this->getActions($id, $module, $actions)) . '</p>'; |
---|
| 1672 | } |
---|
[2171] | 1673 | |
---|
[3699] | 1674 | $line .= |
---|
| 1675 | '</div>'; |
---|
[2171] | 1676 | |
---|
[3699] | 1677 | $line .= |
---|
| 1678 | '</div>'; |
---|
[2171] | 1679 | |
---|
[3699] | 1680 | $count++; |
---|
[2171] | 1681 | |
---|
[3699] | 1682 | $res = $current ? $line . $res : $res . $line; |
---|
| 1683 | } |
---|
[2487] | 1684 | |
---|
[3699] | 1685 | echo |
---|
| 1686 | $res . |
---|
| 1687 | '</div>'; |
---|
[2171] | 1688 | |
---|
[3699] | 1689 | if (!$count && $this->getSearch() === null) { |
---|
| 1690 | echo |
---|
| 1691 | '<p class="message">' . __('No themes matched your search.') . '</p>'; |
---|
| 1692 | } elseif ((in_array('checkbox', $cols) || $count > 1) && !empty($actions) && $this->core->auth->isSuperAdmin()) { |
---|
| 1693 | $buttons = $this->getGlobalActions($actions, in_array('checkbox', $cols)); |
---|
[2428] | 1694 | |
---|
[3699] | 1695 | if (!empty($buttons)) { |
---|
| 1696 | if (in_array('checkbox', $cols)) { |
---|
| 1697 | echo |
---|
| 1698 | '<p class="checkboxes-helpers"></p>'; |
---|
| 1699 | } |
---|
| 1700 | echo '<div>' . implode(' ', $buttons) . '</div>'; |
---|
| 1701 | } |
---|
| 1702 | } |
---|
[2428] | 1703 | |
---|
[3699] | 1704 | echo |
---|
| 1705 | '</form>'; |
---|
[2428] | 1706 | |
---|
[3699] | 1707 | return $this; |
---|
| 1708 | } |
---|
[2428] | 1709 | |
---|
[3699] | 1710 | protected function getActions($id, $module, $actions) |
---|
| 1711 | { |
---|
| 1712 | $submits = array(); |
---|
[2192] | 1713 | |
---|
[3699] | 1714 | $this->core->blog->settings->addNamespace('system'); |
---|
| 1715 | if ($id != $this->core->blog->settings->system->theme) { |
---|
[2192] | 1716 | |
---|
[3699] | 1717 | # Select theme to use on curent blog |
---|
| 1718 | if (in_array('select', $actions)) { |
---|
| 1719 | $submits[] = |
---|
| 1720 | '<input type="submit" name="select[' . html::escapeHTML($id) . ']" value="' . __('Use this one') . '" />'; |
---|
| 1721 | } |
---|
| 1722 | } |
---|
[2215] | 1723 | |
---|
[3699] | 1724 | return array_merge( |
---|
| 1725 | $submits, |
---|
| 1726 | parent::getActions($id, $module, $actions) |
---|
| 1727 | ); |
---|
| 1728 | } |
---|
[2192] | 1729 | |
---|
[3699] | 1730 | protected function getGlobalActions($actions, $with_selection = false) |
---|
| 1731 | { |
---|
| 1732 | $submits = array(); |
---|
[2215] | 1733 | |
---|
[3699] | 1734 | foreach ($actions as $action) { |
---|
| 1735 | switch ($action) { |
---|
[2428] | 1736 | |
---|
[3699] | 1737 | # Update (from store) |
---|
| 1738 | case 'update':if ($this->core->auth->isSuperAdmin() && $this->path_writable) { |
---|
| 1739 | $submits[] = |
---|
| 1740 | '<input type="submit" name="update" value="' . ($with_selection ? |
---|
| 1741 | __('Update selected themes') : |
---|
| 1742 | __('Update all themes from this list') |
---|
| 1743 | ) . '" />' . $this->core->formNonce(); |
---|
| 1744 | }break; |
---|
[2428] | 1745 | |
---|
[3699] | 1746 | # Behavior |
---|
| 1747 | case 'behavior': |
---|
[2428] | 1748 | |
---|
[3699] | 1749 | # --BEHAVIOR-- adminModulesListGetGlobalActions |
---|
| 1750 | $tmp = $this->core->callBehavior('adminModulesListGetGlobalActions', $this); |
---|
[2428] | 1751 | |
---|
[3699] | 1752 | if (!empty($tmp)) { |
---|
| 1753 | $submits[] = $tmp; |
---|
| 1754 | } |
---|
| 1755 | break; |
---|
| 1756 | } |
---|
| 1757 | } |
---|
[2428] | 1758 | |
---|
[3699] | 1759 | return $submits; |
---|
| 1760 | } |
---|
[2428] | 1761 | |
---|
[3699] | 1762 | public function doActions() |
---|
| 1763 | { |
---|
| 1764 | if (empty($_POST) || !empty($_REQUEST['conf'])) { |
---|
| 1765 | return; |
---|
| 1766 | } |
---|
[2428] | 1767 | |
---|
[3699] | 1768 | $modules = !empty($_POST['modules']) && is_array($_POST['modules']) ? array_values($_POST['modules']) : array(); |
---|
[2215] | 1769 | |
---|
[3699] | 1770 | if (!empty($_POST['select'])) { |
---|
[2377] | 1771 | |
---|
[3699] | 1772 | # Can select only one theme at a time! |
---|
| 1773 | if (is_array($_POST['select'])) { |
---|
| 1774 | $modules = array_keys($_POST['select']); |
---|
| 1775 | $id = $modules[0]; |
---|
[2377] | 1776 | |
---|
[3699] | 1777 | if (!$this->modules->moduleExists($id)) { |
---|
| 1778 | throw new Exception(__('No such theme.')); |
---|
| 1779 | } |
---|
[2215] | 1780 | |
---|
[3699] | 1781 | $this->core->blog->settings->addNamespace('system'); |
---|
| 1782 | $this->core->blog->settings->system->put('theme', $id); |
---|
| 1783 | $this->core->blog->triggerBlog(); |
---|
[2215] | 1784 | |
---|
[3699] | 1785 | dcPage::addSuccessNotice(__('Theme has been successfully selected.')); |
---|
| 1786 | http::redirect($this->getURL() . '#themes'); |
---|
| 1787 | } |
---|
| 1788 | } else { |
---|
| 1789 | if (!$this->isWritablePath()) { |
---|
| 1790 | return; |
---|
| 1791 | } |
---|
[2215] | 1792 | |
---|
[3699] | 1793 | if ($this->core->auth->isSuperAdmin() && !empty($_POST['activate'])) { |
---|
[2377] | 1794 | |
---|
[3699] | 1795 | if (is_array($_POST['activate'])) { |
---|
| 1796 | $modules = array_keys($_POST['activate']); |
---|
| 1797 | } |
---|
[2487] | 1798 | |
---|
[3699] | 1799 | $list = $this->modules->getDisabledModules(); |
---|
| 1800 | if (empty($list)) { |
---|
| 1801 | throw new Exception(__('No such theme.')); |
---|
| 1802 | } |
---|
[3221] | 1803 | |
---|
[3699] | 1804 | $count = 0; |
---|
| 1805 | foreach ($list as $id => $module) { |
---|
[3221] | 1806 | |
---|
[3699] | 1807 | if (!in_array($id, $modules)) { |
---|
| 1808 | continue; |
---|
| 1809 | } |
---|
[3221] | 1810 | |
---|
[3699] | 1811 | # --BEHAVIOR-- themeBeforeActivate |
---|
| 1812 | $this->core->callBehavior('themeBeforeActivate', $id); |
---|
[3221] | 1813 | |
---|
[3699] | 1814 | $this->modules->activateModule($id); |
---|
[3221] | 1815 | |
---|
[3699] | 1816 | # --BEHAVIOR-- themeAfterActivate |
---|
| 1817 | $this->core->callBehavior('themeAfterActivate', $id); |
---|
[3221] | 1818 | |
---|
[3699] | 1819 | $count++; |
---|
| 1820 | } |
---|
[3221] | 1821 | |
---|
[3699] | 1822 | dcPage::addSuccessNotice( |
---|
| 1823 | __('Theme has been successfully activated.', 'Themes have been successuflly activated.', $count) |
---|
| 1824 | ); |
---|
| 1825 | http::redirect($this->getURL()); |
---|
| 1826 | } elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['deactivate'])) { |
---|
[3221] | 1827 | |
---|
[3699] | 1828 | if (is_array($_POST['deactivate'])) { |
---|
| 1829 | $modules = array_keys($_POST['deactivate']); |
---|
| 1830 | } |
---|
[3221] | 1831 | |
---|
[3699] | 1832 | $list = $this->modules->getModules(); |
---|
| 1833 | if (empty($list)) { |
---|
| 1834 | throw new Exception(__('No such theme.')); |
---|
| 1835 | } |
---|
[2487] | 1836 | |
---|
[3699] | 1837 | $failed = false; |
---|
| 1838 | $count = 0; |
---|
| 1839 | foreach ($list as $id => $module) { |
---|
[2487] | 1840 | |
---|
[3699] | 1841 | if (!in_array($id, $modules)) { |
---|
| 1842 | continue; |
---|
| 1843 | } |
---|
[2377] | 1844 | |
---|
[3699] | 1845 | if (!$module['root_writable']) { |
---|
| 1846 | $failed = true; |
---|
| 1847 | continue; |
---|
| 1848 | } |
---|
[2377] | 1849 | |
---|
[3699] | 1850 | $module[$id] = $id; |
---|
[2377] | 1851 | |
---|
[3699] | 1852 | # --BEHAVIOR-- themeBeforeDeactivate |
---|
| 1853 | $this->core->callBehavior('themeBeforeDeactivate', $module); |
---|
[2377] | 1854 | |
---|
[3699] | 1855 | $this->modules->deactivateModule($id); |
---|
[2377] | 1856 | |
---|
[3699] | 1857 | # --BEHAVIOR-- themeAfterDeactivate |
---|
| 1858 | $this->core->callBehavior('themeAfterDeactivate', $module); |
---|
[2377] | 1859 | |
---|
[3699] | 1860 | $count++; |
---|
| 1861 | } |
---|
[2377] | 1862 | |
---|
[3699] | 1863 | if ($failed) { |
---|
| 1864 | dcPage::addWarningNotice(__('Some themes have not been deactivated.')); |
---|
| 1865 | } else { |
---|
| 1866 | dcPage::addSuccessNotice( |
---|
| 1867 | __('Theme has been successfully deactivated.', 'Themes have been successuflly deactivated.', $count) |
---|
| 1868 | ); |
---|
| 1869 | } |
---|
| 1870 | http::redirect($this->getURL()); |
---|
| 1871 | } elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['delete'])) { |
---|
[3221] | 1872 | |
---|
[3699] | 1873 | if (is_array($_POST['delete'])) { |
---|
| 1874 | $modules = array_keys($_POST['delete']); |
---|
| 1875 | } |
---|
[3221] | 1876 | |
---|
[3699] | 1877 | $list = $this->modules->getDisabledModules(); |
---|
[3221] | 1878 | |
---|
[3699] | 1879 | $failed = false; |
---|
| 1880 | $count = 0; |
---|
| 1881 | foreach ($modules as $id) { |
---|
| 1882 | if (!isset($list[$id])) { |
---|
[3221] | 1883 | |
---|
[3699] | 1884 | if (!$this->modules->moduleExists($id)) { |
---|
| 1885 | throw new Exception(__('No such theme.')); |
---|
| 1886 | } |
---|
[3221] | 1887 | |
---|
[3699] | 1888 | $module = $this->modules->getModules($id); |
---|
| 1889 | $module['id'] = $id; |
---|
[2377] | 1890 | |
---|
[3699] | 1891 | if (!$this->isDeletablePath($module['root'])) { |
---|
| 1892 | $failed = true; |
---|
| 1893 | continue; |
---|
| 1894 | } |
---|
[3221] | 1895 | |
---|
[3699] | 1896 | # --BEHAVIOR-- themeBeforeDelete |
---|
| 1897 | $this->core->callBehavior('themeBeforeDelete', $module); |
---|
[3221] | 1898 | |
---|
[3699] | 1899 | $this->modules->deleteModule($id); |
---|
[3221] | 1900 | |
---|
[3699] | 1901 | # --BEHAVIOR-- themeAfterDelete |
---|
| 1902 | $this->core->callBehavior('themeAfterDelete', $module); |
---|
| 1903 | } else { |
---|
| 1904 | $this->modules->deleteModule($id, true); |
---|
| 1905 | } |
---|
[3221] | 1906 | |
---|
[3699] | 1907 | $count++; |
---|
| 1908 | } |
---|
[3221] | 1909 | |
---|
[3699] | 1910 | if (!$count && $failed) { |
---|
| 1911 | throw new Exception(__("You don't have permissions to delete this theme.")); |
---|
| 1912 | } elseif ($failed) { |
---|
| 1913 | dcPage::addWarningNotice(__('Some themes have not been delete.')); |
---|
| 1914 | } else { |
---|
| 1915 | dcPage::addSuccessNotice( |
---|
| 1916 | __('Theme has been successfully deleted.', 'Themes have been successuflly deleted.', $count) |
---|
| 1917 | ); |
---|
| 1918 | } |
---|
| 1919 | http::redirect($this->getURL()); |
---|
| 1920 | } elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['install'])) { |
---|
[3221] | 1921 | |
---|
[3699] | 1922 | if (is_array($_POST['install'])) { |
---|
| 1923 | $modules = array_keys($_POST['install']); |
---|
| 1924 | } |
---|
[3221] | 1925 | |
---|
[3699] | 1926 | $list = $this->store->get(); |
---|
[3221] | 1927 | |
---|
[3699] | 1928 | if (empty($list)) { |
---|
| 1929 | throw new Exception(__('No such theme.')); |
---|
| 1930 | } |
---|
[3221] | 1931 | |
---|
[3699] | 1932 | $count = 0; |
---|
| 1933 | foreach ($list as $id => $module) { |
---|
[2377] | 1934 | |
---|
[3699] | 1935 | if (!in_array($id, $modules)) { |
---|
| 1936 | continue; |
---|
| 1937 | } |
---|
[3221] | 1938 | |
---|
[3699] | 1939 | $dest = $this->getPath() . '/' . basename($module['file']); |
---|
[3221] | 1940 | |
---|
[3699] | 1941 | # --BEHAVIOR-- themeBeforeAdd |
---|
| 1942 | $this->core->callBehavior('themeBeforeAdd', $module); |
---|
[3221] | 1943 | |
---|
[3699] | 1944 | $this->store->process($module['file'], $dest); |
---|
[3221] | 1945 | |
---|
[3699] | 1946 | # --BEHAVIOR-- themeAfterAdd |
---|
| 1947 | $this->core->callBehavior('themeAfterAdd', $module); |
---|
[3221] | 1948 | |
---|
[3699] | 1949 | $count++; |
---|
| 1950 | } |
---|
[3221] | 1951 | |
---|
[3699] | 1952 | dcPage::addSuccessNotice( |
---|
| 1953 | __('Theme has been successfully installed.', 'Themes have been successuflly installed.', $count) |
---|
| 1954 | ); |
---|
| 1955 | http::redirect($this->getURL()); |
---|
| 1956 | } elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['update'])) { |
---|
[3221] | 1957 | |
---|
[3699] | 1958 | if (is_array($_POST['update'])) { |
---|
| 1959 | $modules = array_keys($_POST['update']); |
---|
| 1960 | } |
---|
[3221] | 1961 | |
---|
[3699] | 1962 | $list = $this->store->get(true); |
---|
| 1963 | if (empty($list)) { |
---|
| 1964 | throw new Exception(__('No such theme.')); |
---|
| 1965 | } |
---|
[3221] | 1966 | |
---|
[3699] | 1967 | $count = 0; |
---|
| 1968 | foreach ($list as $module) { |
---|
[3221] | 1969 | |
---|
[3699] | 1970 | if (!in_array($module['id'], $modules)) { |
---|
| 1971 | continue; |
---|
| 1972 | } |
---|
[3221] | 1973 | |
---|
[3699] | 1974 | $dest = $module['root'] . '/../' . basename($module['file']); |
---|
[2487] | 1975 | |
---|
[3699] | 1976 | # --BEHAVIOR-- themeBeforeUpdate |
---|
| 1977 | $this->core->callBehavior('themeBeforeUpdate', $module); |
---|
[2487] | 1978 | |
---|
[3699] | 1979 | $this->store->process($module['file'], $dest); |
---|
[3221] | 1980 | |
---|
[3699] | 1981 | # --BEHAVIOR-- themeAfterUpdate |
---|
| 1982 | $this->core->callBehavior('themeAfterUpdate', $module); |
---|
[3221] | 1983 | |
---|
[3699] | 1984 | $count++; |
---|
| 1985 | } |
---|
[3221] | 1986 | |
---|
[3699] | 1987 | $tab = $count && $count == count($list) ? '#themes' : '#update'; |
---|
[3221] | 1988 | |
---|
[3699] | 1989 | dcPage::addSuccessNotice( |
---|
| 1990 | __('Theme has been successfully updated.', 'Themes have been successuflly updated.', $count) |
---|
| 1991 | ); |
---|
| 1992 | http::redirect($this->getURL() . $tab); |
---|
| 1993 | } |
---|
[3221] | 1994 | |
---|
[3699] | 1995 | # Manual actions |
---|
| 1996 | elseif (!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file']) |
---|
| 1997 | || !empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url'])) { |
---|
| 1998 | if (empty($_POST['your_pwd']) || !$this->core->auth->checkPassword($_POST['your_pwd'])) { |
---|
| 1999 | throw new Exception(__('Password verification failed')); |
---|
| 2000 | } |
---|
[3221] | 2001 | |
---|
[3699] | 2002 | if (!empty($_POST['upload_pkg'])) { |
---|
| 2003 | files::uploadStatus($_FILES['pkg_file']); |
---|
[3221] | 2004 | |
---|
[3699] | 2005 | $dest = $this->getPath() . '/' . $_FILES['pkg_file']['name']; |
---|
| 2006 | if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'], $dest)) { |
---|
| 2007 | throw new Exception(__('Unable to move uploaded file.')); |
---|
| 2008 | } |
---|
| 2009 | } else { |
---|
| 2010 | $url = urldecode($_POST['pkg_url']); |
---|
| 2011 | $dest = $this->getPath() . '/' . basename($url); |
---|
| 2012 | $this->store->download($url, $dest); |
---|
| 2013 | } |
---|
[3221] | 2014 | |
---|
[3699] | 2015 | # --BEHAVIOR-- themeBeforeAdd |
---|
| 2016 | $this->core->callBehavior('themeBeforeAdd', null); |
---|
[3221] | 2017 | |
---|
[3699] | 2018 | $ret_code = $this->store->install($dest); |
---|
[3221] | 2019 | |
---|
[3699] | 2020 | # --BEHAVIOR-- themeAfterAdd |
---|
| 2021 | $this->core->callBehavior('themeAfterAdd', null); |
---|
[2487] | 2022 | |
---|
[3699] | 2023 | dcPage::addSuccessNotice($ret_code == 2 ? |
---|
| 2024 | __('Theme has been successfully updated.') : |
---|
| 2025 | __('Theme has been successfully installed.') |
---|
| 2026 | ); |
---|
| 2027 | http::redirect($this->getURL() . '#themes'); |
---|
| 2028 | } else { |
---|
[2377] | 2029 | |
---|
[3699] | 2030 | # --BEHAVIOR-- adminModulesListDoActions |
---|
| 2031 | $this->core->callBehavior('adminModulesListDoActions', $this, $modules, 'theme'); |
---|
[3221] | 2032 | |
---|
[3699] | 2033 | } |
---|
| 2034 | } |
---|
[2377] | 2035 | |
---|
[3699] | 2036 | return; |
---|
| 2037 | } |
---|
[2147] | 2038 | } |
---|