Archive for the ‘Web Apps’ Category

Odd and Even Forums and Hot Icons for PunBB

Tuesday, February 12th, 2008
Posted in PunBB

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.') );
}
}

Gallery2 vs Zenphoto vs Plogger

Tuesday, February 5th, 2008
Posted in Web Apps · Tags: , ,

Here I cover some of the features of the best open source PHP image gallery web applications.

Gallery 2

  • Multiple uploads via JavaScript (can add more file upload boxes)
  • Uploads by e-mail, ZIP or multiple image files
  • Configurable to run from multiple sites from one install
  • Reorder album via JavaScript
  • Ratings
  • Plugins available
  • Can’t protect original sizes of images

Zenphoto

  • Multiple uploads via JavaScript (can add more file upload boxes)
  • Uploads by ZIP or multiple image files
  • Spam filter options (Akismet, CAPTCHA, SpamAssassin, …)
  • Reorder album via JavaScript
  • AJAX editing of albums and images
  • Ratings
  • Watermarks
  • Can’t protect original sizes of images (except with a watermark)
  • RSS feed

Plogger

  • No multiple uploads via JavaScript (can’t add more file upload boxes)
  • Uploads by ZIP or single image files
  • Import from folder (you can FTP all images to a folder and have it import the images from that folder)
  • You can protect the original size images
  • RSS feed

All of these have a clean interface and design, search, EXIF data, subfolder/album creation, cruft-free URLs (for SEO), and comments (Gallery requires the comments plugin to be enabled).

It comes down to what your needs are, if you want something that can run on multiple sites Gallery 2 is the app to choose. If you have to protect your original size images you’ll want to use Plogger. I personally think Zenphoto has the most to offer and the best design out of the bunch, but they are all very well done. I went through all the ones on OpenSourceCMS and these were the best. Coppermine is popular but it’s too ugly and the admin is kind of confusing.

More PunBB Styling

Monday, February 4th, 2008
Posted in PunBB

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;}

More Styling for PunBB

Saturday, February 2nd, 2008
Posted in PunBB

Here is some more CSS styling for PunBB (Note: I put my images in the img folder):

/*style the forum titles*/
.pun .block H2, .pun .blocktable H2 {background-image:url(../../img/bullet_toggle_minus.gif); background-position:10px 50%; background-repeat:no-repeat;}
/*icons for admin moderation links*/
li.postreport a {background:url(../../img/error.gif) no-repeat left 50%; padding-left:20px;}
li.postdelete a {background:url(../../img/delete.gif) no-repeat left 50%; padding-left:20px;}
li.postedit a {background:url(../../img/pencil.gif) no-repeat left 50%; padding-left:20px;}
li.postquote a {background:url(../../img/comment.gif) no-repeat left 50%; padding-left:20px;}
/*post link*/
.postlink a {background:url(../img/add.gif) no-repeat right 50%; padding-right:20px !important;}

Fixed the CSS for .postlink