| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
class midcom_admin_styleeditor_admin extends midcom_baseclasses_components_request_admin { |
|---|
| 10 |
|
|---|
| 11 |
var $msg; |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
* @var current_topic |
|---|
| 15 |
* @access public |
|---|
| 16 |
**/ |
|---|
| 17 |
var $_current_topic = 0; |
|---|
| 18 |
|
|---|
| 19 |
var $_session = null; |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
* The schema database associated with articles. |
|---|
| 23 |
* |
|---|
| 24 |
* @var Array |
|---|
| 25 |
* @access private |
|---|
| 26 |
*/ |
|---|
| 27 |
var $_schemadb = Array(); |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
function __construct($topic, $config) |
|---|
| 31 |
{ |
|---|
| 32 |
|
|---|
| 33 |
parent::__construct($topic, $config); |
|---|
| 34 |
|
|---|
| 35 |
$this->msg = ""; |
|---|
| 36 |
|
|---|
| 37 |
$this->_session = new midcom_service_session(); |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
function _on_initialize() { |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
$_MIDCOM->cache->content->no_cache(); |
|---|
| 44 |
$_MIDCOM->auth->require_valid_user(); |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
$this->request_switch[] = Array |
|---|
| 48 |
( |
|---|
| 49 |
'fixed_args' => array('edit'), |
|---|
| 50 |
'handler' => array('midcom_admin_styleeditor_style','edit_root_element'), |
|---|
| 51 |
'variable_args' => 1, |
|---|
| 52 |
); |
|---|
| 53 |
|
|---|
| 54 |
$this->request_switch[] = Array |
|---|
| 55 |
( |
|---|
| 56 |
'fixed_args' => array('edit'), |
|---|
| 57 |
'handler' => array('midcom_admin_styleeditor_style','edit_element'), |
|---|
| 58 |
'variable_args' => 2, |
|---|
| 59 |
); |
|---|
| 60 |
$this->request_switch[] = Array |
|---|
| 61 |
( |
|---|
| 62 |
'fixed_args' => array('configure'), |
|---|
| 63 |
'handler' => array('midcom_admin_styleeditor_style','edit'), |
|---|
| 64 |
'variable_args' => 1, |
|---|
| 65 |
); |
|---|
| 66 |
$this->request_switch[] = Array |
|---|
| 67 |
( |
|---|
| 68 |
'fixed_args' => array('new'), |
|---|
| 69 |
'handler' => array('midcom_admin_styleeditor_style','edit'), |
|---|
| 70 |
'variable_args' => 1, |
|---|
| 71 |
); |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
* This function adds all of the standard items (configuration and create links) |
|---|
| 76 |
* to the topic toolbar. |
|---|
| 77 |
* |
|---|
| 78 |
* @access private |
|---|
| 79 |
*/ |
|---|
| 80 |
function _prepare_toolbar() |
|---|
| 81 |
{ |
|---|
| 82 |
$toolbar = &midcom_helper_toolbars::get_instance(); |
|---|
| 83 |
$toolbar->top->add_item(Array( |
|---|
| 84 |
MIDCOM_TOOLBAR_URL => 'config/', |
|---|
| 85 |
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('component configuration'), |
|---|
| 86 |
MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('component configuration helptext'), |
|---|
| 87 |
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_folder-properties.png', |
|---|
| 88 |
MIDCOM_TOOLBAR_ENABLED => true, |
|---|
| 89 |
MIDCOM_TOOLBAR_HIDDEN => |
|---|
| 90 |
( |
|---|
| 91 |
! $_MIDCOM->auth->can_do('midgard:update', $this->_topic) |
|---|
| 92 |
|| ! $_MIDCOM->auth->can_do('midcom:component_config', $this->_topic) |
|---|
| 93 |
) |
|---|
| 94 |
)); |
|---|
| 95 |
|
|---|
| 96 |
if (0) foreach (array_reverse($this->_schemadb_article_index, true) as $name => $desc) |
|---|
| 97 |
{ |
|---|
| 98 |
$text = sprintf($this->_l10n_midcom->get('create %s'), $desc); |
|---|
| 99 |
$toolbar->top->add_item( |
|---|
| 100 |
Array |
|---|
| 101 |
( |
|---|
| 102 |
MIDCOM_TOOLBAR_URL => "create/{$name}/", |
|---|
| 103 |
MIDCOM_TOOLBAR_LABEL => $text, |
|---|
| 104 |
MIDCOM_TOOLBAR_HELPTEXT => null, |
|---|
| 105 |
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_new.png', |
|---|
| 106 |
MIDCOM_TOOLBAR_ENABLED => true, |
|---|
| 107 |
MIDCOM_TOOLBAR_HIDDEN => ($_MIDCOM->auth->can_do('midgard:create', $this->_topic) == false) |
|---|
| 108 |
), 0); |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
$current_topic = $this->_current_topic; |
|---|
| 112 |
|
|---|
| 113 |
$toolbar->top->add_item(Array( |
|---|
| 114 |
MIDCOM_TOOLBAR_URL => "styleeditor/topic/create/{$current_topic}", |
|---|
| 115 |
MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("create subtopic"), |
|---|
| 116 |
MIDCOM_TOOLBAR_HELPTEXT => null, |
|---|
| 117 |
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/new-dir.png', |
|---|
| 118 |
MIDCOM_TOOLBAR_ENABLED => true |
|---|
| 119 |
)); |
|---|
| 120 |
$toolbar->top->add_item(Array( |
|---|
| 121 |
MIDCOM_TOOLBAR_URL => "styleeditor/topic/edit/{$current_topic}", |
|---|
| 122 |
MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("edit topic"), |
|---|
| 123 |
MIDCOM_TOOLBAR_HELPTEXT => null, |
|---|
| 124 |
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit-folder.png', |
|---|
| 125 |
MIDCOM_TOOLBAR_ENABLED => true |
|---|
| 126 |
)); |
|---|
| 127 |
$toolbar->top->add_item(Array( |
|---|
| 128 |
MIDCOM_TOOLBAR_URL => "styleeditor/topic/score/{$current_topic}", |
|---|
| 129 |
MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("edit order"), |
|---|
| 130 |
MIDCOM_TOOLBAR_HELPTEXT => null, |
|---|
| 131 |
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/topic-score.png', |
|---|
| 132 |
MIDCOM_TOOLBAR_ENABLED => true |
|---|
| 133 |
)); |
|---|
| 134 |
$toolbar->top->add_item(Array( |
|---|
| 135 |
MIDCOM_TOOLBAR_URL => "styleeditor/topic/delete/{$current_topic}", |
|---|
| 136 |
MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("delete topic"), |
|---|
| 137 |
MIDCOM_TOOLBAR_HELPTEXT => null, |
|---|
| 138 |
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png', |
|---|
| 139 |
MIDCOM_TOOLBAR_ENABLED => true |
|---|
| 140 |
)); |
|---|
| 141 |
|
|---|
| 142 |
$toolbar->top->add_item(Array( |
|---|
| 143 |
MIDCOM_TOOLBAR_URL => "attachment/{$current_topic}", |
|---|
| 144 |
MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("topic attachments"), |
|---|
| 145 |
MIDCOM_TOOLBAR_HELPTEXT => null, |
|---|
| 146 |
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/attach.png', |
|---|
| 147 |
MIDCOM_TOOLBAR_ENABLED => true |
|---|
| 148 |
)); |
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
} |
|---|
| 152 |
|
|---|
| 153 |
function _prepare_meta_toolbar() |
|---|
| 154 |
{ |
|---|
| 155 |
$topic = $GLOBALS['midcom']->get_context_data($GLOBALS["view_contentmgr"]->viewdata["context"], MIDCOM_CONTEXT_CONTENTTOPIC); |
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
// We can only create a toolbar if and only if |
|---|
| 159 |
$nav = new midcom_helper_nav($this->_context); |
|---|
| 160 |
$nap_obj = null; |
|---|
| 161 |
if ($nav->get_current_leaf() !== false) |
|---|
| 162 |
{ |
|---|
| 163 |
$nap_obj = $nav->get_leaf($nav->get_current_leaf()); |
|---|
| 164 |
} |
|---|
| 165 |
else |
|---|
| 166 |
{ |
|---|
| 167 |
$nap_obj = $nav->get_node($nav->get_current_node()); |
|---|
| 168 |
} |
|---|
| 169 |
$meta =& midcom_helper_metadata::retrieve($nap_obj); |
|---|
| 170 |
if (! $meta) |
|---|
| 171 |
{ |
|---|
| 172 |
debug_print_r("Failed to load the Metadata object for this NAP object, we don't create a toolbar therefore:", $nap_obj); |
|---|
| 173 |
return; |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
if (mgd_is_topic_owner($topic->id)) |
|---|
| 177 |
{ |
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
$prefix = "{$this->viewdata['admintopicprefix']}meta/{$nap_obj[MIDCOM_NAV_GUID]}"; |
|---|
| 181 |
|
|---|
| 182 |
$toolbar->add_item(Array( |
|---|
| 183 |
MIDCOM_TOOLBAR_URL => null, |
|---|
| 184 |
MIDCOM_TOOLBAR_LABEL => sprintf($this->_l10n->get('metadata for %s'), $nap_obj[MIDCOM_NAV_NAME]), |
|---|
| 185 |
MIDCOM_TOOLBAR_HELPTEXT => "GUID: {$nap_obj[MIDCOM_NAV_GUID]}" , |
|---|
| 186 |
MIDCOM_TOOLBAR_ICON => null, |
|---|
| 187 |
MIDCOM_TOOLBAR_ENABLED => false, |
|---|
| 188 |
)); |
|---|
| 189 |
|
|---|
| 190 |
if ($meta->is_approved()) |
|---|
| 191 |
{ |
|---|
| 192 |
$toolbar->add_item(Array( |
|---|
| 193 |
MIDCOM_TOOLBAR_URL => "{$prefix}/unapprove/", |
|---|
| 194 |
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('unapprove'), |
|---|
| 195 |
MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('approved'), |
|---|
| 196 |
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/approved.png', |
|---|
| 197 |
MIDCOM_TOOLBAR_ENABLED => true, |
|---|
| 198 |
)); |
|---|
| 199 |
} |
|---|
| 200 |
else |
|---|
| 201 |
{ |
|---|
| 202 |
$toolbar->add_item(Array( |
|---|
| 203 |
MIDCOM_TOOLBAR_URL => "{$prefix}/approve/", |
|---|
| 204 |
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('approve'), |
|---|
| 205 |
MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('unapproved'), |
|---|
| 206 |
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/not_approved.png', |
|---|
| 207 |
MIDCOM_TOOLBAR_ENABLED => true, |
|---|
| 208 |
)); |
|---|
| 209 |
} |
|---|
| 210 |
|
|---|
| 211 |
if ($meta->get('hide')) |
|---|
| 212 |
{ |
|---|
| 213 |
$toolbar->add_item(Array( |
|---|
| 214 |
MIDCOM_TOOLBAR_URL => "{$prefix}/unhide/", |
|---|
| 215 |
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('unhide'), |
|---|
| 216 |
MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('hidden'), |
|---|
| 217 |
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/hidden.png', |
|---|
| 218 |
MIDCOM_TOOLBAR_ENABLED => true, |
|---|
| 219 |
)); |
|---|
| 220 |
} |
|---|
| 221 |
else |
|---|
| 222 |
{ |
|---|
| 223 |
$toolbar->add_item(Array( |
|---|
| 224 |
MIDCOM_TOOLBAR_URL => "{$prefix}/hide/", |
|---|
| 225 |
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('hide'), |
|---|
| 226 |
MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('not hidden'), |
|---|
| 227 |
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/not_hidden.png', |
|---|
| 228 |
MIDCOM_TOOLBAR_ENABLED => true, |
|---|
| 229 |
)); |
|---|
| 230 |
} |
|---|
| 231 |
|
|---|
| 232 |
$toolbar->add_item(Array( |
|---|
| 233 |
MIDCOM_TOOLBAR_URL => "{$prefix}/edit/", |
|---|
| 234 |
MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('edit metadata'), |
|---|
| 235 |
MIDCOM_TOOLBAR_HELPTEXT => null, |
|---|
| 236 |
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/properties.png', |
|---|
| 237 |
MIDCOM_TOOLBAR_ENABLED => true, |
|---|
| 238 |
)); |
|---|
| 239 |
|
|---|
| 240 |
$start = $meta->get('schedule_start'); |
|---|
| 241 |
$end = $meta->get('schedule_end'); |
|---|
| 242 |
if ($start || $end) |
|---|
| 243 |
{ |
|---|
| 244 |
$now = time(); |
|---|
| 245 |
|
|---|
| 246 |
$text = ''; |
|---|
| 247 |
if ($start && $end) |
|---|
| 248 |
{ |
|---|
| 249 |
$text = sprintf($this->_l10n_midcom->get('shown from %s to %s'), |
|---|
| 250 |
strftime("%x %X", $start), |
|---|
| 251 |
strftime("%x %X", $end)); |
|---|
| 252 |
} |
|---|
| 253 |
else if ($start) |
|---|
| 254 |
{ |
|---|
| 255 |
$text = sprintf($this->_l10n_midcom->get('shown from %s'), |
|---|
| 256 |
strftime("%x %X", $start)); |
|---|
| 257 |
} |
|---|
| 258 |
else |
|---|
| 259 |
{ |
|---|
| 260 |
$text = sprintf($this->_l10n_midcom->get('shown until %s'), |
|---|
| 261 |
strftime("%x %X", $end)); |
|---|
| 262 |
} |
|---|
| 263 |
|
|---|
| 264 |
if ( (! $start || $start <= $now) |
|---|
| 265 |
&& (! $end || $end >= $now)) |
|---|
| 266 |
{ |
|---|
| 267 |
$toolbar->add_item(Array( |
|---|
| 268 |
MIDCOM_TOOLBAR_URL => null, |
|---|
| 269 |
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('scheduled and shown'), |
|---|
| 270 |
MIDCOM_TOOLBAR_HELPTEXT => $text, |
|---|
| 271 |
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/scheduled_and_shown.png', |
|---|
| 272 |
MIDCOM_TOOLBAR_ENABLED => false, |
|---|
| 273 |
)); |
|---|
| 274 |
} |
|---|
| 275 |
else |
|---|
| 276 |
{ |
|---|
| 277 |
$toolbar->add_item(Array( |
|---|
| 278 |
MIDCOM_TOOLBAR_URL => null, |
|---|
| 279 |
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('scheduled but hidden'), |
|---|
| 280 |
MIDCOM_TOOLBAR_HELPTEXT => $text, |
|---|
| 281 |
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/scheduled_but_hidden.png', |
|---|
| 282 |
MIDCOM_TOOLBAR_ENABLED => false, |
|---|
| 283 |
)); |
|---|
| 284 |
} |
|---|
| 285 |
} |
|---|
| 286 |
} |
|---|
| 287 |
} |
|---|
| 288 |
|
|---|
| 289 |
function _handler_index() { |
|---|
| 290 |
|
|---|
| 291 |
return true; |
|---|
| 292 |
} |
|---|
| 293 |
|
|---|
| 294 |
function _show_index() { |
|---|
| 295 |
midcom_show_style('index'); |
|---|
| 296 |
} |
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
* Display the content, it uses the handler as determined by can_handle. |
|---|
| 301 |
* This overrides the basic show method of the class to include the ais style around the component. |
|---|
| 302 |
* |
|---|
| 303 |
* @see _on_show(); |
|---|
| 304 |
*/ |
|---|
| 305 |
function show() |
|---|
| 306 |
{ |
|---|
| 307 |
debug_push_class($this, 'show'); |
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
$result = $this->_on_show($this->_handler['id']); |
|---|
| 313 |
if (! $result) |
|---|
| 314 |
{ |
|---|
| 315 |
debug_add('The _on_show event handler returned false, aborting.'); |
|---|
| 316 |
debug_pop(); |
|---|
| 317 |
return; |
|---|
| 318 |
} |
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
$handler =& $this->_handler['handler'][0]; |
|---|
| 322 |
$method = "_show_{$this->_handler['handler'][1]}"; |
|---|
| 323 |
|
|---|
| 324 |
$handler->$method($this->_handler['id'], $this->_request_data); |
|---|
| 325 |
debug_pop(); |
|---|
| 326 |
} |
|---|
| 327 |
|
|---|
| 328 |
} |
|---|
| 329 |
|
|---|
| 330 |
?> |
|---|