| 1 |
<?php |
<?php |
| 2 |
// $Id: page_title.module,v 1.18.2.14 2009/06/17 14:24:39 njt1982 Exp $ |
// $Id: page_title.module,v 1.19 2009/08/15 22:05:04 njt1982 Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 13 |
|
|
| 14 |
|
|
| 15 |
/** |
/** |
| 16 |
* Implementation of hook_help(). |
* Implement hook_help(). |
| 17 |
*/ |
*/ |
| 18 |
function page_title_help($path, $arg) { |
function page_title_help($path, $arg) { |
| 19 |
$output = NULL; |
$output = NULL; |
| 38 |
|
|
| 39 |
|
|
| 40 |
/** |
/** |
| 41 |
* Implementation of hook_perm(). |
* Implement hook_perm(). |
| 42 |
*/ |
*/ |
| 43 |
function page_title_perm() { |
function page_title_perm() { |
| 44 |
return array('set page title', 'administer page titles'); |
return array('set page title', 'administer page titles'); |
| 46 |
|
|
| 47 |
|
|
| 48 |
/** |
/** |
| 49 |
* Implementation of hook_menu(). |
* Implement hook_menu(). |
| 50 |
*/ |
*/ |
| 51 |
function page_title_menu() { |
function page_title_menu() { |
| 52 |
$items = array(); |
$items = array(); |
| 58 |
'page arguments' => array('page_title_admin_settings'), |
'page arguments' => array('page_title_admin_settings'), |
| 59 |
'access arguments' => array('administer page titles'), |
'access arguments' => array('administer page titles'), |
| 60 |
'type' => MENU_LOCAL_TASK, |
'type' => MENU_LOCAL_TASK, |
| 61 |
|
'file' => 'page_title.admin.inc', |
| 62 |
); |
); |
| 63 |
|
|
| 64 |
return $items; |
return $items; |
| 66 |
|
|
| 67 |
|
|
| 68 |
/** |
/** |
| 69 |
* Implementation of hook_theme(). |
* Implement hook_theme(). |
| 70 |
*/ |
*/ |
| 71 |
function page_title_theme() { |
function page_title_theme() { |
| 72 |
return array( |
return array( |
| 73 |
'page_title_admin_settings' => array( |
'page_title_admin_settings' => array( |
| 74 |
'arguments' => array('form' => NULL), |
'render element' => 'form', |
| 75 |
|
'file' => 'page_title.admin.inc', |
| 76 |
), |
), |
| 77 |
|
|
| 78 |
'page_title_preprocess_page' => array( |
'page_title_preprocess_html' => array( |
| 79 |
'arguments' => array('vars' => NULL), |
'arguments' => array('vars' => NULL), |
| 80 |
), |
), |
| 81 |
); |
); |
| 83 |
|
|
| 84 |
|
|
| 85 |
/** |
/** |
| 86 |
* Implementation of hook_node_type(). |
* Implement hook_node_type(). |
| 87 |
* |
* |
| 88 |
* Updates settings after a node type change. |
* Updates settings after a node type change. |
| 89 |
*/ |
*/ |
| 119 |
|
|
| 120 |
|
|
| 121 |
/** |
/** |
| 122 |
* Implementation of hook_form_alter(). |
* Implement hook_form_alter(). |
| 123 |
*/ |
*/ |
| 124 |
function page_title_form_alter(&$form, $form_state, $form_id) { |
function page_title_form_alter(&$form, $form_state, $form_id) { |
| 125 |
// If we dont have permission to set the title then we need to abort this alter now! |
// If we dont have permission to set the title then we need to abort this alter now! |
| 137 |
'#collapsed' => empty($page_title), |
'#collapsed' => empty($page_title), |
| 138 |
'#group' => 'additional_settings', |
'#group' => 'additional_settings', |
| 139 |
'#weight' => 35, |
'#weight' => 35, |
| 140 |
'#attached_js' => array(drupal_get_path('module', 'page_title') . '/page_title.js'), |
'#attached' => array( |
| 141 |
|
'js' => array(drupal_get_path('module', 'page_title') . '/page_title.js'), |
| 142 |
|
), |
| 143 |
); |
); |
| 144 |
$form['page_title']['page_title'] = array( |
$form['page_title']['page_title'] = array( |
| 145 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 225 |
|
|
| 226 |
|
|
| 227 |
/** |
/** |
| 228 |
* Implementation of hook_node_load(). |
* Implement hook_node_load(). |
| 229 |
*/ |
*/ |
| 230 |
function page_title_node_load($nodes) { |
function page_title_node_load($nodes) { |
| 231 |
foreach ($nodes as $node) { |
foreach ($nodes as $node) { |
| 237 |
|
|
| 238 |
|
|
| 239 |
/** |
/** |
| 240 |
* Implementation of hook_node_insert(). |
* Implement hook_node_insert(). |
| 241 |
*/ |
*/ |
| 242 |
function page_title_node_insert($node) { |
function page_title_node_insert($node) { |
| 243 |
if (user_access('set page title') && isset($node->page_title) && drupal_strlen(trim($node->page_title)) > 0) { |
if (user_access('set page title') && isset($node->page_title) && drupal_strlen(trim($node->page_title)) > 0) { |
| 247 |
|
|
| 248 |
|
|
| 249 |
/** |
/** |
| 250 |
* Implementation of hook_node_update(). |
* Implement hook_node_update(). |
| 251 |
*/ |
*/ |
| 252 |
function page_title_node_update($node) { |
function page_title_node_update($node) { |
| 253 |
if (user_access('set page title') && isset($node->page_title) && drupal_strlen(trim($node->page_title)) > 0) { |
if (user_access('set page title') && isset($node->page_title) && drupal_strlen(trim($node->page_title)) > 0) { |
| 257 |
|
|
| 258 |
|
|
| 259 |
/** |
/** |
| 260 |
* Implementation of hook_node_delete(). |
* Implement hook_node_delete(). |
| 261 |
*/ |
*/ |
| 262 |
function page_title_node_delete($node) { |
function page_title_node_delete($node) { |
| 263 |
db_delete('page_title')->condition('type', 'node')->condition('id', $node->nid)->execute(); |
db_delete('page_title')->condition('type', 'node')->condition('id', $node->nid)->execute(); |
| 265 |
|
|
| 266 |
|
|
| 267 |
/** |
/** |
| 268 |
* Implementation of hook_taxonomy_term_update(). |
* Implement hook_taxonomy_term_update(). |
| 269 |
*/ |
*/ |
| 270 |
function page_title_taxonomy_term_update($term) { |
function page_title_taxonomy_term_update($term) { |
| 271 |
if (user_access('set page title')) { |
if (user_access('set page title')) { |
| 280 |
|
|
| 281 |
|
|
| 282 |
/** |
/** |
| 283 |
* Implementation of hook_taxonomy_term_delete(). |
* Implement hook_taxonomy_term_delete(). |
| 284 |
*/ |
*/ |
| 285 |
function page_title_taxonomy_term_delete($term) { |
function page_title_taxonomy_term_delete($term) { |
| 286 |
db_delete('page_title')->condition('type', 'term')->condition('id', $term->tid)->execute(); |
db_delete('page_title')->condition('type', 'term')->condition('id', $term->tid)->execute(); |
| 288 |
|
|
| 289 |
|
|
| 290 |
/** |
/** |
| 291 |
* Implementation of hook_taxonomy_term_insert(). |
* Implement hook_taxonomy_term_insert(). |
| 292 |
*/ |
*/ |
| 293 |
function page_title_taxonomy_term_insert($term) { |
function page_title_taxonomy_term_insert($term) { |
| 294 |
if (user_access('set page title') && isset($term->page_title) && drupal_strlen(trim($term->page_title)) > 0) { |
if (user_access('set page title') && isset($term->page_title) && drupal_strlen(trim($term->page_title)) > 0) { |
| 298 |
|
|
| 299 |
|
|
| 300 |
/** |
/** |
| 301 |
* Implementation of hook_user(). |
* Implement hook_user_insert(). |
| 302 |
*/ |
*/ |
|
/* |
|
|
function page_title_user($op, &$edit, &$account) { |
|
|
dpm(func_get_args()); |
|
|
switch ($op) { |
|
|
case 'update': |
|
|
if (user_access('set page title')) { |
|
|
db_delete('page_title')->condition('type', 'user')->condition('id', $account->uid)->execute(); |
|
|
} |
|
|
// Fallthrough to insert is intentional! |
|
|
case 'insert': |
|
|
if (isset($edit['page_title']) && drupal_strlen(trim($edit['page_title'])) > 0 && user_access('set page title')) { |
|
|
db_insert('page_title')->fields(array('type' => 'user', 'id' => $account->uid, 'page_title' => $edit['page_title']))->execute(); |
|
|
} |
|
|
break; |
|
|
} |
|
|
} |
|
|
*/ |
|
|
|
|
|
|
|
| 303 |
function page_title_user_insert(&$edit, &$account, $category) { |
function page_title_user_insert(&$edit, &$account, $category) { |
| 304 |
if (user_access('set page title') && isset($edit['page_title']) && drupal_strlen(trim($edit['page_title'])) > 0) { |
if (user_access('set page title') && isset($edit['page_title']) && drupal_strlen(trim($edit['page_title'])) > 0) { |
| 305 |
db_insert('page_title')->fields(array('type' => 'user', 'id' => $account->uid, 'page_title' => $edit['page_title']))->execute(); |
db_insert('page_title')->fields(array('type' => 'user', 'id' => $account->uid, 'page_title' => $edit['page_title']))->execute(); |
| 307 |
} |
} |
| 308 |
|
|
| 309 |
|
|
| 310 |
|
/** |
| 311 |
|
* Implement hook_user_update(). |
| 312 |
|
*/ |
| 313 |
function page_title_user_update(&$edit, &$account, $category) { |
function page_title_user_update(&$edit, &$account, $category) { |
| 314 |
if (user_access('set page title')) { |
if (user_access('set page title')) { |
| 315 |
if (isset($edit['page_title']) && drupal_strlen(trim($edit['page_title'])) > 0) { |
if (isset($edit['page_title']) && drupal_strlen(trim($edit['page_title'])) > 0) { |
| 323 |
|
|
| 324 |
|
|
| 325 |
/** |
/** |
| 326 |
* Implementation of hook_user_cancel(). |
* Implement hook_user_cancel(). |
| 327 |
*/ |
*/ |
| 328 |
function page_title_user_cancel(&$edit, &$account, $method) { |
function page_title_user_cancel(&$edit, &$account, $method) { |
| 329 |
switch ($method) { |
switch ($method) { |
| 336 |
} |
} |
| 337 |
|
|
| 338 |
|
|
|
|
|
|
|
|
| 339 |
/** |
/** |
| 340 |
* Simple wrapper function to get the currently set title for a page |
* Simple wrapper function to get the currently set title for a page |
| 341 |
* |
* |
| 424 |
/** |
/** |
| 425 |
* Determines what title should be sent to the page template. |
* Determines what title should be sent to the page template. |
| 426 |
* |
* |
| 427 |
* This function gets called from the implementation of hook_page_preprocess |
* This function gets called from the implementation of hook_preprocess_html |
| 428 |
* |
* |
| 429 |
* @return |
* @return |
| 430 |
* string The page's title. |
* string The page's title. |
| 494 |
|
|
| 495 |
|
|
| 496 |
/** |
/** |
| 497 |
* Implementation of hook_token_values(). |
* Implement hook_token_values(). |
| 498 |
* |
* |
| 499 |
* @param |
* @param |
| 500 |
* string The type of token being generated |
* string The type of token being generated |
| 513 |
|
|
| 514 |
|
|
| 515 |
/** |
/** |
| 516 |
* Implementation of hook_token_info(). |
* Implement hook_token_info(). |
| 517 |
*/ |
*/ |
| 518 |
function page_title_token_info() { |
function page_title_token_info() { |
| 519 |
$result = array(); |
$result = array(); |
| 528 |
|
|
| 529 |
|
|
| 530 |
/** |
/** |
| 531 |
* Implementation of hook_preprocess_page(). |
* Implement hook_preprocess_html(). |
| 532 |
*/ |
*/ |
| 533 |
function page_title_preprocess_page(&$vars) { |
function page_title_preprocess_html(&$vars) { |
| 534 |
$vars['head_title'] = page_title_page_get_title(); |
$vars['head_title'] = page_title_page_get_title(); |
| 535 |
} |
} |
|
|
|
|
|
|
|
/** |
|
|
* Implementation of hook_content_extra_fields(). |
|
|
* |
|
|
* This allows CCK to control the weight of the Page Title element as a "non-cck field" |
|
|
*/ |
|
|
function page_title_content_extra_fields($type_name) { |
|
|
$extra = array(); |
|
|
|
|
|
if (variable_get('page_title_type_'. $type_name .'_showfield', 0)) { |
|
|
$extra['page_title'] = array( |
|
|
'label' => t('Page Title'), |
|
|
'description' => t('Page Title form.'), |
|
|
'weight' => -4 |
|
|
); |
|
|
} |
|
|
|
|
|
return $extra; |
|
|
} |
|