PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/wap/attach.php

https://github.com/flyinghail/MolyX
PHP | 204 lines | 182 code | 13 blank | 9 comment | 20 complexity | 1cf8a434044806936ac95d0c190863f7 MD5 | raw file
  1. <?php
  2. # **************************************************************************#
  3. # MolyX2
  4. # ------------------------------------------------------
  5. # @copyright (c) 2009-2010 MolyX Group..
  6. # @official forum http://molyx.com
  7. # @license http://opensource.org/licenses/gpl-2.0.php GNU Public License 2.0
  8. #
  9. # $Id$
  10. # **************************************************************************#
  11. define('THIS_SCRIPT', 'attachment');
  12. require_once('./global.php');
  13. class attachment
  14. {
  15. function show()
  16. {
  17. global $_INPUT, $DB, $forums;
  18. $_INPUT['id'] = intval($_INPUT['id']);
  19. $_INPUT['tid'] = intval($_INPUT['tid']);
  20. if (!$_INPUT['tid'])
  21. {
  22. $forums->func->load_lang('error');
  23. $forums->lang['wapinfo'] = convert($forums->lang['wapinfo']);
  24. $contents = convert($forums->lang['errorthreadlink']);
  25. include $forums->func->load_template('wap_info');
  26. exit;
  27. }
  28. $this->thread = $DB->query_first("SELECT * FROM " . TABLE_PREFIX . "thread WHERE tid={$_INPUT['tid']}");
  29. if (!$this->thread['attach'])
  30. {
  31. $forums->func->load_lang('error');
  32. $forums->lang['wapinfo'] = convert($forums->lang['wapinfo']);
  33. $contents = convert($forums->lang['erroraddress']);
  34. include $forums->func->load_template('wap_info');
  35. exit;
  36. }
  37. $this->forum = $forums->forum->single_forum($this->thread['forumid']);
  38. if (!$this->forum['id'])
  39. {
  40. $forums->func->load_lang('error');
  41. $forums->lang['wapinfo'] = convert($forums->lang['wapinfo']);
  42. $contents = convert($forums->lang['erroraddress']);
  43. include $forums->func->load_template('wap_info');
  44. exit;
  45. }
  46. switch ($_INPUT['do'])
  47. {
  48. case 'view':
  49. $this->listattachment();
  50. break;
  51. default:
  52. $this->showattachment();
  53. break;
  54. }
  55. }
  56. function listattachment()
  57. {
  58. global $DB, $forums, $_INPUT, $bboptions, $bbuserinfo;
  59. $thread_title = convert(strip_tags($this->thread['title']));
  60. $threadtitle = "<a href='thread.php{$forums->sessionurl}t={$this->thread['tid']}&amp;extra={$_INPUT['extra']}'>{$thread_title}</a>";
  61. $attachments = $DB->query("SELECT a.*, t.*, p.threadid, p.pid FROM " . TABLE_PREFIX . "attachment a
  62. LEFT JOIN " . TABLE_PREFIX . "post p ON ( a.postid=p.pid )
  63. LEFT JOIN " . TABLE_PREFIX . "thread t ON ( t.tid=p.threadid )
  64. WHERE p.threadid={$this->thread['tid']}
  65. ORDER BY a.dateline"
  66. );
  67. while ($row = $DB->fetch_array($attachments))
  68. {
  69. if ($forums->func->fetch_permissions($forums->forum->foruminfo[ $row['forumid'] ]['canread'], 'canread') != true)
  70. {
  71. continue;
  72. }
  73. $row['dateline'] = $forums->func->get_date($row['dateline'], 1);
  74. $row['filesize'] = fetch_number_format($row['filesize'], true);
  75. $attach[] = $row;
  76. }
  77. if (is_array($attach))
  78. {
  79. foreach ($attach AS $a)
  80. {
  81. $attachlink .= "<p><a href='attach.php{$forums->sessionurl}id={$a['attachmentid']}&amp;tid={$this->thread['tid']}'>{$a['filename']}</a><br />\r\n";
  82. $attachlink .= "<small>size: {$a['filesize']}</small><br />\r\n";
  83. $attachlink .= "<small>{$a['dateline']}</small></p>\r\n";
  84. }
  85. }
  86. $attachlink = convert($attachlink);
  87. $otherlink = $this->otherlink();
  88. include $forums->func->load_template('wap_attachment');
  89. exit;
  90. }
  91. function showattachment()
  92. {
  93. global $DB, $forums, $_INPUT, $bbuserinfo, $bboptions;
  94. $forums->noheader = 1;
  95. $attachment = $DB->query_first("SELECT a.*, t.*, p.threadid, p.pid
  96. FROM " . TABLE_PREFIX . "attachment a
  97. LEFT JOIN " . TABLE_PREFIX . "post p
  98. ON ( a.postid=p.pid )
  99. LEFT JOIN " . TABLE_PREFIX . "thread t
  100. ON ( t.tid=p.threadid )
  101. WHERE a.attachmentid='" . $_INPUT['id'] . "'"
  102. );
  103. if (!$attachment['attachmentid'] OR $attachment['threadid'] != $this->thread['tid'])
  104. {
  105. $forums->func->load_lang('error');
  106. $forums->lang['wapinfo'] = convert($forums->lang['wapinfo']);
  107. $contents = convert($forums->lang['erroraddress']);
  108. include $forums->func->load_template('wap_info');
  109. exit;
  110. }
  111. if (!$bbuserinfo['candownload'])
  112. {
  113. $forums->func->load_lang('error');
  114. $forums->lang['wapinfo'] = convert($forums->lang['wapinfo']);
  115. $contents = convert($forums->lang['erroraddress']);
  116. include $forums->func->load_template('wap_info');
  117. exit;
  118. }
  119. if ($bboptions['remoteattach'])
  120. {
  121. $subpath = SAFE_MODE ? '' : implode('/', preg_split('//', intval($attachment['userid']), -1, PREG_SPLIT_NO_EMPTY));
  122. $subpath = $bboptions['remoteattach'] . "/" . $subpath;
  123. $attachment['location'] = str_replace("\\", "/", $attachment['location']);
  124. $attachment['location'] = str_replace("/", "", substr($attachment['location'], strrpos($attachment['location'], '/')));
  125. $showfile = $subpath . "/" . $attachment['location'];
  126. redirect($showfile);
  127. }
  128. else
  129. {
  130. $subpath = $attachment['attachpath'] ? $attachment['attachpath'] : '';
  131. $path = $bboptions['uploadfolder'] . '/' . $subpath;
  132. $attachment['location'] = str_replace("\\", "/", $attachment['location']);
  133. $attachment['location'] = str_replace("/", "", substr($attachment['location'], strrpos($attachment['location'], '/')));
  134. $showfile = $path . "/" . $attachment['location'];
  135. $forums->func->check_cache('attachmenttype');
  136. if (file_exists($showfile) AND ($forums->cache['attachmenttype'][ $attachment['extension'] ]['mimetype'] != ""))
  137. {
  138. @ob_end_clean();
  139. @ob_start();
  140. @ob_implicit_flush(0);
  141. if ($bboptions['attachmentviewsdelay'])
  142. {
  143. if (@$fp = fopen(ROOT_PATH . 'cache/cache/attachmentviews.txt', 'a'))
  144. {
  145. fwrite($fp, intval($_INPUT['id']) . "\n");
  146. fclose($fp);
  147. }
  148. }
  149. else
  150. {
  151. $DB->shutdown_query("UPDATE " . TABLE_PREFIX . "attachment SET counter=counter+1 WHERE attachmentid=" . intval($_INPUT['id']) . "");
  152. }
  153. @header('Cache-control: max-age=31536000');
  154. @header('Expires: ' . $forums->func->get_time(TIMENOW + 31536000, "D, d M Y H:i:s") . ' GMT');
  155. @header('Content-Type: ' . $forums->cache['attachmenttype'][ $attachment['extension'] ]['mimetype']);
  156. @header('Content-Disposition: inline; filename=' . $attachment['filename']);
  157. @header('Content-Length: ' . (string)(filesize($showfile)));
  158. @readfile($showfile);
  159. exit();
  160. }
  161. else
  162. {
  163. $forums->func->load_lang('error');
  164. $forums->lang['wapinfo'] = convert($forums->lang['wapinfo']);
  165. $contents = convert($forums->lang['erroraddress']);
  166. include $forums->func->load_template('wap_info');
  167. exit;
  168. }
  169. }
  170. }
  171. function otherlink()
  172. {
  173. global $forums, $_INPUT, $DB, $bbuserinfo;
  174. $otherlink = "<p>";
  175. $otherlink .= "{$forums->lang['forum']}: <a href='forum.php{$forums->sessionurl}f={$this->forum['id']}{$this->extra}' title='{$forums->lang['go']}'>" . strip_tags($this->forum['name']) . "</a><br />";
  176. $otherlink .= "{$forums->lang['thread']}: <a href='thread.php{$forums->sessionurl}t={$this->thread['tid']}&amp;extra={$_INPUT['extra']}' title='{$forums->lang['go']}'>" . strip_tags($this->thread['title']) . "</a><br />";
  177. if ($prevthread = $DB->query_first("SELECT tid, title FROM " . TABLE_PREFIX . "thread WHERE forumid='" . $this->forum['id'] . "' AND visible=1 AND open != 2 AND lastpost < '" . $this->thread['lastpost'] . "' ORDER BY lastpost DESC LIMIT 0, 1"))
  178. {
  179. $otherlink .= "{$forums->lang['prevthread']}: <a href='thread.php{$forums->sessionurl}t={$prevthread['tid']}&amp;extra={$_INPUT['extra']}' title='{$forums->lang['go']}'>" . strip_tags($prevthread['title']) . "</a><br />";
  180. }
  181. if ($nextthread = $DB->query_first("SELECT tid, title FROM " . TABLE_PREFIX . "thread WHERE forumid='" . $this->forum['id'] . "' AND visible=1 AND open != 2 AND lastpost > '" . $this->thread['lastpost'] . "' ORDER BY lastpost LIMIT 0, 1"))
  182. {
  183. $otherlink .= "{$forums->lang['nextthread']}: <a href='thread.php{$forums->sessionurl}t={$nextthread['tid']}&amp;extra={$_INPUT['extra']}' title='{$forums->lang['go']}'>" . strip_tags($nextthread['title']) . "</a><br />";
  184. }
  185. $otherlink .= "</p>\n";
  186. return convert($otherlink);
  187. }
  188. }
  189. $output = new attachment();
  190. $output->show();
  191. ?>