Source for file main.php

Documentation is available at main.php

  1. <?php
  2.  
  3. class midcom_admin_content_main {
  4. var $errcode;
  5. var $errstr;
  6. var $_mytopic;
  7. var $_mycontext;
  8. var $_topic;
  9. var $_root_topic;
  10. var $_command;
  11. var $_context;
  12. var $_l10n;
  13. var $_l10n_midcom;
  14. var $config;
  15. var $viewdata;
  16. var $msg;
  17.  
  18.  
  19. function midcom_admin_content_main($mytopic, $config, $context) {
  20. global $midcom_cachedir;
  21. global $midcom_cachehandler;
  22. global $midcom_cachemultilang;
  23. // get root_page and root_topic
  24. $page = mgd_get_object_by_guid($config->get("root_page"));
  25. if (!$page)
  26. {
  27. $GLOBALS["midcom"]->generate_error(MIDCOM_ERRCRIT,
  28. "root_page GUID invalid, please check the parameter on the AIS topic");
  29. }
  30. $topic = mgd_get_object_by_guid($config->get("root_topic"));
  31. if (!$topic)
  32. {
  33. $GLOBALS["midcom"]->generate_error(MIDCOM_ERRCRIT,
  34. "root_topic GUID invalid, please check the parameter on the AIS topic");
  35. }
  36. $this->errcode = MIDCOM_ERROK;
  37. $this->errstr = "";
  38. $this->_mytopic = $mytopic;
  39. $this->_mycontext = $context;
  40. $this->_root_topic = $topic;
  41. $this->_command = null;
  42. $this->_mode = null;
  43. $this->config = $config;
  44. $this->viewdata = array();
  45. $this->msg = "";
  46. $i18n =& $GLOBALS["midcom"]->get_service("i18n");
  47. $this->_l10n = $i18n->get_l10n("midcom.admin.content");
  48. $this->_l10n_midcom = $i18n->get_l10n("midcom");
  49. }
  50.  
  51.  
  52. function can_handle ($argc, $argv)
  53. {
  54. debug_push("midcom_admin_content_main::can_handle");
  55. debug_print_r("We have $argc Arguments:", $argv, MIDCOM_LOG_DEBUG);
  56. debug_pop();
  57. if ($argc == 0)
  58. {
  59. return true;
  60. }
  61.  
  62. if ($argc == 1)
  63. {
  64. return false;
  65. }
  66.  
  67. switch ($argv[1])
  68. {
  69. case "data":
  70. case "topic":
  71. case "meta":
  72. case "attachment":
  73. return true;
  74. default:
  75. return false;
  76. }
  77. }
  78.  
  79.  
  80. function handle($argc, $argv)
  81. {
  82. debug_push("midcom_admin_content_main::handle");
  83. global $midcom;
  84. // Disable both MidCOM and Browser-Side Caching
  85. if ( array_key_exists("midcom_helper__cache_disable", $GLOBALS)
  86. && $GLOBALS['midcom_helper__cache_disable'] == true)
  87. {
  88. $midcom->header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  89. $midcom->header("Cache-Control: no-store, no-cache, must-revalidate");
  90. $midcom->header("Pragma: no-cache");
  91. }
  92. else
  93. {
  94. $midcom->cache->content->no_cache();
  95. }
  96. if ($argc == 0)
  97. {
  98. // Redirect to the root topic
  99. debug_add("No parameters given, redirecting to the root_topic ({$this->_root_topic->id})", MIDCOM_LOG_INFO);
  100. $GLOBALS["midcom"]->relocate($midcom->get_context_data(MIDCOM_CONTEXT_ANCHORPREFIX) . "{$this->_root_topic->id}/data/");
  101. // This will exit
  102. }
  103. // Prepare the global variables
  104. $GLOBALS['view_contentmgr'] =& $this;
  105. $GLOBALS['midcom_admin_content_toolbar_main'] = new midcom_admin_content_toolbar(false, 'midcom_toolbar midcom_toolbar_ais_main', null);
  106. $GLOBALS['midcom_admin_content_toolbar_component'] = new midcom_admin_content_toolbar(true, 'midcom_toolbar', null);
  107. $GLOBALS['midcom_admin_content_toolbar_meta'] = new midcom_admin_content_toolbar(false, 'midcom_toolbar midcom_toolbar_ais_meta', null);
  108. // argv has the following format: topic_id/mode
  109. $id = array_shift($argv);
  110. $this->_topic = mgd_get_topic($id);
  111. if (! $this->_topic)
  112. {
  113. $this->errcode = MIDCOM_ERRNOTFOUND;
  114. $this->errstr = "This topic could not be loaded (Topic #{$id} not found).";
  115. return false;
  116. }
  117. if (! mgd_is_in_topic_tree($this->_root_topic->id, $this->_topic->id))
  118. {
  119. $this->errcode = MIDCOM_ERRNOTFOUND;
  120. $this->errstr = "This topic could not be loaded (Topic #{$id} is not below #{$this->_root_topic->id}).";
  121. return false;
  122. }
  123. $mode = array_shift($argv);
  124. // Prepare and enter context:
  125. $prefix = $midcom->get_context_data(MIDCOM_CONTEXT_ANCHORPREFIX) . "{$this->_topic->id}/{$mode}/";
  126. $this->_context = $midcom->_create_context();
  127. $oldcontext = $midcom->get_current_context();
  128. $midcom->_set_current_context($this->_context);
  129. $midcom->_set_context_data($prefix, MIDCOM_CONTEXT_ANCHORPREFIX);
  130. $midcom->_set_context_data("admin", MIDCOM_CONTEXT_SUBSTYLE);
  131. $midcom->_set_context_data(MIDCOM_REQUEST_CONTENTADM, MIDCOM_CONTEXT_REQUESTTYPE);
  132. $midcom->_set_context_data($this->_root_topic, MIDCOM_CONTEXT_ROOTTOPIC);
  133. $midcom->_set_context_data($this->_topic, MIDCOM_CONTEXT_CONTENTTOPIC);
  134. $midcom->_set_context_data($this->_topic->parameter("midcom","component"), MIDCOM_CONTEXT_COMPONENT);
  135. debug_print_r("Context created: ", $midcom->_context[$this->_context]);
  136. $this->viewdata["context"] = $this->_context;
  137. $this->viewdata["adminprefix"] = $midcom->get_context_data($this->_mycontext, MIDCOM_CONTEXT_ANCHORPREFIX);
  138. $this->viewdata["admintopicprefix"] = $this->viewdata["adminprefix"] . $this->_topic->id . "/";
  139. $this->viewdata["adminmode"] = $mode;
  140. debug_print_r("Local Data Cache: ", $this->viewdata, MIDCOM_LOG_DEBUG);
  141. switch ($mode) {
  142. case "data":
  143. debug_add("We are in Data Mode");
  144. $this->_command = new midcom_admin_content__cmddata ($argv, $this);
  145. break;
  146. case "topic":
  147. debug_add("We are in Topic Mode.");
  148. $this->_command = new midcom_admin_content__cmdtopic ($argv, $this);
  149. break;
  150. case "attachment":
  151. debug_add("We are in Attachment Mode.");
  152. $this->_command = new midcom_admin_content__cmdattachment ($argv, $this);
  153. break;
  154. case 'meta':
  155. debug_add("We are in Metadata Mode.");
  156. $this->_command = new midcom_admin_content__cmdmeta ($argv, $this);
  157. break;
  158. default:
  159. $this->errcode = MIDCOM_ERRCRIT;
  160. $this->errstr = "Content Administration: Method " . $mode . " unknown.";
  161. debug_pop();
  162. return false;
  163. }
  164. debug_print_type("Command object has been created: ", $this->_command, MIDCOM_LOG_DEBUG);
  165. debug_add("Preparing Main Toolbar...");
  166. $this->_prepare_main_toolbar();
  167. debug_add("Command executing now.", MIDCOM_LOG_DEBUG);
  168. $result = $this->_command->execute();
  169. debug_add("Command execution Result was: " . $result, MIDCOM_LOG_DEBUG);
  170. debug_add("Preparing Meta Toolbar...");
  171. $this->_prepare_meta_toolbar();
  172. $midcom->_set_current_context($oldcontext);
  173. debug_pop();
  174. return $result;
  175. }
  176. /**
  177. * This function prepares the main content admin toolbar, adding
  178. * the following buttons to it:
  179. *
  180. * - Create topic (poweruser or topic owner, restriction possible through restrict_create config directive)
  181. * - Edit topic (poweruser or topic owner)
  182. * - Delete topic (poweruser or topic owner, restriction possible through restrict_delete config directive)
  183. * - Manage topic attachments (poweruser or topic owner)
  184. */
  185. function _prepare_main_toolbar() {
  186. $adminuser = false;
  187. $poweruser = false;
  188. $topicowner = false;
  189. $restrict_delete = $GLOBALS["midcom_admin_content_topicadmin_config"]["restrict_delete"];
  190. $restrict_create = $GLOBALS["midcom_admin_content_topicadmin_config"]["restrict_create"];
  191. $toolbar =& $GLOBALS['midcom_admin_content_toolbar_main'];
  192. $midgard = $GLOBALS['midcom']->get_midgard();
  193. if ($midgard->admin) {
  194. $adminuser = true;
  195. } else {
  196. $user = mgd_get_person($midgard->user);
  197. if ($user !== false) {
  198. // This parameter is not set for power users
  199. if ($user->parameter("Interface", "Power_User") != "NO")
  200. {
  201. $poweruser = true;
  202. }
  203. $topic = $GLOBALS['midcom']->get_context_data($GLOBALS["view_contentmgr"]->viewdata["context"],
  204. MIDCOM_CONTEXT_CONTENTTOPIC);
  205. if (mgd_is_topic_owner($topic->id))
  206. {
  207. $topicowner = true;
  208. }
  209. }
  210. }
  211. if ($adminuser || ($poweruser && $topicowner))
  212. {
  213. $toolbar->add_item(Array(
  214. MIDCOM_TOOLBAR_URL => "{$this->viewdata['admintopicprefix']}topic/create/",
  215. MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("create subtopic"),
  216. MIDCOM_TOOLBAR_HELPTEXT => null,
  217. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/new-dir.png',
  218. MIDCOM_TOOLBAR_ENABLED => true
  219. ));
  220. $toolbar->add_item(Array(
  221. MIDCOM_TOOLBAR_URL => "{$this->viewdata['admintopicprefix']}topic/edit/",
  222. MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("edit topic"),
  223. MIDCOM_TOOLBAR_HELPTEXT => null,
  224. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit-folder.png',
  225. MIDCOM_TOOLBAR_ENABLED => true
  226. ));
  227. $toolbar->add_item(Array(
  228. MIDCOM_TOOLBAR_URL => "{$this->viewdata['admintopicprefix']}topic/score/",
  229. MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("edit order"),
  230. MIDCOM_TOOLBAR_HELPTEXT => null,
  231. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/topic-score.png',
  232. MIDCOM_TOOLBAR_ENABLED => true
  233. ));
  234. $toolbar->add_item(Array(
  235. MIDCOM_TOOLBAR_URL => "{$this->viewdata['admintopicprefix']}topic/delete/",
  236. MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("delete topic"),
  237. MIDCOM_TOOLBAR_HELPTEXT => null,
  238. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png',
  239. MIDCOM_TOOLBAR_ENABLED => true
  240. ));
  241. $toolbar->add_item(Array(
  242. MIDCOM_TOOLBAR_URL => "{$this->viewdata['admintopicprefix']}attachment/",
  243. MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("topic attachments"),
  244. MIDCOM_TOOLBAR_HELPTEXT => null,
  245. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/attach.png',
  246. MIDCOM_TOOLBAR_ENABLED => true
  247. ));
  248. }
  249. else if ($topicowner && ! $poweruser)
  250. {
  251. if (! $restrict_create)
  252. {
  253. $toolbar->add_item(Array(
  254. MIDCOM_TOOLBAR_URL => "{$this->viewdata['admintopicprefix']}topic/create/",
  255. MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("create subtopic"),
  256. MIDCOM_TOOLBAR_HELPTEXT => null,
  257. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/new-dir.png',
  258. MIDCOM_TOOLBAR_ENABLED => true
  259. ));
  260. }
  261. $toolbar->add_item(Array(
  262. MIDCOM_TOOLBAR_URL => "{$this->viewdata['admintopicprefix']}topic/edit/",
  263. MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("edit topic"),
  264. MIDCOM_TOOLBAR_HELPTEXT => null,
  265. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit-folder.png',
  266. MIDCOM_TOOLBAR_ENABLED => true
  267. ));
  268. if (! $restrict_delete)
  269. {
  270. $toolbar->add_item(Array(
  271. MIDCOM_TOOLBAR_URL => "{$this->viewdata['admintopicprefix']}topic/delete/",
  272. MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("delete topic"),
  273. MIDCOM_TOOLBAR_HELPTEXT => null,
  274. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png',
  275. MIDCOM_TOOLBAR_ENABLED => true
  276. ));
  277. }
  278. $toolbar->add_item(Array(
  279. MIDCOM_TOOLBAR_URL => "{$this->viewdata['admintopicprefix']}attachment/",
  280. MIDCOM_TOOLBAR_LABEL => $this->_l10n->get("topic attachments"),
  281. MIDCOM_TOOLBAR_HELPTEXT => null,
  282. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/attach.png',
  283. MIDCOM_TOOLBAR_ENABLED => true
  284. ));
  285. }
  286. }
  287. function _prepare_meta_toolbar()
  288. {
  289. $topic = $GLOBALS['midcom']->get_context_data($GLOBALS["view_contentmgr"]->viewdata["context"], MIDCOM_CONTEXT_CONTENTTOPIC);
  290.  
  291. // First, we retrieve a metadata object for the currently active object.
  292. // We can only create a toolbar if and only if
  293. $nav = new midcom_helper_nav($this->_context);
  294. $nap_obj = null;
  295. if ($nav->get_current_leaf() !== false)
  296. {
  297. $nap_obj = $nav->get_leaf($nav->get_current_leaf());
  298. }
  299. else
  300. {
  301. $nap_obj = $nav->get_node($nav->get_current_node());
  302. }
  303. $meta =& midcom_helper_metadata::retrieve($nap_obj);
  304. if (! $meta)
  305. {
  306. debug_print_r("Failed to load the Metadata object for this NAP object, we don't create a toolbar therefore:", $nap_obj);
  307. return;
  308. }
  309. // Read old-style Aegir "approval" privileges
  310. // TODO: This should be done via ACL instead
  311. $memberships = mgd_list_memberships($_MIDGARD['user']);
  312. $can_approve = false;
  313. if ($memberships)
  314. {
  315. while ( !$can_approve
  316. && $memberships->fetch())
  317. {
  318. $grp = mgd_get_group($memberships->gid);
  319. if ($grp)
  320. {
  321. $approve_param = $grp->parameter('Interface', 'Approve_Website');
  322. if ($approve_param != 'NO')
  323. {
  324. // User can approve if any of the groups she belongs to is allowed to do it
  325. $can_approve = true;
  326. }
  327. }
  328. }
  329. }
  330. if (mgd_is_topic_owner($topic->id))
  331. {
  332. $toolbar =& $GLOBALS['midcom_admin_content_toolbar_meta'];
  333. $prefix = "{$this->viewdata['admintopicprefix']}meta/{$nap_obj[MIDCOM_NAV_GUID]}";
  334. $toolbar->add_item(Array(
  335. MIDCOM_TOOLBAR_URL => null,
  336. MIDCOM_TOOLBAR_LABEL => sprintf($this->_l10n->get('metadata for %s'), $nap_obj[MIDCOM_NAV_NAME]),
  337. MIDCOM_TOOLBAR_HELPTEXT => "GUID: {$nap_obj[MIDCOM_NAV_GUID]}" ,
  338. MIDCOM_TOOLBAR_ICON => null,
  339. MIDCOM_TOOLBAR_ENABLED => false,
  340. ));
  341. if ( $meta->is_approved()
  342. && $can_approve)
  343. {
  344. $toolbar->add_item(Array(
  345. MIDCOM_TOOLBAR_URL => "{$prefix}/unapprove.html",
  346. MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('unapprove'),
  347. MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('approved'),
  348. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/approved.png',
  349. MIDCOM_TOOLBAR_ENABLED => true,
  350. ));
  351. }
  352. elseif ($can_approve)
  353. {
  354. $toolbar->add_item(Array(
  355. MIDCOM_TOOLBAR_URL => "{$prefix}/approve.html",
  356. MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('approve'),
  357. MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('unapproved'),
  358. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/not_approved.png',
  359. MIDCOM_TOOLBAR_ENABLED => true,
  360. ));
  361. }
  362. if ($meta->get('hide'))
  363. {
  364. $toolbar->add_item(Array(
  365. MIDCOM_TOOLBAR_URL => "{$prefix}/unhide.html",
  366. MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('unhide'),
  367. MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('hidden'),
  368. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/hidden.png',
  369. MIDCOM_TOOLBAR_ENABLED => true,
  370. ));
  371. }
  372. else
  373. {
  374. $toolbar->add_item(Array(
  375. MIDCOM_TOOLBAR_URL => "{$prefix}/hide.html",
  376. MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('hide'),
  377. MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('not hidden'),
  378. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/not_hidden.png',
  379. MIDCOM_TOOLBAR_ENABLED => true,
  380. ));
  381. }
  382. $toolbar->add_item(Array(
  383. MIDCOM_TOOLBAR_URL => "{$prefix}/edit.html",
  384. MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('edit metadata'),
  385. MIDCOM_TOOLBAR_HELPTEXT => null,
  386. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/properties.png',
  387. MIDCOM_TOOLBAR_ENABLED => true,
  388. ));
  389. $start = $meta->get('schedule_start');
  390. $end = $meta->get('schedule_end');
  391. if ($start || $end)
  392. {
  393. $now = time();
  394. $text = '';
  395. if ($start && $end)
  396. {
  397. $text = sprintf($this->_l10n_midcom->get('shown from %s to %s'),
  398. strftime("%x %X", $start),
  399. strftime("%x %X", $end));
  400. }
  401. else if ($start)
  402. {
  403. $text = sprintf($this->_l10n_midcom->get('shown from %s'),
  404. strftime("%x %X", $start));
  405. }
  406. else
  407. {
  408. $text = sprintf($this->_l10n_midcom->get('shown until %s'),
  409. strftime("%x %X", $end));
  410. }
  411. if ( (! $start || $start <= $now)
  412. && (! $end || $end >= $now))
  413. {
  414. $toolbar->add_item(Array(
  415. MIDCOM_TOOLBAR_URL => null,
  416. MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('scheduled and shown'),
  417. MIDCOM_TOOLBAR_HELPTEXT => $text,
  418. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/scheduled_and_shown.png',
  419. MIDCOM_TOOLBAR_ENABLED => false,
  420. ));
  421. }
  422. else
  423. {
  424. $toolbar->add_item(Array(
  425. MIDCOM_TOOLBAR_URL => null,
  426. MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('scheduled but hidden'),
  427. MIDCOM_TOOLBAR_HELPTEXT => $text,
  428. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/scheduled_but_hidden.png',
  429. MIDCOM_TOOLBAR_ENABLED => false,
  430. ));
  431. }
  432. }
  433. }
  434. }
  435. function show() {
  436. global $midcom;
  437. $oldcontext = $midcom->get_current_context();
  438. $midcom->_set_current_context($this->_context);
  439. if ($this->viewdata["adminmode"] == "data") {
  440. // Enter the style context of the component handling the request
  441. // Show the style-init element of the corresponding style.
  442. $midcom->style->enter_context($this->_context);
  443. midcom_show_style("style-init");
  444. }
  445. $this->_command->show();
  446. $midcom->_set_current_context($oldcontext);
  447. if ($this->viewdata["adminmode"] == "data") {
  448. // Show the style-finish element of the component handling the request.
  449. // Then leave the corresponding style context.
  450. midcom_show_style("style-finish");
  451. $midcom->style->leave_context();
  452. }
  453. $midcom->_set_current_context($oldcontext);
  454. }
  455. /* These functions are deprecated now and for compaitibility only */
  456. function add_jsfile($url) { $GLOBALS["midcom"]->add_jsfile($url); }
  457. function add_jscript($script) { $GLOBALS["midcom"]->add_jscript($script); }
  458. function add_jsonload($method) { $GLOBALS["midcom"]->add_jsonload($method); }
  459. function print_jscripts() { return $GLOBALS["midcom"]->print_jscripts(); }
  460. function print_jsonload() { return $GLOBALS["midcom"]->print_jsonload(); }
  461.  
  462. }
  463.  
  464. // Declare the globals
  465.  
  466. /**
  467. * Global reference to the Conent Manager.
  468. *
  469. * Was originally used to gain access to the JScript hooks. Since
  470. * these functions have been moved into midcom_application, the
  471. * usage of this global is deprecated.
  472. *
  473. * @global midcom_admin_content $GLOBALS['view_contentmgr']
  474. * @deprecated Since 2.0.0, Use midcom_application's JScript hooks.
  475. */
  476. $GLOBALS['view_contentmgr'] = null;
  477.  
  478. /**
  479. * Global reference to the main content manager toolbar.
  480. *
  481. * This toolbar is usually initialized with the topic editing
  482. * UI (depending on the permissions set) and the view page link.
  483. *
  484. * It disables the view-this-page-link feature of midcom_admin_content_toolbar.
  485. *
  486. * @global midcom_admin_content_toolbar $GLOBALS['midcom_admin_content_toolbar_main']
  487. */
  488. $GLOBALS['midcom_admin_content_toolbar_main'] = null;
  489.  
  490. /**
  491. * Global reference to the component content manager toolbar.
  492. *
  493. * This toolbar is initialized empty and can be set by the component
  494. * at-will. It is rendered between the heading of the component and the actual
  495. * content admin class output.
  496. *
  497. * It enables the view-this-page-link feature of midcom_admin_content_toolbar.
  498. *
  499. * @global midcom_admin_content_toolbar $GLOBALS['midcom_admin_content_toolbar_component']
  500. */
  501. $GLOBALS['midcom_admin_content_toolbar_component'] = null;
  502.  
  503.  
  504. ?>

Documentation generated on Mon, 21 Nov 2005 18:18:25 +0100 by phpDocumentor 1.3.0RC3