| 1 |
<?php
|
| 2 |
/* $Id: nodewords_nodetype.module,v 1.1.2.5 2008/09/15 15:06:45 hanoii Exp $ */
|
| 3 |
|
| 4 |
function nodewords_nodetype_form_alter($form_id, &$form) {
|
| 5 |
if ($form_id == 'node_type_form' && isset($form['#node_type'])) {
|
| 6 |
$settings = _nodewords_get_settings();
|
| 7 |
$form['nodewords_nodetype'] = array(
|
| 8 |
'#type' => 'fieldset',
|
| 9 |
'#title' => t('Meta tags node type'),
|
| 10 |
'#collapsible' => TRUE,
|
| 11 |
'#collapsed' => FALSE,
|
| 12 |
);
|
| 13 |
|
| 14 |
$form['nodewords_nodetype']['nodewords_nodetype_keywords'] = array(
|
| 15 |
'#type' => 'textfield',
|
| 16 |
'#title' => t('Default "keywords" meta tag'),
|
| 17 |
'#default_value' => variable_get('nodewords_nodetype_keywords_'. $form['#node_type']->type, ''),
|
| 18 |
'#size' => 60,
|
| 19 |
'#maxlength' => $settings['max_size'],
|
| 20 |
'#description' => t('This keywords will be appended after the global keywords and before the page kewords. Enter a comma separated list of keywords for this page. Avoid duplication of words as this will lower your search engine ranking.'),
|
| 21 |
);
|
| 22 |
|
| 23 |
$form['nodewords_nodetype']['description'] = array(
|
| 24 |
'#type' => 'fieldset',
|
| 25 |
'#title' => t('Description'),
|
| 26 |
'#collapsible' => TRUE,
|
| 27 |
);
|
| 28 |
|
| 29 |
$form['nodewords_nodetype']['description']['nodewords_nodetype_description'] = array(
|
| 30 |
'#type' => 'textarea',
|
| 31 |
'#title' => t('Default "description" meta tag'),
|
| 32 |
'#default_value' => variable_get('nodewords_nodetype_description_'. $form['#node_type']->type, ''),
|
| 33 |
'#description' => t('Enter a global meta tag description for this content type. Limit your description to about 20 words, with a maximum of %count characters. It should not contain any HTML tags or other formatting. ' , array('%count' => $settings['max_size'])) . ($settings['use_teaser'] ? ' ' . t('When you leave this field empty, the teaser will be used as description.') : '') . t('Tokens are allowed, data will be shortened to the max and unallowed tags or caracters will be removed.'),
|
| 34 |
);
|
| 35 |
|
| 36 |
$form['nodewords_nodetype']['nodewords_nodetype_token'] = array(
|
| 37 |
'#type' => 'fieldset',
|
| 38 |
'#title' => t('Token replacements'),
|
| 39 |
'#collapsible' => TRUE,
|
| 40 |
'#collapsed' => TRUE,
|
| 41 |
);
|
| 42 |
$form['nodewords_nodetype']['nodewords_nodetype_token']['help'] = array(
|
| 43 |
'#type' => 'markup',
|
| 44 |
'#value' => theme('token_help'),
|
| 45 |
);
|
| 46 |
|
| 47 |
$form['nodewords_nodetype']['description']['advanced'] = array(
|
| 48 |
'#type' => 'fieldset',
|
| 49 |
'#title' => t('Advanced PHP replacement'),
|
| 50 |
'#collapsible' => TRUE,
|
| 51 |
'#collapsed' => TRUE,
|
| 52 |
);
|
| 53 |
$form['nodewords_nodetype']['description']['advanced']['nodewords_nodetype_desc_php'] = array(
|
| 54 |
'#type' => 'textarea',
|
| 55 |
'#title' => t('PHP replacement'),
|
| 56 |
'#default_value' => variable_get('nodewords_nodetype_desc_php_'. $form['#node_type']->type, ''),
|
| 57 |
'#description' => t('Code must be included within %php_tags tags. You can add any php code here to perform a particular replacement on the description meta tag information after token substitution. %description and %php_description are available to be used within this code. %title is the actual description meta tags defined above with any token replacement. Be careful if the title has single or double quotes in it. %php_description is replaced with a PHP code that defines a $description variable that you can use along your eval code with the replaced string (quotes are not a problem here). A good starting poing would be: <code>%code</code>.', array('%php_tags' => '<?php ?>', '%code' => '<?php %php_description return $description; ?>')),
|
| 58 |
);
|
| 59 |
}
|
| 60 |
}
|
| 61 |
|
| 62 |
/**
|
| 63 |
* Implementation of hook_nodewords().
|
| 64 |
*/
|
| 65 |
function nodewords_nodetype_nodewords(&$tags, $op, $type, $ids) {
|
| 66 |
switch ($op) {
|
| 67 |
case 'prepare':
|
| 68 |
if ( $type == 'node' && (!isset($tags['description']) || empty($tags['description'])) && count($ids) == 1) {
|
| 69 |
$meta_description = '';
|
| 70 |
$node = node_load($ids[0]);
|
| 71 |
// description field
|
| 72 |
if ( ( $description = variable_get('nodewords_nodetype_description_'. $node->type, '') ) !== '' ) {
|
| 73 |
$meta_description = token_replace($description, 'node', $node);
|
| 74 |
}
|
| 75 |
// description php field
|
| 76 |
if ( ( $description_php = variable_get('nodewords_nodetype_desc_php_'. $node->type, '') ) !== '' ) {
|
| 77 |
$description_php = token_replace($description_php, 'node', $node);
|
| 78 |
$variables['%description'] = $meta_description;
|
| 79 |
$variables['%php_description'] = '$description = \'' . str_replace('\'', '\\\'', $meta_description) . '\';';
|
| 80 |
$meta_description = drupal_eval(strtr($description_php, $variables));
|
| 81 |
}
|
| 82 |
|
| 83 |
if ( $meta_description != '' ) {
|
| 84 |
$tags['description']= _nodewords_check_content(html_entity_decode($meta_description, ENT_COMPAT, 'UTF-8'));
|
| 85 |
}
|
| 86 |
|
| 87 |
if ( ( $keywords = variable_get('nodewords_nodetype_keywords_'. $node->type, '') ) !== '' ) {
|
| 88 |
$tags['keywords'] = _nodewords_check_content(token_replace($keywords, 'node', $node));
|
| 89 |
}
|
| 90 |
}
|
| 91 |
|
| 92 |
break;
|
| 93 |
}
|
| 94 |
}
|