Source for file navigation.php

Documentation is available at navigation.php

  1. <?php
  2.  
  3. class net_nemein_bookmarks_navigation
  4. {
  5. var $_topic;
  6. var $_config_topic;
  7. var $_config;
  8. var $_l10n;
  9. var $_l10n_midcom;
  10. var $_oldest_time;
  11. var $_oldest_creator;
  12. var $_latest_time;
  13. var $_latest_revisor;
  14.  
  15. function net_nemein_bookmarks_navigation()
  16. {
  17. $this->_topic = null;
  18. $this->_config_topic = null;
  19. $this->_config = $GLOBALS["midcom_component_data"]['net.nemein.bookmarks']['config'];
  20. $i18n =& $GLOBALS["midcom"]->get_service("i18n");
  21. $this->_l10n = $i18n->get_l10n("net.nemein.bookmarks");
  22. $this->_l10n_midcom = $i18n->get_l10n("midcom");
  23. $this->_oldest_time = null;
  24. $this->_oldest_creator = null;
  25. $this->_latest_time = null;
  26. $this->_latest_revisor = null;
  27. }
  28.  
  29. function is_internal()
  30. {
  31. return false;
  32. }
  33.  
  34. function get_leaves()
  35. {
  36. $topic = &$this->_topic;
  37. $leaves = array ();
  38. $now = time();
  39. $tags = net_nemein_bookmarks_helper_list_tags($topic->id);
  40. // Prep toolbar
  41. $toolbar[50] = Array(
  42. MIDCOM_TOOLBAR_URL => '',
  43. MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('edit'),
  44. MIDCOM_TOOLBAR_HELPTEXT => null,
  45. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit.png',
  46. MIDCOM_TOOLBAR_ENABLED => true
  47. );
  48. // Tags are the actual shown leaves
  49. foreach($tags as $tag => $bookmarks)
  50. {
  51. $active = "true";
  52. $showtag = "false";
  53. foreach($bookmarks as $bookmark)
  54. {
  55. if ($_MIDGARD['user'] == $bookmark->author || $_MIDGARD['admin'])
  56. {
  57. $showtag = "true";
  58. break;
  59. } elseif (!$_MIDGARD['user']) {
  60. $showtag = "true";
  61. break;
  62. }
  63. }
  64. if ($showtag == "true" && !empty($tag))
  65. {
  66. // Figure out when the tag was first used and when last edited
  67. foreach ($bookmarks as $url => $object)
  68. {
  69. // Bookmarks must be leaves to support searching
  70. $leaves[$object->id] = array (
  71. MIDCOM_NAV_SITE =>
  72. Array (
  73. MIDCOM_NAV_URL => rawurlencode($tag).".html",
  74. MIDCOM_NAV_NAME => $object->title,
  75. ),
  76. MIDCOM_NAV_ADMIN => null,
  77. MIDCOM_NAV_NOENTRY => true,
  78. MIDCOM_NAV_GUID => $object->guid(),
  79. MIDCOM_META_CREATOR => $object->creator,
  80. MIDCOM_META_EDITOR => $object->revisor,
  81. MIDCOM_META_CREATED => $object->created,
  82. MIDCOM_META_EDITED => $object->revised
  83. );
  84. if ($object->created < $this->_oldest_time || !$this->_oldest_time)
  85. {
  86. // Oldest not set or article is older than it
  87. $this->_oldest_time = $object->created;
  88. $this->_oldest_creator = $object->creator;
  89. }
  90. if ($object->revised > $this->_latest_time || !$this->_latest_time)
  91. {
  92. // Latest not set or article is newer than it
  93. $this->_latest_time = $object->revised;
  94. $this->_latest_revisor = $object->revisor;
  95. }
  96. }
  97. $bookmark_count = count($tags[$tag]);
  98. $toolbar[50][MIDCOM_TOOLBAR_URL] = "list/{$tag}.html";
  99. $leaves[$tag] = array (
  100. MIDCOM_NAV_SITE =>
  101. Array (
  102. MIDCOM_NAV_URL => rawurlencode($tag).".html",
  103. MIDCOM_NAV_NAME => $tag . " (" . $bookmark_count . ")"
  104. ),
  105. MIDCOM_NAV_ADMIN => Array (
  106. MIDCOM_NAV_URL => "list/" . rawurlencode($tag),
  107. MIDCOM_NAV_NAME => $tag . " (" . $bookmark_count . ")"),
  108. MIDCOM_NAV_VISIBLE => $active,
  109. MIDCOM_NAV_TOOLBAR => $toolbar,
  110. MIDCOM_NAV_GUID => $this->_topic->guid(),
  111. MIDCOM_META_CREATOR => $this->_oldest_creator,
  112. MIDCOM_META_EDITOR => $this->_latest_revisor,
  113. MIDCOM_META_CREATED => $this->_oldest_time,
  114. MIDCOM_META_EDITED => $this->_latest_time,
  115. );
  116. }
  117. }
  118. return $leaves;
  119. }
  120.  
  121. function get_node()
  122. {
  123. $topic = &$this->_topic;
  124. // Create Toolbar
  125. $toolbar[100] = Array(
  126. MIDCOM_TOOLBAR_URL => 'config.html',
  127. MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('component configuration'),
  128. MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('component configuration helptext'),
  129. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_folder-properties.png',
  130. MIDCOM_TOOLBAR_ENABLED => true
  131. );
  132. return array (
  133. MIDCOM_NAV_URL => "",
  134. MIDCOM_NAV_NAME => $this->_config_topic->extra,
  135. MIDCOM_NAV_SCORE => $this->_config_topic->score,
  136. MIDCOM_NAV_VISIBLE => $this->_config->get("visible"),
  137. MIDCOM_NAV_TOOLBAR => $toolbar,
  138. MIDCOM_META_CREATOR => $this->_config_topic->creator,
  139. MIDCOM_META_EDITOR => $this->_config_topic->revisor,
  140. MIDCOM_META_CREATED => $this->_config_topic->created,
  141. MIDCOM_META_EDITED => $this->_config_topic->revised
  142. );
  143. }
  144.  
  145. function set_object($object)
  146. {
  147. $this->_config_topic = $object;
  148. $this->_config->store_from_object($object, "net.nemein.bookmarks");
  149. $this->_check_for_content_topic();
  150. // Load Schemas
  151. $data = midcom_get_snippet_content($this->_config->get("schemadb"));
  152. eval("\$schemadb = Array ({$data}\n);");
  153. $this->_schemas = Array();
  154. if (is_array($schemadb))
  155. {
  156. foreach ($schemadb as $schema)
  157. {
  158. $this->_schemas[$schema["name"]] = $schema["description"];
  159. }
  160. }
  161.  
  162. return true;
  163. }
  164.  
  165. function _check_for_content_topic()
  166. {
  167. $guid = $this->_config->get("symlink_topic");
  168. if (is_null($guid))
  169. {
  170. /* No Symlink Topic set */
  171. $this->_topic = $this->_config_topic;
  172. return;
  173. }
  174. $object = mgd_get_object_by_guid($guid);
  175. if (! $object || $object->__table__ != "topic")
  176. {
  177. debug_add("Failed to open symlink content topic, (might also be an invalid object) last Midgard Error: "
  178. . mgd_errstr(), MIDCOM_LOG_ERROR);
  179. debug_print_r("Retrieved object was:", $object, MIDCOM_LOG_INFO);
  180. $GLOBALS["midcom"]->generate_error("Failed to open symlink content topic.");
  181. }
  182. /* Check topic validity */
  183. $root = $GLOBALS["midcom"]->get_context_data(MIDCOM_CONTEXT_ROOTTOPIC);
  184. if ($object->parameter("midcom", "component") != "net.nemein.bookmarks")
  185. {
  186. debug_add("Content Topic is invalid, see LOG_INFO object dump", MIDCOM_LOG_ERROR);
  187. debug_print_r("Retrieved object was:", $object, MIDCOM_LOG_INFO);
  188. debug_print_r("ROOT topic object was:", $root, MIDCOM_LOG_INFO);
  189. $GLOBALS["midcom"]->generate_error("Failed to open symlink content topic.");
  190. }
  191. $this->_topic = $object;
  192. }
  193.  
  194. /*
  195. * function get_current_leaf()
  196. * {
  197. *
  198. * return $GLOBALS["net_nemein_bookmarks_nap_activeid"];
  199. }*/
  200.  
  201. } // navigation
  202.  
  203. ?>

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