- Timestamp:
- 09/23/13 20:34:42 (12 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/maintenance/inc/class.dc.maintenance.php
r1989 r2044 26 26 { 27 27 public $core; 28 public $p_url = 'plugin.php?p=maintenance'; 29 28 30 private $tasks = array(); 29 31 private $tabs = array(); … … 34 36 * Constructor. 35 37 * 36 * Here you register tasks and groups for tasks.37 *38 38 * @param core <b>dcCore</b> dcCore instance 39 39 */ … … 41 41 { 42 42 $this->core = $core; 43 44 $tasks = new ArrayObject();45 $tabs = new ArrayObject();46 $groups = new ArrayObject();47 43 $logs = $this->getLogs(); 48 49 # --BEHAVIOR-- dcMaintenanceRegister 50 $core->callBehavior('dcMaintenanceRegister', $core, $tasks, $groups, $tabs); 51 52 $this->init($tasks, $groups, $tabs); 53 } 54 55 /** 56 * Initialize list of groups and tasks. 57 * 58 * @param tasks <b>arrayObject</b> Array of task to register 59 * @param groups <b>arrayObject</b> Array of groups to add 60 * @param tabs <b>arrayObject</b> Array of tabs to add 61 */ 62 public function init($tasks, $groups, $tabs) 63 { 64 $this->tasks = $this->groups = array(); 65 66 foreach($tasks as $task) 67 { 68 if (!class_exists($task)) { 69 continue; 70 } 71 72 $r = new ReflectionClass($task); 73 $p = $r->getParentClass(); 74 75 if (!$p || $p->name != 'dcMaintenanceTask') { 76 continue; 77 } 78 79 if (($t = new $task($this, 'plugin.php?p=maintenance')) === null 80 || $t->perm() === null && !$this->core->auth->isSuperAdmin() 81 || !$this->core->auth->check($t->perm(), $this->core->blog->id)) { 82 continue; 83 } 84 85 $this->tasks[$task] = $t; 86 } 87 88 foreach($groups as $id => $name) 89 { 90 $this->groups[(string) $id] = (string) $name; 91 } 92 93 foreach($tabs as $id => $name) 94 { 95 $this->tabs[(string) $id] = (string) $name; 96 } 97 } 98 99 /** 100 * Get a tab name. 44 $this->init(); 45 } 46 47 /** 48 * Initialize list of tabs and groups and tasks. 49 * 50 * To register a tab or group or task, 51 * use behavior dcMaintenanceInit then a method of 52 * dcMaintenance like addTab('myTab', ...). 53 */ 54 protected function init() 55 { 56 # --BEHAVIOR-- dcMaintenanceInit 57 $this->core->callBehavior('dcMaintenanceInit', $this); 58 } 59 60 /// @name Tab methods 61 //@{ 62 /** 63 * Add a tab. 64 * 65 * @param id <b>string<b> Tab ID 66 * @param name <b>string<b> Tab name 67 * @param options <b>string<b> Options 68 * @return <b>dcMaintenance</b> Self 69 */ 70 public function addTab($id, $name, $options=array()) 71 { 72 $this->tabs[$id] = new dcMaintenanceDescriptor($id, $name, $options); 73 74 return $this; 75 } 76 77 /** 78 * Get a tab. 101 79 * 102 80 * @param id <b>string</b> Tab ID 103 * @return <b> mixed</b> tab name or null if not exists81 * @return <b>object</b> dcMaintenanceDescriptor of a tab 104 82 */ 105 83 public function getTab($id) … … 117 95 return $this->tabs; 118 96 } 119 120 /** 121 * Get a group name. 97 //@} 98 99 100 /// @name Group methods 101 //@{ 102 /** 103 * Add a group. 104 * 105 * @param id <b>string<b> Group ID 106 * @param name <b>string<b> Group name 107 * @param options <b>string<b> Options 108 * @return <b>dcMaintenance</b> Self 109 */ 110 public function addGroup($id, $name, $options=array()) 111 { 112 $this->groups[$id] = new dcMaintenanceDescriptor($id, $name, $options); 113 114 return $this; 115 } 116 117 /** 118 * Get a group. 122 119 * 123 120 * @param id <b>string</b> Group ID 124 * @return <b> mixed</b> Group name or null if not exists121 * @return <b>object</b> dcMaintenanceDescriptor of a group 125 122 */ 126 123 public function getGroup($id) … … 132 129 * Get groups. 133 130 * 134 * @return <b>array</b> Array of groups ID and name131 * @return <b>array</b> Array of groups ID and descriptor 135 132 */ 136 133 public function getGroups() 137 134 { 138 135 return $this->groups; 136 } 137 //@} 138 139 140 /// @name Task methods 141 //@{ 142 /** 143 * Add a task. 144 * 145 * @param task <b>mixed<b> Class name or object 146 * @return <b>boolean</b> True if it is added 147 * @return <b>dcMaintenance</b> Self 148 */ 149 public function addTask($task) 150 { 151 if (class_exists($task) && is_subclass_of($task, 'dcMaintenanceTask')) { 152 $this->tasks[$task] = new $task($this); 153 } 154 155 return $this; 139 156 } 140 157 … … 174 191 return $res; 175 192 } 176 193 //@} 194 195 196 /// @name Log methods 197 //@{ 177 198 /** 178 199 * Set log for a task. … … 268 289 return $this->logs; 269 290 } 291 //@} 270 292 }
Note: See TracChangeset
for help on using the changeset viewer.