Archive

Archive for the ‘Programming’ Category

mIRC DLL: True Random Card Deck Generator

September 10th, 2009 Mark No comments

I’ve whipped up a quick dll for mIRC to generate random card decks that are as random as possible via random.org

Usage instructions are inside the archive, as is the Delphi source code (requires Indy10 for TIDHttp)

Edit: added alternative sourcecode which uses WinINet instead of Indy10.. results in a smaller DLL

Categories: Programming, Projects Tags: , , , , , ,

Akismet SPAM Filtering in phpBB3

June 3rd, 2009 Mark 6 comments

Recently I’ve been seeing a shitload of Spambot signups and actual spam postings on my Coopersguns BodyBuilding forums

phpBB 3 had a little spam hiatus whilst the spammers cracked the new captcha system, however it’s obviously been well and truly broken now

I decided to clean the forums up and get rid of the spammers. I have employed 2 techniques:

  1. A phpBB3 mod called daroPL_AntiSpam
  2. Some code I quickly conjured up to check with Akismet when a comment is posted

I will obviously be talking about the latter here, follows are instructions on how to implement the Akismet check on posts:

If you want to copy & paste the following code snippets, hover over them and click the ‘copy’ button

1) Download akismet-php-curl-class
2) Copy the akismet.curl.class.php from the archive to your phpBB3 forum’s ‘includes’ folder (e.g. ~/public_html/forums/includes)
3) Edit message_parser.php in the ‘includes’ folder and make the following changes:

Find:

if (!class_exists('bbcode'))
{
        include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
}

After it, insert the following

if (!class_exists('akismet')) {
        include($phpbb_root_path . 'includes/akismet.curl.class.' . $phpEx);
}

Find:

// Check number of links
if ($config['max_' . $mode . '_urls'] && $num_urls > $config['max_' . $mode . '_urls'])
{
	$this->warn_msg[] = sprintf($user->lang['TOO_MANY_URLS'], $config['max_' . $mode . '_urls']);
	return (!$update_this_message) ? $return_message : $this->warn_msg;
}

After it, insert the following:

// Akismet SPAM check
if (($user->data['user_posts']<=6) && ($user->data['user_type']==0)) {

	$akismet_comment = array(
	    'comment_type'              => 'comment',
	    'comment_author'            => $user->data['username'],
	    'comment_author_email'      => $user->data['user_email'],
	    'comment_author_url'        => $user->data['user_website'],
	    'comment_content'           => $this->message,
	);

	$akismet = new akismet('YOURAKISMETAPIKEYHERE','http://www.yourforums.com/forums');

	if(!$akismet->error) {

		if($akismet->valid_key()) {

			if($akismet->is_spam($akismet_comment)) {

				$this->warn_msg[] = $user->lang['AKISMET_SPAM'];
				$a_to = "you@youraddress.com";
				$a_subject = "Attempted SPAM Post by ".$user->data['username'];
				$a_body = $this->message;
				$a_headers = "From: admin@yourforums.com";
				mail($a_to, $a_subject, $a_body, $a_headers);

			}

		}

	}

}

4) Edit posting.php in the ‘language/en/’ folder (obviously you’ll need to add this to other languages your users use too)

Find:

        'TOO_FEW_CHARS'                         => 'Your message contains too few characters.',

After it, insert the following:

        'AKISMET_SPAM'                  => 'Your message looks like SPAM.',

5) Finished!

Secpay, Actinic & SSL lameness

October 30th, 2007 Mark 1 comment

Currently when enabling SSL on shopping cart pages in Actinic, Actinic will no longer be able to link up Secpay transactions to orders.

After numerous hours debugging, I figured out what was going wrong.. when SSL is enabled on shopping cart pages, Actinic provides Secpay with HTTPS callbacks – as you’d expect. It also sets a parameter which Secpay needs if the callbacks are HTTPS. However for some reason at this moment in time Secpay won’t use the HTTPS callbacks – the request is never sent to the server

I don’t know why this is happening, I even used the alternative method of informing Secpay that the callback is HTTPS – via the ‘options’ parameter.. no dice

The solution I’m currently using is to modify the ‘OCCSecPayScriptTemplate.pl’ file, inserting a line after the following block of code:

# to enable Diners cards, remove the ‘#’ from the start of the 2 lines below
#$sOptions .= ‘,’ if ($sOptions ne ”);
#$sOptions .= ‘diners=true’;

the line to change the callback URLs back to HTTP is:

$::sCallBackURLAuth =~ s/https/http/;

phpBB mods: bbcode for ifilm, youtube and google video embedding

