Guest User

Untitled

a guest
Dec 15th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.61 KB | None | 0 0
  1. <?php
  2.  
  3. class wpbb_topics_widget extends WP_Widget
  4. {
  5. function wpbb_topics_widget()
  6. {
  7. /* Widget settings. */
  8. $widget_ops = array(
  9. 'classname' => 'phpBB3 Posts Widget',
  10. 'description' => __('Allows you to display a list of recent topics within a specific forum id\'s.', 'wpbb')
  11. );
  12.  
  13. /* Widget control settings. */
  14. $control_ops = array(
  15. 'width' => 250,
  16. 'height' => 250,
  17. 'id_base' => 'phpbb3-posts-widget'
  18. );
  19.  
  20. /* Create the widget. */
  21. $this->WP_Widget(
  22. 'phpbb3-posts-widget',
  23. 'WP phpBB Bridge posts',
  24. $widget_ops,
  25. $control_ops
  26. );
  27. }
  28.  
  29. function form($instance)
  30. {
  31. $defaults = array(
  32. 'wpbb_title' => __('Latest posts', 'wpbb'),
  33. 'wpbb_forums' => 0,
  34. 'wpbb_total' => '10',
  35. 'wpbb_show_forum' => 'yes',
  36. 'wpbb_show_username' => 'yes',
  37. 'wpbb_show_total_posts' => 'yes',
  38. 'wpbb_show_total_views' => 'yes'
  39. );
  40.  
  41. $instance = wp_parse_args(
  42. (array)$instance,
  43. $defaults
  44. );
  45.  
  46. ?>
  47. <div class="widget-content">
  48. <p>
  49. <label for="<?php echo $this->get_field_id('wpbb_title'); ?>">
  50. <?php
  51. echo _e('Title:', 'wpbb');
  52. ?>
  53. </label>
  54. <input class="widefat" id="<?php echo $this->get_field_id('wpbb_title'); ?>" name="<?php echo $this->get_field_name('wpbb_title'); ?>" type="text" value="<?php echo $instance['wpbb_title']; ?>" />
  55. </p>
  56. <p>
  57. <label for="<?php echo $this->get_field_id('wpbb_forums'); ?>">
  58. <?php echo _e('Forums:', 'wpbb'); ?>
  59. </label>
  60. <input class="widefat" name="<?php echo $this->get_field_name('wpbb_forums'); ?>" type="text" id="<?php echo $this->get_field_id('wpbb_forums'); ?>" value="<?php echo $instance['wpbb_forums']; ?>" />
  61. <small><?php _e('Enter the id of the forum you like to get topics from. You can get topics from more than one forums by seperating the forums id with commas. ex: 3,5,6,12','wpbb'); ?></small>
  62. </p>
  63. <p>
  64. <label for="<?php echo $this->get_field_id('wpbb_total'); ?>">
  65. <?php
  66. echo _e('Total posts:', 'wpbb');
  67. ?>
  68. </label>
  69. <input class="widefat" name="<?php echo $this->get_field_name('wpbb_total'); ?>" type="text" id="<?php echo $this->get_field_id('wpbb_total'); ?>" value="<?php echo $instance['wpbb_total']; ?>" />
  70. </p>
  71. <p>
  72. <label>
  73. <input name="<?php echo $this->get_field_name('wpbb_show_forum'); ?>" type="checkbox" id="<?php echo $this->get_field_id('wpbb_show_forum'); ?>" value="yes" <?php if ($instance['wpbb_show_forum'] == "yes") { echo 'checked="checked" '; } ?> />&nbsp;
  74. <?php
  75. echo _e('Display forum name', 'wpbb');
  76. ?>
  77. </label>
  78. </p>
  79. <p>
  80. <label>
  81. <input name="<?php echo $this->get_field_name('wpbb_show_username'); ?>" type="checkbox" id="<?php echo $this->get_field_id('wpbb_show_username'); ?>" value="yes" <?php if($instance['wpbb_show_username'] == "yes") { echo 'checked="checked" '; } ?> />&nbsp;
  82. <?php
  83. echo _e('Display author name', 'wpbb');
  84. ?>
  85. </label>
  86. </p>
  87. <p>
  88. <label>
  89. <input name="<?php echo $this->get_field_name('wpbb_show_total_posts'); ?>" type="checkbox" id="<?php echo $this->get_field_id('wpbb_show_total_posts'); ?>" value="yes" <?php if ($instance['wpbb_show_total_posts'] == "yes") { echo 'checked="checked" '; } ?> />&nbsp;
  90. <?php
  91. echo _e('Display total replies', 'wpbb');
  92. ?>
  93. </label>
  94. </p>
  95. <p>
  96. <label>
  97. <input name="<?php echo $this->get_field_name('wpbb_show_total_views'); ?>" type="checkbox" id="<?php echo $this->get_field_id('wpbb_show_total_views'); ?>" value="yes" <?php if ($instance['wpbb_show_total_views'] == "yes") { echo 'checked="checked" '; } ?> />&nbsp;
  98. <?php
  99. echo _e('Display total views', 'wpbb');
  100. ?>
  101. </label>
  102. </p>
  103. </div>
  104. <?php
  105. }
  106.  
  107. function update($new_instance, $old_instance)
  108. {
  109. $instance = $old_instance;
  110.  
  111. $instance['wpbb_title'] = $new_instance['wpbb_title'];
  112. $instance['wpbb_forums'] = $new_instance['wpbb_forums'];
  113. $instance['wpbb_total'] = $new_instance['wpbb_total'];
  114. $instance['wpbb_show_forum'] = $new_instance['wpbb_show_forum'];
  115. $instance['wpbb_show_username'] = $new_instance['wpbb_show_username'];
  116. $instance['wpbb_show_total_posts'] = $new_instance['wpbb_show_total_posts'];
  117. $instance['wpbb_show_total_views'] = $new_instance['wpbb_show_total_views'];
  118.  
  119. return $instance;
  120. }
  121.  
  122. function widget($args, $instance)
  123. {
  124. global $wpdb, $phpbb_root_path, $phpEx, $auth, $user, $db, $config, $cache, $template;
  125.  
  126. extract($args);
  127.  
  128. $title = $instance['wpbb_title'];
  129. $forums = $instance['wpbb_forums'];
  130. $total = $instance['wpbb_total'];
  131. $showForum = $instance['wpbb_show_forum'];
  132. $showUsername = $instance['wpbb_show_username'];
  133. $showTotalPosts = $instance['wpbb_show_total_posts'];
  134. $showTotalViews = $instance['wpbb_show_total_views'];
  135.  
  136. echo $before_widget . $before_title . $title . $after_title;
  137.  
  138. $phpbb_config = trim(get_option('wpbb_config_path'));
  139. $phpEx = substr(strrchr($phpbb_config, '.'), 1);
  140. $forum_url = str_replace("/ucp.php", "/", trim(get_option('wpbb_ucp_path')));
  141.  
  142. require($phpbb_config);
  143.  
  144. // TODO : Next Version, to get connected with phpBB $db object in order to retrive the
  145. // forum posts. Also to remove the database encoding from plugin options
  146.  
  147. $cn = mysql_pconnect($dbhost . ":" . $dbport, $dbuser, $dbpasswd);
  148.  
  149. mysql_set_charset(get_option('wpbb_dbms_charset'), $cn);
  150.  
  151. if($cn)
  152. {
  153. if(@mysql_select_db($dbname))
  154. {
  155. $qr = "SELECT p.`topic_id` AS `ID`, p2.`forum_name` AS `FORUM`, p.`forum_id` AS `FORUM_ID`, p.`topic_title` AS `TITLE`, p.`topic_views` AS `VIEWS`, p.`topic_replies` AS `REPLIES`, `username_clean` AS `USERNAME`, p.`topic_poster` AS `USER_ID`, p.`topic_time` AS `TIME`
  156. FROM " . $table_prefix . "topics p
  157. LEFT JOIN " . $table_prefix . "forums p2 ON(p.`forum_id` = p2.`forum_id`)
  158. LEFT JOIN " . $table_prefix . "users p3 ON(p.`topic_poster` = p3.`user_id`)
  159. WHERE p.`forum_id` IN (" . $forums . ") ORDER BY p.`topic_last_post_time` DESC LIMIT " . $total;
  160.  
  161. $rs = mysql_query($qr, $cn);
  162.  
  163. }
  164. }
  165.  
  166. if($rs)
  167. {
  168. ?>
  169. <ul>
  170. <?php
  171. while($get_info = mysql_fetch_assoc($rs))
  172. {
  173. ?>
  174. <li>
  175. <a rel="nofollow" href="<?php echo $forum_url; ?>viewtopic.php?f=<?php echo $get_info['FORUM_ID'] ?>&t=<?php echo $get_info['ID']; ?>" title="<?php echo __('View post','wpbb'); ?>">
  176. <?php echo $get_info['TITLE']; ?>
  177. </a>
  178. <br />
  179. <?php
  180. if($showForum == 'yes')
  181. {
  182. ?>
  183. <small>
  184. <?php
  185. echo __('Forum:', 'wpbb');
  186. ?>
  187. <a rel="nofollow" href="<?php echo $forum_url; ?>viewforum.php?f=<?php echo $get_info['FORUM_ID']; ?>" title="<?php echo __('Go to forum', 'wpbb'); ?>">
  188. <?php
  189. echo $get_info['FORUM'];
  190. ?>
  191. </a>
  192. </small>
  193. <br />
  194. <?php
  195. }
  196.  
  197. if($showUsername == 'yes')
  198. {
  199. ?>
  200. <small>
  201. <?php
  202. echo __('By:', 'wpbb');
  203. ?>
  204. <a rel="nofollow" href="<?php echo $forum_url; ?>memberlist.php?mode=viewprofile&u=<?php echo $get_info['USER_ID']; ?>" title="<?php echo __('View user info', 'wpbb'); ?>">
  205. <?php
  206. echo $get_info['USERNAME'];
  207. ?>
  208. </a>
  209. </small>
  210. <br />
  211. <?php
  212. }
  213.  
  214. if($showTotalViews == 'yes')
  215. {
  216. ?>
  217. <small>
  218. <?php
  219. _e('Views:', 'wpbb');
  220. ?>
  221. <strong>
  222. <?php
  223. echo $get_info['VIEWS'];
  224. ?>
  225. </strong>
  226. </small>
  227. <?php
  228. }
  229.  
  230. if($showTotalViews == 'yes' && $showTotalPosts == 'yes')
  231. {
  232. echo "<small>&nbsp;|&nbsp;</small>";
  233. }
  234.  
  235. if($showTotalPosts == 'yes')
  236. {
  237. ?>
  238. <small>
  239. <?php
  240. _e('Replies:', 'wpbb');
  241. ?>
  242. <strong>
  243. <?php
  244. echo $get_info['REPLIES'];
  245. ?>
  246. </strong>
  247. </small>
  248. <?php
  249. }
  250. ?>
  251. </li>
  252. <?php
  253. }
  254. ?>
  255. </ul>
  256. <?php
  257. }
  258.  
  259. echo $after_widget;
  260. }
  261. }
  262.  
  263. ?>
Add Comment
Please, Sign In to add comment