Ok. This modification lightens the code for the [break] function in sNews.
Final version of this idea:
http://snewscms.com/forum/index.php?topic=8324.msg64913#msg64913In theory, it should lighten the total PHP memory count when using function articles. Meaning, currently the whole article is pulled from the database and then PHP parses the [break]. This version has the parsing in the database...
0. BACKUP!!!!
1. Add a new function. I have mine before the articles function...
function fix_html( $text ) {
if (substr_count ($text, '&') > 0) {
$text = str_replace('&', '&', str_replace('&', '&', $text));
}
if (preg_match('<p>',$text)) {
if (substr_count ($text, '<p>') > substr_count ($text, '</p>')) {
$text .='</p>';
}
}
return str_replace('[break]', '', $text);
}
2. In function articles(), find the last line and add the remainder of the code, before it:
$summary = $_ID
? ''
: 'CASE
WHEN text LIKE "%[break]%"
THEN SUBSTRING_INDEX( text, "[break]", 1 )
ELSE text
END as ';
$has_break = ', CASE
WHEN text LIKE "%[break]%" THEN 1
ELSE ""
END as break_exists';
// get the rows for category
3. Same area... add the $summary and $has_break cases to the queries:
// get the rows for category
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 '. $has_break .'
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
'. $has_break .'
4. further down, find the first line and add the second:
$text = stripslashes($r['text']);
$text = fix_html($text);
5. Comment out this block in function articles:
if (!empty($currentPage)) {
$short_display = strpos($text, '[break]');
$shorten = $short_display == 0 ? 9999000 : $short_display;
} else {
$shorten = 9999000;
}
6. Further down.... Find the first line, comment it out and add the second:
file_include(str_replace('[break]', '',$text), $shorten);
file_include($text);
7. Find the first line in articles(), comment it out and add the second:
case ($tag == 'readmore' && strlen($r['text']) > $shorten):
case ($tag == 'readmore' && $r['break_exists']):
8. In function extras, find the first line, comment it out and add the second:
file_include($r['text'], 9999000);
file_include($r['text']);
9. Function file_include. Find the last line noted, and follow the example of the previous code:
function file_include($text) { //, $shorten) {
/*
$fulltext = substr($text, 0, $shorten);
if (substr_count ($fulltext, '&') > 0) {
$fulltext = str_replace('&', '&', str_replace('&', '&', $fulltext));
}
if ($shorten < 9999000 && preg_match('<p>',$fulltext)) {
if (substr_count ($fulltext, '<p>') > substr_count ($fulltext, '</p>')) {
$fulltext .='</p>';
}
}
*/
// New line
$fulltext = $text;
$ins = strpos($fulltext, '[/func]');
10. For the RSS Feed: Find the last line, comment it out and add the previous code:
// ADDED
$summary = $rss_item == 'rss-articles'
? ', CASE
WHEN text LIKE "%[break]%" THEN SUBSTRING_INDEX( text, "[break]", 1 )
END as summary'
: '';
// MODDED
$result = mysql_query("SELECT *".$summary." FROM $query DESC LIMIT $limit");
$result = mysql_query("SELECT * FROM $query DESC LIMIT $limit");
11. Later down in the function, find the last line, comment it out and add the previous:
$text = $r['summary'] ? $r['summary'] : $r['text'];
$text = fix_html($text);
$text = $r['text'];