Projet

Général

Profil

Paste
Télécharger (5,02 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / page_manager / plugins / tasks / blog_user.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_user_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
    'title' => t('User blog'),
20
    'admin title' => t('User blog'),
21
    'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying user blogs at <em>blog/%user</em>. If no variant is selected, the default Drupal user blog will be used.'),
22
    'admin path' => 'blog/%user',
23

    
24
    // Callback to add items to the page managertask administration form:
25
    'task admin' => 'page_manager_blog_user_task_admin',
26

    
27
    'hook menu alter' => 'page_manager_blog_user_menu_alter',
28

    
29
    // This is task uses 'context' handlers and must implement these to give the
30
    // handler data it needs.
31
    'handler type' => 'context', // handler type -- misnamed
32
    'get arguments' => 'page_manager_blog_user_get_arguments',
33
    'get context placeholders' => 'page_manager_blog_user_get_contexts',
34

    
35
    // Allow this to be enabled or disabled:
36
    'disabled' => variable_get('page_manager_blog_user_disabled', TRUE),
37
    'enable callback' => 'page_manager_blog_user_enable',
38
    'access callback' => 'page_manager_blog_user_access_check',
39
  );
40
}
41

    
42
/**
43
 * Callback defined by page_manager_blog_user_page_manager_tasks().
44
 *
45
 * Alter the user view input so that user view comes to us rather than the
46
 * normal user view process.
47
 */
48
function page_manager_blog_user_menu_alter(&$items, $task) {
49
  if (variable_get('page_manager_blog_user_disabled', TRUE)) {
50
    return;
51
  }
52

    
53
  // Override the user view handler for our purpose.
54
  if ($items['blog/%user_uid_optional']['page callback'] == 'blog_page_user' || variable_get('page_manager_override_anyway', FALSE)) {
55
    $items['blog/%user_uid_optional']['page callback'] = 'page_manager_blog_user';
56
    $items['blog/%user_uid_optional']['file path'] = $task['path'];
57
    $items['blog/%user_uid_optional']['file'] = $task['file'];
58
  }
59
  else {
60
    // Automatically disable this task if it cannot be enabled.
61
    variable_set('page_manager_blog_user_disabled', TRUE);
62
    if (!empty($GLOBALS['page_manager_enabling_blog_user'])) {
63
      drupal_set_message(t('Page manager module is unable to enable blog/%user because some other module already has overridden with %callback.', array('%callback' => $items['blog/%user']['page callback'])), 'error');
64
    }
65
  }
66
}
67

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

    
79
  // Load the account into a context.
80
  ctools_include('context');
81
  ctools_include('context-task-handler');
82
  $contexts = ctools_context_handler_get_task_contexts($task, '', array($account));
83

    
84
  $output = ctools_context_handler_render($task, '', $contexts, array($account->uid));
85
  if ($output !== FALSE) {
86
    return $output;
87
  }
88

    
89
  module_load_include('inc', 'blog', 'blog.pages');
90
  $function = 'blog_page_user';
91
  foreach (module_implements('page_manager_override') as $module) {
92
    $call = $module . '_page_manager_override';
93
    if (($rc = $call('blog_user')) && function_exists($rc)) {
94
      $function = $rc;
95
      break;
96
    }
97
  }
98

    
99
  // Otherwise, fall back.
100
  return $function($account);
101
}
102

    
103
/**
104
 * Callback to get arguments provided by this task handler.
105
 *
106
 * Since this is the node view and there is no UI on the arguments, we
107
 * create dummy arguments that contain the needed data.
108
 */
109
function page_manager_blog_user_get_arguments($task, $subtask_id) {
110
  return array(
111
    array(
112
      'keyword' => 'user',
113
      'identifier' => t('User being viewed'),
114
      'id' => 1,
115
      'name' => 'uid',
116
      'settings' => array(),
117
    ),
118
  );
119
}
120

    
121
/**
122
 * Callback to get context placeholders provided by this handler.
123
 */
124
function page_manager_blog_user_get_contexts($task, $subtask_id) {
125
  return ctools_context_get_placeholders_from_argument(page_manager_blog_user_get_arguments($task, $subtask_id));
126
}
127

    
128
/**
129
 * Callback to enable/disable the page from the UI.
130
 */
131
function page_manager_blog_user_enable($cache, $status) {
132
  variable_set('page_manager_blog_user_disabled', $status);
133

    
134
  // Set a global flag so that the menu routine knows it needs
135
  // to set a message if enabling cannot be done.
136
  if (!$status) {
137
    $GLOBALS['page_manager_enabling_blog_user'] = TRUE;
138
  }
139
}
140

    
141
/**
142
 * Callback to determine if a page is accessible.
143
 *
144
 * @param $task
145
 *   The task plugin.
146
 * @param $subtask_id
147
 *   The subtask id
148
 * @param $contexts
149
 *   The contexts loaded for the task.
150
 *
151
 * @return
152
 *   TRUE if the current user can access the page.
153
 */
154
function page_manager_blog_user_access_check($task, $subtask_id, $contexts) {
155
  $context = reset($contexts);
156
  return blog_page_user_access($context->data);
157
}