@@ -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&id= ' . $ confirm_id . '&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 {
0 commit comments