PageRenderTime 303ms CodeModel.GetById 150ms RepoModel.GetById 1ms app.codeStats 0ms

/interfase/comments.php

https://github.com/nopticon/hyd
PHP | 914 lines | 619 code | 150 blank | 145 comment | 121 complexity | a9abacf05662fa99ddf6f289ab672cb6 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /*
  3. <Orion, a web development framework for RK.>
  4. Copyright (C) <2011> <Orion>
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. if (!defined('IN_APP')) exit;
  17. class comments {
  18. public $ref;
  19. public $mesage;
  20. public $param;
  21. public $data;
  22. public $auth;
  23. public $users;
  24. public $options = array();
  25. public function __construct() {
  26. $this->ref = '';
  27. $this->auth = $this->data = $this->param = $this->users = w();
  28. return;
  29. }
  30. public function reset() {
  31. return self::__construct();
  32. }
  33. public function reset2() {
  34. $this->message = '';
  35. $this->options = w();
  36. return true;
  37. }
  38. public function emoticons() {
  39. global $config, $cache;
  40. if (!$emoticons = $cache->get('emoticons')) {
  41. $sql = 'SELECT *
  42. FROM _smilies
  43. ORDER BY LENGTH(code) DESC';
  44. if ($emoticons = sql_rowset($sql)) {
  45. $cache->save('emoticons', $emoticons);
  46. }
  47. }
  48. foreach ($emoticons as $smile_url => $row) {
  49. _style('smilies_row', array(
  50. 'CODE' => $row->code,
  51. 'IMAGE' => $config->assets_url . '/emoticon/' . $row->smile_url,
  52. 'DESC' => $row->emoticon)
  53. );
  54. }
  55. }
  56. //
  57. // Store user comments for all comment areas.
  58. //
  59. public function receive() {
  60. global $config, $user;
  61. if (request_method() != 'post') {
  62. redirect(s_link());
  63. }
  64. //
  65. // Init member
  66. //
  67. $user->init();
  68. if (!$user->is('member')) {
  69. do_login();
  70. }
  71. $this->ref = request_var('ref', $user->d('session_page'), true);
  72. $part = parse_url($this->ref);
  73. if (!isset($part['path'])) $part['path'] = '';
  74. if (substr($part['path'], -1, 1) != '/') $part['path'] .= '/';
  75. if ($part['host'] != $config->server_name) {
  76. $part['path'] = '/a/' . array_key(explode('.', $part['host']), 0) . $part['path'];
  77. }
  78. //
  79. // Recognize request type
  80. //
  81. $this->param = array_splice(explode('/', $part['path']), 1, -1);
  82. $id = (isset($this->param[3])) ? (int) $this->param[3] : 0;
  83. switch ($this->param[0]) {
  84. case 'a':
  85. if ($this->param[2] == 'downloads') {
  86. $sql = 'SELECT *
  87. FROM _dl d, _artists a
  88. WHERE d.id = ?
  89. AND a.subdomain = ?
  90. AND d.ub = a.ub';
  91. $sql = sql_filter($sql, $id, $this->param[1]);
  92. $this->data = array(
  93. 'DATA_TABLE' => '_dl',
  94. 'POST_TABLE' => 'dl_posts',
  95. 'HISTORY' => UH_M
  96. );
  97. } else {
  98. $sql = 'SELECT *
  99. FROM _artists
  100. WHERE subdomain = ?';
  101. $sql = sql_filter($sql, $this->param[1]);
  102. $this->data = array(
  103. 'DATA_TABLE' => '_artists',
  104. 'POST_TABLE' => 'artists_posts',
  105. 'HISTORY' => UH_C
  106. );
  107. }
  108. break;
  109. case 'events':
  110. $event_field = (is_numb($this->param[1])) ? 'id' : 'event_alias';
  111. $sql = 'SELECT *
  112. FROM _events
  113. WHERE ?? = ?';
  114. $sql = sql_filter($sql, $event_field, $this->param[1]);
  115. $this->data = array(
  116. 'DATA_TABLE' => '_events',
  117. 'POST_TABLE' => 'events_posts',
  118. 'HISTORY' => UH_EP
  119. );
  120. break;
  121. case 'news':
  122. $news_field = (is_numb($this->param[1])) ? 'id' : 'alias';
  123. $sql = 'SELECT *
  124. FROM _news
  125. WHERE news_?? = ?';
  126. $sql = sql_filter($sql, $news_field, $this->param[1]);
  127. $this->data = array(
  128. 'DATA_TABLE' => '_news',
  129. 'POST_TABLE' => 'news_posts',
  130. 'HISTORY' => UH_NP
  131. );
  132. break;
  133. case 'art':
  134. $sql = 'SELECT *
  135. FROM _art
  136. WHERE art_id = ?';
  137. $sql = sql_filter($sql, $this->param[1]);
  138. $this->data = array(
  139. 'DATA_TABLE' => '_art',
  140. 'POST_TABLE' => 'art_posts',
  141. 'HISTORY' => UH_W
  142. );
  143. break;
  144. case 'm':
  145. $sql = 'SELECT *
  146. FROM _members
  147. WHERE username_base = ?';
  148. $sql = sql_filter($sql, $this->param[1]);
  149. $this->data = array(
  150. 'DATA_TABLE' => '_members',
  151. 'POST_TABLE' => 'members_posts',
  152. 'HISTORY' => UH_UPM
  153. );
  154. break;
  155. default:
  156. fatal_error();
  157. break;
  158. }
  159. if (!$post_data = sql_fieldrow($sql)) {
  160. fatal_error();
  161. }
  162. $post_reply = 0;
  163. $error = w();
  164. $update_sql = '';
  165. $current_time = time();
  166. $this->auth['user'] = $user->is('member');
  167. $this->auth['adm'] = $user->is('founder');
  168. /*
  169. //
  170. // Flood control
  171. //
  172. if (!$this->auth['adm'] && !$this->auth['mod']) {
  173. $where_sql = (!$this->auth['user']) ? "post_ip = '$user_ip'" : "poster_id = " . $userdata['user_id'];
  174. $sql = "SELECT MAX(post_time) AS last_datetime
  175. FROM " . $this->data['POST_TABLE'] . "
  176. WHERE $where_sql";
  177. if ($row = sql_fieldrow($sql)) {
  178. if ((intval($row['last_datetime']) > 0) && ($current_time - intval($row['last_datetime'])) < 10) {
  179. $error[] = 'CHAT_FLOOD_CONTROL';
  180. }
  181. }
  182. }
  183. */
  184. //
  185. // Check if message is empty
  186. //
  187. if (!count($error)) {
  188. $message = request_var('message', '', true);
  189. if (empty($message)) {
  190. $error[] = 'EMPTY_MESSAGE';
  191. }
  192. }
  193. //
  194. // If an error is detected.
  195. //
  196. if (count($error)) {
  197. $user->setup();
  198. $return_message = parse_error($error) . '<br /><br /><br /><a href="' . $ref . '">' . lang('click_return_lastpage') . '</a>';
  199. trigger_error($return_message);
  200. }
  201. //
  202. // Insert processed data
  203. //
  204. $update_sql = '';
  205. $post_reply = (isset($this->param[4]) && $this->param[4] == 'reply') ? $id : 0;
  206. $message = $this->prepare($message);
  207. $insert_data = array(
  208. 'post_reply' => $post_reply,
  209. 'post_active' => 1,
  210. 'poster_id' => $user->d('user_id'),
  211. 'post_ip' => $user->ip,
  212. 'post_time' => $current_time,
  213. 'post_text' => $message
  214. );
  215. switch ($this->param[0]) {
  216. case 'a':
  217. switch ($this->param[2]) {
  218. case 9:
  219. $insert_data['download_id'] = (int) $post_data->id;
  220. $update_sql = sql_filter('posts = posts + 1 WHERE id = ?', $post_data->id);
  221. $this->data['HISTORY_EXTRA'] = $post_data->ub;
  222. break;
  223. case 12:
  224. default:
  225. $insert_data['post_ub'] = (int) $post_data->ub;
  226. $update_sql = sql_filter('posts = posts + 1 WHERE ub = ?', $post_data->ub);
  227. $this->data['HISTORY_EXTRA'] = $post_data->ub;
  228. $this->data['REPLY_TO_SQL'] = sql_filter('SELECT p.poster_id, m.user_id
  229. FROM _artists_posts p, _members m
  230. WHERE p.post_id = ?
  231. AND p.poster_id = m.user_id
  232. AND m.user_type NOT IN (??)', $post_reply, USER_INACTIVE);
  233. break;
  234. }
  235. break;
  236. case 'events':
  237. $insert_data['event_id'] = (int) $post_data->id;
  238. $update_sql = sql_filter('posts = posts + 1 WHERE id = ?', $post_data->id);
  239. break;
  240. case 'news':
  241. $insert_data['news_id'] = (int) $post_data->news_id;
  242. $update_sql = sql_filter('post_replies = post_replies + 1 WHERE news_id = ?', $post_data->news_id);
  243. break;
  244. case 'art':
  245. $insert_data['art_id'] = (int) $post_data->art_id;
  246. $update_sql = sql_filter('posts = posts + 1 WHERE art_id = ?', $post_data->art_id);
  247. break;
  248. case 'm':
  249. $insert_data['userpage_id'] = (int) $post_data->user_id;
  250. $update_sql = sql_filter('userpage_posts = userpage_posts + 1 WHERE user_id = ?', $post_data->user_id);
  251. $this->data['HISTORY_EXTRA'] = $post_data->user_id;
  252. break;
  253. }
  254. $post_id = sql_insert($this->data['POST_TABLE'], $insert_data);
  255. if ($update_sql != '') {
  256. $sql = 'UPDATE ' . $this->data['DATA_TABLE'] . ' SET ' . $update_sql;
  257. sql_query($sql);
  258. }
  259. $reply_to = 0;
  260. $history_extra = isset($this->data['HISTORY_EXTRA']) ? $this->data['HISTORY_EXTRA'] : 0;
  261. if ($post_reply && isset($this->data['REPLY_TO_SQL'])) {
  262. if ($reply_row = sql_fieldrow($this->data['REPLY_TO_SQL'])) {
  263. $reply_to = ($reply_row->user_id != GUEST) ? $reply_row->user_id : 0;
  264. }
  265. // TODO: Today save
  266. // $user->delete_unread($this->data['HISTORY'], $post_reply);
  267. }
  268. // TODO: Set config to send notifications.
  269. $notify = false;
  270. if ($this->param[0] == 'm' && $user->d('user_id') == $post_data->user_id) {
  271. $notify = false;
  272. }
  273. if ($notify) {
  274. if ($this->param[0] == 'm') {
  275. $emailer = new emailer();
  276. $emailer->from('info');
  277. $emailer->use_template('user_message');
  278. $emailer->email_address($post_data->user_email);
  279. $emailer->set_subject($config->sitename . ': Mensaje nuevo de ' . $user->d('username'));
  280. $emailer->assign_vars(array(
  281. 'USERNAME_TO' => $post_data->username,
  282. 'USERNAME_FROM' => $user->d('username'),
  283. 'USER_MESSAGE' => entity_decode($message),
  284. 'U_PROFILE' => s_link('m', $user->d('username_base')))
  285. );
  286. $emailer->send();
  287. $emailer->reset();
  288. // TODO: Today save
  289. // $user->save_unread($this->data['HISTORY'], $post_id, $history_extra, $post_data['user_id']);
  290. } else {
  291. // TODO: Today save
  292. // $user->save_unread($this->data['HISTORY'], $post_id, $history_extra, $reply_to, false);
  293. // Points
  294. //$user->points_add(1);
  295. }
  296. }
  297. // Userpage messages
  298. if ($this->param[0] == 'm') {
  299. $sql = 'SELECT post_id
  300. FROM _members_posts p, _members_unread u
  301. WHERE u.item = p.post_id
  302. AND p.userpage_id = ?
  303. AND p.poster_id = ?';
  304. if ($rows = sql_rowset(sql_filter($sql, $user->d('user_id'), $post_data->user_id), false, 'post_id')) {
  305. $sql = 'DELETE FROM _members_unread
  306. WHERE user_id = ?
  307. AND element = ?
  308. AND item IN (??)';
  309. sql_query(sql_filter($sql, $user->d('user_id'), UH_UPM, implode(',', $rows)));
  310. }
  311. }
  312. redirect($this->ref);
  313. }
  314. //
  315. // View comments
  316. //
  317. public function view($start, $start_field, $total_items, $items_pp, $tpl_prefix = '', $pag_prefix = '', $pag_lang_prefix = '', $simple_pagination = false) {
  318. global $config, $user;
  319. if ($tpl_prefix == '') {
  320. $tpl_prefix = 'posts';
  321. }
  322. $ref = $this->ref;
  323. $this->ref = preg_replace('#^/?(.*?)/?$#', '\1', $this->ref);
  324. $this->param = explode('/', $this->ref);
  325. $this->ref = $ref;
  326. if (!isset($start)) {
  327. $start = request_var($start_field, 0);
  328. }
  329. if (!$result = sql_rowset($this->data['SQL'])) {
  330. return false;
  331. }
  332. if (!isset($this->data['ARTISTS_NEWS'])) {
  333. $this->data['ARTISTS_NEWS'] = false;
  334. }
  335. if (!isset($this->data['CONTROL'])) {
  336. $this->data['CONTROL'] = w();
  337. }
  338. $controls_data = $user_profile = w();
  339. _style($tpl_prefix);
  340. foreach ($result as $row) {
  341. $uid = $row->user_id;
  342. if (!isset($user_profile[$uid]) || ($uid == GUEST)) {
  343. $user_profile[$uid] = $this->user_profile($row);
  344. }
  345. $topic_title = isset($row->topic_title) ? $row->topic_title : (isset($row->post_subject) ? $row->post_subject : '');
  346. $topic_title = (!$this->data['ARTISTS_NEWS']) ? $topic_title : preg_replace('#(.*?): (.*?)#', '\\2', $topic_title);
  347. $data = object_merge($user_profile[$uid], array(
  348. 'post_id' => $row->post_id,
  349. 'datetime' => $user->format_date($row->post_time),
  350. 'subject' => $topic_title,
  351. 'message' => $this->parse_message($row->post_text),
  352. 'replies' => ($this->data['ARTISTS_NEWS']) ? $row->topic_replies : 0,
  353. 's_delete' => false)
  354. );
  355. if (isset($this->data['USER_ID_FIELD']) && ($user->is('founder') || ($user->d('user_id') === $row->{$this->data['USER_ID_FIELD']}))) {
  356. $data->s_delete = sprintf($this->data['S_DELETE_URL'], $row->post_id);
  357. }
  358. _style($tpl_prefix . '.item', $data);
  359. _style($tpl_prefix . '.item.' . (($uid != GUEST) ? 'username' : 'guestuser'));
  360. $ic = 0;
  361. foreach ($this->data['CONTROL'] as $block => $block_data) {
  362. if (!$ic) {
  363. $ic++;
  364. _style($tpl_prefix . '.item.controls');
  365. }
  366. foreach ($block_data as $item => $item_data) {
  367. $controls_data[$item_data['ID']][$item] = sprintf($item_data['URL'], $row->{$item_data['ID']});
  368. }
  369. _style($tpl_prefix . '.item.controls.' . $block, $controls_data[$item_data['ID']]);
  370. }
  371. }
  372. $f_pagination = ($simple_pagination) ? 'build_pagination' : 'build_num_pagination';
  373. $f_pagination($ref . $start_field . '%d/', $total_items, $items_pp, $start, $pag_prefix, $pag_lang_prefix);
  374. return true;
  375. }
  376. //
  377. // Get formatted member profile fields
  378. //
  379. public function user_profile(&$row, $unset_fields = false) {
  380. global $user, $config;
  381. static $all_ranks;
  382. if (!isset($this->users[$row->user_id]) || $row->user_id === GUEST) {
  383. $data = new stdClass;
  384. foreach ($row as $key => $value) {
  385. if (strpos($key, 'user') === false && $key != 'post_id') continue;
  386. switch ($key) {
  387. case 'username':
  388. $data->username = ($row->user_id != GUEST) ? $value : '*' . (($row->post_username != '') ? $row->post_username : lang('guest'));
  389. break;
  390. case 'username_base':
  391. $data->profile = ($row->user_id != GUEST) ? s_link('m', $value) : '';
  392. break;
  393. case 'user_sig':
  394. $data->$key = ($value != '') ? '<div' . ((isset($row->post_id)) ? ' id="_sig_' . $row->post_id . '" ' : '') . 'class="lsig">' . $this->parse_message($value) . '</div>' : '';
  395. break;
  396. case 'user_avatar':
  397. if ($row->user_id != GUEST) {
  398. if ($value != '') {
  399. $value = $config->assets_url . 'avatars/' . $value;
  400. } else {
  401. $value = $config->assets_url . 'style/avatar.gif';
  402. }
  403. } else {
  404. $value = $config->assets_url . 'style/avatar.gif';
  405. }
  406. $data->$key = $value;
  407. break;
  408. case 'user_rank':
  409. if (!isset($all_ranks)) {
  410. $all_ranks = $user->init_ranks();
  411. }
  412. if ($row->user_id == GUEST) {
  413. $value = lang('guest');
  414. break;
  415. }
  416. if ($value) {
  417. foreach ($all_ranks as $rank) {
  418. if (($value == $rank->rank_id) && $rank->rank_special) {
  419. $rank_e = explode('|', $rank->rank_title);
  420. $value = (isset($rank_e[$row->user_gender]) && ($rank_e[$row->user_gender] != '')) ? $rank_e[$row->user_gender] : $rank_e[0];
  421. break;
  422. }
  423. }
  424. } else {
  425. $value = '';
  426. if (isset($row->user_gender) && isset($row->user_posts)) {
  427. foreach ($all_ranks as $rank) {
  428. if (($row->user_posts >= $rank->rank_min) && !$rank->rank_special) {
  429. $rank_e = explode('|', $rank->rank_title);
  430. $value = (isset($rank_e[$row->user_gender]) && ($rank_e[$row->user_gender] != '')) ? $rank_e[$row->user_gender] : $rank_e[0];
  431. break;
  432. }
  433. }
  434. }
  435. }
  436. $data->$key = $value;
  437. break;
  438. default:
  439. if ($value != '') $data->$key = $value;
  440. break;
  441. }
  442. }
  443. if ($unset_fields !== false) {
  444. foreach ($unset_fields as $field) {
  445. unset($data->$field);
  446. }
  447. }
  448. $this->users[$row->user_id] = $data;
  449. }
  450. return $this->users[$row->user_id];
  451. }
  452. //
  453. // Comments system functions
  454. //
  455. //
  456. // This function will prepare a posted message for
  457. // entry into the database.
  458. //
  459. public function prepare($message) {
  460. global $config, $user;
  461. $match = array('#\r\n?#', '#sid=[a-z0-9]*?&amp;?#', "#([\n][\s]+){3,}#", "#(\.){3,}#", '#(script|about|applet|activex|chrome):#i');
  462. $replace = array(nr(), '', nr(false, 2), '...', "\\1&#058;");
  463. $message = preg_replace($match, $replace, trim($message));
  464. // Repeated chars on message.
  465. // $message = preg_replace('/(.)\1{10,}/', "$1$1", $message);
  466. if ($user->is('founder') && preg_match('#\[chown\:([0-9a-z\_\-]+)\]#is', $message, $a_chown)) {
  467. $sql = 'SELECT *
  468. FROM _members
  469. WHERE username_base = ?';
  470. if ($row = sql_fieldrow(sql_filter($sql, $a_chown[1]))) {
  471. $sql = 'UPDATE _members SET user_lastvisit = ?
  472. WHERE user_id = ?';
  473. sql_query(sql_filter($sql, time(), $row->user_id));
  474. $user->d(false, $row);
  475. }
  476. $message = str_replace('[chown:' . $a_chown[1] . ']', '', $message);
  477. }
  478. /*$is_mod = $user->is('mod');
  479. $allowed_tags = 'br strong ul ol li em blockquote' . (($is_mod) ? ' a h1 h2 h3 div span img' : '');
  480. $ptags = str_replace('*', '.*?', implode('|', w($allowed_tags)));
  481. $message = preg_replace('#&lt;(\/?)(' . $ptags . ')&gt;#is', '<$1$2>', $message);
  482. if ($is_mod) {
  483. if (preg_match_all('#&lt;(' . $ptags . ') (.*?)&gt;#is', $message, $in_quotes)) {
  484. $repl = array('&lt;' => '<', '&gt;' => '>', '&quot;' => '"');
  485. foreach ($in_quotes[0] as $item) {
  486. $message = preg_replace('#' . preg_quote($item, '#') . '#is', str_replace(array_keys($repl), array_values($repl), $item), $message);
  487. }
  488. }
  489. }*/
  490. return $message;
  491. }
  492. public function remove_quotes($message) {
  493. if (strstr($message, '<blockquote>')) {
  494. $message = trim(preg_replace('#^<br />#is', '', preg_replace("#<blockquote>.*?blockquote>(.*?)#is", '\\1', $message)));
  495. }
  496. return $message;
  497. }
  498. //
  499. // Message parser methods
  500. //
  501. public function parse_message($message) {
  502. $this->message = ' ' . $message . ' ';
  503. unset($message);
  504. $parse = 'flash youtube images url bbcode html smilies artists downloads profiles avatars';
  505. foreach (w($parse) as $method) {
  506. $this->{'parse_' . $method}();
  507. }
  508. return str_replace(nr(), '<br />', substr($this->message, 1, -1));
  509. }
  510. private function parse_flash() {
  511. $p = '#(^|[\n ]|\()\[flash\:([\w]+?://.*?([^ \t\n\r<"\'\)]*)?)\:(\d+)\:(\d+)\]#ie';
  512. if (preg_match_all($p, $this->message, $match)) {
  513. // $this->message = preg_replace($p, '\'$1<div id="flash_"></div> <script type="text/javascript"> swfobject.embedSWF("$2", "flash_", "$4", "$5", "8.0.0", "expressInstall.swf"); </script>\'', $this->message);
  514. $this->message = preg_replace($p, '\'$1<div id="flash_"></div>\'', $this->message);
  515. }
  516. return;
  517. }
  518. private function parse_youtube() {
  519. // $format = '%s<div id="yt_%s">Youtube video: http://www.youtube.com/watch?v=%s</div> <script type="text/javascript"> swfobject.embedSWF("http://www.youtube.com/v/%s", "yt_$2", "425", "350", "8.0.0", "expressInstall.swf"); </script>';
  520. $iframe = '';
  521. $format = '%s<div id="yt_%s"><iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/%s" allowfullscreen frameborder="0"></iframe></div>';
  522. if (preg_match_all('/https?:\/\/(?:www\.)?youtu(?:\.be|be\.com)\/watch(?:\?(.*?)&|\?)v=([a-zA-Z0-9_\-]+)(\S*)/i', $this->message, $match)) {
  523. foreach ($match[0] as $i => $row) {
  524. $this->message = str_replace($row, sprintf($format, '', $match[2][$i], $match[2][$i], $match[2][$i], $match[2][$i]), $this->message);
  525. }
  526. }
  527. if (preg_match_all('#(^|[\n ]|\()\[yt\:([0-9a-zA_Z\-\=\_\&]+)\]#i', $this->message, $match)) {
  528. // $this->message = preg_replace('#(^|[\n ]|\()\[yt\:([0-9a-zA_Z\-\=\_\&]+)\]#i', '$1<div id="yt_$2">Youtube video: http://www.youtube.com/watch?v=$2</div> <script type="text/javascript"> swfobject.embedSWF("http://www.youtube.com/v/$2", "yt_$2", "425", "350", "8.0.0", "expressInstall.swf"); </script>', $this->message);
  529. $this->message = preg_replace('#(^|[\n ]|\()\[yt\:([0-9a-zA_Z\-\=\_\&]+)\]#i', '$1<div id="yt_$2"><iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/$2" allowfullscreen frameborder="0"></iframe></div>', $this->message);
  530. }
  531. return;
  532. }
  533. private function parse_images() {
  534. if (preg_match_all('#(^|[\n ]|\()(http|https|ftp)://([a-z0-9\-\.,\?!%\*_:;~\\&$@/=\+]+)(gif|jpg|jpeg|png)#ie', $this->message, $match)) {
  535. $orig = $repl = w();
  536. foreach ($match[0] as $item) {
  537. $item = trim($item);
  538. $orig[] = '#(^|[\n ]|\()(' . preg_quote($item) . ')#i';
  539. $repl[] = '\\1<img src="' . $item . '" alt="" />';
  540. }
  541. if (count($orig)) {
  542. $this->message = preg_replace($orig, $repl, $this->message);
  543. }
  544. }
  545. return;
  546. }
  547. private function parse_url() {
  548. global $config;
  549. if (!isset($this->options['url'])) {
  550. global $user;
  551. $this->options['url'] = array(
  552. 'orig' => array(
  553. '#(script|about|applet|activex|chrome):#is',
  554. '#(^|[\n ]|\()(' . preg_quote('http://' . $config->server_name, '#') . ')/(.*?([^ \t\n\r<"\'\)]*)?)#is',
  555. '#(^|[\n ]|\()([\w]+?://.*?([^ \t\n\r<"\'\)]*)?)#ie',
  556. '#(^|[\n ]|\()(www\.[\w\-]+\.[\w\-.\~]+(?:/[^ \t\n\r<"\'\)]*)?)#ie',
  557. '#(^|[\n ]|\()([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)#ie'
  558. ),
  559. 'repl' => array(
  560. '\\1&#058;',
  561. '$1<a href="$2/$3">$2/$3</a>',
  562. "'\$1<a href=\"\$2\" target=\"_blank\">$2</a>'",
  563. "'\$1<a href=\"http://\$2\" target=\"_blank\">$2</a>'",
  564. "'\$1<a href=\"mailto:\$2\">$2</a>'"
  565. )
  566. );
  567. if (!$user->is('member')) {
  568. $this->options['url']['orig'][4] = '#(^|[\n ]|\()(([a-z0-9&\-_.]+?@)([\w\-]+\.([\w\-\.]+\.)?[\w]+))#se';
  569. $this->options['url']['repl'][4] = "'\$1<span class=\"red\">$3'.substr('$4', 0, 4).'...</span>'";
  570. }
  571. }
  572. $this->message = preg_replace($this->options['url']['orig'], $this->options['url']['repl'], $this->message);
  573. return;
  574. }
  575. private function parse_bbcode() {
  576. $orig = array('[sb]', '[/sb]');
  577. $repl = array('<blockquote>', '</blockquote>');
  578. $this->message = str_replace($orig, $repl, $this->message);
  579. }
  580. private function parse_html() {
  581. // $is_mod = $user->is('mod');
  582. $allowed_tags = 'a span strong blockquote';
  583. // . (($is_mod) ? ' a h1 h2 h3 div span img' : '');
  584. $ptags = str_replace('*', '.*?', implode('|', w($allowed_tags)));
  585. $this->message = preg_replace('#&lt;(\/?)(' . $ptags . ')&gt;#is', '<$1$2>', $this->message);
  586. $this->message = str_replace('&lt;br /&gt;', '<br />', $this->message);
  587. /*if ($is_mod) {
  588. if (preg_match_all('#&lt;(' . $ptags . ') (.*?)&gt;#is', $message, $in_quotes)) {
  589. $repl = array('&lt;' => '<', '&gt;' => '>', '&quot;' => '"');
  590. foreach ($in_quotes[0] as $item) {
  591. $message = preg_replace('#' . preg_quote($item, '#') . '#is', str_replace(array_keys($repl), array_values($repl), $item), $message);
  592. }
  593. }
  594. }*/
  595. }
  596. private function parse_smilies() {
  597. global $config;
  598. if (!isset($this->options['smilies'])) {
  599. global $cache;
  600. if (!$smilies = $cache->get('smilies')) {
  601. $sql = 'SELECT *
  602. FROM _smilies
  603. ORDER BY LENGTH(code) DESC';
  604. if ($smilies = sql_rowset($sql)) {
  605. $cache->save('smilies', $smilies);
  606. }
  607. }
  608. foreach ($smilies as $row) {
  609. $this->options['smilies']['orig'][] = '#(^|[\n ]|\.|\()' . preg_quote($row->code, '#') . '#';
  610. $this->options['smilies']['repl'][] = ' <img src="' . $config->assets_url . '/emoticon/' . $row->smile_url . '" alt="' . $row->emoticon . '" />';
  611. }
  612. }
  613. if (count($this->options['smilies'])) {
  614. $this->message = preg_replace($this->options['smilies']['orig'], $this->options['smilies']['repl'], $this->message);
  615. }
  616. return;
  617. }
  618. private function parse_artists() {
  619. if (!isset($this->options['a'])) {
  620. global $cache;
  621. if (!$this->options['a']['match'] = $cache->get('artist_list')) {
  622. $sql = 'SELECT name
  623. FROM _artists
  624. ORDER BY name';
  625. $result = sql_rowset($sql);
  626. foreach ($result as $row) {
  627. $this->options['a']['match'][] = $row->name;
  628. }
  629. $cache->save('artist_list', $this->options['a']['match']);
  630. }
  631. }
  632. if (preg_match_all('#\b(' . implode('|', $this->options['a']['match']) . ')\b#i', $this->message, $match)) {
  633. foreach ($match[1] as $n) {
  634. $m = strtolower($n);
  635. $k = str_replace(array(' ', '_'), '', $m);
  636. if (!isset($this->options['a']['data'][$k])) {
  637. $this->options['a']['data'][$k] = ucwords($m);
  638. }
  639. }
  640. $orig = $repl = w();
  641. foreach ($this->options['a']['data'] as $sub => $real) {
  642. $orig[] = '#(^|\s)(?<=.\W|\W.|^\W)\b(' . preg_quote($real, "#") . ')\b(?=.\W|\W.|\W$)#is';
  643. $repl[] = '\\1<a href="' . s_link('a', $sub) . '">' . $real . '</a>';
  644. }
  645. $this->message = preg_replace($orig, $repl, $this->message);
  646. }
  647. return;
  648. }
  649. private function parse_downloads() {
  650. global $user;
  651. if (!isset($this->options['downloads'])) {
  652. global $cache;
  653. if (!$this->options['downloads']['list'] = $cache->get('downloads_list')) {
  654. $sql = 'SELECT a.name, a.subdomain, d.id, d.title
  655. FROM _artists a, _dl d
  656. WHERE a.ub = d.ub
  657. ORDER BY d.id';
  658. $result = sql_rowset($sql);
  659. foreach ($result as $row) {
  660. $this->options['downloads']['list'][$row->id] = $row;
  661. }
  662. $cache->save('downloads_list', $this->options['downloads']['list']);
  663. }
  664. }
  665. if (preg_match_all('#\:d(\d+)(\*)?\:#', $this->message, $match)) {
  666. $orig = $repl = w();
  667. foreach ($match[1] as $i => $download) {
  668. if (isset($this->options['downloads']['list'][$download])) {
  669. $show_a = (isset($match[2][$i]) && $match[2][$i] != '') ? true : false;
  670. $orig[] = ':d' . $download . $match[2][$i] . ':';
  671. $repl[] = '<a href="' . s_link('a', $this->options['downloads']['list'][$download]->subdomain, '9', $download) . '" title="' . $this->options['downloads']['list'][$download]->name . ' - ' . $this->options['downloads']['list'][$download]->title . '">' . (($show_a) ? $this->options['downloads']['list'][$download]->name . ' - ' : '') . $this->options['downloads']['list'][$download]->title . '</a>';
  672. }
  673. }
  674. if (count($orig)) {
  675. $this->message = str_replace($orig, $repl, $this->message);
  676. }
  677. }
  678. return;
  679. }
  680. private function parse_profiles() {
  681. if (preg_match_all('#\:m([0-9a-zA-Z\_\- ]+)\:#ii', $this->message, $match)) {
  682. $orig = $repl = w();
  683. foreach ($match[1] as $orig_member) {
  684. $member = get_username_base($orig_member);
  685. if (!isset($this->options['members'][$member])) {
  686. $this->options['members'][$member] = '<a href="' . s_link('m', $member) . '">' . $orig_member . '</a>';
  687. }
  688. $orig[] = ':m' . $orig_member . ':';
  689. $repl[] = $this->options['members'][$member];
  690. }
  691. $this->message = str_replace($orig, $repl, $this->message);
  692. }
  693. return;
  694. }
  695. private function parse_avatars() {
  696. global $config;
  697. if (preg_match_all('#\:i([0-9a-zA-Z\_\- ]+)\:#si', $this->message, $match)) {
  698. $orig = $repl = w();
  699. $formats = w('.jpg .gif .png');
  700. $assets_url = $config->assets_url . 'avatars/';
  701. $assets_path = $config->assets_path . 'avatars/';
  702. foreach ($match[1] as $orig_member) {
  703. $member = get_username_base($orig_member);
  704. if (!isset($this->options['icons'][$member])) {
  705. for ($i = 0, $end = count($formats); $i < $end; $i++) {
  706. $icon_file = $member . $formats[$i];
  707. if (@file_exists($assets_path . $icon_file)) {
  708. $this->options['icons'][$member] = '<a href="' . s_link('m', $member) . '" title="' . $orig_member . '"><img src="' . $assets_url . $icon_file . '" /></a>';
  709. break;
  710. }
  711. }
  712. }
  713. $orig[] = ':i' . $orig_member . ':';
  714. $repl[] = (isset($this->options['icons'][$member])) ? $this->options['icons'][$member] : '<a href="' . s_link('m', get_username_base($orig_member)) . '">' . $orig_member . '</a>';
  715. }
  716. $this->message = str_replace($orig, $repl, $this->message);
  717. }
  718. return;
  719. }
  720. /*private function parse_html($message) {
  721. global $user, $cache;
  722. $html = w();
  723. $exclude = w();
  724. if (!$user->is('founder')) {
  725. $sql = 'SELECT *
  726. FROM _html_exclude
  727. WHERE html_member = ?';
  728. if ($result = sql_rowset(sql_filter($sql, $user->d('user_id')))) {
  729. $delete_expired = w();
  730. $current_time = time();
  731. foreach ($result as $row) {
  732. if ($row['exclude_until'] > $current_time) {
  733. $exclude[] = $row_exclude['exclude_html'];
  734. } else {
  735. $delete_expired[] = $row_exclude['exclude_id'];
  736. }
  737. }
  738. }
  739. }
  740. if (!$html = $cache->get('html')) {
  741. $sql = 'SELECT *
  742. FROM _html';
  743. if ($html = sql_rowset($sql, 'html_id')) {
  744. $cache->save('html', $html);
  745. }
  746. }
  747. if (count($exclude)) {
  748. foreach ($exclude as $item) {
  749. unset($html[$item]);
  750. }
  751. }
  752. }*/
  753. }