101

Re: New frontpage index mod!

MattF wrote:
bingiman wrote:

hmm..Maybe MattF can look into that. I also found a problem. If I set for example 2 forums to display then the max setting which is (5) really has no effect. It displays way more than that. If however I remove the second forum, then it displays the correct amount of posts. Any solution for this issue and the one Connorhd mentioned.

Cheers!

Right. We'll start afresh. What do you want the script to do? Rather than adding bits that you want to the script you had, what exactly do you want the script to achieve, working from a blank start? Btw, the max setting is per forum, not overall.

Well it might make sense, but i don't think it was intended, and its actually more efficient to do one query and order it using that (a similar query using an array of ids is here http://punbb.org/forums/viewtopic.php?pid=96967#p96967)

102

Re: New frontpage index mod!

It is workable and does what it is intended to do. The problem that I am having is what I explained above. When I set a second forum it displays more than the set items on the page. I want it to be able to display 5 items regardless of the amount of forums being displayed on the main page. Hope you understand what I am trying to say.

103

Re: New frontpage index mod!

bingiman wrote:

It is workable and does what it is intended to do. The problem that I am having is what I explained above. When I set a second forum it displays more than the set items on the page. I want it to be able to display 5 items regardless of the amount of forums being displayed on the main page. Hope you understand what I am trying to say.

Right, so five subjects in total, irrelevant of how many forums your pulling from? How would you then decide what to display if you had six forums in the array? How many posts to display from each forum? The absolute latest posts overall to be displayed, irrelevant of which forum they're in? That's why I'm asking. That is an extremely vague answer you've given.

104

Re: New frontpage index mod!

Connorhd wrote:

Well it might make sense, but i don't think it was intended, and its actually more efficient to do one query and order it using that (a similar query using an array of ids is here http://punbb.org/forums/viewtopic.php?pid=96967#p96967)

The question, though, was simply, can items be displayed from more than one forum. That is a very misinterpretable question. big_smile Btw, totally agree on the lookup/query bit. This only started out as helping on the truncation feature, however, not a full rewrite. big_smile big_smile

105

Re: New frontpage index mod!

lol MattF

If you're going to rewrite it you may want to have the query check for read permissions also.

106 (edited by bingiman 2007-06-23 22:36)

Re: New frontpage index mod!

Well, considering that I am not a coder I really could not answer your complexed questions MattF. All I was trying to do was to get the index to display 5, 10, 15 posts. I don't know how many it will pull from each forum. Is it possible for it to pull a set amount from a variable like the $newsdisplay for example. So something like:

$newsid = array();
$newsid[] = '1, 2posts';
$newsid[] = '4, 3 posts';

etc...

Please do not crucify me. I really am lost with all this coding and to give specifics as to how it can all be done is way beyond me and this is why I am asking for the help. If it can't be done, then I accept that.

107

Re: New frontpage index mod!

soonotes wrote:

lol MattF

If you're going to rewrite it you may want to have the query check for read permissions also.

Don't you start too. big_smile big_smile big_smile

108

Re: New frontpage index mod!

bingiman wrote:

Well, considering that I am not a coder I really could not answer your complexed questions MattF. All I was trying to do was to get the index to display 5, 10, 15 posts. I don't know how many it will pull from each forum. Is it possible for it to pull a set amount from a variable like the $newsdisplay for example. So something like:

$newsid = array();
$newsid[] = '1, 2posts';
$newsid[] = '4, 3 posts';

etc...

Please do not crucify me. I really am lost with all this coding and to give specifics as to how it can all be done is way beyond me and this is why I am asking for the help. If it can't be done, then I accept that.

Not trying to crucify you, just to get a specific answer on how exactly you want it to behave. big_smile big_smile

Anything is possible, (within reason), big_smile but the description of how you want it to behave is still vague. It can pull as few or many posts onto the index page as you wish, but you have to decide *which posts* you want on the index page. For example, do you only want the latest posts from the forums overall? Do you, for example, want the last two posts from each forum until X limit is reached? If more forums are designated than total topics allowed, do you want topics total or per forum totals to override one or the other? Honestly, I'm not intending to sound tardy, and apologies if I do, but I still can't visualise exactly what your exact preference is for its behaviour.

