This repository has been archived by the owner on Jul 10, 2019. It is now read-only.
forked from sayakb/sticky-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.php
executable file
·212 lines (183 loc) · 4.96 KB
/
list.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
/**
* Sticky Notes pastebin
* @ver 0.3
* @license BSD License - www.opensource.org/licenses/bsd-license.php
*
* Copyright (c) 2012 Sayak Banerjee <[email protected]>
* All rights reserved. Do not remove this copyright notice.
*/
// Invoke required files
include_once('init.php');
// Collect some data
$project = $core->variable('project', '');
$page = $core->variable('page', 1);
$mode = $core->variable('mode', '');
$rss = $core->variable('rss', false);
if (empty($mode))
{
$mode = $core->variable('format', '');
$_GET['mode'] = $mode;
}
// Global variables
$count = 0;
$output_data = '';
$published = date('d M Y, h:i:s e', 1288800000);
// Validate mode
if ($mode && $mode != 'xml' && $mode != 'json')
{
die;
}
// Initialize the skin file
if ($rss)
{
$skin->init('rss.xml');
}
else if ($mode)
{
$skin->init("api_list.{$mode}");
}
else
{
$skin->init('tpl_list');
}
// Calculate the first paste count
if ($rss)
{
$lim_start = 0;
}
else
{
$lim_start = ($page * 10) - 10;
}
// Escape the project
$db->escape($project);
// Get total number of posts
$sql = "SELECT COUNT(id) AS total FROM {$db->prefix}main WHERE " .
(!empty($project) ? "project = '{$project}' AND " : '') .
'private = 0';
$row = $db->query($sql);
$total = $row[0]['total'];
// Get page numbers
$pagination = $skin->pagination($total, $page);
// Get the list
$sql = "SELECT * FROM {$db->prefix}main WHERE " .
(!empty($project) ? "project = '{$project}' AND " : '') .
'private = 0 ORDER BY timestamp ' .
"DESC LIMIT {$lim_start}, 10";
$rows = $db->query($sql);
$rowcount = count($rows);
// Populate list items
foreach ($rows as $row)
{
$count++;
// We need 5 lines, whatsoever
$lines = substr_count($row['data'], "\n");
if ($lines > 5)
{
$lines_arr = explode("\n", $row['data']);
$row['data'] = '';
for ($idx = 0; $idx < 5; $idx++)
{
$row['data'] .= ($lines_arr[$idx] . "\n");
}
$row['data'] = substr($row['data'], 0, strlen($row['data']) - 2);
}
// Configure GeSHi
$geshi = new GeSHi($row['data'], $row['language']);
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);
$geshi->set_header_type(GESHI_HEADER_DIV);
$geshi->set_line_style('background: #f7f7f7; text-shadow: 0px 1px #fff; padding: 1px;',
'background: #fbfbfb; text-shadow: 0px 1px #fff; padding: 1px;');
$geshi->set_overall_style('word-wrap:break-word;');
// Generate the data
$user = empty($row['author']) ? $lang->get('anonymous') : htmlspecialchars($row['author']);
$timestamp = $row['timestamp'];
$time = date('d M Y, h:i:s e', $timestamp);
$info = $lang->get('posted_info');
$info = preg_replace('/\_\_user\_\_/', $user, $info);
$info = preg_replace('/\_\_time\_\_/', $time, $info);
// Get first post time
if ($count == 1)
{
$published = $time;
}
// Before we display, we need to escape the data from the skin/lang parsers
$code_data = (!$rss ? $geshi->parse_code() : nl2br(htmlspecialchars($row['data'])));
if ($rss)
{
$core->rss_encode($code_data);
}
else
{
$lang->escape($code_data);
$skin->escape($code_data);
}
// Assign template variables
$skin->assign(array(
'paste_id' => $row['id'],
'paste_url' => $nav->get_paste($row['id'], null, $project, $rss),
'paste_data' => $code_data,
'paste_lang' => htmlspecialchars($row['language']),
'paste_info' => $info,
'paste_time' => $time,
'paste_timestamp' => $timestamp,
'error_visibility' => 'hidden',
'geshi_stylesheet' => $geshi->get_stylesheet(),
));
if ($rss)
{
$output_data .= $skin->output('rss_item.xml');
}
else if ($mode)
{
$output_data .= $api->parse($mode, $count, $row['id'], ($count == $rowcount));
}
else
{
$output_data .= $skin->output('tpl_list_item');
}
}
// Assign some final variables
if ($rowcount)
{
$skin->assign(array(
'error_visibility' => 'hidden',
'data_visibility' => 'visible',
));
}
else
{
if ($mode)
{
$skin->assign('error_message', 'err_no_pastes');
echo $skin->output("api_error.{$mode}");
die;
}
else
{
$skin->assign(array(
'error_visibility' => 'visible',
'data_visibility' => 'hidden',
));
}
}
$skin->assign(array(
'paste_count' => $rowcount,
'paste_pages' => ceil($total / 10),
'error_text' => $lang->get('no_pastes'),
'list_data' => $output_data,
'list_pagination' => $pagination,
'feed_time' => $published,
));
// Output the page
if ($rss || $mode)
{
$skin->output(false, true);
}
else
{
$skin->title($lang->get('paste_archive') . ' • ' . $lang->get('site_title'));
$skin->output();
}
?>