PageRenderTime 47ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/source/include/space/space_album.php

https://github.com/kuaileshike/upload
PHP | 455 lines | 361 code | 88 blank | 6 comment | 110 complexity | 7a0a853416dc3e8a5b6ad60617caea14 MD5 | raw file
  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: space_album.php 28299 2012-02-27 08:48:36Z svn_project_zhangjie $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $minhot = $_G['setting']['feedhotmin']<1?3:intval($_G['setting']['feedhotmin']);
  12. $id = empty($_GET['id'])?0:intval($_GET['id']);
  13. $picid = empty($_GET['picid'])?0:intval($_GET['picid']);
  14. $page = empty($_GET['page'])?1:intval($_GET['page']);
  15. if($page<1) $page=1;
  16. if($id) {
  17. $perpage = 20;
  18. $perpage = mob_perpage($perpage);
  19. $start = ($page-1)*$perpage;
  20. ckstart($start, $perpage);
  21. if($id > 0) {
  22. $album = C::t('home_album')->fetch($id, $space['uid']);
  23. if(empty($album)) {
  24. showmessage('to_view_the_photo_does_not_exist');
  25. }
  26. ckfriend_album($album);
  27. $album['picnum'] = $count = C::t('home_pic')->check_albumpic($id);
  28. if(empty($count) && !$space['self']) {
  29. C::t('home_album')->delete($id);
  30. showmessage('to_view_the_photo_does_not_exist', "home.php?mod=space&uid=$album[uid]&do=album&view=me");
  31. }
  32. if($album['catid']) {
  33. $album['catname'] = C::t('home_album_category')->fetch_catname_by_catid($album['catid']);
  34. $album['catname'] = dhtmlspecialchars($album['catname']);
  35. }
  36. } else {
  37. $count = C::t('home_pic')->check_albumpic(0, NULL, $space['uid']);
  38. $album = array(
  39. 'uid' => $space['uid'],
  40. 'albumid' => -1,
  41. 'albumname' => lang('space', 'default_albumname'),
  42. 'picnum' => $count
  43. );
  44. }
  45. $albumlist = array();
  46. $maxalbum = $nowalbum = $key = 0;
  47. $query = C::t('home_album')->fetch_all_by_uid($space['uid'], 'updatetime', 0, 100);
  48. foreach($query as $value) {
  49. if($value['friend'] != 4 && ckfriend($value['uid'], $value['friend'], $value['target_ids'])) {
  50. $value['pic'] = pic_cover_get($value['pic'], $value['picflag']);
  51. } elseif ($value['picnum']) {
  52. $value['pic'] = STATICURL.'image/common/nopublish.gif';
  53. } else {
  54. $value['pic'] = '';
  55. }
  56. $albumlist[$key][$value['albumid']] = $value;
  57. $key = count($albumlist[$key]) == 5 ? ++$key : $key;
  58. }
  59. $maxalbum = count($albumlist);
  60. $list = array();
  61. $pricount = 0;
  62. if($count) {
  63. $query = C::t('home_pic')->fetch_all_by_albumid($id, $start, $perpage, 0, 0, 1, $space['uid']);
  64. foreach($query as $value) {
  65. if($value['status'] == 0 || $value['uid'] == $_G['uid'] || $_G['adminid'] == 1) {
  66. $value['pic'] = pic_get($value['filepath'], 'album', $value['thumb'], $value['remote']);
  67. $list[] = $value;
  68. } else {
  69. $pricount++;
  70. }
  71. }
  72. }
  73. $multi = multi($count, $perpage, $page, "home.php?mod=space&uid=$album[uid]&do=$do&id=$id#comment");
  74. $actives = array('me' =>' class="a"');
  75. $_G['home_css'] = 'album';
  76. $diymode = intval($_G['cookie']['home_diymode']);
  77. $seodata = array('album' => $album['albumname'], 'user' => $album['username'], 'depict' => $album['depict']);
  78. list($navtitle, $metadescription, $metakeywords) = get_seosetting('album', $seodata);
  79. if(empty($navtitle)) {
  80. $navtitle = $album['albumname'].' - '.lang('space', 'sb_album', array('who' => $album['username']));
  81. $nobbname = false;
  82. } else {
  83. $nobbname = true;
  84. }
  85. if(empty($metakeywords)) {
  86. $metakeywords = $album['albumname'];
  87. }
  88. if(empty($metadescription)) {
  89. $metadescription = $album['albumname'];
  90. }
  91. include_once template("diy:home/space_album_view");
  92. } elseif ($picid) {
  93. $query = C::t('home_pic')->fetch_all_by_uid($space['uid'], 0, 1, $picid);
  94. $pic = $query[0];
  95. if(!$pic || ($pic['status'] == 1 && $pic['uid'] != $_G['uid'] && $_G['adminid'] != 1 && $_GET['modpickey'] != modauthkey($pic['picid']))) {
  96. showmessage('view_images_do_not_exist');
  97. }
  98. $picid = $pic['picid'];
  99. $theurl = "home.php?mod=space&uid=$pic[uid]&do=$do&picid=$picid";
  100. $album = array();
  101. if($pic['albumid']) {
  102. $album = C::t('home_album')->fetch($pic['albumid']);
  103. if(!$album) {
  104. C::t('home_pic')->update_for_albumid($pic['albumid'], array('albumid' => 0));
  105. }
  106. }
  107. if($album) {
  108. ckfriend_album($album);
  109. } else {
  110. $album['picnum'] = C::t('home_pic')->check_albumpic(0, NULL, $pic['uid']);
  111. $album['albumid'] = $pic['albumid'] = '-1';
  112. }
  113. $piclist = $list = $keys = array();
  114. $keycount = 0;
  115. $query = C::t('home_pic')->fetch_all_by_albumid($pic['albumid'], 0, 0, 0, 0, 1, $space['uid']);
  116. foreach($query as $value) {
  117. if($value['status'] == 0 || $value['uid'] == $_G['uid'] || $_G['adminid'] == 1) {
  118. $keys[$value['picid']] = $keycount;
  119. $list[$keycount] = $value;
  120. $keycount++;
  121. }
  122. }
  123. $upid = $nextid = 0;
  124. $nowkey = $keys[$picid];
  125. $endkey = $keycount - 1;
  126. if($endkey>4) {
  127. $newkeys = array($nowkey-2, $nowkey-1, $nowkey, $nowkey+1, $nowkey+2);
  128. if($newkeys[1] < 0) {
  129. $newkeys[0] = $endkey-1;
  130. $newkeys[1] = $endkey;
  131. } elseif($newkeys[0] < 0) {
  132. $newkeys[0] = $endkey;
  133. }
  134. if($newkeys[3] > $endkey) {
  135. $newkeys[3] = 0;
  136. $newkeys[4] = 1;
  137. } elseif($newkeys[4] > $endkey) {
  138. $newkeys[4] = 0;
  139. }
  140. $upid = $list[$newkeys[1]]['picid'];
  141. $nextid = $list[$newkeys[3]]['picid'];
  142. foreach ($newkeys as $nkey) {
  143. $piclist[$nkey] = $list[$nkey];
  144. }
  145. } else {
  146. $newkeys = array($nowkey-1, $nowkey, $nowkey+1);
  147. if($newkeys[0] < 0) {
  148. $newkeys[0] = $endkey;
  149. }
  150. if($newkeys[2] > $endkey) {
  151. $newkeys[2] = 0;
  152. }
  153. $upid = $list[$newkeys[0]]['picid'];
  154. $nextid = $list[$newkeys[2]]['picid'];
  155. $piclist = $list;
  156. }
  157. foreach ($piclist as $key => $value) {
  158. $value['pic'] = pic_get($value['filepath'], 'album', $value['thumb'], $value['remote']);
  159. $piclist[$key] = $value;
  160. }
  161. $pic['pic'] = pic_get($pic['filepath'], 'album', $pic['thumb'], $pic['remote'], 0);
  162. $pic['size'] = formatsize($pic['size']);
  163. $exifs = array();
  164. $allowexif = function_exists('exif_read_data');
  165. if(isset($_GET['exif']) && $allowexif) {
  166. require_once libfile('function/exif');
  167. $exifs = getexif($pic['pic']);
  168. }
  169. $perpage = 20;
  170. $perpage = mob_perpage($perpage);
  171. $start = ($page-1)*$perpage;
  172. ckstart($start, $perpage);
  173. $cid = empty($_GET['cid'])?0:intval($_GET['cid']);
  174. $siteurl = getsiteurl();
  175. $list = array();
  176. $count = C::t('home_comment')->count_by_id_idtype($pic['picid'], 'picid', $cid);
  177. if($count) {
  178. $query = C::t('home_comment')->fetch_all_by_id_idtype($pic['picid'], 'picid', $start, $perpage, $cid);
  179. foreach($query as $value) {
  180. $list[] = $value;
  181. }
  182. }
  183. $multi = multi($count, $perpage, $page, $theurl);
  184. if(empty($album['albumname'])) $album['albumname'] = lang('space', 'default_albumname');
  185. $pic_url = $pic['pic'];
  186. if(!preg_match("/^http\:\/\/.+?/i", $pic['pic'])) {
  187. $pic_url = getsiteurl().$pic['pic'];
  188. }
  189. $pic_url2 = rawurlencode($pic['pic']);
  190. $hash = md5($pic['uid']."\t".$pic['dateline']);
  191. $id = $pic['picid'];
  192. $idtype = 'picid';
  193. $maxclicknum = 0;
  194. loadcache('click');
  195. $clicks = empty($_G['cache']['click']['picid'])?array():$_G['cache']['click']['picid'];
  196. foreach ($clicks as $key => $value) {
  197. $value['clicknum'] = $pic["click{$key}"];
  198. $value['classid'] = mt_rand(1, 4);
  199. if($value['clicknum'] > $maxclicknum) $maxclicknum = $value['clicknum'];
  200. $clicks[$key] = $value;
  201. }
  202. $clickuserlist = array();
  203. foreach(C::t('home_clickuser')->fetch_all_by_id_idtype($id, $idtype, 0, 20) as $value) {
  204. $value['clickname'] = $clicks[$value['clickid']]['name'];
  205. $clickuserlist[] = $value;
  206. }
  207. $actives = array('me' =>' class="a"');
  208. if($album['picnum']) {
  209. $sequence = $nowkey + 1;
  210. }
  211. $diymode = intval($_G['cookie']['home_diymode']);
  212. $navtitle = $album['albumname'];
  213. if($pic['title']) {
  214. $navtitle = $pic['title'].' - '.$navtitle;
  215. }
  216. $metakeywords = $pic['title'] ? $pic['title'] : $album['albumname'];
  217. $metadescription = $pic['title'] ? $pic['title'] : $albumname['albumname'];
  218. include_once template("diy:home/space_album_pic");
  219. } else {
  220. loadcache('albumcategory');
  221. $category = $_G['cache']['albumcategory'];
  222. $perpage = 20;
  223. $perpage = mob_perpage($perpage);
  224. $start = ($page-1)*$perpage;
  225. ckstart($start, $perpage);
  226. $_GET['friend'] = intval($_GET['friend']);
  227. $default = array();
  228. $f_index = '';
  229. $list = array();
  230. $pricount = 0;
  231. $picmode = 0;
  232. if(empty($_GET['view'])) {
  233. $_GET['view'] = 'we';
  234. }
  235. $gets = array(
  236. 'mod' => 'space',
  237. 'uid' => $space['uid'],
  238. 'do' => 'album',
  239. 'view' => $_GET['view'],
  240. 'catid' => $_GET['catid'],
  241. 'order' => $_GET['order'],
  242. 'fuid' => $_GET['fuid'],
  243. 'searchkey' => $_GET['searchkey'],
  244. 'from' => $_GET['from']
  245. );
  246. $theurl = 'home.php?'.url_implode($gets);
  247. $actives = array($_GET['view'] =>' class="a"');
  248. $need_count = true;
  249. if($_GET['view'] == 'all') {
  250. $wheresql = '1';
  251. if($_GET['order'] == 'hot') {
  252. $orderactives = array('hot' => ' class="a"');
  253. $picmode = 1;
  254. $need_count = false;
  255. $ordersql = 'p.dateline';
  256. $count = C::t('home_pic')->fetch_all_by_sql('p.'.DB::field('hot', $minhot, '>='), '', 0, 0, 1);
  257. if($count) {
  258. $query = C::t('home_pic')->fetch_all_by_sql('p.'.DB::field('hot', $minhot, '>='), 'p.dateline DESC', $start, $perpage);
  259. foreach($query as $value) {
  260. if($value['friend'] != 4 && ckfriend($value['uid'], $value['friend'], $value['target_ids']) && ($value['status'] == 0 || $value['uid'] == $_G['uid'] || $_G['adminid'] == 1)) {
  261. $value['pic'] = pic_get($value['filepath'], 'album', $value['thumb'], $value['remote']);
  262. $list[] = $value;
  263. } else {
  264. $pricount++;
  265. }
  266. }
  267. }
  268. } else {
  269. $orderactives = array('dateline' => ' class="a"');
  270. }
  271. } elseif($_GET['view'] == 'we') {
  272. space_merge($space, 'field_home');
  273. $uids = array();
  274. if($space['feedfriend']) {
  275. $uids = explode(',', $space['feedfriend']);
  276. $f_index = 'updatetime';
  277. $fuid_actives = array();
  278. require_once libfile('function/friend');
  279. $fuid = intval($_GET['fuid']);
  280. if($fuid && friend_check($fuid)) {
  281. $uids = array($fuid);
  282. $f_index = '';
  283. $fuid_actives = array($fuid=>' selected');
  284. }
  285. $query = C::t('home_friend')->fetch_all_by_uid($space['uid'], 0, 500, true);
  286. foreach($query as $value) {
  287. $userlist[] = $value;
  288. }
  289. } else {
  290. $need_count = false;
  291. }
  292. } else {
  293. if($_GET['from'] == 'space') $diymode = 1;
  294. $uids = array($space['uid']);
  295. }
  296. if($need_count) {
  297. if($searchkey = stripsearchkey($_GET['searchkey'])) {
  298. $sqlSearchKey = $searchkey;
  299. $searchkey = dhtmlspecialchars($searchkey);
  300. }
  301. $catid = empty($_GET['catid'])?0:intval($_GET['catid']);
  302. $count = C::t('home_album')->fetch_all_by_search(3, $uids, $sqlSearchKey, true, $catid, 0, 0, '');
  303. if($count) {
  304. $query = C::t('home_album')->fetch_all_by_search(1, $uids, $sqlSearchKey, true, $catid, 0, 0, '', '', 'updatetime', 'DESC', $start, $perpage, $f_index);
  305. foreach($query as $value) {
  306. if($value['friend'] != 4 && ckfriend($value['uid'], $value['friend'], $value['target_ids'])) {
  307. $value['pic'] = pic_cover_get($value['pic'], $value['picflag']);
  308. } elseif ($value['picnum']) {
  309. $value['pic'] = STATICURL.'image/common/nopublish.gif';
  310. } else {
  311. $value['pic'] = '';
  312. }
  313. $list[] = $value;
  314. }
  315. }
  316. }
  317. $multi = multi($count, $perpage, $page, $theurl);
  318. dsetcookie('home_diymode', $diymode);
  319. if($_G['uid']) {
  320. if($_GET['view'] == 'all') {
  321. $navtitle = lang('core', 'title_view_all').lang('core', 'title_album');
  322. } elseif($_GET['view'] == 'me') {
  323. $navtitle = lang('core', 'title_my_album');
  324. } else {
  325. $navtitle = lang('core', 'title_friend_album');
  326. }
  327. } else {
  328. if($_GET['order'] == 'hot') {
  329. $navtitle = lang('core', 'title_hot_pic_recommend');
  330. } else {
  331. $navtitle = lang('core', 'title_newest_update_album');
  332. }
  333. }
  334. if($space['username']) {
  335. $navtitle = lang('space', 'sb_album', array('who' => $space['username']));
  336. }
  337. $metakeywords = $navtitle;
  338. $metadescription = $navtitle;
  339. include_once template("diy:home/space_album_list");
  340. }
  341. function ckfriend_album($album) {
  342. global $_G, $space;
  343. if($_G['adminid'] != 1) {
  344. if(!ckfriend($album['uid'], $album['friend'], $album['target_ids'])) {
  345. if(empty($_G['uid'])) {
  346. showmessage('to_login', null, array(), array('showmsg' => true, 'login' => 1));
  347. }
  348. require_once libfile('function/friend');
  349. $isfriend = friend_check($album['uid']);
  350. space_merge($space, 'count');
  351. space_merge($space, 'profile');
  352. $_G['privacy'] = 1;
  353. require_once libfile('space/profile', 'include');
  354. include template('home/space_privacy');
  355. exit();
  356. } elseif(!$space['self'] && $album['friend'] == 4) {
  357. $cookiename = "view_pwd_album_$album[albumid]";
  358. $cookievalue = empty($_G['cookie'][$cookiename])?'':$_G['cookie'][$cookiename];
  359. if($cookievalue != md5(md5($album['password']))) {
  360. $invalue = $album;
  361. include template('home/misc_inputpwd');
  362. exit();
  363. }
  364. }
  365. }
  366. }
  367. ?>