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_user_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
|
'title' => t('User blog'),
|
16
|
'admin title' => t('User blog'),
|
17
|
'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.'),
|
18
|
'admin path' => 'blog/%user',
|
19
|
|
20
|
// Callback to add items to the page managertask administration form:
|
21
|
'task admin' => 'page_manager_blog_user_task_admin',
|
22
|
|
23
|
'hook menu alter' => 'page_manager_blog_user_menu_alter',
|
24
|
|
25
|
// This is task uses 'context' handlers and must implement these to give the
|
26
|
// handler data it needs.
|
27
|
'handler type' => 'context', // handler type -- misnamed
|
28
|
'get arguments' => 'page_manager_blog_user_get_arguments',
|
29
|
'get context placeholders' => 'page_manager_blog_user_get_contexts',
|
30
|
|
31
|
// Allow this to be enabled or disabled:
|
32
|
'disabled' => variable_get('page_manager_blog_user_disabled', TRUE),
|
33
|
'enable callback' => 'page_manager_blog_user_enable',
|
34
|
'access callback' => 'page_manager_blog_user_access_check',
|
35
|
);
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
* Callback defined by page_manager_blog_user_page_manager_tasks().
|
40
|
*
|
41
|
* Alter the user view input so that user view comes to us rather than the
|
42
|
* normal user view process.
|
43
|
*/
|
44
|
function page_manager_blog_user_menu_alter(&$items, $task) {
|
45
|
if (variable_get('page_manager_blog_user_disabled', TRUE)) {
|
46
|
return;
|
47
|
}
|
48
|
|
49
|
// Override the user view handler for our purpose.
|
50
|
if ($items['blog/%user_uid_optional']['page callback'] == 'blog_page_user' || variable_get('page_manager_override_anyway', FALSE)) {
|
51
|
$items['blog/%user_uid_optional']['page callback'] = 'page_manager_blog_user';
|
52
|
$items['blog/%user_uid_optional']['file path'] = $task['path'];
|
53
|
$items['blog/%user_uid_optional']['file'] = $task['file'];
|
54
|
}
|
55
|
else {
|
56
|
// automatically disable this task if it cannot be enabled.
|
57
|
variable_set('page_manager_blog_user_disabled', TRUE);
|
58
|
if (!empty($GLOBALS['page_manager_enabling_blog_user'])) {
|
59
|
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');
|
60
|
}
|
61
|
}
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* Entry point for our overridden user view.
|
66
|
*
|
67
|
* This function asks its assigned handlers who, if anyone, would like
|
68
|
* to run with it. If no one does, it passes through to Drupal core's
|
69
|
* user view, which is user_page_view().
|
70
|
*/
|
71
|
function page_manager_blog_user($account) {
|
72
|
// Load my task plugin:
|
73
|
$task = page_manager_get_task('blog_user');
|
74
|
|
75
|
// Load the account into a context.
|
76
|
ctools_include('context');
|
77
|
ctools_include('context-task-handler');
|
78
|
$contexts = ctools_context_handler_get_task_contexts($task, '', array($account));
|
79
|
|
80
|
$output = ctools_context_handler_render($task, '', $contexts, array($account->uid));
|
81
|
if ($output !== FALSE) {
|
82
|
return $output;
|
83
|
}
|
84
|
|
85
|
module_load_include('inc', 'blog', 'blog.pages');
|
86
|
$function = 'blog_page_user';
|
87
|
foreach (module_implements('page_manager_override') as $module) {
|
88
|
$call = $module . '_page_manager_override';
|
89
|
if (($rc = $call('blog_user')) && function_exists($rc)) {
|
90
|
$function = $rc;
|
91
|
break;
|
92
|
}
|
93
|
}
|
94
|
|
95
|
// Otherwise, fall back.
|
96
|
return $function($account);
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* Callback to get arguments provided by this task handler.
|
101
|
*
|
102
|
* Since this is the node view and there is no UI on the arguments, we
|
103
|
* create dummy arguments that contain the needed data.
|
104
|
*/
|
105
|
function page_manager_blog_user_get_arguments($task, $subtask_id) {
|
106
|
return array(
|
107
|
array(
|
108
|
'keyword' => 'user',
|
109
|
'identifier' => t('User being viewed'),
|
110
|
'id' => 1,
|
111
|
'name' => 'uid',
|
112
|
'settings' => array(),
|
113
|
),
|
114
|
);
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* Callback to get context placeholders provided by this handler.
|
119
|
*/
|
120
|
function page_manager_blog_user_get_contexts($task, $subtask_id) {
|
121
|
return ctools_context_get_placeholders_from_argument(page_manager_blog_user_get_arguments($task, $subtask_id));
|
122
|
}
|
123
|
|
124
|
/**
|
125
|
* Callback to enable/disable the page from the UI.
|
126
|
*/
|
127
|
function page_manager_blog_user_enable($cache, $status) {
|
128
|
variable_set('page_manager_blog_user_disabled', $status);
|
129
|
|
130
|
// Set a global flag so that the menu routine knows it needs
|
131
|
// to set a message if enabling cannot be done.
|
132
|
if (!$status) {
|
133
|
$GLOBALS['page_manager_enabling_blog_user'] = TRUE;
|
134
|
}
|
135
|
}
|
136
|
|
137
|
/**
|
138
|
* Callback to determine if a page is accessible.
|
139
|
*
|
140
|
* @param $task
|
141
|
* The task plugin.
|
142
|
* @param $subtask_id
|
143
|
* The subtask id
|
144
|
* @param $contexts
|
145
|
* The contexts loaded for the task.
|
146
|
* @return
|
147
|
* TRUE if the current user can access the page.
|
148
|
*/
|
149
|
function page_manager_blog_user_access_check($task, $subtask_id, $contexts) {
|
150
|
$context = reset($contexts);
|
151
|
return blog_page_user_access($context->data);
|
152
|
}
|