public function _home() { global $config, $user, $cache; if (!_button()) { return; } $this->id = request_var('msg_id', 0); $sql = 'SELECT * FROM _forum_topics WHERE topic_id = ?'; if (!$this->object = sql_fieldrow(sql_filter($sql, $this->id))) { fatal_error(); } $this->object = (object) $this->object; $this->object->new_value = ($this->object->topic_featured) ? 0 : 1; topic_feature($this->id, $this->object->new_value); $sql_insert = array( 'bio' => $user->d('user_id'), 'time' => time(), 'ip' => $user->ip, 'action' => 'feature', 'old' => $this->object->topic_featured, 'new' => $this->object->new_value ); sql_insert('log_mod', $sql_insert); return redirect(s_link('topic', $this->id)); }
public function _home() { global $config, $user, $cache; if (!_button()) { $sql = 'SELECT forum_id, forum_name FROM _forums ORDER BY forum_order'; $result = sql_rowset($sql); foreach ($result as $i => $row) { if (!$i) _style('forums'); _style('forums.row', array( 'FORUM_ID' => $row['forum_id'], 'FORUM_NAME' => $row['forum_name']) ); } return false; } $t = request_var('topic_id', 0); $f = request_var('forum_id', 0); if (!$f || !$t) { fatal_error(); } // $sql = 'SELECT * FROM _forum_topics WHERE topic_id = ?'; if (!$tdata = sql_fieldrow(sql_filter($sql, $t))) { fatal_error(); } // $sql = 'SELECT * FROM _forums WHERE forum_id = ?'; if (!$fdata = sql_fieldrow(sql_filter($sql, $f))) { fatal_error(); } // $sql = 'UPDATE _forum_topics SET forum_id = ? WHERE topic_id = ?'; sql_query(sql_filter($sql, $f, $t)); $sql = 'UPDATE _forum_posts SET forum_id = ? WHERE topic_id = ?'; sql_query(sql_filter($sql, $f, $t)); if (in_array($f, array(20, 39))) { topic_feature($t, 0); topic_arkane($t, 0); } sync_topic_move($f); sync_topic_move($tdata['forum_id']); //redirect(s_link('forum', $f)); return; }
public function object() { global $auth, $user, $config, $comments, $upload; $mode = request_var('mode', ''); switch ($mode) { case 'view': case 'fav': case 'rsvp': $download_id = request_var('download_id', 0); if (!$download_id) { redirect(s_link('events', $this->v('event_alias'))); } switch ($mode) { case 'view': $sql = 'SELECT e.*, COUNT(e2.image) AS prev_images FROM _events_images e, _events_images e2 WHERE e.event_id = ? AND e.event_id = e2.event_id AND e.image = ? AND e2.image <= ? GROUP BY e.image ORDER BY e.image ASC'; $sql = sql_filter($sql, $this->v('id'), $download_id, $download_id); break; case 'rsvp': $sql = ''; break; default: $sql = 'SELECT e2.* FROM _events_images e2 LEFT JOIN _events e ON e.id = e2.event_id WHERE e2.event_id = ? AND e2.image = ?'; $sql = sql_filter($sql, $this->v('id'), $download_id); break; } if (!empty($sql)) { if (!$imagedata = sql_fieldrow($sql)) { redirect(s_link('events', $this->v('event_alias'))); } } break; } switch ($mode) { case 'fav': if (!$user->is('member')) { do_login(); } $sql = 'SELECT * FROM _events_fav WHERE event_id = ? AND image_id = ? AND member_id = ?'; if ($row = sql_fieldrow(sql_filter($sql, $this->v('id'), $imagedata['image'], $user->d('user_id')))) { $sql = 'UPDATE _events_fav SET fav_date = ? WHERE event_id = ? AND image_id = ?'; sql_query(sql_filter($sql, time(), $this->v('id'), $imagedata['image'])); } else { $sql_insert = array( 'event_id' => (int) $this->v('id'), 'image_id' => (int) $imagedata['image'], 'member_id' => (int) $user->d('user_id'), 'fav_date' => time() ); sql_insert('events_fav', $sql_insert); } redirect(s_link('events', $this->v('event_alias'), $imagedata['image'], 'view')); break; case 'rsvp': $choice = array_key(array_keys(request_var('choice', array(0 => ''))), 0); $topic_id = $this->v('event_topic'); if (!$topic_id) { fatal_error(); } if (!$choice) { redirect(s_link('events', $this->v('event_alias'))); } if (!$user->is('member')) { do_login(); } $sql = 'SELECT vd.vote_id FROM _poll_options vd, _poll_results vr WHERE vd.topic_id = ? AND vr.vote_id = vd.vote_id AND vr.vote_option_id = ? GROUP BY vd.vote_id'; if (!$vote_id = sql_field(sql_filter($sql, $topic_id, $choice), 'vote_id', 0)) { fatal_error(); } $sql = 'SELECT * FROM _poll_voters WHERE vote_id = ? AND vote_user_id = ?'; if (!sql_fieldrow(sql_filter($sql, $vote_id, $user->d('user_id')))) { $sql = 'UPDATE _poll_results SET vote_result = vote_result + 1 WHERE vote_id = ? AND vote_option_id = ?'; sql_query(sql_filter($sql, $vote_id, $choice)); $insert_vote = array( 'vote_id' => (int) $vote_id, 'vote_user_id' => (int) $user->d('user_id'), 'vote_user_ip' => $user->ip, 'vote_cast' => (int) $choice ); sql_insert('poll_voters', $insert_vote); } redirect(s_link('events', $this->v('event_alias'))); break; case 'view': default: /** * Generate thumbnail for events list. */ if ($user->is('colab') && !$this->v('images') && _button('create_thumbnail')) { $location_large = $config['events_path'] . 'future/' . $this->v('id') . '.jpg'; $location_mini = $config['events_path'] . 'mini/' . $this->v('id') . '.jpg'; $x1 = request_var('x1', 0); $y1 = request_var('y1', 0); $x2 = request_var('x2', 0); $y2 = request_var('y2', 0); $w = request_var('w', 0); $h = request_var('h', 0); //Scale the image to the thumb_width set above $scale = $config['events_thumb_width'] / $w; $cropped = $upload->resizeThumbnailImage($location_mini, $location_large, $w, $h, $x1, $y1, $scale); redirect(s_link('events')); } /** * Normal operations */ $t_offset = request_var('offset', 0); if ($mode == 'view') { $sql = 'UPDATE _events_images SET views = views + 1 WHERE event_id = ? AND image = ?'; sql_query(sql_filter($sql, $this->v('id'), $imagedata['image'])); _style('selected', array( 'IMAGE' => $config['events_url'] . 'gallery/' . $this->v('id') . '/' . $imagedata['image'] . '.jpg', 'WIDTH' => $imagedata['width'], 'HEIGHT' => $imagedata['height'], 'FOOTER' => $imagedata['image_footer']) ); if ($user->is('founder')) { _style('selected.update', array( 'URL' => s_link('async eif'), 'EID' => $this->v('id'), 'PID' => $imagedata['image']) ); } $is_fav = false; if ($user->is('member')) { $sql = 'SELECT member_id FROM _events_fav WHERE event_id = ? AND image_id = ? AND member_id = ?'; if (sql_field(sql_filter($sql, $this->v('id'), $imagedata['image'], $user->d('user_id')), 'member_id', 0)) { $is_fav = true; } } if (!$is_fav || !$user->is('member')) { _style('selected.fav', array( 'URL' => s_link('events', $this->v('id'), $imagedata['image'], 'fav')) ); } } else { if (!$t_offset && $user->is('founder')) { $sql = 'UPDATE _events SET views = views + 1 WHERE id = ?'; sql_query(sql_filter($sql, $this->v('id'))); } } $sql = 'SELECT t.topic_id, t.topic_title, t.topic_locked, t.topic_replies, t.topic_time, t.topic_important, t.topic_vote, t.topic_featured, t.topic_points, t.topic_last_post_id, f.forum_alias, f.forum_name, f.forum_locked, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_announce, f.auth_pollcreate, f.auth_vote FROM _forum_topics t, _forums f WHERE t.topic_id = ? AND f.forum_id = t.forum_id'; if (!$event_topic = sql_fieldrow(sql_filter($sql, $this->v('event_topic')))) { fatal_error(); } $mod_auth = $user->is('mod'); $error = w(); $forum_id = $event_topic['forum_id']; $submit_reply = _button('post'); $reply = request_var('reply', 0); if ($reply) { $post_reply = request_var('p', 0); $sql = 'SELECT p.*, u.user_id, u.username FROM _forum_posts p, _members u WHERE p.post_id = ? AND u.user_id = p.poster_id AND p.post_deleted = 0'; if (!$post_data = sql_fieldrow(sql_filter($sql, $post_reply))) { redirect(s_link('events', $this->v('event_alias'))); } } $is_auth = $auth->forum(AUTH_ALL, $forum_id, $event_topic); $u_event_alias = s_link('events', $this->v('event_alias')); $u_event_publish = ($reply) ? s_link('events', $this->v('event_alias'), $post_reply, 'reply') : $u_event_alias; if ($submit_reply) { $auth_key = 'auth_reply'; if (((!$is_auth['auth_view'] || !$is_auth['auth_read'])) || !$is_auth[$auth_key]) { if (!$user->is('member')) { do_login(); } $can_reply_closed = $auth->option(array('forum', 'topics', 'delete')); if (!$can_reply_closed && ($event_topic['forum_locked'] || $event_topic['topic_locked'])) { $error[] = 'TOPIC_LOCKED'; } if (sizeof($error)) { redirect($u_event_alias); } } $post_message = request_var('message', '', true); if ($reply) { $post_reply_message = request_var('reply_message', '', true); } // Check message if (empty($post_message)) { $error[] = 'EMPTY_MESSAGE'; } if (sizeof($error)) { redirect($u_event_alias); } if (!$mod_auth) { $sql = 'SELECT MAX(post_time) AS last_post_time FROM _forum_posts WHERE poster_id = ?'; if ($last_post_time = sql_field(sql_filter($sql, $user->d('user_id')))) { if (intval($last_post_time) > 0 && ($current_time - intval($last_post_time)) < intval($config['flood_interval'])) { $error[] = 'FLOOD_ERROR'; } } } if (sizeof($error)) { redirect($u_event_alias); } $update_topic = w(); if (strstr($post_message, '-Anuncio-') && $user->is('mod')) { $topic_announce = 1; $post_message = str_replace('-Anuncio-', '', $post_message); $update_topic['topic_announce'] = $topic_announce; } if (strstr($post_message, '-Cerrado-') && $user->is('mod')) { $topic_locked = 1; $post_message = str_replace('-Cerrado-', '', $post_message); $update_topic['topic_locked'] = $topic_locked; } $post_message = $comments->prepare($post_message); if ($reply && $post_reply_message != '') { $post_reply_message = preg_replace('#(^|[\n ]|\()(http|https|ftp)://([a-z0-9\-\.,\?!%\*_:;~\\&$@/=\+]+)(gif|jpg|jpeg|png)#ie', '', $post_reply_message); } if ($reply && empty($post_reply_message)) { $post_reply_message = '...'; } if ($reply && $post_reply_message != '') { $post_message = '<blockquote><strong>' . $post_data['username'] . "</strong>" . nr(false, 2) . $post_reply_message . '</blockquote><br /> ' . $post_message; } else { $reply = 0; } $insert_data = array( 'topic_id' => (int) $this->v('event_topic'), 'forum_id' => (int) $forum_id, 'poster_id' => (int) $user->d('user_id'), 'post_time' => time(), 'poster_ip' => $user->ip, 'post_text' => $post_message, 'post_np' => '' ); if ($reply) { $insert_data['post_reply'] = $post_reply; } $post_id = sql_insert('forum_posts', $insert_data); $user->delete_unread(UH_T, $this->v('event_topic')); $user->save_unread(UH_T, $this->v('event_topic')); // $a_list = forum_for_team_list($forum_id); if (count($a_list)) { $sql_delete_unread = 'DELETE FROM _members_unread WHERE element = ? AND item = ? AND user_id NOT IN (??)'; sql_query(sql_filter($sql, 8, $this->v('event_topic'), implode(', ', $a_list))); } $update_topic['topic_last_post_id'] = $post_id; if ($topic_locked) { topic_feature($topic_id, 0); } $sql = 'UPDATE _forums SET forum_posts = forum_posts + 1, forum_last_topic_id = ? WHERE forum_id = ?'; sql_query(sql_filter($sql, $this->v('event_topic'), $forum_id)); $sql = 'UPDATE _forum_topics SET topic_replies = topic_replies + 1, ' . sql_build('UPDATE', $update_topic) . sql_filter(' WHERE topic_id = ?', $this->v('event_topic')); sql_query($sql); $sql = 'UPDATE _members SET user_posts = user_posts + 1 WHERE user_id = ?'; sql_query(sql_filter($sql, $user->d('user_id'))); redirect($u_event_alias); } // Get event thumbnails $t_per_page = 18; if ($mode == 'view' && $download_id) { $val = 1; $sql = 'SELECT MAX(image) AS total FROM _events_images WHERE event_id = ?'; if ($maximage = sql_field(sql_filter($sql, $this->v('id')), 'total', 0)) { $val = ($download_id == $maximage) ? 2 : 1; } $t_offset = floor(($imagedata['prev_images'] - $val) / $t_per_page) * $t_per_page; } if ($this->v('images')) { $exception_sql = (isset($download_id) && $download_id) ? sql_filter(' AND g.image <> ? ', $download_id) : ''; $sql = 'SELECT g.* FROM _events e, _events_images g WHERE e.id = ? AND e.id = g.event_id ' . $exception_sql . ' ORDER BY g.image ASC LIMIT ??, ??'; if (!$result = sql_rowset(sql_filter($sql, $this->v('id'), $t_offset, $t_per_page))) { redirect(s_link('events', $this->v('id'))); } build_num_pagination(s_link('events', $this->v('id'), 's%d'), $this->v('images'), $t_per_page, $t_offset, 'IMG_'); _style('thumbnails'); foreach ($result as $row) { _style('thumbnails.item', array( 'URL' => s_link('events', $this->v('event_alias'), $row['image'], 'view'), 'IMAGE' => $config['events_url'] . 'gallery/' . $this->v('id') . '/thumbnails/' . $row['image'] . '.jpg', 'RIMAGE' => $config['events_url'] . 'gallery/' . $this->v('id') . '/' . $row['image'] . '.jpg', 'FOOTER' => $row['image_footer'], 'WIDTH' => $row['width'], 'HEIGHT' => $row['height']) ); } // Credits $sql = 'SELECT * FROM _events_colab c, _members m WHERE c.colab_event = ? AND c.colab_uid = m.user_id ORDER BY m.username'; if ($result = sql_rowset(sql_filter($sql, $this->v('id')))) { _style('collab'); foreach ($result as $row) { _style('collab.row', array( 'PROFILE' => s_link('m', $row['username_base']), 'USERNAME' => $row['username']) ); } } } else { _style('event_flyer', array( 'IMAGE_SRC' => $config['events_url'] . 'future/' . $this->v('id') . '.jpg?u=' . $this->v('event_update')) ); $location_mini = $config['events_path'] . 'mini/' . $this->v('id') . '.jpg'; if ($user->is('colab') && !$this->v('images') && !@file_exists($location_mini)) { $large_filepath = $config['events_path'] . 'future/' . $this->v('id') . '.jpg'; _style('event_flyer.thumbnail', array( 'ACTION' => $u_event_alias, 'SCALE' => ($config['events_thumb_height'] / $config['events_thumb_width']), 'THUMB_WIDTH' => $config['events_thumb_width'], 'THUMB_HEIGHT' => $config['events_thumb_height'], 'LARGE_WIDTH' => $upload->getWidth($large_filepath), 'LARGE_HEIGHT' => $upload->getHeight($large_filepath) )); } } list($d, $m, $y) = explode(' ', gmdate('j n Y', time() + $user->timezone + $user->dst)); $midnight = gmmktime(0, 0, 0, $m, $d, $y) - $user->timezone - $user->dst; $event_date = $user->format_date($this->v('date'), 'j F Y \a \l\a\s H:i') . ' horas.'; if ($this->v('date') >= $midnight) { if ($this->v('date') >= $midnight && $this->v('date') < $midnight + 86400) { $event_date_format = lang('event_today'); } else if ($this->v('date') >= $midnight + 86400 && $this->v('date') < $midnight + (86400 * 2)) { $event_date_format = lang('event_tomorrow'); } else { $event_date_format = sprintf(lang('event_after'), $event_date); } } else { if ($this->v('date') >= ($midnight - 86400)) { $event_date_format = lang('event_yesterday'); } else { $event_date_format = sprintf(lang('event_before'), $event_date); } } v_style(array( 'EVENT_NAME' => $this->v('title'), 'EVENT_DATE' => $event_date_format, 'EVENT_URL' => $u_event_alias, 'EVENT_PUBLISH' => $u_event_publish) ); $posts_offset = request_var('ps', 0); $topic_id = $this->v('event_topic'); // START RSVP if ($topic_id) { $sql = 'SELECT vd.vote_id, vd.vote_text, vd.vote_start, vd.vote_length, vr.vote_option_id, vr.vote_option_text, vr.vote_result FROM _poll_options vd, _poll_results vr WHERE vd.topic_id = ? AND vr.vote_id = vd.vote_id ORDER BY vr.vote_option_order, vr.vote_option_id ASC'; if ($vote_info = sql_rowset(sql_filter($sql, $topic_id))) { $sql = 'SELECT vote_id FROM _poll_voters WHERE vote_id = ? AND vote_user_id = ?'; $user_voted = sql_field(sql_filter($sql, $vote_info[0]['vote_id'], $user->d('user_id')), 'vote_id', 0); $poll_expired = ($vote_info[0]['vote_length']) ? (($vote_info[0]['vote_start'] + $vote_info[0]['vote_length'] < time()) ? true : false) : false; _style('poll', array( 'POLL_TITLE' => $vote_info[0]['vote_text']) ); if ($user_voted || $poll_expired) { _style('poll.results'); foreach ($vote_info as $row) { if ($this->v('date') >= $midnight) { $caption = ($row['vote_result'] == 1) ? lang('rsvp_future_one') : lang('rsvp_future_more'); } else { $caption = ($row['vote_result'] == 1) ? lang('rsvp_past_one') : lang('rsvp_past_more'); } _style('poll.results.item', array( 'CAPTION' => $caption, 'RESULT' => $row['vote_result']) ); break; } } else { _style('poll.options', array( 'S_VOTE_ACTION' => s_link('events', $this->v('event_alias'), 1, 'rsvp')) ); foreach ($vote_info as $row) { $caption = ($this->v('date') >= $midnight) ? lang('rsvp_future') : lang('rsvp_past'); _style('poll.options.item', array( 'ID' => $row['vote_option_id'], 'CAPTION' => $caption) ); break; } } } } // END RSVP $sql = 'SELECT p.*, u.user_id, u.username, u.username_base, u.user_avatar, u.user_posts, u.user_gender, u.user_rank FROM _forum_posts p, _members u WHERE p.topic_id = ? AND u.user_id = p.poster_id AND p.post_deleted = 0 ORDER BY p.post_time DESC LIMIT ??, ??'; if (!$messages = sql_rowset(sql_filter($sql, $topic_id, $posts_offset, $config['posts_per_page']))) { redirect(s_link('events', $this->v('event_alias'))); } if (!$posts_offset) { //unset($messages[0]); } $i = 0; foreach ($messages as $row) { if (!$i) { $controls = w(); $user_profile = w(); $unset_user_profile = array('user_id', 'user_posts', 'user_gender'); _style('messages'); } if ($user->is('member')) { $controls[$row['post_id']]['reply'] = s_link('events', $this->v('event_alias'), $row['post_id'], 'reply'); if ($mod_auth) { $controls[$row['post_id']]['edit'] = s_link('acp', array('forums_post_modify', 'msg_id' => $row['post_id'])); $controls[$row['post_id']]['delete'] = s_link('acp', array('forums_post_delete', 'msg_id' => $row['post_id'])); } } $user_profile[$row['user_id']] = $comments->user_profile($row, '', $unset_user_profile); $data = array( 'POST_ID' => $row['post_id'], 'DATETIME' => $user->format_date($row['post_time']), 'MESSAGE' => $comments->parse_message($row['post_text']), 'PLAYING' => $row['post_np'], 'DELETED' => $row['post_deleted'] ); foreach ($user_profile[$row['user_id']] as $key => $value) { $data[strtoupper($key)] = $value; } _style('messages.row', $data); if (isset($controls[$row['post_id']])) { _style('messages.row.controls'); foreach ($controls[$row['post_id']] as $item => $url) { _style('messages.row.controls.' . $item, array( 'URL' => $url) ); } } $i++; } build_num_pagination(s_link('events', $this->v('event_alias'), 'ps%d'), $event_topic['topic_replies'], $config['posts_per_page'], $posts_offset, 'MSG_'); $publish_ref = ($posts_offset) ? s_link('events', $this->v('event_alias'), 's' . $t_offset) : s_link('events', $this->v('event_alias')); // Posting box if ($user->is('member')) { _style('publish', array( 'REF' => $publish_ref) ); if ($reply) { if (empty($post_reply_message)) { $post_reply_message = $comments->remove_quotes($post_data['post_text']); } if (!empty($post_reply_message)) { $rx = array('#(^|[\n ]|\()(http|https|ftp)://([a-z0-9\-\.,\?!%\*_:;~\\&$@/=\+]+)(gif|jpg|jpeg|png)#is', '#\[yt:[0-9a-zA-Z\-\=\_]+\]#is', '#\[sb\]#is', '#\[\/sb\]#is'); $post_reply_message = preg_replace($rx, '', $post_reply_message); } if (empty($post_reply_message)) { $post_reply_message = '...'; } _style('publish.reply', array( 'MESSAGE' => $post_reply_message) ); } } break; } $this->_title = $this->v('title'); $this->_template = 'events.view'; return true; }
public function run() { global $config, $auth, $user, $comments; $topic_id = request_var('t', 0); $post_id = request_var('p', 0); if (!$topic_id && !$post_id) { fatal_error(); } // // Get topic data // if ($post_id) { $sql_from = ', _forum_posts p, _forum_posts p2, _members m '; $sql_where = sql_filter('p.post_id = ? AND p.poster_id = m.user_id AND t.topic_id = p.topic_id AND p2.topic_id = p.topic_id AND p2.post_id <= ?', $post_id, $post_id); $sql_count = ', p.post_text, m.username AS reply_username, COUNT(p2.post_id) AS prev_posts, p.post_deleted'; $sql_order = ' GROUP BY p.post_id, t.topic_id, t.topic_title, t.topic_locked, t.topic_replies, t.topic_time, t.topic_important, t.topic_vote, t.topic_last_post_id, f.forum_name, f.forum_locked, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_announce, f.auth_pollcreate, f.auth_vote ORDER BY p.post_id ASC'; } else { $sql_from = $sql_count = $sql_order = ''; $sql_where = sql_filter('t.topic_id = ?', $topic_id); } $sql = 'SELECT t.*, f.*' . $sql_count . ' FROM _forum_topics t, _forums f' . $sql_from . ' WHERE ' . $sql_where . ' AND f.forum_id = t.forum_id' . $sql_order; if (!$topic_data = sql_fieldrow($sql)) { fatal_error(); } switch ($topic_data['forum_alias']) { case 'events': $sql = 'SELECT event_alias FROM _events WHERE event_topic = ?'; if ($event_alias = sql_field(sql_filter($sql, $topic_data['topic_id']), 'event_alias', '')) { redirect(s_link('events', $event_alias)); } break; } // // Hide deleted posts if (isset($topic_data['post_deleted']) && $topic_data['post_deleted']) { fatal_error(); } // // Check mod auth $mod_auth = $user->is('mod'); // // Init vars // $forum_id = (int) $topic_data['forum_id']; $topic_id = (int) $topic_data['topic_id']; $topic_url = s_link('topic', $topic_id); $reply = request_var('reply', 0); $start = request_var('offset', 0); $submit_reply = _button('post'); $submit_vote = _button('vote'); $post_message = ''; $post_reply_message = ''; $post_np = ''; $current_time = time(); $error = $is_auth = w(); if (!$post_id && $reply) { $reply = 0; } // // Start member auth // $is_auth = $auth->forum(AUTH_ALL, $forum_id, $topic_data); if ($submit_reply || $submit_vote) { $auth_key = ($submit_reply) ? 'auth_reply' : 'auth_vote'; if (((!$is_auth['auth_view'] || !$is_auth['auth_read'])) || !$is_auth[$auth_key]) { if (!$user->is('member')) { do_login(); } $can_reply_closed = $auth->option(w('forum topics delete')); if (!$can_reply_closed && ($topic_data['forum_locked'] || $topic_data['topic_locked'])) { $error[] = 'TOPIC_LOCKED'; if ($submit_vote && !$topic_data['topic_vote']) { $error[] = 'POST_HAS_NO_POLL'; } } if (!sizeof($error)) { redirect($topic_url); } } if (!sizeof($error)) { if ($submit_vote) { $vote_option = request_var('vote_id', 0); if ($vote_option) { $sql = 'SELECT vd.vote_id FROM _poll_options vd, _poll_results vr WHERE vd.topic_id = ? AND vr.vote_id = vd.vote_id AND vr.vote_option_id = ? GROUP BY vd.vote_id'; if ($vote_id = sql_field(sql_filter($sql, $topic_id, $vote_option), 'vote_id', 0)) { $sql = 'SELECT * FROM _poll_voters WHERE vote_id = ? AND vote_user_id = ?'; if (!sql_fieldrow(sql_filter($sql, $vote_id, $user->d('user_id')))) { $sql = 'UPDATE _poll_results SET vote_result = vote_result + 1 WHERE vote_id = ? AND vote_option_id = ?'; sql_query(sql_filter($sql, $vote_id, $vote_option)); $insert_vote = array( 'vote_id' => (int) $vote_id, 'vote_user_id' => (int) $user->d('user_id'), 'vote_user_ip' => $user->ip, 'vote_cast' => (int) $vote_option ); sql_insert('poll_voters', $insert_vote); } } } redirect(s_link('topic', $topic_id)); } else { $post_message = request_var('message', '', true); $post_np = request_var('np', ''); if ($reply) { $post_reply_message = request_var('reply_message', '', true); } // Check message if (empty($post_message)) { $error[] = 'EMPTY_MESSAGE'; } if (!sizeof($error) && !$mod_auth) { $sql = 'SELECT MAX(post_time) AS last_post_time FROM _forum_posts WHERE poster_id = ?'; if ($last_post_time = sql_field(sql_filter($sql, $user->d('user_id')))) { if (intval($last_post_time) > 0 && ($current_time - intval($last_post_time)) < intval($config['flood_interval'])) { $error[] = 'FLOOD_ERROR'; } } } if (!sizeof($error)) { $update_topic = w(); if (strstr($post_message, '-Anuncio-') && $user->is('mod')) { $topic_announce = 1; $post_message = str_replace('-Anuncio-', '', $post_message); $update_topic['topic_announce'] = $topic_announce; } if (strstr($post_message, '-Cerrado-') && $user->is('mod')) { $topic_locked = 1; $post_message = str_replace('-Cerrado-', '', $post_message); $update_topic['topic_locked'] = $topic_locked; } $post_message = $comments->prepare($post_message); if ($reply && $post_reply_message != '') { $post_reply_message = preg_replace('#(^|[\n ]|\()(http|https|ftp)://([a-z0-9\-\.,\?!%\*_:;~\\&$@/=\+]+)(gif|jpg|jpeg|png)#ie', '', $post_reply_message); } if ($reply && empty($post_reply_message)) { $post_reply_message = '...'; } if ($reply && $post_reply_message != '') { $post_message = '<blockquote><strong>' . $topic_data['reply_username'] . "</strong>" . nr(false, 2) . $post_reply_message . '</blockquote><br /> ' . $post_message; } else { $reply = 0; } $insert_data = array( 'topic_id' => (int) $topic_id, 'forum_id' => (int) $forum_id, 'poster_id' => (int) $user->d('user_id'), 'post_time' => (int) $current_time, 'poster_ip' => $user->ip, 'post_text' => $post_message, 'post_np' => $post_np ); if ($reply) { $insert_data['post_reply'] = $post_id; } $post_id = sql_insert('forum_posts', $insert_data); $user->delete_unread(UH_T, $topic_id); $user->save_unread(UH_T, $topic_id); if (!in_array($forum_id, forum_for_team_array()) && $topic_data['topic_points']) { //$user->points_add(1); } // $a_list = forum_for_team_list($forum_id); if (count($a_list)) { $sql_delete_unread = 'DELETE FROM _members_unread WHERE element = ? AND item = ? AND user_id NOT IN (??)'; sql_query(sql_filter($sql_delete_unread, 8, $topic_id, implode(', ', $a_list))); } $update_topic['topic_last_post_id'] = $post_id; if ($topic_locked) { topic_feature($topic_id, 0); } $sql = 'UPDATE _forums SET forum_posts = forum_posts + 1, forum_last_topic_id = ? WHERE forum_id = ?'; sql_query(sql_filter($sql, $topic_id, $forum_id)); $sql = 'UPDATE _forum_topics SET topic_replies = topic_replies + 1, ' . sql_build('UPDATE', $update_topic) . sql_filter(' WHERE topic_id = ?', $topic_id); sql_query($sql); $sql = 'UPDATE _members SET user_posts = user_posts + 1 WHERE user_id = ?'; sql_query(sql_filter($sql, $user->d('user_id'))); redirect(s_link('post', $post_id) . '#' . $post_id); } } } } if (!$is_auth['auth_view'] || !$is_auth['auth_read']) { if (!$user->is('member')) { do_login(); } fatal_error(); } if ($post_id) { $start = floor(($topic_data['prev_posts'] - 1) / (int) $config['posts_per_page']) * (int) $config['posts_per_page']; $user->d('user_topic_order', 0); } if ($user->is('member')) { // // Is user watching this topic? // $sql = 'SELECT notify_status FROM _forum_topics_fav WHERE topic_id = ? AND user_id = ?'; if (!sql_field(sql_filter($sql, $topic_id, $user->d('user_id')), 'notify_status')) { if (_button('watch')) { $sql_insert = array( 'user_id' => $user->d('user_id'), 'topic_id' => $topic_id, 'notify_status' => 0 ); sql_insert('forum_topics_fav', $sql_insert); redirect($topic_url . (($start) ? 's' . $start . '/' : '')); } _style('watch_topic'); } } // // Get all data for the topic // $get_post_id = ($reply) ? 'post_id' : 'topic_id'; $get_post_data['p.' . $get_post_id] = ${$get_post_id}; if (!$user->is('founder')) { $get_post_data['p.post_deleted'] = 0; } $sql = 'SELECT p.*, u.user_id, u.username, u.username_base, u.user_avatar, u.user_posts, u.user_gender, u.user_rank, u.user_sig FROM _forum_posts p, _members u WHERE u.user_id = p.poster_id AND p.post_deleted = 0 AND ' . sql_build('SELECT', $get_post_data) . ' ORDER BY p.post_time ' . (($user->d('user_topic_order')) ? 'DESC' : 'ASC') . ((!$reply) ? ' LIMIT ' . (int) $start . ', ' . (int) $config['posts_per_page'] : ''); if (!$messages = sql_rowset($sql)) { if ($topic_data['topic_replies'] + 1) { fatal_error(); } redirect(s_link('topic', $topic_id)); } // // Re-count topic replies // if ($user->is('founder')) { $sql = 'SELECT COUNT(p.post_id) AS total FROM _forum_posts p, _members u WHERE p.topic_id = ? AND u.user_id = p.poster_id'; if ($total = sql_field(sql_filter($sql, $topic_id), 'total')) { $topic_data['topic_replies2'] = $total - 1; } } // // Update the topic views // if (!$start && !$user->is('founder')) { $sql = 'UPDATE _forum_topics SET topic_views = topic_views + 1 WHERE topic_id = ?'; sql_query(sql_filter($sql, $topic_id)); } // // If the topic contains a poll, then process it // if ($topic_data['topic_vote']) { $sql = 'SELECT vd.vote_id, vd.vote_text, vd.vote_start, vd.vote_length, vr.vote_option_id, vr.vote_option_text, vr.vote_result FROM _poll_options vd, _poll_results vr WHERE vd.topic_id = ? AND vr.vote_id = vd.vote_id ORDER BY vr.vote_option_order, vr.vote_option_id ASC'; if ($vote_info = sql_rowset(sql_filter($sql, $topic_id))) { $sql = 'SELECT vote_id FROM _poll_voters WHERE vote_id = ? AND vote_user_id = ?'; $user_voted = sql_field(sql_filter($sql, $vote_info[0]['vote_id'], $user->d('user_id')), 'vote_id', 0); $poll_expired = ($vote_info[0]['vote_length']) ? (($vote_info[0]['vote_start'] + $vote_info[0]['vote_length'] < $current_time) ? true : 0) : 0; _style('poll', array( 'POLL_TITLE' => $vote_info[0]['vote_text']) ); if ($user_voted || $poll_expired || !$is_auth['auth_vote'] || $topic_data['topic_locked']) { $vote_results_sum = 0; foreach ($vote_info as $row) { $vote_results_sum += $row['vote_result']; } _style('poll.results'); foreach ($vote_info as $row) { $vote_percent = ($vote_results_sum > 0) ? $row['vote_result'] / $vote_results_sum : 0; _style('poll.results.item', array( 'CAPTION' => $row['vote_option_text'], 'RESULT' => $row['vote_result'], 'PERCENT' => sprintf("%.1d", ($vote_percent * 100))) ); } } else { _style('poll.options', array( 'S_VOTE_ACTION' => $topic_url) ); foreach ($vote_info as $row) { _style('poll.options.item', array( 'POLL_OPTION_ID' => $row['vote_option_id'], 'POLL_OPTION_CAPTION' => $row['vote_option_text']) ); } } } } // // Advanced auth // $controls = $user_profile = w(); $unset_user_profile = w('user_id user_posts user_gender'); _style('posts'); foreach ($messages as $row) { if ($user->is('member')) { $poster = ($row['user_id'] != GUEST) ? $row['username'] : (($row['post_username'] != '') ? $row['post_username'] : lang('guest')); $controls[$row['post_id']]['reply'] = s_link('post', $row['post_id'], 'reply'); if ($mod_auth) { $controls[$row['post_id']]['edit'] = s_link('acp', array('forums_post_modify', 'msg_id' => $row['post_id'])); $controls[$row['post_id']]['delete'] = s_link('acp', array('forums_post_delete', 'msg_id' => $row['post_id'])); } } $user_profile[$row['user_id']] = $comments->user_profile($row, '', $unset_user_profile); $data = array( 'POST_ID' => $row['post_id'], 'POST_DATE' => $user->format_date($row['post_time']), 'MESSAGE' => $comments->parse_message($row['post_text']), 'PLAYING' => $row['post_np'], 'DELETED' => $row['post_deleted'], 'UNREAD' => 0 ); foreach ($user_profile[$row['user_id']] as $key => $value) { $data[strtoupper($key)] = $value; } _style('posts.item', $data); _style('posts.item.' . (($row['user_id'] != GUEST) ? 'username' : 'guestuser')); if (isset($controls[$row['post_id']])) { _style('posts.item.controls'); foreach ($controls[$row['post_id']] as $item => $url) { _style('posts.item.controls.'.$item, array('URL' => $url)); } } } // // Display Member topic auth // /* if ($mod_auth) { $mod = array((($topic_data['topic_important']) ? 'important' : 'normal'), 'delete', 'move', ((!$topic_data['topic_locked']) ? 'lock' : 'unlock'), 'split', 'merge'); $mod_topic = w(); foreach ($mod as $item) { if ($auth->option(array('forum', 'topics', $item))) { $mod_topic[strtoupper($item)] = s_link('acp', array('topic', topic' => $topic_id, 'mode' => $item)); } } if (sizeof($mod_topic)) { _style('auth'); foreach ($mod_topic as $k => $v) { _style('auth.item', array( 'URL' => $v, 'LANG' => lang($k . '_topic')) ); } } } */ build_num_pagination($topic_url . 's%d/', ($topic_data['topic_replies'] + 1), $config['posts_per_page'], $start, '', 'TOPIC_'); // // Posting box if (sizeof($error)) { _style('post_error', array( 'MESSAGE' => parse_error($error)) ); } $can_reply_closed = $auth->option(array('forum', 'topics', 'delete')); if ((!$topic_data['forum_locked'] && !$topic_data['topic_locked']) || $can_reply_closed) { if ($user->is('member')) { if ($is_auth['auth_reply']) { $s_post_action = (($reply) ? s_link('post', $post_id, 'reply') : $topic_url) . '#e'; _style('post_box', array( 'MESSAGE' => $post_message, 'NP' => $post_np, 'S_POST_ACTION' => $s_post_action) ); if ($reply) { if (empty($post_reply_message)) { $post_reply_message = $comments->remove_quotes($topic_data['post_text']); } if (!empty($post_reply_message)) { $rx = array('#(^|[\n ]|\()(http|https|ftp)://([a-z0-9\-\.,\?!%\*_:;~\\&$@/=\+]+)(gif|jpg|jpeg|png)#is', '#\[yt:[0-9a-zA-Z\-\=\_]+\]#is', '#\[sb\]#is', '#\[\/sb\]#is'); $post_reply_message = preg_replace($rx, '', $post_reply_message); } if (empty($post_reply_message)) { $post_reply_message = '...'; } _style('post_box.reply', array( 'MESSAGE' => $post_reply_message) ); } } } } // MOD: Featured topic if ($user->is('mod')) { $v_lang = ($topic_data['topic_featured']) ? 'REM' : 'ADD'; _style('feature', array( 'U_FEAT' => s_link('acp', array('forums_topic_feature', 'msg_id', $topic_data['topic_id'])), 'V_LANG' => lang('topic_featured_' . $v_lang)) ); } // // Send vars to template // v_style(array( 'FORUM_NAME' => $topic_data['forum_name'], 'TOPIC_TITLE' => $topic_data['topic_title'], 'TOPIC_REPLIES' => $topic_data['topic_replies'], 'S_TOPIC_ACTION' => $topic_url . (($start) ? 's' . $start . '/' : ''), 'U_VIEW_FORUM' => s_link('forum', $topic_data['forum_alias'])) ); $layout_file = 'topic'; if (@file_exists('./template/custom/topics_' . $forum_id . '.htm')) { $layout_file = 'custom/topics_' . $forum_id; } if (@file_exists('./template/custom/topic_' . $topic_id . '.htm')) { $layout_file = 'custom/topic_' . $topic_id; } $this->_title = $topic_data['topic_title']; $this->_template = $layout_file; return; }
public function _home() { global $config, $user, $cache; if (!_button()) { return false; } $from_topic = request_var('from_topic', 0); $to_topic = request_var('to_topic', 0); if (!$from_topic || !$to_topic || $from_topic == $to_topic) { fatal_error(); } $sql = 'SELECT * FROM _forum_topics WHERE topic_id = ?'; if (!$row = sql_fieldrow(sql_filter($sql, $from_topic))) { fatal_error(); } $sql = 'SELECT * FROM _forum_topics WHERE topic_id = ?'; if (!$row = sql_fieldrow(sql_filter($sql, $to_topic))) { fatal_error(); } $from_forum_id = (int) $row['forum_id']; $from_poll = (int) $row['topic_vote']; $to_forum_id = (int) $row['forum_id']; $to_poll = (int) $row['topic_vote']; if ($from_poll) { if ($to_poll) { $sql = 'SELECT vote_id FROM _poll_options WHERE topic_id = ?'; if ($vote_id = sql_field(sql_filter($sql, $from_topic), 'vote_id', 0)) { $sql = array( sql_filter('DELETE FROM _poll_voters WHERE vote_id = ?', $vote_id), sql_filter('DELETE FROM _poll_results WHERE vote_id = ?', $vote_id), sql_filter('DELETE FROM _poll_options WHERE vote_id = ?', $vote_id) ); sql_query($sql); } } else { $sql = 'UPDATE _poll_options SET topic_id = ? WHERE topic_id = ?'; sql_query(sql_filter($sql, $to_topic, $from_topic)); } } // Update destination toic $sql = 'SELECT topic_views FROM _forum_topics WHERE topic_id = ?'; if ($topic_views = sql_field(sql_filter($sql, $from_topic), 'topic_views', 0)) { $sql = 'UPDATE _forum_topics SET topic_views = topic_views + ?? WHERE topic_id = ?'; sql_query(sql_filter($sql, $topic_views, $to_topic)); } // // $sql = 'SELECT * FROM _forum_topics_fav WHERE topic_id = ?'; $user_ids = sql_rowset(sql_filter($sql, $to_topic), false, 'user_id'); $sql_user = (sizeof($user_ids)) ? ' AND user_id NOT IN (' . _implode(', ', $user_ids) . ')' : ''; $sql = array( sql_filter('UPDATE _forum_topics_fav SET topic_id = ? WHERE topic_id = ?', $to_topic, $from_topic) . $sql_user, sql_filter('DELETE FROM _forum_topics_fav WHERE topic_id = ?', $from_topic), sql_filter('UPDATE _forum_posts SET forum_id = ?, topic_id = ? WHERE topic_id = ?', $to_forum_id, $to_topic, $from_topic), sql_filter('DELETE FROM _forum_topics WHERE topic_id = ?', $from_topic), sql_filter('DELETE FROM _members_unread WHERE element = ? AND item = ?', UH_T, $from_topic), ); if ($from_poll && !$to_poll) { $sql[] = sql_filter('UPDATE _forum_topics SET topic_vote = 1 WHERE topic_id = ?', $to_topic); } sql_query($sql); $user->save_unread(UH_T, $to_topic); if (in_array($to_forum_id, array(20, 39))) { topic_feature($to_topic, 0); topic_arkane($to_topic, 0); } sync_topic_merge('topic', $to_topic); sync_topic_merge('forum', $to_forum_id); if ($from_forum_id != $to_forum_id) { sync_topic_merge('forum', $from_forum_id); } return; }
public function run() { global $config, $auth, $user, $comments, $cache; $forum_id = request_var('f', ''); $start = request_var('offset', 0); $submit_topic = _button('post'); if (empty($forum_id)) { fatal_error(); } $is_int_forumid = false; if (preg_match('#^(\d+)$#is', $forum_id)) { $is_int_forumid = true; $forum_id = intval($forum_id); $sql = 'SELECT * FROM _forums WHERE forum_id = ?'; $sql = sql_filter($sql, $forum_id); } else { $sql = 'SELECT * FROM _forums WHERE forum_alias = ?'; $sql = sql_filter($sql, $forum_id); } if (!$forum_row = sql_fieldrow($sql)) { fatal_error(); } if ($is_int_forumid) { redirect(s_link('forum', $forum_row['forum_alias']), true); } $forum_id = $forum_row['forum_id']; // // Start auth check // $is_auth = w(); $is_auth = $auth->forum(AUTH_ALL, $forum_id, $forum_row); if (!$is_auth['auth_view'] || !$is_auth['auth_read']) { if (!$user->is('member')) { do_login(); } fatal_error(); } $error_msg = ''; $post_title = ''; $post_message = ''; $post_np = ''; $poll_title = ''; $poll_options = ''; $poll_length = ''; $current_time = time(); if ($submit_topic) { $topic_important = _button('topictype'); $auth_key = ($topic_important) ? 'auth_announce' : 'auth_post'; if ($forum_row['forum_locked'] && !$is_auth['auth_mod']) { $error_msg .= (($error_msg != '') ? '<br />' : '') . lang('forum_locked'); } if (!$is_auth[$auth_key]) { if (!$user->is('member')) { do_login(); } if (empty($error_msg)) { redirect($topic_url); } } if (empty($error_msg)) { $post_title = request_var('topic_title', ''); $post_message = request_var('message', '', true); $post_np = request_var('np', '', true); $poll_title = ''; $poll_options = ''; $poll_length = 0; if ($is_auth['auth_pollcreate']) { $poll_title = request_var('poll_title', ''); $poll_options = request_var('poll_options', ''); $poll_length = request_var('poll_length', 0); } // Check subject if (empty($post_title)) { $error_msg .= (($error_msg != '') ? '<br />' : '') . lang('empty_subject'); } // Check message if (empty($post_message)) { $error_msg .= (($error_msg != '') ? '<br />' : '') . lang('empty_message'); } if (!empty($poll_options)) { $real_poll_options = w(); $poll_options = explode(nr(), $poll_options); foreach ($poll_options as $option) { if ($option != '') { $real_poll_options[] = $option; } } $sizeof_poll_options = sizeof($real_poll_options); if ($sizeof_poll_options < 2) { $error_msg .= (($error_msg != '') ? '<br />' : '') . lang('few_poll_options'); } else if ($sizeof_poll_options > $config['max_poll_options']) { $error_msg .= (($error_msg != '') ? '<br />' : '') . lang('many_poll_options'); } else if ($poll_title == '') { $error_msg .= (($error_msg != '') ? '<br />' : '') . lang('empty_poll_title'); } } if (empty($error_msg) && !$is_auth['auth_mod']) { $sql = 'SELECT MAX(post_time) AS last_post_time FROM _forum_posts WHERE poster_id = ?'; if ($last_post_time = sql_field(sql_filter($sql, $user->d('user_id')))) { if (intval($last_post_time) > 0 && ($current_time - intval($last_post_time)) < intval($config['flood_interval'])) { $error_msg .= (($error_msg != '') ? '<br />' : '') . lang('flood_error'); } } } if (empty($error_msg)) { $topic_announce = 0; $topic_locked = 0; if ((strstr($post_message, '-Anuncio-') && $user->is('all')) || in_array($forum_id, array(15, 16, 17))) { $topic_announce = 1; $post_message = str_replace('-Anuncio-', '', $post_message); } if (strstr($post_message, '-Cerrado-') && $user->is('mod')) { $topic_locked = 1; $post_message = str_replace('-Cerrado-', '', $post_message); } $post_message = $comments->prepare($post_message); $topic_vote = (!empty($poll_title) && $sizeof_poll_options >= 2) ? 1 : 0; if (!$user->is('founder')) { $post_title = strnoupper($post_title); } $insert_data['TOPIC'] = array( 'topic_title' => $post_title, 'topic_poster' => (int) $user->d('user_id'), 'topic_time' => (int) $current_time, 'forum_id' => (int) $forum_id, 'topic_locked' => $topic_locked, 'topic_announce' => $topic_announce, 'topic_important' => (int) $topic_important, 'topic_vote' => (int) $topic_vote, 'topic_featured' => 1, 'topic_points' => 1 ); $topic_id = sql_insert('forum_topics', $insert_data['TOPIC']); $insert_data['POST'] = array( 'topic_id' => (int) $topic_id, 'forum_id' => (int) $forum_id, 'poster_id' => (int) $user->d('user_id'), 'post_time' => (int) $current_time, 'poster_ip' => $user->ip, 'post_text' => $post_message, 'post_np' => $post_np ); $post_id = sql_insert('forum_posts', $insert_data['POST']); if ($topic_vote) { $insert_data['POLL'] = array( 'topic_id' => (int) $topic_id, 'vote_text' => $poll_title, 'vote_start' => (int) $current_time, 'vote_length' => (int) ($poll_length * 86400) ); $poll_id = sql_insert('poll_options', $insert_data['POLL']); $poll_option_id = 1; foreach ($real_poll_options as $option) { $insert_data['POLLRESULTS'] = array( 'vote_id' => (int) $poll_id, 'vote_option_id' => (int) $poll_option_id, 'vote_option_text' => $option, 'vote_result' => 0 ); sql_insert('poll_results', $insert_data['POLLRESULTS']); $poll_option_id++; } if ($forum_id == $config['main_poll_f']) { $cache->delete('last_poll_id'); } } $user->save_unread(UH_T, $topic_id); if (!in_array($forum_id, forum_for_team_array())) { //$user->points_add(2); } $a_list = forum_for_team_list($forum_id); if (count($a_list)) { $sql_delete_unread = 'DELETE FROM _members_unread WHERE element = ? AND item = ? AND user_id NOT IN (??)'; sql_query(sql_filter($sql_delete_unread, 8, $topic_id, implode(', ', $a_list))); } if (count($a_list) || in_array($forum_id, array(20, 39))) { topic_feature($topic_id, 0); topic_arkane($topic_id, 0); } $sql = 'UPDATE _forums SET forum_posts = forum_posts + 1, forum_last_topic_id = ?, forum_topics = forum_topics + 1 WHERE forum_id = ?'; sql_query(sql_filter($sql, $topic_id, $forum_id)); $sql = 'UPDATE _forum_topics SET topic_first_post_id = ?, topic_last_post_id = ? WHERE topic_id = ?'; sql_query(sql_filter($sql, $post_id, $post_id, $topic_id)); $sql = 'UPDATE _members SET user_posts = user_posts + 1 WHERE user_id = ?'; sql_query(sql_filter($sql, $user->d('user_id'))); redirect(s_link('topic', $topic_id)); } } } // // End Submit // $topics_count = ($forum_row['forum_topics']) ? $forum_row['forum_topics'] : 1; $topics = new stdClass(); $total = new stdClass(); // // All announcement data // $sql = 'SELECT t.*, u.user_id, u.username, u.username_base, u2.user_id as user_id2, u2.username as username2, u2.username_base as username_base2, p.post_time, p.post_username as post_username2 FROM _forum_topics t, _members u, _forum_posts p, _members u2 WHERE t.forum_id = ? AND t.topic_poster = u.user_id AND p.post_id = t.topic_last_post_id AND p.poster_id = u2.user_id AND t.topic_announce = 1 ORDER BY t.topic_last_post_id DESC'; $topics->important = sql_rowset(sql_filter($sql, $forum_id)); $total->important = (is_array($topics->important)) ? count($topics->important) : 0; // // Grab all the topics data for this forum // $sql = 'SELECT t.*, u.user_id, u.username, u.username_base, u2.user_id as user_id2, u2.username as username2, u2.username_base as username_base2, p.post_username, p2.post_username AS post_username2, p2.post_time FROM _forum_topics t, _members u, _forum_posts p, _forum_posts p2, _members u2 WHERE t.forum_id = ? AND t.topic_poster = u.user_id AND p.post_id = t.topic_first_post_id AND p2.post_id = t.topic_last_post_id AND u2.user_id = p2.poster_id AND t.topic_announce = 0 ORDER BY t.topic_important DESC, /*t.topic_last_post_id*/p2.post_time DESC LIMIT ??, ??'; $topics->normal = sql_rowset(sql_filter($sql, $forum_id, $start, $config['topics_per_page'])); $total->normal = (is_array($topics->normal)) ? count($topics->normal) : 0; // // Total topics ... // //$total_topics += $total_announcements; //$total_topics = $total->important + $total->normal; // // Post URL generation for templating vars // if ($is_auth['auth_post'] || $is_auth['auth_mod']) { _style('topic_create', array( 'L_POST_NEW_TOPIC' => ($forum_row['forum_locked']) ? lang('forum_locked') : lang('post_newtopic')) ); } // // Dump out the page header and load viewforum template // v_style(array( 'FORUM_ID' => $forum_id, 'FORUM_NAME' => $forum_row['forum_name'], 'U_VIEW_FORUM' => s_link('forum', $forum_row['forum_alias'])) ); // // End header // // // Let's build the topics // $i = 0; foreach ($topics as $alias => $list) { foreach ($list as $j => $row) { if (!$i) { _style('topics'); $topics_count -= $total->important; build_num_pagination(s_link('forum', $forum_row['forum_alias'], 's%d'), $topics_count, $config['topics_per_page'], $start, '', 'TOPICS_'); } if (!$j) { _style('topics.alias', array( 'NAME' => lang('topic_' . $alias), 'SHOW' => ($total->important && $total->normal > 1)) ); } $row = (object) $row; if ($row->user_id != GUEST) { $row->author = '<a href="' . s_link('m', $row->username_base2) . '">' . $row->username2 . '</a>'; } else { $row->author = '<span>*' . (($row->post_username2 != '') ? $row->post_username2 : lang('guest')) . '</span>'; } if ($row->user_id2 != GUEST) { $row->poster = '<a href="' . s_link('m', $row->username_base2) . '">' . $row->username2 . '</a>'; } else { $row->poster = '<span>*' . (($row->post_username2 != '') ? $row->post_username2 : lang('guest')) . '</span>'; } _style('topics.alias.row', array( 'FORUM_ID' => $forum_id, 'TOPIC_ID' => $row->topic_id, 'TOPIC_AUTHOR' => $row->author, 'REPLIES' => $row->topic_replies, 'VIEWS' => ($user->is('founder')) ? $row->topic_views : '', 'TOPIC_TITLE' => $row->topic_title, 'TOPIC_CREATION_TIME' => $user->format_date($row->topic_time), 'LAST_POST_TIME' => $user->format_date($row->post_time), 'LAST_POST_AUTHOR' => $row->poster, 'U_TOPIC' => s_link('topic', $row->topic_id)) ); $i++; } } if (!$topics_count) { if ($start) { redirect(s_link('forum', $forum_row['forum_alias']), true); } _style('no_topics'); } // // Posting box // if (!empty($error_msg) || (!$is_auth['auth_mod'] && $forum_row['forum_locked']) || (!$is_auth['auth_post'] && $forum_row['auth_post'] == AUTH_REG) || $is_auth['auth_post']) { if ($is_auth['auth_post']) { if (!empty($poll_options)) { $poll_options = implode(nr(), $poll_options); } _style('publish', array( 'S_POST_ACTION' => s_link('forum', $forum_row['forum_alias']), 'TOPIC_TITLE' => $post_title, 'MESSAGE' => $post_message, 'NP' => $post_np, 'POLL_TITLE' => $poll_title, 'POLL_OPTIONS' => $poll_options, 'POLL_LENGTH' => $poll_length) ); if ($is_auth['auth_pollcreate']) { _style('publish.poll'); if (empty($poll_options)) { _style('publish.poll.hide'); } } } if (!empty($error_msg)) { _style('publish.alert', array( 'MESSAGE' => $error_msg) ); } } $layout_file = 'topics'; $use_m_template = 'custom/forum_' . $forum_id; if (@file_exists(ROOT . 'template/' . $use_m_template . '.htm')) { $layout_file = $use_m_template; } $this->_title = $forum_row['forum_name']; $this->_template = $layout_file; return; }