PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/apps/collection/action/my.php

https://bitbucket.org/johnroyer/phpwind8.7
PHP | 186 lines | 163 code | 12 blank | 11 comment | 29 complexity | 577270c8cb4f2b3d05a4a533ec4412e7 MD5 | raw file
  1. <?php
  2. !defined('A_P') && exit('Forbidden');
  3. $USCR = 'user_collection';
  4. $baseUrl = 'apps.php?';
  5. $basename = 'apps.php?q='.$q.'&';
  6. S::gp(array('see', 'job'));
  7. $collectionService = L::loadClass('Collection', 'collection'); /* @var $collectionService PW_Collection */
  8. $db_perpage = 20;
  9. $a = $a ? $a : 'list';
  10. S::gp(array('type','ftype'));
  11. if ($a == 'list') {
  12. $collectionTypeService = L::loadClass('CollectionTypeService', 'collection');
  13. $ftypeid = array();
  14. $ftypeNum = array();
  15. $ftypeSelection = array();
  16. $ftypeNumTotal = 0;
  17. $ftypeData = $collectionTypeService->getTypesByUid($winduid);
  18. $collectionService = L::loadClass('Collection', 'collection'); /* @var $collection PW_Collection */
  19. $typeNumArr = $collectionService->countTypesByUid($winduid);
  20. if (!is_array($typeNumArr)) $typeNumArr = array();
  21. $defaultNum = ($typeNumArr[-1] ) ? $typeNumArr[-1] : 0;
  22. $ftypeNumTotal = $defaultNum;
  23. foreach ($ftypeData as $val) {
  24. $ftypeid[$val['ctid']] = $val['name'];
  25. $ftypeNum[$val['ctid']] = ($typeNumArr[$val['ctid']]) ? $typeNumArr[$val['ctid']] : 0;
  26. $ftypeNumTotal = $ftypeNumTotal + $ftypeNum[$val['ctid']];
  27. }
  28. foreach ($ftypeid as $k => $v) {
  29. $ftypeSelection[$k] = $v;
  30. }
  31. !$ftype && $ftype = 'all';
  32. $count = !$type ? $collectionService->countByUid($winduid,$ftype) : $collectionService->countByUidAndType($winduid,$type,$ftype);
  33. $page > ceil($count/$db_perpage) && $page = ceil($count/$db_perpage);
  34. $collectionDb = ($count) ? (!$type ? $collectionService->findByUidInPage($winduid, $page, $db_perpage, $ftype) : $collectionService->findByUidAndTypeInPage($winduid, $type, $page, $db_perpage, $ftype)) : array();
  35. $pages = numofpage($count,$page,ceil($count/$db_perpage),"{$basename}type=$type&ftype=$ftype&");
  36. } elseif ($a == 'post') {
  37. $totalCollection = $collectionService->countByUid($winduid);
  38. $totalCollection >= $_G['maxfavor'] && Showmsg('已達到用戶組允許的收藏上限');
  39. PostCheck();
  40. S::gp(array('link'),'P',1);
  41. $link = str_replace('&#61;','=',$link);
  42. !$link && Showmsg('鏈接地址不能為空');
  43. !preg_match("/^https?\:\/\/.{4,255}$/i", $link) && Showmsg('mode_share_link_error');
  44. $share['uid'] = $winduid;
  45. $share['username'] = $windid;
  46. $share['link'] = $link;
  47. $parselink = parse_url($link);
  48. if(preg_match("/(youku.com|youtube.com|sohu.com|sina.com.cn)$/i",$parselink['host'],$hosts)) {
  49. $hash = getVideo($link,$hosts[1]);
  50. if(!empty($hash)) {
  51. $type = "multimedia";
  52. $share['type'] = 'video';
  53. $share['video']['hash'] = $f_hash = $hash;
  54. $share['video']['host'] = $hosts[1];
  55. } else {
  56. //$type = "multimedia";
  57. $type = $share['type'] = 'web';
  58. }
  59. if (preg_match("/\.swf\??.*$/i",$link)) {
  60. $type = "multimedia";
  61. $share['type'] = 'flash';
  62. $f_hash = $share['link'];
  63. }
  64. } elseif (preg_match("/\.(mp3|wma)\??.*$/i",$link)) {
  65. $type = "multimedia";
  66. $share['type'] = 'music';
  67. $f_hash = $share['link'];
  68. } elseif (preg_match("/\.swf\??.*$/i",$link)) {
  69. $type = "multimedia";
  70. $share['type'] = 'flash';
  71. $f_hash = $share['link'];
  72. } else {
  73. $type = $share['type'] = 'web';
  74. }
  75. $collectionDate = array(
  76. 'type' => $type,
  77. 'uid' => $winduid,
  78. 'username' => $windid,
  79. 'content' => serialize($share),
  80. 'postdate' => $timestamp
  81. );
  82. if ($collectionService->insert($collectionDate)) {
  83. refreshto("{$basename}&",'operate_success');
  84. } else {
  85. Showmsg('data_error');
  86. }
  87. } elseif($a == 'dels') {
  88. PostCheck();
  89. S::gp(array('idarray'),'P',1);
  90. $ids = $collectionService->checkCollectionIds($idarray,$winduid);
  91. $collectionService->delete($ids);
  92. refreshto("{$basename}type={$type}&",'operate_success');
  93. } elseif($a == 'remove') {
  94. S::gp(array('ftype','idarray'));
  95. !$idarray && Showmsg('undefined_action');
  96. $return = $collectionService->remove($idarray,$ftype);
  97. if($return === true) {
  98. echo "success\t";ajax_footer();
  99. }
  100. } elseif ($a == 'recommend') {
  101. define('AJAX',1);
  102. define('F_M',true);
  103. if (empty($_POST['step'])) {
  104. S::gp(array('id'), null, 2);
  105. $friend = getFriends($winduid);
  106. if ($friend) {
  107. foreach ($friend as $key => $value) {
  108. $frienddb[$value['ftid']][] = $value;
  109. }
  110. }
  111. $query = $db->query("SELECT * FROM pw_friendtype WHERE uid=".S::sqlEscape($winduid)." ORDER BY ftid");
  112. $friendtype = array();
  113. while ($rt = $db->fetch_array($query)) {
  114. $friendtype[$rt['ftid']] = $rt;
  115. }
  116. $no_group_name = getLangInfo('other','no_group_name');
  117. $friendtype[0] = array('ftid' => 0,'uid' => $winduid,'name' => $no_group_name);
  118. $a = 'recommend';
  119. $rt = $db->get_one("SELECT id,type,content,username FROM pw_collection WHERE id=" . S::sqlEscape($id));
  120. if (empty($rt)) {
  121. Showmsg('data_error');
  122. }
  123. $temp = unserialize($rt['content']);
  124. $rt['link'] = $temp['link'];
  125. if ($rt['type']=='user') {
  126. $title = $temp['user']['username']."($rt[link])";
  127. } elseif ($rt['type']=='photo') {
  128. $belong = getLangInfo('app','photo_belong');
  129. $title= $belong.$temp['photo']['username']."($rt[link])";
  130. } elseif ($rt['type']=='album') {
  131. $belong = getLangInfo('app','photo_belong');
  132. $title = $belong.$temp['album']['username']."($rt[link])";
  133. } elseif ($rt['type']=='group') {
  134. $title = $temp['group']['name']."($rt[link])";
  135. } elseif ($rt['type']=='diary') {
  136. $title = $temp['diary']['subject']."($rt[link])";
  137. } elseif ($rt['type']=='topic') {
  138. $title = $temp['topic']['subject']."($rt[link])";
  139. } else {
  140. $title = $rt['link'];
  141. }
  142. $descrip = $temp['descrip'];
  143. $username = $rt['username'];
  144. $atc_name = getLangInfo('app',$rt['type']);
  145. require_once PrintEot('m_ajax');
  146. ajax_footer();
  147. }
  148. }
  149. require_once PrintEot('m_collection');
  150. pwOutPut();
  151. function getVideo($link, $host) {
  152. $matches = array();
  153. switch ($host) {
  154. case 'youku.com':
  155. preg_match("/v_show\/id_(\w+)\.html/",$link,$matches);
  156. break;
  157. case 'youtube.com':
  158. preg_match("/v\=([\w\-]+)/",$link,$matches);
  159. break;
  160. case 'sina.com.cn':
  161. preg_match("/\/(\d+)-(\d+)\.html/",$link,$matches);
  162. break;
  163. case 'sohu.com':
  164. preg_match("/\/(\d+)\/*$/",$link,$matches);
  165. break;
  166. }
  167. if(!empty($matches[1])) {
  168. $return = $matches[1];
  169. } else {
  170. $return = '';
  171. }
  172. return $return;
  173. }