1 (edited by quaker 2007-06-16 18:26)

Topic: New frontpage index mod!

I have modified the news portal to show some functions .
im working on a new index.php for my site. to display news ! well i wanted a few extra items to show.
by who,date,how many viewed it?,and replies. with some functions of report,edit,delete,and reply back.
this image is when a admin is login.
http://nalan.org/ni.png

this image is when a guest is viewing it.
http://nalan.org/nin.png



this is where you set the forum id and how many you want to display on the index.php
http://nalan.org/ni2.png

and now here is the code!

<?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.

$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, 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
echo "\t\t\t\t\t\t\t".'<p><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></p>'."\n";
?>
<div class="box">
                <div class="inbox">

<ul>
<a href="viewtopic.php?id=<?php echo $cur_post['id']; ?>"><strong> » <?php echo $cur_post['subject']; ?></a></strong>
<?php echo $cur_post['message']."\n" ?><br />

<br />
<?php
echo "\t\t\t\t\t\t\t".'<p style="float:right"><strong>  Posted '.format_time($cur_post['posted']).' <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>'.'
|  Viewed:'. $cur_post['num_views'].' |  Replies:'. $cur_post['num_replies'].' | </strong></p>'."\n";
?>




<br /><br /><br />

<?
  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> | </span>'."\n\n\n\n";
 
                            
?>
<br />
</ul>
<br />
 </div>
            </div>
        </div>
<?
}
 }
else
{

 }
     ?>

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

2

Re: New frontpage index mod!

looks rather nice. Although, i feel that the code could be organized in a much better way.

Re: New frontpage index mod!

This is totally awesome. You should have it so that it truncates to a set amount of text. Something like I have in Mega Pun. I think it would be great because then you will have too much clutter on the front page. Maybe add a read more link?

Shedrock

Re: New frontpage index mod!

thanks tubby, this is my first go at it. designing it from the portalnews.php and the latesttopic.php and viewforum.php and viewtopics.php
Bing, ill add that to it. im trying to learn the db and structure so i think for the first round i did very good.

Tubby could u help me with the cleanup? i know there some lang files that i dont need in there,but what the heck they are there..hahaha......
i did this today in about 2 hrs..... not bad for not knowing anything about sql and querys.

Bing, truncates.... hummmm. ill look at the file and see what i can do.. is that the index.php or another file in MEGA PUN>>>>>

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 is the index.php in Mega Pun that has the modded news. As for cleaning up your index.php file. I managed to make it 100% W3C compliant. I can post it here or let me know when you come on to MSN.

Shedrock

Re: New frontpage index mod!

There is something wrong with this mod. If you try to edit or delete a specific post on the front page, it reads a different post therefore it will delete the wrong post.

Re: New frontpage index mod!

ok i got the edit part from vewitopic. $cur_post  i had to use that string from the db to get it working.. maybe ill just take that out.
sure you can post ur code. that what i wanted to do every one help so it will be better...ahahaha...

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

8

Re: New frontpage index mod!

bingiman wrote:

This is totally awesome. You should have it so that it truncates to a set amount of text. Something like I have in Mega Pun. I think it would be great because then you will have too much clutter on the front page. Maybe add a read more link?

Shedrock

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

Re: New frontpage index mod!

so mattf how can this be fixed?

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

10

Re: New frontpage index mod!

i moved then post name down from the h2 bar i wanted it to be different. than other scripts.

>>Test Post

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

11

Re: New frontpage index mod!

quaker wrote:

so mattf how can this be fixed?

Don't think there is any easy way to do it with php. Unless I've missed something major in my manual delving, it has nowhere near the text abilities of, say, shell scripting. big_smile It's either truncate at a preset character count for convenience, or don't if you want to retain W3C strict compliance.

12

Re: New frontpage index mod!

MattF wrote:
quaker wrote:

so mattf how can this be fixed?

Don't think there is any easy way to do it with php. Unless I've missed something major in my manual delving, it has nowhere near the text abilities of, say, shell scripting. big_smile It's either truncate at a preset character count for convenience, or don't if you want to retain W3C strict compliance.

understand that. I think til someone makes a compliant css the world will be mixed up for FF opera and IE6 & 7.


i thought of using the truncate script but i preferred this script to start with. since i sorta understood it functions. i wanted to add more to it.
once i have the bugs out i will convert this to a mod for punportal and frontpage mods etc. so u can display more than 1 forum news at a time on the front page.

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!

MattF wrote:
bingiman wrote:

This is totally awesome. You should have it so that it truncates to a set amount of text. Something like I have in Mega Pun. I think it would be great because then you will have too much clutter on the front page. Maybe add a read more link?

Shedrock

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.

Re: New frontpage index mod!

@Quaker - How can I fix that issue with the edit and delete function?

Re: New frontpage index mod!

Here is my code. It should validate now. This still doesn't have the fix for the Edit and Delete functions.

<?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.

$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, 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
    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>
<?php echo $cur_post['message']."\n" ?><br /><br />

<?php
    echo "\t\t\t\t\t\t\t".'<hr /><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></span>'."\n\n\n\n";
?>
<br />
</ul>
        </div>
    </div>
</div>
<?
}
 }
else
{

 }
     ?>
<br />
<br />

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

16

Re: New frontpage index mod!

give me a sec to load it on one of my sites.....

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

17

Re: New frontpage index mod!

bling when i loaded it on http://bunpai.com/test12.php and i login i clicked edit
i can edit the post ... so what are you talking about ?

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

18

Re: New frontpage index mod!

i see i need to add quote as well to the functions..haha

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

19

Re: New frontpage index mod!

i have added the quote functions...

<?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.

$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, 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
    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>
<?php echo $cur_post['message']."\n" ?><br /><br />

<?php
    echo "\t\t\t\t\t\t\t".'<hr /><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";
?>



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

Re: New frontpage index mod!

I couldn't figure out who "Bling" was and then I figured it must be Bingiman you're meaning to type. big_smile Anyway, I see it works on your site but it is not working on mine. I am using a fresh install of punBB 1.2.14 updated to 1.2.15 and this shouldn't cause the problem. I currently have 3 test post. If I click on the post with ID#1 all the options work just fine. However, if I have other posts on the frontpage the result with edit is the wrong post. The quote also does not work for me. I get a "bad request"

Re: New frontpage index mod!

I must have screwed up something. Anyway, I re-installed pun and it all works now.

22 (edited by MattF 2007-06-18 01:40)

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.

You wouldn't happen to know how, would you? I have a feeling that delving through his blog code might be a somewhat long winded affair without knowing exactly which bit I'm searching for. big_smile

23

Re: New frontpage index mod!

i ran into a issue with parse.php error once but i took out some code and it worked. i hope to continue working on this . my goal is to add the latest topics to the top of the page. sorta like the main page of http://bunpai.com but i got to figure out how to add another sql query to it. how to close that one and open a new one..haha...
this is a learning curve for me.

oh a side note im about to start another project with the contact.php . how can i add captcha to it. im starting to get spam threw that since my register is got captcha...ill post what code i got so far in a new threat. but it not finished nor does it work.


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!

I also asked soonotes if he can assist with the truncate feature so I am just waiting on his response.

Shedrock

25

Re: New frontpage index mod!

kewl are you on msn?
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 !!!