1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
|
4 |
|
|
* more information.
|
5 |
|
|
*/
|
6 |
|
|
function page_manager_comment_reply_page_manager_tasks() {
|
7 |
|
|
if (!module_exists('comment')) {
|
8 |
|
|
return;
|
9 |
|
|
}
|
10 |
|
|
|
11 |
|
|
return array(
|
12 |
|
|
// This is a 'page' task and will fall under the page admin UI
|
13 |
|
|
'task type' => 'page',
|
14 |
|
|
|
15 |
|
|
'title' => t('Comment Reply page'),
|
16 |
|
|
'admin title' => t('Comment Reply page'),
|
17 |
|
|
'admin description' => t('When enabled, this overrides the default Drupal behavior for the site contact page at <em>/contact</em>. If no variant is selected, the default Drupal contact form will be used.'),
|
18 |
|
|
'admin path' => 'comment/reply/%node',
|
19 |
|
|
|
20 |
|
|
// Menu hooks so that we can alter the node/%node menu entry to point to us.
|
21 |
|
|
'hook menu alter' => 'page_manager_comment_reply_menu_alter',
|
22 |
|
|
|
23 |
|
|
// This is task uses 'context' handlers and must implement these to give the
|
24 |
|
|
// handler data it needs.
|
25 |
|
|
'handler type' => 'context',
|
26 |
|
|
'get arguments' => 'page_manager_comment_reply_get_arguments',
|
27 |
|
|
'get context placeholders' => 'page_manager_comment_reply_get_contexts',
|
28 |
|
|
|
29 |
|
|
// Allow this to be enabled or disabled:
|
30 |
|
|
'disabled' => variable_get('page_manager_comment_reply_disabled', TRUE),
|
31 |
|
|
'enable callback' => 'page_manager_comment_reply_enable',
|
32 |
|
|
'access callback' => 'page_manager_comment_reply_check',
|
33 |
|
|
);
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
/**
|
37 |
|
|
* Callback to enable/disable the page from the UI.
|
38 |
|
|
*/
|
39 |
|
|
function page_manager_comment_reply_enable($cache, $status) {
|
40 |
|
|
variable_set('page_manager_comment_reply_disabled', $status);
|
41 |
|
|
// Set a global flag so that the menu routine knows it needs
|
42 |
|
|
// to set a message if enabling cannot be done.
|
43 |
|
|
if (!$status) {
|
44 |
|
|
$GLOBALS['page_manager_enabling_comment_reply'] = TRUE;
|
45 |
|
|
}
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
/**
|
50 |
|
|
* Entry point for our overridden comment.
|
51 |
|
|
*
|
52 |
|
|
*/
|
53 |
|
|
function page_manager_comment_reply_page($node, $pid = NULL){
|
54 |
|
|
// Load my task plugin
|
55 |
|
|
$task = page_manager_get_task('comment_reply');
|
56 |
|
|
|
57 |
|
|
// Load the node into a context.
|
58 |
|
|
ctools_include('context');
|
59 |
|
|
ctools_include('context-task-handler');
|
60 |
|
|
|
61 |
|
|
$contexts = ctools_context_handler_get_task_contexts($task, '', array($node, $pid));
|
62 |
|
|
|
63 |
|
|
if (array_key_exists('argument_cid_3', $contexts) && $contexts['argument_cid_3']->data->nid != $node->nid) {
|
64 |
|
|
// Attempting to reply to a comment not belonging to the current nid.
|
65 |
|
|
drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
|
66 |
|
|
drupal_goto("node/$node->nid");
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
$output = ctools_context_handler_render($task, '', $contexts, array($node, $pid));
|
70 |
e4c061ad
|
Assos Assos
|
if ($output !== FALSE) {
|
71 |
85ad3d82
|
Assos Assos
|
return $output;
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
$function = 'comment_reply';
|
75 |
|
|
foreach (module_implements('page_manager_override') as $module) {
|
76 |
|
|
$call = $module . '_page_manager_override';
|
77 |
|
|
if (($rc = $call('comment_reply')) && function_exists($rc)) {
|
78 |
|
|
$function = $rc;
|
79 |
|
|
break;
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
module_load_include('inc', 'comment', 'comment.pages');
|
84 |
|
|
return $function($node, $pid);
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
/**
|
88 |
|
|
* Callback to get arguments provided by this task handler.
|
89 |
|
|
*
|
90 |
|
|
* Since this is the node view and there is no UI on the arguments, we
|
91 |
|
|
* create dummy arguments that contain the needed data.
|
92 |
|
|
*/
|
93 |
|
|
function page_manager_comment_reply_get_arguments($task, $subtask_id) {
|
94 |
|
|
return array(
|
95 |
|
|
array(
|
96 |
|
|
'keyword' => 'node',
|
97 |
|
|
'identifier' => t('Node being commented on'),
|
98 |
|
|
'id' => 2,
|
99 |
|
|
'name' => 'entity_id:node',
|
100 |
|
|
'settings' => array(),
|
101 |
|
|
),
|
102 |
|
|
array(
|
103 |
|
|
'keyword' => 'comment',
|
104 |
|
|
'identifier' => t('Comment being replied to'),
|
105 |
|
|
'id' => 3,
|
106 |
|
|
'name' => 'entity_id:comment',
|
107 |
|
|
'settings' => array(),
|
108 |
|
|
),
|
109 |
|
|
);
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
/**
|
113 |
|
|
* Callback to get context placeholders provided by this handler.
|
114 |
|
|
*/
|
115 |
|
|
function page_manager_comment_reply_get_contexts($task, $subtask_id) {
|
116 |
|
|
return ctools_context_get_placeholders_from_argument(page_manager_comment_reply_get_arguments($task, $subtask_id));
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
/**
|
120 |
|
|
* Callback defined by page_manager_node_view_page_manager_tasks().
|
121 |
|
|
*
|
122 |
|
|
* Alter the node view input so that node view comes to us rather than the
|
123 |
|
|
* normal node view process.
|
124 |
|
|
*/
|
125 |
|
|
function page_manager_comment_reply_menu_alter(&$items, $task) {
|
126 |
|
|
if (variable_get('page_manager_comment_reply_disabled', TRUE)) {
|
127 |
|
|
return;
|
128 |
|
|
}
|
129 |
|
|
// Override the node view handler for our purpose.
|
130 |
|
|
$callback = $items['comment/reply/%node']['page callback'];
|
131 |
|
|
if ($callback == 'comment_reply' || variable_get('page_manager_override_anyway', FALSE)) {
|
132 |
|
|
$items['comment/reply/%node']['page callback'] = 'page_manager_comment_reply_page';
|
133 |
|
|
$items['comment/reply/%node']['file path'] = $task['path'];
|
134 |
|
|
$items['comment/reply/%node']['file'] = $task['file'];
|
135 |
|
|
}
|
136 |
|
|
else {
|
137 |
|
|
// automatically disable this task if it cannot be enabled.
|
138 |
|
|
variable_set('page_manager_comment_reply_disabled', TRUE);
|
139 |
|
|
if (!empty($GLOBALS['page_manager_enabling_comment_reply'])) {
|
140 |
|
|
drupal_set_message(t('Page manager module is unable to enable comment/reply/%node because some other module already has overridden with %callback.', array('%callback' => $callback)), 'error');
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
// @todo override node revision handler as well?
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
/**
|
148 |
|
|
* Callback to determine if a page is accessible.
|
149 |
|
|
*
|
150 |
|
|
* @param $task
|
151 |
|
|
* The task plugin.
|
152 |
|
|
* @param $subtask_id
|
153 |
|
|
* The subtask id
|
154 |
|
|
* @param $contexts
|
155 |
|
|
* The contexts loaded for the task.
|
156 |
|
|
* @return
|
157 |
|
|
* TRUE if the current user can access the page.
|
158 |
|
|
*/
|
159 |
|
|
function page_manager_comment_reply_access_check($task, $subtask_id, $contexts) {
|
160 |
|
|
$context = reset($contexts);
|
161 |
|
|
return TRUE;
|
162 |
|
|
} |