PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/album_hotornot.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 270 lines | 189 code | 39 blank | 42 comment | 38 complexity | b1c56d5505c286c80860f189c8c89925 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. /**
  11. *
  12. * @Extra credits for this file
  13. * Volodymyr (CLowN) Skoryk (blaatimmy72@yahoo.com)
  14. *
  15. */
  16. define('IN_ICYPHOENIX', true);
  17. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  18. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  19. include(IP_ROOT_PATH . 'common.' . PHP_EXT);
  20. // Start session management
  21. $user->session_begin();
  22. $auth->acl($user->data);
  23. $user->setup();
  24. // End session management
  25. // Get general album information
  26. include(ALBUM_MOD_PATH . 'album_common.' . PHP_EXT);
  27. if (!$user->data['session_logged_in'])
  28. {
  29. message_die(GENERAL_MESSAGE, $lang['Login_To_Vote']);
  30. }
  31. // Force to use the same table for backward compatibility - BEGIN
  32. $album_config['hon_rate_sep'] = false;
  33. // Force to use the same table for backward compatibility - END
  34. $rate_point = request_var('hon_rating', 0);
  35. //if user hasn't rated a picture, show page, else update database
  36. if (($rate_point < 1) || ($rate_point > $album_config['rate_scale']))
  37. {
  38. // ------------------------------------
  39. // get a random pic from album
  40. // ------------------------------------
  41. if (empty($album_config['hon_rate_where']))
  42. {
  43. $sql = "SELECT `pic_id` FROM " . ALBUM_TABLE . "
  44. WHERE pic_user_id <> '" . $user->data['user_id'] . "'
  45. ORDER BY RAND() LIMIT 1";
  46. }
  47. else
  48. {
  49. $sql = "SELECT `pic_id` FROM " . ALBUM_TABLE . "
  50. WHERE pic_cat_id IN (" . $album_config['hon_rate_where'] . ")
  51. AND pic_user_id <> '" . $user->data['user_id'] . "'
  52. ORDER BY RAND() LIMIT 1";
  53. }
  54. $result = $db->sql_query($sql);
  55. $pic_id_temp = $db->sql_fetchrow($result);
  56. $pic_id = $pic_id_temp['pic_id'];
  57. // ------------------------------------
  58. // Get this pic info and current category info
  59. // ------------------------------------
  60. $rating_from = ($album_config['hon_rate_sep'] == 1) ? 'AVG(r.rate_hon_point) AS rating' : 'AVG(r.rate_point) AS rating';
  61. $sql_where = '';
  62. if ($user->data['user_level'] != ADMIN)
  63. {
  64. $sql_where = 'AND p.pic_approval = 1';
  65. }
  66. $sql = "SELECT p.*, cat.*, u.user_id, u.username, r.rate_pic_id, " . $rating_from . ", COUNT(DISTINCT c.comment_id) AS comments
  67. FROM " . ALBUM_CAT_TABLE . " AS cat, " . ALBUM_TABLE . " AS p
  68. LEFT JOIN ". USERS_TABLE ." AS u ON p.pic_user_id = u.user_id
  69. LEFT JOIN ". ALBUM_RATE_TABLE ." AS r ON p.pic_id = r.rate_pic_id
  70. LEFT JOIN ". ALBUM_COMMENT_TABLE ." AS c ON p.pic_id = c.comment_pic_id
  71. WHERE pic_id = '$pic_id'
  72. AND cat.cat_id = p.pic_cat_id
  73. " . $sql_where . "
  74. GROUP BY p.pic_id";
  75. $result = $db->sql_query($sql);
  76. $thispic = $db->sql_fetchrow($result);
  77. $cat_id = $thispic['pic_cat_id'];
  78. $album_user_id = $thispic['cat_user_id'];
  79. $pic_base_path = ALBUM_UPLOAD_PATH;
  80. $pic_extra_path = '';
  81. $pic_new_filename = $pic_extra_path . $pic_filename;
  82. $pic_fullpath = $pic_base_path . $pic_new_filename;
  83. if(empty($thispic) || !file_exists($pic_fullpath))
  84. {
  85. message_die(GENERAL_ERROR, $lang['Pic_not_exist']);
  86. }
  87. // ------------------------------------
  88. // Check the permissions
  89. // ------------------------------------
  90. if ($album_config['hon_rate_users'] == 0)
  91. {
  92. $album_user_access = album_permissions($album_user_id, $cat_id, ALBUM_AUTH_VIEW, $thispic);
  93. if ($album_user_access['view'] == 0)
  94. {
  95. if (!$user->data['session_logged_in'])
  96. {
  97. redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=album_hotornot.' . PHP_EXT));
  98. }
  99. else
  100. {
  101. message_die(GENERAL_ERROR, $lang['Not_Authorized']);
  102. }
  103. }
  104. }
  105. // ------------------------------------
  106. // Check Pic Approval
  107. // ------------------------------------
  108. if ($user->data['user_level'] != ADMIN)
  109. {
  110. if(($thiscat['cat_approval'] == ADMIN) || (($thiscat['cat_approval'] == MOD) && !$album_user_access['moderator']))
  111. {
  112. if ($thispic['pic_approval'] != 1)
  113. {
  114. message_die(GENERAL_ERROR, $lang['Not_Authorized']);
  115. }
  116. }
  117. }
  118. /*
  119. +----------------------------------------------------------
  120. | Main work here...
  121. +----------------------------------------------------------
  122. */
  123. if(($thispic['pic_user_id'] == ALBUM_GUEST) or ($thispic['username'] == ''))
  124. {
  125. $poster = ($thispic['pic_username'] == '') ? $lang['Guest'] : $thispic['pic_username'];
  126. }
  127. else
  128. {
  129. $poster = '<a href="'. append_sid(CMS_PAGE_PROFILE . '?mode=viewprofile&amp;' . POST_USERS_URL . '=' . $thispic['user_id']) . '">' . $thispic['username'] . '</a>';
  130. }
  131. //decide how user wants to show their rating
  132. $image_rating = ImageRating($thispic['rating']);
  133. //hot or not rating
  134. if (CanRate($pic_id, $user->data['user_id']))
  135. {
  136. $template->assign_block_vars('hon_rating', array());
  137. for ($i = 0; $i < $album_config['rate_scale']; $i++)
  138. {
  139. $template->assign_block_vars('hon_rating.hon_row', array(
  140. 'VALUE' => ($i + 1)
  141. )
  142. );
  143. }
  144. }
  145. else
  146. {
  147. $template->assign_block_vars('hon_rating_cant', array());
  148. }
  149. $template->assign_vars(array(
  150. 'L_PLEASE_RATE_IT' => $lang['Please_Rate_It'],
  151. 'L_ALREADY_RATED' => $lang['Already_rated'],
  152. 'L_PIC_ID' => $lang['Pic_ID'],
  153. 'L_RATING' => $lang['Rating'],
  154. 'L_PIC_TITLE' => $lang['Pic_Title'] . $album_config['clown_rateType'],
  155. 'L_PIC_DESC' => $lang['Pic_Desc'],
  156. 'L_POSTER' => $lang['Pic_Poster'],
  157. 'L_POSTED' => $lang['Posted'],
  158. 'L_VIEW' => $lang['View'],
  159. 'L_COMMENTS' => $lang['Comments'],
  160. 'CAT_TITLE' => $thiscat['cat_title'],
  161. 'U_VIEW_CAT' => append_sid(album_append_uid('album_cat.' . PHP_EXT . '?cat_id=' . $cat_id)),
  162. 'U_PIC' => append_sid(album_append_uid('album_pic.' . PHP_EXT . '?pic_id=' . $pic_id)),
  163. 'U_COMMENT' => append_sid(album_append_uid('album_showpage.' . PHP_EXT . '?pic_id=' . $pic_id)),
  164. 'S_ACTION' => append_sid(album_append_uid('album_hotornot.' . PHP_EXT)),
  165. 'PIC_TITLE' => $thispic['pic_title'],
  166. 'PIC_DESC' => nl2br($thispic['pic_desc']),
  167. 'POSTER' => $poster,
  168. 'PIC_TIME' => create_date($config['default_dateformat'], $thispic['pic_time'], $config['board_timezone']),
  169. 'PIC_VIEW' => $thispic['pic_view_count'],
  170. 'PIC_RATING' => $image_rating,
  171. 'PIC_COMMENTS' => $thispic['comments'],
  172. 'PIC_ID' => $pic_id,
  173. 'PICTURE_ID' => $pic_id,
  174. )
  175. );
  176. if ($album_config['rate'])
  177. {
  178. $template->assign_block_vars('rate_switch', array());
  179. }
  180. if ($album_config['comment'])
  181. {
  182. $template->assign_block_vars('comment_switch', array());
  183. }
  184. full_page_generation('album_hon.tpl', $lang['Album'], '', '');
  185. }
  186. else
  187. {
  188. if (!$user->data['session_logged_in'])
  189. {
  190. message_die(GENERAL_MESSAGE, $lang['Not_Auth_View']);
  191. }
  192. $rate_user_id = $user->data['user_id'];
  193. $rate_user_ip = $user->data['session_ip'];
  194. $pic_id = request_var('pic_id', 0);
  195. if($pic_id <= 0)
  196. {
  197. message_die(GENERAL_ERROR, 'Wrong Pic ID');
  198. }
  199. if ($album_config['hon_rate_sep'] == true)
  200. {
  201. $rating_field = 'rate_hon_point';
  202. }
  203. else
  204. {
  205. $rating_field = 'rate_point';
  206. }
  207. $sql = "SELECT * FROM " . ALBUM_RATE_TABLE . "
  208. WHERE rate_pic_id = '" . $pic_id . "'
  209. AND rate_user_id = '" . $rate_user_id . "'
  210. AND " . $rating_field . " > '0'";
  211. $result = $db->sql_query($sql);
  212. if (!($rated = $db->sql_fetchrow($result)))
  213. {
  214. $sql = "INSERT INTO " . ALBUM_RATE_TABLE . " (rate_pic_id, rate_user_id, rate_user_ip, " . $rating_field . ")
  215. VALUES ('" . $db->sql_escape($pic_id) . "', '" . $db->sql_escape($rate_user_id) . "', '" . $db->sql_escape($rate_user_ip) . "', '" . $db->sql_escape($rate_point) . "')";
  216. $result = $db->sql_query($sql);
  217. $rate_string = $lang['Album_rate_successfully'];
  218. }
  219. else
  220. {
  221. $rate_string = $lang['Already_rated'];
  222. }
  223. // --------------------------------
  224. // Complete... now send a message to user
  225. // --------------------------------
  226. $redirect_url = append_sid(album_append_uid('album_hotornot.' . PHP_EXT));
  227. meta_refresh(3, $redirect_url);
  228. $message = $rate_string . '<br /><br />' . sprintf($lang['Click_rate_more'], '<a href="' . append_sid(album_append_uid('album_hotornot.' . PHP_EXT)) . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_album_index'], '<a href="' . append_sid('album.' . PHP_EXT) . '">', '</a>');
  229. message_die(GENERAL_MESSAGE, $message);
  230. }
  231. ?>