TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

April 30, 2024, 05:54:03 PM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,174
  • Total Topics: 21,220
  • Online today: 147
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 126
  • Total: 126

A Topic Post-Teaser for the Frontpage

Started by feline, January 17, 2008, 09:58:41 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

feline

A small modify for TinyPortal for a better display the Topics on the Frontpage ..

You have to modify two files .. TPortal.php and TPortal.template.php
First .. the TPortal.php
Search for:
while ($row = mysql_fetch_assoc($request))
{
// If we want to limit the length of the post.
if (!empty($length) && strlen($row['body']) > $length)
{
$row['body'] = substr($row['body'], 0, $length);

// The first space or line break. (<br />, etc.)
$cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));

if ($cutoff !== false)
$row['body'] = substr($row['body'], 0, $cutoff);
$row['body'] .= '...';
}

$row['body'] = doUBBC($row['body'], $row['smileysEnabled']);

// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

censorText($row['subject']);
censorText($row['body']);


Replay with:
while ($row = mysql_fetch_assoc($request))
{
$row['body'] = doUBBC($row['body'], $row['smileysEnabled']);

// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

censorText($row['subject']);
censorText($row['body']);

// tease post
if(!empty($length))
$row['body'] = FNW_Post_Teaser($row['body'], $length);


Search for:
return $show;
}


Add after:
// ---- Feline
// get word cont for post_teaser
function FNW_word_count($text)
{
$text = strip_tags($text);
$text = preg_split("/\s+/", $text);
$count = count($text);
return $count;
}

// the Post teaser (shorten articles on overwiew)
function FNW_Post_Teaser($content, $content_len)
{
global $context, $settings, $boarddir, $boardurl;

// create post teaser
$blocks = 'p|li|dt|dd|address|form|pre|td|div|span';
$matches = null;
$matches2 = null;
$auto_close = array();

$word_count = FNW_word_count($content);
preg_match_all("!.*?<($blocks)[^>]*>.+?</\\1>!si", $content, $matches);
$matches = $matches[0];
$block_count = count($matches);

$current_word_count = 0;
$block_word_count = array();
for ($i = 0; $current_word_count < $content_len && $i < $block_count;)
{
$block_word_count[$i] = FNW_word_count($matches[$i]);
$current_word_count += $block_word_count[$i];
if ($current_word_count < $content_len)
$i++;
}

if ($current_word_count >= $content_len && $i > 0)
{
$this_block_distance = $current_word_count - $content_len;
$last_block_distance = $content_len - ($current_word_count - $block_word_count[$i]);
if ($this_block_distance > $last_block_distance)
$i--;
}

$new_content = $content;
$tease = false;
if($block_count == 0)
{
$tease = strpos($new_content, '<!--more-->');
if(!$tease)
{
$words = FNW_word_count($new_content);
if($words > $content_len)
{
$tmp = $new_content;
while(FNW_word_count($tmp) > $content_len)
$tmp = substr($tmp, 0, strrpos($tmp, ' '));
$tease = strlen($tmp);
}
}
if($tease)
$new_content = substr($new_content, 0, $tease) . ' ...';
}
elseif($i <= $block_count)
{
for ($j = 0; $j <= $i;)
{
if(isset($matches[$j]))
{
$tease = strpos($matches[$j], '<!--more-->');
if(!$tease)
{
$words = FNW_word_count($matches[$j]);
if($words > $content_len)
{
$tmp = $matches[$j];
while(FNW_word_count($tmp) > $content_len)
$tmp = substr($tmp, 0, strrpos($tmp, ' '));
$tease = strlen($tmp);
}
}
if($tease)
{
$matches[$j] = substr($matches[$j], 0, $tease);
preg_match_all('!<(?:[a-zA-Z1-9]+)[^>]*>!i', $matches[$j], $matches2);
$matches2 = $matches2[0];
foreach ($matches2 as $id => $element)
{
if (preg_match('!^<([a-zA-Z1-9]+)[^>]*/>$!i', $element))
{
unset($matches2[$id]);
continue;
}
$element = preg_replace('!^<([a-zA-Z1-9]+)[^>]*>$!i', "$1", $element);
$auto_close[] = $element;
}
while($j <= $i)
{
$j++;
if(isset($matches[$j]))
unset($matches[$j]);
}
}
else
{
preg_match_all('!<(?:[a-zA-Z1-9]+)[^>]*>!i', $matches[$j], $matches2);
$matches2 = $matches2[0];
foreach ($matches2 as $id => $element)
{
if (preg_match('!^<([a-zA-Z1-9]+)[^>]*/>$!i', $element))
{
unset($matches2[$id]);
continue;
}
$element = preg_replace('!^<([a-zA-Z1-9]+)[^>]*>$!i', "$1", $element);
$auto_close[] = $element;
}
}
}
$j++;
}

$new_content = '';
for ($j = 0; $j <= $i; $j++)
{
if(isset($matches[$j]))
{
$temp = $matches[$j];
foreach ($auto_close as $id => $element)
{
$pos = strpos(" " . $temp, "</$element>");
if ($pos)
{
$temp = substr_replace($temp, '', $pos, strlen("</$element>"));
unset($auto_close[$id]);
}
}
$new_content .= $matches[$j];
}
}
$auto_close = array_reverse($auto_close);
foreach ($auto_close as $element)
$new_content .= "</$element>";
$new_content .= ' ...';
}

return $new_content;
}


