PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/tags.php

https://github.com/MightyGorgon/icy_phoenix
PHP | 317 lines | 234 code | 54 blank | 29 comment | 35 complexity | 2fcd63e52e20becbdfd2f6d64d338f02 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. define('IN_ICYPHOENIX', true);
  11. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  12. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  13. include(IP_ROOT_PATH . 'common.' . PHP_EXT);
  14. // Start session management
  15. $user->session_begin();
  16. $auth->acl($user->data);
  17. $user->setup();
  18. // End session management
  19. $config['jquery_ui'] = true;
  20. // CMS - BEGIN
  21. $cms_page['page_id'] = 'tags';
  22. $cms_page['page_nav'] = (isset($cms_config_layouts[$cms_page['page_id']]['page_nav']) ? $cms_config_layouts[$cms_page['page_id']]['page_nav'] : true);
  23. $cms_page['global_blocks'] = (!empty($cms_config_layouts[$cms_page['page_id']]['global_blocks']) ? true : false);
  24. $cms_auth_level = (isset($cms_config_layouts[$cms_page['page_id']]['view']) ? $cms_config_layouts[$cms_page['page_id']]['view'] : AUTH_ALL);
  25. check_page_auth($cms_page['page_id'], $cms_auth_level);
  26. // CMS - END
  27. // COMMON - BEGIN
  28. @include_once(IP_ROOT_PATH . 'includes/class_form.' . PHP_EXT);
  29. $class_form = new class_form();
  30. @include_once(IP_ROOT_PATH . 'includes/class_topics.' . PHP_EXT);
  31. $class_topics = new class_topics();
  32. @include_once(IP_ROOT_PATH . 'includes/class_topics_tags.' . PHP_EXT);
  33. $class_topics_tags = new class_topics_tags();
  34. // COMMON - END
  35. // CONFIG - BEGIN
  36. $table_fields = array(
  37. 'tag_count' => array('lang_key' => 'TAG_COUNT', 'view_level' => AUTH_ALL),
  38. 'tag_text' => array('lang_key' => 'TAG_TEXT', 'view_level' => AUTH_ALL),
  39. );
  40. // CONFIG - END
  41. // VARS - BEGIN
  42. $tag_id = request_var('tag_id', 0);
  43. $tag_id = ($tag_id < 0) ? 0 : $tag_id;
  44. $tag_text = request_var('tag_text', '', true);
  45. $tag_text = ip_clean_string(urldecode(trim($tag_text)), $lang['ENCODING'], true);
  46. $mode_types = array('cloud', 'list', 'view', 'replace');
  47. $mode = request_var('mode', $mode_types[0]);
  48. $mode = check_var_value($mode, $mode_types);
  49. $action_types = array('list');
  50. $action = request_var('action', $action_types[0]);
  51. $action = check_var_value($action, $action_types);
  52. $start = request_var('start', 0);
  53. $start = ($start < 0) ? 0 : $start;
  54. $per_page = request_var('per_page', 0);
  55. $per_page = (empty($per_page) || ($per_page < 20) || ($per_page > 300)) ? $config['topics_per_page'] : $per_page;
  56. $s_hidden_fields = '';
  57. // SORT ORDER - BEGIN
  58. $sort_order_array = array();
  59. $sort_order_select_array = array();
  60. $sort_order_select_lang_array = array();
  61. foreach ($table_fields as $k => $v)
  62. {
  63. $is_auth = (check_auth_level($v['view_level']));
  64. if ($is_auth)
  65. {
  66. $sort_order_array[] = $k;
  67. $sort_order_select_array[] = $k;
  68. $sort_order_select_lang_array[] = $class_form->get_lang($v['lang_key']);
  69. }
  70. }
  71. $sort_order_default = ((isset($sort_order_default) && in_array($sort_order_default, $sort_order_array)) ? $sort_order_default : $sort_order_array[0]);
  72. $sort_order = request_var('sort_order', $sort_order_default);
  73. $sort_order = (in_array($sort_order, $sort_order_array) ? $sort_order : $sort_order_array[0]);
  74. $select_name = 'sort_order';
  75. $default = $sort_order;
  76. $select_js = '';
  77. $sort_order_select_box = $class_form->build_select_box($select_name, $default, $sort_order_select_array, $sort_order_select_lang_array, $select_js);
  78. // SORT ORDER - END
  79. // SORT DIR - BEGIN
  80. $sort_dir_default = ((isset($sort_dir_default) && in_array($sort_dir_default, array('ASC', 'DESC'))) ? $sort_dir_default : 'DESC');
  81. $sort_dir = request_var('sort_dir', $sort_dir_default);
  82. $sort_dir = ($sort_dir == 'ASC') ? 'ASC' : 'DESC';
  83. $sort_dir_select_array = array('ASC', 'DESC');
  84. $sort_dir_select_lang_array = array($lang['Sort_Ascending'], $lang['Sort_Descending']);
  85. $select_name = 'sort_dir';
  86. $default = $sort_dir;
  87. $select_js = '';
  88. $sort_dir_select_box = $class_form->build_select_box($select_name, $default, $sort_dir_select_array, $sort_dir_select_lang_array, $select_js);
  89. // SORT DIR - END
  90. // VARS - END
  91. if ($mode == 'view')
  92. {
  93. if (empty($tag_text))
  94. {
  95. $msg_title = $lang['TOPIC_TAGS'];
  96. trigger_error('TAGS_NO_TAG', E_USER_NOTICE);
  97. }
  98. $breadcrumbs['bottom_right_links'] .= (($breadcrumbs['bottom_right_links'] != '') ? ('&nbsp;' . MENU_SEP_CHAR . '&nbsp;') : '') . '<a href="' . append_sid(CMS_PAGE_TAGS) . '">' . $lang['TOPIC_TAGS'] . '</a>';
  99. $breadcrumbs['bottom_right_links'] .= (($user->data['user_level'] == ADMIN) ? ('&nbsp;' . MENU_SEP_CHAR . '&nbsp;') . '<a href="' . append_sid(CMS_PAGE_TAGS . '?mode=replace') . '">' . $lang['TOPIC_TAGS_REPLACE'] . '</a>' : '');
  100. $template_to_parse = 'tags_view_body.tpl';
  101. $tags = array($tag_text);
  102. $topics = $class_topics_tags->get_topics_with_tags($tags, $start, $per_page);
  103. $num_items = 0;
  104. $tags_counters = $class_topics_tags->get_tags_counters($tags);
  105. foreach ($tags_counters as $tag_counter)
  106. {
  107. if ($tag_counter['tag_text'] == $tag_text)
  108. {
  109. $num_items = $tag_counter['tag_count'];
  110. break;
  111. }
  112. }
  113. $topic_length = 60;
  114. // UPI2DB - BEGIN
  115. if($user->data['upi2db_access'])
  116. {
  117. if (!defined('UPI2DB_UNREAD'))
  118. {
  119. $user->data['upi2db_unread'] = upi2db_unread();
  120. }
  121. $count_new_posts = sizeof($user->data['upi2db_unread']['new_posts']);
  122. $count_edit_posts = sizeof($user->data['upi2db_unread']['edit_posts']);
  123. $count_always_read = sizeof($user->data['upi2db_unread']['always_read']['topics']);
  124. $count_mark_unread = sizeof($user->data['upi2db_unread']['mark_posts']);
  125. }
  126. // UPI2DB - END
  127. // MG User Replied - BEGIN
  128. // check if user replied to the topic
  129. define('USER_REPLIED_ICON', true);
  130. $user_topics = $class_topics->user_replied_array($topics);
  131. // MG User Replied - END
  132. $i = 0;
  133. foreach ($topics as $topic)
  134. {
  135. $class = ($i % 2) ? $theme['td_class1'] : $theme['td_class2'];
  136. $forum_id = $topic['forum_id'];
  137. $topic_id = $topic['topic_id'];
  138. $forum_id_append = (!empty($forum_id) ? (POST_FORUM_URL . '=' . $forum_id) : '');
  139. $topic_id_append = (!empty($topic_id) ? (POST_TOPIC_URL . '=' . $topic_id) : '');
  140. $forum_url = append_sid(CMS_PAGE_VIEWFORUM . '?' . $forum_id_append);
  141. $topic_url = append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&amp;' . $topic_id_append);
  142. $views = $topic['topic_views'];
  143. $replies = $topic['topic_replies'];
  144. $user_replied = (!empty($user_topics) && isset($user_topics[$topic_id]));
  145. //$news_label = ($line[$i]['news_id'] > 0) ? $lang['News_Cmx'] . '' : '';
  146. $news_label = '';
  147. $topic_title_data = $class_topics->generate_topic_title($topic_id, $topic, $topic_length);
  148. $topic_title = $topic_title_data['title'];
  149. $topic_title_clean = $topic_title_data['title_clean'];
  150. $topic_title_plain = $topic_title_data['title_plain'];
  151. $topic_title_label = $topic_title_data['title_label'];
  152. $topic_title_short = $topic_title_data['title_short'];
  153. $topic_link = $class_topics->build_topic_icon_link($forum_id, $topic['topic_id'], $topic['topic_type'], $topic['topic_reg'], $topic['topic_replies'], $topic['news_id'], $topic['poll_start'], $topic['topic_status'], $topic['topic_moved_id'], $topic['post_time'], $user_replied, $replies);
  154. $topic_id = $topic_link['topic_id'];
  155. $topic_id_append = $topic_link['topic_id_append'];
  156. $topic_pagination = generate_topic_pagination($forum_id, $topic_id, $replies);
  157. $first_time = create_date_ip($lang['DATE_FORMAT_VF'], $topic['topic_time'], $config['board_timezone'], true);
  158. $first_author = ($topic['first_poster_id'] != ANONYMOUS) ? colorize_username($topic['topic_first_poster_id'], $topic['topic_first_poster_name'], $topic['topic_first_poster_color'], 1) : (($topic['topic_first_poster_name'] != '') ? $topic['topic_first_poster_name'] : $lang['Guest']);
  159. $last_time = create_date_ip($config['default_dateformat'], $topic['topic_last_post_time'], $config['board_timezone']);
  160. $last_author = ($topic['topic_last_poster_id'] != ANONYMOUS) ? colorize_username($topic['topic_last_poster_id'], $topic['topic_last_poster_name'], $topic['topic_last_poster_color'], 1) : (($topic['topic_last_poster_name'] != '') ? $topic['topic_last_poster_name'] : $lang['Guest']);
  161. $last_url = '<a href="' . append_sid(CMS_PAGE_VIEWTOPIC . '?' . $forum_id_append . '&amp;' . $topic_id_append . '&amp;' . POST_POST_URL . '=' . $topic['topic_last_post_id']) . '#p' . $topic['topic_last_post_id'] . '"><img src="' . $images['icon_latest_reply'] . '" alt="' . $lang['View_latest_post'] . '" title="' . $lang['View_latest_post'] . '" /></a>';
  162. $topic_tags_links = $class_topics_tags->build_tags_list_single_topic($topic['topic_tags']);
  163. $template->assign_block_vars('row', array(
  164. 'CLASS' => $class,
  165. 'ROW_NUMBER' => $i + 1,
  166. 'TOPIC_ID' => $topic_id,
  167. 'TOPIC_FOLDER_IMG' => $topic_link['image'],
  168. 'L_TOPIC_FOLDER_ALT' => $topic_link['image_alt'],
  169. 'TOPIC_TITLE' => $topic_title,
  170. 'TOPIC_TITLE_PLAIN' => $topic_title_plain,
  171. 'TOPIC_TYPE' => $topic_link['type'],
  172. 'TOPIC_TYPE_ICON' => $topic_link['icon'],
  173. 'TOPIC_CLASS' => (!empty($topic_link['class_new']) ? ('topiclink' . $topic_link['class_new']) : $topic_link['class']),
  174. 'CLASS_NEW' => $topic_link['class_new'],
  175. 'NEWEST_POST_IMG' => $topic_link['newest_post_img'],
  176. 'L_NEWS' => $news_label,
  177. 'GOTO_PAGE' => $topic_pagination['base'],
  178. 'GOTO_PAGE_FULL' => $topic_pagination['full'],
  179. 'VIEWS' => $views,
  180. 'TOPIC_TAGS' => $topic_tags_links,
  181. 'REPLIES' => $replies,
  182. //'FIRST_POST_TIME' => sprintf($lang['Recent_first'], $first_time),
  183. 'FIRST_POST_TIME' => $first_time,
  184. 'FIRST_AUTHOR' => $first_author,
  185. 'LAST_POST_TIME' => $last_time,
  186. 'LAST_AUTHOR' => $last_author,
  187. 'LAST_URL' => $last_url,
  188. 'FORUM_NAME' => $topic['forum_name'],
  189. 'U_VIEW_FORUM' => $forum_url,
  190. 'U_VIEW_TOPIC' => $topic_url,
  191. )
  192. );
  193. $i++;
  194. }
  195. $template->assign_vars(array(
  196. 'L_VIEWS' => $lang['Views'],
  197. 'L_LASTPOST' => $lang['Last_Post'],
  198. 'L_REPLIES' => $lang['Replies'],
  199. 'L_TAG_RESULTS' => sprintf($lang['TAG_RESULTS'], htmlspecialchars($tag_text) . ' (' . $num_items . ')'),
  200. 'U_TAG_RESULTS' => append_sid(CMS_PAGE_TAGS . '?mode=view&amp;tag_text=' . htmlspecialchars(urlencode($tag_text))),
  201. )
  202. );
  203. }
  204. elseif ($mode == 'replace')
  205. {
  206. if ($user->data['user_level'] != ADMIN)
  207. {
  208. message_die(GENERAL_MESSAGE, $lang['Not_Authorized']);
  209. }
  210. $template_to_parse = 'tags_replace_body.tpl';
  211. $breadcrumbs['bottom_right_links'] .= (($breadcrumbs['bottom_right_links'] != '') ? ('&nbsp;' . MENU_SEP_CHAR . '&nbsp;') : '') . '<a href="' . append_sid(CMS_PAGE_TAGS) . '">' . $lang['TOPIC_TAGS'] . '</a>';
  212. $breadcrumbs['bottom_right_links'] .= (($user->data['user_level'] == ADMIN) ? ('&nbsp;' . MENU_SEP_CHAR . '&nbsp;') : '') . '<a href="' . append_sid(CMS_PAGE_TAGS . '?mode=replace') . '">' . $lang['TOPIC_TAGS_REPLACE'] . '</a>';
  213. $search_replace_submit = false;
  214. if (isset($_POST['submit']))
  215. {
  216. $search_replace_submit = true;
  217. $tag_old = request_var('tag_old', '', true);
  218. $tag_new = request_var('tag_new', '', true);
  219. $topics_data = $class_topics_tags->replace_tag($tag_old, $tag_new);
  220. message_die(GENERAL_MESSAGE, sprintf($lang['TAGS_SEARCH_REPLACE_RESULT'], sizeof($topics_data)));
  221. }
  222. }
  223. else
  224. {
  225. $template_to_parse = 'tags_list_body.tpl';
  226. $breadcrumbs['bottom_right_links'] .= (($breadcrumbs['bottom_right_links'] != '') ? ('&nbsp;' . MENU_SEP_CHAR . '&nbsp;') : '') . '<a href="' . append_sid(CMS_PAGE_TAGS . '?mode=' . (($mode == 'cloud') ? 'list' : 'cloud')) . '">' . (($mode == 'cloud') ? $lang['TOPIC_TAGS_LIST'] : $lang['TOPIC_TAGS_CLOUDS']) . '</a>';
  227. $breadcrumbs['bottom_right_links'] .= (($user->data['user_level'] == ADMIN) ? ('&nbsp;' . MENU_SEP_CHAR . '&nbsp;') : '') . '<a href="' . append_sid(CMS_PAGE_TAGS . '?mode=replace') . '">' . $lang['TOPIC_TAGS_REPLACE'] . '</a>';
  228. $per_page = ($mode == 'cloud') ? $config['word_graph_max_words'] : $per_page;
  229. $num_items = $class_topics_tags->get_total_tags();
  230. $tags = $class_topics_tags->get_tags($sort_order, $sort_dir, $start, $per_page);
  231. $row_class = '';
  232. $i = 0;
  233. foreach ($tags as $tag)
  234. {
  235. $row_class = ip_zebra_rows($row_class);
  236. $tag_font_size = intval(mt_rand(8, 14));
  237. $template->assign_block_vars('row', array(
  238. 'CLASS' => $row_class,
  239. 'ROW_NUMBER' => $i + 1,
  240. 'U_TAG_TEXT' => append_sid(CMS_PAGE_TAGS . '?mode=view&amp;tag_text=' . htmlspecialchars(urlencode($tag['tag_text']))),
  241. 'TAG_TEXT' => htmlspecialchars($tag['tag_text']),
  242. 'TAG_FONT_SIZE' => $tag_font_size,
  243. 'TAG_COUNT' => $tag['tag_count'],
  244. )
  245. );
  246. $i++;
  247. }
  248. }
  249. $template->assign_vars(array(
  250. 'S_SHOW_CLOUD' => ($mode == 'cloud') ? true : false,
  251. 'S_FORM_ACTION' => append_sid(CMS_PAGE_TAGS),
  252. 'S_HIDDEN_FIELDS' => $s_hidden_fields,
  253. 'S_SORT_ORDER_SELECT' => $sort_order_select_box,
  254. 'S_SORT_DIR_SELECT' => $sort_dir_select_box,
  255. 'U_TAGS_SEARCH_PAGE' => append_sid(CMS_PAGE_TAGS),
  256. 'U_TAGS_SEARCH_REPLACE' => append_sid(CMS_PAGE_TAGS . '?mode=replace'),
  257. 'U_TAGS' => append_sid(CMS_PAGE_TAGS),
  258. )
  259. );
  260. $pagination_append = ($mode == 'list') ? ('&amp;sort_order=' . $sort_order . '&amp;sort_dir=' . $sort_dir) : ('&amp;tag_text=' . $tag_text);
  261. generate_full_pagination(CMS_PAGE_TAGS . '?mode=' . $mode . $pagination_append, $num_items, $per_page, $start);
  262. full_page_generation($template_to_parse, $lang['TOPIC_TAGS'], '', '');
  263. ?>