'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("
", "\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 '';
$this->log .= $init_log.'
';
}
$msg = str_replace("\n", '', $msg);
$msg = str_replace("\r", '', $msg);
echo '';
}
$this->log .= $msg.'
';
}
/**
* 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 = '