--- /home/sugree/cvs/contrib/contributions/modules/nodewords/nodewords.module 2005-11-04 23:59:58.000000000 +0700
+++ nodewords.module 2006-02-21 21:52:37.000000000 +0700
@@ -63,26 +63,29 @@
}
switch ($op) {
+ case 'load':
+ $output['nodewords'] = _nodewords_load('node', $node->nid);
+ break;
+
case 'delete':
_nodewords_delete('node', $node->nid);
break;
case 'insert':
case 'update':
+ $node->nodewords['abstract'] = $node->nodewords_abstract;
+ $node->nodewords['copyright'] = $node->nodewords_copyright;
+ $node->nodewords['description'] = $node->nodewords_description;
+ $node->nodewords['keywords'] = $node->nodewords_keywords;
_nodewords_set('node', $node->nid, $node->nodewords);
break;
case 'update index':
$output = '
' . $node->nodewords['keywords'] . '
';
$output .= '' . $node->nodewords['description'] . '
';
- return $output;
-
- case 'form post':
- if (!isset($node->nodewords)) {
- $node->nodewords = _nodewords_load('node', $node->nid);
- }
- return _nodewords_form('node', $node->nodewords);
+ break;
}
+ return $output;
}
/**
@@ -93,53 +96,125 @@
}
/**
+ * Displays meta table
+ *
+ * @param $form
+ * Current form
+ * No need to 'check_plain' on content.
+ * @return
+ * Formatted HTML.
+ */
+function theme_meta_tags_table(&$form) {
+ $header = array(t('Meta tags'), t('Edit'), t('Head'));
+ foreach (_nodewords_get_possible_tags() as $name) {
+ $row = array();
+ $row[] = form_render($form['tag']['tag'.$name]);
+ $row[] = form_render($form['edit']['edit'.$name]);
+ $row[] = form_render($form['head']['head'.$name]);
+ $rows[] = $row;
+ }
+ $output = theme('table', $header, $rows);
+ return $output;
+}
+
+/**
* Implementation of hook_settings()
*/
function nodewords_settings() {
$settings = _nodewords_get_settings();
- $output = '';
-
- $form = form_textfield(t('Global copyright'), 'nodewords][global][copyright', $settings['global']['copyright'], 60, $settings['max_size'], t('This copyright text will be used if you do not set it for a specific page.'));
- $output .= form_group(t('Copyright'), $form);
-
- $form = form_checkbox(t('Use teaser if description is empty.'), 'nodewords][use_teaser', '1', $settings['use_teaser']);
- $output .= form_group(t('Description'), $form);
-
- $form = form_textfield(t('Global keywords'), 'nodewords][global][keywords', $settings['global']['keywords'], 60, $settings['max_size'], t('These keywords will be appended to all pages HTML meta keywords. Use commas to separate the words.'));
+ $form['global'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Copyright'),
+ );
+ $form['global']['copyright'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Global copyright'),
+ '#default_value' => $settings['global']['copyright'],
+ '#size' => 60,
+ '#maxlength' => $settings['max_size'],
+ '#description' => t('This copyright text will be used if you do not set it for a specific page.'),
+ );
+
+ $form['description'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Description'),
+ );
+ $form['description']['use_teaser'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Use teaser if description is empty.'),
+ '#return_value' => '1',
+ '#default_value' => $settings['use_teaser'],
+ );
+
+ $form['global']['keywords'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Global keywords'),
+ '#default_value' => $settings['global']['keywords'],
+ '#size' => 60,
+ '#maxlength' => $settings['max_size'],
+ '#description' => t('These keywords will be appended to all pages HTML meta keywords. Use commas to separate the words.'),
+ );
if (function_exists('taxonomy_get_vocabularies')) {
$select = array();
foreach (taxonomy_get_vocabularies() as $vocabulary) {
$select[$vocabulary->vid] = check_plain($vocabulary->name);
}
if (count($select) > 0) {
- $form .= form_select(t('Auto-keywords vocabularies'), 'nodewords][keywords_vids', $settings['keywords_vids'], $select, t('Select the vocabularies which contain terms you want to add to the keywords meta tag for nodes.'), '', TRUE, FALSE);
+ $form['global']['keywords_vids'] = array(
+ '#type' => 'select',
+ '#title' => t('Auto-keywords vocabularies'),
+ '#default_value' => $settings['keywords_vids'],
+ '#options' => $select,
+ '#description' => t('Select the vocabularies which contain terms you want to add to the keywords meta tag for nodes.'),
+ '#extra' => '',
+ '#multiple' => TRUE,
+ '#required' => FALSE,
+ );
}
}
- $output .= form_group(t('Keywords'), $form);
- $header = array(t('Meta tag'), t('Edit'), t('Head'));
- $rows = array();
+ $form['output'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Output options'),
+ '#description' => t('Check the meta tags you would like to output on each page. Check the boxes in the "Edit" column if you want the edit boxes for the meta tags to appear on the node edit forms. Check the boxes in the "Head" column if you want to output these meta tags on each page.'),
+ );
+ $header = array('edit', 'head');
+ $form['output']['#theme'] = 'meta_tags_table';
foreach (_nodewords_get_possible_tags() as $name) {
- $row = array();
- $row[] = ucfirst($name);
- foreach (array_map(strtolower, array_slice($header, 1)) as $where) {
- $row[] = form_checkbox('', "nodewords][$where][$name", '1', $settings[$where][$name]);
+ $form['output']['tag']['tag'.$name] = array(
+ '#type' => 'markup',
+ '#value' => t($name),
+ );
+ foreach ($header as $where) {
+ $form['output'][$where][$where.$name] = array(
+ '#type' => 'checkbox',
+ '#return_value' => '1',
+ '#default_value' => $settings[$where][$name],
+ );
}
- $rows[] = $row;
}
- $form = theme('table', $header, $rows);
- $output .= form_group(t('Output options'), $form, t('Check the meta tags you would like to output on each page. Check the boxes in the "Edit" column if you want the edit boxes for the meta tags to appear on the node edit forms. Check the boxes in the "Head" column if you want to output these meta tags on each page.'));
- $output .= form_textfield(t('Text length'), 'nodewords][max_size', $settings['max_size'], 6, 6, t('The maximum number of characters the content of a meta tag can contain.'));
+ $form['text'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Text options'),
+ );
+ $form['text']['max_size'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Text length'),
+ '#default_value' => $settings['max_size'],
+ '#size' => 6,
+ '#maxlength' => 6,
+ '#description' => t('The maximum number of characters the content of a meta tag can contain.'),
+ );
- return $output;
+ return $form;
}
/**
* Implementation of hook_taxonomy().
*/
-function nodewords_taxonomy($op, $type, $object) {
+function nodewords_taxonomy($op, $type, $object = NULL) {
if ($type == 'term') {
$id = $object['tid'];
}
@@ -161,14 +236,6 @@
_nodewords_set($type, $id, $object['nodewords']);
}
break;
-
- case 'form post':
- if (user_access('administer meta tags')) {
- $tags = _nodewords_load($type, $id);
- $output = _nodewords_form($type, $tags);
- return $output;
- }
- break;
}
}
@@ -317,35 +384,68 @@
/*
* Create a form
*/
-function _nodewords_form($type, $tags) {
- $settings = _nodewords_get_settings();
-
- if ($settings['edit']['abstract']) {
- $form .= form_textfield(t('Abstract'), 'nodewords][abstract', $tags['abstract'], 60, $settings['max_size'], t('Enter a short abstract for this node. Typically it is one sentence.'));
- }
-
- if ($settings['edit']['copyright']) {
- $form .= form_textfield(t('Copyright'), 'nodewords][copyright', $tags['copyright'], 60, $settings['max_size'], t('Enter a short copyright statement for this node.'));
- }
-
- if ($settings['edit']['description']) {
- $form .= form_textarea(t('Description'), 'nodewords][description', $tags['description'], 60, 6, t('Enter a description for this node. 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.') : ''));
- }
-
- if ($settings['edit']['keywords'] && $type != 'term' && $type != 'vocabulary') {
- $form .= form_textfield(t('Keywords'), 'nodewords][keywords', $tags['keywords'], 60, $settings['max_size'], t('Enter a comma seperated list of keywords for this page. Avoid duplication of words as this will lower your search engine ranking.'));
- }
-
- if ($form) {
- if (function_exists('form_group_collapsible')) {
- $form = form_group_collapsible(t('Meta tags'), $form, TRUE);
+function nodewords_form_alter($form_id, &$form) {
+ if (user_access('administer meta tags') && isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
+ $node = $form['#node'];
+ $tags = _nodewords_load('node', $node->nid);
+ $settings = _nodewords_get_settings();
+
+ $form['nodewords'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Meta tags'),
+ '#collapsible' => TRUE,
+ '#collapsed' => empty($tags['abstract']) && empty($tags['copyright']) && empty($tags['description']) && empty($tags['keywords']),
+ '#weight' => 35,
+ );
+
+ if ($settings['edit']['abstract']) {
+ $form['nodewords']['nodewords_abstract'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Abstract'),
+ '#default_value' => $tags['abstract'],
+ '#size' => 60,
+ '#maxlength' => $settings['max_size'],
+ '#description' => t('Enter a short abstract for this node. Typically it is one sentence.'),
+ );
+ }
+
+ if ($settings['edit']['copyright']) {
+ $form['nodewords']['nodewords_copyright'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Copyright'),
+ '#default_value' => $tags['copyright'],
+ '#size' => 60,
+ '#maxlength' => $settings['max_size'],
+ '#description' => t('Enter a short copyright statement for this node.'),
+ );
+ }
+
+ if ($settings['edit']['description']) {
+ $form['nodewords']['nodewords_description'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Description'),
+ '#default_value' => $tags['description'],
+ '#cols' => 60,
+ '#rows' => 6,
+ '#description' => t('Enter a description for this node. 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.') : ''),
+ );
+ }
+
+ if ($settings['edit']['keywords'] && $type != 'term' && $type != 'vocabulary') {
+ $form['nodewords']['nodewords_keywords'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Keywords'),
+ '#default_value' => $tags['keywords'],
+ '#size' => 60,
+ '#maxlength' => $settings['max_size'],
+ '#description' => t('Enter a comma seperated list of keywords for this page. Avoid duplication of words as this will lower your search engine ranking.'),
+ );
}
- else {
- $form = form_group(t('Meta tags'), $form);
+
+ if (count($form['nodewords']) == 0) {
+ unset($form['nodewords']);
}
}
-
- return $form;
}
/************************************************************
@@ -376,16 +476,19 @@
}
if ($settings == NULL) {
- $settings = variable_get('nodewords', array());
-
- foreach ($default_settings as $key => $value) {
- if (is_array($value)) {
- $settings[$key] = isset($settings[$key]) ? array_merge($value, $settings[$key]) : $value;
- }
- else if (!isset($settings[$key])) {
- $settings[$key] = $value;
- }
- }
+ $settings = array('use_teaser' => variable_get('use_teaser',1),
+ 'max_size' => variable_get('max_size',255),
+ 'keywords_vids' => variable_get('keywords_vids',array()),
+ 'global' => array('copyright' => variable_get('copyright',''),
+ 'keywords' => variable_get('keywords','')),
+ 'head' => array('abstract' => variable_get('headabstract',1),
+ 'copyright' => variable_get('headcopyright',1),
+ 'description' => variable_get('headdescription',1),
+ 'keywords' => variable_get('headkeywords',1)),
+ 'edit' => array('abstract' => variable_get('editabstract',0),
+ 'copyright' => variable_get('editcopyright',0),
+ 'description' => variable_get('editdescription',1),
+ 'keywords' => variable_get('editkeywords',1)));
}
return $settings;