Skip to content
Closed
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
164 changes: 164 additions & 0 deletions Controller/Component/NetCommonsVisualCaptchaComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php
/**
* NetCommonsBlock Component
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/

use visualCaptcha\Captcha;
use visualCaptcha\Session;

App::uses('Component', 'Controller');

App::import('Vendor', 'Captcha', array(
'file' => 'visualcaptcha' . DS . 'src' . DS . 'visualCaptcha' . DS . 'Captcha.php'
));
App::import('Vendor', 'Session', array(
'file' => 'visualcaptcha' . DS . 'src' . DS . 'visualCaptcha' . DS . 'Session.php'
));

/**
* NetCommonsVisualCaptcha Component
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\NetCommons\Controller\Component
*/
class NetCommonsVisualCaptchaComponent extends Component {

/**
* call controller w/ associations
*
* @var object
*/
public $controller = null;

/**
* assetPath /r associations
*
* @var string
*/
public $assetPath = null;

/**
* imageField Answer /r associations
*
* @var string
*/
public $imageField = null;

/**
* audioField Answer /r associations
*
* @var string
*/
public $audioField = null;

/**
* Called before the Controller::beforeFilter().
*
* @param Controller $controller Instantiating controller
* @return void
*/
public function initialize(Controller $controller) {
$this->controller = $controller;
// if Security component is used
if (array_key_exists('Security', $this->controller->components)) {
$this->imageField = $this->controller->Session->read('visualcaptcha.frontendData.imageFieldName');
$this->audioField = $this->controller->Session->read('visualcaptcha.frontendData.audioFieldName');

if ($this->imageField && $this->audioField) {
$this->controller->Security->unlockedFields = array(
$this->imageField,
$this->audioField
);
}
}
}

/**
* Called after the Controller::beforeFilter() and before the controller action
*
* @param Controller $controller Controller with components to startup
* @return void
* @throws ForbiddenException
*/
public function startup(Controller $controller) {
//$assetsPath = VENDORS . 'emotionloop' . DS . 'visualcaptcha' . DS . 'src' . DS . 'visualCaptcha' . DS . 'assets';
$this->assetPath = App::pluginPath('NetCommons') . 'Vendor' . DS . 'visual_captcha';
}

/**
* generate visual captcha data and return it
*
* @param int $count display image count
* @return string
*/
public function generate($count = 5) {
$session = new Session();
$lang = Configure::read('Config.language');
$imageJsonPath = $this->assetPath . DS . $lang . DS . 'images.json';
$audioJsonPath = $this->assetPath . DS . $lang . DS . 'audios.json';
$captcha = new Captcha($session, $this->assetPath, $this->__utilReadJSON($imageJsonPath), $this->__utilReadJSON($audioJsonPath));
$captcha->generate($count);
return json_encode($captcha->getFrontEndData());
}

/**
* generate visual captcha image data and return it
*
* @param int $index display image index
* @return string
*/
public function image($index) {
$session = new Session();
$captcha = new Captcha($session, $this->assetPath);
return $captcha->streamImage(array(), $index, 0);
}

/**
* generate audio captcha data and return it
*
* @return streaming data
*/
public function audio() {
$session = new Session();
$captcha = new Captcha($session, $this->assetPath);
return $captcha->streamAudio(array(), 'mp3');
}

/**
* check input response
*
* @return bool
*/
public function check() {
$reqData = $this->controller->request->data;
$session = new Session();
$captcha = new Captcha($session, $this->assetPath);

if (isset($reqData[$this->imageField])) {
return $captcha->validateImage($reqData[$this->imageField]);
} elseif (isset($reqData[$this->audioField])) {
return $captcha->validateAudio($reqData[$this->audioField]);
}

return false;
}

/**
* Read input file as JSON
*
* @param string $filePath json file path
* @return object
*/
private function __utilReadJSON($filePath) {
if (!file_exists($filePath)) {
return null;
}
return json_decode(file_get_contents($filePath), true);
}
}
Binary file modified Locale/jpn/LC_MESSAGES/net_commons.mo
Binary file not shown.
28 changes: 28 additions & 0 deletions Locale/jpn/LC_MESSAGES/net_commons.po
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,31 @@ msgstr "閉じる"
#: Videos/View/VideoBlockSettings/index.ctp:43 Videos/View/Videos/index.ctp:55
msgid "Add"
msgstr "追加"

#: View/Elements/visual_captcha.ctp:34
msgid "Sound icon"
msgstr "音声"

