-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta_tags.admin.inc
195 lines (175 loc) · 6.33 KB
/
meta_tags.admin.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
/**
* @file
* Administration page callbacks for the meta tags module.
*/
/**
* Form builder. Configure annotations.
*
* @ingroup forms
* @see system_settings_form().
*/
function meta_tags_admin_settings() {
// Get an array of node types with internal names as keys and
// "friendly names" as values. E.g.,
// array('page' => Basic Page, 'article' => 'Articles')
$types = node_type_get_types();
foreach($types as $node_type) {
$options[$node_type->type] = $node_type->name;
}
$form['meta_tags_node_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Users may add meta tags these content types'),
'#options' => $options,
'#default_value' => variable_get('meta_tags_node_types', array('page')),
'#description' => t('Meta tag fields will be available on these content types.'),
);
$form['meta_tags_default_title'] = array(
'#type' => 'textfield',
'#title' => t('Default page title'),
'#description' => t('Enter the default page title here. If no content specific page title is set this will be the fall back title.'),
'#default_value' => variable_get('meta_tags_default_title', 'Enter the default title here...'),
);
$form['meta_tags_default_desc'] = array(
'#type' => 'textarea',
'#title' => t('Default page description'),
'#description' => t('Enter the default page description here. If no content specific page title is set this will be the fall back title.'),
'#default_value' => variable_get('meta_tags_default_desc', 'Enter the default description here...'),
'#cols' => 40,
'#rows' => 3,
'#resizeable' => false
);
$form['meta_tags_default_keywords'] = array(
'#type' => 'textarea',
'#title' => t('Default page keywords'),
'#description' => t('Enter the default page keywords here. Any additional keywords will be added to this list.'),
'#default_value' => variable_get('meta_tags_default_keywords', 'Enter the default keywords here...'),
'#cols' => 40,
'#rows' => 3,
'#resizeable' => false
);
$form['#submit'][] = 'meta_tags_admin_settings_submit';
return system_settings_form($form, TRUE);
}
/**
* Validate annotation settings submission.
*/
/*function meta_tags_admin_settings_validate($form, &$form_state) {
$limit = $form_state['values']['meta_tags_limit_per_node'];
if (!is_numeric($limit)) {
form_set_error('meta_tags_limit_per_node', t('Please enter number.'));
}
}*/
/**
* Process annotation settings submission.
*/
function meta_tags_admin_settings_submit($form, $form_state) {
// Loop through each of the content type checkboxes shown on the form.
foreach ($form_state['values']['meta_tags_node_types'] as $key => $value) {
// If the check box for a content type is unchecked, look to see whether
// this content type has the annotation field attached to it using the
// field_info_instance function. If it does then we need to remove the
// annotation field as the administrator has unchecked the box.
if (!$value) {
$instance = field_info_instance('node', 'meta_tags_content_title', $key);
if (!empty($instance)) {
field_delete_instance($instance, FALSE);
watchdog("Meta tags module", 'Deleted meta tags fields from content type:
%key', array('%key' => $key));
}
$instance = field_info_instance('node', 'meta_tags_content_desc', $key);
if (!empty($instance)) {
field_delete_instance($instance, FALSE);
watchdog("Meta tags module", 'Deleted meta tags fields from content type:
%key', array('%key' => $key));
}
$instance = field_info_instance('node', 'meta_tags_default_desc', $key);
if (!empty($instance)) {
field_delete_instance($instance, FALSE);
watchdog("Meta tags module", 'Deleted meta tags fields from content type:
%key', array('%key' => $key));
}
} else {
// If the check box for a content type is checked, look to see whether
// the field is associated with that content type. If not then add the
// annotation field to the content type.
$instance = field_info_instance('node', 'meta_title', $key);
if (empty($instance)) {
$instance = array(
'field_name' => 'meta_title',
'entity_type' => 'node',
'bundle' => $key,
'label' => t('Meta tags Title'),
'widget_type' => 'text',
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'hidden',
),
),
);
$instance = field_create_instance($instance);
watchdog('Meta tags module', 'Added meta tags title field to content type: %key',
array('%key' => $key));
}
$instance = field_info_instance('node', 'meta_desc', $key);
if (empty($instance)) {
$instance = array(
'field_name' => 'meta_desc',
'entity_type' => 'node',
'bundle' => $key,
'label' => t('Meta tags Description'),
'widget' => array(
'type' => 'text_textarea',
'settings' => array(
'rows' => 4,
),
),
'settings' => array(
'text_processing' => 0, // @TODO Find out the name
),
'default_value' => array(),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'hidden',
'settings' => array(),
),
),
);
$instance = field_create_instance($instance);
watchdog('Meta tags module', 'Added meta tags description field to content type: %key',
array('%key' => $key));
}
$instance = field_info_instance('node', 'meta_keywords', $key);
if (empty($instance)) {
$instance = array(
'field_name' => 'meta_keywords',
'entity_type' => 'node',
'bundle' => $key,
'label' => t('Meta tags Keywords'),
'widget' => array(
'type' => 'text_textarea',
'settings' => array(
'rows' => 4,
),
),
'settings' => array(
'text_processing' => 0, // @TODO Find out the name
),
'default_value' => array(),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'hidden',
'settings' => array(),
),
),
);
$instance = field_create_instance($instance);
watchdog('Meta tags module', 'Added meta tags keywords field to content type: %key',
array('%key' => $key));
}
}
} // End foreach loop.
}