misc_swfupload.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: misc_swfupload.php 25756 2011-11-22 02:47:45Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. require_once libfile('function/spacecp');
  12. $op = empty($_GET['op'])?'':$_GET['op'];
  13. $isupload = empty($_GET['cam']) && empty($_GET['doodle']) ? true : false;
  14. $iscamera = isset($_GET['cam']) ? true : false;
  15. $isdoodle = isset($_GET['doodle']) ? true : false;
  16. $fileurl = '';
  17. if(!empty($_POST['uid'])) {
  18. $_G['uid'] = intval($_POST['uid']);
  19. if(empty($_G['uid']) || $_POST['hash'] != md5($_G['uid'].UC_KEY)) {
  20. exit();
  21. }
  22. $member = getuserbyuid($_G['uid']);
  23. $_G['username'] = addslashes($member['username']);
  24. loadcache('usergroup_'.$member['groupid']);
  25. $_G['group'] = $_G['cache']['usergroup_'.$member['groupid']];
  26. } elseif (empty($_G['uid'])) {
  27. showmessage('to_login', null, array(), array('showmsg' => true, 'login' => 1));
  28. }
  29. if($op == "finish") {
  30. $albumid = intval($_GET['albumid']);
  31. if($albumid > 0) {
  32. album_update_pic($albumid);
  33. }
  34. $space = getuserbyuid($_G['uid']);
  35. if(ckprivacy('upload', 'feed')) {
  36. require_once libfile('function/feed');
  37. feed_publish($albumid, 'albumid');
  38. }
  39. exit();
  40. } elseif($op == 'config') {
  41. $hash = md5($_G['uid'].UC_KEY);
  42. $uploadurl = urlencode(getsiteurl().'home.php?mod=misc&ac=swfupload'.($iscamera ? '&op=screen' : ($isdoodle ? '&op=doodle&from=':'')));
  43. if($isupload) {
  44. if(!checkperm('allowupload')) {
  45. $hash = '';
  46. }
  47. } else {
  48. $filearr = $dirstr = array();
  49. if($iscamera) {
  50. $directory = dreaddir(DISCUZ_ROOT.'./static/image/foreground');
  51. foreach($directory as $key => $value) {
  52. $dirstr = DISCUZ_ROOT.'./static/image/foreground/'.$value;
  53. if(is_dir($dirstr)) {
  54. $filearr = dreaddir($dirstr, array('jpg','jpeg','gif','png'));
  55. if(!empty($filearr)) {
  56. if(is_file($dirstr.'/categories.txt')) {
  57. $catfile = @file($dirstr.'/categories.txt');
  58. $dirarr[$key][0] = trim($catfile[0]);
  59. } else {
  60. $dirarr[$key][0] = trim($value);
  61. }
  62. $dirarr[$key][1] = trim('static/image/foreground/'.$value.'/');
  63. $dirarr[$key][2] = $filearr;
  64. }
  65. }
  66. }
  67. } elseif($isdoodle) {
  68. $filearr = dreaddir(DISCUZ_ROOT.'./static/image/doodle/big', array('jpg','jpeg','gif','png'));
  69. }
  70. }
  71. $feedurl = urlencode(getsiteurl().'home.php?mod=misc&ac=swfupload&op=finish&random='.random(8).'&albumid=');
  72. $albumurl = urlencode(getsiteurl().'home.php?mod=space&do=album'.($isdoodle ? '&picid=' : '&id='));
  73. $max = 0;
  74. if(!empty($_G['group']['maximagesize'])) {
  75. $max = intval($_G['group']['maximagesize']);
  76. } else {
  77. $max = @ini_get(upload_max_filesize);
  78. $unit = strtolower(substr($max, -1, 1));
  79. if($unit == 'k') {
  80. $max = intval($max)*1024;
  81. } elseif($unit == 'm') {
  82. $max = intval($max)*1024*1024;
  83. } elseif($unit == 'g') {
  84. $max = intval($max)*1024*1024*1024;
  85. }
  86. }
  87. $albums = getalbums($_G['uid']);
  88. loadcache('albumcategory');
  89. $categorys = $_G['cache']['albumcategory'];
  90. $categorystat = $_G['setting']['albumcategorystat'] && !empty($categorys) ? intval($_G['setting']['albumcategorystat']) : 0;
  91. $categoryrequired = $_G['setting']['albumcategoryrequired'] && !empty($categorys) ? intval($_G['setting']['albumcategoryrequired']) : 0;
  92. } elseif($op == "screen" || $op == "doodle") {
  93. if(empty($GLOBALS['HTTP_RAW_POST_DATA'])) {
  94. $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents("php://input");
  95. }
  96. $status = "failure";
  97. $dosave = true;
  98. if($op == "doodle") {
  99. $magic = C::t('common_magic')->fetch_member_magic($_G['uid'], 'doodle');
  100. if(empty($magic) || $magic['num'] < 1) {
  101. $uploadfiles = -8;
  102. $dosave = false;
  103. }
  104. }
  105. if($dosave && !empty($GLOBALS['HTTP_RAW_POST_DATA'])) {
  106. $_SERVER['HTTP_ALBUMID'] = addslashes(diconv(urldecode($_SERVER['HTTP_ALBUMID']), 'UTF-8'));
  107. $from = false;
  108. if($op == 'screen') {
  109. $from = 'camera';
  110. } elseif($_GET['from'] == 'album') {
  111. $from = 'uploadimage';
  112. }
  113. $_G['setting']['allowwatermark'] = 0;
  114. $uploadfiles = stream_save($GLOBALS['HTTP_RAW_POST_DATA'], $_SERVER['HTTP_ALBUMID'], 'jpg', '', '', 0, $from);
  115. }
  116. $uploadResponse = true;
  117. $picid = $proid = $albumid = 0;
  118. if($uploadfiles && is_array($uploadfiles)) {
  119. $status = "success";
  120. $albumid = $uploadfiles['albumid'];
  121. $picid = $uploadfiles['picid'];
  122. if($op == "doodle") {
  123. $fileurl = pic_get($uploadfiles['filepath'], 'album', $uploadfiles['thumb'], $uploadfiles['remote'], 0);
  124. $remote = $uploadfiles['remote'] > 1 ? $uploadfiles['remote'] - 2 : $uploadfiles['remote'];
  125. if(!$remote) {
  126. if(!preg_match("/^http\:\/\//i", $fileurl)) {
  127. $fileurl = getsiteurl().$fileurl;
  128. }
  129. }
  130. require_once libfile('function/magic');
  131. usemagic($magic['magicid'], $magic['num'], 1);
  132. updatemagiclog($magic['magicid'], '2', '1', '0');
  133. if($albumid > 0) {
  134. album_update_pic($albumid);
  135. }
  136. }
  137. } else {
  138. switch ($uploadfiles) {
  139. case -1:
  140. $uploadfiles = lang('spacecp', 'inadequate_capacity_space');
  141. break;
  142. case -2:
  143. $uploadfiles = lang('spacecp', 'only_allows_upload_file_types');
  144. break;
  145. case -4:
  146. $uploadfiles = lang('spacecp', 'ftp_upload_file_size');
  147. break;
  148. case -8:
  149. $uploadfiles = lang('spacecp', 'has_not_more_doodle');
  150. break;
  151. default:
  152. $uploadfiles = lang('spacecp', 'mobile_picture_temporary_failure');
  153. break;
  154. }
  155. }
  156. } elseif($_FILES && $_POST) {
  157. if($_FILES["Filedata"]['error']) {
  158. $uploadfiles = lang('spacecp', 'file_is_too_big');
  159. } else {
  160. $_FILES["Filedata"]['name'] = addslashes(diconv(urldecode($_FILES["Filedata"]['name']), 'UTF-8'));
  161. $_POST['albumid'] = addslashes(diconv(urldecode($_POST['albumid']), 'UTF-8'));
  162. $catid = $_POST['catid'] ? intval($_POST['catid']) : 0;
  163. $uploadfiles = pic_save($_FILES["Filedata"], $_POST['albumid'], addslashes(diconv(urldecode($_POST['title']), 'UTF-8')), true, $catid);
  164. }
  165. $proid = $_POST['proid'];
  166. $uploadResponse = true;
  167. $albumid = 0;
  168. if($uploadfiles && is_array($uploadfiles)) {
  169. $status = "success";
  170. $albumid = $uploadfiles['albumid'];
  171. } else {
  172. $status = "failure";
  173. }
  174. }
  175. $newalbumname = dgmdate($_G['timestamp'], 'Ymd');
  176. include template("home/misc_swfupload");
  177. $outxml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  178. $outxml .= diconv(ob_get_contents(), $_G['charset'], 'UTF-8');
  179. obclean();
  180. @header("Expires: -1");
  181. @header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
  182. @header("Pragma: no-cache");
  183. @header("Content-type: application/xml; charset=utf-8");
  184. echo $outxml;
  185. ?>