Article Summary

Inspiration
Inspiration
This article shows you how to add a summary at the top of your sNews articles (and push it to the Articles’ RSS feed). The image has nothing to do with the text btw...

The idea with this modification of the sNews script is to make it possible to add an article summary that can be used as the article intro or lead on index pages, and in combination with other mods, as well as in the rss_articles function. Now, it could be argued that you can already do this by using the break function. This is absolutely true, this summary mod is a variation of the break function so if you’re comfortable using break to get the results you want, then you don’t need this mod. I personally have had some comments from people who are not familiar with sNews’ way of doing things, that they would like a summary function, which leads me to believe that there’s a use for it. Plus you get a clearer division between the summary and the article text, which might be a good thing. As always, it’s up to you to use it or not.

Please note that the mod replaces the use of break. In other words, to get a shortened article with this mod in place, you need to use the summary feature. Using break with the mod causes problems.

First of all

Before we go into the code you should make sure to have a backup of your database and site files. It is not recommended to perform changes on a live site, instead you should set up a safe test environment. Just in case the proverbial shit hits the fan.

Steps

  1. Backup
  2. In your database admin tool, find your database and make the following change:
    ALTER TABLE `articles` ADD `summary` TEXT CHARACTER SET utf8 COLLATE utf8_bin NULL

    Note that the character set and collate values should match the ones already used in your database.

  3. Now open your sNews installation’s language file (default is EN.php) in your text/code editor and add the following somewhere in the article structure block:
    $l['summary'] = 'Article summary';
    Save and close file.
  4. Next, open snews.php and locate the form_articles($contents) function. After the first switch, just before $frm_text, add:
    $frm_summary = str_replace('&', '&', $_SESSION[_SITE.'temp']['summary'] ? $_SESSION[_SITE.'temp']['summary'] : $r['summary']);
    (You can use $frm_text and $text as a marker where to put the additions almost throughout snews.php).
  5. A few lines further down, after the second switch, add:
    $frm_summary = $_SESSION[_SITE.'temp']['summary'];
  6. Another few lines further down there’s the html_input part. Locate the html_input for the textarea and directly before it, add:
    echo html_input('textarea', 'summary', 'sutxt', $frm_summary, l('summary'), '', '', '', '', '', '3', '100', '', '', '');
    While your at it you can change the col value for the original textarea to 10 to make it more defined and different than the summary textarea, as a visual aid, like this:
    echo html_input('textarea', 'text', 'txt', $frm_text, l('text'), '', '', '', '', '', '10', '100', '', '', '');
  7. Next is function processing. In the first big block in processing, add:
    $summary = clean($_POST['summary']);
    A good place to put it might be next to $seftitle, since $text isn’t in there. It can really go anywhere in that block, just try and keep it logical so you can find it easily or replicate it for other times.
  8. Still in processing, find case (isset($_POST['add_article'])). In the first group in that case, add summary, before text, and then in the next group, add '$summary',.
  9. Some lines further down, find:
    mysql_query("UPDATE "._PRE.'articles'." SET
    and in that segment, add summary = '$summary',.
  10. Important Update: Go back up to function articles. First, find $query_articles = 'SELECT (there are three instances of it), and add a.summary in each, like this:
    $query_articles = 'SELECT
    a.id AS aid,title,a.seftitle AS asef,a.summary,text,a.date,
    a.displaytitle,a.displayinfo,a.commentable,a.visible,a.views
    FROM '._PRE.'articles'.' AS a
  11. Update: Next, locate $title, and after it add this:
    $sumtxt = stripslashes($r['summary']);
  12. Important Update: Still in articles, locate the file_include line and replace it with this:
    if(!empty($currentPage)) {
    if(!empty($sumtxt)) {
    echo '<div class="summary">'.$sumtxt.'</div>';
    } else {
    file_include(str_replace('', '',$text), $shorten);
    }
    } else {
    file_include(str_replace('', '',$text), $shorten);
    }
  13. Next, a few lines down, find the first if ($infoline == true), locate the readmore case and add a second version after it, like this:
    case ($tag == 'readmore' && $sumtxt):
    echo $link.$uri.'/'.$r['asef'].'/">'.l('read_more').'</a>';
    break;
    (Yes, we need two readmore instances, just in case summary isn’t used.)
  14. And, for our last trick, go to function rss_contents($rss_item, $artSEF='') and find the rss_articles case. Then make it look like this:
    case 'rss-articles':
    $date = date('D, d M Y H:i:s +0000', strtotime($r['date']));
    if ($r['category'] == 0) {
    $categorySEF = '';
    } else {
    $categorySEF = cat_rel($r['category'], 'seftitle').'/';
    }
    $articleSEF = $r['seftitle'];
    $title = $r['title'];
    $text = $r['summary'] ? $r['summary'] : $r['text']; //Changed!
    break;

Then save the file, and preview your site. You won’t be able to preview the RSS feed locally, it must be “out there” for you to grab it, but check that everything else is working properly. You can see the mod at work on this site. The short lead text on the index pages, and the bold text at the top of each article in full page view – that’s the summary. As you can also see from this guide’s summary, you can put an image in there, or a video clip or what ever you like that fits within the limitations of the TEXT db field. If you need more space, change the TEXT value to LONGTEXT. But if you do, keep in mind that the summary is intended to be short by nature.

Update: “nukpana” offered a solution for the RSS articles case that is better than the previous, so use the update instead. (Thanks Jason!)

Important updates: Due to lack of focus I’d missed one important step, the first part of the changes in articles(). This was a bad mistake since the mod won’t work without this change. So, if you’re having problems with the mod, go through the description again and make sure you change the three instances of $query_articles = 'SELECT in the top part of articles(). The other updates are also important but this one’s really important and I’m sorry I missed it. Thanks to Jason (“nukpana”) for pointing it out.

Comments

1

Fred,
to say it straight away: I haven't tested yet whether it is windproof, but this mod appears to work even without step 14. Background: I'm using Matt Jones' mod to "fix RSS feeds", which for some reason didn't quite work as expected. Then I figured out that step 14 kind of breaks Matt's fix. Therefore I got reverted this particular step and, for the life of me, I cannot see a difference.

, 2 years ago

Gerry, step 14 only affects the RSS function and since you already had Matt’s function which has a similar effect on the RSS function (as step 14) among other things, leaving out that step won’t make any difference for you, no. Those that don’t use Matt’s RSS fix and do want the summary in the RSS feed need to do step 14. Just so it’s clear.

Fred K (Admin) 2 years ago

Commenting is off.

Popular stories


Categories

Subcategories


Pages