Skip to content

Commit 3d561ba

Browse files
authored
Merge pull request #58 from Mike-on-Tour/3.2.x
implement snippet edit function
2 parents 8b3658f + be5edf1 commit 3d561ba

File tree

6 files changed

+53
-12
lines changed

6 files changed

+53
-12
lines changed

controller/main.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private function display_pb()
156156
$snippet_id = $this->request->variable('s', 0);
157157
$submit = $this->request->is_set_post('submit');
158158

159-
if (in_array($mode, array('view', 'download', 'moderate')))
159+
if (in_array($mode, array('view', 'download', 'moderate', 'edit_snippet')))
160160
{
161161
// for all of these we have to check if the entry exists
162162

@@ -232,6 +232,35 @@ private function display_pb()
232232
// Now let's decide what to do
233233
switch ($mode)
234234
{
235+
case 'edit_snippet':
236+
if (!check_form_key('pastebinform'))
237+
{
238+
trigger_error('PASTEBIN_FORM_INVALID');
239+
}
240+
else
241+
{
242+
$data = [
243+
'snippet_id' => $snippet_id,
244+
'snippet_text' => $this->request->variable('edit_snippet', '', true),
245+
];
246+
247+
$snippet->load_from_array($data);
248+
$snippet->submit();
249+
250+
$redirect_append = array("mode"=>"view","s"=>$snippet_id);
251+
$redirect_url = $this->helper->route('phpbbde_pastebin_main_controller', $redirect_append);
252+
253+
$message = $this->language->lang('PASTEBIN_SNIPPET_MODERATED');
254+
$message .= '<br /><br />';
255+
$message .= $this->language->lang('PASTEBIN_RETURN_SNIPPET', '<a href="' . $redirect_url . '">', '</a>');
256+
257+
meta_refresh(3, $redirect_url);
258+
trigger_error($message);
259+
}
260+
261+
262+
break;
263+
235264
case 'post':
236265
// process submitted data from the posting form
237266
if (!$this->auth->acl_get('u_pastebin_post'))

language/de/pastebin.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
'PASTEBIN_ERR_NO_BODY' => 'Du hast keinen Code eingefügt oder keine gültige Datei zum Upload ausgewählt.',
4444
'PASTEBIN_ERR_NO_TITLE' => 'Du hast keinen Titel für den Eintrag eingegeben.',
4545
'PASTEBIN_ERR_NO_DESC' => 'Du hast keine Beschreibung für den Eintrag eingegeben.',
46+
'PASTEBIN_FORM_INVALID' => 'Ungültiges Formular.',
4647

4748
'PASTEBIN_HIGHLIGHT_LANG' => 'Syntaxhervorhebung',
4849

@@ -103,6 +104,7 @@
103104
'PASTEBIN_SNIPPET_PRUNABLE' => 'Eintrag prunable - automatisch löschbar',
104105
'PASTEBIN_SNIPPET_PRUNABLE_EXPLAIN' => 'Wenn diese Option deaktiviert ist, wird der Eintrag nicht in die monatlich automatisch zu löschenden Einträge aufgenommen.',
105106
'PASTEBIN_SNIPPET_SUBMITTED' => 'Dein Eintrag wurde erfolgreich erstellt.',
107+
'PASTEBIN_SNIPPET_SAVE' => 'Änderungen speichern',
106108

107109
// Language keys for Syntax highlighting dropdown
108110
'PASTEBIN_LANGS_TEXT' => 'Text',

language/de/permissions_pastebin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
'ACL_U_PASTEBIN_POST' => 'Kann Snippets posten',
4343
'ACL_U_PASTEBIN_POST_NOVC' => 'Kann Snippets posten ohne visuelle Bestätigung',
4444
'ACL_U_PASTEBIN_POST_NOTLIM' => 'Kann Snippets dauerhaft in den Pastebin einstellen',
45-
'ACL_U_PASTEBIN_EDIT' => 'Kann eigene Snippets bearbeiten (Speicherdauer, Syntaxhervorhebung)',
45+
'ACL_U_PASTEBIN_EDIT' => 'Kann eigene Snippets bearbeiten (Speicherdauer, Syntaxhervorhebung, Quellcode)',
4646
'ACL_U_PASTEBIN_DELETE' => 'Kann eigene Snippets löschen',
4747

4848
// Moderator perms,
49-
'ACL_M_PASTEBIN_EDIT' => 'Kann Snippets editieren (Speicherdauer, Syntaxhervorhebung)',
49+
'ACL_M_PASTEBIN_EDIT' => 'Kann Snippets editieren (Speicherdauer, Syntaxhervorhebung, Quellcode)',
5050
'ACL_M_PASTEBIN_DELETE' => 'Kann Snippets löschen',
5151
'ACL_M_PASTEBIN_POST_NOTLIM' => 'Kann die automatische Löschung von Snippets deaktivieren',
5252
));

