| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
class midcom_admin_folder_folder_management extends midcom_baseclasses_components_handler |
|---|
| 16 |
{ |
|---|
| 17 |
|
|---|
| 18 |
* Anchor prefix stores the link back to the edited content topic |
|---|
| 19 |
* |
|---|
| 20 |
* @access private |
|---|
| 21 |
* @var string |
|---|
| 22 |
*/ |
|---|
| 23 |
var $_anchor_prefix = null; |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
* Simple constructor, which only initializes the parent constructor. |
|---|
| 27 |
*/ |
|---|
| 28 |
function midcom_admin_folder_folder_management() |
|---|
| 29 |
{ |
|---|
| 30 |
parent::midcom_baseclasses_components_handler(); |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
* Get the object title of the content topic. |
|---|
| 35 |
* |
|---|
| 36 |
* @return string containing the content topic title |
|---|
| 37 |
*/ |
|---|
| 38 |
function _get_object_title($object) |
|---|
| 39 |
{ |
|---|
| 40 |
$title = ''; |
|---|
| 41 |
if (array_key_exists('title', $object)) |
|---|
| 42 |
{ |
|---|
| 43 |
$title = $object->title; |
|---|
| 44 |
} |
|---|
| 45 |
else if (is_a($object, 'midcom_baseclasses_database_topic')) |
|---|
| 46 |
{ |
|---|
| 47 |
$title = $object->extra; |
|---|
| 48 |
} |
|---|
| 49 |
else if (array_key_exists('name', $object)) |
|---|
| 50 |
{ |
|---|
| 51 |
$title = $object->name; |
|---|
| 52 |
} |
|---|
| 53 |
else |
|---|
| 54 |
{ |
|---|
| 55 |
$title = get_class($object) . " GUID {$object->guid}"; |
|---|
| 56 |
} |
|---|
| 57 |
return $title; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
* Initializes the context data and toolbar objects |
|---|
| 62 |
* |
|---|
| 63 |
* @access private |
|---|
| 64 |
*/ |
|---|
| 65 |
function _on_initialize() |
|---|
| 66 |
{ |
|---|
| 67 |
$config = $this->_request_data['plugin_config']; |
|---|
| 68 |
if ($config) |
|---|
| 69 |
{ |
|---|
| 70 |
foreach ($config as $key => $value) |
|---|
| 71 |
{ |
|---|
| 72 |
$this->$key = $value; |
|---|
| 73 |
} |
|---|
| 74 |
} |
|---|
| 75 |
$this->_anchor_prefix = $this->_request_data['plugin_anchorprefix']; |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
$_MIDCOM->style->prepend_component_styledir('midcom.admin.folder'); |
|---|
| 79 |
|
|---|
| 80 |
$this->_request_data['folder'] = $this->_topic; |
|---|
| 81 |
|
|---|
| 82 |
if (!array_key_exists($this->_topic->component, $_MIDCOM->componentloader->manifests)) |
|---|
| 83 |
{ |
|---|
| 84 |
$this->_topic->component = 'midcom.core.nullcomponent'; |
|---|
| 85 |
} |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
* Get the plugin handlers, which act alike with Request Switches of MidCOM |
|---|
| 90 |
* Baseclasses Components (midcom.baseclasses.components.request) |
|---|
| 91 |
* |
|---|
| 92 |
* @access public |
|---|
| 93 |
* @return mixed Array of the plugin handlers |
|---|
| 94 |
*/ |
|---|
| 95 |
function get_plugin_handlers() |
|---|
| 96 |
{ |
|---|
| 97 |
$_MIDCOM->load_library('midcom.admin.folder'); |
|---|
| 98 |
return array |
|---|
| 99 |
( |
|---|
| 100 |
|
|---|
| 101 |
* Basic functionalities such as creation, editing and deleting |
|---|
| 102 |
* topic objects. |
|---|
| 103 |
*/ |
|---|
| 104 |
/** |
|---|
| 105 |
* Create a new topic |
|---|
| 106 |
* |
|---|
| 107 |
* Match /create/ |
|---|
| 108 |
*/ |
|---|
| 109 |
'create' => array |
|---|
| 110 |
( |
|---|
| 111 |
'handler' => array('midcom_admin_folder_handler_edit', 'edit'), |
|---|
| 112 |
'fixed_args' => array ('create'), |
|---|
| 113 |
), |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
* Edit a topic |
|---|
| 117 |
* |
|---|
| 118 |
* Match /edit/ |
|---|
| 119 |
*/ |
|---|
| 120 |
'edit' => array |
|---|
| 121 |
( |
|---|
| 122 |
'handler' => array('midcom_admin_folder_handler_edit', 'edit'), |
|---|
| 123 |
'fixed_args' => array ('edit'), |
|---|
| 124 |
), |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
* Delete a topic |
|---|
| 128 |
* |
|---|
| 129 |
* Match /delete/ |
|---|
| 130 |
*/ |
|---|
| 131 |
'delete' => array |
|---|
| 132 |
( |
|---|
| 133 |
'handler' => array('midcom_admin_folder_handler_delete', 'delete'), |
|---|
| 134 |
'fixed_args' => array ('delete'), |
|---|
| 135 |
), |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
* Approval pseudo locations, which redirect back to the original page |
|---|
| 139 |
* after saving the new status. |
|---|
| 140 |
*/ |
|---|
| 141 |
/** |
|---|
| 142 |
* Approve a topic object |
|---|
| 143 |
* |
|---|
| 144 |
* Match /metadata/approve/ |
|---|
| 145 |
*/ |
|---|
| 146 |
'approve' => array |
|---|
| 147 |
( |
|---|
| 148 |
'handler' => array('midcom_admin_folder_handler_approvals', 'approval'), |
|---|
| 149 |
'fixed_args' => array ('approve'), |
|---|
| 150 |
), |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
* Unapprove a topic object |
|---|
| 154 |
* |
|---|
| 155 |
* Match /metadata/unapprove/ |
|---|
| 156 |
*/ |
|---|
| 157 |
'unapprove' => array |
|---|
| 158 |
( |
|---|
| 159 |
'handler' => array('midcom_admin_folder_handler_approvals', 'approval'), |
|---|
| 160 |
'fixed_args' => array ('unapprove'), |
|---|
| 161 |
), |
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
* Miscellaneous other functionalities |
|---|
| 165 |
*/ |
|---|
| 166 |
/** |
|---|
| 167 |
* Metadata editing |
|---|
| 168 |
* |
|---|
| 169 |
* Match /metadata/<object guid>/ |
|---|
| 170 |
*/ |
|---|
| 171 |
'metadata' => array |
|---|
| 172 |
( |
|---|
| 173 |
'handler' => array('midcom_admin_folder_handler_metadata', 'metadata'), |
|---|
| 174 |
'fixed_args' => array ('metadata'), |
|---|
| 175 |
'variable_args' => 1, |
|---|
| 176 |
), |
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
* Object moving |
|---|
| 180 |
* |
|---|
| 181 |
* Match /move/<object guid>/ |
|---|
| 182 |
*/ |
|---|
| 183 |
'move' => array |
|---|
| 184 |
( |
|---|
| 185 |
'handler' => array('midcom_admin_folder_handler_move', 'move'), |
|---|
| 186 |
'fixed_args' => array ('move'), |
|---|
| 187 |
'variable_args' => 1, |
|---|
| 188 |
), |
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
'order' => array |
|---|
| 192 |
( |
|---|
| 193 |
'handler' => array('midcom_admin_folder_handler_order', 'order'), |
|---|
| 194 |
'fixed_args' => array ('order'), |
|---|
| 195 |
), |
|---|
| 196 |
); |
|---|
| 197 |
} |
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
* Static method to list names of the non-purecore components |
|---|
| 201 |
* |
|---|
| 202 |
* @access public |
|---|
| 203 |
* @param string $parent_component Name of the parent component, which will pop the item first on the list |
|---|
| 204 |
* @return mixed Array containing names of the components |
|---|
| 205 |
*/ |
|---|
| 206 |
function get_component_list($parent_component = '') |
|---|
| 207 |
{ |
|---|
| 208 |
$components = array (); |
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
foreach ($_MIDCOM->componentloader->manifests as $manifest) |
|---|
| 212 |
{ |
|---|
| 213 |
|
|---|
| 214 |
if ($manifest->purecode) |
|---|
| 215 |
{ |
|---|
| 216 |
continue; |
|---|
| 217 |
} |
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
if ( ereg('^(midcom|midgard)\.', $manifest->name) |
|---|
| 221 |
&& $manifest->name != 'midcom.helper.search') |
|---|
| 222 |
{ |
|---|
| 223 |
continue; |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
if ( !is_array($manifest->_raw_data) |
|---|
| 228 |
|| !array_key_exists('package.xml', $manifest->_raw_data)) |
|---|
| 229 |
{ |
|---|
| 230 |
continue; |
|---|
| 231 |
} |
|---|
| 232 |
|
|---|
| 233 |
if (array_key_exists('description', $manifest->_raw_data['package.xml'])) |
|---|
| 234 |
{ |
|---|
| 235 |
$description = $_MIDCOM->i18n->get_string($manifest->_raw_data['package.xml']['description'], $manifest->name); |
|---|
| 236 |
} |
|---|
| 237 |
else |
|---|
| 238 |
{ |
|---|
| 239 |
$description = ''; |
|---|
| 240 |
} |
|---|
| 241 |
|
|---|
| 242 |
$components[$manifest->name] = array |
|---|
| 243 |
( |
|---|
| 244 |
'name' => $manifest->get_name_translated(), |
|---|
| 245 |
'description' => $description, |
|---|
| 246 |
'state' => @$manifest->state, |
|---|
| 247 |
'version' => $manifest->version, |
|---|
| 248 |
); |
|---|
| 249 |
} |
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
asort($components); |
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
if ( $parent_component !== '' |
|---|
| 256 |
&& array_key_exists($parent_component, $components)) |
|---|
| 257 |
{ |
|---|
| 258 |
$temp = array(); |
|---|
| 259 |
$temp[$parent_component] = $components[$parent_component]; |
|---|
| 260 |
unset($components[$parent_component]); |
|---|
| 261 |
|
|---|
| 262 |
$components = array_merge($temp, $components); |
|---|
| 263 |
} |
|---|
| 264 |
|
|---|
| 265 |
return $components; |
|---|
| 266 |
} |
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
* Static method for populating user interface for editing and creating topics |
|---|
| 270 |
* |
|---|
| 271 |
* @access public |
|---|
| 272 |
* @static |
|---|
| 273 |
* @return Array Containing a list of components |
|---|
| 274 |
*/ |
|---|
| 275 |
function list_components($parent_component = '', $all = false) |
|---|
| 276 |
{ |
|---|
| 277 |
$list = array(); |
|---|
| 278 |
|
|---|
| 279 |
foreach (midcom_admin_folder_folder_management::get_component_list() as $component => $details) |
|---|
| 280 |
{ |
|---|
| 281 |
|
|---|
| 282 |
if ( isset($GLOBALS['midcom_config']['component_listing_allowed']) |
|---|
| 283 |
&& is_array($GLOBALS['midcom_config']['component_listing_allowed']) |
|---|
| 284 |
&& !in_array($component, $GLOBALS['midcom_config']['component_listing_allowed']) |
|---|
| 285 |
&& $component !== $parent_component |
|---|
| 286 |
&& !$all) |
|---|
| 287 |
{ |
|---|
| 288 |
continue; |
|---|
| 289 |
} |
|---|
| 290 |
|
|---|
| 291 |
if ( isset($GLOBALS['midcom_config']['component_listing_excluded']) |
|---|
| 292 |
&& is_array($GLOBALS['midcom_config']['component_listing_excluded']) |
|---|
| 293 |
&& in_array($component, $GLOBALS['midcom_config']['component_listing_excluded']) |
|---|
| 294 |
&& $component !== $parent_component |
|---|
| 295 |
&& !$all) |
|---|
| 296 |
{ |
|---|
| 297 |
continue; |
|---|
| 298 |
} |
|---|
| 299 |
|
|---|
| 300 |
$list[$component] = "{$details['name']} ({$component} {$details['version']})"; |
|---|
| 301 |
} |
|---|
| 302 |
|
|---|
| 303 |
return $list; |
|---|
| 304 |
} |
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
* Static method for listing available style templates |
|---|
| 308 |
* |
|---|
| 309 |
* @access public |
|---|
| 310 |
*/ |
|---|
| 311 |
function list_styles($up = 0, $prefix = '/', $spacer = '') |
|---|
| 312 |
{ |
|---|
| 313 |
static $style_array = array(); |
|---|
| 314 |
|
|---|
| 315 |
$style_array[''] = $_MIDCOM->i18n->get_string('default', 'midcom.admin.folder'); |
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
$style_array['__create'] = $_MIDCOM->i18n->get_string('new layout template', 'midcom.admin.folder'); |
|---|
| 319 |
|
|---|
| 320 |
$qb = midcom_db_style::new_query_builder(); |
|---|
| 321 |
$qb->add_constraint('up', '=', $up); |
|---|
| 322 |
$styles = $qb->execute(); |
|---|
| 323 |
|
|---|
| 324 |
foreach ($styles as $style) |
|---|
| 325 |
{ |
|---|
| 326 |
$style_string = "{$prefix}{$style->name}"; |
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 |
if (preg_match('/(asgard|aegir|empty|spider|admin site)/i', $style_string)) |
|---|
| 330 |
{ |
|---|
| 331 |
continue; |
|---|
| 332 |
} |
|---|
| 333 |
|
|---|
| 334 |
$style_array[$style_string] = "{$spacer}{$style->name}"; |
|---|
| 335 |
midcom_admin_folder_folder_management::list_styles($style->id, $style_string . '/', $spacer . ' '); |
|---|
| 336 |
} |
|---|
| 337 |
|
|---|
| 338 |
if ($prefix === '/') |
|---|
| 339 |
{ |
|---|
| 340 |
return $style_array; |
|---|
| 341 |
} |
|---|
| 342 |
} |
|---|
| 343 |
} |
|---|
| 344 |
?> |
|---|