Posts Tagged ‘code’

Last Modified Posts in WordPress

Saturday, March 8th, 2008
Posted in Web Apps · Tags: ,

Want to show the last posts you updated in WordPress? This shows the posts you went back and updated or modified, which is different than your recent posts.


<?php
query_posts('showposts=10&orderby=modified&order=DESC');
if (have_posts())
{
echo '<h3>Last Modified Posts</h3>';
echo '<ul>' . "\n";
while (have_posts()) : the_post();
echo '<li>';
echo '<a href="' . get_permalink() . '">' . the_title('','', false) . '</a>';
echo '</li>' . "\n";
endwhile;
echo '</ul>';
}
?>

RSS feeds in PunBB

Saturday, March 8th, 2008
Posted in PunBB · Tags:

These are quick easy hacks to get RSS feeds for each forum on the index.php page and viewforum.php pages.

I covered how to put the main RSS feed on PunBB already.

Open up index.php and after this line

$forum_field = '<h3><a href="viewforum.php?id='.$cur_forum['fid'].'">'.pun_htmlspecialchars($cur_forum['forum_name']).'</a></h3>';

Add this

$forum_field .= '<div class="forum_rss"><a class="rss" href="extern.php?action=active&type=RSS&fid='.$cur_forum['fid'].'"><span>RSS</span></a></div>';/

Now open up viewforum.php and find this line

<h2><span><?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?></span></h2>

and modify it to be

<h2><span><?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?> <a class="rss" href="extern.php?action=active&type=RSS&fid=<?php echo $id /*MODIFIED - RSS*/ ?>"><span>RSS</span></a></span></h2>

And now for the CSS

.forum_rss {float:right;}
a.rss {background:url(../../img/feed.png) no-repeat left; width:16px; height:16px; padding-left:20px;}
a.rss span {display:none;}

Odd and Even Forums and Hot Icons for PunBB

Tuesday, February 12th, 2008
Posted in PunBB · Tags:

PunBB adds classes for odd and even posts, but not for odd and even forum rows. PunBB also adds several classes for icons we can tap into, but there is no way to know if a topic is “hot”. Let’s add a hack that will mark any topic that has more than 25 posts as “hot” and setup odd and even forum rows.

Open up viewforum.php

Find this line

