PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/apps/photos/admin/manage.php

https://bitbucket.org/johnroyer/phpwind8.7
PHP | 308 lines | 280 code | 24 blank | 4 comment | 96 complexity | e69e347c46edf3e9631b1e13b8ddd803 MD5 | raw file
  1. <?php
  2. !function_exists('adminmsg') && exit('Forbidden');
  3. //* @include_once pwCache::getPath(D_P.'data/bbscache/o_config.php');
  4. pwCache::getData(D_P.'data/bbscache/o_config.php');
  5. !$action && $action = 'albums';
  6. if ($action == 'albums') {
  7. if ($job == 'delete') {
  8. S::gp(array('selid','aname','owner','crtime_s','crtime_e','lasttime_s','lasttime_e','private','lines','orderway','ordertype'));
  9. empty($selid) && adminmsg("no_album_selid", "$basename&action=albums");
  10. require_once(R_P . 'u/require/core.php');
  11. foreach ($selid as $key => $aid) {
  12. $query = $db->query("SELECT cn.pid,cn.path,cn.ifthumb,ca.ownerid FROM pw_cnphoto cn LEFT JOIN pw_cnalbum ca ON cn.aid=ca.aid WHERE cn.aid=" . S::sqlEscape($aid));
  13. if (($num = $db->num_rows($query)) > 0) {
  14. $affected_rows = 0;
  15. while ($rt = $db->fetch_array($query)) {
  16. $uids[] = $rt['ownerid'];
  17. pwDelatt($rt['path'], $db_ifftp);
  18. if ($rt['ifthumb']) {
  19. $lastpos = strrpos($rt['path'],'/') + 1;
  20. pwDelatt(substr($rt['path'], 0, $lastpos) . 's_' . substr($rt['path'], $lastpos), $db_ifftp);
  21. }
  22. $affected_rows += delAppAction('photo',$rt['pid'])+1;//TODO 效率?
  23. }
  24. pwFtpClose($ftp);
  25. countPosts("-$affected_rows");
  26. }
  27. $db->update("DELETE FROM pw_cnphoto WHERE aid=" . S::sqlEscape($aid));
  28. $db->update("DELETE FROM pw_cnalbum WHERE aid=" . S::sqlEscape($aid));
  29. }
  30. $uids = array_unique($uids);
  31. updateUserAppNum($uids,'photo','recount');
  32. adminmsg('operate_success',"$basename&action=albums&job=list&aname=".rawurlencode($aname)."&owner=".rawurlencode($owner)."&crtime_s=$crtime_s&crtime_e=$crtime_e&lasttime_s=$lasttime_s&lasttime_e=$lasttime_e&private=$private&lines=$lines&orderway=$orderway&ordertype=$ordertype&page=$page&");
  33. } elseif ($job == 'edit') {
  34. S::gp(array('aid'));
  35. $album = $db->get_one("SELECT * FROM pw_cnalbum WHERE aid=".S::sqlEscape($aid));
  36. empty($album) && Showmsg('album_not_exist',"$basename&action=albums");
  37. if (empty($_POST['step'])) {
  38. S::gp(array('aname','owner','crtime_s','crtime_e','lasttime_s','lasttime_e','private','lines','orderway','ordertype','page'));
  39. ${'private_'.$album['private']} = 'selected';
  40. require_once PrintApp('admin');
  41. } else {
  42. S::gp(array('aname','aintro','private','pwd','repwd'));
  43. S::gp(array('url_aname','url_owner','url_crtime_s','url_crtime_e','url_lasttime_s','url_lasttime_e','url_private','url_lines','url_orderway','url_ordertype','url_page'));
  44. //密碼情況
  45. if ($pwd) {
  46. if (strlen($pwd) < 3 || strlen($pwd) > 15) {
  47. Showmsg('photo_password_minlimit');
  48. }
  49. $S_key = array("\\",'&',' ',"'",'"','/','*',',','<','>',"\r","\t","\n",'#','%','?');
  50. if (str_replace($S_key,'',$pwd) != $pwd) {
  51. Showmsg('illegal_password');
  52. }
  53. if ($pwd != $repwd) {
  54. Showmsg('password_confirm');
  55. }
  56. $pwd = md5($pwd);
  57. $sqlArr = array('aname' => $aname,'aintro' => $aintro, 'private' => $private, 'albumpwd'=>$pwd);
  58. } else {
  59. $sqlArr = array('aname' => $aname,'aintro' => $aintro, 'private' => $private);
  60. }
  61. $db->update("UPDATE pw_cnalbum SET ".S::sqlSingle($sqlArr)." WHERE aid=".S::sqlEscape($aid));
  62. adminmsg('operate_success',"$basename&action=albums&job=list&aname=".rawurlencode($url_aname)."&owner=".rawurlencode($url_owner)."&crtime_s=$url_crtime_s&crtime_e=$url_crtime_e&lasttime_s=$url_lasttime_s&lasttime_e=$url_lasttime_e&private=$url_private&lines=$url_lines&orderway=$url_orderway&ordertype=$url_ordertype&page=$url_page&");
  63. }
  64. } else {
  65. S::gp(array('aname','owner','crtime_s','crtime_e','lasttime_s','lasttime_e','private','lines','orderway','ordertype','page', 'searchDisplay'));
  66. $photoPrivateSelection = array(
  67. '-1'=>'不限制',
  68. '0'=>'全站可見',
  69. '1'=>'僅好友可見',
  70. '2'=>'僅自己可見',
  71. '3'=>'需要密碼訪問',
  72. );
  73. $photoPrivateSelection = formSelect('private', $private, $photoPrivateSelection, 'class="select_wa"');
  74. $orderBySelection = array(
  75. 'crtime'=>'按發表時間排序',
  76. 'lasttime'=>'最後更新時間',
  77. );
  78. $orderBySelection = formSelect('orderway', $orderway, $orderBySelection, 'class="select_wa fl mr20"');
  79. $crttimeStartString = $crtime_s && is_numeric($crtime_s) ? get_date($crtime_s, 'Y-m-d') : $crtime_s;
  80. $crttimeEndString = $crtime_e && is_numeric($crtime_e) ? get_date($crtime_e, 'Y-m-d') : $crtime_e;
  81. $lasttimeStartString = $lasttime_s && is_numeric($lasttime_s) ? get_date($lasttime_s, 'Y-m-d') : $lasttime_s;
  82. $lasttimeEndString = $lasttime_e && is_numeric($lasttime_e) ? get_date($lasttime_e, 'Y-m-d') : $lasttime_e;
  83. $lines = $lines <= 0 ? 30 : $lines;
  84. $private = null === $private ? -1 : $private;
  85. null === $searchDisplay && $searchDisplay = 'none';
  86. $ascChecked = $ordertype == 'asc' ? 'checked' : '';
  87. $descChecked = !$ascChecked ? 'checked' : '';
  88. $albumdb = array();
  89. if (empty($aname) && empty($owner) && empty($crtime_s) && empty($crtime_e) && empty($lasttime_s) && empty($lasttime_e) && ($private == '-1')) {
  90. $noticeMessage = getLangInfo('cpmsg', 'noenough_condition');
  91. } else {
  92. $encode_aname = rawurlencode($aname);
  93. $encode_owner = rawurlencode($owner);
  94. $crtime_s && !is_numeric($crtime_s) && $crtime_s = PwStrtoTime($crtime_s);
  95. $crtime_e && !is_numeric($crtime_e) && $crtime_e = PwStrtoTime($crtime_e);
  96. $crtime_e && $sqlcrtime_e = $crtime_e + 86400;
  97. $lasttime_s && !is_numeric($lasttime_s) && $lasttime_s = PwStrtoTime($lasttime_s);
  98. $lasttime_e && !is_numeric($lasttime_e) && $lasttime_e = PwStrtoTime($lasttime_e);
  99. $lasttime_e && $sqllasttime_e = $lasttime_e + 86400;
  100. $sql = "atype='0'";
  101. $urladd = '';
  102. if ($aname) {
  103. $aname = str_replace('*','%',$aname);
  104. $sql .= ' AND aname LIKE '.S::sqlEscape($aname);
  105. $urladd .= '&aname='.rawurlencode($aname);
  106. }
  107. if ($owner) {
  108. $owner = str_replace('*','%',$owner);
  109. $sql .= ' AND owner LIKE '.S::sqlEscape($owner);
  110. $urladd .= '&owner='.rawurlencode($owner);
  111. }
  112. if ($crtime_s) {
  113. $sql .= ' AND crtime>='.S::sqlEscape($crtime_s);
  114. $urladd .= "&crtime_s=$crtime_s";
  115. }
  116. if ($crtime_e) {
  117. $sql .= ' AND crtime<='.S::sqlEscape($sqlcrtime_e);
  118. $urladd .= "&crtime_e=$crtime_e";
  119. }
  120. if ($lasttime_s) {
  121. $sql .= ' AND lasttime>='.S::sqlEscape($lasttime_s);
  122. $urladd .= "&lasttime_s=$lasttime_s";
  123. }
  124. if ($lasttime_e) {
  125. $sql .= ' AND lasttime<='.S::sqlEscape($sqllasttime_e);
  126. $urladd .= "&lasttime_e=$lasttime_e";
  127. }
  128. if ($private != -1) {
  129. $sql .= ' AND private='.S::sqlEscape($private);
  130. $urladd .= "&private=$private";
  131. }
  132. $orderway = $orderway == 'crtime' ? 'crtime' : 'lasttime';
  133. $ordertype = $ordertype == 'asc' ? 'asc' : 'desc';
  134. $urladd .= "&orderway=$orderway&ordertype=$ordertype&lines=$lines&searchDisplay=$searchDisplay";
  135. $count = $db->get_value("SELECT COUNT(*) AS count FROM pw_cnalbum WHERE $sql");
  136. //empty($count) && adminmsg('album_not_exist',"$basename&action=albums");
  137. !is_numeric($lines) && $lines=30;
  138. $page < 1 && $page = 1;
  139. $numofpage = ceil($count/$lines);
  140. if ($numofpage && $page > $numofpage) {
  141. $page = $numofpage;
  142. }
  143. $pages=numofpage($count,$page,$numofpage,"$basename&action=$action&job=list$urladd&");
  144. $start = ($page-1)*$lines;
  145. $limit = S::sqlLimit($start,$lines);
  146. $query = $db->query("SELECT aid,aname,private,ownerid,owner,photonum,lasttime,lastpid,crtime FROM pw_cnalbum WHERE $sql "."ORDER BY $orderway $ordertype ".$limit);
  147. while ($rt = $db->fetch_array($query)) {
  148. $rt['s_aname'] = substrs($rt['aname'],30);
  149. $rt['lasttime'] = $rt['lasttime'] ? get_date($rt['lasttime']) : '-';
  150. $rt['crtime'] = $rt['crtime'] ? get_date($rt['crtime']) : '-';
  151. $albumdb[] = $rt;
  152. }
  153. }
  154. $aname = str_replace('%', '*', $aname);
  155. $owner = str_replace('%', '*', $owner);
  156. require_once PrintApp('admin');
  157. }
  158. } elseif ($action == 'photos') {
  159. ${'ordertypedesc'} = 'checked';
  160. if ($job == 'delete') {
  161. S::gp(array('aid','aname','uploader','pintro','uptime_s','uptime_e','orderway','ordertype','lines','page','selid'));
  162. require_once(R_P . 'u/require/core.php');
  163. foreach ($selid as $key => $pid) {
  164. $photo = $db->get_one("SELECT cp.path,ca.aid,ca.lastphoto,ca.lastpid,ca.ownerid FROM pw_cnphoto cp LEFT JOIN pw_cnalbum ca ON cp.aid=ca.aid WHERE cp.pid=" . S::sqlEscape($pid) . " AND ca.atype='0'");
  165. if (empty($photo)) {
  166. adminmsg('data_error',"$basename&action=photos");
  167. }
  168. $uids[] = $photo['ownerid'];
  169. $db->update("DELETE FROM pw_cnphoto WHERE pid=" . S::sqlEscape($pid));
  170. $pwSQL = array();
  171. if ($photo['path'] == $photo['lastphoto']) {
  172. $pwSQL['lastphoto'] = $db->get_value("SELECT path FROM pw_cnphoto WHERE aid=" . S::sqlEscape($photo['aid']) . " ORDER BY pid DESC LIMIT 1");
  173. }
  174. if (strpos(",$photo[lastpid],",",$pid,") !== false) {
  175. $pwSQL['lastpid'] = implode(',',getLastPid($photo['aid']));
  176. }
  177. $upsql = $pwSQL ? ',' . S::sqlSingle($pwSQL) : '';
  178. $db->update("UPDATE pw_cnalbum SET photonum=photonum-1{$upsql} WHERE aid=" . S::sqlEscape($photo['aid']));
  179. pwDelatt($photo['path'], $db_ifftp);
  180. $lastpos = strrpos($photo['path'],'/') + 1;
  181. pwDelatt(substr($photo['path'], 0, $lastpos) . 's_' . substr($photo['path'], $lastpos), $db_ifftp);
  182. pwFtpClose($ftp);
  183. $affected_rows = delAppAction('photo',$pid) + 1;
  184. countPosts("-$affected_rows");
  185. }
  186. $uids = array_unique($uids);
  187. updateUserAppNum($uids,'photo','recount');
  188. adminmsg('operate_success',"$basename&action=photos&job=list&aid=$aid&aname=".rawurlencode($aname)."&uploader=".rawurlencode($uploader)."&pintro=".rawurlencode($pintro)."&uptime_s=$uptime_s&uptime_e=$uptime_e&orderway=$orderway&ordertype=$ordertype&lines=$lines&page=$page&");
  189. } else {
  190. require_once(R_P . 'u/require/core.php');
  191. S::gp(array('aid','aname','uploader','pintro','uptime_s','uptime_e','orderway','ordertype','lines','page'));
  192. $cnpho = array();
  193. $orderBySelection = array(
  194. 'default'=>'默認排序',
  195. 'uptime'=>'上傳日期',
  196. 'hits'=>'瀏覽數',
  197. 'c_num'=>'評論數',
  198. );
  199. $orderBySelection = formSelect('orderway', $orderway, $orderBySelection, 'class="select_wa fl mr20"');
  200. $uptimeStartString = $uptime_s && is_numeric($uptime_s) ? get_date($uptime_s, 'Y-m-d') : $uptime_s;
  201. $uptimeEndString = $uptime_e && is_numeric($uptime_e) ? get_date($uptime_e, 'Y-m-d') : $uptime_e;
  202. !is_numeric($lines) && $lines = 30;
  203. if (empty($aid) && empty($aname) && empty($uploader) && empty($pintro) && empty($uptime_s) && empty($uptime_e)) {
  204. $noticeMessage = getLangInfo('cpmsg', 'noenough_condition');
  205. } else {
  206. $uptime_s=$uptime_s && !is_numeric($uptime_s) ? PwStrtoTime($uptime_s):$uptime_s;
  207. $uptime_e=$uptime_e && !is_numeric($uptime_e) ? PwStrtoTime($uptime_e):$uptime_e;
  208. $uptime_e && $sqluptime_e = $uptime_e + 86400;
  209. $urladd = '';
  210. $sql = "ca.atype='0'";
  211. if ($aid) {
  212. $sql .= ' AND ca.aid ='.S::sqlEscape($aid);
  213. $urladd .= '&aid='.$aid;
  214. }
  215. if ($aname) {
  216. $aname = str_replace('*','%',$aname);
  217. $sql .= ' AND ca.aname LIKE '.S::sqlEscape($aname);
  218. $urladd .= '&aname='.rawurlencode($aname);
  219. }
  220. if ($uploader) {
  221. $uploader = str_replace('*','%',$uploader);
  222. $sql .= ' AND cp.uploader LIKE '.S::sqlEscape($uploader);
  223. $urladd .= '&uploader='.rawurlencode($uploader);
  224. }
  225. if ($pintro) {
  226. $pintro = str_replace('*','%',$pintro);
  227. $sql .= ' AND cp.pintro LIKE '.S::sqlEscape($pintro);
  228. $urladd .= '&pintro='.rawurlencode($pintro);
  229. }
  230. if ($uptime_s) {
  231. $sql .= ' AND cp.uptime>='.S::sqlEscape($uptime_s);
  232. $urladd .= "&uptime_s=$uptime_s";
  233. }
  234. if ($uptime_e) {
  235. $sql .= ' AND cp.uptime<='.S::sqlEscape($sqluptime_e);
  236. $urladd .= "&uptime_e=$uptime_e";
  237. }
  238. switch ($orderway) {
  239. case 'uptime' :
  240. $orderway = 'cp.uptime';
  241. $orderwayurl = 'uptime';
  242. break;
  243. case 'hits' :
  244. $orderway = 'cp.hits';
  245. $orderwayurl = 'hits';
  246. break;
  247. case 'c_num' :
  248. $orderway = 'cp.c_num';
  249. $orderwayurl = 'c_num';
  250. break;
  251. default:
  252. $orderway = '';break;
  253. }
  254. ${'ordertypedesc'} = '';
  255. $ordertype == 'asc' ? 'asc' : 'desc';
  256. ${'ordertype'.$ordertype} = 'checked';
  257. $sqladd = $orderway ? "ORDER BY $orderway $ordertype" : '';
  258. $urladd .= $orderwayurl ? "&orderway=$orderwayurl&ordertype=$ordertype" : '';
  259. $count = $db->get_value("SELECT COUNT(*) AS count FROM pw_cnphoto cp LEFT JOIN pw_cnalbum ca ON cp.aid=ca.aid WHERE $sql");
  260. //empty($count) && adminmsg('no_photos',"$basename&action=photos&job=list");
  261. $page < 1 && $page = 1;
  262. $numofpage = ceil($count/$lines);
  263. if ($numofpage && $page > $numofpage) {
  264. $page = $numofpage;
  265. }
  266. $pages=numofpage($count,$page,$numofpage,"$basename&action=$action&job=list&lines=$lines$urladd&");
  267. $start = ($page-1)*$lines;
  268. $limit = S::sqlLimit($start,$lines);
  269. $query = $db->query("SELECT cp.pid,cp.aid,cp.path,cp.uploader,cp.uptime,cp.ifthumb,cp.hits,cp.c_num,ca.aname FROM pw_cnphoto cp LEFT JOIN pw_cnalbum ca ON cp.aid=ca.aid WHERE ".$sql." ".$sqladd." ".$limit);
  270. $cnpho = array();
  271. while ($rt = $db->fetch_array($query)) {
  272. $rt['s_aname'] = substrs($rt['aname'],10);
  273. $rt['path'] = getphotourl($rt['path'], $rt['ifthumb']);
  274. $rt['uptime'] = get_date($rt['uptime']);
  275. $cnpho[] = $rt;
  276. }
  277. $aname = str_replace('%', '*', $aname);
  278. $uploader = str_replace('%', '*', $uploader);
  279. $pintro = str_replace('%', '*', $pintro);
  280. }
  281. require_once PrintApp('admin');
  282. }
  283. }
  284. ?>