1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Plugin to handle the 'node' content type which allows individual nodes
|
6 |
|
|
* to be embedded into a panel.
|
7 |
|
|
*/
|
8 |
|
|
|
9 |
|
|
/**
|
10 |
|
|
* Plugins are described by creating a $plugin array which will be used
|
11 |
|
|
* by the system that includes this file.
|
12 |
|
|
*/
|
13 |
|
|
$plugin = array(
|
14 |
e4c061ad
|
Assos Assos
|
'title' => t('Existing node'),
|
15 |
85ad3d82
|
Assos Assos
|
'single' => TRUE,
|
16 |
|
|
'defaults' => array(
|
17 |
|
|
'nid' => '',
|
18 |
|
|
'links' => TRUE,
|
19 |
|
|
'leave_node_title' => FALSE,
|
20 |
|
|
'identifier' => '',
|
21 |
|
|
'build_mode' => 'teaser',
|
22 |
|
|
),
|
23 |
|
|
'icon' => 'icon_node.png',
|
24 |
|
|
'description' => t('Add a node from your site as content.'),
|
25 |
|
|
'category' => t('Custom'),
|
26 |
|
|
'top level' => TRUE,
|
27 |
|
|
'js' => array('misc/autocomplete.js'),
|
28 |
|
|
);
|
29 |
|
|
|
30 |
|
|
/**
|
31 |
|
|
* Output function for the 'node' content type.
|
32 |
|
|
*
|
33 |
|
|
* Outputs a node based on the module and delta supplied in the configuration.
|
34 |
|
|
*/
|
35 |
|
|
function ctools_node_content_type_render($subtype, $conf, $panel_args) {
|
36 |
|
|
$nid = $conf['nid'];
|
37 |
|
|
$block = new stdClass();
|
38 |
|
|
|
39 |
|
|
foreach (explode('/', $_GET['q']) as $id => $arg) {
|
40 |
|
|
$nid = str_replace("%$id", $arg, $nid);
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
foreach ($panel_args as $id => $arg) {
|
44 |
|
|
if (is_string($arg)) {
|
45 |
|
|
$nid = str_replace("@$id", $arg, $nid);
|
46 |
|
|
}
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
// Support node translation
|
50 |
|
|
if (module_exists('translation')) {
|
51 |
|
|
if ($translations = module_invoke('translation', 'node_get_translations', $nid)) {
|
52 |
|
|
if (isset($translations[$GLOBALS['language']->language])) {
|
53 |
|
|
$nid = $translations[$GLOBALS['language']->language]->nid;
|
54 |
|
|
}
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
if (!is_numeric($nid)) {
|
59 |
|
|
return;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
$node = node_load($nid);
|
63 |
|
|
if (!node_access('view', $node)) {
|
64 |
|
|
return;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
// Don't store viewed node data on the node, this can mess up other
|
68 |
|
|
// views of the node.
|
69 |
|
|
$node = clone($node);
|
70 |
|
|
|
71 |
|
|
$block->module = 'node';
|
72 |
|
|
$block->delta = $node->nid;
|
73 |
|
|
|
74 |
|
|
// Set block->title to the plain node title, then additionally set block->title_link to
|
75 |
|
|
// the node url if required. The actual link is rendered in ctools_content_render().
|
76 |
|
|
$block->title = check_plain($node->title);
|
77 |
|
|
if (!empty($conf['link_node_title'])) {
|
78 |
|
|
$block->title_link = 'node/' . $node->nid;
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
if (empty($conf['leave_node_title'])) {
|
82 |
|
|
$node->title = NULL;
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
if (!empty($conf['identifier'])) {
|
86 |
|
|
$node->ctools_template_identifier = $conf['identifier'];
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
// Handle existing configurations with the deprecated 'teaser' option.
|
90 |
|
|
if (isset($conf['teaser'])) {
|
91 |
|
|
$conf['build_mode'] = $conf['teaser'] ? 'teaser' : 'full';
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
$block->content = node_view($node, $conf['build_mode']);
|
95 |
|
|
|
96 |
|
|
// Hide links if they've been suppressed.
|
97 |
|
|
if (empty($conf['links'])) {
|
98 |
|
|
$block->content['links']['#access'] = FALSE;
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
return $block;
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
/**
|
105 |
|
|
* The form to add or edit a node as content.
|
106 |
|
|
*/
|
107 |
|
|
function ctools_node_content_type_edit_form($form, &$form_state) {
|
108 |
|
|
$conf = $form_state['conf'];
|
109 |
|
|
|
110 |
|
|
$form['leave_node_title'] = array(
|
111 |
|
|
'#type' => 'checkbox',
|
112 |
|
|
'#default_value' => !empty($conf['leave_node_title']),
|
113 |
|
|
'#title' => t('Leave node title'),
|
114 |
|
|
'#description' => t('Advanced: if checked, do not touch the node title; this can cause the node title to appear twice unless your theme is aware of this.'),
|
115 |
|
|
);
|
116 |
|
|
|
117 |
|
|
$form['link_node_title'] = array(
|
118 |
|
|
'#type' => 'checkbox',
|
119 |
|
|
'#default_value' => !empty($conf['link_node_title']),
|
120 |
|
|
'#title' => t('Link the node title to the node'),
|
121 |
|
|
'#description' => t('Check this box if you would like your pane title to link to the node.'),
|
122 |
|
|
);
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
if ($form_state['op'] == 'add') {
|
126 |
|
|
$form['nid'] = array(
|
127 |
|
|
'#prefix' => '<div class="no-float">',
|
128 |
|
|
'#title' => t('Enter the title or NID of a node'),
|
129 |
|
|
'#description' => t('To use a NID from the URL, you may use %0, %1, ..., %N to get URL arguments. Or use @0, @1, @2, ..., @N to use arguments passed into the panel.'),
|
130 |
|
|
'#type' => 'textfield',
|
131 |
|
|
'#maxlength' => 512,
|
132 |
|
|
'#autocomplete_path' => 'ctools/autocomplete/node',
|
133 |
|
|
'#weight' => -10,
|
134 |
|
|
'#suffix' => '</div>',
|
135 |
|
|
);
|
136 |
|
|
}
|
137 |
|
|
else {
|
138 |
|
|
$form['nid'] = array(
|
139 |
|
|
'#type' => 'value',
|
140 |
|
|
'#value' => $conf['nid'],
|
141 |
|
|
);
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
$form['links'] = array(
|
145 |
|
|
'#type' => 'checkbox',
|
146 |
|
|
'#default_value' => $conf['links'],
|
147 |
|
|
'#title' => t('Include node links for "add comment", "read more" etc.'),
|
148 |
|
|
);
|
149 |
|
|
|
150 |
|
|
$form['identifier'] = array(
|
151 |
|
|
'#type' => 'textfield',
|
152 |
|
|
'#default_value' => !empty($conf['identifier']) ? $conf['identifier'] : '',
|
153 |
|
|
'#title' => t('Template identifier'),
|
154 |
|
|
'#description' => t('This identifier will be added as a template suggestion to display this node: node--panel--IDENTIFIER.tpl.php. Please see the Drupal theming guide for information about template suggestions.'),
|
155 |
|
|
);
|
156 |
|
|
|
157 |
|
|
$entity = entity_get_info('node');
|
158 |
|
|
$build_mode_options = array();
|
159 |
|
|
foreach ($entity['view modes'] as $mode => $option) {
|
160 |
|
|
$build_mode_options[$mode] = $option['label'];
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
// Handle existing configurations with the deprecated 'teaser' option.
|
164 |
|
|
// Also remove the teaser key from the form_state.
|
165 |
|
|
if (isset($conf['teaser']) || !isset($conf['build_mode'])) {
|
166 |
|
|
unset($form_state['conf']['teaser']);
|
167 |
|
|
$conf['build_mode'] = $conf['teaser'] ? 'teaser' : 'full';
|
168 |
|
|
}
|
169 |
|
|
$form['build_mode'] = array(
|
170 |
|
|
'#title' => t('Build mode'),
|
171 |
|
|
'#type' => 'select',
|
172 |
|
|
'#description' => t('Select a build mode for this node.'),
|
173 |
|
|
'#options' => $build_mode_options,
|
174 |
|
|
'#default_value' => $conf['build_mode'],
|
175 |
|
|
);
|
176 |
|
|
return $form;
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
/**
|
180 |
|
|
* Validate the node selection.
|
181 |
|
|
*/
|
182 |
|
|
function ctools_node_content_type_edit_form_validate(&$form, &$form_state) {
|
183 |
|
|
if ($form_state['op'] != 'add') {
|
184 |
|
|
return;
|
185 |
|
|
}
|
186 |
|
|
|
187 |
|
|
$nid = $form_state['values']['nid'];
|
188 |
|
|
$preg_matches = array();
|
189 |
|
|
$match = preg_match('/\[id: (\d+)\]/', $nid, $preg_matches);
|
190 |
|
|
if (!$match) {
|
191 |
|
|
$match = preg_match('/^id: (\d+)/', $nid, $preg_matches);
|
192 |
|
|
}
|
193 |
|
|
|
194 |
|
|
if ($match) {
|
195 |
|
|
$nid = $preg_matches[1];
|
196 |
|
|
}
|
197 |
|
|
if (is_numeric($nid)) {
|
198 |
|
|
$node = db_query('SELECT nid, status FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
|
199 |
|
|
}
|
200 |
|
|
else {
|
201 |
|
|
$node = db_query('SELECT nid, status FROM {node} WHERE LOWER(title) = LOWER(:title)', array(':title' => $nid))->fetchObject();
|
202 |
|
|
}
|
203 |
|
|
if ($node) {
|
204 |
|
|
$form_state['values']['nid'] = $node->nid;
|
205 |
|
|
}
|
206 |
|
|
|
207 |
|
|
if (!($node || preg_match('/^[@%]\d+$/', $nid)) ||
|
208 |
|
|
// Do not allow unpublished nodes to be selected by unprivileged users
|
209 |
|
|
(empty($node->status) && !user_access('administer nodes'))) {
|
210 |
|
|
form_error($form['nid'], t('Invalid node'));
|
211 |
|
|
}
|
212 |
|
|
}
|
213 |
|
|
|
214 |
|
|
/**
|
215 |
|
|
* Validate the node selection.
|
216 |
|
|
*/
|
217 |
|
|
function ctools_node_content_type_edit_form_submit($form, &$form_state) {
|
218 |
|
|
foreach (array('nid', 'links', 'leave_node_title', 'link_node_title', 'identifier', 'build_mode') as $key) {
|
219 |
|
|
$form_state['conf'][$key] = $form_state['values'][$key];
|
220 |
|
|
}
|
221 |
|
|
}
|
222 |
|
|
|
223 |
|
|
/**
|
224 |
|
|
* Returns the administrative title for a node.
|
225 |
|
|
*/
|
226 |
|
|
function ctools_node_content_type_admin_title($subtype, $conf) {
|
227 |
|
|
if (!is_numeric($conf['nid'])) {
|
228 |
|
|
return t('Node loaded from @var', array('@var' => $conf['nid']));
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
$node = node_load($conf['nid']);
|
232 |
|
|
if ($node) {
|
233 |
|
|
if (!empty($node->status) || user_access('administer nodes')) {
|
234 |
|
|
return check_plain($node->title);
|
235 |
|
|
}
|
236 |
|
|
else {
|
237 |
|
|
return t('Unpublished node @nid', array('@nid' => $conf['nid']));
|
238 |
|
|
}
|
239 |
|
|
}
|
240 |
|
|
else {
|
241 |
|
|
return t('Deleted/missing node @nid', array('@nid' => $conf['nid']));
|
242 |
|
|
}
|
243 |
|
|
}
|
244 |
|
|
|
245 |
|
|
/**
|
246 |
|
|
* Display the administrative information for a node pane.
|
247 |
|
|
*/
|
248 |
|
|
function ctools_node_content_type_admin_info($subtype, $conf) {
|
249 |
|
|
// Just render the node.
|
250 |
|
|
return ctools_node_content_type_render($subtype, $conf, array());
|
251 |
|
|
} |