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 » Guestbook

    The Brännström family websitePosts RSS Comments RSS

    Guestbook

    Please add yourself to our guestmap and sign our Guestbook. Thanks!

    One Guestbook Entry

    1. on 16 Jan 2010 at 1:12 pmsandra rönnqvist

      Jag saknar dig maddie

    2. on 07 Dec 2009 at 9:55 amGunilla Falk

      Hej familjen Brännström, det är grannen som hälsar på!
      Såg Kyllies bild på fototävlingen (lokaldelen), en sagolikt vacker bild.
      Har tittat runt på er hemsida……trevlig och internationell.
      Tänk vad världen blivit liten sedan datorerna slog ner i våra hem.

      MVH / Gunilla

    3. on 26 Jan 2009 at 2:15 pmAmanda

      Hejsan kul att du hade kommenterat min blogg fina bilder hälsa alla du mee <3<3

    4. on 24 Oct 2008 at 3:21 pmMaree

      Kyllie, the town you live in is beautiful, typical Nordic scenery, so tranquil. The children are gorgeous, Maddie is so much like you. The buns you cooked were tempting, I wouldn’t mind having a go at them myself. Take Care Kyllie, will talk again soon.

      Aunty Maree.

    5. on 17 Jun 2008 at 2:49 pmGranny Franny

      Hi Kylles,

      Love the photos and videos - just like being back there. I can’t believe how the kids have grown - wow. They are georgeous.

      Where is my recipe of those curly buns you made for me when I was there? I still have the sugary stuff to put on the top and the paper cups to cook them in - all I need are the instructions.

      Love to all
      Granny Franny

    6. on 09 May 2008 at 10:09 amNicole

      Hi Kyllie
      Your family is drop dead gorgeous, ty for sharing them with me.
      Please stay in touch, would love to hear whats happening in your life.
      Nicole xx

    7. on 19 Apr 2008 at 5:05 amNooi

      Hi Chooka, I see you came out of blog retirement to mention our bundle of joy! I think you need to come home and meet her haha Kind of a long way I know. Take care of your beautiful family.

      xxxx

    8. on 09 Jul 2007 at 2:08 pmAsh & Fab

      Hi Kyllie,

      so good to hear from you, love the web site great way show your way of life over in sweeden.

      Sounds like you have really settled in, take care I will send some pics soon.

    9. on 17 Apr 2007 at 12:27 pmDarren Shone

      Dear Kyllie

      Good to hesr from you. Great website. Missing photos of you however. Hand the camera over and upload some or send me a family photo by email.

      Catch up with you again soon.

    10. on 06 Apr 2007 at 7:57 amSabby

      Very envious that you have done so well with getting a website up and running to keep all the friends and rele’s up to date on life in Sweden…I know my family expect that with all the years I have spent on the computer I should have had something as impressive for them to be updated with.. Love all the pics too.. still wanna come and visit.. summer looks really lovely….

    11. on 05 Apr 2007 at 8:26 amFranny

      That’s fabulous. I couldn’t wait until I answered my month’s worth of e-mails that had banked up while my computer was in hospital - I had to have a sneak peek.
      Wish I were there …..

      love Granny Franny

    12. on 01 Apr 2007 at 9:19 amJohn Dunne

      Hi There

      Great website! Good to catch up on all your news. We only have eight weeks to go before we become parents for the first time!!

      Keep in touch.

      JD

    13. on 30 Mar 2007 at 11:19 pmBen & leisa

      G’day you crazy swede’s, love the website, most impressive!

      Very jealous that you’ve been to the ice hotel!!
      Will talk again soon

      Ben Leisa and Kaleb

    Sign Our Guestbook

    Enter characters from the image:

18206 visitors since 3/1-2007