Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GIFEncoder3.0.php - Parenthesis removed #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions AnimatedCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
class AnimatedCaptcha
{
protected $_options = array(
'millisecondsBetweenFrames' => 100,
'pluginName' => 'MovingRectangle',
'pluginOptions' => array()
);

'millisecondsBetweenFrames' => 100,
'pluginName' => 'MovingRectangle',
'pluginOptions' => array()
);
/**
* @var string
*/
Expand All @@ -31,6 +30,13 @@ public function __construct(array $options = array())
if (is_array($options)) {
$this->setOptions($options);
}

return;
}

public function __destruct()
{
return;
}

/**
Expand All @@ -43,7 +49,6 @@ public function setOptions(array $options)
{
foreach ($options as $key => $value) {
$normalized = ucfirst($key);

$method = 'set' . $normalized;
if (method_exists($this, $method)) {
$this->$method($value);
Expand Down Expand Up @@ -74,11 +79,8 @@ public function setPluginOptions($pluginOptions)
public function render()
{
$this->_createTempFilePath();

$this->_getFramesFromPlugin();

$this->_writeFramesToTargetFile();

return $this;
}

Expand All @@ -89,15 +91,19 @@ public function render()
*/
public function outputRenderedImage()
{
header('Cache-Control: private, no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s',time()-60).' GMT');
header('Pragma: no-cache');
header('Content-Length: '.filesize($this->_tempFilePath));
header('Content-Type: image/gif');
if(!headers_sent()) {
header('Cache-Control: private, no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s',time()-60).' GMT');
header('Pragma: no-cache');
header('Content-Length: '.filesize($this->_tempFilePath));
header('Content-Type: image/gif');
}
else {
throw new Exception('Can not send header parameters. Thats already sent.');
}

readfile($this->_tempFilePath);

return $this;
}

Expand Down Expand Up @@ -126,12 +132,12 @@ public function getRenderedFilePath()

protected function _getFramesFromPlugin()
{
require __DIR__ . '/plugins/'.$this->_options['pluginName'].'.php';
require (__DIR__ . '/plugins/'.$this->_options['pluginName'].'.php');
$pluginClassName = 'AnimatedCaptcha_Plugin_'.$this->_options['pluginName'];
$pluginClass = new $pluginClassName($this->_options['pluginOptions']);
/** @var $pluginClass AnimatedCaptcha_Plugin */

$this->_frames = $pluginClass->getFrames();
return;
}

/**
Expand All @@ -140,8 +146,8 @@ protected function _getFramesFromPlugin()
protected function _createTempFilePath()
{
$tempFilePath = tempnam('', '') . '.gif';

$this->_tempFilePath = $tempFilePath;
return;
}

/**
Expand All @@ -150,12 +156,13 @@ protected function _createTempFilePath()
protected function _writeFramesToTargetFile()
{
$delays = array();

for ($i=0; $i<count($this->_frames); $i++) {
$delays[] = $this->_options['millisecondsBetweenFrames'];
}

$gif = new GIFEncoder($this->_frames, $delays, 0, 2, 0, 0, 0, 0, "bin" );

$gif = new GIFEncoder($this->_frames, $delays, 0, 2, 0, 0, 0, 0, 'bin' );
file_put_contents($this->_tempFilePath, $gif->GetAnimation());
return;
}
}
6 changes: 3 additions & 3 deletions library/GIFEncoder3.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ function GIFBlockCompare ( $GlobalBlock, $LocalBlock, $Len ) {
$GlobalBlock { 3 * $i + 1 } != $LocalBlock { 3 * $i + 1 } ||
$GlobalBlock { 3 * $i + 2 } != $LocalBlock { 3 * $i + 2 }
) {
return ( 0 );
return 0;
}
}

return ( 1 );
return 1;
}
/*
:::::::::::::::::::::::::::::::::::::::::::::::::::
Expand All @@ -262,6 +262,6 @@ function GIFWord ( $int ) {
::
*/
function GetAnimation ( ) {
return ( $this->GIF );
return $this->GIF;
}
}