/[drupal]/contributions/modules/nodewords/nodewords.admin.inc
ViewVC logotype

Contents of /contributions/modules/nodewords/nodewords.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Sat Oct 24 16:48:54 2009 UTC (4 weeks, 3 days ago) by kiam
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--3
Changes since 1.5: +7 -7 lines
File MIME type: text/x-php
#613350 by KiamLaLuno: Rename the tab "Global and default meta tags".
1 <?php
2 // $Id: nodewords.admin.inc,v 1.5 2009/10/24 16:13:20 kiam Exp $
3
4 /**
5 * @file
6 * Assign META tags to nodes, vocabularies, terms and pages.
7 */
8
9 /**
10 * @addtogroup nodewords
11 * @{
12 */
13
14 /*****************************************************************************
15 * Menu callbacks / form builders, submit/validate functions.
16 ****************************************************************************/
17
18 /**
19 * Show the confirmation form for the page meta tags delete operation.
20 */
21 function nodewords_pages_confirm_delete(&$form_state, $page) {
22 $form['path'] = array(
23 '#type' => 'value',
24 '#value' => $page->path,
25 );
26
27 return confirm_form($form,
28 t('Are you sure you want to delete the meta tags for %path?', array('%path' => $page->path)),
29 isset($_GET['destination']) ? $_GET['destination'] : 'admin/content/nodewords/meta-tags/other',
30 t('This action cannot be undone.'),
31 t('Delete'),
32 t('Cancel')
33 );
34 }
35
36 /**
37 *
38 */
39 function nodewords_pages_confirm_delete_submit($form, &$form_state) {
40 if ($form_state['values']['confirm']) {
41 nodewords_delete_tags('page', $form_state['values']['path']);
42 }
43
44 if (db_affected_rows()) {
45 drupal_set_message(t('The configuration options have been saved.'), 'status');
46 }
47
48 $form_state['redirect'] = 'admin/content/nodewords/meta-tags/other';
49 }
50
51 /**
52 * Return the list of pages with custom meta tags settings.
53 */
54 function nodewords_pages_overview() {
55 $enabled = array();
56 $form = array('#tree' => TRUE);
57 $pages = array();
58
59 _nodewords_check_enabled_modules();
60
61 foreach (_nodewords_get_pages_data() as $pid => $page) {
62 $pages[$pid] = '';
63
64 if ($page->enabled) {
65 $enabled[] = $pid;
66 }
67
68 $form['path'][$pid] = array(
69 '#type' => 'hidden',
70 '#value' => $page->path,
71 '#prefix' => check_plain($page->path),
72 );
73
74 $form['weight'][$pid] = array(
75 '#type' => 'weight',
76 '#delta' => 10,
77 '#default_value' => $page->weight,
78 );
79
80 $form['edit'][$pid] = array(
81 '#value' => l(t('edit'), "admin/content/nodewords/meta-tags/other/edit/$page->pid"),
82 );
83 $form['delete'][$pid] = array(
84 '#value' => l(t('delete'), "admin/content/nodewords/meta-tags/other/delete/$page->pid"),
85 );
86 }
87
88 if (!empty($pages)) {
89 $form['enabled'] = array(
90 '#type' => 'checkboxes',
91 '#options' => $pages,
92 '#default_value' => $enabled,
93 '#checkall' => count($pages) > 1 ? 'nodewords-pages-overview-enabled' : FALSE,
94 );
95
96 $form['submit'] = array(
97 '#type' => 'submit',
98 '#value' => t('Save')
99 );
100 }
101
102 return $form;
103 }
104
105 function nodewords_pages_overview_submit($form, &$form_state) {
106 $row = new stdClass();
107
108 foreach ($form_state['values']['path'] as $pid => $value) {
109 $row->pid = $pid;
110 $row->path = $form_state['values']['path'][$pid];
111 $row->weight = $form_state['values']['weight'][$pid];
112 $row->enabled = $form_state['values']['enabled'][$pid];
113
114 drupal_write_record('nodewords_custom', $row, 'pid');
115 $done = TRUE;
116 }
117
118 if (isset($done)) {
119 drupal_set_message(t('The configuration options have been saved.'));
120 }
121 }
122
123 /**
124 *
125 */
126 function nodewords_pages_edit($form_state, $page = NULL) {
127 if (!isset($page)) {
128 $page = new stdClass();
129 $page->path = '';
130 $page->weight = 0;
131 $page->enabled = 1;
132 $page->tags = array();
133 }
134 else {
135 $form['pid'] = array(
136 '#type' => 'value',
137 '#value' => $page->pid,
138 );
139 }
140
141 $form['path'] = array(
142 '#type' => 'textfield',
143 '#title' => t('Path'),
144 '#description' => t("Enter the Drupal path of the page. The '*' character is a wildcard. Example paths are <em>blog</em> for the blog page and <em>blog/*</em> for every personal blog."),
145 '#default_value' => $page->path,
146 '#size' => 60,
147 '#maxlength' => 255,
148 '#required' => TRUE,
149 );
150
151 $form['weight'] = array(
152 '#type' => 'weight',
153 '#title' => t('Weight'),
154 '#description' => t('Pages with lower weight will be considered first. Only the first matching page will be used.'),
155 '#delta' => 10,
156 '#default_value' => $page->weight,
157 );
158
159 $form['enabled'] = array(
160 '#type' => 'checkbox',
161 '#title' => t('Enabled'),
162 '#default_value' => $page->enabled,
163 );
164
165 $form['nodewords'] = nodewords_form(
166 'page',
167 $page->tags,
168 array(
169 'fieldset' => FALSE,
170 )
171 );
172
173 if (empty($form['nodewords'])) {
174 if (!count(array_filter(variable_get('nodewords_edit', array())))) {
175 drupal_set_message(
176 t(
177 'No meta tags have been enabled for editing; enable them on the <a href="@settings_page">settings page</a>.',
178 array('@settings_page' => url('admin/content/nodewords/settings'))
179 )
180 );
181 }
182
183 return array();
184 }
185 else {
186 $form['nodewords']['#tree'] = TRUE;
187
188 $form['submit'] = array(
189 '#type' => 'submit',
190 '#value' => t('Save'),
191 '#weight' => 40,
192 );
193 }
194
195 return $form;
196 }
197
198 /**
199 * Validate function for the meta tags edit page.
200 */
201 function nodewords_pages_edit_validate($form, &$form_state) {
202 if ($path = trim($form_state['values']['path'])) {
203 if ($path[0] == '/') {
204 form_set_error('path', t('The path must not start with a slash.'));
205 return;
206 }
207
208 $bool = db_result(
209 db_query("SELECT 1 FROM {nodewords_custom} WHERE path = '%s' AND pid <> %d",
210 $path,
211 isset($form_state['values']['pid']) ? $form_state['values']['pid'] : 0
212 )
213 );
214
215 if ($bool) {
216 form_set_error('path', t('The path is already used.'));
217 }
218 }
219 else {
220 form_set_error('path', t('The path must not contain only spaces.'));
221 }
222 }
223
224 /**
225 * Submission function for the meta tags edit page.
226 */
227 function nodewords_pages_edit_submit($form, &$form_state) {
228 $form_state['values']['path'] = trim($form_state['values']['path']);
229
230 nodewords_save_tags('page', $form_state['values']['path'], $form_state['values']['nodewords'], TRUE);
231 drupal_write_record('nodewords_custom', $form_state['values'], isset($form_state['values']['pid']) ? 'pid' : NULL);
232
233 drupal_set_message(t('The configuration options have been saved.'));
234 $form_state['redirect'] = 'admin/content/nodewords/meta-tags/other';
235 }
236
237 /**
238 * Menu callback: settings form.
239 */
240 function nodewords_settings_form() {
241 $edit_options = array();
242 $edit_tags = variable_get('nodewords_edit', array());
243 $form = array();
244 $head_options = array();
245 $head_tags = variable_get('nodewords_head', array());
246 $tags_info = nodewords_get_possible_tags();
247
248 _nodewords_check_enabled_modules();
249
250 foreach ($tags_info as $name => $info) {
251 $bool = (
252 isset($info['tag:context:allowed']) &&
253 in_array('<none>', $info['tag:context:allowed'])
254 );
255
256 if (!$bool) {
257 $edit_options[$name] = $info['widget:label'];
258 }
259
260 $head_options[$name] = $info['widget:label'];
261 }
262
263 uasort($edit_options, 'strnatcmp');
264 uasort($head_options, 'strnatcmp');
265
266 $form['edit'] = array(
267 '#type' => 'fieldset',
268 '#title' => t('Meta tags to show on edit forms'),
269 '#description' => t('Select the meta tags you want to be able to edit; the meta tag edit fields will always be shown in the administration settings pages. The meta tags that appear only in the list of the meta tags output in HTML, are automatically set by a module.'),
270 '#collapsible' => TRUE,
271 );
272
273 $form['edit']['nodewords_edit'] = array(
274 '#type' => 'checkboxes',
275 '#options' => $edit_options,
276 '#default_value' => $edit_tags,
277 '#checkall' => TRUE,
278 );
279
280 $form['head'] = array(
281 '#type' => 'fieldset',
282 '#title' => t('Meta tags to output in HTML'),
283 '#description' => t('Select the meta tags you want to appear in the HEAD section of the HTML pages.'),
284 '#collapsible' => TRUE,
285 );
286
287 $form['head']['nodewords_head'] = array(
288 '#type' => 'checkboxes',
289 '#options' => $head_options,
290 '#default_value' => $head_tags,
291 '#checkall' => TRUE,
292 );
293
294 if (function_exists('taxonomy_get_vocabularies')) {
295 $options = array();
296
297 foreach (taxonomy_get_vocabularies() as $vocabulary) {
298 $options[$vocabulary->vid] = check_plain($vocabulary->name);
299 }
300
301 if ($count = count($options)) {
302 $form['taxonomy'] = array(
303 '#type' => 'fieldset',
304 '#title' => t('Taxonomy'),
305 '#collapsible' => TRUE,
306 );
307 $form['taxonomy']['nodewords_keyword_vids'] = array(
308 '#type' => $count > 10 ? 'select' : 'checkboxes',
309 '#title' => t('Auto-keywords vocabularies'),
310 '#description' => t('Select the vocabularies which contain terms you want to add to the keywords meta tag for nodes. The terms of these vocabularies are added before the global keywords but after the page-specific keywords.'),
311 '#default_value' => variable_get('nodewords_keyword_vids', array()),
312 '#options' => $options,
313 '#multiple' => TRUE,
314 );
315
316 if ($count > 10) {
317 $form['taxonomy']['nodewords_keyword_vids']['#multiple'] = TRUE;
318 }
319 elseif ($count > 2) {
320 // Add support for Check All if the checkboxes are more than two.
321 $form['taxonomy']['nodewords_keyword_vids']['#checkall'] = TRUE;
322 }
323 }
324 }
325
326 $form['advanced'] = array(
327 '#type' => 'fieldset',
328 '#title' => t('Advanced options'),
329 '#collapsible' => TRUE,
330 );
331
332 $form['advanced']['nodewords_enable_tokens'] = array(
333 '#type' => 'checkbox',
334 '#title' => t('Enable the use of tokens in meta tags content'),
335 '#default_value' => variable_get('nodewords_enable_tokens', TRUE),
336 );
337
338 if (!module_exists('token')) {
339 $form['advanced']['nodewords_enable_tokens']['#description'] = t('The module token.module is not enabled; the tokens used in the meta tags content will not be replaced.');
340 }
341
342 $form['advanced']['nodewords_enable_user_metatags'] = array(
343 '#type' => 'checkbox',
344 '#title' => t('Enable the user profile meta tags'),
345 '#default_value' => variable_get('nodewords_enable_user_metatags', TRUE),
346 );
347
348 $form['advanced']['nodewords_list_repeat'] = array(
349 '#type' => 'checkbox',
350 '#title' => t('Repeat meta tags for lists'),
351 '#description' => t('Some search engines punish sites that use the same meta tags on different pages. Uncheck this option if you want to suppress the repetition of the same meta tags on pages that use the pager - if unchecked, Drupal will only display the meta tags for the first page and not for subsequent pages. If unsure, select this option.'),
352 '#default_value' => variable_get('nodewords_list_repeat', FALSE),
353 );
354
355 $form['advanced']['nodewords_use_frontpage_tags'] = array(
356 '#type' => 'checkbox',
357 '#title' => t('Use front page meta tags'),
358 '#description' => t('Check this option if you want to use the <a href="@front-page-url" title="Meta tags for front page">meta tags for the front page</a> even if the <a href="@site-settings-url" title="Site information">default front page</a> specified is a view, panel or node - in this case, the meta tags specified for the view, panel or node will be ignored. If you want to use the meta tags of the view, panel or node instead, uncheck this option. If unsure, select this option and specify the meta tags you want on the <a href="@front-page-url" title="Meta tags for front page">meta tags for the front page</a>.', array('@front-page-url' => url('admin/content/nodewords/meta-tags/frontpage'), '@site-settings-url' => url('admin/settings/site-information'))),
359 '#default_value' => variable_get('nodewords_use_frontpage_tags', TRUE),
360 );
361
362 $form['advanced']['nodewords_collapse_fieldset'] = array(
363 '#type' => 'checkbox',
364 '#title' => t('Always show the meta tags fieldset as collapsed'),
365 '#description' => t('Check this option if you want to always show the meta tags fieldset as collapsed.'),
366 '#default_value' => variable_get('nodewords_collapse_fieldset', FALSE),
367 );
368
369 $default_size = variable_get('nodewords_max_size', 350);
370
371 $form['advanced']['nodewords_max_size'] = array(
372 '#type' => 'textfield',
373 '#title' => t('Maximum meta tags length'),
374 '#description' => t('The maximum length to use for the meta tags form fields.'),
375 '#default_value' => $default_size,
376 '#required' => TRUE,
377 '#element_validate' => array('nodewords_max_size_validate'),
378 '#size' => 6,
379 '#maxlength' => 6,
380 );
381
382 if ($default_size < 350) {
383 $form['advanced']['nodewords_max_size']['#description'] .= ' ' . t('Most of the search engines are now indexing 350 characters, which is not the maximum length actually set for the meta tags. See <a href="@google-blog">Official Google Blog: Two new improvements to Google results pages</a> for more information.', array('@google-blog' => 'http://googleblog.blogspot.com/2009/03/two-new-improvements-to-google-results.html'));
384 }
385
386 foreach ($tags_info as $name => $info) {
387 $function = $info['tag:function:prefix'] . '_settings_form';
388 $options = array(
389 'parameters' => !empty($info['tag:function:parameters']) ? $info['tag:function:parameters'] : array(),
390 );
391
392 if (function_exists($function)) {
393 $function($form, 'advanced_settings', $options);
394 }
395 }
396
397 return system_settings_form($form);
398 }
399
400 /**
401 * Function to validate the value entered for the maximum meta tags length.
402 *
403 */
404 function nodewords_max_size_validate($element, &$form_state) {
405
406 if (!empty($element['#value'])) {
407 $value = trim($element['#value']);
408
409 if (empty($value) || (!empty($value) && (!is_numeric($value) || $value <= 0))) {
410 form_error($element, t('The value must be a number greater than zero.'));
411 }
412 }
413 }
414
415 /**
416 * Front page settings form.
417 */
418 function nodewords_tags_form(&$form_state, $type = NODEWORDS_MT_TYPE_DEFAULT, $id = '') {
419 $form = array();
420
421 $form['#nodewords_type'] = $type;
422 $form['#nodewords_id'] = $id;
423
424 _nodewords_check_enabled_modules();
425
426 $form['nodewords'] = nodewords_form(
427 $type,
428 nodewords_load_tags($type, $id),
429 array(
430 'fieldset' => FALSE,
431 )
432 );
433
434 if (empty($form['nodewords'])) {
435 if (!count(array_filter(variable_get('nodewords_edit', array())))) {
436 drupal_set_message(
437 t(
438 'No meta tags have been enabled for editing; enable them on the <a href="@settings_page">settings page</a>.',
439 array('@settings_page' => url('admin/content/nodewords/settings'))
440 )
441 );
442 }
443
444 return array();
445 }
446 else {
447 $form['nodewords']['#tree'] = TRUE;
448
449 $form['submit'] = array(
450 '#type' => 'submit',
451 '#value' => t('Save configuration'),
452 '#weight' => 40,
453 );
454
455 $form['reset'] = array(
456 '#type' => 'submit',
457 '#value' => t('Reset to defaults'),
458 '#submit' => array('nodewords_tags_form_reset'),
459 '#weight' => 42,
460 );
461 }
462
463 return $form;
464 }
465
466 /**
467 * Submission function for the meta tags edit page (reset button).
468 */
469 function nodewords_tags_form_reset($form, &$form_state) {
470 nodewords_delete_tags($form['#nodewords_type'], $form['#nodewords_id']);
471 drupal_set_message(t('The configuration options have been reset to their default values.'));
472 }
473
474 /**
475 * Submission function for the meta tags edit page.
476 */
477 function nodewords_tags_form_submit($form, &$form_state) {
478 nodewords_save_tags($form['#nodewords_type'], $form['#nodewords_id'], $form_state['values']['nodewords'], TRUE);
479 drupal_set_message(t('The configuration options have been saved.'));
480 }
481
482 /*****************************************************************************
483 * Theme functions.
484 ****************************************************************************/
485
486 /**
487 * Render the list of pages with meta tags.
488 */
489 function theme_nodewords_pages_overview($form) {
490 $has_pages = isset($form['path']) && is_array($form['path']);
491 $rows = array();
492
493 if ($has_pages) {
494 foreach (element_children($form['path']) as $key) {
495 $row = array();
496 $row[] = drupal_render($form['path'][$key]);
497
498 $form['weight'][$key]['#attributes']['class'] = 'page-weight';
499
500 $row[] = drupal_render($form['weight'][$key]);
501 $row[] = drupal_render($form['enabled'][$key]);
502 $row[] = drupal_render($form['edit'][$key]);
503 $row[] = drupal_render($form['delete'][$key]);
504
505 $rows[] = array(
506 'data' => $row,
507 'class' => 'draggable',
508 );
509 }
510 }
511
512 if (empty($rows)) {
513 $rows[] = array(
514 array(
515 'data' => t('There are currently no meta tags defined.'),
516 'colspan' => '5'
517 )
518 );
519 }
520
521 $header[] = t('Drupal path');
522 $header[] = t('Weight');
523
524 if (!empty($rows)) {
525 $header[] = array(
526 'data' => t('Enabled'),
527 'class' => count($rows) > 1 ? 'nodewords-pages-overview-enabled' : '',
528 );
529 }
530 else {
531 $header[] = array(
532 'data' => t('Enabled'),
533 );
534 }
535
536 $header[] = array(
537 'data' => t('Operations'),
538 'colspan' => '2',
539 );
540
541 drupal_add_tabledrag('nodewords', 'order', 'sibling', 'page-weight');
542
543 return theme('table', $header, $rows, array('id' => 'nodewords')) .
544 drupal_render($form);
545 }
546
547 /**
548 * @} End of "addtogroup nodewords" .
549 */

  ViewVC Help
Powered by ViewVC 1.1.2