This repository was archived by the owner on Sep 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_public.php
More file actions
executable file
·100 lines (82 loc) · 2.68 KB
/
_public.php
File metadata and controls
executable file
·100 lines (82 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of dcReCaptcha, a plugin for Dotclear 2.
#
# Copyright (c) 2013 Benoit de Marne and contributors
# benoit.de.marne@gmail.com
# Many thanks to Association Dotclear
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; }
require_once dirname(__FILE__).'/inc/class.dc.recaptcha.php';
# check settings before load the filter
$core->blog->settings->addNamespace('dcReCaptcha');
$blog_settings =& $core->blog->settings->dcReCaptcha;
$dcRecaptcha_settings = array(
'public_key' => $blog_settings->reCaptcha_public_key,
'private_key' => $blog_settings->reCaptcha_private_key,
'theme' => $blog_settings->reCaptcha_theme,
'comments_form_enable' => $blog_settings->reCaptcha_comments_form_enable
);
# reCAPTCHA is not correctly configured
if(empty($dcRecaptcha_settings['private_key'])
|| empty($dcRecaptcha_settings['public_key'])) {
return;
}
# adding behaviors
$core->addBehavior('publicBeforeCommentCreate', array('dcReCaptchaBehaviorsPublic','publicBeforeDocument'));
if($dcRecaptcha_settings['comments_form_enable']) {
$core->addBehavior('publicCommentFormAfterContent', array('dcReCaptchaBehaviorsPublic','publicCommentFormAfterContent'));
}
$core->tpl->addValue('dcReCaptchaForm', array('tplDcReCaptcha', 'dcReCaptchaForm'));
class dcReCaptchaBehaviorsPublic
{
public static function publicBeforeDocument()
{
global $_ctx;
global $core;
# start session if not already started
$session_id = session_id();
if (empty($session_id)) {
session_start();
}
$dcReCaptcha = new dcReCaptcha($core);
# if the commentator is not authenticated
if (!isset($_SESSION['recaptcha_ok'])) {
$resp = $dcReCaptcha->checkAnswer();
if ($resp === true) {
$_SESSION['recaptcha_ok'] = true;
} else {
$_SESSION['recaptcha_ok'] = false;
unset($_SESSION['recaptcha_ok']);
}
}
}
public static function publicCommentFormAfterContent($core)
{
if (!isset($_SESSION['recaptcha_ok'])) {
$dcReCaptcha = new dcReCaptcha($core);
echo $dcReCaptcha->getReCaptchaHtml();
}
}
}
class tplDcReCaptcha
{
public static function dcReCaptchaForm($attr, $content)
{
global $core;
$res = '';
if (!isset($_SESSION['recaptcha_ok'])) {
$dcReCaptcha = new dcReCaptcha($core);
$res = '<p id="dcrecaptcha-form">'.
$dcReCaptcha->getReCaptchaHtml().
'</p>';
}
return $res;
}
}