Getting it to stick to an overall total is no problem whatsoever. The bit that's vague is exactly how you want it to discriminate on which topics/posts it shows within that total. smile I'll have a go at getting it doing what you want when I have chance, but the more specific you can be, the better. With that example you gave above, would you want specific totals per forum with no overall total, or an overall total that would override forum totals if it was exceeded, or vice-versa?

109 (edited by bingiman 2007-06-23 23:44)

Re: New frontpage index mod!

fair enoguh MattF. What I would like is this.

Display a set of forums in $newsdisply so that's we are clear on. I would then like it to display the latest topics from each forum. So if I set the $newsdisplay to display the 5 latest topics, then it should display the 5 topics from the a specific forum or I can choose 5 latest topics from 5 forums. Or another way would be to pull 5 latest topics from each forum but only display a set amount depending on the $newsdisplay setting, so if I had:

forum1, forum2 and forum3 then

forum1 displays 2 topics (latest)
forum2 displays 2 topics (latest)
forum3 displays 1 topic (latest)


Hope this makes more sense for you.

Or here is a scenario with a few settings in the index file which I would love to see. I am sure this must be very hard to code.

$newsdisplay = 1,2,3,4etc...;
$amtofpost = 2; // per forum
$totalpost = 5; // a total pull from all forums (if 5 forums are used, then it just defaults to the $newsdisplay max setting)
$disp_first_latest = $first // displays first post of each forum ubt the latest post, so if I started a new thread in that forum, it will display that post and not a reply to it. If set to $latest, the it displays the latest reply to that post.

whew! Hope you follow.

110 (edited by complete 2007-06-23 23:44)

Re: New frontpage index mod!

I have been keeping a eye on this thread, Quaker and I have been discussing it on Punres.org
http://www.punres.org/viewtopic.php?id=3508


Can you make the feeds pull from 2 different threads.

For example:

Have 1 news feed pull from say a category / thread called: Recent News

Have another feed pull from a different category / thread called: Annoucements


Have 1 have priority or rankings over the other, so it will show up before, or above the other on the frontpage.

I am have no real experience in coding, so don't laugh at me. But maybe something of this sort.



$newsid = array();
$newsid[] = '1, 2posts';
$newsid[] = '4, 3 posts';


$newsid2 = array();
$newsid2[] = '1, 2posts';
$newsid2[] = '4, 3 posts';

111

Re: New frontpage index mod!

I guess everyone wants the index.php to be a mile long.. trying to add all of the first or second post of there forum.

Simply pull the topics from a news category is fine with me...

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 !!!

112

Re: New frontpage index mod!

Now that I can understand Bingiman. big_smile I'll have a diddle at some of those features over the next few days when I've chance. For now, I've altered the last one slightly:

http://outgoing.bauchan.org/unix/multi-index2.php.txt