Now modify the TPortal.template.php
Search for:
// ..and for views and ratings , even comments?
echo '</div><div style="text-align: right; margin-top: 1ex;">';
$opts=array();
if(isset($story['options']['views']) || $story['is_boardnews'])
$opts[] = '<span class="smalltext">' . $story['views'] . ' ' . $txt['tp-views'] . '</span>';
if(isset($story['options']['comments']) || $story['is_boardnews']){
if($story['is_boardnews'] && ($story['comments']>1 || $story['comments']==0))
$what=$txt[110];
elseif($story['is_boardnews'] && $story['comments']==1)
$what=$txt[146];
else
$what='<a href="'.$scripturl.'?page='.$story['id'].'#tp-comment">'.$txt['tp-comments'].'</a>';

$opts[] = '<span class="smalltext">' . $story['comments'] . ' ' . $what . '</span>';
}
if(isset($story['options']['rating']))
$opts[] = '<span class="smalltext">' . $txt['tp-ratingaverage'] . ' ' . ($context['TPortal']['showstars'] ? (str_repeat('<img src="'.$settings['images_url'].'/tpblue.gif" style="width: .7em; height: .7em; margin-right: 2px;" alt="" />', $story['rating_average'])) : $story['rating_average']) . ' (' . $story['rating_votes'] . ' ' . $txt['tp-ratingvotes'] . ') </span>';

                     echo implode("&nbsp;|&nbsp;",$opts);

echo '
      </div>
</td>';


Replace with:
// ..and for views and ratings , even comments?
// add by Feline
echo '</div>';
if($story['is_boardnews'])
{
echo '
<div style="margin-top:1ex; height:18px;"><div style="float:left;">
<a href="' , $story['href'] , '"><i>Read more</i></a>
</div>';
}

$opts=array();

if(isset($story['options']['views']) || $story['is_boardnews'])
{
echo '
<div style="float:right;">';
$opts[] = '<span class="smalltext">' . $story['views'] . ' ' . $txt['tp-views'] . '</span>';
}

if(isset($story['options']['comments']) || $story['is_boardnews']){
if($story['is_boardnews'] && ($story['comments']>1 || $story['comments']==0))
$what=$txt[110];
elseif($story['is_boardnews'] && $story['comments']==1)
$what=$txt[146];
else
$what='<a href="'.$scripturl.'?page='.$story['id'].'#tp-comment">'.$txt['tp-comments'].'</a>';

$opts[] = '<span class="smalltext">' . $story['comments'] . ' ' . $what . '</span>';
}
if(isset($story['options']['rating']))
$opts[] = '<span class="smalltext">' . $txt['tp-ratingaverage'] . ' ' . ($context['TPortal']['showstars'] ? (str_repeat('<img src="'.$settings['images_url'].'/tpblue.gif" style="width: .7em; height: .7em; margin-right: 2px;" alt="" />', $story['rating_average'])) : $story['rating_average']) . ' (' . $story['rating_votes'] . ' ' . $txt['tp-ratingvotes'] . ') </span>';

                     echo implode("&nbsp;|&nbsp;",$opts);

if(isset($story['options']['views']) || $story['is_boardnews'])
echo '
</div></div>';
echo '
</td>';
// ---


Now .. in the ACP - TinyPortal - Setting - Frontpage
Set here Number of characters to show per forum-post:  the number of WORDS eg. 30 or more ..

Thats all ..
You can see that on my site ...

Fel

dannbass


IchBin



fmartin

could this code be modified to parse for a some king of read-more tag? i don't if that would be possible or would require deeper changes