5.x: 17. Changes to hook_node_info() and the node type system ??? function nodeteaser_node_info() { //return array('nodeteaser' => array('name' => t('Separate Node Teaser Field'), 'base' => 'nodeteaser')); } /** * Implementation of hook_nodeapi(). */ //4.7.x->5.x: 15. Change hook_view() and hook_nodeapi($op = 'view') ??? 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': //??? if ($teaser) { $node->content['body'] = array( '#value' => _nodeteaser_load($node), '#weight' => 0, ); } break; case 'view': //??? if ($teaser) { $t = _nodeteaser_load($node); $node->content['body'] = array( '#value' => _nodeteaser_format($t), '#weight' => 0, ); } // $node->content = _nodeteaser_format($t); // $node->teaser = _nodeteaser_format($t); break; //4.7.x->5.x: 16. New hook_nodeapi($op = 'alter') has been added //case 'alter': //??? } } /** * 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['nodeteaser'] = _nodeteaser_form($type, $tags); } } } /* * Create a form - returns a $form variable */ function _nodeteaser_form($type, $tags) { //$settings = _nodewords_get_settings(); $form = array(); $form['nodeteaser'] = array( '#type' => 'textarea', '#title' => t('Teaser or Summary'), '#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!'), ); return $form; } /** * Implementation of hook_load(). */ function _nodeteaser_load($node) { if (!is_object($node)) {$id = $node; $node = (object) $node;} else {$id = $node->nid;} $nt = db_fetch_object(db_query('SELECT teaser FROM {nodeteaser} WHERE nid = %d', $id)); if($nt) { $teaser = $nt->teaser; if ($teaser != '') { $node->teaser = $nt->teaser; $node->nodeteaser = TRUE; }else { $node->nodeteaser = FALSE; //return $node->teaser; } } else { $node->nodeteaser = FALSE; //return $node->teaser; } 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;} // Get the unformatted teaser and body for comparison $nt = db_fetch_object(db_query('SELECT teaser, body FROM {node_revisions} WHERE nid = %d', $node->nid)); $body = $nt->body; $teaser = $nt->teaser; $blength = strlen(htmlentities($body)); $tlength = strlen(htmlentities($teaser)); if ((variable_get('nodeteaser_readmore', FALSE)) && (($blength > $tlength) || ($node->nodeteaser))) { $output .= "
continue reading \"".$node->title."\"
"; } return $output; } /* 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 */ function _nodeteaser_update($node) { return db_query("UPDATE {nodeteaser} SET teaser = '%s' WHERE nid = %d", $node->nodeteaser, $node->nid); } /** * Module configuration settings * @return settings HTML or deny access */ //4.7.x->5.x: 8. Removed hook_settings() //4.7.x->5.x: 11. New administration layout function nodeteaser_menu($may_cache) { $items[] = array( 'path' => 'admin/settings/nodeteaser', 'title' => t('nodeteaser'), 'description' => t('Node teaser settings page.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('nodeteaser_admin_settings'), 'access' => user_access('administer site configuration'), 'type' => MENU_NORMAL_ITEM, // optional ); return $items; } function nodeteaser_admin_settings() { // only administrators can access this module if (!user_access("administer nodeteaser")) { return message_access(); } $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 ); $options = array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')); //4.7.x->5.x: 22. Altered the behaviour of placeholders in t() calls ??? $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', '