PageRenderTime 62ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/upload/mode/cms/lib/upload/articleupload.class.php

https://github.com/bluelovers/phpwind
PHP | 290 lines | 284 code | 6 blank | 0 comment | 4 complexity | 6136f33d8afdc641ec1fbc629322280b MD5 | raw file
  1. <?php
  2. !defined('P_W') && exit('Forbidden');
  3. L::loadClass('upload', '', false);
  4. class ArticleUpload extends uploadBehavior {
  5. var $db;
  6. var $attachs;
  7. var $replacedb = array();
  8. function ArticleUpload() {
  9. global $db,$db_ifathumb,$db_athumbsize,$db_uploadfiletype,$winduid;
  10. parent::uploadBehavior();
  11. $this->uid = $winduid;
  12. $this->db =& $db;
  13. $this->ifthumb =& $db_ifathumb;
  14. $this->thumbsize =& $db_athumbsize;
  15. $this->ftype = !is_array($db_uploadfiletype) ? unserialize($db_uploadfiletype) : $db_uploadfiletype;
  16. }
  17. function transfer() {
  18. if (empty($this->flashatt)) {
  19. return false;
  20. }
  21. require_once(R_P . 'require/functions.php');
  22. $pw_attachs = L::loadDB('attachs', 'forum');
  23. $saveAttach = $this->getSaveAttach($this->uid);
  24. $deltmp = array();
  25. $attach = $pw_attachs->gets(array('tid' => 0, 'pid' => 0, 'uid' => $this->uid, 'did' => 0, 'mid' => 0));
  26. foreach ($attach as $rt) {
  27. $deltmp[] = $rt['aid'];
  28. if (!isset($this->flashatt[$rt['aid']])) {
  29. pwDelatt($rt['attachurl'], $this->ifftp);
  30. continue;
  31. }
  32. $saveAttach && $saveAttach->add($rt);
  33. $value = $this->flashatt[$rt['aid']];
  34. $rt['descrip'] = $value['desc'];
  35. $this->attachs[] = array(
  36. 'id' => $rt['aid'],
  37. 'attname' => 'attachment',
  38. 'name' => $rt['name'],
  39. 'type' => $rt['type'],
  40. 'fileuploadurl' => $rt['attachurl'],
  41. 'size' => $rt['size'],
  42. 'descrip' => str_replace('\\','', $rt['descrip']),
  43. 'ifthumb' => $rt['ifthumb']
  44. );
  45. }
  46. $saveAttach && $saveAttach->execute();
  47. $deltmp && $pw_attachs->delete($deltmp);
  48. return true;
  49. }
  50. function allowType($key) {
  51. list($t) = explode('_', $key);
  52. return in_array($t, array('replace', 'attachment'));
  53. }
  54. function getFilePath($currUpload) {
  55. global $timestamp;
  56. $prename = substr(md5($timestamp . $currUpload['id'] . randstr(8)),10,15);
  57. $filename = "{$this->uid}_$prename." . preg_replace('/(php|asp|jsp|cgi|fcgi|exe|pl|phtml|dll|asa|com|scr|inf)/i', "scp_\\1", $currUpload['ext']);
  58. $savedir = $this->getSaveDir($currUpload['ext']);
  59. return array($filename, $savedir);
  60. }
  61. function update($uploaddb) {
  62. global $db_charset;
  63. $this->transfer();
  64. foreach ($uploaddb as $value) {
  65. $value['descrip'] = S::escapeChar(S::getGP('atc_desc'.$value['id'], 'P'));
  66. $value['name'] = stripslashes(pwConvert($value['name'], $db_charset, 'utf-8'));
  67. $this->attachs[] = $value;
  68. }
  69. return $uploaddb;
  70. }
  71. function getSaveDir($ext) {
  72. global $db_attachdir;
  73. $savedir = 'cms_article/';
  74. if ($db_attachdir) {
  75. if ($db_attachdir == 2) {
  76. $savedir .= "Type_$ext/";
  77. } elseif ($db_attachdir == 3) {
  78. $savedir .= 'Mon_'.date('ym').'/';
  79. } elseif ($db_attachdir == 4) {
  80. $savedir .= 'Day_'.date('ymd').'/';
  81. }
  82. }
  83. return $savedir;
  84. }
  85. function allowThumb() {
  86. return (int) $this->ifthumb;
  87. }
  88. function allowWaterMark() {
  89. global $db_watermark;
  90. return (int)$db_watermark;
  91. }
  92. function getThumbInfo($filename, $dir) {
  93. return array(
  94. array($filename, 'thumb/' . $dir, $this->thumbsize)
  95. );
  96. }
  97. function getAttachs() {
  98. return $this->attachs;
  99. }
  100. function getAids() {
  101. return array_keys($this->attachs);
  102. }
  103. function getAttNum() {
  104. return count($this->attachs);
  105. }
  106. }
  107. class articleMutiUpload extends uploadBehavior {
  108. var $db;
  109. var $attachs;
  110. function articleMutiUpload($uid) {
  111. global $db,$db_ifathumb,$db_athumbsize,$db_uploadfiletype;
  112. parent::uploadBehavior();
  113. $this->uid = $uid;
  114. $this->db =& $db;
  115. $this->ifthumb =& $db_ifathumb;
  116. $this->thumbsize =& $db_athumbsize;
  117. $this->ftype = !is_array($db_uploadfiletype) ? unserialize($db_uploadfiletype) : $db_uploadfiletype;
  118. }
  119. function check() {
  120. return true;
  121. }
  122. function allowType($key) {
  123. return true;
  124. }
  125. function getFilePath($currUpload) {
  126. global $timestamp;
  127. $prename = substr(md5($timestamp . $currUpload['id'] . randstr(8)),10,15);
  128. $filename = "{$this->uid}_$prename." . preg_replace('/(php|asp|jsp|cgi|fcgi|exe|pl|phtml|dll|asa|com|scr|inf)/i', "scp_\\1", $currUpload['ext']);
  129. $savedir = $this->getSaveDir($currUpload['ext']);
  130. return array($filename, $savedir);
  131. }
  132. function getSaveDir($ext) {
  133. global $db_attachdir;
  134. $savedir = 'cms_article/';
  135. if ($db_attachdir) {
  136. if ($db_attachdir == 2) {
  137. $savedir .= "Type_$ext/";
  138. } elseif ($db_attachdir == 3) {
  139. $savedir .= 'Mon_'.date('ym').'/';
  140. } elseif ($db_attachdir == 4) {
  141. $savedir .= 'Day_'.date('ymd').'/';
  142. }
  143. }
  144. return $savedir;
  145. }
  146. function allowThumb() {
  147. return (int) $this->ifthumb;
  148. }
  149. function allowWaterMark() {
  150. global $db_watermark;
  151. return (int)$db_watermark;
  152. }
  153. function getThumbInfo($filename, $dir) {
  154. return array(
  155. array($filename, 'thumb/' . $dir, $this->thumbsize)
  156. );
  157. }
  158. function update($uploaddb) {
  159. global $timestamp,$db_charset;
  160. foreach ($uploaddb as $value) {
  161. $value['name'] = pwConvert($value['name'], $db_charset, 'utf-8');
  162. $this->db->update("INSERT INTO pw_attachs SET " . S::sqlSingle(array(
  163. 'uid' => $this->uid,
  164. 'hits' => 0, 'name' => $value['name'],
  165. 'type' => $value['type'], 'size' => $value['size'],
  166. 'attachurl' => $value['fileuploadurl'],
  167. 'uploadtime'=> $timestamp, 'ifthumb' => $value['ifthumb']
  168. )));
  169. $aid = $this->db->insert_id();
  170. $value['aid'] = $aid;
  171. $this->attachs[$aid] = $value;
  172. }
  173. return true;
  174. }
  175. function getAttachInfo() {
  176. $array = current($this->attachs);
  177. list($path) = geturl($array['fileuploadurl'], 'lf', $array['ifthumb']);
  178. return array('aid' => $array['aid'], 'path' => $path);
  179. }
  180. }
  181. class ArticleModify extends uploadBehavior {
  182. var $db;
  183. var $attach;
  184. var $attachs;
  185. function ArticleModify($aid) {
  186. global $db,$db_ifathumb,$db_athumbsize,$db_uploadfiletype,$_G;
  187. parent::uploadBehavior();
  188. $this->db =& $db;
  189. $this->attach = $this->db->get_one("SELECT * FROM pw_cms_attach a LEFT JOIN pw_cms_article at USING(article_id) WHERE a.attach_id=" . S::sqlEscape($aid));
  190. $this->ifthumb =& $db_ifathumb;
  191. $this->thumbsize =& $db_athumbsize;
  192. !is_array($db_uploadfiletype) && $db_uploadfiletype = unserialize($db_uploadfiletype);
  193. $this->ftype =& $db_uploadfiletype;
  194. }
  195. function check() {
  196. global $db_allowupload, $winddb, $groupid, $_G, $windid, $winduid, $manager;
  197. if (empty($this->attach)) {
  198. return 'job_attach_error';
  199. }
  200. if (!$db_allowupload) {
  201. return 'upload_close';
  202. }
  203. if (!($winduid == $this->attach['userid'] || S::inArray($windid, $manager))) {
  204. return 'modify_noper';
  205. }
  206. return true;
  207. }
  208. function allowType($key) {
  209. list(, $t) = explode('_', $key);
  210. return $t == $this->attach['attach_id'];
  211. }
  212. function getFilePath($currUpload) {
  213. $arr = explode('/', $this->attach['attachurl']);
  214. $filename = array_pop($arr);
  215. $savedir = $arr ? implode('/',$arr) . '/' : '';
  216. return array($filename, $savedir);
  217. }
  218. function allowThumb() {
  219. return $this->ifthumb;
  220. }
  221. function allowWaterMark() {
  222. global $db_watermark;
  223. return (int)$db_watermark;
  224. }
  225. function getThumbInfo($filename, $dir) {
  226. return array(
  227. array($filename, 'thumb/' . $dir, $this->thumbsize)
  228. );
  229. }
  230. function update($uploaddb) {
  231. global $timestamp;
  232. foreach ($uploaddb as $value) {
  233. $value['name'] = addslashes($value['name']);
  234. $aid = $value['id'];
  235. pwQuery::update('pw_cms_attach', 'attach_id=:attach_id', array($aid), array(
  236. 'name' => $value['name'], 'type' => $value['type'],
  237. 'size' => $value['size'], 'attachurl' => $value['fileuploadurl'],
  238. 'uploadtime'=> $timestamp, 'ifthumb' => $value['ifthumb']
  239. ));
  240. }
  241. $this->attachs = $uploaddb;
  242. return true;
  243. }
  244. function getAttachName() {
  245. $array = current($this->attachs);
  246. return $array['name'];
  247. }
  248. }
  249. ?>