| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: node_language.inc,v 1.7.2.3 2010/07/14 01:30:19 merlinofchaos Exp $ 3 4 /** 5 * @file 6 * Plugin to provide access control based upon node type. 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 if (module_exists('locale')) { 14 $plugin = array( 15 'title' => t("Node: language"), 16 'description' => t('Control access by node language.'), 17 'callback' => 'ctools_node_language_ctools_access_check', 18 'default' => array('language' => array()), 19 'settings form' => 'ctools_node_language_ctools_access_settings', 20 'settings form submit' => 'ctools_node_language_ctools_access_settings_submit', 21 'summary' => 'ctools_node_language_ctools_access_summary', 22 'required context' => new ctools_context_required(t('Node'), 'node'), 23 ); 24 } 25 26 /** 27 * Settings form for the 'by node_language' access plugin 28 */ 29 function ctools_node_language_ctools_access_settings(&$form, &$form_state, $conf) { 30 $options = array( 31 'current' => t('Current site language'), 32 'default' => t('Default site language'), 33 'no_language' => t('No language'), 34 ); 35 $options = array_merge($options, locale_language_list()); 36 $form['settings']['language'] = array( 37 '#title' => t('Language'), 38 '#type' => 'checkboxes', 39 '#options' => $options, 40 '#description' => t('Pass only if the node is in one of the selected languages.'), 41 '#default_value' => $conf['language'], 42 ); 43 } 44 45 /** 46 * Check for access. 47 */ 48 function ctools_node_language_ctools_access_check($conf, $context) { 49 // As far as I know there should always be a context at this point, but this 50 // is safe. 51 if (empty($context) || empty($context->data) || !isset($context->data->language)) { 52 return FALSE; 53 } 54 55 global $language; 56 57 // Specialcase: if 'no language' is checked, return TRUE if the language field is 58 // empty. 59 if (!empty($conf['language']['no_language'])) { 60 if (empty($context->data->language)) { 61 return TRUE; 62 } 63 } 64 65 // Specialcase: if 'current' is checked, return TRUE if the current site language 66 // matches the node language. 67 if (!empty($conf['language']['current'])) { 68 if ($context->data->language == $language->language) { 69 return TRUE; 70 } 71 } 72 73 // Specialcase: If 'default' is checked, return TRUE if the default site language 74 // matches the node language. 75 if (!empty($conf['language']['default'])) { 76 if ($context->data->language == language_default('language')) { 77 return TRUE; 78 } 79 } 80 81 if (array_filter($conf['language']) && empty($conf['language'][$context->data->language])) { 82 return FALSE; 83 } 84 85 return TRUE; 86 } 87 88 /** 89 * Provide a summary description based upon the checked node_languages. 90 */ 91 function ctools_node_language_ctools_access_summary($conf, $context) { 92 $languages = array( 93 'current' => t('Current site language'), 94 'default' => t('Default site language'), 95 'no_language' => t('No language'), 96 ); 97 $languages = array_merge($languages, locale_language_list()); 98 99 if (!isset($conf['language'])) { 100 $conf['language'] = array(); 101 } 102 103 $names = array(); 104 foreach (array_filter($conf['language']) as $language) { 105 $names[] = $languages[$language]; 106 } 107 108 if (empty($names)) { 109 return t('@identifier is in any language', array('@identifier' => $context->identifier)); 110 } 111 112 return format_plural(count($names), '@identifier language is "@languages"', '@identifier language is one of "@languages"', array('@languages' => implode(', ', $names), '@identifier' => $context->identifier)); 113 } 114
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |