Re: New frontpage index mod!

bingiman wrote:
MattF wrote:

The only problem with truncation is that it screws the W3C compliance if it happens to trim the message inbetween a pair of tags. big_smile

Actually, this is true but soonotes (tinytim) managed to resolve this issue with his User Blogs.

Yeah, had to do some searching to get that to work as the function for it is beyond my abilities. I would love to give proper credit for the functions below but I lost that info and have not been able to find it again.

Here's the code from blog.php where I call the function

                //First we parse the message
                $pre = parse_message($cur_blog['blog'], $cur_blog['hide_smilies']);

                // Now we trim it
                $str = truncate ($pre, $id);

$pre parses the message normal pun style (ie $cur_post) and then the truncate function is called.

The message and the blog id are required due to the fact the function also adds a 'read more' link.

Below are two functions actually. The truncate function does just that. The close tags function closes any open tags and is fully xhtml 1.0 compliant (ie. it accounts for self closing tags like img)

You should be able to use this without much trouble for what you want to do.

If you look at the truncate function you'll notice $len which sets the amount of characters to display. You will probably want to hard code that. (ie. $len = 400;)

The other variable you need to adjust is $append which adds the read more link.

Hope that helps.


//
// Close any open tags when truncating a blog
//

function close_tags($string)
{
  // match opened tags
  if(preg_match_all('/<([a-z\:\-]+)[ >]/', $string, $start_tags))
  {
    $start_tags = $start_tags[1];

    // match closed tags
    if(preg_match_all('/<\/>([a-z]+)>/', $string, $end_tags))
    {
      $complete_tags = array();
      $end_tags = $end_tags[1];
    
      foreach($start_tags as $key => $val)
      {   
        $posb = array_search($val, $end_tags);
        if(is_integer($posb))
        {
          unset($end_tags[$posb]);
        }
        else
        {
          $complete_tags[] = $val;
        }
      }
    }
    else
    {
      $complete_tags = $start_tags;
    }
    
    $complete_tags = array_reverse($complete_tags);
    for($i = 0; $i < count($complete_tags); $i++)
    {
      $string .= '</' . $complete_tags[$i] . '>';
    }
  }
  // Removes the </img> tag
$xhtml_tags = array("</img>", "</hr>", "</br>");
$string = str_replace($xhtml_tags, "", $string);
  return $string;
}





//
// Truncate string longer than max length
//

function truncate($str, $id) {
    global $pun_config;
$len = $pun_config['b_blog_trun_length'];
$splitter = '<!--MORE-->';
$append = ' ... <span class="barlink"><i><a href="blog.php?cid='.$id.'&c_id='.$id.'">Full Blog';
    if(strlen($str) <= $len){
        return $str;
    }
    if($len > 0 && !strstr($str,$splitter)){
        preg_match('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$len.',}\b#U', $str,$matches);
        $str = $matches[0];
        # remove trailing opener tags and close all other open tags:
        $str = close_tags(preg_replace('#\s*<[^>]+>?\s*$#','',$str).$append);
    } else {
        $arr = explode($splitter,$str,2);
        $str = $arr[0];
    }
    return $str;
}

Re: New frontpage index mod!

can u make it as Forum/index.php Directory

MyFootballCafe.com  is Now Online!

28

Re: New frontpage index mod!

supermag, just create a new php file called test.php and copy code to it and try it out if u like it  then rename index.php and rename test to index.php..

Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

Re: New frontpage index mod!

Does anyone know how to put this all together to make it work?

30

Re: New frontpage index mod!

Cheers for that soonotes. smile I've had the truncation bugbear with the portal ever since I made it W3C strict, so I should be able to sort that now. Thanks again for posting the code. smile

'Bling', big_smile I'll have a diddle when I've a moment if you like? That don't mean it'll work though. big_smile

31 (edited by bingiman 2007-06-18 12:47)

Re: New frontpage index mod!

This version below uses an avatar.

<?php
 
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
 
//Set the page title here
$page_title = pun_htmlspecialchars($pun_config['o_board_title']);

define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';
require PUN_ROOT.'include/parser.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/topic.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';

$newsid = '1'; //This is the forum the news is retrieved from
$newsdisplay = '5'; //This is how many news articles are displayed.


