| 9 |
/** The empty field specifier. */ |
/** The empty field specifier. */ |
| 10 |
define('NODEWORDS_NONE', '<none>'); |
define('NODEWORDS_NONE', '<none>'); |
| 11 |
|
|
|
require_once(drupal_get_path('module', 'nodewords_bypath') .'/nodewords_bypath.forms.inc'); |
|
|
|
|
|
|
|
| 12 |
/** |
/** |
| 13 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 14 |
* |
* |
| 48 |
'type' => MENU_LOCAL_TASK, |
'type' => MENU_LOCAL_TASK, |
| 49 |
'access arguments' => array('administer meta tags'), |
'access arguments' => array('administer meta tags'), |
| 50 |
'weight' => 5, |
'weight' => 5, |
| 51 |
|
'file' => 'nodewords_bypath.forms.inc', |
| 52 |
); |
); |
| 53 |
|
|
| 54 |
$items['admin/content/nodewords/path/list'] = array( |
$items['admin/content/nodewords/path/list'] = array( |
| 56 |
'page callback' => 'nodewords_bypath_admin_overview', |
'page callback' => 'nodewords_bypath_admin_overview', |
| 57 |
'type' => MENU_DEFAULT_LOCAL_TASK, |
'type' => MENU_DEFAULT_LOCAL_TASK, |
| 58 |
'access arguments' => array('administer meta tags'), |
'access arguments' => array('administer meta tags'), |
| 59 |
|
'file' => 'nodewords_bypath.forms.inc', |
| 60 |
); |
); |
| 61 |
|
|
| 62 |
$items['admin/content/nodewords/path/new'] = array( |
$items['admin/content/nodewords/path/new'] = array( |
| 63 |
'title' => 'New Rule', |
'title' => 'New Rule', |
| 64 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 65 |
'page arguments' => array('nodewords_bypath_create_form'), |
'page arguments' => array('nodewords_bypath_form'), |
| 66 |
'type' => MENU_LOCAL_TASK, |
'type' => MENU_LOCAL_TASK, |
| 67 |
'weight' => 1, |
'weight' => 1, |
| 68 |
'access arguments' => array('administer meta tags'), |
'access arguments' => array('administer meta tags'), |
| 69 |
|
'file' => 'nodewords_bypath.forms.inc', |
| 70 |
); |
); |
| 71 |
|
|
| 72 |
if (function_exists('token_get_list')) { |
if (function_exists('token_get_list')) { |
| 77 |
'type' => MENU_LOCAL_TASK, |
'type' => MENU_LOCAL_TASK, |
| 78 |
'weight' => 2, |
'weight' => 2, |
| 79 |
'access arguments' => array('administer meta tags'), |
'access arguments' => array('administer meta tags'), |
| 80 |
|
'file' => 'nodewords_bypath.forms.inc', |
| 81 |
); |
); |
| 82 |
} |
} |
| 83 |
|
|
| 84 |
$items['admin/content/nodewords/path/edit/%'] = array( |
$items['admin/content/nodewords/path/%nodewords_bypath_rule/edit'] = array( |
| 85 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 86 |
'page arguments' => array('nodewords_bypath_create_form', arg(5)), |
'page arguments' => array('nodewords_bypath_form', 4), |
| 87 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 88 |
'access arguments' => array('administer meta tags'), |
'access arguments' => array('administer meta tags'), |
| 89 |
|
'file' => 'nodewords_bypath.forms.inc', |
| 90 |
); |
); |
| 91 |
|
|
| 92 |
$items['admin/content/nodewords/path/delete/%'] = array( |
$items['admin/content/nodewords/path/%nodewords_bypath_rule/delete'] = array( |
| 93 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 94 |
'page arguments' => array('nodewords_bypath_delete_form', arg(5)), |
'page arguments' => array('nodewords_bypath_delete_form', 4), |
| 95 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 96 |
'access arguments' => array('administer meta tags'), |
'access arguments' => array('administer meta tags'), |
| 97 |
|
'file' => 'nodewords_bypath.forms.inc', |
| 98 |
); |
); |
| 99 |
|
|
| 100 |
return $items; |
return $items; |
| 132 |
switch ($op) { |
switch ($op) { |
| 133 |
case 'prepare': |
case 'prepare': |
| 134 |
$path = drupal_get_path_alias($_GET['q']); |
$path = drupal_get_path_alias($_GET['q']); |
| 135 |
if ($rule = _nodewords_bypath_get_path_rule($path)) { |
if ($rule = _nodewords_bypath_path_rule_load($path)) { |
| 136 |
$rule_tags = _nodewords_bypath_get_tags_for($rule->id); |
$rule_tags = _nodewords_bypath_tags_load($rule->id); |
| 137 |
|
|
| 138 |
//-------------------------------------------------------------------- |
//-------------------------------------------------------------------- |
| 139 |
// Determine the context for token replacement. |
// Determine the context for token replacement. |
| 176 |
* |
* |
| 177 |
* @param $rule object The rule instance to create or update. |
* @param $rule object The rule instance to create or update. |
| 178 |
*/ |
*/ |
| 179 |
function _nodewords_bypath_save($rule) { |
function nodewords_bypath_rule_save($rule) { |
| 180 |
// Updating an existing rule |
// Updating an existing rule |
| 181 |
if (isset($rule->id) && ($rule->id > -1)) { |
if (isset($rule->id) && ($rule->id > -1)) { |
| 182 |
db_query("UPDATE {nodewords_bypath_rules} SET |
drupal_write_record('nodewords_bypath_rules', $rule, 'id'); |
|
name = '%s', type = %d, path_expr = '%s', weight = %d |
|
|
WHERE id = %d", |
|
|
$rule->name, $rule->type, $rule->path_expr, |
|
|
$rule->weight, $rule->id); |
|
| 183 |
|
|
| 184 |
//---------------------------------------------------------------------- |
//---------------------------------------------------------------------- |
| 185 |
// Tags are trickier. They could exist already, or they may be new if |
// Tags are trickier. They could exist already, or they may be new if |
| 186 |
// the administrator has recently changed the available tags. |
// the administrator has recently changed the available tags. |
| 187 |
foreach ($rule->tags as $tag => $value) { |
foreach ($rule->tags as $name => $value) { |
| 188 |
|
$tag = new stdClass; |
| 189 |
|
$tag->rule_id = $rule->id; |
| 190 |
|
$tag->meta_tag = $name; |
| 191 |
|
$tag->meta_value = $value; |
| 192 |
|
|
| 193 |
$exists = db_result(db_query("SELECT COUNT(*) FROM {nodewords_bypath_tags} |
$exists = db_result(db_query("SELECT COUNT(*) FROM {nodewords_bypath_tags} |
| 194 |
WHERE (rule_id = %d AND meta_tag = '%s')", |
WHERE (rule_id = %d AND meta_tag = '%s')", |
| 195 |
$rule->id, $tag)); |
$rule->id, $name)); |
| 196 |
if ($exists > 0) { |
if ($exists > 0) { |
| 197 |
db_query("UPDATE {nodewords_bypath_tags} SET meta_value = '%s' |
drupal_write_record('nodewords_bypath_tags', $tag, array('rule_id', 'meta_tag')); |
|
WHERE (rule_id = %d AND meta_tag = '%s')", |
|
|
$value, $rule->id, $tag); |
|
| 198 |
} |
} |
| 199 |
else { |
else { |
| 200 |
db_query("INSERT INTO {nodewords_bypath_tags} (rule_id, meta_tag, meta_value) |
drupal_write_record('nodewords_bypath_tags', $tag); |
|
VALUES (%d, '%s', '%s')", $rule->id, $tag, $value); |
|
| 201 |
} |
} |
| 202 |
} |
} |
| 203 |
} |
} |
| 204 |
// Saving a new rule |
// Saving a new rule |
| 205 |
else { |
else { |
| 206 |
db_query("INSERT INTO {nodewords_bypath_rules} |
drupal_write_record('nodewords_bypath_rules', $rule); |
| 207 |
(name, type, path_expr, weight) |
foreach ($rule->tags as $name => $value) { |
| 208 |
VALUES ('%s', %d, '%s', %d)", |
$tag = new stdClass; |
| 209 |
$rule->name, $rule->type, |
$tag->rule_id = $rule->id; |
| 210 |
$rule->path_expr, $rule->weight); |
$tag->meta_tag = $name; |
| 211 |
$id = db_last_insert_id('nodewords_bypath_rules', 'id'); |
$tag->meta_value = $value; |
| 212 |
foreach ($rule->tags as $tag => $value) { |
drupal_write_record('nodewords_bypath_tags', $tag); |
|
db_query("INSERT INTO {nodewords_bypath_tags} (rule_id, meta_tag, meta_value) |
|
|
VALUES (%d, '%s', '%s')", $id, $tag, $value); |
|
| 213 |
} |
} |
| 214 |
} |
} |
| 215 |
} |
} |
| 216 |
|
|
|
|
|
| 217 |
/** |
/** |
| 218 |
* Retrieve the meta tags for the given rule ID. |
* Retrieve the meta tags for the given rule ID. |
| 219 |
* |
* |
| 221 |
* |
* |
| 222 |
* @return array A mapping of term names (string) to their values (string). |
* @return array A mapping of term names (string) to their values (string). |
| 223 |
*/ |
*/ |
| 224 |
function _nodewords_bypath_get_tags_for($id) { |
function _nodewords_bypath_tags_load($id) { |
| 225 |
$tags = array(); |
$tags = array(); |
| 226 |
$result = db_query('SELECT meta_tag, meta_value |
$result = db_query('SELECT meta_tag, meta_value |
| 227 |
FROM {nodewords_bypath_tags} WHERE rule_id = %d', $id); |
FROM {nodewords_bypath_tags} WHERE rule_id = %d', $id); |
| 241 |
* @return array The meta tag rule information, or NULL if no rule with the |
* @return array The meta tag rule information, or NULL if no rule with the |
| 242 |
* given ID was found. |
* given ID was found. |
| 243 |
*/ |
*/ |
| 244 |
function _nodewords_bypath_load_instance($id) { |
function nodewords_bypath_rule_load($id) { |
| 245 |
$title = NULL; |
$rule = db_fetch_object(db_query('SELECT id, name, type, path_expr, weight |
|
|
|
|
$result = db_fetch_object(db_query('SELECT id, name, type, path_expr, weight |
|
| 246 |
FROM {nodewords_bypath_rules} WHERE id = %d', $id)); |
FROM {nodewords_bypath_rules} WHERE id = %d', $id)); |
| 247 |
|
|
| 248 |
if ($result AND (!empty($result->id))) { |
if ($rule AND (!empty($rule->id))) { |
| 249 |
$result->tags = _nodewords_bypath_get_tags_for($result->id); |
$rule->tags = _nodewords_bypath_tags_load($rule->id); |
| 250 |
|
return $rule; |
| 251 |
|
} |
| 252 |
|
else { |
| 253 |
|
return FALSE; |
| 254 |
} |
} |
|
|
|
|
return $result; |
|
| 255 |
} |
} |
| 256 |
|
|
| 257 |
|
|
| 260 |
* |
* |
| 261 |
* @return array The meta tag rule objects. |
* @return array The meta tag rule objects. |
| 262 |
*/ |
*/ |
| 263 |
function _nodewords_bypath_get_all() { |
function _nodewords_bypath_load_all() { |
| 264 |
$rules = array(); |
$rules = array(); |
| 265 |
$result = db_query('SELECT id, name, type, path_expr, weight |
$result = db_query('SELECT id, name, type, path_expr, weight |
| 266 |
FROM {nodewords_bypath_rules} ORDER BY weight, name ASC'); |
FROM {nodewords_bypath_rules} ORDER BY weight, name ASC'); |
| 267 |
|
|
| 268 |
// The tags aren't loaded here. They're loaded on demand when the path |
// The tags aren't loaded here. They're loaded on demand when the path |
| 269 |
// is matched. |
// is matched. |
| 270 |
while ($row = db_fetch_object($result)) { |
while ($rule = db_fetch_object($result)) { |
| 271 |
$rules[] = $row; |
$rules[] = $rule; |
| 272 |
} |
} |
| 273 |
|
|
| 274 |
return $rules; |
return $rules; |
| 282 |
* |
* |
| 283 |
* @return object The meta tag rule for the given path. |
* @return object The meta tag rule for the given path. |
| 284 |
*/ |
*/ |
| 285 |
function _nodewords_bypath_get_path_rule($path) { |
function _nodewords_bypath_path_rule_load($path) { |
| 286 |
$rules = _nodewords_bypath_get_all(); |
$rules = _nodewords_bypath_load_all(); |
| 287 |
|
|
| 288 |
foreach ($rules as $rule) { |
foreach ($rules as $rule) { |
| 289 |
//---------------------------------------------------------------------- |
//---------------------------------------------------------------------- |