Skip to content

Commit 08fd4b7

Browse files
authored
Fixes file upload and a few small things, too (#21)
* Add new language object and use it in controller * use service files.factory * Add a few more allowed file formats * Add common checks * Change get('uploadname') to get('filename') in controller/main.php * Add snippet time to view template * Remove duplicate error messages and redudant code
1 parent 82c6e28 commit 08fd4b7

8 files changed

Lines changed: 145 additions & 93 deletions

File tree

config/services.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ services:
2525
- '@dbal.conn'
2626
- '@template'
2727
- '@user'
28+
- '@language'
29+
- '@files.factory'
2830
- '@controller.helper'
2931
- '@captcha.factory'
3032
- '@phpbbde.pastebin.functions.utility'
@@ -37,10 +39,10 @@ services:
3739
phpbbde.pastebin.base_listener:
3840
class: phpbbde\pastebin\event\base_events
3941
arguments:
40-
- '@auth'
4142
- '@template'
4243
- '@controller.helper'
4344
- '@user'
45+
- '@language'
4446
- '%core.root_path%'
4547
- '%core.php_ext%'
4648
tags:

controller/main.php

Lines changed: 99 additions & 79 deletions
Large diffs are not rendered by default.

event/base_events.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,55 @@ static public function getSubscribedEvents()
2727
);
2828
}
2929

30+
/** @var \phpbb\template\template */
31+
protected $template;
32+
33+
/** @var \phpbb\user */
34+
protected $user;
35+
36+
/* @var \phpbb\language\language */
37+
protected $language;
38+
39+
/** @var \phpbb\controller\helper */
40+
protected $helper;
41+
42+
/** @var string */
43+
protected $root_path;
44+
45+
/** @var string */
46+
protected $php_ext;
47+
3048
/**
3149
* Constructor
3250
*
33-
* @param \phpbb\auth\auth $auth Auth object
3451
* @param \phpbb\template\template $template Template object
3552
* @param \phpbb\controller\helper $helper Helper
53+
* @param \phpbb\user $user
54+
* @param \phpbb\language\language $language
3655
* @param string $phpbb_root_path phpBB root path (community/)
3756
* @param string $php_ext php file extension (php)
3857
* @param string $root_path php file extension (...phpbb.de/)
3958
*/
40-
public function __construct(\phpbb\auth\auth $auth, \phpbb\template\template $template, \phpbb\controller\helper $helper, \phpbb\user $user, $phpbb_root_path, $php_ext)
59+
public function __construct(
60+
\phpbb\template\template $template,
61+
\phpbb\controller\helper $helper,
62+
\phpbb\user $user,
63+
\phpbb\language\language $language,
64+
$root_path,
65+
$php_ext
66+
)
4167
{
42-
$this->auth = $auth;
4368
$this->template = $template;
44-
$this->phpbb_root_path = $phpbb_root_path;
69+
$this->root_path = $root_path;
4570
$this->helper = $helper;
4671
$this->php_ext = $php_ext;
4772
$this->user = $user;
73+
$this->language = $language;
4874
}
4975