$result = $db->query('SELECT t.id, t.subject, t.num_replies, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.forum_id, u.use_avatar, p.poster AS username, p.poster_id, p.message, p.hide_smilies, p.posted, g.g_title, f.forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON p.topic_id=t.id AND p.posted=t.posted INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE t.forum_id='.$newsid.' AND t.moved_to IS NULL AND f.redirect_url IS NULL ORDER BY t.posted DESC LIMIT '.$newsdisplay) or error('Unable to fetch announcements', __FILE__, __LINE__, $db->error());


        if ($db->num_rows($result))
                    {
                            while($cur_post = $db->fetch_assoc($result))
                            {
                                    $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
?>
    <div class="block">
       
<?php
        if ($pun_config['o_avatars'] == '1' && $cur_post['use_avatar'] == '1' && $pun_user['show_avatars'] != '0')
        {
            if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif'))
                $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif" '.$img_size[3].' title="'.$cur_post['username'].'\'s Avatar" alt="'.$cur_post['username'].'\'s Avatar" /></a>';
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg'))
                $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg" '.$img_size[3].' title="'.$cur_post['username'].'\'s Avatar" alt="'.$cur_post['username'].'\'s Avatar" /></a>';
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png'))
                $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png" '.$img_size[3].' title="'.$cur_post['username'].'\'s Avatar" alt="'.$cur_post['username'].'\'s Avatar" /></a>';
        }
        else
            $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img alt="" src="img/noimage.gif" /></a>';
    echo "\t\t\t\t\t\t\t".'<h2><strong><a href="forum.php">Forum</a> » <a href="viewforum.php?id='.$cur_post['forum_id'].'">'.pun_htmlspecialchars($cur_post['forum_name']).'</a>'.'</strong></h2>'."\n";
?>
<div class="box">
    <div class="inbox">
<ul><li>
<div style="padding-bottom: 6px;" ><a class="news_subject" href="viewtopic.php?id=<?php echo $cur_post['id']; ?>"><strong><?php echo $cur_post['subject']; ?></strong></a></div>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td style="border: 0px;" width="90%"><?php echo $cur_post['message']."\n" ?></td>
    <td align="right" style="border: 0px;" width="10%" valign="top"><?php echo $user_avatar ?></td>
  </tr>
</table>
<br />
<br />
<table class="news_footer" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td width="100%">
<?php


    echo "\t\t\t\t\t\t\t".'<span class="byuser" style="float:left">Posted on: '.format_time($cur_post['posted']).' by:<span class="byuser'.(isset($cur_post['g_title']) ? ' '.strtolower(str_replace(' ', '', $cur_post['g_title'])) : '').'"> <a href="profile.php?id='.$cur_post['poster_id'].'" class="username">'.pun_htmlspecialchars($cur_post['poster']).'</a> |  Views: '. $cur_post['num_views'].' |  Replies: '. $cur_post['num_replies'].'</span></span>'."\n";
        if ($cur_post['poster_id'] == $pun_user['id'] || $pun_user['g_id'] < PUN_GUEST)
    echo "\t\t\t\t\t\t\t".'<a style="text-decoration: none" href="viewtopic.php?id='.$cur_post['id'].'" class="username">'.pun_htmlspecialchars($lang_portal['Visit_Topic']).'</a>'.'<span style="float:right">'.'<a href="misc.php?report='.$cur_post['id'].'">'.$lang_topic['Report'].'</a>'.' | <a href="delete.php?id='.$cur_post['id'].'">'.$lang_topic['Delete'].'</a> | <a href="edit.php?id='.$cur_post['id'].'">'.$lang_topic['Edit'].'</a>'.' | <a href="post.php?tid='.$cur_post['id'].'">'.'Reply'.'</a>'.' | <a href="post.php?tid='.$cur_post['id'].'&qid='.$cur_post['id'].'">'.$lang_topic['Quote'].'</a>'.'</span>'."\n\n\n\n";
?>
        </td>
    </tr>
</table>
</ul>
        </div>
    </div>
</div>
<?
}
     }
else
{
    }
     ?>
<br />
<br />

<?php
require PUN_ROOT.'footer.php';

32

Re: New frontpage index mod!

ok i have added the read more function.

<?php
 
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
 
//Set the page title here
$page_title = pun_htmlspecialchars($pun_config['o_board_title']);

define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';
require PUN_ROOT.'include/parser.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/topic.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';

$newsid = '1'; //This is the forum the news is retrieved from
$newsdisplay = '5'; //This is how many news articles are displayed.

