spacecp_album.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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: spacecp_album.php 34045 2013-09-25 03:39:47Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $albumid = empty($_GET['albumid'])?0:intval($_GET['albumid']);
  12. $picid = empty($_GET['picid'])?0:intval($_GET['picid']);
  13. if($_GET['op'] == 'edit') {
  14. if($albumid < 1) {
  15. showmessage('photos_do_not_support_the_default_settings', "home.php?mod=spacecp&ac=album&uid=$_G[uid]&op=editpic&quickforward=1");
  16. }
  17. if(!$album = C::t('home_album')->fetch($albumid)) {
  18. showmessage('album_does_not_exist');
  19. }
  20. if($album['uid'] != $_G['uid'] && !checkperm('managealbum')) {
  21. showmessage('no_privilege_album_edit');
  22. }
  23. if(submitcheck('editsubmit')) {
  24. $_POST['albumname'] = getstr($_POST['albumname'], 50);
  25. $_POST['albumname'] = censor($_POST['albumname']);
  26. if(empty($_POST['albumname'])) {
  27. showmessage('album_name_errors');
  28. }
  29. $_POST['friend'] = intval($_POST['friend']);
  30. $_POST['target_ids'] = '';
  31. if($_POST['friend'] == 2) {
  32. $uids = array();
  33. $names = empty($_POST['target_names'])?array():explode(',', preg_replace("/(\s+)/s", ',', $_POST['target_names']));
  34. if($names) {
  35. $uids = C::t('common_member')->fetch_all_uid_by_username($names);
  36. }
  37. if(empty($uids)) {
  38. $_POST['friend'] = 3;
  39. } else {
  40. $_POST['target_ids'] = implode(',', $uids);
  41. }
  42. } elseif($_POST['friend'] == 4) {
  43. $_POST['password'] = trim($_POST['password']);
  44. if($_POST['password'] == '') $_POST['friend'] = 0;
  45. }
  46. if($_POST['friend'] !== 2) {
  47. $_POST['target_ids'] = '';
  48. }
  49. if($_POST['friend'] !== 4) {
  50. $_POST['password'] == '';
  51. }
  52. $_POST['catid'] = intval($_POST['catid']);
  53. if($_POST['catid'] != $album['catid']) {
  54. if($album['catid']) {
  55. C::t('home_album_category')->update_num_by_catid('-1', $album['catid'], true);
  56. }
  57. if($_POST['catid']) {
  58. C::t('home_album_category')->update_num_by_catid('1', $_POST['catid']);
  59. }
  60. }
  61. C::t('home_album')->update($albumid, array('albumname'=>$_POST['albumname'], 'catid'=>$_POST['catid'], 'friend'=>$_POST['friend'], 'password'=>$_POST['password'], 'target_ids'=>$_POST['target_ids'], 'depict'=>dhtmlspecialchars($_POST['depict'])));
  62. showmessage('spacecp_edit_ok', "home.php?mod=spacecp&ac=album&op=edit&albumid=$albumid");
  63. }
  64. $album['target_names'] = '';
  65. $friendarr = array($album['friend'] => ' selected');
  66. $passwordstyle = $selectgroupstyle = 'display:none';
  67. if($album['friend'] == 4) {
  68. $passwordstyle = '';
  69. } elseif($album['friend'] == 2) {
  70. $selectgroupstyle = '';
  71. if($album['target_ids']) {
  72. $names = array();
  73. foreach(C::t('common_member')->fetch_all($album['target_ids']) as $uid => $value) {
  74. $names[$uid] = $value['username'];
  75. }
  76. $album['target_names'] = implode(' ', $names);
  77. }
  78. }
  79. require_once libfile('function/friend');
  80. $groups = friend_group_list();
  81. if($_G['setting']['albumcategorystat']) {
  82. loadcache('albumcategory');
  83. $category = $_G['cache']['albumcategory'];
  84. $categoryselect = '';
  85. if($category) {
  86. $categoryselect = "<select id=\"catid\" name=\"catid\" width=\"120\"><option value=\"0\">------</option>";
  87. foreach ($category as $value) {
  88. if($value['level'] == 0) {
  89. $selected = $album['catid'] == $value['catid']?' selected':'';
  90. $categoryselect .= "<option value=\"$value[catid]\"{$selected}>$value[catname]</option>";
  91. if(!$value['children']) {
  92. continue;
  93. }
  94. foreach ($value['children'] as $catid) {
  95. $selected = $album['catid'] == $catid?' selected':'';
  96. $categoryselect .= "<option value=\"{$category[$catid][catid]}\"{$selected}>-- {$category[$catid][catname]}</option>";
  97. if($category[$catid]['children']) {
  98. foreach ($category[$catid]['children'] as $catid2) {
  99. $selected = $album['catid'] == $catid2?' selected':'';
  100. $categoryselect .= "<option value=\"{$category[$catid2][catid]}\"{$selected}>---- {$category[$catid2][catname]}</option>";
  101. }
  102. }
  103. }
  104. }
  105. }
  106. $categoryselect .= "</select>";
  107. }
  108. }
  109. } elseif($_GET['op'] == 'delete') {
  110. if(!$album = C::t('home_album')->fetch($albumid)) {
  111. showmessage('album_does_not_exist');
  112. }
  113. if($album['uid'] != $_G['uid'] && !checkperm('managealbum')) {
  114. showmessage('no_privilege_album_del');
  115. }
  116. $albums = getalbums($album['uid']);
  117. if(empty($albums[$albumid])) {
  118. showmessage('no_privilege_album_delother');
  119. }
  120. if(submitcheck('deletesubmit')) {
  121. $_POST['moveto'] = intval($_POST['moveto']);
  122. if($_POST['moveto'] < 0) {
  123. require_once libfile('function/delete');
  124. deletealbums(array($albumid));
  125. } else {
  126. if($_POST['moveto'] > 0 && $_POST['moveto'] != $albumid && !empty($albums[$_POST['moveto']])) {
  127. C::t('home_pic')->update_for_albumid($albumid, array('albumid'=>$_POST['moveto']));
  128. album_update_pic($_POST['moveto']);
  129. } else {
  130. C::t('home_pic')->update_for_albumid($albumid, array('albumid'=>0));
  131. }
  132. C::t('home_album')->delete($albumid);
  133. }
  134. showmessage('do_success', "home.php?mod=space&uid=$_GET[uid]&do=album&view=me");
  135. }
  136. } elseif($_GET['op'] == 'editpic') {
  137. $managealbum = checkperm('managealbum');
  138. require_once libfile('class/bbcode');
  139. if($albumid > 0) {
  140. if(!$album = C::t('home_album')->fetch($albumid)) {
  141. showmessage('album_does_not_exist', 'home.php?mod=space&uid='.$_G['uid'].'&do=album&view=me', array(), array('return' => true));
  142. }
  143. if($album['uid'] != $_G['uid'] && !$managealbum) {
  144. showmessage('no_privilege_pic_edit', 'home.php?mod=space&uid='.$_G['uid'].'&do=album&view=me', array(), array('return' => true));
  145. }
  146. } else {
  147. $album['uid'] = $_G['uid'];
  148. }
  149. if(submitcheck('editpicsubmit')) {
  150. $return = true;
  151. foreach ($_POST['title'] as $picid => $value) {
  152. if($value == $_GET['oldtitle'][$picid]) {
  153. continue;
  154. }
  155. $title = getstr($value, 150);
  156. $title = censor($title);
  157. if(censormod($title) || $_G['group']['allowuploadmod']) {
  158. $pic_status = 1;
  159. manage_addnotify('verifypic');
  160. } else {
  161. $pic_status = 0;
  162. }
  163. $wherearr = array('picid'=>$picid);
  164. if(!$managealbum) $wherearr['uid'] = $_G['uid'];
  165. C::t('home_pic')->update($picid, array('title'=>$title, 'status' => $pic_status));
  166. }
  167. if($_GET['subop'] == 'delete') {
  168. if($_POST['ids']) {
  169. require_once libfile('function/delete');
  170. deletepics($_POST['ids']);
  171. if($albumid > 0) $return = album_update_pic($albumid);
  172. }
  173. } elseif($_GET['subop'] == 'move') {
  174. if($_POST['ids']) {
  175. $sqluid = $managealbum ? '' : $_G['uid'];
  176. $_POST['newalbumid'] = intval($_POST['newalbumid']);
  177. if($_POST['newalbumid']) {
  178. if(!$album = C::t('home_album')->fetch($_POST['newalbumid'], $sqluid)) {
  179. $_POST['newalbumid'] = 0;
  180. }
  181. }
  182. if($managealbum) {
  183. $updatecount = C::t('home_pic')->update($_POST['ids'], array('albumid' => $_POST['newalbumid']));
  184. }else {
  185. $updatecount = C::t('home_pic')->update_for_uid($_G['uid'], $_POST['ids'], array('albumid' => $_POST['newalbumid']));
  186. }
  187. if($updatecount) {
  188. if($albumid>0) {
  189. C::t('home_album')->update_num_by_albumid($albumid, -$updatecount, 'picnum', $sqluid);
  190. $return = album_update_pic($albumid);
  191. }
  192. if($_POST['newalbumid']) {
  193. C::t('home_album')->update_num_by_albumid($_POST['newalbumid'], $updatecount, 'picnum', $sqluid);
  194. $return = album_update_pic($_POST['newalbumid']);
  195. }
  196. }
  197. }
  198. }
  199. $url = $return ? "home.php?mod=spacecp&ac=album&op=editpic&albumid=$albumid&page=$_POST[page]" : 'home.php?mod=space&uid='.$_G['uid'].'&do=album&view=me';
  200. if($_G['inajax']) {
  201. showmessage('do_success', $url, array('title' => $title), array('showdialog' => 3, 'showmsg' => true, 'closetime' => true));
  202. } else {
  203. showmessage('do_success', $url);
  204. }
  205. }
  206. $perpage = 10;
  207. $page = empty($_GET['page'])?0:intval($_GET['page']);
  208. if($page<1) $page = 1;
  209. $start = ($page-1)*$perpage;
  210. ckstart($start, $perpage);
  211. if($albumid > 0) {
  212. $count = $picid?1:$album['picnum'];
  213. } else {
  214. $count = C::t('home_pic')->fetch_all_by_albumid($albumid, 0, 0, $picid, 0, 0, $_G['uid'], true);
  215. }
  216. $list = array();
  217. if($count) {
  218. if($page > 1 && $start >=$count) {
  219. $page--;
  220. $start = ($page-1)*$perpage;
  221. }
  222. $bbcode = & bbcode::instance();
  223. $query = C::t('home_pic')->fetch_all_by_albumid($albumid, $start, $perpage, $picid, 0, 1, ($albumid > 0 ? 0 : $_G['uid']));
  224. foreach($query as $value) {
  225. if($picid) {
  226. $value['checked'] = ' checked';
  227. }
  228. $value['title'] = $bbcode->html2bbcode($value['title']);
  229. $value['pic'] = pic_get($value['filepath'], 'album', $value['thumb'], $value['remote']);
  230. $value['bigpic'] = pic_get($value['filepath'], 'album', $value['thumb'], $value['remote'], 0);
  231. $list[] = $value;
  232. }
  233. }
  234. $multi = multi($count, $perpage, $page, "home.php?mod=spacecp&ac=album&op=editpic&albumid=$albumid");
  235. $albumlist = getalbums($album['uid']);
  236. } elseif($_GET['op'] == 'setpic') {
  237. album_update_pic($albumid, $picid);
  238. showmessage('do_success', dreferer(), array('picid' => $picid), array('showmsg' => true, 'closetime' => true));
  239. } elseif($_GET['op'] == 'edittitle') {
  240. $picid = empty($_GET['picid'])?0:intval($_GET['picid']);
  241. $pic = C::t('home_pic')->fetch($picid);
  242. if(!checkperm('managealbum') && $pic['uid'] != $_G['uid']) {
  243. $pic = array();
  244. }
  245. } elseif($_GET['op'] == 'edithot') {
  246. if(!checkperm('managealbum')) {
  247. showmessage('no_privilege_edithot_album');
  248. }
  249. if(!$pic = C::t('home_pic')->fetch($picid)) {
  250. showmessage('image_does_not_exist');
  251. }
  252. if(submitcheck('hotsubmit')) {
  253. $_POST['hot'] = intval($_POST['hot']);
  254. C::t('home_pic')->update($picid, array('hot'=>$_POST['hot']));
  255. if($_POST['hot'] > 0) {
  256. require_once libfile('function/feed');
  257. feed_publish($picid, 'picid');
  258. } else {
  259. C::t('home_feed')->update($picid, array('hot'=>$_POST['hot']), 'picid');
  260. }
  261. showmessage('do_success', dreferer());
  262. }
  263. } elseif($_GET['op'] == 'saveforumphoto') {
  264. if(submitcheck('savephotosubmit')) {
  265. $aid = intval($_GET['aid']);
  266. $albumid = intval($_POST['albumid']);
  267. if(!$aid) {
  268. showmessage('parameters_error');
  269. }
  270. $attach = C::t('forum_attachment_n')->fetch('aid:'.$aid, $aid);
  271. if(empty($attach) || $attach['uid'] != $_G['uid'] || !$attach['isimage']) {
  272. showmessage('parameters_error');
  273. }
  274. if($albumid) {
  275. $album = C::t('home_album')->fetch($albumid, $_G['uid']);
  276. if(empty($album)) {
  277. showmessage('album_does_not_exist');
  278. }
  279. } else {
  280. $album = array('albumid' => 0);
  281. }
  282. $picdata = array(
  283. 'albumid' => $album['albumid'],
  284. 'uid' => $_G['uid'],
  285. 'username' => $_G['username'],
  286. 'dateline' => $attach['dateline'],
  287. 'postip' => $_G['clientip'],
  288. 'port' => $_G['remoteport'],
  289. 'filename' => censor($attach['filename']),
  290. 'title' => censor(cutstr(dhtmlspecialchars($attach['description']), 100)),
  291. 'type' => fileext($attach['attachment']),
  292. 'size' => $attach['filesize'],
  293. 'filepath' => $attach['attachment'],
  294. 'thumb' => $attach['thumb'],
  295. 'remote' => $attach['remote'] + 2
  296. );
  297. $picid = C::t('home_pic')->insert($picdata, 1);
  298. showmessage('do_success', dreferer(), array('picid' => $picid), array('showdialog'=>true, 'showmsg' => true, 'closetime' => true));
  299. } else {
  300. $albumlist = C::t('home_album')->fetch_all_by_uid($_G['uid'], 'updatetime');
  301. }
  302. }
  303. include_once template("home/spacecp_album");
  304. ?>