Skip to content

Commit

Permalink
refs #1705 : reCAPTCHA now works with comment-to-comment as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Dec 16, 2014
1 parent 8d2c18e commit f207085
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 20 deletions.
9 changes: 7 additions & 2 deletions interface/blog/comment/comment/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/// All rights reserved. Licensed under the GPL.
/// See the GNU General Public License for more details. (/documents/LICENSE, /documents/COPYRIGHT)
define('__TEXTCUBE_ADMINPANEL__',true);
require ROOT . '/library/preprocessor.php';
requireModel('blog.comment');
$IV = array(
'POST' => array(
'name' => array('string', 'default' => ''),
Expand All @@ -13,8 +15,11 @@
'secret' => array(array('on'), 'default' => null)
)
);
require ROOT . '/library/preprocessor.php';
requireModel('blog.comment');
$customIV = fireEvent('ManipulateIVRules',$IV,$context->getProperty('uri.interfaceRoute'));
Validator::addRule($customIV);
if(!Validator::isValid())
Respond::PrintResult(array('error' => 1, 'description' => 'Illegal parameters'));
requireStrictRoute();

if (!Setting::getBlogSettingGlobal('acceptComments',0) && !doesHaveOwnership()) {
Respond::PrintResult(array('error' => 0, 'commentBlock' => '', 'recentCommentBlock' => ''));
Expand Down
15 changes: 9 additions & 6 deletions library/view/replyEditorView.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,26 @@
}
}

$context = Model_Context::getInstance();
$pageHeadTitle = $pageTitle;
if( Acl::getIdentity('openid') ) {
$pageHeadTitle = $pageTitle;
$pageTitle = "$pageTitle ( <img src=\"".$service['path']."/resources/image/icon_openid.gif\" style=\"position:static;\" height=\"16\" width=\"16\"> ".OpenID::getDisplayName(Acl::getIdentity('openid')).")";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko">
<!DOCTYPE html>
<html>
<head>
<title><?php echo $pageHeadTitle ;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $service['path'] . $adminSkinSetting['skin'];?>/popup-comment.css" />
<script type="text/javascript">
//<![CDATA[
var servicePath = "<?php echo $service['path'];?>";
var blogURL = "<?php echo $blogURL;?>";
var servicePath = "<?php echo $context->getProperty('service.path');?>";
var serviceURL = "<?php echo $context->getProperty('uri.service');?>";
var blogURL = "<?php echo $context->getProperty('uri.blog');?>";
var adminSkin = "<?php echo $adminSkinSetting['skin'];?>";
var doesHaveOwnership = <?php echo doesHaveOwnership() ? 'true' : 'false';?>;
//]]>
</script>
<script type="text/javascript" src="<?php echo (doesHaveOwnership() ? $service['path'].'/resources' : $service['resourcepath']);?>/script/common2.js"></script>
Expand Down Expand Up @@ -73,7 +76,7 @@ function confirmOverwrite() {
}
//]]>
</script>
<?php echo fireEvent('REPLY_head_end',null,$comment);?>
<?php echo fireEvent('REPLY_head_end', '', $comment);?>
</head>
<?php
if (doesHaveOwnership())
Expand Down Expand Up @@ -191,6 +194,6 @@ function confirmOverwrite() {
<input name="openidedit" type="hidden" value="1" />
<?php } ?>
</form>
<?php echo fireEvent('REPLY_body_end',null,$comment);?>
<?php echo fireEvent('REPLY_body_end', '', $comment);?>
</body>
</html>
48 changes: 36 additions & 12 deletions plugins/reCAPTCHA/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function Recaptcha_AddInputValidatorRule($target, $mother) {
$signed_in = (doesHaveOwnership() || doesHaveMembership());
if ($mother == 'interface/blog/comment/add/') {
if ($mother == 'interface/blog/comment/add/' || $mother == 'interface/blog/comment/comment/') {
$target['POST']['g-recaptcha-response'] = array('string', 'default' => '', 'mandatory' => !$signed_in);
}
return $target;
Expand Down Expand Up @@ -40,26 +40,50 @@ function recaptchaWaitForElement(selector, cb) {
return $target;
}

function Recaptcha_CCHeader($target) {
global $configVal, $pluginURL;
$config = Setting::fetchConfigVal($configVal);
if (!is_null($config) && isset($config['siteKey'])) {
$target .= <<<EOS
<script type="text/javascript">
function recaptcha_init() {
var $ = jQuery;
if (!doesHaveOwnership) {
$('form').find('textarea').after('<div style="margin: 5pt 0 5pt 0" id="comment_recaptcha"></div>');
grecaptcha.render('comment_recaptcha', {
'sitekey': '{$config['siteKey']}'
});
}
}
</script>
<script src="https://www.google.com/recaptcha/api.js?render=explicit&onload=recaptcha_init"></script>
EOS;
}
return $target;
}

function Recaptcha_Footer($target) {
global $configVal, $pluginURL;
$config = Setting::fetchConfigVal($configVal);
if (!is_null($config) && isset($config['siteKey'])) {
$target .= <<<EOS
<script type="text/javascript">
(function($) {
if (!doesHaveOwnership) {
$('a[id^=commentCount]').click(function(e) {
var entryId = $(e.target).attr('id').match(/(\d+)/)[1];
recaptchaWaitForElement('form[id=entry' + entryId + 'WriteComment]', function(f) {
var blockId = 'comment_recaptcha_' + entryId;
if ($(blockId).length > 0) return;
$(f).find('textarea').after('<div style="margin: 5pt 0 5pt 0" id="' + blockId + '"></div>');
grecaptcha.render(blockId, {
'sitekey': '{$config['siteKey']}'
$(document).ready(function() {
if (!doesHaveOwnership) {
$('a[id^=commentCount]').click(function(e) {
var entryId = $(e.target).attr('id').match(/(\d+)/)[1];
recaptchaWaitForElement('form[id=entry' + entryId + 'WriteComment]', function(f) {
var blockId = 'comment_recaptcha_' + entryId;
if ($(blockId).length > 0) return;
$(f).find('textarea').after('<div style="margin: 5pt 0 5pt 0" id="' + blockId + '"></div>');
grecaptcha.render(blockId, {
'sitekey': '{$config['siteKey']}'
});
});
});
});
}
}
});
})(jQuery);
</script>
EOS;
Expand Down
1 change: 1 addition & 0 deletions plugins/reCAPTCHA/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<binding>
<tag name="SKIN_head_end" handler="Recaptcha_Header" />
<tag name="SKIN_body_end" handler="Recaptcha_Footer" />
<listener event="REPLY_head_end" handler="Recaptcha_CCHeader" />
<listener event="AddingComment" handler="Recaptcha_AddingCommentHandler" />
<listener event="ManipulateIVRules" handler="Recaptcha_AddInputValidatorRule" />
<config xml:lang="ko" dataValHandler="Recaptcha_ConfigHandler">
Expand Down

0 comments on commit f207085

Please sign in to comment.