-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
skywalker512
committed
Jul 12, 2018
1 parent
52e1ab7
commit f7f33a8
Showing
27 changed files
with
5,484 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
if (!defined("IN_ESOTALK")) exit; | ||
|
||
class CaptchaController extends ETController { | ||
public function action_test() | ||
{ | ||
$this->form = $form = ETFactory::make('form'); | ||
$form->action = URL('captcha/test'); | ||
$this->data('form', $form); | ||
|
||
if ( $form->validPostBack('captcha') ) { | ||
if ( ETPlugin_Captcha::verifyCode($form->getValue('captcha')) ) { | ||
$this->message('Success', 'success'); | ||
} else { | ||
$this->message('Failed', 'warning'); | ||
} | ||
|
||
$this->render('captcha/test'); | ||
} else { | ||
$this->render('captcha/test'); | ||
} | ||
} | ||
|
||
// set captcha and show image | ||
public function action_index($is2x = false) { | ||
$fontSize = 32 * ($is2x ? 2 : 1); | ||
$fontColor = '666666'; | ||
|
||
$code = ETPlugin_Captcha::generateCode(); | ||
$path = dirname(__FILE__) . '/resources'; | ||
|
||
$background = $is2x ? "$path/[email protected]" : "$path/bg.png"; | ||
$font = "$path/font.ttf"; | ||
|
||
// set up | ||
list($width, $height) = getimagesize($background); | ||
$img = imagecreatefrompng($background); | ||
|
||
list($r, $g, $b) = $this->hex2rgb($fontColor); | ||
$color = imagecolorallocate($img, $r, $g, $b); | ||
|
||
// center text | ||
list($x1, $y1, , , $x2, $y2) = imagettfbbox($fontSize, /*angle*/0, $font, $code); | ||
imagettftext($img, $fontSize, /*angle*/0, $width/2 + ($x1-$x2)/2, $height/2 + ($y1-$y2)/2, $color, $font, $code); | ||
|
||
// invert half image | ||
$invert = imagecreatetruecolor($width, $height); | ||
imagecopy($invert, $img, 0, 0, 0, 0, $width, $height); | ||
imagefilter($invert, IMG_FILTER_NEGATE); | ||
imagecopy($img, $invert, 0, 0, 0, 0, $width/2, $height); | ||
imagedestroy($invert); | ||
|
||
// output | ||
header('Cache-Control: no-cache, must-revalidate'); | ||
header('Content-Type: image/png'); | ||
imagepng($img); | ||
imagedestroy($img); | ||
} | ||
|
||
// retina support | ||
public function action_2x() | ||
{ | ||
$this->action_index(true); | ||
} | ||
|
||
|
||
private function hex2rgb($hex) { | ||
$value = hexdec($hex); | ||
return array( | ||
0xFF & ($value >> 0x10), | ||
0xFF & ($value >> 0x8), | ||
0xFF & $value, | ||
); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
if (!defined('IN_ESOTALK')) exit; | ||
|
||
ET::$pluginInfo['Captcha'] = array( | ||
'name' => '图形验证码', | ||
'description' => '在用户注册时要求用户识别图形验证码', | ||
'version' => '0.1.0', | ||
'author' => 'rhyzx', | ||
'authorEmail' => '[email protected]', | ||
'authorURL' => 'https://3dgundam.org', | ||
'license' => 'MIT', | ||
'priority' => 0, | ||
); | ||
|
||
class ETPlugin_Captcha extends ETPlugin { | ||
|
||
public function __construct($rootDirectory) | ||
{ | ||
parent::__construct($rootDirectory); | ||
ETFactory::registerController('captcha', 'CaptchaController', dirname(__FILE__).'/CaptchaController.class.php'); | ||
} | ||
|
||
public function handler_renderBefore($sender) | ||
{ | ||
$sender->addCSSFile($this->resource('captcha.css')); | ||
$sender->addJSFile($this->resource('captcha.js')); | ||
} | ||
|
||
public function handler_userController_initJoin($sender, $form) | ||
{ | ||
if ($this->skipCaptcha()) return; | ||
$form->addSection('captcha', '验证码'); | ||
$form->addField('captcha', 'captcha', function($form) use ($sender) | ||
{ | ||
return $sender->getViewContents($this->view('captcha/captcha'), array('form' => $form, 'tips' => true)); | ||
}, | ||
function($form, $key, &$data) use ($sender) | ||
{ | ||
if ( !self::verifyCode($form->getValue($key)) ) { | ||
$form->error($key, '验证码错误'); | ||
} | ||
}); | ||
} | ||
|
||
|
||
public function handler_conversationController_renderFormButtonsAfter($sender, &$content, $form, $conversation) | ||
{ | ||
if ($this->skipCaptcha()) return; | ||
$result = $sender->getViewContents($this->view('captcha/captcha'), array('form' => $form, 'tabindex' => 290)); | ||
addToArray($content, $result, 0); | ||
} | ||
|
||
public function handler_conversationController_reply($sender, $form) | ||
{ | ||
if ($this->skipCaptcha()) return; | ||
$form->addField('captcha', 'captcha', null, | ||
function($form, $key, &$data) use ($sender) | ||
{ | ||
if ( !self::verifyCode($form->getValue($key)) ) { | ||
$form->error($key, '验证码错误'); | ||
} | ||
}); | ||
} | ||
public function handler_conversationController_start($sender, $form) | ||
{ | ||
if ($this->skipCaptcha()) return; | ||
$form->addField('captcha', 'captcha', null, | ||
function($form, $key, &$data) use ($sender) | ||
{ | ||
if ( !self::verifyCode($form->getValue($key)) ) { | ||
$form->error($key, '验证码错误'); | ||
} | ||
}); | ||
} | ||
|
||
|
||
private function skipCaptcha() | ||
{ | ||
if (ET::$session->user && ET::$session->user['countPosts'] >= 10) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
|
||
public static function verifyCode($code = '') { | ||
$code = strtoupper($code); | ||
return ET::$session->get('plugin_captcha') === $code; | ||
} | ||
public static function generateCode() { | ||
static $codes = 'ABCDEFGHIJKLMNPQRSTUVWXYZ01245678'; | ||
$count = strlen($codes); | ||
|
||
$code = ''; | ||
for ($i=0; $i < 4; $i++) { | ||
$code .= substr($codes, rand() % $count, 1); | ||
} | ||
|
||
// case insensitive | ||
$code = strtoupper($code); | ||
ET::$session->store('plugin_captcha', $code); | ||
return $code; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.sheet .buttons .captcha { | ||
float: right; | ||
margin-left: 10px; | ||
} | ||
.captcha img { | ||
width: 102px; | ||
height: 34px; | ||
vertical-align: middle; | ||
cursor: pointer; | ||
} | ||
.captcha img.loading { | ||
cursor: wait; | ||
background-position: center center; | ||
box-shadow: inset 0 0 1px rgba(0,0,0,.5); | ||
} | ||
.captcha input { | ||
padding: 7px; | ||
width: 72px; | ||
} | ||
.fieldGroup .captcha input { | ||
width: 154px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// reload captcha | ||
void function () { | ||
|
||
$(document).off('click.captcha') | ||
.on('click.captcha', '.captcha img:not(.loading)', function () { | ||
reload($(this)) | ||
}) | ||
|
||
if (typeof ETConversation !== 'undefined') { | ||
var startConversation = ETConversation.startConversation | ||
ETConversation.startConversation = function () { | ||
startConversation.apply(startConversation, arguments) | ||
.done(function (res) { | ||
if (typeof res.redirect !== 'undefined') return | ||
reload($('#reply .captcha img')) | ||
$('#reply .captcha input').val('') | ||
}) | ||
.fail(function () { | ||
reload($('#reply .captcha img')) | ||
$('#reply .captcha input').val('') | ||
}) | ||
} | ||
|
||
var addReply = ETConversation.addReply | ||
ETConversation.addReply = function () { | ||
addReply.apply(addReply, arguments) | ||
.always(function () { | ||
reload($('#reply .captcha img')) | ||
$('#reply .captcha input').val('') | ||
}) | ||
} | ||
} | ||
|
||
|
||
function reload($img) { | ||
var t = $.now() | ||
|
||
$img | ||
.addClass('loading') | ||
.one('load error', function () { | ||
$img.removeClass('loading') | ||
}) | ||
// remove attr to show loading image | ||
.removeAttr('src') | ||
.removeAttr('srcset') | ||
.attr('src', '/captcha?t=' + t) | ||
.attr('srcset', '/captcha/2x?t=' + t + ' 2x') | ||
} | ||
|
||
|
||
// tooltip | ||
$(function () { | ||
$('.captcha img').tooltip() | ||
}) | ||
}(); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
if (!defined('IN_ESOTALK')) exit; | ||
$form = $data['form']; | ||
?> | ||
<div class="captcha"> | ||
<img src="/captcha" srcset="/captcha/2x 2x" alt="" width="102" height="34" title="点击更换验证码" role="button"> | ||
<?php echo $form->input('captcha', 'text', array('placeholder' => '输入验证码', 'value' => '', 'tabindex' => $data['tabindex'] )) ?> | ||
<?php if ($data['tips']): ?> | ||
<br><small>请输入图片中的验证码</small> | ||
<?php endif ?> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
if (!defined("IN_ESOTALK")) exit; | ||
$form = $data["form"]; | ||
?> | ||
|
||
<div class="sheet"> | ||
<div class="sheetContent"> | ||
<h3>全自动人机区别图灵测试</h3> | ||
<?php echo $form->open(); ?> | ||
<div class="buttons"> | ||
<button type="submit" class="submit button big">Test</button> | ||
<span class="captcha"> | ||
<img src="/captcha" srcset="/captcha/2x 2x" alt="" width="102" height="34"> | ||
<input type="text" name="captcha" value="" placeholder="输入验证码"> | ||
</span> | ||
</div> | ||
<?php echo $form->close(); ?> | ||
</div> | ||
</div> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
if (!defined("IN_ESOTALK")) exit; | ||
|
||
ET::$pluginInfo["Photoswipe"] = array( | ||
"name" => "Photoswipe", | ||
"description" => "允许用户点击帖子中的图片,形成图片画廊样式,与 Upyun 结合使用", | ||
'version' => '0.1.0', | ||
'author' => 'rhyzx', | ||
'authorEmail' => '[email protected]', | ||
'authorURL' => 'https://3dgundam.org', | ||
'license' => 'MIT', | ||
"priority" => "0", | ||
'dependencies' => array( | ||
'Upyun' => '0', | ||
) | ||
); | ||
|
||
class ETPlugin_Photoswipe extends ETPlugin { | ||
|
||
public function handler_conversationController_renderBefore($sender){ | ||
$PhotoswipeCSS= "<link rel=\"stylesheet\" href=\"//cdn.bootcss.com/photoswipe/4.1.2/photoswipe.min.css\"> | ||
<link rel=\"stylesheet\" href=\"//cdn.bootcss.com/photoswipe/4.1.2/default-skin/default-skin.min.css\">"; | ||
$PhotoswipeJS = "<script src=\"//cdn.bootcss.com/photoswipe/4.1.2/photoswipe.min.js\"></script> | ||
<script src=\"//cdn.bootcss.com/photoswipe/4.1.2/photoswipe-ui-default.min.js\"></script> | ||
"; | ||
|
||
$sender->addToHead($PhotoswipeCSS); | ||
$sender->addToHead($PhotoswipeJS); | ||
$sender->addCSSFile($this->resource("photoswipe.css")); | ||
$sender->addJSFile($this->resource("photoswipe.js")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.link-external > img + i:not(.icon-external-link), | ||
.link-external > img + i:not(.icon-external-link) + .icon-external-link { | ||
display: none; | ||
} |
Oops, something went wrong.