| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * @brief Themes specific handler |
|---|
| 4 | * |
|---|
| 5 | * Provides an specialized object to handle themes. An instance of this |
|---|
| 6 | * class should be created when needed. |
|---|
| 7 | * |
|---|
| 8 | * @package Dotclear |
|---|
| 9 | * @subpackage Core |
|---|
| 10 | * |
|---|
| 11 | * @copyright Olivier Meunier & Association Dotclear |
|---|
| 12 | * @copyright GPL-2.0-only |
|---|
| 13 | */ |
|---|
| 14 | |
|---|
| 15 | if (!defined('DC_RC_PATH')) {return;} |
|---|
| 16 | |
|---|
| 17 | class dcThemes extends dcModules |
|---|
| 18 | { |
|---|
| 19 | protected static $type = 'theme'; |
|---|
| 20 | |
|---|
| 21 | /** |
|---|
| 22 | This method registers a theme in modules list. You should use this to |
|---|
| 23 | register a new theme. |
|---|
| 24 | |
|---|
| 25 | <var>$parent</var> is a optional value to indicate them inheritance. |
|---|
| 26 | If <var>$parent</var> is null / not set, we simply fall back to |
|---|
| 27 | the standard behavior, by using 'default'. |
|---|
| 28 | |
|---|
| 29 | <var>$priority</var> is an integer. Modules are sorted by priority and name. |
|---|
| 30 | Lowest priority comes first. This property is currently ignored when dealing |
|---|
| 31 | with themes. |
|---|
| 32 | |
|---|
| 33 | @param name <b>string</b> Module name |
|---|
| 34 | @param desc <b>string</b> Module description |
|---|
| 35 | @param author <b>string</b> Module author name |
|---|
| 36 | @param version <b>string</b> Module version |
|---|
| 37 | @param properties <b>array</b> extra properties |
|---|
| 38 | (currently available keys : parent, priority, standalone_config, type, tplset) |
|---|
| 39 | */ |
|---|
| 40 | public function registerModule($name, $desc, $author, $version, $properties = array()) |
|---|
| 41 | { |
|---|
| 42 | # Fallback to legacy registerModule parameters |
|---|
| 43 | if (!is_array($properties)) { |
|---|
| 44 | $args = func_get_args(); |
|---|
| 45 | $properties = array(); |
|---|
| 46 | if (isset($args[4])) { |
|---|
| 47 | $properties['parent'] = $args[4]; |
|---|
| 48 | } |
|---|
| 49 | if (isset($args[5])) { |
|---|
| 50 | $properties['priority'] = (integer) $args[5]; |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | # Themes specifics properties |
|---|
| 54 | $properties = array_merge( |
|---|
| 55 | array('parent' => null, 'tplset' => DC_DEFAULT_TPLSET), |
|---|
| 56 | $properties, |
|---|
| 57 | array('permissions' => 'admin') // force themes perms |
|---|
| 58 | ); |
|---|
| 59 | |
|---|
| 60 | parent::registerModule($name, $desc, $author, $version, $properties); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | /** |
|---|
| 64 | Loads namespace <var>$ns</var> specific file for module with ID |
|---|
| 65 | <var>$id</var> |
|---|
| 66 | Note : actually, only 'public' namespace is supported with themes. |
|---|
| 67 | |
|---|
| 68 | @param id <b>string</b> Module ID |
|---|
| 69 | @param ns <b>string</b> Namespace name |
|---|
| 70 | */ |
|---|
| 71 | public function loadNsFile($id, $ns = null) |
|---|
| 72 | { |
|---|
| 73 | switch ($ns) { |
|---|
| 74 | case 'public': |
|---|
| 75 | $parent = $this->modules[$id]['parent']; |
|---|
| 76 | if ($parent) { |
|---|
| 77 | // This is not a real cascade - since we don't call loadNsFile -, |
|---|
| 78 | // thus limiting inclusion process. |
|---|
| 79 | // TODO : See if we have to change this. |
|---|
| 80 | $this->loadModuleFile($this->modules[$parent]['root'] . '/_public.php'); |
|---|
| 81 | } |
|---|
| 82 | $this->loadModuleFile($this->modules[$id]['root'] . '/_public.php'); |
|---|
| 83 | break; |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | } |
|---|