Advertisement
Guest User

Untitled

a guest
Mar 30th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.89 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @package NV Advanced Last Topic Titles
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10.  
  11. /**
  12. * @ignore
  13. */
  14. if (!defined('IN_PHPBB'))
  15. {
  16. exit;
  17. }
  18.  
  19. /**
  20. *
  21. */
  22. class phpbb_mods_advanced_last_topic_titles
  23. {
  24. /**
  25. * Is the MOD activated in the ACP?
  26. */
  27. static public $is_active = true;
  28.  
  29. /**
  30. * Shall we ignore forum passwords and view the topic-title nevertheless?
  31. */
  32. static public $ignore_password = false;
  33.  
  34. /**
  35. * Shall we ignore the permissions and view the topic-title nevertheless?
  36. */
  37. static public $ignore_permissions = false;
  38.  
  39. /**
  40. * Display topic-title or last-post-title?
  41. */
  42. static public $use_topic_title = true;
  43.  
  44. /**
  45. * Link to topic (1), first-unread-post (2) or to the last post (0 || >2)
  46. */
  47. static public $link_url = 1;
  48.  
  49. /**
  50. * If the title is longer, we cut it down to this length. (0 means 64 and is the maximum)
  51. */
  52. static public $length_limit = 64;
  53.  
  54. /**
  55. * Initialise the MOD and populate the config values to the template.
  56. */
  57. static public function initialise()
  58. {
  59. global $config;
  60.  
  61. self::$is_active = (bool) $config['altt_active'];
  62.  
  63. if (!self::$is_active)
  64. {
  65. return;
  66. }
  67.  
  68. global $user, $template;
  69. $user->add_lang('mods/info_acp_altt');
  70.  
  71. self::$ignore_password = (bool) $config['altt_ignore_password'];
  72. self::$ignore_permissions = (bool) $config['altt_ignore_rights'];
  73. self::$use_topic_title = (bool) $config['altt_link_name'];
  74. self::$link_url = (int) $config['altt_link_url'];
  75. self::$length_limit = (($config['altt_char_limit'] <= 0) || ($config['altt_char_limit'] >= 64)) ? 64 : $config['altt_char_limit'];
  76.  
  77. $template->assign_var('S_ALTT_ACTIVE', self::$is_active);
  78.  
  79. $style_tags = array();
  80. if ($config['altt_style_bold'])
  81. {
  82. $style_tags[] = "font-weight: bold;";
  83. }
  84. if ($config['altt_style_italic'])
  85. {
  86. $style_tags[] = "font-style: italic;";
  87. }
  88. if ($config['altt_style_adv'])
  89. {
  90. $style_tags[] = $config['altt_style_adv2'];
  91. }
  92. if (!empty($style_tags))
  93. {
  94. $template->assign_var('ALTT_STYLE', implode(' ', $style_tags));
  95. }
  96. }
  97.  
  98. /**
  99. * Extend the query as we need the topic_title and some more values from the TOPICS_TABLE
  100. */
  101. static public function inject_sql($sql_array)
  102. {
  103. if (!self::$is_active)
  104. {
  105. return $sql_array;
  106. }
  107.  
  108. // Is the topics-table already left-joined for some SEO-MOD?
  109. $already_left_joined = false;
  110. foreach ($sql_array['LEFT_JOIN'] as $left_join)
  111. {
  112. if (isset($left_join['FROM'][TOPICS_TABLE]))
  113. {
  114. $already_left_joined = true;
  115. break;
  116. }
  117. }
  118.  
  119. if (!$already_left_joined)
  120. {
  121. $sql_array['LEFT_JOIN'][] = array(
  122. 'FROM' => array(TOPICS_TABLE => 't'),
  123. 'ON' => "f.forum_last_post_id = t.topic_last_post_id"
  124. );
  125. }
  126.  
  127. $altt_values = array('t.topic_title', 't.topic_id', 't.topic_moved_id', 't.topic_last_post_id');
  128. $select_values = explode(', ', $sql_array['SELECT']);
  129. $sql_array['SELECT'] = implode(', ', array_unique(array_merge($select_values, $altt_values)));
  130.  
  131. return $sql_array;
  132. }
  133.  
  134. /**
  135. * We need to "cache" the forum_id in a seperated key, so it's not overwritten.
  136. */
  137. static public function inject_forum_row($row)
  138. {
  139. if (!self::$is_active)
  140. {
  141. return $row;
  142. }
  143.  
  144. $row['nv_permission_forum_id'] = (int) $row['forum_id'];
  145. return $row;
  146. }
  147.  
  148. /**
  149. * Put the data we need into the $forum_rows which is used to loop data into the template.
  150. */
  151. static public function inject_forum_row_values($forum_rows, $parent_id, $row)
  152. {
  153. if (!self::$is_active)
  154. {
  155. return $forum_rows;
  156. }
  157.  
  158. $forum_rows[$parent_id]['topic_title'] = $row['topic_title'];
  159. $forum_rows[$parent_id]['topic_id'] = $row['topic_id'];
  160. $forum_rows[$parent_id]['nv_permission_forum_id'] = $row['forum_id'];
  161. $forum_rows[$parent_id]['forum_password'] = $row['forum_password'];
  162. return $forum_rows;
  163. }
  164.  
  165. /**
  166. * Display the data, we edit the last row which was published and add our data to it.
  167. */
  168. static public function display_information($row)
  169. {
  170. if (!self::$is_active)
  171. {
  172. return false;
  173. }
  174.  
  175. if ($row['forum_last_post_id'])
  176. {
  177. global $auth;
  178.  
  179. $password_protected = !(self::$ignore_password || !$row['forum_password']);
  180. $permissions_protected = !(self::$ignore_permissions || $auth->acl_get('f_read', $row['nv_permission_forum_id']));
  181.  
  182. if (!$password_protected && !$permissions_protected)
  183. {
  184. global $template, $phpbb_root_path, $phpEx;
  185.  
  186. $altt_link_name = (self::$use_topic_title) ? $row['topic_title'] : $row['forum_last_post_subject'];
  187. $altt_link_name = ($altt_link_name == '') ? 'Re: ' . $row['topic_title'] : $altt_link_name;
  188. $altt_link_name_short = (utf8_strlen(htmlspecialchars_decode($altt_link_name)) > self::$length_limit + 3 )? htmlspecialchars((utf8_substr(htmlspecialchars_decode($altt_link_name), 0, self::$length_limit) . '...')) : ($altt_link_name);
  189.  
  190. $real_topic_id = ($row['topic_moved_id']) ? $row['topic_moved_id'] : $row['topic_id'];
  191.  
  192. switch (self::$link_url)
  193. {
  194. case 1:
  195. $altt_link_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&amp;t=' . $real_topic_id);
  196. break;
  197. case 2:
  198. $altt_link_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&amp;t=' . $real_topic_id . '&amp;view=unread') . '#unread';
  199. break;
  200. default:
  201. $altt_link_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&amp;p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
  202. break;
  203. }
  204.  
  205. $template->alter_block_array('forumrow', array(
  206. 'ALTT_LINK_NAME_SHORT' => censor_text($altt_link_name_short),
  207. 'ALTT_LINK_NAME' => censor_text($altt_link_name),
  208. 'U_ALTT_LINK' => $altt_link_url,
  209. ), true, 'change');
  210. }
  211. }
  212. }
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement