Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Pondelok, 22. júl 2024

Súbor: [Platon] / Metafox / libpub / RotateAntispam / RotateAntispam.php (stiahnutie)

Revízia 1.9, Fri Jun 9 15:12:59 2017 UTC (7 years, 1 month ago) by igor


Zmeny od 1.8: +1 -1 [lines]

changed functions mysql_* to mysqli_* for PHP/7.0

<?php
/**
 *    RotateAntispam - antispamamova ochrana pomocou rotovania obrazku
 *
 *    tato trieda sluzi na:
 *    - ochranu formulara pred vyplnanim robotmi
 *
 *    Autor:        Igor Mino, igor@platon.sk
 *    Autor napadu:    Daniel Ivanis, daniel.ivanis@gmail.com
 *
 *                Copyright (c) 2012 Platon Technologies, s.r.o., http://platon.sk/
 *                All rights reserved.
 *
 *    verzia:        1.00, 2011-02-22 17:16
 *                1.01, 2012-03-26 17:22  Igor
 *                1.02, 2012-05-11 10:51  Igor
 *                1.03, 2012-10-02 10:20  Igor
 *                1.04, 2013-02-27 09:56  Igor
 *                1.05, 2013-08-05 16:43  Igor
 *                1.06, 2013-10-07 15:50  Igor
 *                1.07, 2015-10-21 12:40  Igor - fix pozicie siveho screenu
 *
 */

class RotateAntispam {
    // ====[ Definovanie premennych ]==========================================

    /**
     *    definovane premenne pre beh RotateAntispam - SUKROMNE
     */

    // chybova sprava
    // znakova hodnota
    protected $errorMessage = '';

    // ukladanie roznych poznamok pocas vykonavania, pomoze pri debugovani
    // znakova hodnota
    protected $log = '';

    // ak nastala chyba, koly ktorej nie je mozne pokracovat, tak TRUE
    // logicka hodnota
    protected $isError = false;

    // ak je nastaveny debug mod, tak pri chybe nenastane DIE() - aby bolo mozne vypisat logy
    protected $debug = false;
    
    // obrazok, ktory sa pouzije pre narotovanie
    protected $image = '';
    
    // nazov polozky s odpovedou
    protected $answer_name = '';
    
    // ID tlacitka, ktorym sa odosiela formualr
    protected $submit_name = null;
    
    // URL k triede RotateAntispam
    protected $urlRotateAntispam = '';
    
    // vysledok kontroly odpovede
    protected $correctAnswer_cache = null;
    
    // vystupne kodovanie
    protected $outputEncoding = 'UTF-8';
    
    // texty
    protected $texts = array(
        'title' => 'Antispam',
        'description' => 'Otočte obrázok do vodorovnej polohy.',
        'submit' => 'OdoslaĹĽ',
        'cancel' => 'ZruĹĄiĹĽ'
    );
    
    // informacie o obrazku
    protected $imageInfo = array(
        'width' => null,
        'height' => null,
        'type' => null,
        'mime' => null
    );
    
    // konfiguracia vzhladu
    protected $design = array(
        // Left Button
        'leftButtonColor' => '#000',
        'leftButtonColorHover' => '#fc0',
        'leftButtonBorderColor' => '#ccc',
        'leftButtonImage' => '',
        'leftButtonImageHover' => '',
        // Right Button
        'rightButtonColor' => '#000',
        'rightButtonColorHover' => '#fc0',
        'rightButtonBorderColor' => '#ccc',
        'rightButtonImage' => '',
        'rightButtonImageHover' => '',
    );
    
    // ====[ Konstruktor ]=====================================================
    
