t('Meta tags'), 'description' => t('Meta tags fieldset.'), 'weight' => 10, ); return $extras; } /** * Implements hook_form_alter(). */ function nodewords_form_alter(&$form, &$form_state, $form_id) { $bool = ( isset($form['type']) && isset($form['#node']) && $form_id == $form['type']['#value'] . '_node_form' && variable_get('nodewords_edit_metatags_' . $form['type']['#value'], TRUE) ); if ($bool) { $node = $form['#node']; $form['nodewords'] = nodewords_form( NODEWORDS_TYPE_NODE, !empty($node->nodewords) ? $node->nodewords : array(), array( 'tag_options' => array('node_type' => $form['type']['#value']), ) ); } } /** * Implements hook_form_FORM_ID_alter(). */ function nodewords_form_node_type_form_alter(&$form, &$form_state) { if (isset($form['#node_type'])) { $form['nodewords'] = array( '#type' => 'fieldset', '#title' => t('Meta tags settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#group' => 'additional_settings', ); $form['nodewords']['nodewords_edit_metatags'] = array( '#type' => 'checkbox', '#title' => t('Allow editing of meta tags'), '#description' => t('If selected, the node edit form will allow the users with the right permissions to edit the meta tags associated with nodes of this content type.'), '#default_value' => variable_get('nodewords_edit_metatags_' . $form['#node_type']->type, TRUE), ); $form['nodewords']['metatags_generation'] = array( '#type' => 'fieldset', '#title' => t('Node meta tags generation options'), '#description' => t('These options change how a meta tag content is generated from the node content. These settings apply to specific meta tags.'), '#collapsible' => TRUE, ); $options = array( NODEWORDS_GENERATION_NEVER => t('Do not generate meta tags content'), NODEWORDS_GENERATION_WHEN_EMPTY => t('Generate meta tag content when the meta tag content is empty (default)'), NODEWORDS_GENERATION_ALWAYS => t('Always generate the meta tag content'), ); $form['nodewords']['metatags_generation']['nodewords_metatags_generation_method'] = array( '#type' => 'radios', '#options' => $options, '#default_value' => variable_get( 'nodewords_metatags_generation_method_' . $form['#node_type']->type, NODEWORDS_GENERATION_WHEN_EMPTY ), ); $options = array( NODEWORDS_GENERATION_BODY => t('Generate meta tags content from the node body'), NODEWORDS_GENERATION_TEASER => t('Generate meta tags content from the node teaser (default)'), NODEWORDS_GENERATION_TEASER_BODY => t('Generate meta tags content from the node teaser, or the node body when the node teaser is empty'), ); $form['nodewords']['metatags_generation']['nodewords_metatags_generation_source'] = array( '#type' => 'radios', '#title' => t('Generation source'), '#options' => $options, '#default_value' => variable_get( 'nodewords_metatags_generation_source_' . $form['#node_type']->type, NODEWORDS_GENERATION_TEASER ), ); $form['nodewords']['metatags_generation']['nodewords_use_alt_attribute'] = array( '#type' => 'checkbox', '#title' => t('Replace the tag IMG content with the attribute ALT'), '#default_value' => variable_get( 'nodewords_use_alt_attribute_' . $form['#node_type']->type, TRUE ), ); $options = array( 'imagebrowser' => 'imagebrowser.module', 'img_assist' => 'img_assist.module', ); $form['nodewords']['metatags_generation']['nodewords_filter_modules_output'] = array( '#type' => 'checkboxes', '#title' => t('Filter the text added by third-party modules in the node teaser'), '#options' => $options, '#default_value' => variable_get( 'nodewords_filter_modules_output_' . $form['#node_type']->type, array() ), '#checkall' => TRUE, ); $form['nodewords']['metatags_generation']['nodewords_filter_regexp'] = array( '#type' => 'textfield', '#title' => t('Custom regular expression'), '#description' => t('A regular expression used to filter the text added in the node teaser from a third-party module. The regular expression uses the Perl compatible syntax. Slashes are assumed as delimiters and all expressions are case-sensitive.'), '#element_validate' => array('nodewords_filter_regex_validate'), '#default_value' => variable_get( 'nodewords_filter_regexp_' . $form['#node_type']->type, '' ), '#field_prefix' => '/', '#field_suffix' => '/', '#size' => 60, ); foreach (nodewords_get_possible_tags() as $name => $info) { $function = $info['callback'] . '_settings_form'; $options = array(); if (function_exists($function)) { $function($form, 'node_type_form', $options); } } } } /** * Implements hook_form_FORM_ID_alter(). */ function nodewords_form_taxonomy_form_term_alter(&$form, &$form_state) { $bool = (isset($form['tid']['#value']) && !isset($form_state['confirm_delete']) && !isset($form_state['confirm_parents']) ); if ($bool) { $id = $form['tid']['#value']; if (!empty($form_state['values']['nodewords'])) { $tags = $form_state['values']['nodewords']; } elseif (isset($id) && is_numeric($id)) { $tags = nodewords_load_tags(NODEWORDS_TYPE_TERM, $id); } else { $tags = array(); } $form['nodewords'] = nodewords_form( NODEWORDS_TYPE_TERM, $tags ); // Ensure the submit & delete buttons are at the bottom. Hopefully. $form['submit']['#weight'] = 1000; $form['delete']['#weight'] = 1001; } } /** * Implements hook_form_FORM_ID_alter(). */ function nodewords_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) { if (isset($form['vid']['#value'])) { $id = $form['vid']['#value']; if (!empty($form_state['values']['nodewords'])) { $tags = $form_state['values']['nodewords']; } elseif (isset($id) && is_numeric($id)) { $tags = nodewords_load_tags(NODEWORDS_TYPE_VOCABULARY, $id); } else { $tags = array(); } $form['nodewords'] = nodewords_form( NODEWORDS_TYPE_VOCABULARY, $tags ); // Ensure the submit & delete buttons are at the bottom. Hopefully. $form['submit']['#weight'] = 1000; $form['delete']['#weight'] = 1001; } } /** * Implemenation of hook_help(). */ function nodewords_help($path, $arg) { switch ($path) { case 'admin/content/nodewords/meta-tags': $output = '
' . t('On this page you can enter the default values for the meta tags of your site.') . '
'; break; case 'admin/content/nodewords/meta-tags/errorpage_403': $output = '' . t('On this page you can enter the meta tags for the access denied
error page of your site.') . '
' . t('On this page you can enter the meta tags for the page not found
error page of your site.') . '
' . t('On this page you can enter the meta tags for the front page of your site.') . '
'; break; case 'admin/content/nodewords/meta-tags/custom': $output = '' . t('On this page you can enter the meta tags for other pages of your site. The meta tags set in these page are used before the ones set for nodes or user profiles, and they can ovverride those meta tags.') . '
'; break; default: $output = ''; break; } return $output; } /** * Implements hook_menu(). */ function nodewords_menu() { $admin_access = array('administer meta tags'); $items = array(); $items['admin/content/nodewords'] = array( 'title' => 'Meta tags', 'page callback' => 'drupal_get_form', 'page arguments' => array('nodewords_settings_form'), 'description' => 'Configure HTML meta tags for all the content.', 'access arguments' => $admin_access, 'type' => MENU_NORMAL_ITEM, 'file' => 'nodewords.admin.inc', ); $items['admin/content/nodewords/settings'] = array( 'title' => 'Settings', 'access arguments' => $admin_access, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, 'file' => 'nodewords.admin.inc', ); $items['admin/content/nodewords/meta-tags'] = array( 'title' => 'Default and specific meta tags', 'page callback' => 'drupal_get_form', 'page arguments' => array('nodewords_tags_form'), 'access arguments' => $admin_access, 'type' => MENU_LOCAL_TASK, 'file' => 'nodewords.admin.inc', 'weight' => -9, ); $items['admin/content/nodewords/meta-tags/default'] = array( 'title' => 'Default values', 'access arguments' => $admin_access, 'type' => MENU_DEFAULT_LOCAL_TASK, 'file' => 'nodewords.admin.inc', 'weight' => -10, ); $items['admin/content/nodewords/meta-tags/frontpage'] = array( 'title' => 'Front page', 'page callback' => 'drupal_get_form', 'page arguments' => array('nodewords_tags_form', (string) NODEWORDS_TYPE_FRONTPAGE), 'access arguments' => $admin_access, 'type' => MENU_LOCAL_TASK, 'file' => 'nodewords.admin.inc', 'weight' => -9, ); $items['admin/content/nodewords/meta-tags/offline'] = array( 'title' => 'Site off-line page', 'page callback' => 'drupal_get_form', 'page arguments' => array('nodewords_tags_form', (string) NODEWORDS_TYPE_OFFLINE), 'access arguments' => $admin_access, 'type' => MENU_LOCAL_TASK, 'file' => 'nodewords.admin.inc', 'weight' => -8, ); $items['admin/content/nodewords/meta-tags/errorpage_403'] = array( 'title' => 'Error 403 page', 'page callback' => 'drupal_get_form', 'page arguments' => array('nodewords_tags_form', (string) NODEWORDS_TYPE_ERRORPAGE, '403'), 'access arguments' => $admin_access, 'type' => MENU_LOCAL_TASK, 'file' => 'nodewords.admin.inc', 'weight' => -7, ); $items['admin/content/nodewords/meta-tags/errorpage_404'] = array( 'title' => 'Error 404 page', 'page callback' => 'drupal_get_form', 'page arguments' => array('nodewords_tags_form', (string) NODEWORDS_TYPE_ERRORPAGE, '404'), 'access arguments' => $admin_access, 'type' => MENU_LOCAL_TASK, 'file' => 'nodewords.admin.inc', 'weight' => -6, ); // Only show the forum settings page if the core Blog module is enabled. if (module_exists('blog')) { $items['admin/content/nodewords/meta-tags/blog'] = array( 'title' => 'Blog main page', 'page callback' => 'drupal_get_form', 'page arguments' => array('nodewords_tags_form', (string) NODEWORDS_TYPE_BLOG), 'access arguments' => $admin_access, 'type' => MENU_LOCAL_TASK, 'file' => 'nodewords.admin.inc', 'weight' => -5, ); } // Only show the forum settings page if the core Forum module is enabled. if (module_exists('forum')) { $items['admin/content/nodewords/meta-tags/forum'] = array( 'title' => 'Forum main page', 'page callback' => 'drupal_get_form', 'page arguments' => array('nodewords_tags_form', (string) NODEWORDS_TYPE_FORUM), 'access arguments' => $admin_access, 'type' => MENU_LOCAL_TASK, 'file' => 'nodewords.admin.inc', 'weight' => -4, ); } $items['admin/content/nodewords/meta-tags/custom'] = array( 'title' => 'Custom pages', 'page callback' => 'drupal_get_form', 'page arguments' => array('nodewords_custom_pages_overview'), 'access arguments' => $admin_access, 'type' => MENU_LOCAL_TASK, 'weight' => 20, 'file' => 'nodewords.admin.inc', ); $items['admin/content/nodewords/meta-tags/custom/add'] = array( 'title' => 'Add custom pages meta tags', 'page callback' => 'drupal_get_form', 'page arguments' => array('nodewords_custom_pages_edit'), 'access arguments' => $admin_access, 'type' => MENU_CALLBACK, 'file' => 'nodewords.admin.inc', ); $items['admin/content/nodewords/meta-tags/custom/%nodewords_page/delete'] = array( 'title' => 'Delete custom pages meta tags', 'page callback' => 'drupal_get_form', 'page arguments' => array('nodewords_custom_pages_confirm_delete', 5), 'access arguments' => $admin_access, 'parent' => 'admin/content/nodewords/meta-tags/custom', 'type' => MENU_CALLBACK, 'file' => 'nodewords.admin.inc', ); $items['admin/content/nodewords/meta-tags/custom/%nodewords_page/edit'] = array( 'title' => 'Edit custom pages meta tags', 'page callback' => 'drupal_get_form', 'page arguments' => array('nodewords_custom_pages_edit', 5), 'access arguments' => $admin_access, 'parent' => 'admin/content/nodewords/meta-tags/custom', 'type' => MENU_CALLBACK, 'file' => 'nodewords.admin.inc', ); return $items; } /** * Implements hook_node_operations(). */ function nodewords_node_operations() { $operations = array( 'delete_metatags' => array( 'label' => t('Delete meta tags'), 'callback' => 'nodewords_mass_update', 'callback arguments' => array('type' => NODEWORDS_TYPE_NODE, 'operation' => 'delete'), ), ); return $operations; } /** * Implements hook_node_type(). */ function nodewords_node_type($op, $info) { if ($op == 'delete') { $variables = array( 'nodewords_metatags_generation_method_', 'nodewords_metatags_generation_source_', 'nodewords_edit_metatags_', 'nodewords_filter_modules_output_', 'nodewords_filter_regexp_', 'nodewords_use_alt_attr_', 'nodewords_use_teaser_', ); foreach ($variables as $variable) { variable_del($variable . $info->type); } } } /** * Implements hook_nodeapi(). */ function nodewords_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { switch ($op) { case 'delete': nodewords_delete_tags(NODEWORDS_TYPE_NODE, $node->nid); break; case 'insert': case 'update': if (isset($node->nodewords)) { nodewords_save_tags(NODEWORDS_TYPE_NODE, $node->nid, $node->nodewords, TRUE); } break; case 'load': return array( 'nodewords' => nodewords_load_tags(NODEWORDS_TYPE_NODE, $node->nid), ); case 'prepare translation': if (isset($node->translation_source->nodewords)) { $node->nodewords = $node->translation_source->nodewords; } break; case 'update index': $output_tags = array(); $tag_options = array( 'type' => NODEWORDS_TYPE_NODE, 'id' => $node->nid, 'output' => 'update index', ); if (isset($node->nodewords)) { // Prepare the tags. foreach (nodewords_get_possible_tags() as $name => $info) { $bool = ( !empty($info['templates']['search index']) && function_exists($function = $info['callback'] . '_prepare') ); if ($bool) { $function( $output_tags, isset($node->nodewords[$name]) ? $node->nodewords[$name] : array(), $tag_options ); } } drupal_alter('nodewords_tags', $output_tags, $tag_options); $output = _nodewords_output_tags($output_tags, 'update index'); drupal_alter('nodewords_tags_output', $output, $tag_options); return $output; } return ''; } } /** * Implements hook_perm(). */ function nodewords_perm() { return array('administer meta tags'); } /** * Implements hook_preprocess_page(). */ function nodewords_preprocess_page(&$variables) { // Do not do anything when running in install or update mode. if (defined('MAINTENANCE_MODE')) { return; } $options = _nodewords_detect_type_and_id(); $output_tags = array(); $options += array( 'default' => nodewords_load_tags(), 'output' => 'head', ); if ($options['type'] == NODEWORDS_TYPE_PAGER) { foreach (nodewords_get_possible_tags() as $name => $info) { $bool = ( !empty($info['context']['allowed']) && in_array(NODEWORDS_TYPE_PAGER, $info['context']['allowed']) && function_exists($function = $info['callback'] . '_prepare') ); if ($bool) { $function($output_tags, array(), $options); } } } else { // User profiles meta tags are not enabled. if ($options['type'] == NODEWORDS_TYPE_USER && !variable_get('nodewords_enable_user_metatags', TRUE)) { return; } // If the visitor doesn't have access to this node, don't load anything. elseif ($options['type'] == NODEWORDS_TYPE_NODE && !node_access('view', node_load($options['id']))) { $tags = array(); } // Otherwise, load the tags for this page. else { $tags = nodewords_load_tags($options['type'], $options['id']); } // Prepare the tags. foreach (nodewords_get_possible_tags() as $name => $info) { if (function_exists($function = $info['callback'] . '_prepare')) { $function($output_tags, isset($tags[$name]) ? $tags[$name] : array(), $options); } } } drupal_alter('nodewords_tags', $output_tags, $options); // Title tag has its own page preprocess variable and must be handled // separately. if (isset($output_tags['page_title'])) { if (!empty($output_tags['page_title'])) { drupal_set_title($output_tags['page_title']); $variables['head_title'] = strip_tags(drupal_get_title()); } unset($output_tags['page_title']); } $output = _nodewords_output_tags($output_tags); drupal_alter('nodewords_tags_output', $output, $options); // Output the tags to the header. drupal_set_html_head($output); $variables['head'] = drupal_get_html_head(); } /** * Implements hook_preprocess_maintenance_page(). */ function nodewords_preprocess_maintenance_page(&$variables) { nodewords_preprocess_page($variables); } /** * Implements hook_taxonomy(). */ function nodewords_taxonomy($op, $type, $array = NULL) { if (isset($array)) { if ($type == 'term') { $type = NODEWORDS_TYPE_TERM; $id = $array['tid']; } elseif ($type == 'vocabulary') { $type = NODEWORDS_TYPE_VOCABULARY; $id = $array['vid']; } else { return; } switch ($op) { case 'delete': nodewords_delete_tags($type, $id); break; case 'insert': case 'update': if (isset($array['nodewords'])) { nodewords_save_tags($type, $id, $array['nodewords'], TRUE); } break; } } } /** * Implements hook_theme(). */ function nodewords_theme() { return array( 'nodewords_custom_pages_overview' => array( 'arguments' => array('form' => array()), 'file' => 'nodewords.admin.inc', ), ); } /** * Implements hook_user(). */ function nodewords_user($op, &$edit, &$account, $category = NULL) { global $user; switch ($op) { case 'load': if (arg(0) == 'user' && !empty($account->uid) && variable_get('nodewords_enable_user_metatags', TRUE)) { $account->nodewords = nodewords_load_tags(NODEWORDS_TYPE_USER, $account->uid); } break; case 'delete': nodewords_delete_tags(NODEWORDS_TYPE_USER, $account->uid); break; case 'insert': case 'update': if (isset($edit['nodewords'])) { nodewords_save_tags(NODEWORDS_TYPE_USER, $account->uid, $edit['nodewords'], TRUE); } $edit['nodewords'] = NULL; break; case 'form': $bool = ( ( user_access('administer meta tags') || $user->uid == $account->uid ) && variable_get('nodewords_enable_user_metatags', TRUE) && $category == 'account' ); if ($bool) { $tags = nodewords_load_tags(NODEWORDS_TYPE_USER, $account->uid); $form['nodewords'] = nodewords_form( NODEWORDS_TYPE_USER, $tags ); return $form; } return array(); } } /** * Implements hook_user_operations(). */ function nodewords_user_operations() { $operations = array( 'delete_metatags' => array( 'label' => t('Delete meta tags'), 'callback' => 'nodewords_mass_update', 'callback arguments' => array('type' => NODEWORDS_TYPE_USER, 'operation' => 'delete'), ), ); return $operations; } /** * Delete tags from table. */ function nodewords_delete_tags($type, $id) { db_query("DELETE FROM {nodewords} WHERE type = %d AND id = %d", $type, $id); if ($type == NODEWORDS_TYPE_PAGE) { db_query("DELETE FROM {nodewords_custom} WHERE pid = %d", $id); } } /** * Return the form used to set the meta tags values. * * @param $type * The object to which the meta tags are associated (node, user, taxonomy * term, etc...). * @param $tags * The meta tags array as returned by nodewords_load_tags(). * * @return * An array as requested by the form API. */ function nodewords_form($type, $tags, $options = array()) { $default_options = array( 'fieldset' => TRUE, 'fieldset:title' => t('Meta tags'), 'fieldset:weight' => 20, ); $default_tag_options = array( 'default' => nodewords_load_tags(), 'type' => $type, ); $edit_tags = variable_get('nodewords_edit', array()); $form = array(); $options += $default_options; if (isset($options['tag_options']) && is_array($options['tag_options'])) { $tag_options = $options['tag_options'] + $default_tag_options; } else { $tag_options = $default_tag_options; } $tags_info = nodewords_get_possible_tags(); foreach ($tags_info as $name => $info) { $bool = ( ( user_access('administer meta tags') ) || !empty($edit_tags[$name]) ); if ($bool) { $bool = ( ( !empty($info['context']['allowed']) && is_array($info['context']['allowed']) && !in_array($type, $info['context']['allowed']) ) || ( !empty($info['context']['denied']) && is_array($info['context']['denied']) && in_array($type, $info['context']['denied']) ) ); if ($bool) { continue; } $bool = ( ( user_access('administer meta tags') ) || ( !empty($info['permission']) && user_access($info['permission']) ) ); if ($bool) { if (function_exists($function = $info['callback'] . '_form')) { $function($form, isset($tags[$name]) ? $tags[$name] : array(), $tag_options); } } } } if (!empty($form) && $options['fieldset']) { $form['#type'] = 'fieldset'; $form['#title'] = $options['fieldset:title']; $form['#tree'] = TRUE; $form['#collapsible'] = TRUE; $form['#collapsed'] = TRUE; $form['#weight'] = $options['fieldset:weight']; $form['#group'] = 'additional_settings'; } return $form; } /** * Query all the modules implementing meta tags and return the list of meta tags. * * @param $load * If TRUE, the file containing the code implementing the meta tags will be loaded. * * @return * An array containing the list of meta tags definitions. */ function nodewords_get_possible_tags($load = FALSE) { static $tags_info = array(); if ($load) { $tags_info = array(); } if (empty($tags_info)) { // Allow third-party modules to alter the meta tags list, or to add new // meta tags. foreach (module_implements('nodewords_tags_info') as $module) { if (module_hook($module, 'nodewords_api')) { $info = module_invoke($module, 'nodewords_api'); $version = '0.0'; if (isset($info)) { if (is_string($info)) { $version = $info; } elseif (is_array($info) && isset($info['version'])) { $version = $info['version']; if ($load && !empty($info['file'])) { $include_file = $info['file']; if (isset($info['path'])) { $include_file = $info['path'] . '/' . $include_file; } include_once $include_file; } } } $bool = ( version_compare($version, NODEWORDS_MINIMUM_API_VERSION, '<') || version_compare($version, NODEWORDS_API_VERSION, '>') ); if ($bool) { continue; } $result = module_invoke($module, 'nodewords_tags_info'); if (isset($result) && is_array($result)) { $tags_info = array_merge($tags_info, $result); } } } } return $tags_info; } /** * Return the term object matching a term ID. This is a modified version of * taxonomy_get_term() which uses db_rewrite_sql(). * * @param $tid * A term's ID. * @param $uid * The user ID; if not passed, the function will use the global user ID. * * @return * A term object, or FALSE. Results are statically cached. */ function nodewords_get_term($tid, $uid = NULL) { global $user; static $terms = array(); if (!isset($uid)) { $uid = $user->uid; } if (!isset($terms[$uid][$tid])) { $terms[$uid][$tid] = db_fetch_object( db_query( db_rewrite_sql('SELECT * FROM {term_data} t WHERE t.tid = %d', 't', 'tid'), $tid ) ); } return !empty($terms[$uid][$tid]) ? $terms[$uid][$tid] : FALSE; } /** * Load tags from table. */ function nodewords_load_tags($type = NODEWORDS_TYPE_DEFAULT, $id = 0) { static $queries = array(); // If the metatags haven't been loaded before, load them. if (!isset($queries[$type][$id])) { $result = db_query("SELECT * FROM {nodewords} WHERE type = %d AND id = %d", $type, $id); $tags = array(); $tags_info = nodewords_get_possible_tags(); while ($row = db_fetch_object($result)) { if (isset($tags_info[$row->name])) { $tags[$row->name] = unserialize($row->content); } } // If no metatags are found for this term, try loading the vocabulary's. if (empty($tags) && $type == NODEWORDS_TYPE_TERM) { $tags = nodewords_load_tags(NODEWORDS_TYPE_VOCABULARY, db_result(db_query('SELECT vid FROM {term_data} WHERE tid = %d', $id))); } // Cache the metatags for later. $queries[$type][$id] = $tags; } return $queries[$type][$id]; } /** * Delete the nodes meta tags. * * @param $ids * An array of IDs. * @param $type * The type of the object associated with the IDs (NODEWORDS_TYPE_NODE, NODEWORDS_TYPE_USER, * NODEWORDS_TYPE_PAGER, NODEWORDS_TYPE_PAGE, ...). * @param $operation * The operation to execute (currently implemented: delete). */ function nodewords_mass_update($ids, $type, $operation = 'delete') { if ($operation == 'delete') { if (($count = count($ids))) { if ($count <= 10) { db_query("DELETE FROM {nodewords} WHERE id IN (" . db_placeholders($ids, 'int') . ") AND type = %d", array_merge($ids, array($type)) ); if ($type == NODEWORDS_TYPE_PAGE) { db_query("DELETE FROM {nodewords_custom} WHERE pid IN (" . db_placeholders($ids, 'int') . ")", $ids); } drupal_set_message(t('The update has been performed.')); } else { $batch = array( 'operations' => array( array('_nodewords_mass_delete_batch_process', array($ids, $type)) ), 'finished' => '_nodewords_mass_update_batch_finished', 'title' => t('Processing'), 'progress_message' => '', 'error_message' => t('The update has encountered an error.'), 'file' => drupal_get_path('module', 'nodewords') .'/nodewords.admin.inc', ); batch_set($batch); } } } } /** * Create the content of a meta tag from a node teaser. * * @param $node * The node object the meta tag refers to. * @param $content * The meta tag content. * @param $options * An array of options; currently, the only option used is the maximum allowed * length. * * @return * The string used as meta tag content. */ function nodewords_metatag_from_node_content($node, $content, $options = array()) { // The method used to generate the summary string. $method = variable_get('nodewords_metatags_generation_method_' . $node->type, NODEWORDS_GENERATION_WHEN_EMPTY); // If not generating an automatic description, return immediately. if ($method == NODEWORDS_GENERATION_NEVER || ($method == NODEWORDS_GENERATION_WHEN_EMPTY && !empty($content))) { return $content; } // Proceed as normal. $result = ''; $source = variable_get('nodewords_metatags_generation_source_' . $node->type, NODEWORDS_GENERATION_TEASER); // If generating an automatic description, determine the source. if (!empty($node->teaser) && ($source == NODEWORDS_GENERATION_TEASER || $source == NODEWORDS_GENERATION_TEASER_BODY)) { $result = $node->teaser; } elseif (!empty($node->body) && ($source == NODEWORDS_GENERATION_BODY || ($source == NODEWORDS_GENERATION_TEASER_BODY && empty($node->teaser)))) { $result = $node->body; } // Clean up the text by running it through applicable filters. if (!empty($result)) { // Check for the presence of the PHP evaluator filter in the current format. // If the text contains PHP code, do not split it up to prevent parse errors. $filters = filter_list_format($node->format); if (isset($filters['php/0']) && strpos($result, '') !== FALSE) { $result = ''; } // Continue as normal. else { // Run all of the normal text filters on the summary text. $result = check_markup($result, $node->format, FALSE); // Ensure there's a setting for controlling the maximum summary length. if (!isset($options['size'])) { $options['size'] = variable_get('nodewords_max_size', 350); } // Optionally replace the tag IMG with its ALT attribute. if (variable_get('nodewords_use_alt_attribute', FALSE)) { $result = preg_replace("/