September 21st, 2006 Mark 16 comments

I wanted to be able to embed videos from various services into forum posts on CoopersGuns Health, Fitness & BodyBuilding Forums so I decided to have a play with modifying the bbcode processor and here’s what I’ve come up with..

Modification instructions

Make the following modifications to forum/includes/bbcode.php

  • Find the bbencode_first_pass function
  • Locate the end of the function

	// Remove our padding from the string..
	return substr($text, 1);
  • Add the following just before the above:

	// [ifilm] and [/ifilm]
	$text = preg_replace("#\[ifilm=([0-9]+[,][0-9]+[,][0-9]+)\](.*?)\[/ifilm\]#si", "[ifilm=\\1:$uid]\\2[/ifilm:$uid]", $text);

	// [youtube] and [/youtube]
	$text = preg_replace("#\[youtube=([0-9]+[,][0-9]+[,][0-9a-z\-_]+)\](.*?)\[/youtube\]#si", "[youtube=\\1:$uid]\\2[/youtube:$uid]", $text);

	// [gvid] and [/gvid]
	$text = preg_replace("#\[gvid=([0-9]+[,][0-9]+[,][0-9a-z\-_]+)\](.*?)\[/gvid\]#si", "[gvid=\\1:$uid]\\2[/gvid:$uid]", $text);
  • Find the bbencode_second_pass function
  • Locate the part that deals with [QUOTE]

	// [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
	$text = str_replace("[quote:$uid]", $bbcode_tpl['quote_open'], $text);
	$text = str_replace("[/quote:$uid]", $bbcode_tpl['quote_close'], $text);
  • Add the following code after the above:

	// [ifilm] and [/ifilm]
	$text = preg_replace("#\[ifilm=([0-9]+)[,]([0-9]+)[,]([0-9]+):$uid\](.*?)\[/ifilm:$uid\]#si", "", $text); 	

	// [youtube] and [/youtube]
	$text = preg_replace("#\[youtube=([0-9]+)[,]([0-9]+)[,]([0-9a-z\-_]+):$uid\](.*?)\[/youtube:$uid\]#si", ""."[/youtube:$uid]", $text);
	$text = str_replace("[/youtube:$uid]", "", $text); 		

	// [gvid] and [/gvid]
	$text = preg_replace("#\[gvid=([0-9]+)[,]([0-9]+)[,]([0-9a-z\-_]+):$uid\](.*?)\[/gvid:$uid\]#si", ""."[/gvid:$uid]", $text);
	$text = str_replace("[/gvid:$uid]", "", $text);
  • Save your changes to bbcode.php and upload the modified file (if you downloaded it to modify)

That’s it.. you can now embed iFilm, YouTube and Google Video videos into your forum posts

Usage

The syntax is similar for all three:

[ifilm=width,height,id]description[/ifilm]

[youtube=width,height,id]description[/youtube]

[gvid=width,height,id]description[/gvid]

Example:
CoopersGuns Health, Fitness & BodyBuilding Forums Post

Categories: Internet, Programming, Website Tags:

WordPress’ TinyMCE Popup Width In Firefox

July 13th, 2006 Mark 7 comments

I’m surprised there isn’t much about this online.. although I admit my search wasn’t very comprehensive

Anyway, for a while now I’ve been a bit annoyed with the TinyMCE editor in WordPress.. for example, when you click the “Insert/edit link” button on the toolbar, a popup window is launched which proceeds to resize itself to be a less than useful width

Apparently according to one of the developers of TinyMCE in this thread, it’s down to Firefox using the status bar width when it shouldn’t

Anyway, the fix is as follows:

Just after the statements below in tiny_mce_popup.js

   // Netscape 7.1 workaround
   if (this.isWindow && tinyMCE.isNS71) {
      window.resizeBy(0, 10);
      return;
   }

Add the following:

   // Gecko workaround
   if (this.isWindow && tinyMCE.isGecko) {
      window.resizeBy(20, 10);
      return;
   }

That seems to work alright and resize the window to a useable width!

Categories: Programming, WebDev Tags:

Google Desktop Sidebar & Delphi

October 14th, 2005 Mark No comments

Recently I’ve been trying to produce a plugin using Delphi Win32 for Google Desktop 2 Beta – a Sidebar plugin.

Unfortunately my knowledge of COM isn’t great and my knowledge of COM in Delphi is even less. However I have learned what I think is enough and cannot seem to solve the problems I’m experiencing. No amount of posting to the Google Desktop Developer Group seems produce replies on the subject.

This is a plea for anybody who can program in Delphi to produce an example Sidebar plugin!

Categories: Programming Tags: