Projet

Général

Profil

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

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

1
<?php
2

    
3
/**
4
 * @file
5
 */
6

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

    
16
  return array(
17
    // This is a 'page' task and will fall under the page admin UI.
18
    'task type' => 'page',
19

    
20
    'title' => t('All blogs'),
21
    'admin title' => t('All blogs'),
22
    '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.'),
23
    'admin path' => 'blog',
24

    
25
    // Menu hooks so that we can alter the node/%node menu entry to point to us.
26
    'hook menu alter' => 'page_manager_blog_menu_alter',
27

    
28
    // This is task uses 'context' handlers and must implement these to give the
29
    // handler data it needs.
30
    'handler type' => 'context',
31

    
32
    // Allow this to be enabled or disabled:
33
    'disabled' => variable_get('page_manager_blog_disabled', TRUE),
34
    'enable callback' => 'page_manager_blog_enable',
35
    'access callback' => 'page_manager_blog_access_check',
36
  );
37
}
38

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

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

    
65
}
66

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

    
78
  ctools_include('context');
79
  ctools_include('context-task-handler');
80
  $output = ctools_context_handler_render($task, '', array(), array());
81
  if ($output !== FALSE) {
82
    return $output;
83
  }
84

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

    
95
  // Otherwise, fall back.
96
  return $function();
97
}
98

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

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