language/en/pastebin.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
'PASTEBIN_ERR_NO_BODY' => 'You did not enter any code or a valid file for upload.',
4343
'PASTEBIN_ERR_NO_TITLE' => 'You did not enter a title for your entry.',
4444
'PASTEBIN_ERR_NO_DESC' => 'You did not enter a description for your entry.',
45+
'PASTEBIN_FORM_INVALID' => 'Invalid form.',
4546

4647
'PASTEBIN_HIGHLIGHT_LANG' => 'Syntax highlighting',
4748

@@ -102,6 +103,7 @@
102103
'PASTEBIN_SNIPPET_PRUNABLE' => 'Entry prunable',
103104
'PASTEBIN_SNIPPET_PRUNABLE_EXPLAIN' => 'If this option is disabled, the entry will not be entered in the monthly list of prunable entries.',
104105
'PASTEBIN_SNIPPET_SUBMITTED' => 'Your entry was sucessfully created.',
106+
'PASTEBIN_SNIPPET_SAVE' => 'Save edited snippet',
105107

106108
// Language keys for Syntax highlighting dropdown
107109
'PASTEBIN_LANGS_TEXT' => 'Text',

language/en/permissions_pastebin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
'ACL_U_PASTEBIN_POST' => 'Can post pastebin entries',
4343
'ACL_U_PASTEBIN_POST_NOVC' => 'Can post pastebin entries without visual confirmation',
4444
'ACL_U_PASTEBIN_POST_NOTLIM' => 'Can post non-pruned pastebin entries',
45-
'ACL_U_PASTEBIN_EDIT' => 'Can edit own pastebin entries (Storage duration, Syntax highlighting)',
45+
'ACL_U_PASTEBIN_EDIT' => 'Can edit own pastebin entries (Storage duration, Syntax highlighting, Source code)',
4646
'ACL_U_PASTEBIN_DELETE' => 'Can delete own pastebin entries',
4747

4848
// Moderator perms
49-
'ACL_M_PASTEBIN_EDIT' => 'Can edit pastebin entries (Storage duration, Syntax highlighting)',
49+
'ACL_M_PASTEBIN_EDIT' => 'Can edit pastebin entries (Storage duration, Syntax highlighting, Source code)',
5050
'ACL_M_PASTEBIN_DELETE' => 'Can delete pastebin entries',
5151
'ACL_M_PASTEBIN_POST_NOTLIM' => 'Can deactivate pruning of selected pastebin entries',
5252
));

styles/prosilver/template/pastebin_view.html

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@ <h3>{{ SNIPPET_TITLE_V }}</h3>
2929
</dl>
3030

3131
<h3>{{ lang('PASTEBIN_COPY_PASTE') }}</h3>
32-
<p>
33-
{{ lang('PASTEBIN_COPY_PASTE_EXPLAIN') }} {{ DOWNLOAD_SNIPPET_EXPLAIN }}<br />
34-
<div class="textwrapper">
35-
<textarea id="copy_paste" class="inputbox" rows="5" cols="76" tabindex="4">{{ SNIPPET_TEXT_ORIG }}</textarea>
36-
</div>
37-
<input type="button" class="button1" onclick="getElementById('copy_paste').select(); return false;" value="{{ lang('PASTEBIN_SELECT_CODE') }}" />
38-
</p>
32+
<form id="edit_form" method="post" action="{{ S_FORM_ACTION }}">
33+
<p>
34+
{{ lang('PASTEBIN_COPY_PASTE_EXPLAIN') }} {{ DOWNLOAD_SNIPPET_EXPLAIN }}<br />
35+
<div class="textwrapper">
36+
<textarea id="copy_paste" class="inputbox" name="edit_snippet" rows="5" cols="76" tabindex="4">{{ SNIPPET_TEXT_ORIG }}</textarea>
37+
</div>
38+
<input type="button" class="button1" onclick="getElementById('copy_paste').select(); return false;" value="{{ lang('PASTEBIN_SELECT_CODE') }}" />
39+
{% if S_AUTH_EDIT %}
40+
<input type="hidden" name="mode" value="edit_snippet" />
41+
{{ S_HIDDEN_FIELDS_V }}
42+
&nbsp;<input type="submit" class="button1" value="{{ lang('PASTEBIN_SNIPPET_SAVE') }}" />
43+
{% endif %}
44+
</p>
45+
{{ S_FORM_TOKEN }}
46+
</form>

0 commit comments

Comments
 (0)