Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2]

Author Topic: [SOLVED] Summary (connecting Intro with RSS Articles, automagically, sort of)  (Read 3088 times)

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663

I may have another solution, untested fully and would need to be modded into other functions as needed (menu_articles, rss), but something to ponder....

Code: (In the articles function) [Select]
<?php

// get the rows for category
$summary $_ID 
''
'CASE WHEN text LIKE "%[break]%" THEN SUBSTRING_INDEX( text, "[break]", 1 )
ELSE CONCAT( LEFT( text, 200 ) , " ..." )
END as '
;

if ($_catID) {
$query_articles 'SELECT
a.id AS aid,title,a.seftitle AS asef,'
.$summary.'text,a.date,
a.displaytitle,a.displayinfo,a.commentable,a.visible
FROM '
._PRE.'articles'.' AS a
WHERE position = 1
AND a.published =1
AND category = '
.$_catID.$visible.'
ORDER BY artorder ASC,date DESC
LIMIT '
.($currentPage 1) * $article_limit.','.$article_limit;
} else {
$query_articles 'SELECT
a.id AS aid,title,a.seftitle AS asef,'
.$summary.'text,a.date,
displaytitle,displayinfo,commentable,a.visible,
c.name AS name,c.seftitle AS csef,
x.name AS xname,x.seftitle AS xsef
FROM '
._PRE.'articles'.' AS a
LEFT OUTER JOIN '
._PRE.'categories'.' as c
ON category = c.id
LEFT OUTER JOIN '
._PRE.'categories'.' as x
ON c.subcat =  x.id AND x.published =\'YES\'
WHERE show_on_home = \'YES\'
AND position = 1
AND a.published =1
AND c.published =\'YES\''
.$visible.'
ORDER BY date DESC
LIMIT '
.($currentPage 1) * $article_limit.','.$article_limit;
}


// Later on...

case ($tag == 'readmore'
// && strlen($r['text']) > $shorten
):

echo $link.$uri.'/'.$r['asef'].'/">'.l('read_more').'</a> ';

break;

?>

What is going on??

First, I am using the MySQL function SUBSTRING_INDEX() to just give me the text before the [break]  - SUBSTRING_INDEX( text, "[break]", 1 ).  If there isn't a break, then give me the first 200 characters and add a space and three trailing periods..  ONLY WHEN THIS IS NOT A ARTICLE OR A PAGE

then I commented out the shorten part on the read more, since I want the whole thing to show on all (may not be desired...

For RSS since it was noted....
Code: [Select]
<?php

// ADDED
 
$summary $rss_item == 'rss-articles'
 
' ,CASE WHEN text LIKE "%[break]%" THEN SUBSTRING_INDEX( text, "[break]", 1 )
ELSE CONCAT( LEFT( text, 200 ) , " ..." )
END as summary'

 
'';
// MODDED
 
$result mysql_query("SELECT *".$summary." FROM $query DESC LIMIT $limit");
 
$numrows mysql_num_rows($result);
 
$comments_order s('comments_order');
 
$ordinal $comments_order == 'DESC' $numrows;
 
$comment_limit s('comment_limit') < s('comment_limit');
 
$comments_order s('comments_order');
 
while ($r mysql_fetch_assoc($result)) {
switch($rss_item) {
case 'rss-articles':
case 'rss-pages':
$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'];
// MODDED
$text $r['summary'] ? $r['summary'] : $r['text'];

break;

?>


menu_articles....

Code: [Select]
<?php

$query 'SELECT
title,a.seftitle AS asef,date,CASE WHEN text LIKE "%[break]%" THEN SUBSTRING_INDEX( text, "[break]", 1 ) ELSE CONCAT( LEFT( text, 200 ) , " ..." ) END as text,
c.name AS name,c.seftitle AS csef,
x.name AS xname,x.seftitle AS xsef
FROM '
._PRE.'articles'.' AS a
LEFT OUTER JOIN '
._PRE.'categories'.' as c
ON category = c.id
LEFT OUTER JOIN '
._PRE.'categories'.' as x
ON c.subcat =  x.id AND x.published =\'YES\'
WHERE position = 1
AND a.published = 1
AND c.published =\'YES\'
AND a.visible = \'YES\'
'
.$subcat.'
ORDER BY date DESC
LIMIT '
."$start$size";


// later on

echo  '<li><a href="'._SITE.$link.'/'.$r['asef'].'/"
title="'
.$r['name'].' / '.$r['title'].' ('.$date.')">'.$r['title'].$name.'</a><p>'.strip_tags($r['text']).'</p>
</li>'
;

?>


Again, just a test...

For normal sNews usage, you can just use SUBSTRING_INDEX( text, "[break]", 1 ) as this will return the string before the break, and if there is no break, it will return the whole string.  In thinking this should reduce the system's memory consumption for article lists...
« Last Edit: August 07, 2010, 04:35:13 PM by nukpana »
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal

Interesting. Will test it out to see how it functions. In the meantime I've altered my RSS articles code with your suggestion
Code: [Select]
$text = $r['summary'] ? $r['summary'] : $r['text'];
I was doing something similar in a previous version though it didn't work out for whatever reason but this works nicely. Thanks.
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663

ehh I am rethinking the RSS implementation...  again.. I just thought of it and I was just testing it. Nothing substantial (or well thought out yet)
Logged
Pages: 1 [2]