// If there are topics in this forum.
if ($db->num_rows($result))
{

And add this afterwards

$temp_counter = 0;

Then find this line

// Should we show the "New posts" and/or the multipage links?
if (!empty($subject_new_posts) || !empty($subject_multipage))
{
$subject .= '  '.(!empty($subject_new_posts) ? $subject_new_posts : '');
$subject .= !empty($subject_multipage) ? ' '.$subject_multipage : '';
}

And add this afterwards

$temp_counter++;

Then find this line

<tr<?php if ($item_status != '') echo ' class="'.trim($item_status).'"'; ?>>

And modify it to be this instead

<tr class="<?php
/*MODIFIED*/
if ($temp_counter % 2)
echo 'forum_rowodd';
else
echo 'forum_roweven';
//hoticon
$temp_status = trim($item_status);
if (($cur_topic['num_replies'] > 25) && ($temp_status == '' || $temp_status == 'inew'))
{
if ($temp_status == '')
echo ' ihot';
else
echo ' ihot_inew';
}
else if ($item_status != '')
echo ' '.trim($item_status);
/*MODIFIED END*/ ?>">

Now for CSS

/*style rows*/
tr.forum_rowodd {background-color:#eee;}
tr.forum_rowodd td.tc2, tr.forum_rowodd td.tc3 {background-color:#ddd;}
tr.forum_roweven {background-color:#ccc;}
tr.forum_roweven td.tc2, tr.forum_roweven td.tc3 {background-color:#bbb;}
/*style hot and hot new posts*/
tr.ihot div.icon {background-image:url(../../img/hot.png);}
tr.ihot_inew div.icon {background-image:url(../../img/hot_new.png);}
/*css we used for icons before*/
div.icon {
float:left;
display:block;
width:28px;
height:25px;
background-repeat:no-repeat;
background-position:center center;
border:0 !important;
}
/*if you aren't using any images you can use something like this
tr.ihot DIV.icon {BORDER-COLOR: #600 #700 #800 #900}
tr.ihot_inew DIV.inew {BORDER-COLOR: #006 #007 #008 #009}
*/

I updated code the code, since I didn’t like how it was before

WordPress Spam Prevention Hack

Sunday, February 10th, 2008
Posted in Web Apps · Tags: , ,

Akismet catches a lot of spam, but there is a lot it won’t catch. Therefore I decided to put together a hack to catch some more. The hack has 2 options:

  • One for you to put in spam words that if they are in the comment, the whole comment will be considered spam. Just be careful, if you add cialis you will block the word specialist also.
  • The other option lets you set the maximum number of links you will allow in a comment.

It will catch links that start with http://, https://, http://www., https://www. and www.. WordPress doesn’t convert text like example.com into a link.

The hack also checks to see if there is more content in the comment than just A tag(s), if there isn’t it’s considered spam. I recommend to use this with the Akismet plugin because it won’t prevent all spam. Keep in mind this hack may not work with other spam prevention plugins.

Open up wp-comments-post.php and after these lines

if ( '' == $comment_content )
wp_die( __('Error: please type a comment.') );

Add the following:

else /*MODIFIED - added this else to filter strings and count links*/
{
//OPTIONS
$link_limit = 3;//set the maximum number of links we allow
$disallowed_strings = array('[url', '[/url]', 'zithromax', 'levaquin');//add any strings you wont allow, make them lowercase, we test for case insensitivity later
//END OPTIONS
$temp_comment = strtolower($comment_content);//lowercase text so we can be case insensitive, php4 doesnt have stripos
$total_disallowed_strings = count($disallowed_strings);
//look for disallowed strings
for ($temp_counter = 0; $temp_counter < $total_disallowed_strings; $temp_counter++)
{
if (strpos($temp_comment, $disallowed_strings[$temp_counter]) !== false)
{
wp_die( __('Sorry, that looks like spam.') );
}
}
$comment_links = 0;
//regex would be better
$link_strings = array('http://www.', 'https://www.', 'http://', 'https://', 'www.');//order is important here
$temp_comment = str_replace($link_strings, '[LINK]', $temp_comment);
$comment_links = substr_count($temp_comment, '[LINK]');
//test for number of links
if ($comment_links > $link_limit)
{
wp_die( __('Sorry, that looks like spam.') );
}
//weed out all A tags and see if anything is left
$temp_comment = preg_replace('/<a[^\<]{1,}\<\/a\>/', '', $temp_comment);
$temp_comment = trim($temp_comment);
//see if the comment is nothing but links
if (empty($temp_comment))
{
wp_die( __('Sorry, that looks like spam.') );
}
}

More PunBB Styling

Monday, February 4th, 2008
Posted in PunBB · Tags:

Want to style the usertitles in PunBB based on their usertype (as in styling admins, moderators, members and guests)? Open up viewtopic.php and after this line
<div class="postleft">

We are going to modify the DL to this:

<dl class="<?php
if ($user_title == 'Administrator')
echo 'usertype_admin';
else if ($user_title == 'Moderator')
echo 'usertype_mod';
else if ($user_title == 'Member')
echo 'usertype_member';
else if ($user_title == 'Guest')
echo 'usertype_guest';
?>">

I added it a little higher than you might of assumed, so you can style the username and avatars if you want also. Its easy to add new types if you have more groups than the standard ones.

Now for more CSS to make PunBB not so boring:

/*styles for the usertype hack*/
dd.usertitle {padding-left:20px; height:16px;}
dl.usertype_admin dd.usertitle {background:url(../img/award_star_gold_3.png) no-repeat left;}
dl.usertype_mod dd.usertitle {background:url(../img/bronze_medal.png) no-repeat left;}
dl.usertype_member dd.usertitle {background:url(../img/vcard.png) no-repeat left;}
dl.usertype_guest dd.usertitle {background:url(../img/status_offline.png) no-repeat left;}
/*style your announcements*/
DIV#announce H2 {BACKGROUND-COLOR:#ffc}
DIV#announce DIV.box {BORDER-COLOR:#f90 #f90 #f90}
DIV#announce DIV.inbox {BACKGROUND-COLOR:#ffc}
/*style errors*/
DIV#posterror H2 {BACKGROUND-COLOR:#bf3030; color:#ff0;}
DIV#posterror DIV.box {BORDER-COLOR:#bf3030 #bf3030 #bf3030}
DIV#posterror DIV.inbox {BACKGROUND-COLOR:#592d2d}
#posterror LI STRONG {COLOR:#ff0}
/*style messages (info boxes from punbb)*/
DIV#msg {color:#fff;}
DIV#msg H2 {BACKGROUND-COLOR:#bfbf8f; color:#000;}
DIV#msg DIV.box {BORDER-COLOR:#bfbf8f #bfbf8f #bfbf8f}
DIV#msg DIV.inbox {BACKGROUND-COLOR:#808060}
DIV#msg a {color:#89d9ff;}
DIV#msg a:hover {color:#b8ffff;}
/*style even row posts, odd posts will get default styling already set to them*/
DIV.roweven DIV.box, DIV.roweven DIV.postright, DIV.roweven DIV.postfootright {BACKGROUND-COLOR:#c9c}
DIV.roweven DIV.postright, DIV.roweven DIV.postfootright {BORDER-LEFT-COLOR:#dad}
DIV.roweven DIV.postleft, DIV.roweven DIV.postfootleft, DIV.roweven DIV.blockpost LABEL {BACKGROUND-COLOR:#dad;}
DIV.roweven H2 {BACKGROUND-COLOR:#fcc}
DIV.roweven DIV.box {BORDER-COLOR:#fcc #fcc #fcc}
/*style first post*/
DIV.firstpost DIV.box, DIV.firstpost DIV.postright, DIV.firstpost DIV.postfootright {BACKGROUND-COLOR:#c96 !important;}
DIV.firstpost DIV.postright, DIV.firstpost DIV.postfootright {BORDER-LEFT-COLOR:#da7 !important}
DIV.firstpost DIV.postleft, DIV.firstpost DIV.postfootleft, DIV.firstpost DIV.blockpost LABEL {BACKGROUND-COLOR:#da7 !important}
DIV.firstpost DIV.box {BORDER-COLOR:#fc9 #fc9 #fc9 !important}
DIV.firstpost H2 {BACKGROUND-COLOR:#fc9 !important;}
div.firstpost h2 span a, div.firstpost h2 span a:link, div.firstpost h2 span a:visited {color:#ccc !important;}
DIV.firstpost DIV.postright .postmsg {background:url(../../img/firstpost.png) no-repeat top right;}