Skip to content

Commit 35af3dd

Browse files
committed
Merge pull request #3 from gn36/dev/captcha
Use default captcha.
2 parents c89366b + cf28027 commit 35af3dd

3 files changed

Lines changed: 27 additions & 82 deletions

File tree

config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ services:
2020
- @template
2121
- @user
2222
- @controller.helper
23+
- @captcha.factory
2324
- @phpbbde.pastebin.functions.pastebin
2425
- %core.root_path%
2526
- %core.php_ext%

controller/main.php

Lines changed: 21 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class main
5252
/** @var \phpbbde\pastebin\functions\pastebin */
5353
protected $pastebin;
5454

55+
/** @var \phpbb\captcha\factory */
56+
protected $captcha_factory;
57+
5558
/** @var string */
5659
protected $ext_path;
5760

@@ -75,7 +78,7 @@ class main
7578
* @param string $root_path
7679
* @param string $php_ext
7780
*/
78-
public function __construct(\phpbb\auth\auth $auth, \phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\request\request $request, \phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, \phpbbde\pastebin\functions\pastebin $pastebin, $root_path, $php_ext)
81+
public function __construct(\phpbb\auth\auth $auth, \phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\request\request $request, \phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, \phpbb\captcha\factory $captcha_factory, \phpbbde\pastebin\functions\pastebin $pastebin, $root_path, $php_ext)
7982
{
8083
$this->auth = $auth;
8184
$this->cache = $cache;
@@ -88,6 +91,7 @@ public function __construct(\phpbb\auth\auth $auth, \phpbb\cache\service $cache,
8891
$this->root_path = $root_path;
8992
$this->php_ext = $php_ext;
9093
$this->pastebin = $pastebin;
94+
$this->captcha_factory = $captcha_factory;
9195

9296
global $phpbb_container;
9397
$this->geshi_path = $phpbb_container->getParameter('phpbbde.pastebin.geshi');
@@ -259,40 +263,16 @@ private function display_pb()
259263
{
260264
$user->add_lang('ucp');
261265

262-
if (!$confirm_id)
266+
$captcha = $this->captcha_factory->get_instance($this->config['captcha_plugin']);
267+
$captcha->init($this::CONFIRM_PASTEBIN);
268+
269+
if (!$captcha->is_solved())
263270
{
264271
$error[] = $user->lang['CONFIRM_CODE_WRONG'];
265272
}
266273
else
267274
{
268-
$sql = 'SELECT code
269-
FROM ' . CONFIRM_TABLE . "
270-
WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
271-
AND session_id = '" . $db->sql_escape($user->session_id) . "'
272-
AND confirm_type = " . $this::CONFIRM_PASTEBIN;
273-
$result = $db->sql_query($sql);
274-
$row = $db->sql_fetchrow($result);
275-
$db->sql_freeresult($result);
276-
277-
if ($row)
278-
{
279-
if (strcasecmp($row['code'], $confirm_code) === 0)
280-
{
281-
$sql = 'DELETE FROM ' . CONFIRM_TABLE . "
282-
WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
283-
AND session_id = '" . $db->sql_escape($user->session_id) . "'
284-
AND confirm_type = " . $this::CONFIRM_PASTEBIN;
285-
$db->sql_query($sql);
286-
}
287-
else
288-
{
289-
$error[] = $user->lang['CONFIRM_CODE_WRONG'];
290-
}
291-
}
292-
else
293-
{
294-
$error[] = $user->lang['CONFIRM_CODE_WRONG'];
295-
}
275+
$captcha->garbage_collect($this::CONFIRM_PASTEBIN);
296276
}
297277
}
298278

@@ -533,57 +513,26 @@ private function display_pb()
533513
$confirm_image = '';
534514
if (!$auth->acl_get('u_pastebin_post_novc'))
535515
{
536-
$str = '';
537-
$sql = 'SELECT session_id
538-
FROM ' . SESSIONS_TABLE;
539-
$result = $db->sql_query($sql);
540-
541-
if ($row = $db->sql_fetchrow($result))
516+
if(!isset($captcha))
542517
{
543-
$sql_in = array();
544-
do
545-
{
546-
$sql_in[] = (string) $row['session_id'];
547-
}
548-
while ($row = $db->sql_fetchrow($result));
549-
550-
if (sizeof($sql_in))
551-
{
552-
$sql = 'DELETE FROM ' . CONFIRM_TABLE . '
553-
WHERE ' . $db->sql_in_set('session_id', $sql_in, true) . '
554-
AND confirm_type = ' . $this::CONFIRM_PASTEBIN;
555-
$db->sql_query($sql);
556-
}
518+
$captcha = $this->captcha_factory->get_instance($this->config['captcha_plugin']);
519+
$captcha->init($this::CONFIRM_PASTEBIN);
557520
}
558-
$db->sql_freeresult($result);
559-
560-
$code = gen_rand_string(mt_rand(5, 8));
561-
$confirm_id = md5(unique_id($user->ip));
562-
$seed = hexdec(substr(unique_id(), 4, 10));
563-
564-
// compute $seed % 0x7fffffff
565-
$seed -= 0x7fffffff * floor($seed / 0x7fffffff);
566-
567-
$sql = 'INSERT INTO ' . CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array(
568-
'confirm_id' => (string) $confirm_id,
569-
'session_id' => (string) $user->session_id,
570-
'confirm_type' => (int) $this::CONFIRM_PASTEBIN,
571-
'code' => (string) $code,
572-
'seed' => (int) $seed)
573-
);
574-
$db->sql_query($sql);
575-
576-
$confirm_image = '<img src="' . append_sid("{$this->root_path}ucp.{$this->php_ext}", 'mode=confirm&amp;id=' . $confirm_id . '&amp;type=' . $this::CONFIRM_PASTEBIN . $str) . '" alt="" title="" />';
577-
$s_hidden_fields['confirm_id'] = $confirm_id;
521+
$this->template->assign_var('CAPTCHA_TEMPLATE', $captcha->get_template());
578522
}
579523

580524
$pruning_months_select = '';
525+
$prune_month = $this->request->variable('pruning_months', 0);
581526
for ($i = 1; $i < 7; $i++)
582527
{
583-
if(isset($data['snippet_prune_on']))
528+
if(isset($data['snippet_prune_on']) && isset($data['snippet_time']))
584529
{
585530
$selected = ($data['snippet_prune_on'] - $data['snippet_time'] == $i * $this::SECONDS_MONTH) ? ' selected="selected"' : '';
586531
}
532+
else if($prune_month)
533+
{
534+
$selected = ($i == $prune_month) ? ' selected="selected"' : '';
535+
}
587536
else
588537
{
589538
$selected = ($i == 1) ? ' selected="selected"' : '';
@@ -596,7 +545,7 @@ private function display_pb()
596545
{
597546
if(isset($data['snippet_prunable']))
598547
{
599-
$selected = ($data['snippet_prunable'] == 0) ? ' selected="selected"' : '';
548+
$selected = ($data['snippet_prunable'] == 0 || $prune_month == -1) ? ' selected="selected"' : '';
600549
}
601550
else
602551
{

styles/prosilver/template/pastebin_post.html

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,14 @@ <h3>{L_SNIPPET_TEXT}</h3>
5656
</dl>
5757
</fieldset>
5858

59-
<!-- IF S_CONFIRM_CODE -->
59+
<!-- IF CAPTCHA_TEMPLATE -->
6060
<h3>{L_PASTEBIN_CONFIRM}</h3>
6161
<p>{L_PASTEBIN_CONFIRM_EXPLAIN}</p>
6262

63-
<fieldset class="fields2">
64-
<dl>
65-
<dt><label for="confirm_code">{L_CONFIRM_CODE}:</label></dt>
66-
<dd>{CONFIRM_IMG}</dd>
67-
<dd><input type="text" name="confirm_code" id="confirm_code" size="8" maxlength="8" class="inputbox narrow" title="{L_PASTEBIN_CONFIRM}" tabindex="4" /></dd>
68-
69-
<dd>{L_CONFIRM_CODE_EXPLAIN}</dd>
70-
</dl>
71-
</fieldset>
63+
64+
<!-- DEFINE $CAPTCHA_TAB_INDEX = 8 -->
65+
<!-- INCLUDE {CAPTCHA_TEMPLATE} -->
66+
7267
<!-- ENDIF -->
7368

7469
<span class="corners-bottom"><span></span></span></div>

0 commit comments

Comments
 (0)