#: View/Elements/visual_captcha.ctp:35
msgid "Accessibility option: listen to a question and answer it!"
msgstr "アクセシビリティ対応:音声を聞いて答える"

#: View/Elements/visual_captcha.ctp:36
msgid ""
"Type below the <strong>answer</strong> to what you hear. Numbers or words:"
msgstr ""
"質問の音声を聞いて、下の回答欄に<strong>答え</strong>の数字・または言葉を入力"
"してください。"

#: View/Elements/visual_captcha.ctp:37
msgid "Click or touch the <strong>ANSWER</strong>"
msgstr ""
"<strong>ANSWER</strong>のアイコンをクリックまたはタッチして、決定してください"

#: View/Elements/visual_captcha.ctp:38
msgid "Refresh/reload icon"
msgstr "再読み込み"

#: View/Elements/visual_captcha.ctp:39
msgid "Refresh/reload: get new images and accessibility option!"
msgstr "再読み込み:新しい絵や音声に変えます"
23 changes: 23 additions & 0 deletions Locale/net_commons.pot
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,26 @@ msgstr ""
msgid "Add"
msgstr ""

#: View/Elements/visual_captcha.ctp:34
msgid "Sound icon"
msgstr ""

#: View/Elements/visual_captcha.ctp:35
msgid "Accessibility option: listen to a question and answer it!"
msgstr ""

#: View/Elements/visual_captcha.ctp:36
msgid "Type below the <strong>answer</strong> to what you hear. Numbers or words:"
msgstr ""

#: View/Elements/visual_captcha.ctp:37
msgid "Click or touch the <strong>ANSWER</strong>"
msgstr ""

#: View/Elements/visual_captcha.ctp:38
msgid "Refresh/reload icon"
msgstr ""

#: View/Elements/visual_captcha.ctp:39
msgid "Refresh/reload: get new images and accessibility option!"
msgstr ""
Binary file added Vendor/visual_captcha/audios/12times2.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/12times2.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/12times2_ja.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/2times10.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/2times10.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/2times10_ja.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/2times10_ja.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/4plus1.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/4plus1.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/4plus1_ja.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/4plus3.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/4plus3.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/4plus3_ja.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/5plus1.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/5plus1.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/5plus1_ja.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/5times2.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/5times2.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/5times2_ja.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/6plus6.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/6plus6.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/6plus6_ja.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/99plus1.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/99plus1.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/99plus1_ja.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/add3to1.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/add3to1.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/add3to1_ja.mp3
Binary file not shown.
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/addblueandyellow.ogg
Binary file not shown.
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/after2.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/after2.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/after2_ja.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/capitaloffrance.mp3
Binary file not shown.
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/divide4by2.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/divide4by2.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/divide4by2_ja.mp3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/milkcolor.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/milkcolor.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/skycolor.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/skycolor.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/skynight.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/skynight.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/sunastar.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/sunastar.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/thirdmonth.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/thirdmonth.ogg
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/yourobot.mp3
Binary file not shown.
Binary file added Vendor/visual_captcha/audios/yourobot.ogg
Binary file not shown.
82 changes: 82 additions & 0 deletions Vendor/visual_captcha/eng/audios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
[
{
"path": "5times2.mp3",
"value": "10"
},
{
"path": "2times10.mp3",
"value": "20"
},
{
"path": "5plus1.mp3",
"value": "6"
},
{
"path": "4plus1.mp3",
"value": "5"
},
{
"path": "4plus3.mp3",
"value": "7"
},
{
"path": "6plus6.mp3",
"value": "12"
},
{
"path": "12times2.mp3",
"value": "24"
},
{
"path": "99plus1.mp3",
"value": "100"
},
{
"path": "add3to1.mp3",
"value": "4"
},
{
"path": "addblueandyellow.mp3",
"value": "green"
},
{
"path": "after2.mp3",
"value": "3"
},
{
"path": "divide4by2.mp3",
"value": "2"
},
{
"path": "milkcolor.mp3",
"value": "white"
},
{
"path": "skycolor.mp3",
"value": "blue"
},
{
"path": "sunastar.mp3",
"value": "yes"
},
{
"path": "yourobot.mp3",
"value": "no"
},
{
"path": "capitaloffrance.mp3",
"value": "paris"
},
{
"path": "skynight.mp3",
"value": "black"
},
{
"path": "thirdmonth.mp3",
"value": "march"
},
{
"path": "firstletteralphabet.mp3",
"value": "a"
}
]
Loading