Dotclear

source: inc/core/class.dc.themes.php @ 2239:cd7100fa57db

Revision 2239:cd7100fa57db, 3.3 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Prevent install theme as plugin and vice versa by adding property "type" to modules definition, fixes #1713

Line 
1<?php
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 -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14/**
15@ingroup DC_CORE
16@brief Themes specific handler
17
18Provides an specialized object to handle themes. An instance of this
19class should be created when needed.
20
21This class extends dcModules.
22*/
23class dcThemes extends dcModules
24{   
25     protected static $type = 'theme';
26
27     /**
28     This method registers a theme in modules list. You should use this to
29     register a new theme.
30     
31     <var>$parent</var> is a optional value to indicate them inheritance.
32     If <var>$parent</var> is null / not set, we simply fall back to
33     the standard behavior, by using 'default'.
34     
35     <var>$priority</var> is an integer. Modules are sorted by priority and name.
36     Lowest priority comes first. This property is currently ignored when dealing
37     with themes.
38     
39     @param    name           <b>string</b>       Module name
40     @param    desc           <b>string</b>       Module description
41     @param    author         <b>string</b>       Module author name
42     @param    version        <b>string</b>       Module version
43     @param    properties     <b>array</b>        extra properties (currently available keys : parent, priority, standalone_config)
44     */
45     public function registerModule($name,$desc,$author,$version,$properties = array())
46     {
47          if (!is_array($properties)) {
48               //Fallback to legacy registerModule parameters
49               $args = func_get_args();
50               $properties = array();
51               if (isset($args[4])) {
52                    $properties['parent']=$args[4];
53               }
54               if (isset($args[5])) {
55                    $properties['priority']= (integer)$args[5];
56               }
57          }
58          $properties = array_merge(
59               array(
60                    'parent' => null,
61                    'priority' => 1000,
62                    'standalone_config' => false,
63                    'type' => null
64               ), $properties
65          );
66
67          if ($properties['type'] !== null && $properties['type'] != self::$type) {
68               $this->errors[] = sprintf(
69                    __('Module "%s" has type "%s" that mismatch required module type "%s".'),
70                    '<strong>'.html::escapeHTML($name).'</strong>',
71                    '<em>'.html::escapeHTML($properties['type']).'</em>',
72                    '<em>'.html::escapeHTML(self::$type).'</em>'
73               );
74               return;
75          }
76
77          if ($this->id) {
78               $this->modules[$this->id] = array_merge(
79                    $properties,
80                    array(
81                         'root' => $this->mroot,
82                         'name' => $name,
83                         'desc' => $desc,
84                         'author' => $author,
85                         'version' => $version,
86                         'root_writable' => is_writable($this->mroot)
87                    )
88               );
89          }
90     }   
91     
92     /**
93     Loads namespace <var>$ns</var> specific file for module with ID
94     <var>$id</var>
95     Note : actually, only 'public' namespace is supported with themes.
96     
97     @param    id        <b>string</b>       Module ID
98     @param    ns        <b>string</b>       Namespace name
99     */
100     public function loadNsFile($id,$ns=null)
101     {
102          switch ($ns) {
103               case 'public':
104                    $parent = $this->modules[$id]['parent'];
105                    if ($parent) {
106                         // This is not a real cascade - since we don't call loadNsFile -,
107                         // thus limiting inclusion process.
108                         // TODO : See if we have to change this.
109                         $this->loadModuleFile($this->modules[$parent]['root'].'/_public.php');
110                    }
111                    $this->loadModuleFile($this->modules[$id]['root'].'/_public.php');
112                    break;
113          }
114     }
115}
116?>
Note: See TracBrowser for help on using the repository browser.

Sites map