Skip to content

Commit c89366b

Browse files
committed
Merge pull request #2 from gn36/master
Infinite Storage in Templates, fix errors on language selection in display
2 parents 6cda1c6 + ba0e22c commit c89366b

4 files changed

Lines changed: 58 additions & 37 deletions

File tree

controller/main.php

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,17 @@ private function display_pb()
201201
'snippet_title' => utf8_normalize_nfc(str_replace("\n", '', $this->request->variable('snippet_title', '', true))),
202202
'snippet_desc' => utf8_normalize_nfc(str_replace("\n", '', $this->request->variable('snippet_desc', '', true))),
203203
'snippet_text' => utf8_normalize_nfc($this->request->variable('snippet_text', '', true)),
204-
'snippet_prunable' => isset($_REQUEST['snippet_prunable']) ? true : false,
204+
'snippet_prunable' => 1,
205205
'snippet_highlight' => $this->request->variable('snippet_highlight', ''),
206206
'snippet_prune_on' => max(1, min(6, $this->request->variable('pruning_months', 0))),
207207
);
208208

209+
if($this->auth->acl_get('u_pastebin_post_notlim') && $this->request->variable('pruning_months',0) == -1)
210+
{
211+
//Infinite Time...
212+
$data['snippet_prunable'] = 0;
213+
}
214+
209215
$snippet_contents = $data['snippet_text'];
210216

211217
if (empty($data['snippet_title']))
@@ -314,7 +320,7 @@ private function display_pb()
314320

315321
$snippet_id = $db->sql_nextid();
316322

317-
$redirect_url = $this->helper->route('phpbbde_pastebin_main_controller', array("mode=view", "s=$snippet_id"));
323+
$redirect_url = $this->helper->route('phpbbde_pastebin_main_controller', array('mode' => "view", 's' => $snippet_id));
318324

319325
// Uncomment for instant redirect :)
320326
//redirect($redirect_url);
@@ -342,10 +348,10 @@ private function display_pb()
342348
'WHERE' => "pb.snippet_author = u.user_id AND pb.snippet_id = $snippet_id",
343349
));
344350
$result = $db->sql_query($sql);
345-
$row = $db->sql_fetchrow($result);
351+
$data = $db->sql_fetchrow($result);
346352
$db->sql_freeresult($result);
347353

348-
if (!$row)
354+
if (!$data)
349355
{
350356
$message = $user->lang['NO_VALID_SNIPPET'];
351357
$message .= '<br /><br />';
@@ -361,11 +367,11 @@ private function display_pb()
361367
trigger_error('PASTEBIN_AUTH_NO_VIEW');
362368
}
363369

364-
page_header(sprintf($user->lang['PASTEBIN_VIEW'], $row['snippet_title']));
370+
page_header(sprintf($user->lang['PASTEBIN_VIEW'], $data['snippet_title']));
365371

366-
$snippet_text = $row['snippet_text'];
372+
$snippet_text = $data['snippet_text'];
367373

368-
$highlight = (isset($_REQUEST['highlight'])) ? $this->request->variable('highlight', '') : $row['snippet_highlight'];
374+
$highlight = (isset($_REQUEST['highlight'])) ? $this->request->variable('highlight', '') : $data['snippet_highlight'];
369375

370376
if (!$pastebin->geshi_check($highlight))
371377
{
@@ -390,33 +396,24 @@ private function display_pb()
390396
's' => $snippet_id,
391397
));
392398

393-
$pruning_months_select = '';
394-
for ($i = 1; $i < 7; $i++)
395-
{
396-
$selected = ($i == (($row['snippet_prune_on'] - $row['snippet_time']) / $this::SECONDS_MONTH)) ? ' selected="selected"' : '';
397-
$pruning_months_select .= '<option' . $selected . ' value="' . $i . '">' . $i . '</option>';
398-
}
399-
400-
$snippet_download_url = $this->helper->route('phpbbde_pastebin_main_controller', array("mode" => "download", "s" => $row['snippet_id']));
399+
$snippet_download_url = $this->helper->route('phpbbde_pastebin_main_controller', array("mode" => "download", "s" => $data['snippet_id']));
401400

