CAPTCHA implementation to protecting comments from spam robots. Check plugin's settings under Options / SCaptcha menu. The handfont2.ttf was taken from Openfontlibrary.org. For more info, please read the readme.txt file from the installation package. Author: Silver Version: 0.2.1 Author URI: http://silver.balaton.to/ */ /* Copyright 2006 Silver (email : silver@balaton.to) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* ============================================================================= FUNCTIONS ============================================================================= */ /* ----------------------------------------------------------------------------- Adding admin menu ----------------------------------------------------------------------------- */ function s_captcha_adminmenu() { add_options_page("Silver's CAPTCHA", "SCaptcha", 10, __FILE__, 's_captcha_options'); } /* ----------------------------------------------------------------------------- Options page in admin menu ----------------------------------------------------------------------------- */ function s_captcha_options() { global $table_prefix, $wpdb; $s_table_data = $table_prefix . "s_captcha_data"; $s_table_conf = $table_prefix . "s_captcha_config"; if (isset($_POST["update"])) { $sql="UPDATE ".$s_table_conf." " . " SET cap_installed =1" . ", cap_use_grid =".$_POST['cap_use_grid'] . ", cap_use_background =0" . ", cap_use_random =1" . ", cap_ttf_path ='".$_POST['cap_ttf_path']."'" . ", cap_ttf_size =".$_POST['cap_ttf_size'] . ", cap_ttf_X =".$_POST['cap_ttf_X'] . ", cap_ttf_Y =".$_POST['cap_ttf_Y'] . ", cap_X_size =".$_POST['cap_X_size'] . ", cap_Y_size =".$_POST['cap_Y_size'] . ", cap_rotation =".$_POST['cap_rotation'] . ", cap_paper_color_R =".$_POST['cap_paper_color_R'] . ", cap_paper_color_G =".$_POST['cap_paper_color_G'] . ", cap_paper_color_B =".$_POST['cap_paper_color_B'] . ", cap_font_color_R =".$_POST['cap_font_color_R'] . ", cap_font_color_G =".$_POST['cap_font_color_G'] . ", cap_font_color_B =".$_POST['cap_font_color_B'] . ", cap_grid_color_R =".$_POST['cap_grid_color_R'] . ", cap_grid_color_G =".$_POST['cap_grid_color_G'] . ", cap_grid_color_B =".$_POST['cap_grid_color_B'] . ", cap_grid_spacing =".$_POST['cap_grid_spacing'] . ", cap_background_path =''".$_POST['cap_background_path'] . " limit 1"; $wpdb->query($sql); } $select = 'SELECT * FROM '.$s_table_conf.' LIMIT 1'; $row = $wpdb->get_row($select, ARRAY_A, 0); $cap_installed = $row['cap_installed']; $cap_use_grid = $row['cap_use_grid']; $cap_use_background = $row['cap_use_background']; $cap_use_random = $row['cap_use_random']; $cap_ttf_path = $row['cap_ttf_path']; $cap_ttf_size = $row['cap_ttf_size']; $cap_ttf_X = $row['cap_ttf_X']; $cap_ttf_Y = $row['cap_ttf_Y']; $cap_X_size = $row['cap_X_size']; $cap_Y_size = $row['cap_Y_size']; $cap_rotation = $row['cap_rotation']; $cap_paper_color_R = $row['cap_paper_color_R']; $cap_paper_color_G = $row['cap_paper_color_G']; $cap_paper_color_B = $row['cap_paper_color_B']; $cap_font_color_R = $row['cap_font_color_R']; $cap_font_color_G = $row['cap_font_color_G']; $cap_font_color_B = $row['cap_font_color_B']; $cap_grid_color_R = $row['cap_grid_color_R']; $cap_grid_color_G = $row['cap_grid_color_G']; $cap_grid_color_B = $row['cap_grid_color_B']; $cap_grid_spacing = $row['cap_grid_spacing']; $cap_background_path = $row['cap_background_path']; if ($cap_installed) $cap_installed_text = "YES"; else $cap_installed_text = "NO
(For first time installation, press the UPDATE OPTIONS button to show the captcha with plugin's defaults.)"; if ($cap_use_grid) $cap_use_grid_text = "YES"; else $cap_use_grid_text = "NO"; if ($cap_use_background) $cap_use_background_text = "YES"; else $cap_use_background_text = "NO"; if ($cap_use_random) $cap_use_random_text = "YES"; else $cap_use_random_text = "NO"; #$url = $wpdb->get_var("SELECT url FROM ".$blogringping_table." limit 1"); echo "
"; echo "
"; echo "

Silver's CAPTCHA:

"; echo "
"; echo ""; echo " "; echo ""; echo "
A random generated and a long example."; echo "
"; echo "
"; echo "Current settings"; echo "
    "; echo ""; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo "
    Installed:$cap_installed_text
    Image dimensions in pixels:".$cap_X_size."x".$cap_Y_size."
    Font path:$cap_ttf_path
    Font size in points:$cap_ttf_size
    Font's start position:X: $cap_ttf_X, Y: $cap_ttf_Y
    Text rotation:$cap_rotation degrees
    Show grid:$cap_use_grid_text
    Grid spacing in pixels:$cap_grid_spacing
    Image background color:Red: $cap_paper_color_R, Green: $cap_paper_color_G, Blue: $cap_paper_color_B      
    Text color:Red: $cap_font_color_R, Green: $cap_font_color_G, Blue: $cap_font_color_B      
    Grid color:Red: $cap_grid_color_R, Green: $cap_grid_color_G, Blue: $cap_grid_color_B      
    "; echo ""; echo "Edit CAPTCHA options"; echo "
      "; echo "
    "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo "
    Image dimensions in pixels:x
    Font path:
    Font size in points:
    Font's start position:X: , Y:
    Text rotation: degrees
    Show grid:
    Grid spacing in pixels:
    Image background color:Red:\n"; echo " "; echo ", Green: "; echo " "; echo ", Blue: \n"; echo " "; echo "
    Text color:Red:\n"; echo " "; echo ", Green: "; echo " "; echo ", Blue: \n"; echo " "; echo "
    Grid color:Red:\n"; echo " "; echo ", Green: "; echo " "; echo ", Blue: \n"; echo " "; echo "
    Update options:
    "; echo ""; echo ""; echo ""; echo ""; /* echo "
    "; echo "URL:

    "; echo ""; echo "

    "; $wpdb->flush(); */ } /* ----------------------------------------------------------------------------- Making random seed ----------------------------------------------------------------------------- */ function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } function s_get_fontpath() { global $_GET; $s_plugin_path = $_GET["plugin"]; $s_nix_path = str_replace("\\", "/", $s_plugin_path); $s_path = getcwd(); $s_path = str_replace("\\", "/", $s_path); $s_pos = strrpos($s_path, "wp-admin"); $s_path = substr($s_path, 0, $s_pos); $s_path.= "wp-content/plugins/"; $s_pos = strrpos($s_nix_path, "/"); $s_nix_path = substr($s_nix_path, 0, $s_pos); $s_path.= $s_nix_path; $s_lastfont=""; if ( $s_dirID = opendir($s_path) ) { while ( false !== ($s_file = readdir( $s_dirID )) ) { if ($s_file != "." && $s_file != "..") { #echo "$s_file\n"; if ( strtolower(substr($s_file, -4, 4)) == ".ttf" ) $s_lastfont=$s_file; } } closedir($s_dirID); } $s_path.="/".$s_lastfont; /* $h=fopen("c:/log.txt","w"); fwrite($h,"PATH: ".$s_path); fclose($h); */ return $s_path; } /* ----------------------------------------------------------------------------- This function will install the needed tables if they does not exists. If the data table exists, it will be empty. ----------------------------------------------------------------------------- */ function s_captcha_install() { global $table_prefix, $wpdb, $_GET; $s_table_data = $table_prefix . "s_captcha_data"; $s_table_conf = $table_prefix . "s_captcha_config"; $s_font_path = s_get_fontpath(); if($wpdb->get_var("show tables like '$s_table_data'") != $s_table_data) { require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); $sql = 'CREATE TABLE '.$s_table_data.' (' . ' captcha_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, ' . ' captcha_str VARCHAR(32) NOT NULL,' . ' PRIMARY KEY (captcha_id),' . ' INDEX (captcha_str)' . ' )'; dbDelta($sql); } // if data table not exists else { $delete = 'DELETE FROM '.$s_table_data; $results = $wpdb->query( $delete ); } if($wpdb->get_var("show tables like '$s_table_conf'") != $s_table_conf) { require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); $sql = 'CREATE TABLE '.$s_table_conf.' (' . ' cap_installed TINYINT(1) NOT NULL, ' . ' cap_use_grid TINYINT(1), ' . ' cap_use_background TINYINT(1), ' . ' cap_use_random TINYINT(1), ' . ' cap_ttf_path VARCHAR(250), ' . ' cap_ttf_size INT, ' . ' cap_ttf_X INT, ' . ' cap_ttf_Y INT, ' . ' cap_X_size INT, ' . ' cap_Y_size INT, ' . ' cap_rotation INT, ' . ' cap_paper_color_R INT, ' . ' cap_paper_color_G INT, ' . ' cap_paper_color_B INT, ' . ' cap_font_color_R INT, ' . ' cap_font_color_G INT, ' . ' cap_font_color_B INT, ' . ' cap_grid_color_R INT, ' . ' cap_grid_color_G INT, ' . ' cap_grid_color_B INT, ' . ' cap_grid_spacing INT, ' . ' cap_background_path VARCHAR(250), ' . ' PRIMARY KEY (cap_installed) ' . ' )'; dbDelta($sql); $insert = "insert into ".$s_table_conf." VALUES (0, 1, 0, 1, '".$s_font_path."', 15, 5, 35, 115, 40, 10, 200, 200, 200, 100, 100, 100, 150, 150, 150, 5, '')"; $results = $wpdb->query( $insert ); } // if config table not exists } /* ----------------------------------------------------------------------------- Cleaning data table when the plugin will be deactivated. ----------------------------------------------------------------------------- */ function s_captcha_deactivate() { global $table_prefix, $wpdb, $_GET; $s_table_data = $table_prefix . "s_captcha_data"; $delete = 'DELETE FROM '.$s_table_data; $results = $wpdb->query( $delete ); } /* ----------------------------------------------------------------------------- Error message in an image ----------------------------------------------------------------------------- */ function s_captcha_errimage($errtitle,$errmsg) { $IMG_X = 150; $IMG_Y = 30; $image = imagecreate($IMG_X,$IMG_Y); $paper = imagecolorallocate( $image, 222,0,0 ); $pen = imagecolorallocate( $image, 255, 255, 255 ); imagestring($image, 3, 5, 4, $errtitle, $pen); imagestring($image, 1, 5, 18, $errmsg, $pen); $corners[0]=2; $corners[1]=2; $corners[2]=$IMG_X-3; $corners[3]=2; $corners[4]=$IMG_X-3; $corners[5]=$IMG_Y-3; $corners[6]=2; $corners[7]=$IMG_Y-3; imagepolygon($image,$corners,4,$pen); header("Content-type: image/jpg"); imagejpeg($image); } /* ----------------------------------------------------------------------------- Creating the image ----------------------------------------------------------------------------- */ function s_captcha_showimage() { global $table_prefix, $wpdb, $_GET; $s_table_conf = $table_prefix . "s_captcha_config"; $s_table_data = $table_prefix . "s_captcha_data"; $is_installed = $wpdb->get_var("SELECT cap_installed FROM ".$s_table_conf." limit 1"); if ($is_installed) { $select = 'SELECT * FROM '.$s_table_conf.' LIMIT 1'; $row = $wpdb->get_row($select, ARRAY_A, 0); if (!file_exists($row['cap_ttf_path'])) { s_captcha_errimage("Font not foud","Set SCaptcha under Options!"); die(); } if ($row['cap_use_random']) { srand(make_seed()); $RandomWord=""; while ( strlen($RandomWord)!=6 ) { $ChrCode=0; $IsNumber = mt_rand(0,1); if ($IsNumber) $ChrCode = mt_rand(50,57); # All numbers without zero and one else $ChrCode = mt_rand(65,90); $RandomWord .= chr( $ChrCode ); } if (isset($_GET['demo'])) if ($_GET['demo']=="2") $RandomWord="WWWWWW"; $SecretWord=md5($RandomWord); } $image = imagecreate($row['cap_X_size'],$row['cap_Y_size']); $paper = imagecolorallocate( $image, $row['cap_paper_color_R'], $row['cap_paper_color_G'], $row['cap_paper_color_B'] ); $font = imagecolorallocate( $image, $row['cap_font_color_R'], $row['cap_font_color_G'], $row['cap_font_color_B'] ); $grid = imagecolorallocate( $image, $row['cap_grid_color_R'], $row['cap_grid_color_G'], $row['cap_grid_color_B'] ); if ($row['cap_use_grid']) { for($i=$row['cap_grid_spacing'];$i<$row['cap_Y_size'];$i+=$row['cap_grid_spacing']) { imageline ( $image, 0, $i, $row['cap_X_size']-1, $i, $grid ); } for($i=$row['cap_grid_spacing'];$i<$row['cap_X_size'];$i+=$row['cap_grid_spacing']) { imageline ( $image, $i, 0, $i, $row['cap_Y_size']-1, $grid ); } } imagettftext($image, $row['cap_ttf_size'], $row['cap_rotation'], $row['cap_ttf_X'], $row['cap_ttf_Y'], $font, $row['cap_ttf_path'], $RandomWord); if (!isset($_GET['demo'])) { $insert = 'insert into '.$s_table_data.' (captcha_str) values (\''.$SecretWord.'\')'; $results = $wpdb->query( $insert ); } header("Content-type: image/jpg"); imagejpeg($image); } else { s_captcha_errimage("Not installed","Set SCaptcha under Options!"); } } /* ----------------------------------------------------------------------------- Examinig user's answer ----------------------------------------------------------------------------- */ function s_captcha_comment_post($comment_ID) { global $table_prefix, $wpdb, $_GET, $_POST; $s_table_data = $table_prefix . "s_captcha_data"; $EnteredWord = strtoupper(trim($_POST["s_captcha"])); $EncodedWord = md5($EnteredWord); $post_ID=-1; $mytable=$table_prefix."silvers_captcha"; $select = "SELECT captcha_id FROM ".$s_table_data." WHERE captcha_str='".$EncodedWord."' LIMIT 1"; if (($captcha_id = $wpdb->get_var( $select )) == null ) { // reading comment's post_ID if the comment is approved and showing $select = "SELECT comment_approved FROM ".$table_prefix."comments WHERE comment_ID=".$comment_ID." LIMIT 1"; $comment_approved = $wpdb->get_var( $select ); $select = "SELECT comment_post_ID FROM ".$table_prefix."comments WHERE comment_ID=".$comment_ID." LIMIT 1"; $post_ID = $wpdb->get_var( $select ); if ( ( $post_ID == null ) || ( $comment_approved == null ) ) { $wpdb->bail("

    Error establishing a database connection

    ". "Comment ID: ".$comment_ID."
    ". "Comment approved: ".$comment_approved."
    ". "

    Silver's captcha plugin can not ". "read the approval of the comment.

    "); die(); } else { // updating post's count $select = "SELECT comment_count from ".$table_prefix."posts WHERE ID=".$post_ID; if (($comment_count = $wpdb->get_var( $select )) == null ) { $wpdb->bail("

    Error establishing a database connection

    ". "

    Silver's captcha plugin can not ". "update posts table. (Stage 1)

    "); die(); } else { $comment_count--; $update="UPDATE ".$table_prefix."posts SET comment_count=".$comment_count." WHERE ID=".$post_ID." LIMIT 1"; $result = $wpdb->query( $update ); if (!$result) { $wpdb->bail("

    Error establishing a database connection

    ". "

    Silver's captcha plugin can not ". "update posts table. (Stage 2)

    "); die(); } } } // deleting comment $delete="DELETE FROM ".$table_prefix."comments WHERE comment_ID=".$comment_ID; $result = $wpdb->query( $delete ); if (!$result) { $wpdb->bail("

    Error establishing a database connection

    ". "

    Silver's captcha plugin can not ". "delete from the database. (Stage 1)

    "); die(); } } else { $delete="DELETE FROM ".$s_table_data." where captcha_id=".$captcha_id; $result = $wpdb->query( $delete ); if (!$result) { $wpdb->bail("

    Error establishing a database connection

    ". "

    Silver's captcha plugin can not ". "delete from the database. (Stage 2)

    "); die(); } } } /* ============================================================================= Hanging our ACTIONS into hooks of WordPress ============================================================================= */ if (function_exists("add_action")) { // if this plugin was called from the WordPress add_action('activate_'.$_GET["plugin"],'s_captcha_install'); add_action('deactivate_'.$_GET["plugin"],'s_captcha_deactivate'); add_action('admin_menu', 's_captcha_adminmenu'); add_action('comment_post', 's_captcha_comment_post'); } else { // if this plugin was called as an image resource require_once("../../../wp-config.php"); require_once("../../../wp-includes/wp-db.php"); $wpdb=new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); s_captcha_showimage(); } ?> Brannstroms.se » About us

    The Brännström family websitePosts RSS Comments RSS

    The Brännström family is Stefan, Kyllie, Madison (Maddie) and Jonas. We currently live in a small village called Vaikijaur which is located just outside Jokkmokk which is a small town in northern Sweden.

    We arrived in Sweden in December 2005 to spend a few years with Stefan’s family, the plan is to stay for 3 years but right now we are just playing it by ear and waiting to see what our future holds.

    Here’s some aerial pictures of our place taken from Google Earth

    Aerial view of Jokkmokk town Aerial view of Vaikijaur Aerial view of our place

    If you have Google Earth installed on your computer you can google our house. If not, get Google Earth here. It’s a really cool (and free) software…

    Leave a Reply

    8 Feb 2012 10:47 pm

    Sunrise
    Sunset
    Current temperature12.9°C
    Warmest today13.4°C
    Coldest today10.6°C
18206 visitors since 3/1-2007