Have been playing with 'Contaires' teaser.module and thought I should report how I managed to install and implement it.

First, the install doesn't have a teaser.mysql to support the modifications to the node table required for the module to function. You need to modify the table "node" and add the following six columns

teaser_title varChar(100)
teaser_link varChar(100)
teaser_weight tinyInt(4)
teaser_image varChar(255)
teaser_image_width tinyInt(6)
teaser_image_height tinyInt(6)

or in MYSQL

ALTER TABLE `node` ADD `teaser_title` VARCHAR( 255 ) NOT NULL ;
ALTER TABLE `node` ADD `teaser_link` VARCHAR( 255 ) NOT NULL ;
ALTER TABLE `node` ADD `teaser_weight` VARCHAR( 255 ) NOT NULL ;
ALTER TABLE `node` ADD `teaser_image` TINYINT( 4 ) NOT NULL ;
ALTER TABLE `node` ADD `teaser_image_width` TINYINT( 6 ) NOT NULL ;
ALTER TABLE `node` ADD `teaser_image_height` TINYINT( 6 ) NOT NULL ;

Having done this the module installs successfully and users can now add nodes with extra teaser information.

Second, I then modified the module slightly so that the drupal coulmn node.teaser was also made visible as part of the node editing window. This will then allow you to modify the teaser text that drupal creates as standard - drupal chops first X chars of the content and puts that into the teaser field, but for our implementation we needed to have a customised input. I have altered the function "teaser_nodeapi", the changed function is listed below:

function teaser_nodeapi(&$node, $op, $teaser, $page) {
  static $teaser_count = 0;
  switch ($op) {
    case 'settings':
      $settings = array();
      $settings[t('contaire')] = form_checkbox('', 'teaser_'. $node->type, 1, variable_get('teaser_'. $node->type, TRUE));
      return $settings; 

    case 'fields':
      return array('teaser_title', 'teaser', 'teaser_image', 'teaser_link', 'teaser_image_width', 'teaser_image_height', 'teaser_weight');

    case 'form post':
      if (variable_get('teaser_'. $node->type, TRUE)) {
        $form .= form_textfield(t("Title"), "teaser_title", $node->teaser_title, 90, 128, t(""));
        $form .= form_textarea(t("Text"), "teaser", $node->teaser, 90, 6, t(""));
        $form .= form_textfield(t("Image"), "teaser_image", $node->teaser_image, 90, 128, t("The image filename, relative to the image directory."));
        $form .= form_textfield(t("Link"), "teaser_link", $node->teaser_link, 90, 128, t("Link that replaces the usual 'read more' link."));
        $form .= form_weight(t('Weight'), 'teaser_weight', $node->teaser_weight, 15, t('Teasers at a given level are ordered first by weight and then by title.'));
        return '<div class="contaire-form">' . form_group(t("Teaser"), $form) . '</div>';
      }
      return '';

    case 'view':
      if ($teaser && variable_get('teaser_'. $node->type, TRUE)) {
        if ($node->teaser_title) {
          $node->title = $node->teaser_title;
        }
        $align = ($teaser_count++ % 2) ? 'even' : 'odd';
        if ($node->teaser_image) {
          $node->teaser = '<img class="teaser-image-' . $align . '" src="/images/' . $node->teaser_image . '" width="' . $node->teaser_image_width . '" height="' . $node->teaser_image_height . '" alt="" />' . $node->teaser;
        }
        if ($node->teaser_link) {
          unset($node->readmore);
          $node->links[] = l(t('read more'), $node->teaser_link);
        }
      }
      break;

    case 'validate':
      if (variable_get('teaser_'. $node->type, TRUE)) {
        if ($node->teaser_image) {
          //$teaser_image = 'images/' . $node->teaser_image;
          $teaser_image = 'files/images/' . $node->teaser_image;
          if (file_exists($teaser_image)) {
            $size = getimagesize($teaser_image);
            $node->teaser_image_width = $size[0];
            $node->teaser_image_height = $size[1];
          }
          else {
            form_set_error('teaser_' . $node->type, t('The teaser image must exist')); 
          }
        }
      }
      break;
  }

Last, I wanted to display the teasers for the last 5 stories created in a block on the front page as part of a side bar. To do this we created a new block and changed the Input format to PHP code, and pasted the following into the Block Body:

$nlimit = 5;
$type = "story";
$result = db_query_range(db_prefix_tables("SELECT n.created, n.title, n.nid, n.changed,n.teaser_title,n.teaser_link,n.teaser, n.teaser_image
FROM {node} n
WHERE n.type = '$type'
AND n.teaser_title != ''
ORDER BY n.changed
DESC "), 0, $nlimit);
$output .= "<ul>";
while ($node = db_fetch_object($result)) {
$output .= "<li>".theme('node', $node, $teaser = TRUE, $page = FALSE);
$output .= theme('image', 'files/images/'.$node->teaser_image, $node->teaser_title, $node->teaser_image, $attributes = NULL, $getsize = TRUE);
$output .= "</li>";
}
$output .= "</ul>";
print $output;

This will then give you a block with the last 5 stories with teaser title / node as a link / teaser text / teaser image. Its then up to you to CSS and theme it.

To summarise the teaser.module requires a fair bit of tidying, I am going to atempt this whilst developing the project I am working on and will post my results at a later date. Hope the above helps somebody

Comments

logicexpertise’s picture

Hi, and thanks for this guide.

I've applied it, but I'm still unable to use the teaser module. The error I get is: "The teaser image must exist". This happens no matter what URL I use for the image -- I've tried using the full URL, i.e. "http://mysite.com/system/files?file=images/image-name.jpg, and also just the image file name without the site url. Am I missing something? Things work well without the image.

Any information on this will be appreciated.

Thanks.

tsaorin’s picture

I've noticed that theres is a missing in the SQL above:

There are two lines tha makes that error:

ALTER TABLE `node` ADD `teaser_weight` VARCHAR( 255 ) NOT NULL ;
ALTER TABLE `node` ADD `teaser_image` TINYINT( 4 ) NOT NULL ;

The properties of the teaser_weight must be TINYINT( 4 ), and for teaser_image will be VARCHAR( 255 ) (Here comes the name of the image file).

We are trying to use this feature in our web Murcia en familia

merlinofchaos’s picture

It isn't really a good idea for a module to modify the node table to add its data. It's a much better idea for a module to create an additional table and use hook_load, hook_save and hook_delete to transfer its data from its table to the $node object.

Clearly this module needs quite a lot of work.

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]