5076
public function page_header_after($event)
5177
{
52-
$this->user->add_lang_ext('phpbbde/pastebin', 'global');
78+
$this->language->add_lang('global', 'phpbbde/pastebin');
5379

5480
$this->template->assign_vars(array(
5581
// Main Menu
@@ -63,7 +89,7 @@ public function viewonline_page($event)
6389
{
6490
if (strrpos($event['row']['session_page'], 'app.' . $this->php_ext . '/pastebin') === 0)
6591
{
66-
$event['location'] = $this->user->lang('PASTEBIN_VIEWONLINE');
92+
$event['location'] = $this->language->lang('PASTEBIN_VIEWONLINE');
6793
$event['location_url'] = $this->helper->route('phpbbde_pastebin_main_controller');
6894
}
6995
}

functions/pastebin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ function submit()
206206
function delete()
207207
{
208208
$sql = 'DELETE FROM ' . $this->pastebin_table . '
209-
WHERE snippet_id = ' . $this->data['snippet_id'];
209+
WHERE snippet_id = ' . (int) $this->data['snippet_id'];
210210
$this->db->sql_query($sql);
211211
$this->empty_data();
212212
}

language/de/pastebin.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
'DOWNLOAD_SNIPPET' => 'Eintrag herunterladen',
3535
'DOWNLOAD_SNIPPET_EXPLAIN' => 'Alternativ kannst du den gesamten Eintrag auch als Datei %sherunterladen%s.',
3636

37-
'ERR_NO_BODY' => 'Du hast kein Code eingefügt oder keine gültige Datei zum Upload ausgewählt.',
37+
'DISALLOWED_EXTENSION' => 'Die Dateierweiterung %s ist nicht erlaubt',
38+
39+
'ERR_NO_BODY' => 'Du hast keinen Code eingefügt oder keine gültige Datei zum Upload ausgewählt.',
3840
'ERR_NO_TITLE' => 'Du hast keinen Titel für den Eintrag eingegeben.',
3941
'ERR_NO_DESC' => 'Du hast keine Beschreibung für den Eintrag eingegeben.',
4042

@@ -53,7 +55,6 @@
5355
'PASTEBIN_AUTH_NO_POST' => 'Du hast keine Berechtigung, einen Eintrag zu erstellen.',
5456
'PASTEBIN_CONFIRM' => 'Visuelle Bestätigung',
5557
'PASTEBIN_CONFIRM_EXPLAIN' => 'Gib den Code genau so ein, wie du ihn siehst; Groß- und Kleinschreibung wird nicht unterschieden, Null wird nicht verwendet.',
56-
'PASTEBIN_DISALLOWED_EXTENSION' => 'Die Dateierweiterung %s ist nicht erlaubt',
5758
'PASTEBIN_EMPTY_FILEUPLOAD' => 'Die hochgeladene Datei ist leer.',
5859
'PASTEBIN_EXPLAIN' => 'Im Pastebin kannst du Codeabschnitte oder auch ganze Dateien ablegen, um sie zum Beispiel später in einem Supportthema zu verlinken.',
5960
'PASTEBIN_HELLO' => 'Hat dich jemand hierher geschickt?',

language/en/pastebin.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
'DOWNLOAD_SNIPPET' => 'Download as file',
3434
'DOWNLOAD_SNIPPET_EXPLAIN' => 'Alternatively, you can %sdownload%s the whole entry as a file.',
3535

36-
'ERR_NO_BODY' => 'You did not enter any code or upload a valid file.',
36+
'DISALLOWED_EXTENSION' => 'The file extension %s is not allowed.',
37+
38+
'ERR_NO_BODY' => 'You did not enter any code or a valid file for upload.',
3739
'ERR_NO_TITLE' => 'You did not enter a title for your entry.',
3840
'ERR_NO_DESC' => 'You did not enter a description for your entry.',
3941

@@ -52,11 +54,11 @@
5254
'PASTEBIN_AUTH_NO_POST' => 'You are not authorized to enter a new entry.',
5355
'PASTEBIN_CONFIRM' => 'Visual confirmation',
5456
'PASTEBIN_CONFIRM_EXPLAIN' => 'Enter the code exactly as you see it; capitalization will be ignored, zero is not used.',
55-
'PASTEBIN_DISALLOWED_EXTENSION' => 'The file extension %s is not allowed.',
5657
'PASTEBIN_EMPTY_FILEUPLOAD' => 'The uploaded file is empty.',
5758
'PASTEBIN_EXPLAIN' => 'In the pastebin, you can paste code snippets or whole files, for example to add a link to them to a support topic.',
5859
'PASTEBIN_HELLO' => 'Did someone direct you here?',
5960
'PASTEBIN_HELLO_EXPLAIN' => 'If you were directed here, please add the desired file or enter the code into the text area below and send the url to the person who sent you here.',
61+
'PASTEBIN_INSTALLED' => 'Pastebin was successfully installed.',
6062
'PASTEBIN_INVALID_FILENAME' => '%s is an invalid filename',
6163
'PASTEBIN_NOT_UPLOADED' => 'The upload of the file failed.',
6264
'PASTEBIN_NO_AUTH' => 'Information',
@@ -68,6 +70,7 @@
6870
'PASTEBIN_POST' => 'New entry',
6971
'PASTEBIN_POST_EXPLAIN' => 'Please enter a title, choose the language to highlight, and choose the storage duration. Optionally, you can add a description of the entry. Finally, you upload your code as a file <em>or</em> enter it in the text area below.',
7072
'PASTEBIN_TOO_MANY' => 'You exeeded the maximum number of login trials. Please try again later.',
73+
'PASTEBIN_UPDATED' => 'Pastebin was successfully updated to the latest version.',
7174
'PASTEBIN_UPLOAD' => 'Upload file',
7275
'PASTEBIN_UPLOAD_EXPLAIN' => 'If you selected a file for upload, code entered into the text area below will be ignored!',
7376
'PASTEBIN_VIEW' => 'View entry - %s',

styles/prosilver/template/pastebin_view.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h3>{SNIPPET_TITLE_V}</h3>
2-
<!-- IF SNIPPET_AUTHOR_FULL --><em class="author">{L_POST_BY_AUTHOR} {SNIPPET_AUTHOR_FULL}</em><!-- ENDIF -->
2+
<!-- IF SNIPPET_AUTHOR_FULL --><em class="author">{L_POST_BY_AUTHOR} {SNIPPET_AUTHOR_FULL} ({SNIPPET_TIME})</em><!-- ENDIF -->
33
<!-- IF SNIPPET_DESC_V -->
44
<dl>
55
<dt><strong>{L_SNIPPET_DESC}:</strong></dt>

styles/prosilver/theme/pastebin.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
display: block;
2121
padding: 1em ;
2222
margin-top: 1em;
23-
margin-bottom: 1em;
23+
margin-bottom: 1em;
2424
}
2525

2626
.pastebin #content {

0 commit comments

Comments
 (0)