Skip to content

Commit a3e42bc

Browse files
committed
[ticket/10] Apply correct file extension according to stored code type.
1 parent 391b1a7 commit a3e42bc

2 files changed

Lines changed: 104 additions & 1 deletion

File tree

controller/main.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ private function display_pb()
434434
// Thanks download.php
435435
$snippet_text = htmlspecialchars_decode(utf8_decode($data['snippet_text']));
436436

437-
$filename = htmlspecialchars_decode($data['snippet_title']) . '.txt';
437+
$filename = htmlspecialchars_decode($data['snippet_title']) . '.' . $this->pastebin->file_ext();
438438

439439
$user_agent = $this->request->server('HTTP_USER_AGENT', '');
440440
if (strpos($user_agent, 'MSIE') !== false || strpos($user_agent, 'Safari') !== false || strpos($user_agent, 'Konqueror') !== false)

functions/pastebin.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class pastebin implements \ArrayAccess
1818
/** @var array */
1919
protected $data;
2020

21+
/** @var array */
22+
protected $file_ext;
23+
2124
/** @var \phpbb\db\driver\driver_interface */
2225
protected $db;
2326

@@ -34,6 +37,92 @@ function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, $
3437
$this->pastebin_table = $pastebin_table;
3538
$this->empty_data();
3639

40+
$this->file_ext = array(
41+
'text' => 'txt',
42+
'php' => 'php',
43+
'sql' => 'sql',
44+
'html4strict' => 'htm',
45+
'css' => 'css',
46+
'javascript' => 'js',
47+
'java' => 'java',
48+
'xml' => 'xml',
49+
'asp' => 'asp',
50+
'c' => 'c',
51+
'cpp' => 'cpp',
52+
'csharp' => 'cs',
53+
'perl' => 'pl',
54+
'vb' => 'vbs',
55+
'diff' => 'diff',
56+
'robots' => 'txt',
57+
'smarty' => 'html',
58+
59+
'actionscript' => 'as',
60+
'ada' => 'ada',
61+
'apache' => 'txt',
62+
'applescript' => 'scrpt',
63+
'asm' => 'asm',
64+
'autoit' => 'txt',
65+
'bash' => 'sh',
66+
'blitzbasic' => 'bas',
67+
'bnf' => 'bnf',
68+
'c_mac' => 'c',
69+
'caddcl' => 'dcl',
70+
'cadlisp' => 'lisp',
71+
'cfdg' => 'cfd',
72+
'cfm' => 'cfm',
73+
'cpp-qt' => 'cpp',
74+
'css-gen.cfg' => 'cfg',
75+
'c_mac' => 'c',
76+
'd' => 'd',
77+
'delphi' => 'dpr',
78+
'div' => 'div',
79+
'dos' => 'bat',
80+
'eiffel' => 'E',
81+
'fortran' => 'F',
82+
'freebasic' => 'bas',
83+
'gml' => 'gml',
84+
'groovy' => 'groovy',
85+
'idl' => 'idl',
86+
'ini' => 'ini',
87+
'inno' => 'ino',
88+
'io' => 'io',
89+
'java5' => 'java',
90+
'latex' => 'tex',
91+
'lisp' => 'lsp',
92+
'lua' => 'lua',
93+
'matlab' => 'm',
94+
'mirc' => 'mrc',
95+
'mpasm' => 'asm',
96+
'mysql' => 'sql',
97+
'nsis' => 'nsh',
98+
'objc' => 'C',
99+
'ocaml-brief' => 'ml',
100+
'ocaml' => 'ml',
101+
'oobas' => 'bas',
102+
'oracle8' => 'sql',
103+
'pascal' => 'p',
104+
'php-brief' => 'php',
105+
'ruby' => 'rb',
106+
'sas' => 'sas',
107+
'scheme' => 's',
108+
'sdlbasic' => 'bas',
109+
'smalltalk' => 'st',
110+
'tcl' => 'tcl',
111+
'thinbasic' => 'bas',
112+
'tsql' => 'sql',
113+
'plsql' => 'sql',
114+
'python' => 'py',
115+
'qbasic' => 'bas',
116+
'rails' => 'rb',
117+
'reg' => 'reg',
118+
'vbnet' => 'vbs',
119+
'vhdl' => 'vhdl',
120+
'visualfoxpro' => 'fky',
121+
'winbatch' => 'bat',
122+
'xpp' => 'xpp',
123+
'z80' => 'z80',
124+
);
125+
37126
}
38127

39128
/**
@@ -122,6 +211,20 @@ function delete()
122211
$this->empty_data();
123212
}
124213

214+
/**
215+
* Returns file extension for this entry depending on syntax highlighting.
216+
*
217+
* This will probably not always be correct, but more often than always using "txt".
218+
*/
219+
function file_ext()
220+
{
221+
if(isset($this->file_ext[$this->data['snippet_highlight']]))
222+
{
223+
return $this->file_ext[$this->data['snippet_highlight']];
224+
}
225+
return 'txt';
226+
}
227+
125228
// ArrayAccess
126229
//
127230

0 commit comments

Comments
 (0)