    /**
     *  konstruktor, nastavenie behu RotateAntispam
     *
     *  @param  array    $opts        - nastavenie jednotlivych hodnot pre beh RotatoAntispam
     *  @param  array    $opts['debug']            - nastavenie DEBUG modu
     *  @param  array    $opts['image']            - nastavenie defaultneho obrazka
     *  @return void
     */
    public function __construct($opts = array()) {
        $this->addLog('Spusteny konstruktor');

        if (isset($opts['debug'])
            && is_bool($opts['debug']))
        {
            $this->debug = $opts['debug'];
            $this->addLog('Debug nastaveny na hodnotu ' . (($this->debug) ? 'TRUE' : 'FALSE'));
        } else {
            $this->debug = false;
            $this->addLog('Debug bol nastaveny na default hodnotu FALSE');
        }
        
        if (isset($opts['image'])
            && is_string($opts['image']))
        {
            if ($this->setImage($opts['image'])) {
                $this->addLog('Obrazok pre rotovanie bol nastaveny');
            } else {
                   $this->setError('Chyba pri nastavovani obrazku');
            }
        } else {
            $this->setError('Nebol nastaveny obrazok pre rotovanie');
        }
        
        if (isset($opts['answer_name'])
            && is_string($opts['answer_name']))
        {
            $this->answer_name = $opts['answer_name'];
        } else {
            $this->answer_name = 'answer_name_'.Time();
        }
        $this->addLog('Nazov polozky odpovede bol nastaveny na hodnotu "'.$this->answer_name.'"');
        
        if (isset($opts['submit_name'])
            && is_string($opts['submit_name']))
        {
            $this->submit_name = $opts['submit_name'];
            $this->addLog('Nazov tlacitka pre odosielanie formulara bol nastaveny');
        } else {
            $this->addLog('Nazov tlacitka pre odosielanie formulara NEBOL nastaveny');
        }

        if (isset($opts['url'])
            && is_string($opts['url']))
        {
            if ($this->setUrlRotateAntispam($opts['url'])) {
                $this->addLog('URL pre RotateAntispam bola nastavena');
            } else {
                $this->addLog('URL pre RotateAntispam NEBOLA nastavena');
            }
        } else {
            $this->setError('URL pre RotateAntispam NEBOLA zadana');
        }
        
        if (isset($opts['encoding'])
            && is_string($opts['encoding']))
        {
            if ($this->setOutputEncoding($opts['encoding'])) {
                $this->addLog('Vystupne kodovanie bolo nastavene na hodnotu '.$this->outputEncoding);
            } else {
                $this->addLog('Vystupne kodovanie NEBOLO nastavene na hodnotu '.$opts['encoding']);
            }
        }
    }
    
    // ====[ Metody pre zaznamenanie chyb a logov ]============================
    /**
     *  nastavi chybovu spravu, ktoru je v mozne vyziadat pomoocu getErrorMessage()
     *
     *  @param  string  $msg            - chybova sprava
     */
    protected function setErrorMessage($msg) {
        $msg = 'Error: "'.$msg.'"';
        $this->addLog($msg);
        $this->errorMessage = $msg;
    }

    /**
     *  nastavi chybovu spravu a priznak chyby
     *
     *  @param  string  $msg            - chybova sprava
     */
    protected function setError($msg) {
        $this->setErrorMessage($msg);
        $this->isError = true;
        if (!$this->debug) {
            $message = 'Error: Nastala chyba pri behu RotateAntispam. Nasleduju zaznamenavane poznamky pocas behu objektu RotateAntispam:'."\n"
                    .'Umiestnenie RotateAntispam: '.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."\n"
                    ."\n"
                    .str_replace("<br>", "\n", $this->getLog())
                    ."\n"
                    ."Koniec spravy.";
            die($msg);
        }
    }

    /**
     *  vrati ci nastala chyba
     *
     *  @return bool                - ak nastala chyba vrati TRUE, inak FALSE
     */
    public function isError() {
        return $this->isError;
    }

    /**
     *  varati poslednu chybovu spravu
     *
     *  @return string                - posledna chybova sprava
     */
    public function getErrorMessage() {
        return $this->errorMessage;
    }

    /**
     *  prida poznamku pre neskorsi debug
     *
     *  @param  string $msg            - poznamka
     */
    protected function addLog($msg) {
        if ($this->debug) {
            $init_log = '--[ RotateAntispam ]----------------------------------------------------';
            if (strpos($this->getLog(), $init_log) === false) {
                echo '<script type="text/javascript">console.log("'.$init_log.'");</script>';
                $this->log .= $init_log.'<br>';
            }
            $msg = str_replace("\n", '', $msg);
            $msg = str_replace("\r", '', $msg);
            echo '<script type="text/javascript">console.log("'.addslashes($msg).'");</script>';
        }
        $this->log .= $msg.'<br>';
    }

    /**
     *  vrati vsetky poznamku
     *
     *  @return string                - poznamky, ktore boli zaznamenane pocas behu
     */
    public function getLog() {
        return $this->log;
    }

    // ====[ Sukromne metody ]=================================================

     /**
     *  stavi URL adresu triedy
     *
     *  @param $url                - URL adresa k triede RotateAntispam
     *  @return bool                - uspesnost nastavenia
     */
    protected function setUrlRotateAntispam($url) {
        // TODO: spravit nejake osetrenie URL
        $this->urlRotateAntispam = $url;
        return true;
    }
    
    /**
     *  vrati URL adresu triedy
     *
     *  @return string                - URL adresa triedy
     */
    protected function getUrlRotateAntispam() {
        return $this->urlRotateAntispam;
    }
    