402401
$template->assign_vars(array(
403402
'SNIPPET_TEXT_ORIG' => $snippet_text,
404403
'SNIPPET_TEXT_DISPLAY' => $snippet_text_display,
405404

406-
'SNIPPET_DESC_V' => $row['snippet_desc'],
407-
'SNIPPET_TITLE_V' => $row['snippet_title'],
408-
'SNIPPET_AUTHOR' => $row['username'],
409-
'SNIPPET_AUTHOR_ID' => $row['user_id'],
410-
'SNIPPET_AUTHOR_COLOUR' => $row['user_colour'],
411-
'SNIPPET_AUTHOR_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
412-
'SNIPPET_DATE' => $user->format_date($row['snippet_time']),
413-
'SNIPPET_PRUNABLE' => ($row['snippet_prunable']) ? true : false,
414-
'PRUNING_MONTHS_SELECT' => $pruning_months_select,
415-
'HIGHLIGHT_SELECT' => $pastebin->highlight_select($highlight),
416-
'HIGHLIGHT_SELECT_MOD' => $pastebin->highlight_select($row['snippet_highlight']),
405+
'SNIPPET_DESC_V' => $data['snippet_desc'],
406+
'SNIPPET_TITLE_V' => $data['snippet_title'],
407+
'SNIPPET_AUTHOR' => $data['username'],
408+
'SNIPPET_AUTHOR_ID' => $data['user_id'],
409+
'SNIPPET_AUTHOR_COLOUR' => $data['user_colour'],
410+
'SNIPPET_AUTHOR_FULL' => get_username_string('full', $data['user_id'], $data['username'], $data['user_colour']),
411+
'SNIPPET_DATE' => $user->format_date($data['snippet_time']),
412+
413+
'HIGHLIGHT_SELECT_MOD' => $pastebin->highlight_select($data['snippet_highlight']),
417414
'DOWNLOAD_SNIPPET_EXPLAIN' => sprintf($user->lang['DOWNLOAD_SNIPPET_EXPLAIN'], '<a href="' . $snippet_download_url . '">', '</a>'),
418415

419-
'U_SNIPPET' => $this->helper->route('phpbbde_pastebin_main_controller', array("mode" => "view", "s" => $row['snippet_id'])),
416+
'U_SNIPPET' => $this->helper->route('phpbbde_pastebin_main_controller', array("mode" => "view", "s" => $data['snippet_id'])),
420417
'U_SNIPPET_DOWNLOAD' => $snippet_download_url,
421418

422419
'S_HIGHLIGHT' => $highlight,
@@ -583,20 +580,47 @@ private function display_pb()
583580
$pruning_months_select = '';
584581
for ($i = 1; $i < 7; $i++)
585582
{
586-
$selected = ($i == 1) ? ' selected="selected"' : '';
583+
if(isset($data['snippet_prune_on']))
584+
{
585+
$selected = ($data['snippet_prune_on'] - $data['snippet_time'] == $i * $this::SECONDS_MONTH) ? ' selected="selected"' : '';
586+
}
587+
else
588+
{
589+
$selected = ($i == 1) ? ' selected="selected"' : '';
590+
}
587591
$pruning_months_select .= '<option' . $selected . ' value="' . $i . '">' . $i . '</option>';
588592
}
589593

594+
//Allow infinite storage if it is already set and we are editing, or if the user is allowed to
595+
if((isset($data['snippet_prunable']) && !$data['snippet_prunable']) || $this->auth->acl_get('u_pastebin_post_notlim'))
596+
{
597+
if(isset($data['snippet_prunable']))
598+
{
599+
$selected = ($data['snippet_prunable'] == 0) ? ' selected="selected"' : '';
600+
}
601+
else
602+
{
603+
$selected = '';
604+
}
605+
$pruning_months_select .= '<option' . $selected . ' value="-1">' . $this->user->lang['INFINITE'] . '</option>';
606+
}
607+
608+
if(!isset($highlight))
609+
{
610+
$highlight = isset($data['snippet_highlight']) ? $data['snippet_highlight'] : 'php';
611+
}
612+
$highlight_select = $pastebin->highlight_select($highlight);
613+
590614
add_form_key('pastebinform');
591615

592616
$template->assign_vars(array(
593617
'SNIPPET_TITLE' => isset($data['snippet_title']) ? $data['snippet_title'] : '',
594618
'SNIPPET_DESC' => isset($data['snippet_desc']) ? $data['snippet_desc'] : '',
595619
'AUTHOR_FULL' => isset($data['username']) ? get_username_string('full', $data['user_id'], $data['username'], $data['user_colour']) : '',
596620
'SNIPPET_TEXT' => isset($data['snippet_text']) ? $data['snippet_text'] : '',
597-
'SNIPPET_PRUNABLE' => isset($data['snippet_prunable']) ? $data['snippet_prunable'] : true,
621+
//'SNIPPET_PRUNABLE' => isset($data['snippet_prunable']) ? $data['snippet_prunable'] : true,
598622

599-
'HIGHLIGHT_SELECT' => isset($data['snippet_highlight']) ? $pastebin->highlight_select($data['snippet_highlight']) : $pastebin->highlight_select('php'),
623+
'HIGHLIGHT_SELECT' => $highlight_select,
600624
'PRUNING_MONTHS_SELECT' => $pruning_months_select,
601625

602626
'FILESIZE' => $this->config['max_filesize'],

language/de/pastebin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
'RETURN_SNIPPET' => '%sEintrag anzeigen%s',
8484

8585
'SHORT_PRUNABLE' => 'Prunable - automatisch löschbar',
86+
'INFINITE' => 'Unendlich',
8687
'SNIPPET_NEW' => 'Neuer Eintrag',
8788
'SNIPPET_DESC' => 'Beschreibung',
8889
'SNIPPET_DOWNLOAD' => 'Eintrag herunterladen',

language/en/pastebin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
'RETURN_SNIPPET' => '%sShow entry%s',
8181

8282
'SHORT_PRUNABLE' => 'Prunable',
83+
'INFINITE' => 'Infinite',
8384
'SNIPPET_NEW' => 'New entry',
8485
'SNIPPET_DESC' => 'Description',
8586
'SNIPPET_DOWNLOAD' => 'Download entry',

styles/prosilver/template/pastebin_post.html

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,12 @@ <h3>{L_PASTEBIN_POST}</h3>
3131
<dt><label for="snippet_highlight">{L_SNIPPET_HIGHLIGHT}:</label></dt>
3232
<dd><select name="snippet_highlight" id="snippet_highlight">{HIGHLIGHT_SELECT}</select></dd>
3333
</dl>
34-
<!-- IF ORIGINAL -->
35-
<dl>
36-
<dt><label for="snippet_prunable">{L_SNIPPET_PRUNABLE}:</label><br /><span>{L_SNIPPET_PRUNABLE_EXPLAIN}</span></dt>
37-
<dd><label for="snippet_prunable"><input type="checkbox" name="snippet_prunable" id="snippet_prunable"<!-- IF SNIPPET_PRUNABLE --> checked="checked"<!-- ENDIF --> /> {L_SHORT_PRUNABLE}</label></dd>
38-
</dl>
39-
<!-- ELSE -->
34+
4035
<dl>
4136
<dt><label for="pruning_months">{L_PRUNING_MONTHS}:</label></dt>
4237
<dd><select name="pruning_months" id="pruning_months">{PRUNING_MONTHS_SELECT}</select> {L_PRUNING_MONTH_SHORT}</dd>
4338
</dl>
44-
<!-- ENDIF -->
39+
4540
</fieldset>
4641

4742
<h3>{L_SNIPPET_TEXT}</h3>

0 commit comments

Comments
 (0)