blog.inc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * @file
  4. */
  5. /**
  6. * Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
  7. * more information.
  8. */
  9. function page_manager_blog_page_manager_tasks() {
  10. if (!module_exists('blog')) {
  11. return;
  12. }
  13. return array(
  14. // This is a 'page' task and will fall under the page admin UI.
  15. 'task type' => 'page',
  16. 'title' => t('All blogs'),
  17. 'admin title' => t('All blogs'),
  18. 'admin description' => t('When enabled, this overrides the default Drupal behavior for the all blogs at <em>/blog</em>. If no variant is selected, the default Drupal most recent blog posts will be shown.'),
  19. 'admin path' => 'blog',
  20. // Menu hooks so that we can alter the node/%node menu entry to point to us.
  21. 'hook menu alter' => 'page_manager_blog_menu_alter',
  22. // This is task uses 'context' handlers and must implement these to give the
  23. // handler data it needs.
  24. 'handler type' => 'context',
  25. // Allow this to be enabled or disabled:
  26. 'disabled' => variable_get('page_manager_blog_disabled', TRUE),
  27. 'enable callback' => 'page_manager_blog_enable',
  28. 'access callback' => 'page_manager_blog_access_check',
  29. );
  30. }
  31. /**
  32. * Callback defined by page_manager_blog_page_manager_tasks().
  33. *
  34. * Alter the node edit input so that node edit comes to us rather than the
  35. * normal node edit process.
  36. */
  37. function page_manager_blog_menu_alter(&$items, $task) {
  38. if (variable_get('page_manager_blog_disabled', TRUE)) {
  39. return;
  40. }
  41. $callback = $items['blog']['page callback'];
  42. // Override the node edit handler for our purpose.
  43. if ($callback == 'blog_page_last' || variable_get('page_manager_override_anyway', FALSE)) {
  44. $items['blog']['page callback'] = 'page_manager_blog';
  45. $items['blog']['file path'] = $task['path'];
  46. $items['blog']['file'] = $task['file'];
  47. }
  48. else {
  49. variable_set('page_manager_blog_disabled', TRUE);
  50. if (!empty($GLOBALS['page_manager_enabling_blog'])) {
  51. drupal_set_message(t('Page manager module is unable to enable blog because some other module already has overridden with %callback.', array('%callback' => $callback)), 'warning');
  52. }
  53. return;
  54. }
  55. }
  56. /**
  57. * Entry point for our overridden node edit.
  58. *
  59. * This function asks its assigned handlers who, if anyone, would like
  60. * to run with it. If no one does, it passes through to Drupal core's
  61. * node edit, which is node_page_edit().
  62. */
  63. function page_manager_blog() {
  64. // Load my task plugin.
  65. $task = page_manager_get_task('blog');
  66. ctools_include('context');
  67. ctools_include('context-task-handler');
  68. $output = ctools_context_handler_render($task, '', array(), array());
  69. if ($output !== FALSE) {
  70. return $output;
  71. }
  72. module_load_include('inc', 'blog', 'blog.pages');
  73. $function = 'blog_page_last';
  74. foreach (module_implements('page_manager_override') as $module) {
  75. $call = $module . '_page_manager_override';
  76. if (($rc = $call('blog')) && function_exists($rc)) {
  77. $function = $rc;
  78. break;
  79. }
  80. }
  81. // Otherwise, fall back.
  82. return $function();
  83. }
  84. /**
  85. * Callback to enable/disable the page from the UI.
  86. */
  87. function page_manager_blog_enable($cache, $status) {
  88. variable_set('page_manager_blog_disabled', $status);
  89. // Set a global flag so that the menu routine knows it needs
  90. // to set a message if enabling cannot be done.
  91. if (!$status) {
  92. $GLOBALS['page_manager_enabling_blog'] = TRUE;
  93. }
  94. }
  95. /**
  96. * Callback to determine if a page is accessible.
  97. *
  98. * @param $task
  99. * The task plugin.
  100. * @param $subtask_id
  101. * The subtask id
  102. * @param $contexts
  103. * The contexts loaded for the task.
  104. *
  105. * @return
  106. * TRUE if the current user can access the page.
  107. */
  108. function page_manager_blog_access_check($task, $subtask_id, $contexts) {
  109. return user_access('access content');
  110. }