You have a single lookup, (a variation of Connors code as I couldn't get his snippet to work, but that may be a pgsql thing, so let me know if it works okay with mysql), which pulls the latest X amount of topics from all designated forums, specified in the script by:

$forumids = array(1,2);

Just use the same comma separation for any further forums you want to add. For example:

$forumids = array(1,2,3,4,5);

There is no per forum limit at the moment.


Changed the $newsdisplay variable to:

$master_limit

Just seemed more relevant if the other changes are doable. big_smile big_smile


Have got rid of the | - - | if the topic isn't truncated.



Let me know if the sql query works on mysql. smile

113 (edited by bingiman 2007-06-24 01:40)

Re: New frontpage index mod!

It works great. The only thing is that it lists the posts in reverse. By that I mean Forum ID2 is listed before Forum ID1 even thought it is set as:
$forumids = array(1,2); Other than that it is great. big_smile

Edit: I guess because it is pulling the latest the order is correct? meaning that if my last post was in forum 2 then it will be displayed at top.

114

Re: New frontpage index mod!

Glad to hear that sql query is okay. Cheers. smile For the ordering, I believe that's how it's working. Sql ain't my forte. big_smile I'll see if I can figure that out.

115 (edited by bingiman 2007-06-24 02:14)

Re: New frontpage index mod!

That's ok, I actually like it like that. It makes sense to have it that way, so that the latest post will always appear at the top regardless of the forum.

Thank you so much for your help. I really, really appreciate all that you've done. smile


I did forget to ask you another favor in my previous post. Would it be hard to add a link replies so that when I click on it, it takes me to that reply nut if there are no replies it just shows the text Replies: with no URL.

Cheers!
Bingiman

116

Re: New frontpage index mod!

You mean like this?

http://outgoing.bauchan.org/unix/multi-index3.php.txt

117

Re: New frontpage index mod!

That is awesome.  Is the line below:

$forumids = array(1,2);
$numposts = array(3,7); <--- this one. does this mean 3 post from forum #1 will be displayed and 7 posts will be displayed for forum #2?

Thanks again

118

Re: New frontpage index mod!

I take it that was what you wanted then? big_smile big_smile

Delete that second array line. It's doing nowt. I was going to have a quick go at the forum/post count thing, but couldn't get the brain in gear on it yet, so gave up. big_smile

119

Re: New frontpage index mod!

yes, that is what I wanted. It works perfectly.

120 (edited by MattF 2007-06-24 03:14)

Re: New frontpage index mod!

If there's anything else you think of, just build the list up in this thread. Can't say when I'll have chance to get round to attempting the other additions, but I'll have a diddle when I can. smile No promises that I'll be able to manage 'em though. big_smile big_smile

121

Re: New frontpage index mod!

MattF wrote:

You have a single lookup, (a variation of Connors code as I couldn't get his snippet to work, but that may be a pgsql thing, so let me know if it works okay with mysql)

Just as an addendum to that bit, muppet boy here has just twigged that the code Connorhd posted on the other thread was for the miniportal mod. So, that is Connor's query adaptation adapted for this index mod. big_smile Cheers Connor. smile

122 (edited by quaker 2007-06-24 04:23)

Re: New frontpage index mod!

i really do like this code. I want to thank everyone for helping out. i have added some info about the user to this script...
Q

demo link follows: http://nalan.org/8.php can we say final release?

<?php
 
define('PUN_ROOT', './');
require_once 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_once PUN_ROOT.'header.php';
require_once PUN_ROOT.'include/parser.php';
require_once PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';
require_once PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
require_once PUN_ROOT.'lang/'.$pun_user['language'].'/topic.php';
require_once PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';
require_once PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';

//----------------------------------------------------------------------//

//These are the forums from which the news is retrieved
$forumids = array(1,2);

//This is the overall limit for how many news items will be displayed
$master_limit = '10';

//This is the amount of characters above which truncation will occur
$trunc_chars = '100';

//----------------------------------------------------------------------//

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
}

//----------------------------------------------------------------------//

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

        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 irrelevant tags
    $xhtml_tags = array ('</img>', '</hr>', '</br>');
    $string = str_replace ($xhtml_tags, '', $string);
    return $string;
}

//----------------------------------------------------------------------//

function truncate($string)
{
global $pun_config;
$trunc_chars = '100';
$length = $trunc_chars;
$append = ' ..... ';

    if (strlen ($string) <= $length)
    {
        return $string;
    }
    else if ($length > 0)
    {
        preg_match ('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$length.',}\b#U', $string, $matches);
        $string = $matches[0];
        $string = close_tags (preg_replace ('#\s*<[^>]+>?\s*$#', '', $string).$append);
        return $string;
    }
}

//----------------------------------------------------------------------//

$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, u.num_posts, u.registered, u.title, 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 IN ('.implode(',', $forumids).') AND t.moved_to IS NULL AND f.redirect_url IS NULL ORDER BY t.posted DESC LIMIT '.$master_limit) or error('Unable to fetch announcements', __FILE__, __LINE__, $db->error());

