PageRenderTime 27ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/Portal_XL50_Plain-3.0.8/phpbb3/portal/includes/functions.php

https://github.com/Lucky65/phpBB-Portal-XL-5.0-italian
PHP | 489 lines | 379 code | 56 blank | 54 comment | 44 complexity | 5bffb4262b2980ac1c06c810d40b8523 MD5 | raw file
  1. <?php
  2. /*
  3. *
  4. * @name functions.php
  5. * @package phpBB3 Portal XL 5.0
  6. * @version $Id: functions.php,v 1.4 2010/01/22 damysterious Exp $
  7. *
  8. * @copyright (c) 2007, 2010 Portal XL Group
  9. * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL)
  10. *
  11. */
  12. if (!defined('IN_PHPBB'))
  13. {
  14. exit;
  15. }
  16. /**
  17. * Only include once
  18. */
  19. if (function_exists('portal_init'))
  20. {
  21. return;
  22. }
  23. /**
  24. * Available functions
  25. *
  26. * phpbb_fetch_news()
  27. * character_limit()
  28. * smilies_pass()
  29. * smiley_sort()
  30. * phpbb_preg_quote()
  31. * smilie_text()
  32. * obtain_word_list()
  33. *
  34. */
  35. /**
  36. *
  37. */
  38. include($phpbb_root_path . 'includes/message_parser.'.$phpEx);
  39. /**
  40. * Fetch news processing
  41. */
  42. function phpbb_fetch_news($forum_from, $number_of_posts, $text_length, $time, $type, $start = 0)
  43. {
  44. /**
  45. * initalise some global variables
  46. */
  47. global $db, $config, $portal_config, $phpbb_root_path, $auth, $user, $bbcode_bitfield, $mode, $forum_id, $forum_status;
  48. $posts = array();
  49. $post_time = ($time == 0) ? '' : 'AND t.topic_time > ' . (time() - $time * 86400);
  50. $forum_from = ( strpos($forum_from, ',') !== FALSE ) ? explode(',', $forum_from) : (($forum_from != '') ? array($forum_from) : array());
  51. $str_where = '';
  52. $topic_icons = array(0);
  53. $have_icons = 0;
  54. $global_f = 0;
  55. $allow_access = array_unique(array_keys($auth->acl_getf('f_read', true)));
  56. if( sizeof($allow_access) ){
  57. if( sizeof($forum_from) )
  58. {
  59. foreach( $allow_access as $acc_id )
  60. {
  61. if( in_array($acc_id, $forum_from ) )
  62. {
  63. $str_where .= "t.forum_id = $acc_id OR ";
  64. if( !isset($gobal_f) )
  65. {
  66. $global_f = $acc_id;
  67. }
  68. }
  69. }
  70. }
  71. else
  72. {
  73. foreach( $allow_access as $acc_id )
  74. {
  75. $str_where .= "t.forum_id = $acc_id OR ";
  76. if( !isset($gobal_f) )
  77. {
  78. $global_f = $acc_id;
  79. }
  80. }
  81. }
  82. if( utf8_strlen($str_where) > 0 )
  83. {
  84. switch( $type )
  85. {
  86. case "announcements":
  87. $topic_type = '(( t.topic_type = ' . POST_ANNOUNCE . ') OR ( t.topic_type = ' . POST_GLOBAL . '))';
  88. $str_where = ( utf8_strlen($str_where) > 0 ) ? 'AND (t.forum_id = 0 OR ' . substr($str_where, 0, -4) . ')' : '';
  89. $user_link = 't.topic_poster = u.user_id';
  90. $post_link = 't.topic_first_post_id = p.post_id';
  91. $topic_order = 't.topic_time DESC';
  92. break;
  93. case "news":
  94. $topic_type = '(( t.topic_type = ' . POST_NORMAL . ') OR ( t.topic_type = ' . POST_STICKY . '))';
  95. $str_where = ( strlen($str_where) > 0 ) ? 'AND (' . trim(substr($str_where, 0, -4)) . ')' : '';
  96. if ( $portal_config['portal_news_show_last_post'] == true)
  97. {
  98. $user_link = 't.topic_last_poster_id = u.user_id';
  99. $post_link = 't.topic_last_post_id = p.post_id';
  100. $topic_order = 't.topic_last_post_id DESC';
  101. }
  102. else
  103. {
  104. $user_link = 't.topic_poster = u.user_id';
  105. $post_link = 't.topic_first_post_id = p.post_id';
  106. $topic_order = 't.topic_time DESC';
  107. }
  108. break;
  109. case "news_all":
  110. $topic_type = '( t.topic_type <> ' . POST_ANNOUNCE . ' ) AND ( t.topic_type <> ' . POST_GLOBAL . ')';
  111. $str_where = ( strlen($str_where) > 0 ) ? 'AND (' . trim(substr($str_where, 0, -4)) . ')' : '';
  112. if ( $portal_config['portal_news_show_last_post'] == true)
  113. {
  114. $user_link = 't.topic_last_poster_id = u.user_id';
  115. $post_link = 't.topic_last_post_id = p.post_id';
  116. $topic_order = 't.topic_last_post_id DESC';
  117. }
  118. else
  119. {
  120. $user_link = 't.topic_poster = u.user_id';
  121. $post_link = 't.topic_first_post_id = p.post_id';
  122. $topic_order = 't.topic_time DESC';
  123. }
  124. break;
  125. }
  126. $sql_array = array(
  127. 'SELECT' => 'f.enable_icons,
  128. f.forum_name,
  129. p.bbcode_bitfield,
  130. p.bbcode_uid,
  131. p.enable_bbcode,
  132. p.enable_magic_url,
  133. p.enable_smilies,
  134. p.post_approved,
  135. p.post_attachment,
  136. p.post_id,
  137. p.post_subject,
  138. p.post_text,
  139. p.post_time,
  140. p.post_username,
  141. p.poster_id,
  142. t.forum_id,
  143. t.icon_id,
  144. t.poll_start,
  145. t.poll_title,
  146. t.topic_approved,
  147. t.topic_attachment,
  148. t.topic_first_post_id,
  149. t.topic_id,
  150. t.topic_last_post_id,
  151. t.topic_last_post_time,
  152. t.topic_last_poster_colour,
  153. t.topic_last_poster_id,
  154. t.topic_last_poster_name,
  155. t.topic_moved_id,
  156. t.topic_poster,
  157. t.topic_replies,
  158. t.topic_replies_real,
  159. t.topic_status,
  160. t.topic_time,
  161. t.topic_title,
  162. t.topic_type,
  163. t.topic_views,
  164. u.user_colour,
  165. u.user_id,
  166. u.user_rank,
  167. u.user_type,
  168. u.username',
  169. 'FROM' => array(
  170. TOPICS_TABLE => 't',
  171. ),
  172. 'LEFT_JOIN' => array(
  173. array(
  174. 'FROM' => array(USERS_TABLE => 'u'),
  175. 'ON' => $user_link,
  176. ),
  177. array(
  178. 'FROM' => array(FORUMS_TABLE => 'f'),
  179. 'ON' => 't.forum_id=f.forum_id',
  180. ),
  181. array(
  182. 'FROM' => array(POSTS_TABLE => 'p'),
  183. 'ON' => $post_link,
  184. ),
  185. ),
  186. 'WHERE' => $topic_type . '
  187. ' . $post_time . '
  188. AND t.topic_status <> ' . ITEM_MOVED . '
  189. AND t.topic_approved = 1
  190. AND t.topic_moved_id = 0
  191. ' . $str_where,
  192. 'ORDER_BY' => $topic_order,
  193. );
  194. $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']);
  195. $sql_array['SELECT'] .= ', tp.topic_posted';
  196. $sql = $db->sql_build_query('SELECT', $sql_array);
  197. if($number_of_posts != 0)
  198. {
  199. $result = $db->sql_query_limit($sql, $number_of_posts, $start);
  200. } else {
  201. $result = $db->sql_query($sql);
  202. }
  203. $i = 0;
  204. while ( $row = $db->sql_fetchrow($result) )
  205. {
  206. // Pull attachment data
  207. $display_notice = false;
  208. $attachments = array();
  209. if ($row['post_attachment'] && $config['allow_attachments'])
  210. {
  211. if ($auth->acl_get('u_download', $row['post_attachment']))
  212. {
  213. $sql2 = 'SELECT *
  214. FROM ' . ATTACHMENTS_TABLE . '
  215. WHERE post_msg_id = '. $row['post_id'] .'
  216. AND in_message = 0
  217. ORDER BY filetime DESC';
  218. $result2 = $db->sql_query($sql2);
  219. while ($row2 = $db->sql_fetchrow($result2))
  220. {
  221. $attachments[] = $row2;
  222. }
  223. $db->sql_freeresult($result2);
  224. }
  225. else
  226. {
  227. $display_notice = true;
  228. }
  229. }
  230. if ($row['user_id'] != ANONYMOUS && $row['user_colour'])
  231. {
  232. $row['username'] = '<b style="color:#' . $row['user_colour'] . '">' . $row['username'] . '</b> ';
  233. }
  234. $posts[$i]['bbcode_uid'] = $row['bbcode_uid'];
  235. $len_check = $row['post_text'];
  236. if (($text_length != 0) && (strlen($len_check) > $text_length))
  237. {
  238. $message = substr($len_check, 0, $text_length);
  239. $message = str_replace(array("\n", "\r"), array('<br />', "\n"), $message);
  240. $message .= ' ...';
  241. $posts[$i]['striped'] = true;
  242. }
  243. else
  244. {
  245. $message = censor_text(str_replace("\n", '<br/> ', $row['post_text']));
  246. }
  247. if ($auth->acl_get('f_html', $row['forum_id']))
  248. {
  249. $message = preg_replace('#<!\-\-(.*?)\-\->#is', '', $message); // Remove Comments from post content
  250. }
  251. if (!empty($attachments))
  252. {
  253. parse_attachments($row['forum_id'], $message, $attachments, $update_count);
  254. }
  255. if ($portal_config['portal_acronyms_allow'] == true)
  256. {
  257. include_once($phpbb_root_path . 'portal/includes/functions_acronym.php');
  258. $message = acronym_pass($message);
  259. }
  260. // Parse bbcode here
  261. $row['bbcode_options'] = (($row['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + (($row['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + (($row['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);
  262. $message = generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']);
  263. $posts[$i] = array_merge($posts[$i], array(
  264. 'attachment' => ($row['topic_attachment']) ? true : false,
  265. 'attachments' => (!empty($attachments)) ? $attachments : array(),
  266. 'bbcode_bitfield' => $row['bbcode_bitfield'],
  267. 'bbcode_uid' => $row['bbcode_uid'],
  268. 'enable_bbcode' => $row['enable_bbcode'],
  269. 'enable_magic_url' => $row['enable_magic_url'],
  270. 'enable_smilies' => $row['enable_smilies'],
  271. 'forum_id' => $row['forum_id'],
  272. 'forum_name' => $row['forum_name'],
  273. 'icon_id' => $row['icon_id'],
  274. 'poll' => ($row['poll_title']) ? true : false,
  275. 'poll_start' => (int) $row['poll_start'],
  276. 'poll_title' => ($row['poll_title'] != '') ? true : false,
  277. 'post_approved' => $row['post_approved'],
  278. 'post_attachment' => $row['post_attachment'],
  279. 'post_id' => $row['post_id'],
  280. 'post_subject' => $row['post_subject'],
  281. 'post_text' => $message,
  282. 'post_time' => $user->format_date($row['post_time']),
  283. 'topic_approved' => $row['topic_approved'],
  284. 'topic_attachment' => $row['topic_attachment'],
  285. 'topic_first_post_id' => $row['topic_first_post_id'],
  286. 'topic_id' => $row['topic_id'],
  287. 'topic_last_post_id' => $row['topic_last_post_id'],
  288. 'topic_last_post_time' => $row['topic_last_post_time'],
  289. 'topic_posted' => (isset($row['topic_posted']) && $row['topic_posted']) ? true : false,
  290. 'topic_poster' => $row['topic_poster'],
  291. 'topic_replies' => $row['topic_replies'],
  292. 'topic_replies_real' => $row['topic_replies_real'],
  293. 'topic_status' => $row['topic_status'],
  294. 'topic_time' => $user->format_date($row['post_time']),
  295. 'topic_title' => $row['topic_title'],
  296. 'topic_type' => $row['topic_type'],
  297. 'topic_views' => $row['topic_views'],
  298. 'user_colour' => $row['user_colour'],
  299. 'user_id' => $row['user_id'],
  300. 'user_rank' => $row['user_rank'],
  301. 'user_type' => $row['user_type'],
  302. 'username' => $row['username'],
  303. 'username_full' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $row['username']),
  304. 'username_full_last' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour'], $row['topic_last_poster_name']),
  305. ));
  306. $posts[$i]['global_id'] = $global_f;
  307. $i++;
  308. }
  309. $db->sql_freeresult($result);
  310. }
  311. }
  312. return $posts;
  313. }
  314. /**
  315. * Censor title, return short title
  316. *
  317. * @param $title string title to censor
  318. * @param $limit int short title character limit
  319. *
  320. */
  321. function character_limit(&$title, $limit = 0)
  322. {
  323. $title = censor_text($title);
  324. if ($limit > 0)
  325. {
  326. return (utf8_strlen(utf8_decode($title)) > $limit + 3) ? truncate_string($title, $limit) . '...' : $title;
  327. }
  328. else
  329. {
  330. // return the result
  331. return $title;
  332. }
  333. }
  334. /**
  335. * smilies_pass processing
  336. */
  337. function smilies_pass($message)
  338. {
  339. static $orig, $repl;
  340. if (!isset($orig))
  341. {
  342. global $db, $images, $portal_config;
  343. $orig = $repl = array();
  344. if(!$orig)
  345. {
  346. $sql = 'SELECT * FROM ' . SMILIES_TABLE;
  347. if( !$result = $db->sql_query($sql) )
  348. {
  349. message_die(GENERAL_ERROR, "Couldn't obtain smilies data", "", __LINE__, __FILE__, $sql);
  350. }
  351. $smilies = $db->sql_fetchrowset($result);
  352. if (count($smilies))
  353. {
  354. usort($smilies, "smiley_sort");
  355. }
  356. for ($i = 0; $i < count($smilies); $i++)
  357. {
  358. $orig[] = "/(?<=.\W|\W.|^\W)" . phpbb_preg_quote($smilies[$i]['code'], "/") . "(?=.\W|\W.|\W$)/";
  359. $repl[] = '<img src="images/smilies/'. $images['smilies'] . '/' . $smilies[$i]['smiley_url'] . '" alt="' . $smilies[$i]['emotion'] . '" border="0" />';
  360. }
  361. }
  362. }
  363. if (count($orig))
  364. {
  365. $message = preg_replace($orig, $repl, ' ' . $message . ' ');
  366. $message = substr($message, 1, -1);
  367. }
  368. return $message;
  369. }
  370. /**
  371. * smiley_sort processing
  372. */
  373. function smiley_sort($a, $b)
  374. {
  375. if ( utf8_strlen($a['code']) == utf8_strlen($b['code']) )
  376. {
  377. return 0;
  378. }
  379. return ( utf8_strlen($a['code']) > utf8_strlen($b['code']) ) ? -1 : 1;
  380. }
  381. /**
  382. * phpbb_preg_quote processing
  383. */
  384. function phpbb_preg_quote($str, $delimiter)
  385. {
  386. $text = preg_quote($str);
  387. $text = str_replace($delimiter, '\\' . $delimiter, $text);
  388. return $text;
  389. }
  390. /**
  391. * smilie_text processing
  392. */
  393. function smilie_text($text, $force_option = false)
  394. {
  395. global $config, $user, $phpbb_root_path;
  396. $userstylepath = $phpbb_root_path . 'images/smilies';
  397. $phpbb_root_path = '';
  398. return ($force_option || !$config['allow_smilies'] || !$user->optionget('viewsmilies')) ? preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#', '\1', $text) : str_replace('<img src="{SMILIES_PATH}', '<img src="' . $userstylepath, $text);
  399. }
  400. /**
  401. * obtain_word_list processing
  402. */
  403. function obtain_word_list(&$censors)
  404. {
  405. global $db, $cache, $user;
  406. if (!$user->optionget('viewcensors') && $config['allow_nocensors'])
  407. {
  408. return;
  409. }
  410. $sql = 'SELECT word, replacement
  411. FROM ' . WORDS_TABLE;
  412. $result = $db->sql_query($sql);
  413. $censors = array();
  414. while ($row = $db->sql_fetchrow($result))
  415. {
  416. $censors['match'][] = '#\b(' . str_replace('\*', '\w*?', preg_quote($row['word'], '#')) . ')\b#i';
  417. $censors['replace'][] = $row['replacement'];
  418. }
  419. $db->sql_freeresult($result);
  420. $cache->put('word_censors', $censors);
  421. // }
  422. return true;
  423. }
  424. ?>