@@ -54,6 +54,9 @@ class main
5454 /** @var \phpbbde\pastebin\functions\pastebin */
5555 protected $ pastebin ;
5656
57+ /** @var \phpbbde\pastebin\functions\utility */
58+ protected $ util ;
59+
5760 /** @var \phpbb\captcha\factory */
5861 protected $ captcha_factory ;
5962
@@ -77,10 +80,11 @@ class main
7780 * @param \phpbb\user $user
7881 * @param \phpbb\controller\helper $helper
7982 * @param \phpbbde\pastebin\functions\pastebin $pastebin
83+ * @param \phpbbde\pastebin\functions\utility $util
8084 * @param string $root_path
8185 * @param string $php_ext
8286 */
83- 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 , $ geshi_path , $ geshi_lang , $ pastebin_table )
87+ 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 \utility $ util , \ phpbbde \ pastebin \ functions \ pastebin $ pastebin , $ root_path , $ php_ext , $ geshi_path , $ geshi_lang , $ pastebin_table )
8488 {
8589 $ this ->auth = $ auth ;
8690 $ this ->cache = $ cache ;
@@ -93,6 +97,7 @@ public function __construct(\phpbb\auth\auth $auth, \phpbb\cache\service $cache,
9397 $ this ->root_path = $ root_path ;
9498 $ this ->php_ext = $ php_ext ;
9599 $ this ->pastebin = $ pastebin ;
100+ $ this ->util = $ util ;
96101 $ this ->captcha_factory = $ captcha_factory ;
97102
98103 $ this ->geshi_path = $ geshi_path ;
@@ -129,7 +134,7 @@ public function handle($name = '')
129134 */
130135 private function table ($ name )
131136 {
132- if ($ name == 'pastebin ' )
137+ if ($ name == 'pastebin ' )
133138 {
134139 return $ this ->pastebin_table ;
135140 }
@@ -140,7 +145,7 @@ private function table($name)
140145 */
141146 private function display_pb ()
142147 {
143- $ pastebin = $ this ->pastebin ;
148+ $ util = $ this ->util ;
144149 $ template = $ this ->template ;
145150 $ db = $ this ->db ;
146151 $ auth = $ this ->auth ;
@@ -150,8 +155,43 @@ private function display_pb()
150155 $ mode = $ this ->request ->variable ('mode ' , '' );
151156 $ confirm_id = $ this ->request ->variable ('confirm_id ' , '' );
152157 $ confirm_code = $ this ->request ->variable ('confirm_code ' , '' );
158+ $ snippet_id = $ this ->request ->variable ('s ' , 0 );
153159 $ submit = isset ($ _POST ['submit ' ]) ? true : false ;
154160
161+ if (in_array ($ mode , array ('view ' , 'download ' , 'moderate ' )))
162+ {
163+ // for all of these we have to check if the entry exists
164+
165+ $ sql = $ db ->sql_build_query ('SELECT ' , array (
166+ 'SELECT ' => 'pb.*, u.user_id, u.username, u.user_colour ' ,
167+ 'FROM ' => array (
168+ $ this ->table ('pastebin ' ) => 'pb ' ,
169+ USERS_TABLE => 'u ' ,
170+ ),
171+ 'WHERE ' => "pb.snippet_author = u.user_id AND pb.snippet_id = $ snippet_id " ,
172+ ));
173+ $ result = $ db ->sql_query ($ sql );
174+ $ data = $ db ->sql_fetchrow ($ result );
175+ $ db ->sql_freeresult ($ result );
176+
177+ if (!$ data )
178+ {
179+ $ message = $ user ->lang ['NO_VALID_SNIPPET ' ];
180+ $ message .= '<br /><br /> ' ;
181+ $ message .= sprintf ($ user ->lang ['RETURN_PASTEBIN ' ], '<a href=" ' . $ this ->helper ->route ('phpbbde_pastebin_main_controller ' ) . '"> ' , '</a> ' );
182+
183+ trigger_error ($ message );
184+ }
185+
186+ $ this ->pastebin ->load_from_array ($ data );
187+ $ snippet = $ this ->pastebin ;
188+
189+ $ this ->template ->assign_vars (array (
190+ 'S_AUTH_EDIT ' => ($ auth ->acl_get ('m_pastebin_edit ' ) || ($ auth ->acl_get ('u_pastebin_edit ' ) && $ snippet ['snippet_author ' ] == $ this ->user ->data ['user_id ' ])) ? true : false ,
191+ 'S_AUTH_DELETE ' => ($ auth ->acl_get ('m_pastebin_delete ' ) || ($ auth ->acl_get ('u_pastebin_delete ' ) && $ snippet ['snippet_author ' ] == $ this ->user ->data ['user_id ' ])) ? true : false ,
192+ ));
193+ }
194+
155195 // Some default values
156196 $ error = $ s_hidden_fields = array ();
157197
@@ -188,8 +228,6 @@ private function display_pb()
188228
189229 'S_AUTH_VIEW ' => ($ auth ->acl_get ('u_pastebin_view ' )) ? true : false ,
190230 'S_AUTH_POST ' => ($ auth ->acl_get ('u_pastebin_post ' )) ? true : false ,
191- 'S_AUTH_EDIT ' => ($ auth ->acl_get ('m_pastebin_edit ' )) ? true : false ,
192- 'S_AUTH_DELETE ' => ($ auth ->acl_get ('m_pastebin_delete ' )) ? true : false ,
193231 ));
194232
195233 // Now let's decide what to do
@@ -216,7 +254,7 @@ private function display_pb()
216254 'snippet_prune_on ' => max (1 , min (6 , $ this ->request ->variable ('pruning_months ' , 0 ))),
217255 );
218256
219- if ($ this ->auth ->acl_get ('u_pastebin_post_notlim ' ) && $ this ->request ->variable ('pruning_months ' ,0 ) == -1 )
257+ if ($ this ->auth ->acl_get ('u_pastebin_post_notlim ' ) && $ this ->request ->variable ('pruning_months ' ,0 ) == -1 )
220258 {
221259 //Infinite Time...
222260 $ data ['snippet_prunable ' ] = 0 ;
@@ -229,7 +267,7 @@ private function display_pb()
229267 $ error [] = $ user ->lang ['ERR_NO_TITLE ' ];
230268 }
231269
232- if (!$ pastebin ->geshi_check ($ data ['snippet_highlight ' ]))
270+ if (!$ util ->geshi_check ($ data ['snippet_highlight ' ]))
233271 {
234272 $ data ['snippet_highlight ' ] = 'text ' ;
235273 }
@@ -259,7 +297,7 @@ private function display_pb()
259297 $ error [] = $ user ->lang ['ERR_NO_BODY ' ];
260298 }
261299
262- if (!check_form_key ('pastebinform ' ))
300+ if (!check_form_key ('pastebinform ' ))
263301 {
264302 $ error [] = $ user ->lang ['FORM_INVALID ' ];
265303 }
@@ -324,32 +362,6 @@ private function display_pb()
324362 case 'view ' :
325363 case 'download ' :
326364 case 'moderate ' :
327-
328- // for all of these we have to check if the entry exists
329-
330- $ snippet_id = $ this ->request ->variable ('s ' , 0 );
331-
332- $ sql = $ db ->sql_build_query ('SELECT ' , array (
333- 'SELECT ' => 'pb.*, u.user_id, u.username, u.user_colour ' ,
334- 'FROM ' => array (
335- $ this ->table ('pastebin ' ) => 'pb ' ,
336- USERS_TABLE => 'u ' ,
337- ),
338- 'WHERE ' => "pb.snippet_author = u.user_id AND pb.snippet_id = $ snippet_id " ,
339- ));
340- $ result = $ db ->sql_query ($ sql );
341- $ data = $ db ->sql_fetchrow ($ result );
342- $ db ->sql_freeresult ($ result );
343-
344- if (!$ data )
345- {
346- $ message = $ user ->lang ['NO_VALID_SNIPPET ' ];
347- $ message .= '<br /><br /> ' ;
348- $ message .= sprintf ($ user ->lang ['RETURN_PASTEBIN ' ], '<a href=" ' . $ this ->helper ->route ('phpbbde_pastebin_main_controller ' ) . '"> ' , '</a> ' );
349-
350- trigger_error ($ message );
351- }
352-
353365 if ($ mode == 'view ' )
354366 {
355367 if (!$ auth ->acl_get ('u_pastebin_view ' ))
@@ -363,7 +375,7 @@ private function display_pb()
363375
364376 $ highlight = (isset ($ _REQUEST ['highlight ' ])) ? $ this ->request ->variable ('highlight ' , '' ) : $ data ['snippet_highlight ' ];
365377
366- if (!$ pastebin ->geshi_check ($ highlight ))
378+ if (!$ util ->geshi_check ($ highlight ))
367379 {
368380 $ highlight = 'php ' ;
369381 }
@@ -374,7 +386,7 @@ private function display_pb()
374386
375387 $ code = htmlspecialchars_decode ($ snippet_text );
376388
377- $ geshi = new \GeSHi ($ code , $ highlight , $ pastebin ->geshi_dir );
389+ $ geshi = new \GeSHi ($ code , $ highlight , $ util ->geshi_dir );
378390 $ geshi ->set_header_type (GESHI_HEADER_NONE );
379391 $ geshi ->enable_line_numbers (GESHI_NORMAL_LINE_NUMBERS , 100 );
380392
@@ -400,7 +412,7 @@ private function display_pb()
400412 'SNIPPET_AUTHOR_FULL ' => get_username_string ('full ' , $ data ['user_id ' ], $ data ['username ' ], $ data ['user_colour ' ]),
401413 'SNIPPET_DATE ' => $ user ->format_date ($ data ['snippet_time ' ]),
402414
403- 'HIGHLIGHT_SELECT_MOD ' => $ pastebin ->highlight_select ($ data ['snippet_highlight ' ]),
415+ 'HIGHLIGHT_SELECT_MOD ' => $ util ->highlight_select ($ data ['snippet_highlight ' ]),
404416 'DOWNLOAD_SNIPPET_EXPLAIN ' => sprintf ($ user ->lang ['DOWNLOAD_SNIPPET_EXPLAIN ' ], '<a href=" ' . $ snippet_download_url . '"> ' , '</a> ' ),
405417
406418 'U_SNIPPET ' => $ this ->helper ->route ('phpbbde_pastebin_main_controller ' , array ("mode " => "view " , "s " => $ data ['snippet_id ' ])),
@@ -422,7 +434,7 @@ private function display_pb()
422434 // Thanks download.php
423435 $ snippet_text = htmlspecialchars_decode (utf8_decode ($ data ['snippet_text ' ]));
424436
425- $ filename = htmlspecialchars_decode ($ data ['snippet_title ' ]) . '.txt ' ;
437+ $ filename = htmlspecialchars_decode ($ data ['snippet_title ' ]) . '. ' . $ this -> pastebin -> file_ext () ;
426438
427439 $ user_agent = $ this ->request ->server ('HTTP_USER_AGENT ' , '' );
428440 if (strpos ($ user_agent , 'MSIE ' ) !== false || strpos ($ user_agent , 'Safari ' ) !== false || strpos ($ user_agent , 'Konqueror ' ) !== false )
@@ -453,11 +465,15 @@ private function display_pb()
453465 else if ($ mode == 'moderate ' )
454466 {
455467 $ delete = (isset ($ _POST ['delete_snippet ' ])) ? true : false ;
456- $ prunable = (isset ($ _POST ['snippet_prunable ' ])) ? true : false ;
457468 $ highlight = $ this ->request ->variable ('snippet_highlight ' , '' );
458- $ pruning_months = max (1 , min (6 , $ this ->request ->variable ('pruning_months ' , 0 )));
469+ $ pruning_months = $ this ->request ->variable ('pruning_months ' , 0 );
470+ $ prunable = $ pruning_months != -1 ;
471+
472+ $ auth_edit = ($ auth ->acl_get ('m_pastebin_edit ' ) || ($ auth ->acl_get ('u_pastebin_edit ' ) && $ this ->user ->data ['user_id ' ] == $ snippet ['snippet_author ' ]));
473+ $ auth_delete = ($ auth ->acl_get ('m_pastebin_delete ' ) || ($ auth ->acl_get ('u_pastebin_delete ' ) && $ this ->user ->data ['user_id ' ] == $ snippet ['snippet_author ' ]));
459474
460- if (!$ auth ->acl_get ('m_pastebin_edit ' ) || ($ delete && !$ auth ->acl_get ('m_pastebin_delete ' )))
475+ // Generic permissions check
476+ if (!$ auth_edit && !$ auth_delete )
461477 {
462478 trigger_error ('PASTEBIN_AUTH_NO_VIEW ' );
463479 }
@@ -468,7 +484,7 @@ private function display_pb()
468484 redirect ($ this ->helper ->route ('phpbbde_pastebin_main_controller ' , array ("mode " =>"view " ,"s " =>$ snippet_id )));
469485 }
470486
471- if ($ delete )
487+ if ($ delete && $ auth_delete )
472488 {
473489 // Confirm box
474490 if (!confirm_box (true ))
@@ -478,21 +494,25 @@ private function display_pb()
478494 }
479495 else
480496 {
481- $ sql = 'DELETE FROM ' . $ this ->table ('pastebin ' ) . '
482- WHERE snippet_id = ' . $ snippet_id ;
497+ $ snippet ->delete ();
483498 $ redirect_append = array ();
484499 }
485500 }
486- else
501+ else if ( $ auth_edit )
487502 {
488- $ sql = 'UPDATE ' . $ this ->table ('pastebin ' ) . ' SET ' . $ db ->sql_build_array ('UPDATE ' , array (
489- 'snippet_prunable ' => (int ) $ prunable ,
490- 'snippet_highlight ' => $ highlight ,
491- 'snippet_prune_on ' => $ row ['snippet_time ' ] + ($ pruning_months * $ this ::SECONDS_MONTH ),
492- )) . ' WHERE snippet_id = ' . $ snippet_id ;
503+ $ snippet ->load_from_array (array (
504+ 'snippet_prunable ' => (int ) $ prunable ,
505+ 'snippet_highlight ' => $ highlight ,
506+ 'snippet_prune_on ' => $ data ['snippet_time ' ] + ($ pruning_months * $ this ::SECONDS_MONTH ),
507+ ));
508+ $ snippet ->submit ();
509+
493510 $ redirect_append = array ("mode " =>"view " ,"s " =>$ snippet_id );
494511 }
495- $ db ->sql_query ($ sql );
512+ else
513+ {
514+ trigger_error ('PASTEBIN_NOT_AUTH_EDIT ' );
515+ }
496516
497517 $ redirect_url = $ this ->helper ->route ('phpbbde_pastebin_main_controller ' , $ redirect_append );
498518
@@ -521,7 +541,7 @@ private function display_pb()
521541 $ confirm_image = '' ;
522542 if (!$ auth ->acl_get ('u_pastebin_post_novc ' ))
523543 {
524- if (!isset ($ captcha ))
544+ if (!isset ($ captcha ))
525545 {
526546 $ captcha = $ this ->captcha_factory ->get_instance ($ this ->config ['captcha_plugin ' ]);
527547 $ captcha ->init ($ this ::CONFIRM_PASTEBIN );
@@ -533,11 +553,11 @@ private function display_pb()
533553 $ prune_month = $ this ->request ->variable ('pruning_months ' , 0 );
534554 for ($ i = 1 ; $ i < 7 ; $ i ++)
535555 {
536- if (isset ($ data ['snippet_prune_on ' ]) && isset ($ data ['snippet_time ' ]))
556+ if (isset ($ data ['snippet_prune_on ' ]) && isset ($ data ['snippet_time ' ]))
537557 {
538558 $ selected = ($ data ['snippet_prune_on ' ] - $ data ['snippet_time ' ] == $ i * $ this ::SECONDS_MONTH ) ? ' selected="selected" ' : '' ;
539559 }
540- else if ($ prune_month )
560+ else if ($ prune_month )
541561 {
542562 $ selected = ($ i == $ prune_month ) ? ' selected="selected" ' : '' ;
543563 }
@@ -549,9 +569,9 @@ private function display_pb()
549569 }
550570
551571 //Allow infinite storage if it is already set and we are editing, or if the user is allowed to
552- if ((isset ($ data ['snippet_prunable ' ]) && !$ data ['snippet_prunable ' ]) || $ this ->auth ->acl_get ('u_pastebin_post_notlim ' ))
572+ if ((isset ($ data ['snippet_prunable ' ]) && !$ data ['snippet_prunable ' ]) || $ this ->auth ->acl_get ('u_pastebin_post_notlim ' ))
553573 {
554- if (isset ($ data ['snippet_prunable ' ]))
574+ if (isset ($ data ['snippet_prunable ' ]))
555575 {
556576 $ selected = ($ data ['snippet_prunable ' ] == 0 || $ prune_month == -1 ) ? ' selected="selected" ' : '' ;
557577 }
@@ -562,11 +582,11 @@ private function display_pb()
562582 $ pruning_months_select .= '<option ' . $ selected . ' value="-1"> ' . $ this ->user ->lang ['INFINITE ' ] . '</option> ' ;
563583 }
564584
565- if (!isset ($ highlight ))
585+ if (!isset ($ highlight ))
566586 {
567587 $ highlight = isset ($ data ['snippet_highlight ' ]) ? $ data ['snippet_highlight ' ] : 'php ' ;
568588 }
569- $ highlight_select = $ pastebin ->highlight_select ($ highlight );
589+ $ highlight_select = $ util ->highlight_select ($ highlight );
570590
571591 add_form_key ('pastebinform ' );
572592
0 commit comments