| 1 |
<?php
|
| 2 |
// $Id: nodewords.install,v 1.17 2009/10/25 07:22:34 kiam Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Installation file for Nodewords.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Installation constants.
|
| 11 |
*/
|
| 12 |
define('NODEWORDS_INSTALL_MT_TYPE_DEFAULT', 1);
|
| 13 |
define('NODEWORDS_INSTALL_MT_TYPE_ERRORPAGE', 2);
|
| 14 |
define('NODEWORDS_INSTALL_MT_TYPE_FRONTPAGE', 3);
|
| 15 |
define('NODEWORDS_INSTALL_MT_TYPE_PAGER', 4);
|
| 16 |
define('NODEWORDS_INSTALL_MT_TYPE_NODE', 5);
|
| 17 |
define('NODEWORDS_INSTALL_MT_TYPE_TERM', 6);
|
| 18 |
define('NODEWORDS_INSTALL_MT_TYPE_TRACKER', 7);
|
| 19 |
define('NODEWORDS_INSTALL_MT_TYPE_USER', 8);
|
| 20 |
define('NODEWORDS_INSTALL_MT_TYPE_VOCABULARY', 9);
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Implementation of hook_requirements().
|
| 24 |
*/
|
| 25 |
function nodewords_requirements($phase) {
|
| 26 |
$requirements = array();
|
| 27 |
|
| 28 |
if ($phase == 'runtime') {
|
| 29 |
if (!count(module_implements('nodewords_api'))) {
|
| 30 |
$requirements['nodewords'] = array(
|
| 31 |
'title' => t('Nodewords'),
|
| 32 |
'description' => t('Nodewords does not create meta tags anymore; it is just a module that implements a public API used from the modules that create meta tags. You need to enable at least one module between nodewords_basic.module, nodewords_extra.module, and nodewords_verification_tags.module that are listed under <em>Meta tags</em> in the modules page.'),
|
| 33 |
'severity' => REQUIREMENT_ERROR,
|
| 34 |
'value' => t('Enable the <a href="@url">meta tags modules</a>.', array('@url' => url('admin/build/modules'))),
|
| 35 |
);
|
| 36 |
}
|
| 37 |
elseif (module_exists('nodewords_bypath')) {
|
| 38 |
$requirements['nodewords'] = array(
|
| 39 |
'title' => t('Nodewords'),
|
| 40 |
'description' => t('The feature implemented in <q>Meta Tags by Path</q> is now included in Nodewords; there is not need to use <q>Meta Tags by Path</q>, and the module should be disabled to avoid possible conflicts.'),
|
| 41 |
'severity' => REQUIREMENT_ERROR,
|
| 42 |
'value' => t('Disable the module in the<a href="@url">modules page</a>.', array('@url' => url('admin/build/modules'))),
|
| 43 |
);
|
| 44 |
}
|
| 45 |
}
|
| 46 |
|
| 47 |
return $requirements;
|
| 48 |
}
|
| 49 |
|
| 50 |
/**
|
| 51 |
* Implementation of hook_schema().
|
| 52 |
*/
|
| 53 |
function nodewords_schema() {
|
| 54 |
$schema['nodewords'] = array(
|
| 55 |
'description' => 'The table containing the meta tag values for all the pages.',
|
| 56 |
'fields' => array(
|
| 57 |
'mtid' => array(
|
| 58 |
'description' => 'The primary key.',
|
| 59 |
'type' => 'serial',
|
| 60 |
'unsigned' => TRUE,
|
| 61 |
'not null' => TRUE,
|
| 62 |
),
|
| 63 |
'type' => array(
|
| 64 |
'description' => 'The type of object to which the meta tag refers (node, user, page, etc...).',
|
| 65 |
'type' => 'int',
|
| 66 |
'size' => 'small',
|
| 67 |
'unsigned' => TRUE,
|
| 68 |
'not null' => TRUE,
|
| 69 |
'default' => 0,
|
| 70 |
),
|
| 71 |
'id' => array(
|
| 72 |
'description' => 'The object ID.',
|
| 73 |
'type' => 'varchar',
|
| 74 |
'length' => 255,
|
| 75 |
'not null' => TRUE,
|
| 76 |
'default' => '',
|
| 77 |
),
|
| 78 |
'name' => array(
|
| 79 |
'description' => 'The meta tag name.',
|
| 80 |
'type' => 'varchar',
|
| 81 |
'length' => 32,
|
| 82 |
'not null' => TRUE,
|
| 83 |
'default' => '',
|
| 84 |
),
|
| 85 |
'content' => array(
|
| 86 |
'description' => 'The content of the meta tag.',
|
| 87 |
'type' => 'text',
|
| 88 |
'size' => 'big',
|
| 89 |
'not null' => TRUE,
|
| 90 |
),
|
| 91 |
),
|
| 92 |
'indexes' => array(
|
| 93 |
'nodewords_id' => array(array('id', 6)),
|
| 94 |
'nodewords_type' => array('type'),
|
| 95 |
),
|
| 96 |
'unique keys' => array(
|
| 97 |
'tin' => array('type', 'id', 'name'),
|
| 98 |
),
|
| 99 |
'primary key' => array('mtid'),
|
| 100 |
);
|
| 101 |
|
| 102 |
$schema['nodewords_custom'] = array(
|
| 103 |
'description' => 'The table containing data for custom pages.',
|
| 104 |
'fields' => array(
|
| 105 |
'pid' => array(
|
| 106 |
'description' => 'The primary key.',
|
| 107 |
'type' => 'serial',
|
| 108 |
'unsigned' => TRUE,
|
| 109 |
'not null' => TRUE,
|
| 110 |
),
|
| 111 |
'path' => array(
|
| 112 |
'description' => 'The page path.',
|
| 113 |
'type' => 'varchar',
|
| 114 |
'length' => 255,
|
| 115 |
'not null' => TRUE,
|
| 116 |
'default' => '',
|
| 117 |
),
|
| 118 |
'weight' => array(
|
| 119 |
'description' => 'The weight of the page.',
|
| 120 |
'type' => 'int',
|
| 121 |
'size' => 'tiny',
|
| 122 |
'not null' => TRUE,
|
| 123 |
'default' => 0,
|
| 124 |
),
|
| 125 |
'enabled' => array(
|
| 126 |
'description' => 'A flag set when the page is enabled.',
|
| 127 |
'type' => 'int',
|
| 128 |
'size' => 'tiny',
|
| 129 |
'not null' => TRUE,
|
| 130 |
'default' => 1,
|
| 131 |
),
|
| 132 |
),
|
| 133 |
'unique keys' => array(
|
| 134 |
'path' => array('path'),
|
| 135 |
),
|
| 136 |
'primary key' => array('pid'),
|
| 137 |
);
|
| 138 |
|
| 139 |
return $schema;
|
| 140 |
}
|
| 141 |
|
| 142 |
/**
|
| 143 |
* Implementation of hook_install().
|
| 144 |
*/
|
| 145 |
function nodewords_install() {
|
| 146 |
drupal_install_schema('nodewords');
|
| 147 |
db_query("UPDATE {system} SET weight = 10 WHERE name = 'nodewords' AND type = 'module'");
|
| 148 |
}
|
| 149 |
|
| 150 |
/**
|
| 151 |
* Implementation of hook_update_N().
|
| 152 |
*/
|
| 153 |
function nodewords_update_6300() {
|
| 154 |
$bool = (
|
| 155 |
variable_get('nodewords_update_6113', FALSE) ||
|
| 156 |
variable_get('nodewords_update_6139', FALSE)
|
| 157 |
);
|
| 158 |
$ret = array();
|
| 159 |
$types = array(
|
| 160 |
'default' => NODEWORDS_INSTALL_MT_TYPE_DEFAULT,
|
| 161 |
'errorpage' => NODEWORDS_INSTALL_MT_TYPE_ERRORPAGE,
|
| 162 |
'frontpage' => NODEWORDS_INSTALL_MT_TYPE_FRONTPAGE,
|
| 163 |
'pager' => NODEWORDS_INSTALL_MT_TYPE_PAGER,
|
| 164 |
'node' => NODEWORDS_INSTALL_MT_TYPE_NODE,
|
| 165 |
'term' => NODEWORDS_INSTALL_MT_TYPE_TERM,
|
| 166 |
'tracker' => NODEWORDS_INSTALL_MT_TYPE_TRACKER,
|
| 167 |
'user' => NODEWORDS_INSTALL_MT_TYPE_USER,
|
| 168 |
'vocabulary' => NODEWORDS_INSTALL_MT_TYPE_VOCABULARY,
|
| 169 |
);
|
| 170 |
|
| 171 |
if ($bool) {
|
| 172 |
foreach ($types as $type => $value) {
|
| 173 |
$ret[] = update_sql("UPDATE {nodewords} SET type = '$value' WHERE type = '$type'");
|
| 174 |
}
|
| 175 |
|
| 176 |
db_drop_unique_key($ret, 'nodewords', 'tin');
|
| 177 |
db_drop_index($ret, 'nodewords', 'nodewords_type');
|
| 178 |
db_change_field($ret, 'nodewords', 'mtid', 'mtid',
|
| 179 |
array(
|
| 180 |
'type' => 'serial',
|
| 181 |
'unsigned' => TRUE,
|
| 182 |
'not null' => TRUE,
|
| 183 |
)
|
| 184 |
);
|
| 185 |
db_change_field($ret, 'nodewords', 'type', 'type',
|
| 186 |
array(
|
| 187 |
'type' => 'int',
|
| 188 |
'size' => 'small',
|
| 189 |
'unsigned' => TRUE,
|
| 190 |
'not null' => TRUE,
|
| 191 |
'default' => 0,
|
| 192 |
)
|
| 193 |
);
|
| 194 |
db_add_unique_key($ret, 'nodewords', 'tin', array('type', 'id', 'name'));
|
| 195 |
db_add_index($ret, 'nodewords', 'nodewords_type', array('type'));
|
| 196 |
|
| 197 |
db_change_field($ret, 'nodewords_custom', 'pid', 'pid',
|
| 198 |
array(
|
| 199 |
'type' => 'serial',
|
| 200 |
'unsigned' => TRUE,
|
| 201 |
'not null' => TRUE,
|
| 202 |
)
|
| 203 |
);
|
| 204 |
}
|
| 205 |
else {
|
| 206 |
$ret['#abort'] = array(
|
| 207 |
'success' => FALSE,
|
| 208 |
'query' => 'The only supported update is from version 6.x-1.3-beta3 or later.'
|
| 209 |
);
|
| 210 |
}
|
| 211 |
|
| 212 |
return $ret;
|
| 213 |
}
|
| 214 |
|
| 215 |
/**
|
| 216 |
* Implementation of hook_update_N().
|
| 217 |
*/
|
| 218 |
function nodewords_update_6301() {
|
| 219 |
$ret = array();
|
| 220 |
|
| 221 |
$ret[] = update_sql("UPDATE {nodewords} nw SET nw.id = (SELECT n.vid FROM {node} n WHERE n.nid = nw.id)");
|
| 222 |
|
| 223 |
return $ret;
|
| 224 |
|
| 225 |
}
|
| 226 |
|
| 227 |
/**
|
| 228 |
* Implementation of hook_update_N().
|
| 229 |
*/
|
| 230 |
function nodewords_update_6302() {
|
| 231 |
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'nodewords\_basic\_user\_teaser\_%'");
|
| 232 |
$ret = array();
|
| 233 |
|
| 234 |
while ($row = db_fetch_object($result)) {
|
| 235 |
$variable = str_replace('nodewords_basic_user_', 'nodewords_basic_use_', $row->name);
|
| 236 |
|
| 237 |
if (!db_result(db_query("SELECT 1 FROM {variable} WHERE name = '%s'", $variable))) {
|
| 238 |
$ret[] = update_sql(
|
| 239 |
"UPDATE {variable} SET name = '" .
|
| 240 |
$variable . "' WHERE name = '" . $row->name . "'"
|
| 241 |
);
|
| 242 |
}
|
| 243 |
}
|
| 244 |
|
| 245 |
return $ret;
|
| 246 |
}
|
| 247 |
|
| 248 |
/**
|
| 249 |
* Implementation of hook_update_N().
|
| 250 |
*/
|
| 251 |
function nodewords_update_6303() {
|
| 252 |
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'nodewords\_basic_use\_teaser\_%'");
|
| 253 |
$ret = array();
|
| 254 |
|
| 255 |
$ret[] = update_sql("UPDATE {variable} SET name = 'nodewords_use_teaser' WHERE name = 'nodewords_basic_use_teaser'");
|
| 256 |
$ret[] = update_sql("UPDATE {variable} SET name = 'nodewords_use_alt_attribute' WHERE name = 'nodewords_basic_use_alt_attribute'");
|
| 257 |
|
| 258 |
while ($row = db_fetch_object($result)) {
|
| 259 |
$variable = str_replace('nodewords_basic_use_', 'nodewords_use_', $row->name);
|
| 260 |
|
| 261 |
if (!db_result(db_query("SELECT 1 FROM {variable} WHERE name = '%s'", $variable))) {
|
| 262 |
$ret[] = update_sql(
|
| 263 |
"UPDATE {variable} SET name = '" .
|
| 264 |
$variable . "' WHERE name = '" . $row->name . "'"
|
| 265 |
);
|
| 266 |
}
|
| 267 |
}
|
| 268 |
|
| 269 |
return $ret;
|
| 270 |
}
|
| 271 |
|
| 272 |
/**
|
| 273 |
* Implementation of hook_update_N().
|
| 274 |
*/
|
| 275 |
function nodewords_update_6304() {
|
| 276 |
$ret = array();
|
| 277 |
|
| 278 |
// Only update if the setting have the default value, and if it has been
|
| 279 |
// previously set.
|
| 280 |
$value = variable_get('nodewords_max_size', NULL);
|
| 281 |
|
| 282 |
if (isset($value) && $value == 255) {
|
| 283 |
variable_set('nodewords_max_size', 350);
|
| 284 |
|
| 285 |
$ret[] = array(
|
| 286 |
'success' => TRUE,
|
| 287 |
'query' => "UPDATE {variable} SET value = 350 WHERE name = 'nodewords_max_size'",
|
| 288 |
);
|
| 289 |
|
| 290 |
drupal_set_message('The default maximum meta tags length has been extended to 350 characters to improve Google results pages. See <a href="http://googleblog.blogspot.com/2009/03/two-new-improvements-to-google-results.html">Two new improvements to Google results pages</a> in the official Google blog for more information.');
|
| 291 |
}
|
| 292 |
|
| 293 |
return $ret;
|
| 294 |
}
|
| 295 |
|
| 296 |
/**
|
| 297 |
* Implementation of hook_uninstall().
|
| 298 |
*/
|
| 299 |
function nodewords_uninstall() {
|
| 300 |
drupal_uninstall_schema('nodewords');
|
| 301 |
db_query("DELETE FROM {variable} WHERE name LIKE 'nodewords%'");
|
| 302 |
}
|
| 303 |
|
| 304 |
/*****************************************************************************
|
| 305 |
* Private functions.
|
| 306 |
****************************************************************************/
|
| 307 |
|
| 308 |
/*
|
| 309 |
* Remove the duplicates from a list of items separated from the separator,
|
| 310 |
* preserving the order in which they appear.
|
| 311 |
* @param $text
|
| 312 |
* The string containing the list of items.
|
| 313 |
*
|
| 314 |
* @return
|
| 315 |
* A string containing only unique items present in the string of concatenated
|
| 316 |
* items.
|
| 317 |
*/
|
| 318 |
function _nodewords_get_unique_values($text) {
|
| 319 |
$lc_values = array();
|
| 320 |
$unique_values = array();
|
| 321 |
|
| 322 |
foreach (array_filter(array_map('trim', explode(',', $text))) as $item) {
|
| 323 |
$lowercase = drupal_strtolower($item);
|
| 324 |
|
| 325 |
if (!in_array($lowercase, $lc_values)) {
|
| 326 |
$lc_values[] = $lowercase;
|
| 327 |
$unique_values[] = $item;
|
| 328 |
}
|
| 329 |
}
|
| 330 |
|
| 331 |
return implode(', ', $unique_values);
|
| 332 |
}
|