PageRenderTime 35ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/misc/modules/includes/ucp/ucp_titania.php

http://github.com/phpbb/customisation-db
PHP | 448 lines | 336 code | 76 blank | 36 comment | 43 complexity | eb9082910f1d0494249f9539f06dd81f MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Titania
  5. * @copyright (c) 2008 phpBB Customisation Database Team
  6. * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2
  7. *
  8. */
  9. global $phpbb_root_path;
  10. /**
  11. * Configuration needed!
  12. *
  13. * Set the titania root path here
  14. */
  15. define('TITANIA_ROOT', $phpbb_root_path . '../customise/db/');
  16. /**
  17. * @ignore
  18. */
  19. if (!defined('IN_PHPBB'))
  20. {
  21. exit;
  22. }
  23. /**
  24. * ucp_titania
  25. * Handling the titania stuff (proxy for some stuff in titania/manage/
  26. */
  27. class ucp_titania
  28. {
  29. var $u_action;
  30. var $p_master;
  31. function ucp_titania(&$p_master)
  32. {
  33. $this->p_master = &$p_master;
  34. }
  35. function main($id, $mode)
  36. {
  37. global $phpbb_root_path;
  38. define('PHPBB_INCLUDED', true);
  39. define('USE_PHPBB_TEMPLATE', true);
  40. define('IN_TITANIA', true);
  41. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  42. require TITANIA_ROOT . 'common.' . PHP_EXT;
  43. // Need a few hacks to be used from within phpBB
  44. titania_url::decode_url(titania::$config->phpbb_script_path);
  45. titania::$hook->register(array('titania_url', 'build_url'), 'titania_outside_build_url', 'standalone');
  46. titania::$hook->register(array('titania_url', 'append_url'), 'titania_outside_build_url', 'standalone');
  47. titania::$hook->register(array('titania', 'page_header'), 'titania_outside_page_header', 'standalone');
  48. titania::$hook->register(array('titania', 'page_footer'), 'titania_outside_page_footer', 'standalone');
  49. $this->p_master->assign_tpl_vars(phpbb::append_sid('ucp'));
  50. // Include some files
  51. titania::_include('functions_display', 'titania_topic_folder_img');
  52. // Setup the sort tool
  53. $sort = new titania_sort();
  54. $sort->default_limit = phpbb::$config['topics_per_page'];
  55. $sort->request();
  56. // Start initial var setup
  57. $url = $this->u_action;
  58. add_form_key('ucp_front_subscription');
  59. // User wants to unsubscribe?
  60. if (isset($_POST['unsubscribe']))
  61. {
  62. if (check_form_key('ucp_front_subscription'))
  63. {
  64. $sections = request_var('sections', array(0 => array(0 => 0)));
  65. $items = request_var('items', array(0 => array(0 => 0)));
  66. $subscriptions = $sections + $items;
  67. if (sizeof($subscriptions))
  68. {
  69. foreach($subscriptions as $type => $type_id)
  70. {
  71. $object_ids = array_keys($type_id);
  72. foreach($object_ids as $object_id)
  73. {
  74. $sql = 'DELETE FROM ' . TITANIA_WATCH_TABLE . '
  75. WHERE watch_user_id = ' . phpbb::$user->data['user_id'] . '
  76. AND watch_object_type = ' . $type . '
  77. AND watch_object_id = ' . $object_id;
  78. phpbb::$db->sql_query($sql);
  79. }
  80. }
  81. }
  82. else
  83. {
  84. $msg = phpbb::$user->lang['NO_SUBSCRIPTIONS_SELECTED'];
  85. }
  86. }
  87. else
  88. {
  89. $msg = phpbb::$user->lang['FORM_INVALID'];
  90. }
  91. if (isset($msg))
  92. {
  93. meta_refresh(3, $url);
  94. $message = $msg . '<br /><br />' . sprintf(phpbb::$user->lang['RETURN_UCP'], '<a href="' . $url . '">', '</a>');
  95. trigger_error($message);
  96. }
  97. }
  98. switch($mode)
  99. {
  100. case 'subscription_items':
  101. $array_items = array(TITANIA_CONTRIB, TITANIA_TOPIC);
  102. // We prepare pagination stuff
  103. $sql = 'SELECT COUNT(*) AS subscription_count
  104. FROM ' . TITANIA_WATCH_TABLE . '
  105. WHERE ' . phpbb::$db->sql_in_set('watch_object_type', $array_items) . '
  106. AND watch_user_id = ' . phpbb::$user->data['user_id'];
  107. phpbb::$db->sql_query($sql);
  108. $subscription_count = phpbb::$db->sql_fetchfield('subscription_count');
  109. phpbb::$db->sql_freeresult();
  110. $sort->total = $subscription_count;
  111. $sort->build_pagination($url);
  112. $sql_ary = array(
  113. 'SELECT' => '*,
  114. CASE w.watch_object_type
  115. WHEN ' . TITANIA_CONTRIB . ' THEN c.contrib_last_update
  116. WHEN ' . TITANIA_TOPIC . ' THEN t.topic_last_post_time
  117. END AS time',
  118. 'FROM' => array(
  119. TITANIA_WATCH_TABLE => 'w',
  120. ),
  121. 'LEFT_JOIN' => array(
  122. array(
  123. 'FROM' => array(TITANIA_CONTRIBS_TABLE => 'c'),
  124. 'ON' => '(w.watch_object_type = ' . TITANIA_CONTRIB. ')
  125. AND c.contrib_id = w.watch_object_id',
  126. ),
  127. array(
  128. 'FROM' => array(TITANIA_TOPICS_TABLE => 't'),
  129. 'ON' => 'w.watch_object_type = ' . TITANIA_TOPIC. '
  130. AND t.topic_id = w.watch_object_id',
  131. ),
  132. ),
  133. 'WHERE' => 'w.watch_user_id = ' . phpbb::$user->data['user_id'] . '
  134. AND ' . phpbb::$db->sql_in_set('watch_object_type', $array_items),
  135. 'ORDER_BY' => 'time DESC',
  136. );
  137. // Additional tracking for support topics
  138. titania_tracking::get_track_sql($sql_ary, TITANIA_TOPIC, 't.topic_id');
  139. titania_tracking::get_track_sql($sql_ary, TITANIA_SUPPORT, 0, 'tsa');
  140. titania_tracking::get_track_sql($sql_ary, TITANIA_SUPPORT, 't.parent_id', 'tsc');
  141. titania_tracking::get_track_sql($sql_ary, TITANIA_QUEUE_DISCUSSION, 0, 'tqt');
  142. // Tracking for contributions
  143. titania_tracking::get_track_sql($sql_ary, TITANIA_CONTRIB, 'c.contrib_id', 'tc');
  144. $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary);
  145. // Get the data
  146. $result = phpbb::$db->sql_query_limit($sql, $sort->limit, $sort->start);
  147. $user_ids = $rows = array();
  148. while ($row = phpbb::$db->sql_fetchrow($result))
  149. {
  150. $rows[] = $row;
  151. titania_tracking::store_from_db($row);
  152. if ($row['watch_object_type'] == TITANIA_TOPIC)
  153. {
  154. $user_ids[] = $row['topic_first_post_user_id'];
  155. $user_ids[] = $row['topic_last_post_user_id'];
  156. }
  157. else if ($row['watch_object_type'] == TITANIA_CONTRIB)
  158. {
  159. $user_ids[] = $row['contrib_user_id'];
  160. }
  161. }
  162. phpbb::$db->sql_freeresult($result);
  163. // Get user data
  164. users_overlord::load_users($user_ids);
  165. foreach ($rows as $row)
  166. {
  167. $folder_img = $folder_alt = '';
  168. if ($row['watch_object_type'] == TITANIA_TOPIC)
  169. {
  170. if (!$row['topic_id'])
  171. {
  172. // Topic was deleted
  173. $sql = 'DELETE FROM ' . TITANIA_WATCH_TABLE . '
  174. WHERE watch_object_type = ' . (int) $row['watch_object_type'] . '
  175. AND watch_object_id = ' . (int) $row['watch_object_id'];
  176. phpbb::$db->sql_query($sql);
  177. continue;
  178. }
  179. $topic = new titania_topic;
  180. $topic->__set_array($row);
  181. $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'id' => 0);
  182. $topic->additional_unread_fields[] = array('type' => TITANIA_SUPPORT, 'parent_match' => true);
  183. $topic->additional_unread_fields[] = array('type' => TITANIA_QUEUE_DISCUSSION, 'id' => 0, 'type_match' => true);
  184. $tpl_block = 'items';
  185. $subscription_target = '';
  186. if ($row['topic_type'] == TITANIA_QUEUE_DISCUSSION)
  187. {
  188. $subscription_target = phpbb::$user->lang['SUBSCRIPTION_QUEUE_VALIDATION'];
  189. }
  190. if ($row['topic_type'] == TITANIA_QUEUE)
  191. {
  192. $subscription_target = phpbb::$user->lang['SUBSCRIPTION_QUEUE'];
  193. }
  194. if ($row['topic_type'] == TITANIA_SUPPORT)
  195. {
  196. $subscription_target = phpbb::$user->lang['SUBSCRIPTION_SUPPORT_TOPIC'];
  197. }
  198. // Tracking check
  199. $last_read_mark = titania_tracking::get_track(TITANIA_TOPIC, $topic->topic_id, true);
  200. $last_read_mark = max($last_read_mark, titania_tracking::find_last_read_mark($topic->additional_unread_fields, $topic->topic_type, $topic->parent_id));
  201. $topic->unread = ($topic->topic_last_post_time > $last_read_mark) ? true : false;
  202. // Get the folder image
  203. $topic->topic_folder_img($folder_img, $folder_alt);
  204. $vars = array(
  205. 'LAST_POST_IMG' => phpbb::$user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
  206. 'SUBSCRIPTION_AUTHOR_FULL' => users_overlord::get_user($row['topic_first_post_user_id'], '_full'),
  207. 'SUBSCRIPTION_ID' => $row['topic_id'],
  208. 'SUBSCRIPTION_LAST_AUTHOR_FULL' => users_overlord::get_user($row['topic_last_post_user_id'], '_full'),
  209. 'SUBSCRIPTION_LAST_TIME' => phpbb::$user->format_date($row['topic_last_post_time']),
  210. 'SUBSCRIPTION_TIME' => phpbb::$user->format_date($row['topic_time']),
  211. 'SUBSCRIPTION_TARGET' => $subscription_target,
  212. 'SUBSCRIPTION_TITLE' => censor_text($row['topic_subject']),
  213. 'SUBSCRIPTION_TYPE' => $row['watch_object_type'],
  214. 'U_VIEW_SUBSCRIPTION' => $topic->get_url(),
  215. 'U_VIEW_LAST_POST' => titania_url::append_url($topic->get_url(), array('p' => $topic->topic_last_post_id, '#p' => $topic->topic_last_post_id)),
  216. 'S_ACCESS_TEAMS' => ($row['topic_access'] == TITANIA_ACCESS_TEAMS || $row['topic_type'] == TITANIA_QUEUE) ? true : false,
  217. 'S_ACCESS_AUTHORS' => ($row['topic_access'] == TITANIA_ACCESS_AUTHORS) ? true : false,
  218. 'S_TOPIC' => true
  219. );
  220. }
  221. else if ($row['watch_object_type'] == TITANIA_CONTRIB)
  222. {
  223. $tpl_block = 'items';
  224. $contrib = new titania_contribution;
  225. $contrib->__set_array($row);
  226. titania_topic_folder_img($folder_img, $folder_alt, 0, titania_tracking::is_unread(TITANIA_CONTRIB, $contrib->contrib_id, $contrib->contrib_last_update));
  227. $vars = array(
  228. 'SUBSCRIPTION_AUTHOR_FULL' => users_overlord::get_user($row['contrib_user_id'], '_full'),
  229. 'SUBSCRIPTION_CONTRIB_TYPE' => titania_types::$types[$contrib->contrib_type]->lang,
  230. 'SUBSCRIPTION_DOWNLOADS' => $row['contrib_downloads'],
  231. 'SUBSCRIPTION_ID' => $row['contrib_id'],
  232. 'SUBSCRIPTION_TARGET' => phpbb::$user->lang['SUBSCRIPTION_CONTRIB'],
  233. 'SUBSCRIPTION_TIME' => phpbb::$user->format_date($row['contrib_last_update']),
  234. 'SUBSCRIPTION_TITLE' => $row['contrib_name'],
  235. 'SUBSCRIPTION_TYPE' => $row['watch_object_type'],
  236. 'SUBSCRIPTION_VIEWS' => $row['contrib_views'],
  237. 'U_VIEW_SUBSCRIPTION' => $contrib->get_url(),
  238. 'S_CONTRIB' => true
  239. );
  240. }
  241. phpbb::$template->assign_block_vars($tpl_block, array_merge($vars, array(
  242. 'FOLDER_IMG' => phpbb::$user->img($folder_img, $folder_alt),
  243. 'FOLDER_IMG_SRC' => phpbb::$user->img($folder_img, $folder_alt, false, '', 'src'),
  244. 'FOLDER_IMG_ALT' => phpbb::$user->lang[$folder_alt],
  245. 'FOLDER_IMG_WIDTH' => phpbb::$user->img($folder_img, '', false, '', 'width'),
  246. 'FOLDER_IMG_HEIGHT' => phpbb::$user->img($folder_img, '', false, '', 'height'),
  247. )));
  248. }
  249. break;
  250. case 'subscription_sections':
  251. $array_items = array(TITANIA_SUPPORT, TITANIA_QUEUE, TITANIA_ATTENTION);
  252. // We prepare pagination stuff
  253. $sql = 'SELECT COUNT(*) AS subscription_count
  254. FROM ' . TITANIA_WATCH_TABLE . '
  255. WHERE ' . phpbb::$db->sql_in_set('watch_object_type', $array_items) . '
  256. AND watch_user_id = ' . phpbb::$user->data['user_id'];
  257. phpbb::$db->sql_query($sql);
  258. $subscription_count = phpbb::$db->sql_fetchfield('subscription_count');
  259. phpbb::$db->sql_freeresult();
  260. $sort->total = $subscription_count;
  261. $sort->build_pagination($url);
  262. $sql_ary = array(
  263. 'SELECT' => '*,
  264. CASE w.watch_object_type
  265. WHEN ' . TITANIA_SUPPORT . ' THEN c.contrib_last_update
  266. END AS time',
  267. 'FROM' => array(
  268. TITANIA_WATCH_TABLE => 'w',
  269. ),
  270. 'LEFT_JOIN' => array(
  271. array(
  272. 'FROM' => array(TITANIA_CONTRIBS_TABLE => 'c'),
  273. 'ON' => '(w.watch_object_type = ' . TITANIA_SUPPORT. ')
  274. AND c.contrib_id = w.watch_object_id',
  275. ),
  276. ),
  277. 'WHERE' => 'w.watch_user_id = ' . phpbb::$user->data['user_id'] . '
  278. AND ' . phpbb::$db->sql_in_set('watch_object_type', $array_items),
  279. 'ORDER_BY' => 'time DESC',
  280. );
  281. $sql = phpbb::$db->sql_build_query('SELECT', $sql_ary);
  282. // Get the data
  283. $result = phpbb::$db->sql_query_limit($sql, $sort->limit, $sort->start);
  284. $user_ids = array();
  285. while ($row = phpbb::$db->sql_fetchrow($result))
  286. {
  287. $rows[] = $row;
  288. $user_ids[] = $row['contrib_user_id'];
  289. }
  290. phpbb::$db->sql_freeresult($result);
  291. // Get user data
  292. users_overlord::load_users($user_ids);
  293. if (isset($rows))
  294. {
  295. foreach ($rows as $row)
  296. {
  297. if ($row['watch_object_type'] == TITANIA_SUPPORT)
  298. {
  299. $tpl_block = 'sections';
  300. $contrib = new titania_contribution;
  301. $contrib->__set_array($row);
  302. $vars = array(
  303. 'SUBSCRIPTION_AUTHOR_FULL' => users_overlord::get_user($row['contrib_user_id'], '_full'),
  304. 'SUBSCRIPTION_ID' => $row['watch_object_id'],
  305. 'SUBSCRIPTION_TARGET' => phpbb::$user->lang['SUBSCRIPTION_SUPPORT'],
  306. 'SUBSCRIPTION_TIME' => phpbb::$user->format_date($row['contrib_last_update']),
  307. 'SUBSCRIPTION_TITLE' => $row['contrib_name'],
  308. 'SUBSCRIPTION_TYPE' => $row['watch_object_type'],
  309. 'U_VIEW_SUBSCRIPTION' => $contrib->get_url('support')
  310. );
  311. }
  312. else if ($row['watch_object_type'] == TITANIA_ATTENTION)
  313. {
  314. $tpl_block = 'sections';
  315. $vars = array(
  316. 'SUBSCRIPTION_ID' => $row['watch_object_id'],
  317. 'SUBSCRIPTION_TIME' => phpbb::$user->format_date($row['watch_mark_time']),
  318. 'SUBSCRIPTION_TITLE' => phpbb::$user->lang['SUBSCRIPTION_ATTENTION'],
  319. 'SUBSCRIPTION_TYPE' => $row['watch_object_type'],
  320. 'S_ATTENTION' => true,
  321. 'S_ACCESS_TEAMS' => true,
  322. 'U_VIEW_SUBSCRIPTION' => titania_url::build_url('manage/attention')
  323. );
  324. }
  325. else if ($row['watch_object_type'] == TITANIA_QUEUE)
  326. {
  327. $tpl_block = 'sections';
  328. $queue_id = $row['watch_object_id'];
  329. // Setup the base url we will use
  330. $base_url = titania_url::build_url('manage/queue');
  331. $vars = array(
  332. 'SUBSCRIPTION_ID' => $queue_id,
  333. 'SUBSCRIPTION_TARGET' => titania_types::$types[$queue_id]->lang,
  334. 'SUBSCRIPTION_TIME' => phpbb::$user->format_date($row['watch_mark_time']),
  335. 'SUBSCRIPTION_TITLE' => phpbb::$user->lang['SUBSCRIPTION_QUEUE'],
  336. 'SUBSCRIPTION_TYPE' => $row['watch_object_type'],
  337. 'S_QUEUE' => true,
  338. 'S_ACCESS_TEAMS' => true,
  339. 'U_VIEW_SUBSCRIPTION' => titania_url::append_url($base_url, array('queue' => titania_types::$types[$queue_id]->url))
  340. );
  341. }
  342. phpbb::$template->assign_block_vars($tpl_block, $vars);
  343. }
  344. }
  345. break;
  346. }
  347. phpbb::$template->assign_vars(array(
  348. 'S_ACTION' => $url,
  349. 'TITANIA_THEME_PATH' => titania::$absolute_path . 'styles/' . titania::$config->style . '/theme/'
  350. ));
  351. titania::page_header(phpbb::$user->lang['SUBSCRIPTION_TITANIA']);
  352. titania::page_footer(true, 'manage/' . $mode . '.html');
  353. }
  354. }
  355. function titania_outside_build_url(&$hook, $base, $params = array())
  356. {
  357. global $mode;
  358. if ($base == 'manage/' . $mode || $base == titania_url::$current_page || strpos($base, 'ucp.' . PHP_EXT))
  359. {
  360. return phpbb::append_sid('ucp', array_merge(array('i' => 'titania', 'mode' => $mode), $params));
  361. }
  362. }
  363. function titania_outside_page_header(&$hook, $page_title)
  364. {
  365. page_header($page_title);
  366. return true;
  367. }
  368. function titania_outside_page_footer(&$hook, $run_cron)
  369. {
  370. page_footer(false);
  371. return true;
  372. }