if ($db->num_rows($result))
{
    while($cur_post = $db->fetch_assoc($result))
    {
        echo '<div class="block">';
        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 src="img/noimage.gif" alt=""/></a>';
        }

        $news_message = parse_message($cur_post['message'], $cur_post['hide_smilies']);

        if (pun_strlen($news_message) > $trunc_chars)
        {
            $news_message = truncate($news_message);
            $read_more = ' | <a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'">Read More</a> | ';
        }
        else
        {
            $read_more = ' | ';
        }

        if ($cur_post['num_replies'] != '0')
        {
            $replies = ' <a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_post['id'].'#p'.$cur_post['last_post_id'].'">Replies</a>: '.$cur_post['num_replies'].' ';
        }
        else
        {
            $replies = ' Replies: '.$cur_post['num_replies'].' ';
        }

        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>
        <table cellSpacing="0" cellPadding="0" width="100%" border="0">
            <tr>
            <td style="border: 0px; padding: 0px 10px 7px 7px;"><a class="news_subject" href="viewtopic.php?id=<?php echo $cur_post['id']; ?>"><strong><?php echo $cur_post['subject']; ?></strong></a></td>
            </tr>
        </table> 
        <table cellSpacing="0" cellPadding="0" width="100%" border="0">
            <tr>
            <td align="left" style="white-space: nowrap; width: 8em; padding-left: 7px; padding-top: 6px; padding-bottom: 30px; border: 0px;" valign="top"><?php echo $user_avatar ?><p></p><strong><?php echo pun_htmlspecialchars($cur_post['poster']) ?></strong><p></p><?php echo 'Title: '.$cur_post['g_title'] ?><p></p><?php echo 'Total Post: '.$cur_post['num_posts'] ?><p></p><?php echo 'Registered Date: '. format_time($cur_post['registered'], true) ?></td>
            <td style="text-align: left; border: 0px; padding-top: 0px;" valign="top"><?php echo $news_message."\n" ?></td>
            </tr>
        </table>
        <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="user" style="float:left">Posted: '.format_time($cur_post['posted']).' by:<span class="user'.(isset($cur_post['g_title']) ? ' '.strtolower(str_replace(' ', '', $cur_post['g_title'])) : '').'"> <a class="poster" href="profile.php?id='.$cur_post['poster_id'].'">'.pun_htmlspecialchars($cur_post['poster']).'</a>'.$read_more.'Views: '.$cur_post['num_views'].' |'.$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 href="viewtopic.php?id='.$cur_post['id'].'">'.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>       
        </li></ul>
        </div>
    </div>
</div>
<?php
    }
}
?>
        <div align="center">Theme Designed by: Shedrock - <a onclick="window.open(this.href); return false;" href="http://shednotes.com">shednotes.com</a></div>
        <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 !!!

123

Re: New frontpage index mod!

quaker wrote:

demo link follows: http://nalan.org/8.php can we say final release?

If you're thinking final, use version 4. I've stripped out all the unnecessary single quotes and full stops, and added  's instead of blank spaces. smile Just change the number to 4 on the link to download it.

124 (edited by bingiman 2007-06-24 11:39)

Re: New frontpage index mod!

@quaker. I would not call it final yet. Actually some users may not like all the extra flare added to it such as the title, total post, reg. date etc...They may find the main page topic over crowded. What may be a good idea is to have control over it in the user profile. This way members can turn on different options if they prefer. How's that for an idea? yes, yes..I have the ideas, I just cant code. big_smile


Also, you may not have noticed but that code has some info on it like them designed by Shedrock etc. This should be stripped from the script as well as the Welcome code at the very top.

125

Re: New frontpage index mod!

Here is a sample of the boxover script used with the FP news mod.

http://shedrockonline.com/filedump/boxed.jpg

Give me some feed back and let me know if I should include this as part or the final release.