    /**
     *  vrati ziadany text
     *
     *  @param string $key            - kluc retazca
     *  @return string                - hodnota prisluchajuca klucu
     */
    protected function getText($key) {
        $ret = $this->texts[$key];
        return ($this->outputEncoding == 'UTF-8')
            ? $ret
            : iconv('UTF-8', $this->outputEncoding, $ret);
    }

    /**
     *  vrati dizajn jedneho elementu
     *
     *  @param string $key            - kluc elementu
     *  @return string                - hodnota ziadaneho elementu
     */
    protected function getDesignElement($key) {
        if (strlen($key) <= 0
            || !isset($this->design[$key]))
        {
            return false;
        }
        return $this->design[$key];
    }

    /**
     *  vrati informacie o obrazku
     *
     *  @param string $image        - subor obrazka
     *  @return array                - pole s informacia o obrazku
     */
    protected function getImageInfo($image) {
        if (strlen($image) <= 0) {
            return false;
        }
        $img = getimagesize($image);
        return array(
            'width'    => $img[0],
            'height'   => $img[1],
            'type'     => $img[2],
            'mime'     => $img['mime']
        );
    }

    /**
     *  nastavi typ vystupneho kodovania
     *
     *  @param string $encoding        - nazov kodovania
     *  @return bool                - uspech nastavenia
     */
    protected function setOutputEncoding($encoding) {
        $allowEncoding = array('UTF-8', 'CP1250', 'ISO-8859-1', 'ISO-8859-2', 'WINDOWS-1250');
        $encoding = strtoupper($encoding);
        if (in_array($encoding, $allowEncoding)) {
            $this->outputEncoding = $encoding.'//TRANSLIT';
            return true;
        }
        return false;
    }

    // ====[ Verejne metody ]==================================================

    /**
     *  nastavi obrazok pre rotovanie
     *
     *  @param  string    $image        - subor s obrazkom
     *  @return bool                - uspesnot nastavenia
     */
    public function setImage($image) {
        $this->addLog('Spusteny setImage');
        $this->addLog('Vypis $_SESSION: '.json_encode($_SESSION));
        if (!isset($image)
            || !is_string($image)
            || !(strlen($image) > 0))
        {
            $this->setError('Obrazok \''.$image.'\' nebol nastaveny');
            return false;
        }
        if (!file_exists($image)) {
            $this->setError('Zadany obrazok \''.$image.'\' neexistuje');
            return false;
        }
        $this->image = $image;
        $relative_path = str_replace(dirname(__FILE__), '', realpath($image));
        if (substr($relative_path, 0, 1) == '/'
            || substr($relative_path, 0, 1) == '\\')
        {
            $relative_path = substr($relative_path, 1);
        }
        $_SESSION['RotateAntispam']['image'] = $relative_path;
        
          $this->imageInfo = $this->getImageInfo($this->image);
        
        $this->addLog('Obrazok "'.$image.'" bol nastaveny');
        return true;
    }
    
