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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235 |
<?php
/**
*
* @package Icy Phoenix
* @version $Id$
* @copyright (c) 2008 Icy Phoenix
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
if (!defined('IN_ICYPHOENIX'))
{
die('Hacking attempt');
}
/**
* For display of custom parsed text on user-facing pages
* Expects $text to be the value directly from the database (stored value)
*/
function generate_text_for_display($text, $only_smileys = false, $censor = true, $acro_autolinks = false, $forum_id = '999999')
{
global $bbcode, $config, $user;
if (empty($text))
{
return '';
}
if (defined('IS_ICYPHOENIX') && $censor)
{
$text = censor_text($text);
}
if (!class_exists('bbcode'))
{
include_once(IP_ROOT_PATH . 'includes/bbcode.' . PHP_EXT);
}
if (empty($bbcode))
{
$bbcode = new bbcode();
if (!$user->data['session_logged_in'])
{
$user->data['user_allowhtml'] = $config['allow_html'] ? true : false;
$user->data['user_allowbbcode'] = $config['allow_bbcode'] ? true : false;
$user->data['user_allowsmile'] = $config['allow_smilies'] ? true : false;
}
$bbcode->allow_html = ($user->data['user_allowhtml'] && $config['allow_html']) ? true : false;
$bbcode->allow_bbcode = ($user->data['user_allowbbcode'] && $config['allow_bbcode']) ? true : false;
$bbcode->allow_smilies = ($user->data['user_allowsmile'] && $config['allow_smilies']) ? true : false;
}
if ($only_smileys)
{
$text = $bbcode->parse_only_smilies($text);
}
else
{
$text = $bbcode->parse($text);
if ($acro_autolinks)
{
$text = $bbcode->acronym_pass($text);
$text = $bbcode->autolink_text($text, $forum_id);
}
}
return $text;
}
/*
* Generate a single row of smileys
* Moved here from functions_post to optimize viewtopic and remove the full include of functions_post
*/
function generate_smilies_row()
{
global $db, $cache, $config, $template;
$max_smilies = (!empty($config['smilie_single_row']) ? intval($config['smilie_single_row']) : 20);
$sql = "SELECT emoticon, code, smile_url FROM " . SMILIES_TABLE . " GROUP BY smile_url ORDER BY smilies_order LIMIT " . $max_smilies;
$result = $db->sql_query($sql, 0, 'smileys_');
$host = extract_current_hostname();
$orig = array();
$repl = array();
while ($row = $db->sql_fetchrow($result))
{
$template->assign_block_vars('smilies', array(
'CODE' => $row['code'],
'URL' => 'http://' . $host . $config['script_path'] . $config['smilies_path'] . '/' . $row['smile_url'],
'DESC' => htmlspecialchars($row['emoticon'])
)
);
}
$db->sql_freeresult($result);
}
/*
* Get attachment details
*/
function get_attachment_details($attach_id)
{
global $db;
$sql = "SELECT a.*, d.*, s.*, p.forum_id
FROM " . ATTACHMENTS_TABLE . " a, " . ATTACHMENTS_DESC_TABLE . " d, " . ATTACHMENTS_STATS_TABLE . " s, " . POSTS_TABLE . " p
WHERE a.attach_id = " . $attach_id . "
AND d.attach_id = a.attach_id
AND s.attach_id = a.attach_id
AND a.post_id > 0
AND p.post_id = a.post_id
LIMIT 1";
$db->sql_return_on_error(true);
$result = $db->sql_query($sql);
$db->sql_return_on_error(false);
if ($row = $db->sql_fetchrow($result))
{
$db->sql_freeresult($result);
return $row;
}
else
{
return false;
}
}
/*
* Get download details
*/
function get_download_details($file_id)
{
global $db, $user;
$sql = "SELECT f.*, c.*
FROM " . PA_FILES_TABLE . " f, " . PA_CATEGORY_TABLE . " c
WHERE file_id = " . $file_id . "
AND file_approved = '1'
AND c.cat_id = f.file_catid
LIMIT 1";
$db->sql_return_on_error(true);
$result = $db->sql_query($sql);
$db->sql_return_on_error(false);
if ($row = $db->sql_fetchrow($result))
{
$db->sql_freeresult($result);
$allowed = false;
if (($row['auth_view_file'] == AUTH_ALL) || ($user->data['user_level'] == ADMIN))
{
$allowed = true;
}
elseif (($row['auth_view_file'] == AUTH_REG) && $user->data['session_logged_in'])
{
$allowed = true;
}
return ($allowed ? $row : false);
}
else
{
return false;
}
}
/*
* This function turns HTML into text... strips tags, comments spanning multiple lines including CDATA, and anything else that gets in it's way.
*/
function html2txt($document)
{
$search = array(
'@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA
);
$text = preg_replace($search, '', $document);
return $text;
}
/*
* Convert newline to paragraph
*/
function nl2any($text, $tag = 'p', $feed = '')
{
// making tags
$start_tag = "<$tag" . ($feed ? ' ' . $feed : '') . '>';
$end_tag = "</$tag>";
// exploding string to lines
$lines = preg_split('`[\n\r]+`', trim($text));
// making new string
$string = '';
foreach($lines as $line)
$string .= "$start_tag$line$end_tag\n";
return $string;
}
/*
* Convert paragraphs to newline
*/
function any2nl($text, $tag = 'p')
{
//exploding
preg_match_all("`<" . $tag . "[^>]*>(.*)</" . $tag . ">`Ui", $text, $results);
// reimploding without tags
return implode("\n", array_filter($results[1]));
}
/*
* Convert BR to newline
*/
function br2nl($text, $remove_linebreaks = false)
{
if ($remove_linebreaks)
{
$text = preg_replace("/(\r\n|\n|\r)/", "", $text);
}
return preg_replace("=<br */?>=i", "\n", $text);
}
/*
* Convert newline to BR
*/
function nl2br_mg($text)
{
/*
$text = preg_replace("/\r\n/", "\n", $text);
$text = str_replace('<br />', "\n", $text);
*/
$text = preg_replace(array("/<br \/>\r\n/", "/<br>\r\n/", "/(\r\n|\n|\r)/"), array("\r\n", "\r\n", "<br />\r\n"), $text);
return $text;
}
?> |