global $lang_common, $db, $pun_config, $pun_user, $db_prefix;
$result = $db->query('SELECT t.id, t.subject, t.num_replies, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.forum_id, u.use_avatar, p.poster AS username, p.poster_id, p.message, p.hide_smilies, p.posted, g.g_title, f.forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON p.topic_id=t.id AND p.posted=t.posted INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE t.forum_id='.$newsid.' AND t.moved_to IS NULL AND f.redirect_url IS NULL ORDER BY t.posted DESC LIMIT '.$newsdisplay) or error('Unable to fetch announcements', __FILE__, __LINE__, $db->error());


        if ($db->num_rows($result))
                    {
                            while($cur_post = $db->fetch_assoc($result))
                            {
                                    $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
?>
    <div class="block">
       
<?php
        if ($pun_config['o_avatars'] == '1' && $cur_post['use_avatar'] == '1' && $pun_user['show_avatars'] != '0')
        {
            if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif'))
                $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif" '.$img_size[3].' title="'.$cur_post['username'].'\'s Avatar" alt="'.$cur_post['username'].'\'s Avatar" /></a>';
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg'))
                $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg" '.$img_size[3].' title="'.$cur_post['username'].'\'s Avatar" alt="'.$cur_post['username'].'\'s Avatar" /></a>';
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png'))
                $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png" '.$img_size[3].' title="'.$cur_post['username'].'\'s Avatar" alt="'.$cur_post['username'].'\'s Avatar" /></a>';
        }
        else
            $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img alt="" src="img/noimage.gif" /></a>';
    echo "\t\t\t\t\t\t\t".'<h2><strong><a href="forum.php">Forum</a> » <a href="viewforum.php?id='.$cur_post['forum_id'].'">'.pun_htmlspecialchars($cur_post['forum_name']).'</a>'.'</strong></h2>'."\n";
?>
<div class="box">
    <div class="inbox">
<ul><li>
<div style="padding-bottom: 6px;" ><a class="news_subject" href="viewtopic.php?id=<?php echo $cur_post['id']; ?>"><strong><?php echo $cur_post['subject']; ?></strong></a></div>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td style="border: 0px;" width="90%"><?php echo $cur_post['message']."\n" ?></td>
    <td align="right" style="border: 0px;" width="10%" valign="top"><?php echo $user_avatar ?></td>
  </tr>
</table>
<br />
<br />
<table class="news_footer" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td width="100%">
<?php


    echo "\t\t\t\t\t\t\t".'<span class="byuser" style="float:left">Posted on: '.format_time($cur_post['posted']).' by:<span class="byuser'.(isset($cur_post['g_title']) ? ' '.strtolower(str_replace(' ', '', $cur_post['g_title'])) : '').'"> <a href="profile.php?id='.$cur_post['poster_id'].'" class="username">'.pun_htmlspecialchars($cur_post['poster']).'</a> |  Views: '. $cur_post['num_views'].' |  Replies: '. $cur_post['num_replies'].'</span></span>'."\n";
        if ($cur_post['poster_id'] == $pun_user['id'] || $pun_user['g_id'] < PUN_GUEST)
    echo "\t\t\t\t\t\t\t".'<a style="text-decoration: none" href="viewtopic.php?id='.$cur_post['id'].'" class="username">'.pun_htmlspecialchars($lang_portal['Visit_Topic']).'</a>'.'<span style="float:right">'.'<a href="misc.php?report='.$cur_post['id'].'">'.$lang_topic['Report'].'</a>'.' | <a href="delete.php?id='.$cur_post['id'].'">'.$lang_topic['Delete'].'</a> | <a href="edit.php?id='.$cur_post['id'].'">'.$lang_topic['Edit'].'</a>'.' | <a href="post.php?tid='.$cur_post['id'].'">'.'Reply'.'</a>'.' | <a href="post.php?tid='.$cur_post['id'].'&qid='.$cur_post['id'].'">'.$lang_topic['Quote'].'</a>'.' | <a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'">'.'Read More'.'</a></span>'."\n\n\n\n";
?>
        </td>
    </tr>
</table>
</ul>
        </div>
    </div>
</div>
<?
}
     }
else
{
    }
     ?>
<br />
<br />

<?php
require PUN_ROOT.'footer.php';
My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

33

Re: New frontpage index mod!

here what i got so far...

[b]now this is for only mega PUN ONLY!!!![/b
]

<?php
 
define('PUN_ROOT', './');
define('PUN_QUIET_VISIT', 1);
require PUN_ROOT.'include/common.php';
 
//Set the page title here
$page_title = pun_htmlspecialchars($pun_config['o_board_title']);
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';
require PUN_ROOT.'include/parser.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/topic.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';


