'admin/settings/nodeteaser', 'title' => t('Node Teaser'), 'description' => t('Set a variety of options for node teaser input and display.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nodeteaser_admin_settings'), 'access' => user_access('administer site configuration'), 'type' => MENU_NORMAL_ITEM, // optional ); } return $items; } /** * Implementation of hook_nodeapi(). */ function nodeteaser_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { switch ($op) { case 'delete': _nodeteaser_delete($node); break; case 'insert': _nodeteaser_insert($node); break; case 'update': _nodeteaser_update($node); break; case 'prepare': $node = _nodeteaser_load($node); $node = node_prepare($node, $teaser); break; case 'view': $node = _nodeteaser_load($node); $node = node_prepare($node, $teaser); break; } } /** * Implementation of hook_form_alter(). */ function nodeteaser_form_alter($form_id, &$form) { if (_nodeteaser_page_match()) { // Make sure that teaser should be displayed on this page if (isset($form['type']) && $form_id == $form['type']['#value'] . '_node_form') { $type = 'node'; $id = $form['nid']['#value']; } else if ($form_id == 'taxonomy_form_vocabulary') { $type = 'vocabulary'; $id = $form['vid']['#value']; $form['submit']['#weight'] = 5; $form['delete']['#weight'] = 5; } else if ($form_id == 'taxonomy_form_term') { $type = 'term'; $id = $form['tid']['#value']; $form['submit']['#weight'] = 5; $form['delete']['#weight'] = 5; } if (isset($type)) { if (isset($id) && is_numeric($id)) { $tags = _nodeteaser_load($id); } else { $tags = array(); } $form['nt'] = array( '#type' => 'fieldset', '#title' => t('Teaser or Summary'), '#collapsible' => TRUE, '#collapsed' => variable_get('nodeteaser_collapsed', FALSE), ); $form['nt']['nodeteaser'] = array( '#type' => 'textarea', '#default_value' => $tags->teaser, '#cols' => 65, '#rows' => 12, '#description' => t('Enter a teaser, summary, or description for this node. If you would like the whole body to display, DO NOT enter a teaser!'), ); } } } /** * Implementation of hook_load(). */ function _nodeteaser_load($node) { if (!is_object($node)) { $id = $node; $node = (object) $node; } else { $id = $node->nid; } if (isset($node->nodeteaser)) { $nt->teaser = $node->nodeteaser; } else { $nt = db_fetch_object(db_query('SELECT teaser FROM {nodeteaser} WHERE nid = %d', $id)); if(!$nt) { $node->nodeteaser = FALSE; } } if ($nt->teaser != '') { $node->teaser = $nt->teaser; $node->nodeteaser = TRUE; }else { switch (variable_get("nodeteaser_empty", 'drupal_default')) { case 'drupal_default': break; case 'nothing': $node->teaser = ' '; break; case 'node_title': $node->teaser = $node->title; break; case 'full_post': $node->teaser = $node->body; break; } $node->nodeteaser = FALSE; } return $node; } /* This function formats the teaser for display */ /*function _nodeteaser_format($node) { $output = $node->teaser; $path = $node->path; if (!isset($path)) { $path = "node/".$node->nid; } if ($node->nodeteaser) { if (variable_get('nodeteaser_readmore', FALSE)) { $node->teaser .= "

continue reading \"".$node->title."\""; } } elseif (variable_get('nodeteaser_readmore', FALSE)) { // Get the unformatted teaser and body for comparison $nt = db_fetch_object(db_query('SELECT body FROM {node_revisions} WHERE nid = %d', $node->nid)); $body = $nt->body; $teaser = $node->teaser; $blength = strlen(htmlentities($body)); $tlength = strlen(htmlentities($teaser)); if ($blength > $tlength) { $node->teaser .= "

continue reading \"".$node->title."\""; } } return $node; }*/ /* Delete teaser from table */ function _nodeteaser_delete($node) { return db_query("DELETE FROM {nodeteaser} WHERE nid = %d", $node->nid); } /* Insert teaser into table */ function _nodeteaser_insert($node) { return db_query("INSERT INTO {nodeteaser} (nid, teaser) VALUES (%d, '%s')", $node->nid, $node->nodeteaser); } /** * Update teaser for new and existing content */ function _nodeteaser_update($node) { $nt = db_fetch_object(db_query('SELECT teaser FROM {nodeteaser} WHERE nid = %d', $node->nid)); if ($nt) return db_query("UPDATE {nodeteaser} SET teaser = '%s' WHERE nid = %d", $node->nodeteaser, $node->nid); else return _nodeteaser_insert($node); } /** * Module configuration settings * @return settings HTML or deny access */ function nodeteaser_admin_settings() { /*$form['nodeteaser_readmore'] = array('#type' => 'checkbox', '#title' => t('"continue reading" link'), '#default_value' => variable_get("nodeteaser_readmore", FALSE), '#description' => t('Display a "continue reading" link below teasers'), '#required' => FALSE, '#weight' => 0, );*/ $form['nodeteaser_empty'] = array('#type' => 'radios', '#title' => t('If node teaser is empty'), '#default_value' => variable_get("nodeteaser_empty", 'drupal_default'), '#description' => t('Default display for empty node teasers'), '#options' => array('drupal_default' => 'Drupal default', 'nothing' => 'display nothing', 'node_title' => 'node title', 'full_post' => 'full post'), '#required' => FALSE, '#weight' => 0, ); $form['nodeteaser_collapsed'] = array('#type' => 'checkbox', '#title' => t('Collapse node teaser'), '#default_value' => variable_get("nodeteaser_collapsed", FALSE), '#description' => t('Collapse node teaser by default'), '#required' => FALSE, '#weight' => 0, ); // Check if user has permission to 'use PHP for block visibility' // in Administer > access control > block //$access = user_access('use PHP for block visibility'); $options = array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')); $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => theme('placeholder', 'blog'), '%blog-wildcard' => theme('placeholder', 'blog/*'), '%front' => theme('placeholder', ''))); // If user does not have access to PHP code for visibility in Administer > access control > block, // radio button option for 'PHP for visibility' and description won't appear //if ($access) { $options[] = t('Show if the following PHP code returns TRUE (PHP-mode, experts only).'); $description .= t(' If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => theme('placeholder', ''))); //} $form['nodeteaser_access'] = array( '#type' => 'radios', '#title' => t('Show Teaser on specific pages'), '#default_value' => variable_get('nodeteaser_access', 1), '#options' => $options, ); $form['nodeteaser_access_pages'] = array( '#type' => 'textarea', '#title' => t('Pages'), '#default_value' => variable_get('nodeteaser_access_pages', ''), '#description' => $description, ); return system_settings_form($form); } /** * Determine if nodeteaser has permission to be used on the current page. * * @return * TRUE if can render, FALSE if not allowed. */ function _nodeteaser_page_match() { $page_match = "FALSE"; // If one of the options to control nodeteaser visibility was selected if (variable_get('nodeteaser_access_pages', '')) { // If the PHP option wasn't selected if (variable_get('nodeteaser_access', 1)< 2) { $path = drupal_get_path_alias($_GET['q']); $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote(variable_get('nodeteaser_access_pages', ''), '/')) .')$/'; $page_match = !(variable_get('nodeteaser_access', 1) xor preg_match($regexp, $path)); } // If the PHP option was selected else { $page_match = drupal_eval(variable_get('nodeteaser_access_pages', '')); } } // If no options to control nodeteaser visibility are selected, // visibility defaults to show nodeteaser on every page else { $page_match = "TRUE"; } return $page_match; } ?>