Projet

Général

Profil

Paste
Télécharger (3,68 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / page_manager / plugins / tasks / blog.inc @ 1e39edcb

1
<?php
2

    
3
/**
4
 * Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
5
 * more information.
6
 */
7
function page_manager_blog_page_manager_tasks() {
8
  if (!module_exists('blog')) {
9
    return;
10
  }
11

    
12
  return array(
13
    // This is a 'page' task and will fall under the page admin UI
14
    'task type' => 'page',
15

    
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

    
21
    // Menu hooks so that we can alter the node/%node menu entry to point to us.
22
    'hook menu alter' => 'page_manager_blog_menu_alter',
23

    
24
    // This is task uses 'context' handlers and must implement these to give the
25
    // handler data it needs.
26
    'handler type' => 'context',
27

    
28
    // Allow this to be enabled or disabled:
29
    'disabled' => variable_get('page_manager_blog_disabled', TRUE),
30
    'enable callback' => 'page_manager_blog_enable',
31
    'access callback' => 'page_manager_blog_access_check',
32
  );
33
}
34

    
35
/**
36
 * Callback defined by page_manager_blog_page_manager_tasks().
37
 *
38
 * Alter the node edit input so that node edit comes to us rather than the
39
 * normal node edit process.
40
 */
41
function page_manager_blog_menu_alter(&$items, $task) {
42
  if (variable_get('page_manager_blog_disabled', TRUE)) {
43
    return;
44
  }
45

    
46
  $callback = $items['blog']['page callback'];
47
  // Override the node edit handler for our purpose.
48
  if ($callback == 'blog_page_last' || variable_get('page_manager_override_anyway', FALSE)) {
49
    $items['blog']['page callback'] = 'page_manager_blog';
50
    $items['blog']['file path'] = $task['path'];
51
    $items['blog']['file'] = $task['file'];
52
  }
53
  else {
54
    variable_set('page_manager_blog_disabled', TRUE);
55
    if (!empty($GLOBALS['page_manager_enabling_blog'])) {
56
      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');
57
    }
58
    return;
59
  }
60

    
61
}
62

    
63
/**
64
 * Entry point for our overridden node edit.
65
 *
66
 * This function asks its assigned handlers who, if anyone, would like
67
 * to run with it. If no one does, it passes through to Drupal core's
68
 * node edit, which is node_page_edit().
69
 */
70
function page_manager_blog() {
71
  // Load my task plugin
72
  $task = page_manager_get_task('blog');
73

    
74
  ctools_include('context');
75
  ctools_include('context-task-handler');
76
  $output = ctools_context_handler_render($task, '', array(), array());
77
  if ($output !== FALSE) {
78
    return $output;
79
  }
80

    
81
  module_load_include('inc', 'blog', 'blog.pages');
82
  $function = 'blog_page_last';
83
  foreach (module_implements('page_manager_override') as $module) {
84
    $call = $module . '_page_manager_override';
85
    if (($rc = $call('blog')) && function_exists($rc)) {
86
      $function = $rc;
87
      break;
88
    }
89
  }
90

    
91
  // Otherwise, fall back.
92
  return $function();
93
}
94

    
95
/**
96
 * Callback to enable/disable the page from the UI.
97
 */
98
function page_manager_blog_enable($cache, $status) {
99
  variable_set('page_manager_blog_disabled', $status);
100
  // Set a global flag so that the menu routine knows it needs
101
  // to set a message if enabling cannot be done.
102
  if (!$status) {
103
    $GLOBALS['page_manager_enabling_blog'] = TRUE;
104
  }
105
}
106

    
107
/**
108
 * Callback to determine if a page is accessible.
109
 *
110
 * @param $task
111
 *   The task plugin.
112
 * @param $subtask_id
113
 *   The subtask id
114
 * @param $contexts
115
 *   The contexts loaded for the task.
116
 * @return
117
 *   TRUE if the current user can access the page.
118
 */
119
function page_manager_blog_access_check($task, $subtask_id, $contexts) {
120
  return user_access('access content');
121
}