Просмотр файла attach_mod/pm_attachments.php

Размер файла: 6.94Kb
  1. <?php
  2. /***************************************************************************
  3. * mides.ru
  4. * -------------------
  5. ***************************************************************************/
  6. if ( !defined('IN_PHPBB') )
  7. {
  8. die('Hacking attempt');
  9. exit;
  10. }
  11.  
  12. class attach_pm extends attach_parent
  13. {
  14. var $pm_delete_attachments = false;
  15.  
  16. function attach_pm()
  17. {
  18. global $HTTP_POST_VARS;
  19.  
  20. $this->attach_parent();
  21. $this->pm_delete_attachments = (isset($HTTP_POST_VARS['pm_delete_attach'])) ? true : false;
  22. $this->page = PAGE_PRIVMSGS;
  23. }
  24.  
  25. function preview_attachments()
  26. {
  27. global $attach_config, $userdata;
  28.  
  29. if (!intval($attach_config['allow_pm_attach']))
  30. {
  31. return false;
  32. }
  33. display_attachments_preview($this->attachment_list, $this->attachment_filesize_list, $this->attachment_filename_list, $this->attachment_comment_list, $this->attachment_extension_list, $this->attachment_thumbnail_list);
  34. }
  35.  
  36. function insert_attachment_pm($a_privmsgs_id)
  37. {
  38. global $db, $mode, $attach_config, $privmsg_sent_id, $userdata, $to_userdata, $HTTP_POST_VARS;
  39.  
  40. $a_privmsgs_id = (int) $a_privmsgs_id;
  41.  
  42. if (!$a_privmsgs_id)
  43. {
  44. $a_privmsgs_id = (int) $privmsg_sent_id;
  45. }
  46. if ($a_privmsgs_id && ($mode == 'post' || $mode == 'reply' || $mode == 'edit') && intval($attach_config['allow_pm_attach']))
  47. {
  48. $this->do_insert_attachment('attach_list', 'pm', $a_privmsgs_id);
  49. $this->do_insert_attachment('last_attachment', 'pm', $a_privmsgs_id);
  50.  
  51. if ((sizeof($this->attachment_list) > 0 || $this->post_attach) && !isset($HTTP_POST_VARS['update_attachment']))
  52. {
  53. $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
  54. SET privmsgs_attachment = 1
  55. WHERE privmsgs_id = ' . (int) $a_privmsgs_id;
  56.  
  57. if (!$db->sql_query($sql))
  58. {
  59. message_die(GENERAL_ERROR, 'Unable to update Private Message Table.', '', __LINE__, __FILE__, $sql);
  60. }
  61. }
  62. }
  63. }
  64.  
  65. function duplicate_attachment_pm($switch_attachment, $original_privmsg_id, $new_privmsg_id)
  66. {
  67. global $db, $privmsg, $folder;
  68.  
  69. if (($privmsg['privmsgs_type'] == PRIVMSGS_NEW_MAIL || $privmsg['privmsgs_type'] == PRIVMSGS_UNREAD_MAIL) && $folder == 'inbox' && intval($switch_attachment) == 1)
  70. {
  71. $sql = 'SELECT *
  72. FROM ' . ATTACHMENTS_TABLE . '
  73. WHERE privmsgs_id = ' . (int) $original_privmsg_id;
  74.  
  75. if (!($result = $db->sql_query($sql)))
  76. {
  77. message_die(GENERAL_ERROR, 'Couldn\'t query Attachment Table', '', __LINE__, __FILE__, $sql);
  78. }
  79. $rows = $db->sql_fetchrowset($result);
  80. $num_rows = $db->sql_numrows($result);
  81. $db->sql_freeresult($result);
  82.  
  83. if ($num_rows > 0)
  84. {
  85. for ($i = 0; $i < $num_rows; $i++)
  86. {
  87. $sql_ary = array(
  88. 'attach_id' => (int) $rows[$i]['attach_id'],
  89. 'post_id' => (int) $rows[$i]['post_id'],
  90. 'privmsgs_id' => (int) $new_privmsg_id,
  91. 'user_id_1' => (int) $rows[$i]['user_id_1'],
  92. 'user_id_2' => (int) $rows[$i]['user_id_2'],
  93. );
  94.  
  95. $sql = 'INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . attach_mod_sql_build_array('INSERT', $sql_ary);
  96.  
  97. if (!($result = $db->sql_query($sql)))
  98. {
  99. message_die(GENERAL_ERROR, 'Couldn\'t store Attachment for sent Private Message', '', __LINE__, __FILE__, $sql);
  100. }
  101. }
  102.  
  103. $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
  104. SET privmsgs_attachment = 1
  105. WHERE privmsgs_id = ' . (int) $new_privmsg_id;
  106.  
  107. if (!($db->sql_query($sql)))
  108. {
  109. message_die(GENERAL_ERROR, 'Unable to update Private Message Table.', '', __LINE__, __FILE__, $sql);
  110. }
  111. }
  112. }
  113. }
  114.  
  115. function delete_all_pm_attachments($mark_list)
  116. {
  117. global $confirm, $delete_all;
  118.  
  119. if (sizeof($mark_list))
  120. {
  121. $delete_sql_id = '';
  122. for ($i = 0; $i < sizeof($mark_list); $i++)
  123. {
  124. $delete_sql_id .= (($delete_sql_id != '') ? ', ' : '') . intval($mark_list[$i]);
  125. }
  126.  
  127. if ($delete_all && $confirm)
  128. {
  129. delete_attachment($delete_sql_id, 0, PAGE_PRIVMSGS);
  130. }
  131. }
  132. }
  133.  
  134. function display_attach_box_limits()
  135. {
  136. global $folder, $attach_config, $board_config, $template, $lang, $userdata, $db;
  137.  
  138. if (!$attach_config['allow_pm_attach'] && $userdata['user_level'] != ADMIN)
  139. {
  140. return;
  141. }
  142.  
  143. $this->get_quota_limits($userdata);
  144.  
  145. $pm_filesize_limit = (!$attach_config['pm_filesize_limit']) ? $attach_config['attachment_quota'] : $attach_config['pm_filesize_limit'];
  146.  
  147. $pm_filesize_total = get_total_attach_pm_filesize('to_user', (int) $userdata['user_id']);
  148.  
  149. $attach_limit_pct = ( $pm_filesize_limit > 0 ) ? round(( $pm_filesize_total / $pm_filesize_limit ) * 100) : 0;
  150. $attach_limit_img_length = ( $pm_filesize_limit > 0 ) ? round(( $pm_filesize_total / $pm_filesize_limit ) * $board_config['privmsg_graphic_length']) : 0;
  151. if ($attach_limit_pct > 100)
  152. {
  153. $attach_limit_img_length = $board_config['privmsg_graphic_length'];
  154. }
  155. $attach_limit_remain = ( $pm_filesize_limit > 0 ) ? $pm_filesize_limit - $pm_filesize_total : 100;
  156.  
  157. $l_box_size_status = sprintf($lang['Attachbox_limit'], $attach_limit_pct);
  158.  
  159. $template->assign_vars(array(
  160. 'ATTACHBOX_LIMIT_IMG_WIDTH' => $attach_limit_img_length,
  161. 'ATTACHBOX_LIMIT_PERCENT' => $attach_limit_pct,
  162.  
  163. 'ATTACH_BOX_SIZE_STATUS' => $l_box_size_status)
  164. );
  165. }
  166.  
  167. function privmsgs_attachment_mod($mode)
  168. {
  169. global $attach_config, $template, $lang, $userdata, $HTTP_POST_VARS, $phpbb_root_path, $phpEx, $db;
  170. global $confirm, $delete, $delete_all, $post_id, $privmsgs_id, $privmsg_id, $submit, $refresh, $mark_list, $folder;
  171.  
  172. if ($folder != 'outbox')
  173. {
  174. $this->display_attach_box_limits();
  175. }
  176.  
  177. if (!intval($attach_config['allow_pm_attach']))
  178. {
  179. return;
  180. }
  181.  
  182. if (!$refresh)
  183. {
  184. $add_attachment_box = (!empty($HTTP_POST_VARS['add_attachment_box'])) ? TRUE : FALSE;
  185. $posted_attachments_box = (!empty($HTTP_POST_VARS['posted_attachments_box'])) ? TRUE : FALSE;
  186.  
  187. $refresh = $add_attachment_box || $posted_attachments_box;
  188. }
  189.  
  190. $post_id = $privmsgs_id;
  191.  
  192. $result = $this->handle_attachments($mode, PAGE_PRIVMSGS);
  193.  
  194. if ($result === false)
  195. {
  196. return;
  197. }
  198.  
  199. $mark_list = get_var('mark', array(0));
  200.  
  201. if (($this->pm_delete_attachments || $delete) && sizeof($mark_list))
  202. {
  203. if (!$userdata['session_logged_in'])
  204. {
  205. $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
  206. header($header_location . append_sid($phpbb_root_path . "login.$phpEx?redirect=privmsg.$phpEx&folder=inbox", true));
  207. exit;
  208. }
  209. if (sizeof($mark_list))
  210. {
  211. $delete_sql_id = '';
  212. for ($i = 0; $i < sizeof($mark_list); $i++)
  213. {
  214. $delete_sql_id .= (($delete_sql_id != '') ? ', ' : '') . intval($mark_list[$i]);
  215. }
  216.  
  217. if (($this->pm_delete_attachments || $confirm) && !$delete_all)
  218. {
  219. delete_attachment($delete_sql_id, 0, PAGE_PRIVMSGS);
  220. }
  221. }
  222. }
  223.  
  224. if ($submit || $refresh || $mode != '')
  225. {
  226. $this->display_attachment_bodies();
  227. }
  228. }
  229. }
  230.  
  231. function execute_privmsgs_attachment_handling($mode)
  232. {
  233. global $attachment_mod;
  234.  
  235. $attachment_mod['pm'] = new attach_pm();
  236. if ($mode != 'read')
  237. {
  238. $attachment_mod['pm']->privmsgs_attachment_mod($mode);
  239. }
  240. }
  241.  
  242. ?>