//$newsid = '1'; //This is the forum the news is retrieved from
//$newsdisplay = '5'; //This is how many news articles are displayed.
function pun_news($fid='', $show=15, $truncate=350)
{
    global $lang_common, $db, $pun_config, $pun_user, $db_prefix;
    $max_subject_length = 30;
    $show_max_topics = 50;
    $fid = intval($fid);
    $order_by = 't.posted';
    $forum_sql = '';
    // Was a forum ID supplied?
    if ( $fid ) $forum_sql = 'f.id='.$fid.' AND ';
    $show = intval($show);
    if ($show < 1 || $show > $show_max_topics)
    $show = 15;
    $saveddate="";
$result = $db->query('SELECT t.id, t.subject, t.num_replies, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.forum_id, p.poster, p.poster_id, p.message, p.hide_smilies, p.posted, g.g_title, g.g_color, u.use_avatar,  f.id AS fid, f.forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON p.topic_id=t.id AND p.posted=t.posted INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE t.forum_id='.$fid.' AND t.moved_to IS NULL ORDER BY '.$order_by.' DESC') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
$show_count = 0;
    if ( !$db->num_rows($result) ) return $output;
    while ( ($show_count < $show) && ($cur_post = $db->fetch_assoc($result)) ) {
        $temp = '';
        if ($pun_config['o_avatars'] == '1' && $cur_post['use_avatar'] == '1' && $pun_user['show_avatars'] != '0')
        {
            if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif'))
                $user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif" '.$img_size[3].' title="'.$cur_post['poster'].'\'s Avatar" alt="'.$cur_post['poster'].'\'s Avatar" />';
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg'))
                $user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg" '.$img_size[3].' title="'.$cur_post['poster'].'\'s Avatar" alt="'.$cur_post['poster'].'\'s Avatar" />';
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png'))
                $user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png" '.$img_size[3].' title="'.$cur_post['poster'].'\'s Avatar" alt="'.$cur_post['poster'].'\'s Avatar" />';
        }
        else
            $user_avatar = '<img alt="" src="img/noimage.gif" />';
        if ($pun_config['o_censoring'] == '1')
            $cur_post['subject'] = censor_words($cur_post['subject']);
        if (pun_strlen($cur_post['subject']) > $max_subject_length)
            $subject_truncated = trim(substr($cur_post['subject'], 0, ($max_subject_length-5))).' ...';
        else

            $subject_truncated = $cur_post['subject'];
        $newsheading = '<div style="margin-top:-8px;"><img style="vertical-align: middle;" src="img/'.$pun_user['style'].'/icon_passive.gif" alt="" /> <a class="news-links" href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'" title="'.pun_htmlspecialchars($cur_post['subject']).'"><b>'.pun_htmlspecialchars($subject_truncated).'</b></a><br />Posted by: <a href="profile.php?id='.$cur_post['poster_id'].'"><span style="color:'.$cur_post['g_color'].'">'.pun_htmlspecialchars($cur_post['poster']).'</span></a> at '.date('h:i A', $cur_post['posted']).'<br /><a style="font-weight: normal;" href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'&action=last" title="'.pun_htmlspecialchars($cur_post['subject']).'">Comments: ('.$cur_post['num_replies'].')</a> | Reads: '.pun_htmlspecialchars($cur_post['num_views']).'</div>';

        // Group posts by date    
        $thisdate = date('l, d F Y', $cur_post['posted']);
        if ($thisdate != $saveddate) 
 
        {
            if ($saveddate)
            {
                $temp .= "</div></div>";
            }
            $temp .= '<div class="block"><h2><span><b>News:</b> '.$thisdate.'</span></h2><div class="box"><div class="inbox"><br />';
            $saveddate = $thisdate;
        }
        else {
            $temp .= '<div class="inbox"><hr /><br />';
        }
        $temp .= '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>
            <td style="border: 0px; width: 80%;">'.$newsheading.'</td></tr>
    <tr>
        <td style="border: 0px;" valign="top" align="left">';
        $id = $cur_post['id'];
        $msg = $db->query('SELECT id, poster, poster_id, poster_ip, poster_email, message, posted, edited, edited_by FROM '.$db_prefix.'posts WHERE topic_id='.$id.' LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
            if ( !$db->num_rows($msg) ) continue;
        $cur_post = $db->fetch_assoc($msg);

        // Display first paragraph only (comment out next four lines to turn off)
        if ($truncate)
        {
            $paragraph = '';
            for ($numchar=0; $numchar<$truncate; $numchar++)
            {
                if (isset($cur_post['message'][$numchar]))
                    $paragraph .= $cur_post['message'][$numchar];
                else break;
            }
      if ($numchar > 300){
        $paragraph .= '...';
            $cur_post['message'] = $paragraph;
        }
        $cur_post['message'] = parse_message($cur_post['message'], 0);
       $temp .= ''.$cur_post['message'].'</td>
    <td align="right" style="border: 0px; width: auto;"><a href="profile.php?id='.$cur_post['poster_id'].'">'.$user_avatar.'</a></td>
  </tr>
</table><br />';

        if ($numchar > 300){
        $temp .= '<div style="width: auto; padding: 3px 0px 2px 5px; margin-bottom: 3px;" class="bookmarks_readmore"><span style="float: left;"><img src="../img/digg_icon.gif" alt="Digg!" title="Digg!" /> <a style="font-weight: normal;" href="http://digg.com/submit?phase=2&url='.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'&title='.urlencode($cur_post['subject']).'">Digg It</a> | <img src="../img/delicious_icon.gif" alt="del.icio.us" title="del.icio.us" /> <a style="font-weight: normal;" href="http://del.icio.us/post?url='.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'&title='.urlencode($cur_post['subject']).'">del.icio.us</a> </span><span style="float: right; margin-right: 6px; vertical-align: middle;">'.'<a href="misc.php?report='.$cur_post['id'].'">'.'Report'.'</a>'.' | <a href="delete.php?id='.$cur_post['id'].'">'.'Delete'.'</a>'.' | <a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'">'.'Read More'.'</a></span>'.'</div></div>';
        
        
        
}else {
        $temp .= '<div style="width: auto; padding: 3px 4px 2px 5px; margin-bottom: 3px;" class="bookmarks"><img src="../img/digg_icon.gif" alt="Digg!" title="Digg!" /> <a style="font-weight: normal;" href="http://digg.com/submit?phase=2&url='.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'&title='.urlencode($cur_post['subject']).'">Digg It</a> | <img src="../img/delicious_icon.gif" alt="del.icio.us" title="del.icio.us" /> <a style="font-weight: normal;" href="http://del.icio.us/post?url='.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'&title='.urlencode($cur_post['subject']).'">del.icio.us</a></div></div>';
        
    }
}
        if (isset($output)) {
            $output .= $temp;
        }
        else {
            $output = $temp;
        }
        ++$show_count;
    } // end of while
    $output .= "</div></div>";
    return $output;
}
if ($pun_config['o_index_message_show'] == 1)
{
?>

<?php
                }
        
?>


<?php


echo pun_news(1, 5, 350);
 
require PUN_ROOT.'footer.php';
My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

34

Re: New frontpage index mod!

here the code for mega pun ..

<?php
 
define('PUN_ROOT', './');
define('PUN_QUIET_VISIT', 1);
require PUN_ROOT.'include/common.php';
 
//Set the page title here
$page_title = pun_htmlspecialchars($pun_config['o_board_title']);
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';
require PUN_ROOT.'include/parser.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/topic.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';


//$newsid = '1'; //This is the forum the news is retrieved from
//$newsdisplay = '5'; //This is how many news articles are displayed.
function pun_news($fid='', $show=15, $truncate=350)
{
    global $lang_common, $db, $pun_config, $pun_user, $db_prefix;
    $max_subject_length = 30;
    $show_max_topics = 50;
    $fid = intval($fid);
    $order_by = 't.posted';
    $forum_sql = '';
    // Was a forum ID supplied?
    if ( $fid ) $forum_sql = 'f.id='.$fid.' AND ';
    $show = intval($show);
    if ($show < 1 || $show > $show_max_topics)
    $show = 15;
    $saveddate="";
$result = $db->query('SELECT t.id, t.subject, t.num_replies, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.forum_id, p.poster, p.poster_id, p.message, p.hide_smilies, p.posted, g.g_title, g.g_color, u.use_avatar,  f.id AS fid, f.forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON p.topic_id=t.id AND p.posted=t.posted INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE t.forum_id='.$fid.' AND t.moved_to IS NULL ORDER BY '.$order_by.' DESC') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
$show_count = 0;
    if ( !$db->num_rows($result) ) return $output;
    while ( ($show_count < $show) && ($cur_post = $db->fetch_assoc($result)) ) {
        $temp = '';
        if ($pun_config['o_avatars'] == '1' && $cur_post['use_avatar'] == '1' && $pun_user['show_avatars'] != '0')
        {
            if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif'))
                $user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif" '.$img_size[3].' title="'.$cur_post['poster'].'\'s Avatar" alt="'.$cur_post['poster'].'\'s Avatar" />';
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg'))
                $user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg" '.$img_size[3].' title="'.$cur_post['poster'].'\'s Avatar" alt="'.$cur_post['poster'].'\'s Avatar" />';
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png'))
                $user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png" '.$img_size[3].' title="'.$cur_post['poster'].'\'s Avatar" alt="'.$cur_post['poster'].'\'s Avatar" />';
        }
        else
            $user_avatar = '<img alt="" src="img/noimage.gif" />';
        if ($pun_config['o_censoring'] == '1')
            $cur_post['subject'] = censor_words($cur_post['subject']);
        if (pun_strlen($cur_post['subject']) > $max_subject_length)
            $subject_truncated = trim(substr($cur_post['subject'], 0, ($max_subject_length-5))).' ...';
        else

            $subject_truncated = $cur_post['subject'];
        $newsheading = '<div style="margin-top:-8px;"><img style="vertical-align: middle;" src="img/'.$pun_user['style'].'/icon_passive.gif" alt="" /> <a class="news-links" href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'" title="'.pun_htmlspecialchars($cur_post['subject']).'"><b>'.pun_htmlspecialchars($subject_truncated).'</b></a><br />Posted by: <a href="profile.php?id='.$cur_post['poster_id'].'"><span style="color:'.$cur_post['g_color'].'">'.pun_htmlspecialchars($cur_post['poster']).'</span></a> at '.date('h:i A', $cur_post['posted']).'<br /><a style="font-weight: normal;" href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'&action=last" title="'.pun_htmlspecialchars($cur_post['subject']).'">Comments: ('.$cur_post['num_replies'].')</a> | Reads: '.pun_htmlspecialchars($cur_post['num_views']).'</div>';

        // Group posts by date    
        $thisdate = date('l, d F Y', $cur_post['posted']);
        if ($thisdate != $saveddate) 
 
        {
            if ($saveddate)
            {
                $temp .= "</div></div>";
            }
            $temp .= '<div class="block"><h2><span><b>News:</b> '.$thisdate.'</span></h2><div class="box"><div class="inbox"><br />';
            $saveddate = $thisdate;
        }
        else {
            $temp .= '<div class="inbox"><hr /><br />';
        }
        $temp .= '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>
            <td style="border: 0px; width: 80%;">'.$newsheading.'</td></tr>
    <tr>
        <td style="border: 0px;" valign="top" align="left">';
        $id = $cur_post['id'];
        $msg = $db->query('SELECT id, poster, poster_id, poster_ip, poster_email, message, posted, edited, edited_by FROM '.$db_prefix.'posts WHERE topic_id='.$id.' LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
            if ( !$db->num_rows($msg) ) continue;
        $cur_post = $db->fetch_assoc($msg);

        // Display first paragraph only (comment out next four lines to turn off)
        if ($truncate)
        {
            $paragraph = '';
            for ($numchar=0; $numchar<$truncate; $numchar++)
            {
                if (isset($cur_post['message'][$numchar]))
                    $paragraph .= $cur_post['message'][$numchar];
                else break;
            }
      if ($numchar > 300){
        $paragraph .= '...';
            $cur_post['message'] = $paragraph;
        }
        $cur_post['message'] = parse_message($cur_post['message'], 0);
       $temp .= ''.$cur_post['message'].'</td>
    <td align="right" style="border: 0px; width: auto;"><a href="profile.php?id='.$cur_post['poster_id'].'">'.$user_avatar.'</a></td>
  </tr>
</table><br />';

        if ($numchar > 300){
        $temp .= '<div style="width: auto; padding: 3px 0px 2px 5px; margin-bottom: 3px;" class="bookmarks_readmore"><span style="float: left;"><img src="../img/digg_icon.gif" alt="Digg!" title="Digg!" /> <a style="font-weight: normal;" href="http://digg.com/submit?phase=2&url='.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'&title='.urlencode($cur_post['subject']).'">Digg It</a> | <img src="../img/delicious_icon.gif" alt="del.icio.us" title="del.icio.us" /> <a style="font-weight: normal;" href="http://del.icio.us/post?url='.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'&title='.urlencode($cur_post['subject']).'">del.icio.us</a> </span><span style="float: right; margin-right: 6px; vertical-align: middle;">'.' | <a href="post.php?tid='.$cur_post['id'].'">'.'Reply'.'</a>'.' | <a href="edit.php?id='.$cur_post['id'].'">'.'Edit'.'</a>'.' | <a href="misc.php?report='.$cur_post['id'].'">'.'Report'.'</a>'.' | <a href="delete.php?id='.$cur_post['id'].'">'.'Delete'.'</a>'.' | <a href="post.php?tid='.$cur_post['id'].'&qid='.$cur_post['id'].'">'.'Quote'.'</a>'.' | <a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'">'.'Read More'.' | </a></span>'.'</div></div>';
        
        
        
}else {
        $temp .= '<div style="width: auto; padding: 3px 4px 2px 5px; margin-bottom: 3px;" class="bookmarks"><img src="../img/digg_icon.gif" alt="Digg!" title="Digg!" /> <a style="font-weight: normal;" href="http://digg.com/submit?phase=2&url='.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'&title='.urlencode($cur_post['subject']).'">Digg It</a> | <img src="../img/delicious_icon.gif" alt="del.icio.us" title="del.icio.us" /> <a style="font-weight: normal;" href="http://del.icio.us/post?url='.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'&title='.urlencode($cur_post['subject']).'">del.icio.us</a></div></div>';
        
    }
}
        if (isset($output)) {
            $output .= $temp;
        }
        else {
            $output = $temp;
        }
        ++$show_count;
    } // end of while
    $output .= "</div></div>";
    return $output;
}
if ($pun_config['o_index_message_show'] == 1)
{
?>

<?php
                }
        
?>


<?php


echo pun_news(1, 5, 350);
 
require PUN_ROOT.'footer.php';
My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

35 (edited by Dr.Jeckyl 2007-06-18 16:57)

Re: New frontpage index mod!

can you make it miniportal compatible?

never mind... bingiman's is. big_smile thanks guys.

~James
FluxBB - Less is more

Re: New frontpage index mod!

addition: this should be added to the miniportal on the wiki as an optional index page.

~James
FluxBB - Less is more

37

Re: New frontpage index mod!

That tag closer almost..... works perfectly. big_smile The following makes it throw an extra couple of closing tags in though, and I ain't figured out where/why yet:

<span style="color: #FF0000">Red</span> <span style="color: #008000">Green</span></span></span>

The last two spans are purely gratuitous. big_smile

Re: New frontpage index mod!

Are those spans in the $append? If so leave them open.

39

Re: New frontpage index mod!

soonotes wrote:

Are those spans in the $append? If so leave them open.

Have removed the append. smile Already have the read more setup where I'm trying to jemmy it, so that bit's unneeded. smile It's purely between the <p> </p> tags that it's adding the extras. I think it's the following where the problem is initially occuring:

if (preg_match_all ('/<([a-z\:\-]+)[ >]/', $string, $start_tags))

Re: New frontpage index mod!

Wish I could help. That's the point where it becomes greek to me smile

41

Re: New frontpage index mod!

I ain't much better on that bit. big_smile The mix of pcre and multi key arrays ain't exactly the easiest to figure. big_smile

42 (edited by quaker 2007-06-18 18:21)

Re: New frontpage index mod!

thanks for everyone help on this..... but now im going to recode it for miniportal  take it back to the way i had it first looking...
truncate kewl but a pain to fingure out... and specially when i dont know what im doing and it works..hahaha.....
so im going back to the first design i had.
Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

43 (edited by quaker 2007-06-18 18:44)

Re: New frontpage index mod!

bing if you look at the code that validates. u will notice that it not displaying the user name that posted the article.
Posted on: 2007-01-17 12:06:20 by:  |  Views: 7 |  Replies: 0  that what i see in ie7 and FF!

<a href="profile.php?id='.$cur_post['poster_id'].'" class="username">'.pun_htmlspecialchars($cur_post['poster']).'</a>
My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

Re: New frontpage index mod!

I already fixed it...thanks

45 (edited by bingiman 2007-06-19 01:14)

Re: New frontpage index mod!

Here is my final coding for the index.php. I will post this one here with hopes that someone will add the truncate function to it. Not the Mega Pun version. I prefer this layout.

<?php
 
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
 
//Set the page title here
$page_title = pun_htmlspecialchars($pun_config['o_board_title']);

define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';
require PUN_ROOT.'include/parser.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/topic.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';

$newsid = '1'; //This is the forum the news is retrieved from
$newsdisplay = '5'; //This is how many news articles are displayed.

if ($pun_config['o_index_message_show'] == 1)
{
?>
 
        <div class="block">
            <h2><span><?php echo pun_htmlspecialchars($pun_config['o_index_message_head']) ?></span></h2>
            <div class="box">
                <div class="inbox">
        <?php echo $pun_config['o_index_message'] ?>
                </div>
            </div>
        </div>
<?php
}
$result = $db->query('SELECT t.id, t.subject, t.num_replies, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.forum_id, u.use_avatar, p.poster, p.poster_id, p.message, p.hide_smilies, p.posted, g.g_title, f.forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON p.topic_id=t.id AND p.posted=t.posted INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE t.forum_id='.$newsid.' AND t.moved_to IS NULL AND f.redirect_url IS NULL ORDER BY t.posted DESC LIMIT '.$newsdisplay) or error('Unable to fetch announcements', __FILE__, __LINE__, $db->error());


        if ($db->num_rows($result))
                    {
                            while($cur_post = $db->fetch_assoc($result))
                            {
                                    $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
?>
    <div class="block">
       
<?php
        if ($pun_config['o_avatars'] == '1' && $cur_post['use_avatar'] == '1' && $pun_user['show_avatars'] != '0')
        {
            if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif'))
                $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif" '.$img_size[3].' title="'.$cur_post['poster'].'\'s Avatar" alt="'.$cur_post['poster'].'\'s Avatar" /></a>';
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg'))
                $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg" '.$img_size[3].' title="'.$cur_post['poster'].'\'s Avatar" alt="'.$cur_post['poster'].'\'s Avatar" /></a>';
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png'))
                $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png" '.$img_size[3].' title="'.$cur_post['poster'].'\'s Avatar" alt="'.$cur_post['poster'].'\'s Avatar" /></a>';
        }
        else
            $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img alt="" src="img/noimage.gif" /></a>';
    echo "\t\t\t\t\t\t\t".'<h2><strong><a href="forum.php">Forum</a> » <a href="viewforum.php?id='.$cur_post['forum_id'].'">'.pun_htmlspecialchars($cur_post['forum_name']).'</a>'.'</strong></h2>'."\n";
?>
<div class="box">
    <div class="inbox">
<ul><li>
<div style="padding-bottom: 6px;" ><a class="news_subject" href="viewtopic.php?id=<?php echo $cur_post['id']; ?>"><strong><?php echo $cur_post['subject']; ?></strong></a></div>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td style="border: 0px; width: 90%;"><?php echo $cur_post['message']."\n" ?></td>
    <td align="right" style="border: 0px; width: 10%;" valign="top"><?php echo $user_avatar ?></td>
  </tr>
</table>
<br />
<br />
<table class="news_footer" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td width="100%">
<?php


    echo "\t\t\t\t\t\t\t".'<span class="byuser" style="float:left">Posted: '.format_time($cur_post['posted']).' by:<span class="byuser'.(isset($cur_post['g_title']) ? ' '.strtolower(str_replace(' ', '', $cur_post['g_title'])) : '').'"> <a href="profile.php?id='.$cur_post['poster_id'].'" class="username">'.pun_htmlspecialchars($cur_post['poster']).'</a> |  Views: '. $cur_post['num_views'].' |  Replies: '. $cur_post['num_replies'].'</span></span>'."\n";
        if ($cur_post['poster_id'] == $pun_user['id'] || $pun_user['g_id'] < PUN_GUEST)
    echo "\t\t\t\t\t\t\t".'<a style="text-decoration: none" href="viewtopic.php?id='.$cur_post['id'].'" class="username">'.pun_htmlspecialchars($lang_portal['Visit_Topic']).'</a>'.'<span style="float:right">'.'<a href="misc.php?report='.$cur_post['id'].'">'.$lang_topic['Report'].'</a>'.' | <a href="delete.php?id='.$cur_post['id'].'">'.$lang_topic['Delete'].'</a> | <a href="edit.php?id='.$cur_post['id'].'">'.$lang_topic['Edit'].'</a>'.' | <a href="post.php?tid='.$cur_post['id'].'">'.'Reply'.'</a>'.' | <a href="post.php?tid='.$cur_post['id'].'&qid='.$cur_post['id'].'">'.$lang_topic['Quote'].'</a>'.'</span>'."\n\n\n\n";
?>
        </td>
    </tr>
</table>
</ul>
        </div>
    </div>
</div>
<?
}
     }

     ?>
<br />
<br />

<?php
require PUN_ROOT.'footer.php';

46

Re: New frontpage index mod!

bing there is an issue if people dont have the avatar mod installed it will show up as a blank picture in ie7
this is the line that i removed on mine

<?php echo $user_avatar ?>

Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

47 (edited by bingiman 2007-06-18 22:11)

Re: New frontpage index mod!

Well, You don't need the avatar mod. All they would need to do is place a blank image called: noimage.gif in the images folder.

48

Re: New frontpage index mod!

true... i just too the code out and it works like a charm... I want to thank everyone that helped on this...
this was my truly fist go at a mod and it turned out good.

thanks again !

Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

Re: New frontpage index mod!

It will be perfect once we can get the text truncated. big_smile

50

Re: New frontpage index mod!

kewl... maybe one day..hahaha...


Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!