    /**
     *  vrati HTML antispam ochrany
     *
     *  @return string                - HTML kod pre antispam ochrany
     */
    public function getAntispamHtml() {
        $this->addLog('Spusteny getAntispamHtml');
        $shift = rand(-10, 10);
        $_SESSION['RotateAntispam']['shift'] = $shift;
        $this->addLog('Shift nastaveny na hodnotu "'.$shift.'"');
        $html = '
            <style type="text/css">
                .antispam-hide { display: none; }
                .antispam-box-hide { display: none; }
                .antispam-box {
                    width: '.($this->imageInfo['width'] + 200).'px;
                    height: '.($this->imageInfo['height'] + 130).'px;
                    background: #FFFFFF;
                    color: #000000;
                    text-align: center;
                    position: absolute;
                    margin-left: -'.(($this->imageInfo['width'] + 200) / 2).'px;
                    margin-top: 50px;
                    left: 50%;
                    top: 50%;
                    z-index: 20;
                    display: block;
                    padding: 20px;
                    box-shadow: 10px 10px 5px #333;
                    -webkit-box-shadow: 10px 10px 5px #333;
                    -moz-box-shadow: 10px 10px 5px #333;
                    border-radius: 20px;
                    -webkit-border-radius: 20px;
                    -moz-border-radius: 20px;
                    text-align: left;
                    background-color: #FFFFFF;
                }
                .antispam-box .antispam-box-title { color: #000000; font-size: 20px; }
                .screen { position: fixed;    left: 0; top: 0; background: #000; }
            </style>
            <div id="screen" class="screen"></div>
            <div id="antispam-box" class="antispam-box-hide">
                <center>
                <span class="antispam-box-title">'.$this->getText('title').'</span>
                <div id="rotimg">
                    <img id="rotateantispamimage" src="'.$this->getUrlRotateAntispam().'?getImage" />
                    ';
        $leftButtonImage = (strlen($this->getDesignElement('leftButtonImage')) > 0
                            && strlen($this->getDesignElement('leftButtonImageHover')) > 0);
        if ($leftButtonImage) {
            $html .= '<img id="rotateantispamimage_leftButton" src="'.$this->getDesignElement('leftButtonImage').'" />';
            $html .= '<img id="rotateantispamimage_leftButtonHover" src="'.$this->getDesignElement('leftButtonImageHover').'" />';
            $leftButtonImageInfo = $this->getImageInfo($this->getDesignElement('leftButtonImage'));

        }
        $rightButtonImage = (strlen($this->getDesignElement('rightButtonImage')) > 0
                            && strlen($this->getDesignElement('rightButtonImageHover')) > 0);
        if ($rightButtonImage) {
            $html .= '<img id="rotateantispamimage_rightButton" src="'.$this->getDesignElement('rightButtonImage').'" />';
            $html .= '<img id="rotateantispamimage_rightButtonHover" src="'.$this->getDesignElement('rightButtonImageHover').'" />';
            $rightButtonImageInfo = $this->getImageInfo($this->getDesignElement('rightButtonImage'));
        }
        $submitType = (strlen($this->getText('submit')) <= 0) ? 'image' : 'submit';
        $cancelType = (strlen($this->getText('cancel')) <= 0) ? 'image' : 'button';
        $html .= '
                </div>
                '.$this->getText('description').'<br>
                <input type="'.$submitType.'" value="'.$this->getText('submit').'" id="rotate_antispam_submit_button">
                <input type="'.$cancelType.'" value="'.$this->getText('cancel').'" id="rotate_antispam_cancel_button" onclick="antispam_box_hide(); return false;">
                </center>
            </div>
            <input type="hidden" name="'.$this->answer_name.'" id="ezin_antispam" value="'.$shift.'">
            <input type="hidden" name="antispam_log" id="antispam_log" value="">
            <script type="text/javascript">
                if (typeof RotateAntispam == "undefined") window.RotateAntispam = {};
                var _beforeBox = null;
                RotateAntispam.beforeBox = function(fnc) {
                    _beforeBox = fnc;
                }
                var button_submit;
                var IE;
                var MSIE_ver;
                function initRotateAntispam() {
                    var button_submit = document.getElementsByName("'.$this->submit_name.'")[0];
                    if (button_submit == null) {
                        console.error("Not exists submit button with name '.$this->submit_name.'");
                        return false;
                    }
                    var fnc = button_submit.getAttribute("onclick");
                    //var IE = document.all ? true : false;
                    IE = (navigator.appName == "Microsoft Internet Explorer");
                    //var version = navigator.appVersion.substr(0,3);
                    var MSIE_pos = navigator.appVersion.search("MSIE");
                    MSIE_ver = parseFloat(navigator.appVersion.substr(MSIE_pos+4, 5));
                    if(IE && MSIE_ver < 10) { // fixnute pre IE7 a menej; 2013-07-16 zmenene na IE9 a starsie
                        var ret = button_submit.setAttribute("onclick", function(){ antispam_box(); return false; });
                    } else { // if onclick is a function, use the IE7 method and call onclick() in the anonymous function
                        var ret = button_submit.setAttribute("onclick","antispam_box(); return false;"); // for FF,Opera,Chrome
                    }
                    //console.info(button_submit.getAttribute("onclick").toString().toString());
                    button_submit.setAttribute("name","submit");
                    // hide old input
                    var old_inputs = document.getElementsByName("ezin_antispam");
                    var old_input = null;
                    var i = 0;
                    if (old_inputs != null) {
                        for (i = 0; i < old_inputs.length; i++) {
                            old_input = old_inputs[i];
                            if (IE) {
                                old_input.className = "antispam-hide";
                            } else {
                                old_input.setAttribute("class","antispam-hide");
                            }
                        }
                    }
                    button_submit.disabled = "";
                    document.getElementById("rotate_antispam_submit_button").setAttribute("name","'.$this->submit_name.'");
                }
                window.onload = initRotateAntispam;
                function getPageSize() {
                    var xScroll, yScroll;
                    if (window.innerHeight && window.scrollMaxY) {
                        xScroll = window.innerWidth + window.scrollMaxX;
                        yScroll = window.innerHeight + window.scrollMaxY;
                    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
                        xScroll = document.body.scrollWidth;
                        yScroll = document.body.scrollHeight;
                    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
                        xScroll = document.body.offsetWidth;
                        yScroll = document.body.offsetHeight;
                    }
                    var windowWidth, windowHeight;
                    if (self.innerHeight) {    // all except Explorer
                        if(document.documentElement.clientWidth){
                            windowWidth = document.documentElement.clientWidth;
                        } else {
                            windowWidth = self.innerWidth;
                        }
                        windowHeight = self.innerHeight;
                    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
                        windowWidth = document.documentElement.clientWidth;
                        windowHeight = document.documentElement.clientHeight;
                    } else if (document.body) { // other Explorers
                        windowWidth = document.body.clientWidth;
                        windowHeight = document.body.clientHeight;
                    }
                    // for small pages with total height less then height of the viewport
                    if(yScroll < windowHeight){
                        pageHeight = windowHeight;
                    } else {
                        pageHeight = yScroll;
                    }
                    // for small pages with total width less then width of the viewport
                    if(xScroll < windowWidth){
                        pageWidth = xScroll;
                    } else {
                        pageWidth = windowWidth;
                    }
                    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
                    return arrayPageSize;
                };
                function getPageScroll() {
                    var xScroll, yScroll;
                    if (self.pageYOffset) {
                        yScroll = self.pageYOffset;
                        xScroll = self.pageXOffset;
                    } else if (document.documentElement && document.documentElement.scrollTop) {     // Explorer 6 Strict
                        yScroll = document.documentElement.scrollTop;
                        xScroll = document.documentElement.scrollLeft;
                    } else if (document.body) {// all other Explorers
                        yScroll = document.body.scrollTop;
                        xScroll = document.body.scrollLeft;
                    }
                    arrayPageScroll = new Array(xScroll,yScroll);
                    return arrayPageScroll;
                };
                function antispam_box(){
                    if (!triggerBeforeBox()) {
                        return false;
                    }
                    var pageSize = getPageSize();
                    var pageScroll = getPageScroll();
                    var myWidth = pageSize[0];
                    var myHeight = pageSize[1];
                    var paddingTop = pageScroll[1];
                    var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
                    var screen = document.getElementById("screen");
                    screen.style.display = "block";
                    screen.style.opacity = "0.7";
                    screen.style.width = myWidth+"px";
                    screen.style.height = myHeight+"px";
                    var antispam_box = document.getElementById("antispam-box");
                    antispam_box.className = "antispam-box";
                    antispam_box.style.top = paddingTop+"px";
                }
                function antispam_box_hide(){
                    var screen = document.getElementById("screen");
                    screen.style.display = "none";
                    var antispam_box = document.getElementById("antispam-box");
                    antispam_box.className = "antispam-box-hide";
                }
                function antispam_log(val) {
                    console.log(val);
                    document.getElementById("antispam_log").value += val+"\n";
                }
                function triggerBeforeBox() {
                    if (_beforeBox != null) {
                        return _beforeBox();
                    }
                    return true;
                }
                var src = document.getElementById("rotateantispamimage").src;
                ';
        if ($leftButtonImage) {
            $html .= 'var src_leftButton = document.getElementById("rotateantispamimage_leftButton").src;';
            $html .= 'var src_leftButtonHover = document.getElementById("rotateantispamimage_leftButtonHover").src;';
        }
        if ($rightButtonImage) {
            $html .= 'var src_rightButton = document.getElementById("rotateantispamimage_rightButton").src;';
            $html .= 'var src_rightButtonHover = document.getElementById("rotateantispamimage_rightButtonHover").src;';
        }
        $html .= '
                var angle = '.$shift.';
                document.getElementById("rotimg").innerHTML = "";
                var R = Raphael("rotimg", '.($this->imageInfo['width'] + 100).', '.($this->imageInfo['height'] + 50).');
                R.circle('.(($this->imageInfo['width'] + 100) / 2).', '.(($this->imageInfo['height'] + 50) / 2).', '.(($this->imageInfo['width'] /2 ) + 5).').attr({fill: "#CCC", "stroke-width": 5});
                var img = R.image(src, 50, 25, '.$this->imageInfo['width'].', '.$this->imageInfo['height'].');
                var butt1 = R.set(),
                    butt2 = R.set();
                ';
        if ($leftButtonImage) {
            $html .= '
                butt1.push(R.image(src_leftButton, 0, 0, '.$leftButtonImageInfo['width'].', '.$leftButtonImageInfo['height'].'));
                butt1.translate(10, 20);
                butt1.click(function () {                                       //antispam_log("klik DOLAVA");
                    angle -= 10;                                                //antispam_log("angle "+angle.toString());
                    img.stop().animate({transform: "r" + angle}, 1000, "<>");
                    document.getElementById("ezin_antispam").value = angle;     //antispam_log("-------------------------");
                }).mouseover(function () {
                    if(IE && MSIE_ver < 9) {
                        butt1[0].node.href.baseVal = src_leftButtonHover;
                    } else {
                        butt1.animate({opacity: 0.5}, 200, function() {
                            butt1[0].node.href.baseVal = src_leftButtonHover;
                            butt1.animate({opacity: 1}, 200);
                        });
                    }
                }).mouseout(function () {
                    if(IE && MSIE_ver < 9) {
                        butt1[0].node.href.baseVal = src_leftButton;
                    } else {
                        butt1.animate({opacity: 0.5}, 200, function() {
                            butt1[0].node.href.baseVal = src_leftButton;
                            butt1.animate({opacity: 1}, 200);
                        });
                    }
                });
                ';
        } else {
            $html .= '
                butt1.push(R.circle(24.833, 26.917, 26.667).attr({stroke: "'.$this->getDesignElement('leftButtonBorderColor').'", fill: "#fff", "fill-opacity": .4, "stroke-width": 2}),
                           R.path("M12.582,9.551C3.251,16.237,0.921,29.021,7.08,38.564l-2.36,1.689l4.893,2.262l4.893,2.262l-0.568-5.36l-0.567-5.359l-2.365,1.694c-4.657-7.375-2.83-17.185,4.352-22.33c7.451-5.338,17.817-3.625,23.156,3.824c5.337,7.449,3.625,17.813-3.821,23.152l2.857,3.988c9.617-6.893,11.827-20.277,4.935-29.896C35.591,4.87,22.204,2.658,12.582,9.551z").attr({stroke: "none", fill: "'.$this->getDesignElement('leftButtonColor').'"}),
                           R.circle(24.833, 26.917, 26.667).attr({fill: "#fff", opacity: 0}));
                butt1.translate(10, 20);
                butt1[2].click(function () {
                    angle -= 10;
                    img.stop().animate({transform: "r" + angle}, 1000, "<>");
                    document.getElementById("ezin_antispam").value = angle;
                }).mouseover(function () {
                    butt1[1].animate({fill: "'.$this->getDesignElement('leftButtonColorHover').'"}, 300);
                }).mouseout(function () {
                    butt1[1].stop().attr({fill: "'.$this->getDesignElement('leftButtonColor').'"});
                });
                ';
        }
        if ($rightButtonImage) {
            $html .= '
                butt2.push(R.image(src_rightButton, 0, 0, '.$rightButtonImageInfo['width'].', '.$rightButtonImageInfo['height'].'));
                butt2.translate('.($this->imageInfo['width'] + 40).', 20);
                butt2.click(function () {                                       //antispam_log("klik DOPRAVA");
                    angle += 10;                                                //antispam_log("angle "+angle.toString());
                    img.stop().animate({transform: "r" + angle}, 1000, "<>");
                    document.getElementById("ezin_antispam").value = angle;     //antispam_log("-------------------------");
                }).mouseover(function () {
                    if(IE && MSIE_ver < 9) {
                        butt2[0].node.href.baseVal = src_rightButtonHover;
                    } else {
                        butt2.animate({opacity: 0.5}, 200, function() {
                            butt2[0].node.href.baseVal = src_rightButtonHover;
                            butt2.animate({opacity: 1}, 200);
                        });
                    }
                }).mouseout(function () {
                    if(IE && MSIE_ver < 9) {
                        butt2[0].node.href.baseVal = src_rightButton;
                    } else {
                        butt2.animate({opacity: 0.5}, 200, function() {
                            butt2[0].node.href.baseVal = src_rightButton;
                            butt2.animate({opacity: 1}, 200);
                        });
                    }
                });
                ';
        } else {
            $html .= '
                butt2.push(R.circle(24.833, 26.917, 26.667).attr({stroke: "'.$this->getDesignElement('rightButtonBorderColor').'", fill: "#fff", "fill-opacity": .4, "stroke-width": 2}),
                           R.path("M37.566,9.551c9.331,6.686,11.661,19.471,5.502,29.014l2.36,1.689l-4.893,2.262l-4.893,2.262l0.568-5.36l0.567-5.359l2.365,1.694c4.657-7.375,2.83-17.185-4.352-22.33c-7.451-5.338-17.817-3.625-23.156,3.824C6.3,24.695,8.012,35.06,15.458,40.398l-2.857,3.988C2.983,37.494,0.773,24.109,7.666,14.49C14.558,4.87,27.944,2.658,37.566,9.551z").attr({stroke: "none", fill: "'.$this->getDesignElement('rightButtonColor').'"}),
                           R.circle(24.833, 26.917, 26.667).attr({fill: "#fff", opacity: 0}));
                butt2.translate('.($this->imageInfo['width'] + 40).', 20);
                butt2[2].click(function () {
                    angle += 10;
                    img.animate({transform: "r" + angle}, 1000, "<>");
                    document.getElementById("ezin_antispam").value = angle;
                }).mouseover(function () {
                    butt2[1].animate({fill: "'.$this->getDesignElement('rightButtonColorHover').'"}, 300);
                }).mouseout(function () {
                    butt2[1].stop().attr({fill: "'.$this->getDesignElement('rightButtonColor').'"});
                });
                ';
        }
        $html .= '
                setTimeout(function () {R.safari();});
                
                function updateAngle() {
                    img.stop().animate({transform: "r" + angle}, 1, "<>");
                    //console.log("updateAngle");
                    setTimeout("updateAngle();", 5000);
                }
                updateAngle();
                
            </script>
        ';
        return $html;
    }
    
    /**
     *  nastavi ziadany text
     *
     *  @param string $key            - kluc retazca
     *  @param string $value            - hodnota prisluchajuca klucu
     *  @return void
     */
    public function setText($key, $value) {
        $this->texts[$key] = $value;
    }
    
    /**
     *  nastavi dizajn
     *
     *  @param string $arr            - asociativne pole prvkov
     *  @return void
     */
    public function setDesign($arr) {
        if (!is_array($arr)) {
            return false;
        }
        foreach($arr as $key => $val) {
            $this->setDesignElement($key, $val);
        }
    }

    /**
     *  nastavi dizajn jedneho elementu
     *
     *  @param string $key            - kluc elementu
     *  @param string $val            - hodnota elementu
     *  @return void
     */
    public function setDesignElement($key, $val) {
        if (strlen($key) <= 0) {
            return false;
        }
        $this->design[$key] = $val;
    }

     /**
     *  skontroluje ovdpoved
     *
     *  @param $answer                - odpoved, ak nie je nastavena default to berie z $_POST
     *  @return bool                - spravnost odpovede, TRUE = spravna, FALSE = nespravna
     */
    public function correctAnswer($answer_user = null) {
        $this->addLog('Spusta sa correctAnswer');
        if (is_null($this->correctAnswer_cache)) {
            $this->addLog('Prvy krat spracuvavam');
            $answer_user = (is_null($answer_user)) ? @$_POST[$this->answer_name] : $answer_user;
            $answer = @$_SESSION['RotateAntispam']['answer'];
            $this->addLog('Odpoved pouzivatela je "'.$answer_user.'"');
            if (!isset($answer)
                || strlen($answer) <= 0)
            {
                 $this->addLog('Odpoved nebola nastavena');
                $this->correctAnswer_cache = false;
            } else {
                $this->addLog('Spravna odpoved je "'.$answer.'"');
                $this->correctAnswer_cache = ($answer == $answer_user);
            }
            $_SESSION['RotateAntispam'] = null;
            unset($_SESSION['RotateAntispam']);
        }
        $this->addLog('Vraciam odpoved '.(($this->correctAnswer_cache) ? 'TRUE' : 'FALSE'));
        $this->addLog('<hr>JavaScript LOG: <br>'.nl2br(@$_REQUEST['antispam_log']));
        return $this->correctAnswer_cache;
    }
    
    // ====[ Funkcie - vseobecne ]=============================================
    

} // class RotateAntispam

error_reporting(E_ALL && ~E_NOTICE);

// ak nie je nastartovana $_SESSION
if (!isset($_SESSION)
    || strlen(session_id()) == 0)
{
    session_start();
}

function loadFromSession($name) {
    $ret = null;
    $maxSleep = 10;
    $sleep = 1;
    while (strlen($ret) <= 0 && $maxSleep > 0) {
        $ret = @$_SESSION['RotateAntispam'][$name];
        sleep($sleep); // prve nacitanie = 0
        $sleep = 1;
        $maxSleep--;
    }
    return $ret;
}

// Spracovanie vyziadaneho obrazku
if (isset($_REQUEST['getImage'])) {
    $filename = loadFromSession('image');
    if (strlen($filename) <= 0
        || !file_exists($filename))
    {
        die('Neexistuje obrazok "'.$filename.'"');
    }
    $shift = loadFromSession('shift');
    do {
        $degrees = (rand(-5,5) * 10) + $shift;
    } while($degrees == $shift || $_SESSION['RotateAntispam']['answer'] == $degrees);
    $_SESSION['RotateAntispam']['answer'] = (string)$degrees;

    if(!function_exists("imagerotate")) {
        function imagerotate($srcImg, $angle, $bgcolor=0, $ignore_transparent = 0) {
            return imagerotateEquivalent($srcImg, $angle, $bgcolor, $ignore_transparent);
        }
    }

    /*
        Imagerotate replacement. ignore_transparent is work for png images
        Also, have some standard functions for 90, 180 and 270 degrees.
        Rotation is clockwise
    */

    function imagerotateEquivalent($srcImg, $angle, $bgcolor, $ignore_transparent = 0) {
        function rotateX($x, $y, $theta){
            return $x * cos($theta) - $y * sin($theta);
        }
        function rotateY($x, $y, $theta){
            return $x * sin($theta) + $y * cos($theta);
        }

        $srcw = imagesx($srcImg);
        $srch = imagesy($srcImg);

        //Normalize angle
        $angle %= 360;
        //Set rotate to clockwise
        //$angle = -$angle;

        if($angle == 0) {
            if ($ignore_transparent == 0) {
                imagesavealpha($srcImg, true);
            }
            return $srcImg;
        }

        // Convert the angle to radians
        $theta = deg2rad ($angle);

        //Standart case of rotate
        if ( (abs($angle) == 90) || (abs($angle) == 270) ) {
            $width = $srch;
            $height = $srcw;
            if ( ($angle == 90) || ($angle == -270) ) {
                $minX = 0;
                $maxX = $width;
                $minY = -$height+1;
                $maxY = 1;
            } else if ( ($angle == -90) || ($angle == 270) ) {
                $minX = -$width+1;
                $maxX = 1;
                $minY = 0;
                $maxY = $height;
            }
        } else if (abs($angle) === 180) {
            $width = $srcw;
            $height = $srch;
            $minX = -$width+1;
            $maxX = 1;
            $minY = -$height+1;
            $maxY = 1;
        } else {
            // Calculate the width of the destination image.
            $temp = array (rotateX(0, 0, 0-$theta),
            rotateX($srcw, 0, 0-$theta),
            rotateX(0, $srch, 0-$theta),
            rotateX($srcw, $srch, 0-$theta)
            );
            $minX = floor(min($temp));
            $maxX = ceil(max($temp));
            $width = $maxX - $minX;

            // Calculate the height of the destination image.
            $temp = array (rotateY(0, 0, 0-$theta),
            rotateY($srcw, 0, 0-$theta),
            rotateY(0, $srch, 0-$theta),
            rotateY($srcw, $srch, 0-$theta)
            );
            $minY = floor(min($temp));
            $maxY = ceil(max($temp));
            $height = $maxY - $minY;
        }

        $destimg = imagecreatetruecolor($width, $height);
        if ($ignore_transparent == 0) {
            imagefill($destimg, 0, 0, imagecolorallocatealpha($destimg, 255,255, 255, 127));
            imagesavealpha($destimg, true);
        }

        // sets all pixels in the new image
        for($x=$minX; $x<$maxX; $x++) {
            for($y=$minY; $y<$maxY; $y++) {
                // fetch corresponding pixel from the source image
                $srcX = round(rotateX($x, $y, $theta));
                $srcY = round(rotateY($x, $y, $theta));
                if($srcX >= 0 && $srcX < $srcw && $srcY >= 0 && $srcY < $srch) {
                    $color = imagecolorat($srcImg, $srcX, $srcY );
                } else {
                    $color = $bgcolor;
                }
                imagesetpixel($destimg, $x-$minX, $y-$minY, $color);
            }
        }
        return $destimg;
    }

    header('Content-type: image/png');
    $source = imagecreatefrompng($filename);
    $color = imagecolorallocate($source, 204, 204, 204);
    $rotate = imagerotate($source, $degrees, $color);

    $img = getimagesize($filename);
    $image_info['width'] = $img[0];
    $image_info['height'] = $img[1];
    $image_info['type'] = $img[2];
    $image_info['mime'] = $img['mime'];

    $rotate_width = imagesx($rotate);
    $rotate_height = imagesy($rotate);

    $trim_image = imagecreatetruecolor($image_info['width'], $image_info['height']);
    imagecopyresampled($trim_image, $rotate,
                    0, 0,
                    ($rotate_width - $image_info['width']) / 2, ($rotate_height - $image_info['height']) / 2,
                    $image_info['width'], $image_info['height'],
                    $image_info['width'], $image_info['height'] );

    imagecolortransparent($trim_image, $color);
    imagepng($trim_image);

}

?>

Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok