/[drupal]/contributions/modules/page_lang/page_lang.module
ViewVC logotype

Contents of /contributions/modules/page_lang/page_lang.module

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


Revision 1.1 - (show annotations) (download) (as text)
Fri May 25 23:39:42 2007 UTC (2 years, 6 months ago) by cay
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
can use these to ensure that their HTML is easily adaptable for an international audience.
1 <?php
2
3 /**
4 * This module gives you control over the page lang. It gives you the chance
5 * to provide templates for how the lang tag should be structured, and on node
6 * pages, gives you the chance to specify the page lang rather than defaulting
7 * to the node lang.
8 */
9
10 define(MODULE_DESCRIPTIONS, 'This is a SEO module. Enhanced control over the tag page lang (in the &lt;head&gt; tag).');
11
12 function page_lang_help($section) {
13 switch ($section) {
14 case 'admin/modules#description':
15 $output = t(MODULE_DESCRIPTIONS);
16 break;
17 case 'admin/help#page_lang':
18 $output = t('<p>Adds an extra form element to node creation forms that allows you to specify the page lang.</p>
19 <p>Allows for better global configuration of the page lang.</p>');
20 break;
21 case 'admin/settings/page_lang':
22 $output = t("<p>The default page lang is en. This code is a variable form xhtml tag. Spesific this variable for indicate a cantry to de search ingenie. There are more countrys in the world:</p>
23 <p>es-ar cs en-uk en en-ca eu fr gl hu ja nl sk ca de de-de de-at de-ch es fi ga he it km ru sv...</p>
24 <p>Write in the box for the page the spesific code for the country.</p>");
25 break;
26 }
27 return $output;
28 }
29
30 /**
31 * Implementation of hook_perm().
32 */
33 function page_lang_perm() {
34 return array('set page lang');
35 }
36
37 /**
38 * Implementation of hook_menu().
39 */
40 function page_lang_menu($may_cache) {
41 if ($may_cache) {
42 $items[] = array(
43 'path' => 'admin/settings/page_lang',
44 'title' => t('Page lang'),
45 'description' => t(MODULE_DESCRIPTIONS),
46 'callback' => 'drupal_get_form',
47 'callback arguments' => 'page_lang_admin_settings',
48 'access' => user_access('administer site configuration'),
49 'type' => MENU_NORMAL_ITEM,
50 );
51 }
52 return $items;
53 }
54
55 function page_lang_admin_settings() {
56 $form['page_lang'] = array(
57 '#type' => 'fieldset',
58 '#title' => t('Page lang templates'),
59 );
60 $form['page_lang']['page_lang_individual'] = array(
61 '#type' => 'textfield',
62 '#title' => t('Pattern for individual pages'),
63 '#default_value' => variable_get('page_lang_individual', 'en'),
64 '#maxlength' => 5,
65 '#description' => t('Change in here the value for default: <code>en</code>.'),
66 );
67 return system_settings_form($form);
68 }
69
70 function page_lang_form_alter($form_id, &$form) {
71 if ($form['#id'] == 'node-form' && user_access('set page lang')) {
72 $form['page_lang'] = array(
73 '#type' => 'textfield',
74 '#title' => t('Page language'),
75 '#default_value' => $form['#node']->page_lang,
76 '#size' => 5,
77 '#maxlength' => 5,
78 '#weight' => -4,
79 );
80 }
81 }
82
83 function page_lang_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
84 switch ($op) {
85 case 'update':
86 db_query("DELETE FROM {page_lang} WHERE nid = %d", $node->nid);
87 // fallthrough to insert intentional!
88 case 'insert':
89 if (strlen(trim($node->page_lang)) > 0) {
90 db_query("INSERT INTO {page_lang} VALUES (%d, '%s')", $node->nid, $node->page_lang);
91 }
92 break;
93
94 case 'delete':
95 db_query('DELETE FROM {page_lang} WHERE nid = %d', $node->nid);
96 break;
97
98 case 'load':
99 $object = new stdClass();
100 $object->page_lang = page_lang_node_get_lang($node->nid);
101 return array('page_lang' => $object->page_lang);
102
103 case 'view':
104 if ($page) {
105 page_lang_set_lang($node->page_lang);
106 }
107 break;
108 }
109 }
110
111
112 /**
113 * Set the page lang of the current page, for display on the page and in the lang bar.
114 */
115 function page_lang_set_lang($lang = NULL) {
116 static $stored_lang;
117
118 if (isset($lang)) {
119 $stored_lang = $lang;
120 }
121 return $stored_lang;
122 }
123
124 // Public API (every module's gotta have one =)
125
126 /**
127 * Gets the page lang for a node id
128 *
129 * @param the node's id
130 * @return the node's page lang.
131 */
132 function page_lang_node_get_lang($nid) {
133 $row = db_fetch_object(db_query('SELECT page_lang FROM {page_lang} WHERE nid = %d', $nid));
134 return $row->page_lang;
135 }
136
137 /**
138 * Does the logic to see what lang should be send to the page template. Call this function from
139 * the page hook of function _phptemplate_variables in template.php.
140 */
141 function page_lang_page_get_lang() {
142 $page_lang_individual = variable_get('page_lang_individual', '!page_lang');
143
144 // this is the custom page lang. For node pages it is $node->page_lang.
145 $page_lang = (page_lang_set_lang()) ? page_lang_set_lang() : $drupal_lang;
146 $page_lang = strip_tags($page_lang);
147
148 if ($page_lang){
149 $lang = $page_lang;
150 }
151 else {
152 $lang = $page_lang_individual;
153 }
154
155 return $lang;
156 }

  ViewVC Help
Powered by ViewVC 1.1.2