PageRenderTime 57ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/startZine/src/main/core/service/share.service.php

http://ownerpress.googlecode.com/
PHP | 2235 lines | 1668 code | 253 blank | 314 comment | 268 complexity | 7ec4764df97da91970104d514d95b57c MD5 | raw file
Possible License(s): Apache-2.0, AGPL-1.0, GPL-2.0, GPL-3.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ?????????? (Build on ThinkPHP)
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. /**
  8. * share.service.php
  9. *
  10. * ?????
  11. *
  12. * @package service
  13. * @author awfigq <awfigq@qq.com>
  14. */
  15. class ShareService
  16. {
  17. /*===========??????? Begin==============*/
  18. /**
  19. * ?????????
  20. * @param string $content ????
  21. * @param string $type content,title,tag ????
  22. * @return array(
  23. * 'error_code' => '????'
  24. * 'error_msg' => ????
  25. * )
  26. */
  27. public function checkWord(&$content,$type)
  28. {
  29. $result = array('error_code'=>0,'error_msg'=>'');
  30. $server = FS("ContentCheck");
  31. if($server->check($content) > 0)
  32. {
  33. $words_found = implode("?", $server->words_found);
  34. $tt_str = lang('share','word_'.$type);
  35. $result['error_code'] = $server->result;
  36. $result['error_msg'] = sprintf(lang('share','word_tips_'. $server->result),$tt_str,$words_found);
  37. }
  38. return $result;
  39. }
  40. /**
  41. * ??????????????
  42. * @param mix $_POST ??????? $_POST['type'] default:??,bar:??,ershou:??,ask:??
  43. * $_POST['share_data'] = photo ?? goods ??? goods_photo:????? default:???
  44. * * ??
  45. * array(
  46. * 'status' => xxx ?? bool
  47. * 'share_id' => share_id
  48. * 'error_code' => '????'
  49. * 'error_msg' => ????
  50. * )
  51. */
  52. public function submit($_POST,$is_check = true,$is_score = true,$is_album = FALSE)
  53. {
  54. //??????
  55. global $_FANWE;
  56. $share_content = htmlspecialchars(trim($_POST['content']));
  57. $share_data = array();
  58. $share_data['content'] = $share_content;
  59. $share_data['uid'] = intval($_FANWE['uid']);
  60. $share_data['parent_id'] = intval($_POST['parent_id']); //?????
  61. $share_data['rec_id'] = intval($_POST['rec_id']); //?????
  62. $share_data['base_id'] = intval($_POST['base_id']);
  63. $share_data['albumid'] = intval($_POST['albumid']);
  64. if($is_check)
  65. {
  66. $check_result = ShareService::checkWord($share_data['content'],'content');
  67. if($check_result['error_code'] == 1)
  68. {
  69. $check_result['status'] = false;
  70. return $check_result;
  71. }
  72. }
  73. /*//????????????ID
  74. if($share_data['parent_id'] > 0 && $share_data['base_id'] == 0)
  75. {
  76. $base_id = intval(FDB::resultFirst('SELECT base_id
  77. FROM '.FDB::table("share").'
  78. WHERE share_id = '.$share_data['parent_id']));
  79. $share_data['base_id'] = $base_id == 0 ? $share_data['parent_id'] : $base_id;
  80. }*/
  81. if(isset($_POST['type']))
  82. $share_data['type'] = $_POST['type'];
  83. $share_data['title'] = isset($_POST['title']) ? htmlspecialchars(trim($_POST['title'])) : '';
  84. if(!empty($share_data['title']) && $is_check)
  85. {
  86. $check_result = ShareService::checkWord($share_data['title'],'title');
  87. if($check_result['error_code'] == 1)
  88. {
  89. $check_result['status'] = false;
  90. return $check_result;
  91. }
  92. }
  93. $data['share'] = $share_data;
  94. //????????
  95. $share_goods_data = array();
  96. if(isset($_POST['goods']) && is_array($_POST['goods']) && count($_POST['goods']) > 0)
  97. {
  98. $share_goods = $_POST['goods'];
  99. foreach($share_goods as $goods)
  100. {
  101. $goods = unserialize(authcode($goods,'DECODE'));
  102. $gkey = $goods['item']['key'];
  103. $c_data = array();
  104. $c_data['img'] = $goods['item']['img'];
  105. $c_data['goods_key'] = $gkey;
  106. $c_data['name'] = addslashes(htmlspecialchars($goods['item']['name']));
  107. $c_data['url'] = $goods['item']['url'];
  108. $c_data['taoke_url'] = $goods['item']['taoke_url'];
  109. $c_data['price'] = $goods['item']['price'];
  110. $c_data['sort'] = isset($_POST['goods_sort'][$gkey]) ? intval($_POST['goods_sort'][$gkey]) : 10;
  111. $c_data['shop_name'] = addslashes(htmlspecialchars($goods['shop']['name']));
  112. $c_data['shop_logo'] = $goods['shop']['logo'];
  113. $c_data['shop_url'] = $goods['shop']['url'];
  114. $c_data['shop_taoke_url'] = $goods['shop']['taoke_url'];
  115. array_push($share_goods_data,$c_data);
  116. }
  117. }
  118. $data['share_goods'] = $share_goods_data;
  119. //??????
  120. $share_photos_data = array();
  121. if(isset($_POST['pics']) && is_array($_POST['pics']) && count($_POST['pics']) > 0)
  122. {
  123. $share_photos = $_POST['pics'];
  124. foreach($share_photos as $pkey => $photo)
  125. {
  126. $photo = authcode($photo,'DECODE');
  127. $photo = unserialize($photo);
  128. $c_data = array();
  129. $c_data['img'] = $photo['path'];
  130. $type = $photo['type'];
  131. if(empty($type) || !in_array($type,array('default', 'dapei', 'look')))
  132. $type = 'default';
  133. $c_data['type'] = $type;
  134. $c_data['sort'] = isset($_POST['pics_sort'][$pkey]) ? intval($_POST['pics_sort'][$pkey]) : 10;
  135. array_push($share_photos_data,$c_data);
  136. }
  137. }
  138. $data['share_photo'] = $share_photos_data;
  139. if($share_data['albumid'] > 0 && count($share_photos_data) == 0 && count($share_goods_data) == 0)
  140. exit;
  141. $data['share_tag'] = array();
  142. if(isset($_POST['tags']) && trim($_POST['tags']) != '')
  143. {
  144. $tags = htmlspecialchars(trim($_POST['tags']));
  145. if($is_check)
  146. {
  147. $check_result = ShareService::checkWord($tags,'tag');
  148. if($check_result['error_code'] == 1)
  149. {
  150. $check_result['status'] = false;
  151. return $check_result;
  152. }
  153. }
  154. $tags = str_replace('?',' ',$tags);
  155. $data['share_tag'] = explode(' ',$tags);
  156. }
  157. $data['pub_out_check'] = intval($_POST['pub_out_check']); //???????
  158. $result = ShareService::save($data,$is_score,$is_album);
  159. return $result;
  160. }
  161. /**
  162. * ??????
  163. * ??????????????????????????
  164. * $data = array( //???????
  165. * 'share'=>array(
  166. * 'uid'=> xxx, //?????ID
  167. * 'parent_id' => xxx //?????ID
  168. * 'content' => xxx //?????
  169. * 'type'=> xxx //?????????default
  170. * 'title' => xxx //?????
  171. * 'base_id' => xxx //??ID
  172. * ),
  173. *
  174. * 'share_photo'=>array( //?? #??#
  175. * array( //???
  176. * 'img' => xxx //??
  177. * )
  178. * ),
  179. * 'share_goods'=>array( //????? #??#
  180. * array(
  181. * 'img' => xxx //???
  182. * 'name' => xxx //??
  183. * 'url' => xxx //????
  184. * 'price' => xxx //??
  185. * 'shop_name' => xxx //????
  186. * 'shop_logo' => xxx //???logo
  187. * 'shop_url' => xxx //????
  188. * ) //????
  189. * ),
  190. * 'share_tag' => array(xxx,xxx,xxx), //??????
  191. * );
  192. *
  193. * ??
  194. * array(
  195. * 'status' => xxx ?? bool
  196. * 'share_id' => share_id
  197. * )
  198. */
  199. public function save($data,$is_score = true,$is_album = FALSE)
  200. {
  201. global $_FANWE;
  202. //??????
  203. $share_data = $data['share'];
  204. $share_album_id = (int)$share_data['albumid'];
  205. unset($share_data['albumid']);
  206. $share_data['create_time'] = TIME_UTC;
  207. $share_data['day_time'] = getTodayTime();
  208. $share_data['share_content_match'] = segmentToUnicode(strtolower(clearSymbol($share_data['content'])));
  209. $share_id = FDB::insert('share',$share_data,true);
  210. if(intval($share_id)>0)
  211. {
  212. $share_data_now_type = $share_data['type'];
  213. $share_data_rec_id = $share_data['rec_id'];
  214. if(empty($share_data_now_type))
  215. $share_data_now_type = 'default';
  216. /*//????? ?? ? ????????
  217. if(intval($share_data['parent_id']) > 0)
  218. {
  219. $base_share_id = FDB::resultFirst("select uid from ".FDB::table('share')." where share_id = ".$share_data['parent_id']);
  220. $result = FDB::query("INSERT INTO ".FDB::table('user_notice')."(uid, type, num, create_time) VALUES('$base_share_id',3,1,'".TIME_UTC."')", 'SILENT');
  221. if(!$result)
  222. FDB::query("UPDATE ".FDB::table('user_notice')." SET num = num + 1, create_time='".TIME_UTC."' WHERE uid='$base_share_id' AND type=3");
  223. }*/
  224. //????
  225. $is_event = false;
  226. $event_list = array();
  227. $pattern = "/#([^\f\n\r\t\v]{1,80}?)#/";
  228. preg_match_all($pattern,$share_data['content'],$event_list);
  229. if(!empty($event_list[1]))
  230. {
  231. array_unique($event_list[1]);
  232. foreach($event_list[1] as $v)
  233. {
  234. $event_id = (int)FDB::resultFirst("select id from ".FDB::table("event")." where `title`='".$v."'");
  235. if($event_id == 0)
  236. {
  237. $event_data = array();
  238. $event_data['uid'] = $share_data['uid'];
  239. $event_data['title'] = $v;
  240. $event_data['share_id'] = $share_id;
  241. $event_data['create_time'] = TIME_UTC;
  242. $event_data['last_share'] = $share_id;
  243. $event_data['last_time'] = TIME_UTC;
  244. FDB::insert("event",$event_data);
  245. }
  246. else
  247. {
  248. $event_data = array();
  249. $event_data['event_id'] = $event_id;
  250. $event_data['uid'] = $share_data['uid'];
  251. $event_data['share_id'] = $share_id;
  252. FDB::insert("event_share",$event_data);
  253. FDB::query("update ".FDB::table("event")." set thread_count = thread_count+1,last_share=".$share_id.",last_time=".TIME_UTC." where id = $event_id");
  254. }
  255. }
  256. }
  257. $share_cates = array();
  258. $result['status'] = true;
  259. $result['share_id'] = $share_id;
  260. /*$content_match = FS('Words')->segment(clearExpress($share_data['content']),100);
  261. $title_tags = FS('Words')->segment($share_data['title'],100);
  262. if(!empty($title_tags))
  263. $content_match = array_merge($content_match, $title_tags);*/
  264. $content_match = clearExpress($share_data['content']);
  265. $content_match .= $share_data['title'];
  266. $is_rel_imgage = false;
  267. $weibo_img = '';
  268. $weibo_img_sort = 100000;
  269. $photo_count = 0;
  270. $server_args = array();
  271. FS("Image")->getImageArgs(&$server_args);
  272. //??????
  273. if(isset($data['share_photo'])){
  274. $share_photo = $data['share_photo'];
  275. foreach($share_photo as $k=>$photo)
  276. {
  277. if($photo_count >= $_FANWE['setting']['share_pic_count'])
  278. break;
  279. $o_img = false;
  280. if(FS("Image")->getIsServer() && !empty($photo['server_code']))
  281. {
  282. $server = FS("Image")->getServer($photo['server_code']);
  283. if(!empty($server))
  284. {
  285. $server_args['share_id'] = $share_id;
  286. $server_args['img_path'] = $photo['img'];
  287. $server = FS("Image")->getImageUrlToken($server_args,$server,1);
  288. $body = FS("Image")->sendRequest($server,'saveshare',true);
  289. if(!empty($body))
  290. {
  291. $o_img = unserialize($body);
  292. FS("Image")->setServerUploadCount($o_img['server_code']);
  293. $share_server_code[] = $o_img['server_code'];
  294. $o_img['url'] = str_replace('./','./'.$o_img['server_code'].'/',$o_img['url']);
  295. $weibo_img_url = FS("Image")->getImageUrl($o_img['url'],1);
  296. }
  297. }
  298. }
  299. else
  300. {
  301. $o_img = copyImage($photo['img'],array(),'share',true,$share_id);
  302. $weibo_img_url = FS("Image")->getImageUrl($o_img['url'],1);
  303. }
  304. if(!empty($o_img))
  305. {
  306. if($photo['sort'] < $weibo_img_sort)
  307. {
  308. $weibo_img = $weibo_img_url;
  309. $weibo_img_sort = $photo['sort'];
  310. }
  311. $share_photo_data['uid'] = $_FANWE['uid'];
  312. $share_photo_data['share_id'] = $share_id;
  313. $share_photo_data['img'] = $o_img['url'];
  314. $share_photo_data['type'] = $photo['type'];
  315. $share_photo_data['sort'] = $photo['sort'];
  316. $share_photo_data['img_width'] = $o_img['width'];
  317. $share_photo_data['img_height'] = $o_img['height'];
  318. $share_photo_data['server_code'] = $photo['server_code'];
  319. FDB::insert('share_photo',$share_photo_data,true);
  320. $photo_count++;
  321. }
  322. }
  323. }
  324. //??????
  325. if(isset($data['rel_photo']))
  326. {
  327. $share_photo = $data['rel_photo'];
  328. foreach($share_photo as $share_photo_data)
  329. {
  330. if($photo_count >= $_FANWE['setting']['share_pic_count'])
  331. break;
  332. $is_rel_imgage = true;
  333. if($share_photo_data['sort'] < $weibo_img_sort)
  334. {
  335. $weibo_img = $share_photo_data['img'];
  336. $weibo_img_sort = $share_photo_data['sort'];
  337. }
  338. $share_photo_data['uid'] = $_FANWE['uid'];
  339. $share_photo_data['share_id'] = $share_id;
  340. FDB::insert('share_photo',$share_photo_data,true);
  341. $photo_count++;
  342. }
  343. }
  344. //??????
  345. $post_count=0;
  346. if(isset($data['share_posts'])){
  347. $share_posts=$data['share_posts'];
  348. foreach($share_posts as $post){
  349. $share_post_data['uid'] = $_FANWE['uid'];
  350. $share_post_data['share_id'] = $share_id;
  351. $share_post_data['post_title'] = $post['post_title'];
  352. $share_post_data['post_content'] = $post['post_content'];
  353. $share_post_data['post_excerpt'] = $post['post_excerpt'];
  354. $share_post_data['post_type'] = $post['type'];
  355. $share_post_data['sort'] = $post['sort'];
  356. if(isset($post['feature_img']))
  357. $share_post_data['feature_img']=$post['feature_img'];
  358. FDB::insert('share_posts',$share_post_data,true);
  359. $post_count++;
  360. }
  361. }
  362. //??????
  363. $shop_ids = array();
  364. $goods_count = 0;
  365. //???????
  366. if(isset($data['share_goods']))
  367. {
  368. $share_goods = $data['share_goods'];
  369. foreach($share_goods as $goods)
  370. {
  371. if($goods_count >= $_FANWE['setting']['share_goods_count'])
  372. break;
  373. $shop_id = 0;
  374. if(!empty($goods['shop_url']))
  375. {
  376. $shop_id = FDB::resultFirst('SELECT shop_id
  377. FROM '.FDB::table('shop').'
  378. WHERE shop_url = \''.$goods['shop_url'].'\'');
  379. if(intval($shop_id) == 0)
  380. {
  381. $content_match .= $goods['shop_name'];
  382. $shop_logo = copyFile(FANWE_ROOT.$goods['shop_logo'],'shop',md5(microtime(true)).random('6').'.jpg',true);
  383. $shop_data['shop_name'] = $goods['shop_name'];
  384. $shop_data['shop_logo'] = $shop_logo['url'];
  385. $shop_data['shop_url'] = $goods['shop_url'];
  386. $shop_data['taoke_url'] = $goods['shop_taoke_url'];
  387. $shop_id = FDB::insert('shop',$shop_data,true);
  388. }
  389. if($shop_id > 0)
  390. $shop_ids[] = $shop_id;
  391. }
  392. $goods_img = copyImage(FANWE_ROOT.$goods['img'],md5(microtime(true)).random('6').'.jpg',array(),'share',true,$share_id);
  393. if(!empty($goods_img))
  394. {
  395. if($goods['sort'] < $weibo_img_sort)
  396. {
  397. $weibo_img = $goods_img['url'];
  398. $weibo_img_sort = $goods['sort'];
  399. }
  400. $shop_id = intval($shop_id);
  401. //?????????
  402. $share_goods_data['uid'] = $_FANWE['uid'];
  403. $share_goods_data['share_id'] = $share_id;
  404. $share_goods_data['shop_id'] = $shop_id;
  405. $share_goods_data['img'] = $goods_img['url'];
  406. $share_goods_data['name'] = $goods['name'];
  407. $share_goods_data['url'] = $goods['url'];
  408. $share_goods_data['price'] = $goods['price'];
  409. $share_goods_data['sort'] = $goods['sort'];
  410. $share_goods_data['taoke_url'] = $goods['taoke_url'];
  411. $share_goods_data['goods_key'] = $goods['goods_key'];
  412. FDB::insert('share_goods',$share_goods_data,true);
  413. $goods_tags = FS('Words')->segment($goods['name'],10);
  414. if(!empty($goods_tags))
  415. {
  416. $share_cates[] = ShareService::getCateByTags($goods_tags);
  417. }
  418. $content_match .= $goods['name'];
  419. $goods_count++;
  420. }
  421. }
  422. }
  423. //??????
  424. if(isset($data['rel_goods']))
  425. {
  426. $share_goods = $data['rel_goods'];
  427. foreach($share_goods as $share_goods_data)
  428. {
  429. if($goods_count >= $_FANWE['setting']['share_goods_count'])
  430. break;
  431. $is_rel_imgage = true;
  432. $shop_ids[] = $share_goods_data['shop_id'];
  433. if($share_goods_data['sort'] < $weibo_img_sort)
  434. {
  435. $weibo_img = $share_goods_data['img'];
  436. $weibo_img_sort = $share_goods_data['sort'];
  437. }
  438. $share_goods_data['uid'] = $_FANWE['uid'];
  439. $share_goods_data['share_id'] = $share_id;
  440. FDB::insert('share_goods',$share_goods_data,true);
  441. $goods_tags = FS('Words')->segment($goods['name'],10);
  442. if(!empty($goods_tags))
  443. {
  444. $share_cates[] = ShareService::getCateByTags($goods_tags);
  445. }
  446. $content_match .= $goods['name'];
  447. $goods_count++;
  448. }
  449. }
  450. if($goods_count > 0 && $photo_count > 0)
  451. $share_data_type = 'goods_photo';
  452. elseif($goods_count > 0)
  453. $share_data_type = 'goods';
  454. elseif($photo_count > 0)
  455. $share_data_type = 'photo';
  456. elseif($post_count>0)
  457. $share_data_type='post';
  458. else
  459. $share_data_type = 'default';
  460. $update_share = array();
  461. $update_share['share_data'] = $share_data_type;
  462. if($share_album_id > 0 && in_array($share_data_type,array('goods','photo','goods_photo','post')))
  463. {
  464. $album = FDB::fetchFirst('SELECT cid,id,title FROM '.FDB::table('album').' WHERE id = '.$share_album_id);
  465. if($album)
  466. {
  467. $update_share['type'] = 'album_item';
  468. $share_data_now_type = 'album_item';
  469. $share_data_rec_id = $album['id'];
  470. $share_data_rec_cate = $album['cid'];
  471. $update_share['rec_id'] = $album['id'];
  472. $update_share['title'] = addslashes($album['title']);
  473. }
  474. else
  475. {
  476. $update_share['rec_id'] = 0;
  477. $share_data_rec_id = 0;
  478. }
  479. }
  480. else
  481. $share_data_rec_id = 0;
  482. FDB::update("share",$update_share,"share_id=".$share_id);
  483. //??????---?????? $is_album = true
  484. if(!$is_album)
  485. FDB::query('UPDATE '.FDB::table('user_count').'
  486. SET shares = shares + 1,goods = goods + '.$goods_count.',photos = photos + '.$photo_count.'
  487. WHERE uid = '.$share_data['uid']);
  488. FS('Medal')->runAuto($share_data['uid'],'shares');
  489. FS('User')->medalBehavior($share_data['uid'],'continue_share');
  490. switch($share_data_type)
  491. {
  492. case 'goods_photo':
  493. FS('Medal')->runAuto($share_data['uid'],'goods');
  494. FS('User')->medalBehavior($share_data['uid'],'continue_goods');
  495. FS('Medal')->runAuto($share_data['uid'],'photos');
  496. FS('User')->medalBehavior($share_data['uid'],'continue_photo');
  497. break;
  498. case 'goods':
  499. FS('Medal')->runAuto($share_data['uid'],'goods');
  500. FS('User')->medalBehavior($share_data['uid'],'continue_goods');
  501. break;
  502. case 'photo':
  503. FS('Medal')->runAuto($share_data['uid'],'photos');
  504. FS('User')->medalBehavior($share_data['uid'],'continue_photo');
  505. break;
  506. }
  507. if(in_array($share_data_type,array('goods','photo','goods_photo','post')))
  508. {
  509. //?????????????
  510. //FS('User')->setShareIds($share_data['uid'],$share_id);
  511. if(!empty($share_cates))
  512. {
  513. $cids = ShareService::getCidsByCates($share_cates);
  514. }
  515. if(!empty($data['share_tag']))
  516. {
  517. if(empty($cids))
  518. {
  519. $share_cates = array();
  520. $share_cates[] = ShareService::getCateByTags($data['share_tag']);
  521. $cids = ShareService::getCidsByCates($share_cates);
  522. }
  523. //$content_match = array_merge($content_match, $data['share_tag']);
  524. }
  525. //????
  526. $share_tags = array();
  527. foreach($data['share_tag'] as $tag)
  528. {
  529. if(trim($tag) != '' && !in_array($tag,$share_tags))
  530. {
  531. array_push($share_tags,$tag);
  532. //?????tags????
  533. FDB::query('UPDATE '.FDB::table('goods_tags').'
  534. SET count = count + 1
  535. WHERE tag_name = \''.$tag.'\'');
  536. //????100??????
  537. FDB::query('UPDATE '.FDB::table('goods_tags').'
  538. SET is_hot = 1
  539. WHERE tag_name = \''.$tag.'\' AND count >= 100');
  540. $content_match.=$tag;
  541. $tag_data = array();
  542. $tag_data['share_id'] = $share_id;
  543. $tag_data['tag_name'] = $tag;
  544. FDB::insert('share_tags',$tag_data);
  545. }
  546. }
  547. unset($share_tags);
  548. if(!empty($cids))
  549. {
  550. foreach($cids as $cid)
  551. {
  552. $cate_data = array();
  553. $cate_data['share_id'] = $share_id;
  554. $cate_data['cate_id'] = $cid;
  555. FDB::insert('share_category',$cate_data);
  556. }
  557. }
  558. //??????
  559. $share_match['share_id'] = $share_id;
  560. $share_match['content_match'] = segmentToUnicode(clearSymbol($content_match));
  561. FDB::insert("share_match",$share_match);
  562. }
  563. ShareService::updateShareCache($share_id);
  564. if($share_data_rec_id > 0)
  565. {
  566. $album_share = array();
  567. $album_share['album_id'] = $share_data_rec_id;
  568. $album_share['share_id'] = $share_id;
  569. $album_share['cid'] = $share_data_rec_cate;
  570. $album_share['create_day'] = getTodayTime();
  571. FDB::insert("album_share",$album_share);
  572. FS('Album')->updateAlbumByShare($share_data_rec_id,$share_id);
  573. FS('Album')->updateAlbum($share_data_rec_id);
  574. }
  575. if(count($shop_ids) > 0)
  576. FS("Shop")->updateShopStatistic($shop_ids);
  577. //??????
  578. $atme_share_type = FDB::resultFirst("select `type` from ".FDB::table("share")." where `share_id`='".$share_id."'");
  579. if($atme_share_type != "fav")
  580. {
  581. $atme_list = array();
  582. $pattern = "/@([^\f\n\r\t\v@ ]{2,20}?)(?:\:| )/";
  583. preg_match_all($pattern,$share_data['content'],$atme_list);
  584. if(!empty($atme_list[1]))
  585. {
  586. $atme_list[1] = array_unique($atme_list[1]);
  587. $users = array();
  588. foreach($atme_list[1] as $user)
  589. {
  590. if(!empty($user))
  591. {
  592. $users[] = $user;
  593. }
  594. }
  595. $res = FDB::query('SELECT uid
  596. FROM '.FDB::table('user').'
  597. WHERE user_name '.FDB::createIN($users));
  598. while($data = FDB::fetch($res))
  599. {
  600. FS("User")->setUserTips($data['uid'],4,$share_id);
  601. }
  602. }
  603. }
  604. if($is_score && !in_array($share_data_now_type,array('fav','album_best','album_rec')))
  605. {
  606. if(!$is_rel_imgage && in_array($share_data_type,array('goods','photo','goods_photo','post')))
  607. FS("User")->updateUserScore($share_data['uid'],'share','image',$share_data['content'],$share_id);
  608. else
  609. FS("User")->updateUserScore($share_data['uid'],'share','default',$share_data['content'],$share_id);
  610. }
  611. if($data['pub_out_check'])
  612. {
  613. $weibo = array();
  614. $weibo['content'] = $share_data['content'];
  615. $weibo['img'] = $weibo_img;
  616. $weibo['ip'] = $_FANWE['client_ip'];
  617. $weibo['url'] = $_FANWE['site_url'].FU('note/index',array('sid'=>$share_id));
  618. $weibo['url'] = str_replace('//','/',$weibo['url']);
  619. $weibo['url'] = str_replace(':/','://',$weibo['url']);
  620. $weibo = base64_encode(serialize($weibo));
  621. if(empty($share_data['type']))
  622. $share_data['type'] = 'default';
  623. //???????
  624. $uid = $_FANWE['uid'];
  625. $user_binds = FS("User")->getUserBindList($uid);
  626. $is_open = false;
  627. foreach($user_binds as $class => $bind)
  628. {
  629. if($bind['sync'] && file_exists(FANWE_ROOT."login/".$class.".php"))
  630. {
  631. $check_field = "";
  632. if(in_array($share_data['type'],array('bar','ask')))
  633. $check_field = "topic";
  634. elseif($share_data['type'] == 'default')
  635. $check_field = "weibo";
  636. if($bind['sync'][$check_field] == 1)
  637. {
  638. $is_open = true;
  639. //????
  640. $schedule['uid'] = $uid;
  641. $schedule['type'] = $class;
  642. $schedule['data'] = $weibo;
  643. $schedule['pub_time'] = TIME_UTC;
  644. FDB::insert('pub_schedule',$schedule,true);
  645. }
  646. }
  647. }
  648. if($is_open)
  649. {
  650. $fp=fsockopen($_SERVER['HTTP_HOST'],80,&$errno,&$errstr,5);
  651. if($fp)
  652. {
  653. $request = "GET ".SITE_URL."login.php?loop=true&uid=".$uid." HTTP/1.0\r\n";
  654. $request .= "Host: ".$_SERVER['HTTP_HOST']."\r\n";
  655. $request .= "Connection: Close\r\n\r\n";
  656. fwrite($fp, $request);
  657. while(!feof($fp))
  658. {
  659. fgets($fp, 128);
  660. break;
  661. }
  662. fclose($fp);
  663. }
  664. }
  665. }
  666. }
  667. else
  668. {
  669. $result['status'] = false;
  670. }
  671. return $result;
  672. }
  673. /*??????????*/
  674. public function getCateByTags($tags)
  675. {
  676. static $tag_cates = array();
  677. $tags = array_unique($tags);
  678. $cates = array();
  679. foreach($tags as $tag)
  680. {
  681. if(!empty($tag))
  682. {
  683. if(isset($tag_cates[$tag]))
  684. {
  685. foreach($tag_cates[$tag] as $data)
  686. {
  687. if(isset($cates[$data['cate_id']]))
  688. $cates[$data['cate_id']] += $data['weight'];
  689. else
  690. $cates[$data['cate_id']] = $data['weight'];
  691. }
  692. continue;
  693. }
  694. $is_bln = true;
  695. $res = FDB::query('SELECT gct.cate_id,gct.weight
  696. FROM '.FDB::table('goods_tags').' AS gt
  697. LEFT JOIN '.FDB::table('goods_category_tags')." AS gct ON gct.tag_id = gt.tag_id
  698. WHERE gt.tag_name = '$tag'");
  699. while($data = FDB::fetch($res))
  700. {
  701. if($data['weight'] < 1)
  702. $data['weight'] = 1;
  703. if(isset($cates[$data['cate_id']]))
  704. $cates[$data['cate_id']] += $data['weight'];
  705. else
  706. $cates[$data['cate_id']] = $data['weight'];
  707. $tag_cates[$tag][] = $data;
  708. $is_bln = false;
  709. }
  710. if($is_bln)
  711. {
  712. $like_tag = fMysqlLikeQuote($tag);
  713. $res = FDB::query('SELECT gct.cate_id,gct.weight
  714. FROM '.FDB::table('goods_tags').' AS gt
  715. LEFT JOIN '.FDB::table('goods_category_tags')." AS gct ON gct.tag_id = gt.tag_id
  716. WHERE gt.tag_name LIKE '%".$like_tag."%' OR INSTR('$tag',gt.tag_name) > 0");
  717. while($data = FDB::fetch($res))
  718. {
  719. if($data['weight'] < 1)
  720. $data['weight'] = 1;
  721. if(isset($cates[$data['cate_id']]))
  722. $cates[$data['cate_id']] += $data['weight'];
  723. else
  724. $cates[$data['cate_id']] = $data['weight'];
  725. $tag_cates[$tag] = $data;
  726. }
  727. }
  728. }
  729. }
  730. if(empty($cates))
  731. return array();
  732. $cids = array();
  733. foreach($cates as $cate_id => $weight)
  734. {
  735. $cids[$weight][] = $cate_id;
  736. }
  737. krsort($cids);
  738. return each($cids);
  739. }
  740. public function getCidsByCates($cates)
  741. {
  742. $list = array();
  743. $cids = array();
  744. foreach($cates as $cate)
  745. {
  746. foreach($cate['value'] as $cid)
  747. {
  748. if(isset($cids[$cid]))
  749. $cids[$cid] = $cate['key'];
  750. else
  751. $cids[$cid] += $cate['key'];
  752. }
  753. }
  754. foreach($cates as $cate)
  755. {
  756. $id = 0;
  757. $weight = 0;
  758. foreach($cate['value'] as $cid)
  759. {
  760. if($cids[$cid] > $weight)
  761. $id = $cid;
  762. }
  763. if($id > 0)
  764. $list[] = $id;
  765. }
  766. return array_unique($list);
  767. }
  768. public function deleteShare($share_id,$is_score = true)
  769. {
  770. $share = ShareService::getShareById($share_id);
  771. if(!empty($share))
  772. {
  773. $goods_count = FDB::resultFirst('SELECT COUNT(goods_id) FROM '.FDB::table('share_goods').' WHERE share_id = '.$share_id);
  774. $photo_count = FDB::resultFirst('SELECT COUNT(photo_id) FROM '.FDB::table('share_photo').' WHERE share_id = '.$share_id);
  775. $collect_count = FDB::resultFirst('SELECT COUNT(c_uid) FROM '.FDB::table('user_collect').' WHERE share_id = '.$share_id);
  776. FDB::delete('share','share_id = '.$share_id);
  777. FDB::delete('share_goods','share_id = '.$share_id);
  778. //FDB::delete('share_photo','share_id = '.$share_id);
  779. FDB::delete('share_category','share_id = '.$share_id);
  780. FDB::delete('share_comment','share_id = '.$share_id);
  781. FDB::delete('share_match','share_id = '.$share_id);
  782. FDB::delete('share_tags','share_id = '.$share_id);
  783. FDB::delete('user_collect','share_id = '.$share_id);
  784. $pattern = "/#([^\f\n\r\t\v]{1,80}?)#/";
  785. if(preg_match($pattern,$share['content']))
  786. {
  787. FS("Event")->deleteEvent($share_id);
  788. }
  789. $pattern = "/@([^\f\n\r\t\v@ ]{2,20}?)(?:\:| )/";
  790. if(preg_match($pattern,$share['content']))
  791. {
  792. FDB::delete('atme','share_id = '.$share_id);
  793. }
  794. if(defined('MANAGE_HANDLER') && MANAGE_HANDLER && $is_score)
  795. {
  796. if(!in_array($share['type'],array('fav','album_best','album_rec')))
  797. {
  798. if($share['rec_uid'] == 0 && in_array($share['share_data'],array('goods','photo','goods_photo')))
  799. FS("User")->updateUserScore($share['uid'],'delete_share','image',$share['content'],$share_id);
  800. else
  801. FS("User")->updateUserScore($share['uid'],'delete_share','default',$share['content'],$share_id);
  802. }
  803. }
  804. FDB::query('UPDATE '.FDB::table('user_count').' SET
  805. shares = shares - 1,
  806. photos = photos - '.$photo_count.',
  807. goods = goods - '.$goods_count.',
  808. collects = collects - '.$collect_count.' WHERE uid = '.$share['uid']);
  809. $key = getDirsById($share_id);
  810. clearCacheDir('share/'.$key);
  811. $count = (int)FDB::resultFirst('SELECT COUNT(share_id) FROM '.FDB::table('share_rec').' WHERE share_id = '.$share_id);
  812. if($count == 0)
  813. clearDir(PUBLIC_ROOT.'./upload/share/'.$key,true);
  814. }
  815. }
  816. public function deleteShareCache()
  817. {
  818. }
  819. /**
  820. * ????????
  821. * @param int $share_id ????
  822. * @return array
  823. */
  824. public function getShareById($share_id)
  825. {
  826. $share_id = (int)$share_id;
  827. if(!$share_id)
  828. return false;
  829. static $list = array();
  830. if(!isset($list[$share_id]))
  831. {
  832. $share = FDB::fetchFirst('SELECT * FROM '.FDB::table('share').' WHERE share_id = '.$share_id);
  833. if($share)
  834. $share['url'] = FU('note/index',array('sid'=>$share_id));
  835. $list[$share_id] = $share;
  836. }
  837. return $list[$share_id];
  838. }
  839. /**
  840. * ??????
  841. * @param int $share_id ????
  842. * @return void
  843. */
  844. public function updateShare($share_id,$title,$content)
  845. {
  846. if(empty($title) && empty($content))
  847. return;
  848. $data = array();
  849. if(!empty($title))
  850. $data['title'] = $title;
  851. if(!empty($content))
  852. $data['content'] = $content;
  853. FDB::update('share',$data,"share_id = '$share_id'");
  854. ShareService::updateShareMatch($share_id);
  855. }
  856. /**
  857. * ??????
  858. * @param int $share_id ????
  859. * @return array
  860. */
  861. public function getShareDetail($share_id,$is_collect = false,$is_tag = false,$collect_count = 20)
  862. {
  863. $share = ShareService::getShareById($share_id);
  864. if($share)
  865. {
  866. $share['cache_data'] = unserialize($share['cache_data']);
  867. $share['authoritys'] = ShareService::getIsEditShare($share);
  868. $share['time'] = getBeforeTimelag($share['create_time']);
  869. ShareService::shareImageFormat($share);
  870. }
  871. return $share;
  872. }
  873. /**
  874. * ?????????
  875. * @param int $share_id ????
  876. * @return array
  877. */
  878. public function getShareDynamic($share_id)
  879. {
  880. $dynamic = FDB::fetchFirst('SELECT collect_count,comment_count,relay_count,click_count
  881. FROM '.FDB::table('share').'
  882. WHERE share_id = '.$share_id);
  883. return $dynamic;
  884. }
  885. /**
  886. * ????????
  887. * @param array $list ????
  888. * @param bool $is_parent ????????
  889. * @param bool $is_collect ?????????
  890. * @param bool $is_parent ????????
  891. * @return array
  892. */
  893. public function getShareDetailList($list,$is_parent = false,$is_collect = false,$is_tag = false,$is_comment = false,$comment_count = 10,$collect_count = 20,$is_user = false)
  894. {
  895. global $_FANWE;
  896. $shares = array();
  897. $share_ids = array();
  898. $rec_shares_ids = array();
  899. $share_users = array();
  900. $share_collects = array();
  901. $share_comments = array();
  902. $share_follows = array();
  903. foreach($list as $item)
  904. {
  905. $share_id = $item['share_id'];
  906. $share_ids[] = $share_id;
  907. $item['cache_data'] = unserialize($item['cache_data']);
  908. $item['authoritys'] = ShareService::getIsEditShare($item);
  909. $item['time'] = getBeforeTimelag($item['create_time']);
  910. $item['url'] = FU('note/index',array('sid'=>$share_id));
  911. ShareService::shareImageFormat($item);
  912. $shares[$share_id] = $item;
  913. unset($shares[$share_id]['cache_data']);
  914. //????
  915. if($is_user)
  916. {
  917. $shares[$share_id]['user'] = &$share_users[$item['uid']];
  918. if($item['rec_uid'] > 0)
  919. $shares[$share_id]['rec_user'] = &$share_users[$item['rec_uid']];
  920. }
  921. //????
  922. if($is_comment)
  923. {
  924. $shares[$share_id]['comments'] = array();
  925. if(!empty($item['cache_data']['comments']))
  926. {
  927. $comment_ids = array_slice($item['cache_data']['comments'],0,$comment_count);
  928. foreach($comment_ids as $comment_id)
  929. {
  930. $shares[$share_id]['comments'][$comment_id] = &$share_comments[$comment_id];
  931. }
  932. }
  933. }
  934. //???????
  935. if($is_collect)
  936. {
  937. $shares[$share_id]['collects'] = array();
  938. if(!empty($item['cache_data']['collects']))
  939. {
  940. $collect_ids = array_slice($item['cache_data']['collects'],0,$collect_count);
  941. foreach($collect_ids as $collect_uid)
  942. {
  943. if($is_user)
  944. $shares[$share_id]['collects'][$collect_uid] = &$share_users[$collect_uid];
  945. else
  946. $shares[$share_id]['collects'][$collect_uid] = $collect_uid;
  947. }
  948. }
  949. }
  950. if($is_tag)
  951. {
  952. $shares[$share_id]['is_eidt_tag'] = ShareService::getIsEditTag($item);
  953. $shares[$share_id]['tags'] = $item['cache_data']['tags'];
  954. ShareService::tagsFormat($shares[$share_id]['tags']['user']);
  955. }
  956. $shares[$share_id]['is_relay'] = false;
  957. $shares[$share_id]['is_parent'] = false;
  958. if($is_parent)
  959. {
  960. if($item['base_id'] > 0)
  961. {
  962. $shares[$share_id]['is_relay'] = true;
  963. $rec_shares_ids[$item['base_id']] = false;
  964. $shares[$share_id]['relay_share'] = &$rec_shares_ids[$item['base_id']];
  965. if($item['parent_id'] > 0 && $item['parent_id'] != $item['base_id'])
  966. {
  967. $shares[$share_id]['is_parent'] = true;
  968. $rec_shares_ids[$item['parent_id']] = false;
  969. $shares[$share_id]['parent_share'] = &$rec_shares_ids[$item['parent_id']];
  970. }
  971. }
  972. }
  973. }
  974. $rec_ids = array_keys($rec_shares_ids);
  975. if(count($rec_ids) > 0)
  976. {
  977. $intersects = array_intersect($share_ids,$rec_ids);
  978. $temp_ids = array();
  979. foreach($intersects as $share_id)
  980. {
  981. $rec_shares_ids[$share_id] = $shares[$share_id];
  982. $temp_ids[] = $share_id;
  983. }
  984. $diffs = array_diff($rec_ids,$temp_ids);
  985. if(count($diffs) > 0)
  986. {
  987. $res = FDB::query('SELECT * FROM '.FDB::table('share').' WHERE share_id IN ('.implode(',',$diffs).')');
  988. while($item = FDB::fetch($res))
  989. {
  990. $share_id = $item['share_id'];
  991. $share_ids[] = $share_id;
  992. $item['cache_data'] = unserialize($item['cache_data']);
  993. $item['authoritys'] = ShareService::getIsEditShare($item);
  994. $item['time'] = getBeforeTimelag($item['create_time']);
  995. $item['url'] = FU('note/index',array('sid'=>$share_id));
  996. ShareService::shareImageFormat($item);
  997. $rec_shares_ids[$share_id] = $item;
  998. unset($rec_shares_ids[$share_id]['cache_data']);
  999. //????
  1000. if($is_user)
  1001. {
  1002. $rec_shares_ids[$share_id]['user'] = &$share_users[$item['uid']];
  1003. if($item['rec_uid'] > 0)
  1004. $rec_shares_ids[$share_id]['rec_user'] = &$share_users[$item['rec_uid']];
  1005. }
  1006. //????
  1007. if($is_comment)
  1008. {
  1009. $rec_shares_ids[$share_id]['comments'] = array();
  1010. if(!empty($item['cache_data']['comments']))
  1011. {
  1012. $comment_ids = array_slice($item['cache_data']['comments'],0,$comment_count);
  1013. foreach($comment_ids as $comment_id)
  1014. {
  1015. $rec_shares_ids[$share_id]['comments'][$comment_id] = &$share_comments[$comment_id];
  1016. }
  1017. }
  1018. }
  1019. //???????
  1020. if($is_collect)
  1021. {
  1022. $rec_shares_ids[$share_id]['collects'] = array();
  1023. if(!empty($item['cache_data']['collects']))
  1024. {
  1025. $collect_ids = array_slice($item['cache_data']['collects'],0,$collect_count);
  1026. foreach($collect_ids as $collect_uid)
  1027. {
  1028. if($is_user)
  1029. $rec_shares_ids[$share_id]['collects'][$collect_uid] = &$share_users[$collect_uid];
  1030. else
  1031. $rec_shares_ids[$share_id]['collects'][$collect_uid] = $collect_uid;
  1032. }
  1033. }
  1034. }
  1035. if($is_tag)
  1036. {
  1037. $rec_shares_ids[$share_id]['is_eidt_tag'] = ShareService::getIsEditTag($item);
  1038. $rec_shares_ids[$share_id]['tags'] = $item['cache_data']['tags'];
  1039. ShareService::tagsFormat($rec_shares_ids[$share_id]['tags']['user']);
  1040. }
  1041. }
  1042. }
  1043. }
  1044. $comment_ids = array_keys($share_comments);
  1045. if(count($comment_ids) > 0)
  1046. {
  1047. $res = FDB::query("SELECT * FROM ".FDB::table('share_comment').' WHERE comment_id IN ('.implode(',',$comment_ids).')');
  1048. while($item = FDB::fetch($res))
  1049. {
  1050. $item['time'] = getBeforeTimelag($item['create_time']);
  1051. $share_comments[$item['comment_id']] = $item;
  1052. if($is_user)
  1053. $share_comments[$item['comment_id']]['user'] = &$share_users[$item['uid']];
  1054. }
  1055. }
  1056. if($is_user)
  1057. FS('User')->usersFormat($share_users);
  1058. return $shares;
  1059. }
  1060. /**
  1061. * ???????
  1062. */
  1063. public function getShareImage($share_id,$data_type)
  1064. {
  1065. $share_id = (int)$share_id;
  1066. $list = array();
  1067. switch($data_type)
  1068. {
  1069. case 'goods':
  1070. $sql = 'SELECT share_id,goods_id AS id,img,\'g\' AS type,name,url,price,taoke_url
  1071. FROM '.FDB::table('share_goods').'
  1072. WHERE share_id = '.$share_id.' ORDER BY sort ASC';
  1073. $res = FDB::query($sql);
  1074. while($data = FDB::fetch($res))
  1075. {
  1076. $data['name'] = addslashes($data['name']);
  1077. $data['url'] = addslashes($data['url']);
  1078. $pkey = $data['type'].$data['id'];
  1079. $list['all'][$pkey] = $data;
  1080. }
  1081. break;
  1082. case 'photo':
  1083. $sql = 'SELECT share_id,photo_id AS id,img,type AS ptype,\'m\' AS type,\'\' AS name,\'\' AS url,0 AS price
  1084. FROM '.FDB::table('share_photo').'
  1085. WHERE share_id = '.$share_id.' ORDER BY sort ASC';
  1086. $res = FDB::query($sql);
  1087. while($data = FDB::fetch($res))
  1088. {
  1089. $pkey = $data['type'].$data['id'];
  1090. $ptype = $data['ptype'];
  1091. unset($data['ptype']);
  1092. $list['all'][$pkey] = $data;
  1093. if($ptype != 'default')
  1094. {
  1095. $list[$ptype][] = $pkey;
  1096. }
  1097. }
  1098. break;
  1099. case 'goods_photo':
  1100. $sql = '(SELECT share_id,goods_id AS id,img,\'default\' AS ptype,\'g\' AS type,name,url,price,taoke_url,sort
  1101. FROM '.FDB::table('share_goods').'
  1102. WHERE share_id = '.$share_id.')
  1103. UNION
  1104. (SELECT share_id,photo_id AS id,img,type AS ptype,\'m\' AS type,\'\' AS name,\'\' AS url,0 AS price,\'\' AS taoke_url,sort
  1105. FROM '.FDB::table('share_photo').'
  1106. WHERE share_id = '.$share_id.')
  1107. ORDER BY sort ASC';
  1108. $res = FDB::query($sql);
  1109. while($data = FDB::fetch($res))
  1110. {
  1111. $data['name'] = addslashes($data['name']);
  1112. $data['url'] = addslashes($data['url']);
  1113. $pkey = $data['type'].$data['id'];
  1114. $ptype = $data['ptype'];
  1115. unset($data['ptype']);
  1116. unset($data['sort']);
  1117. $list['all'][$pkey] = $data;
  1118. if($ptype != 'default')
  1119. {
  1120. $list[$ptype][] = $pkey;
  1121. }
  1122. }
  1123. break;
  1124. }
  1125. return $list;
  1126. }
  1127. /**
  1128. * ?????????
  1129. */
  1130. public function getShareImages(&$share_datas)
  1131. {
  1132. foreach($share_datas as $share_data => $share_ids)
  1133. {
  1134. if($share_data == 'default' || count($share_ids) == 0)
  1135. continue;
  1136. $share_ids = array_keys($share_ids);
  1137. $list = array();
  1138. switch($share_data)
  1139. {
  1140. case 'goods':
  1141. $sql = 'SELECT share_id,goods_id AS id,img,\'g\' AS type,name,url,price,taoke_url
  1142. FROM '.FDB::table('share_goods').'
  1143. WHERE share_id IN ('.implode(',',$share_ids).') ORDER BY sort ASC';
  1144. $res = FDB::query($sql);
  1145. while($data = FDB::fetch($res))
  1146. {
  1147. $list[$data['share_id']]['all'][] = $data;
  1148. }
  1149. break;
  1150. case 'photo':
  1151. $sql = 'SELECT share_id,photo_id AS id,img,type AS ptype,\'m\' AS type,\'\' AS name,\'\' AS url,0 AS price
  1152. FROM '.FDB::table('share_photo').'
  1153. WHERE share_id IN ('.implode(',',$share_ids).') ORDER BY sort ASC';
  1154. $res = FDB::query($sql);
  1155. while($data = FDB::fetch($res))
  1156. {
  1157. $pkey = $data['type'].$data['id'];
  1158. $ptype = $data['ptype'];
  1159. unset($data['ptype']);
  1160. $list[$data['share_id']]['all'][$pkey] = $data;
  1161. if($ptype != 'default')
  1162. {
  1163. $list[$data['share_id']][$ptype][] = $pkey;
  1164. }
  1165. }
  1166. break;
  1167. case 'goods_photo':
  1168. $sql = '(SELECT share_id,goods_id AS id,img,\'default\' AS ptype,\'g\' AS type,name,url,price,taoke_url,sort
  1169. FROM '.FDB::table('share_goods').'
  1170. WHERE share_id IN ('.implode(',',$share_ids).'))
  1171. UNION
  1172. (SELECT share_id,photo_id AS id,img,type AS ptype,\'m\' AS type,\'\' AS name,\'\' AS url,0 AS price,\'\' AS taoke_url,sort
  1173. FROM '.FDB::table('share_photo').'
  1174. WHERE share_id IN ('.implode(',',$share_ids).'))
  1175. ORDER BY sort ASC';
  1176. $res = FDB::query($sql);
  1177. while($data = FDB::fetch($res))
  1178. {
  1179. $pkey = $data['type'].$data['id'];
  1180. $ptype = $data['ptype'];
  1181. unset($data['ptype']);
  1182. unset($data['sort']);
  1183. $list[$data['share_id']]['all'][$pkey] = $data;
  1184. if($ptype != 'default')
  1185. {
  1186. $list[$data['share_id']][$ptype][] = $pkey;
  1187. }
  1188. }
  1189. break;
  1190. }
  1191. foreach($list as $share_id => $item)
  1192. {
  1193. foreach($item['all'] as $ik => $img)
  1194. {
  1195. if($img['type'] == 'g')
  1196. {
  1197. $img['goods_url'] = $img['url'];
  1198. if(empty($img['taoke_url']))
  1199. $img['to_url'] = FU('tgo',array('url'=>$img['url']));
  1200. else
  1201. $img['to_url'] = FU('tgo',array('url'=>$img['taoke_url']));
  1202. $img['price_format'] = priceFormat($img['price']);
  1203. }
  1204. $img['url'] = FU('note/'.$img['type'],array('sid'=>$img['share_id'],'id'=>$img['id']));
  1205. $item['all'][$ik] = $img;
  1206. }
  1207. $share_datas[$share_data][$share_id] = $item;
  1208. }
  1209. }
  1210. }
  1211. public function shareImageFormat(&$share,$pic_num = 0)
  1212. {
  1213. $images = $share['cache_data']['imgs'];
  1214. foreach($images['all'] as $ik => $img)
  1215. {
  1216. if($img['type'] == 'g')
  1217. {
  1218. $img['goods_url'] = $img['url'];
  1219. if(empty($img['taoke_url']))
  1220. $img['to_url'] = FU('tgo',array('url'=>$img['url']));
  1221. else
  1222. $img['to_url'] = FU('tgo',array('url'=>$img['taoke_url']));
  1223. $img['price_format'] = priceFormat($img['price']);
  1224. }
  1225. $img['url'] = FU('note/'.$img['type'],array('sid'=>$img['share_id'],'id'=>$img['id']));
  1226. $images['all'][$ik] = $img;
  1227. $share['imgs'][] = $img;
  1228. }
  1229. foreach($images['dapei'] as $ik)
  1230. {
  1231. $share['dapei_imgs'][] = $images['all'][$ik];
  1232. }
  1233. foreach($images['look'] as $ik)
  1234. {
  1235. $share['look_imgs'][] = $images['all'][$ik];
  1236. }
  1237. if($pic_num > 0 && count($share['imgs']) > $pic_num)
  1238. $share['imgs'] = array_slice($share['imgs'],0,$pic_num);
  1239. unset($images);
  1240. }
  1241. /**
  1242. * ?????????????????
  1243. * @param array $_POST ?????
  1244. * @return array(
  1245. 'prev'=>?????,
  1246. 'next'=>?????,
  1247. )
  1248. */
  1249. public function getPrevNextShares($uid,$share_id)
  1250. {
  1251. $arr = array('prev'=>0,'next'=>0);
  1252. $share_ids = FS('User')->getShareIds($uid);
  1253. $key = array_search($share_id,$share_ids);
  1254. if($key !== false)
  1255. {
  1256. $count = count($share_ids);
  1257. if($count > 1)
  1258. {
  1259. if($key == 0)
  1260. {
  1261. $arr['prev'] = $share_ids[$count - 1];
  1262. $arr['next'] = $share_ids[$key + 1];
  1263. }
  1264. elseif($key == $count - 1)
  1265. {
  1266. $arr['prev'] = $share_ids[$key - 1];
  1267. $arr['next'] = $share_ids[0];
  1268. }
  1269. else
  1270. {
  1271. $arr['prev'] = $share_ids[$key - 1];
  1272. $arr['next'] = $share_ids[$key + 1];
  1273. }
  1274. }
  1275. }
  1276. return $arr;
  1277. }
  1278. public function updateShareCache($share_id,$type = 'all')
  1279. {
  1280. $share_id = (int)$share_id;
  1281. if(!$share_id)
  1282. return;
  1283. $share = FDB::fetchFirst('SELECT cache_data,share_data FROM '.FDB::table('share').' WHERE share_id = '.$share_id);
  1284. if(!$share)
  1285. return;
  1286. $cache_data = unserialize($share['cache_data']);
  1287. switch($type)
  1288. {
  1289. case 'tags':
  1290. $cache_data['tags'] = ShareService::getShareTags($share_id,true);
  1291. break;
  1292. case 'collects':
  1293. $cache_data['collects'] = ShareService::getShareCollectUser($share_id,50);
  1294. break;
  1295. case 'comments':
  1296. $cache_data['comments'] = ShareService::getNewCommentIdsByShare($share_id,10);
  1297. break;
  1298. case 'imgs':
  1299. $cache_data['imgs'] = ShareService::getShareImage($share_id,$share['share_data']);
  1300. break;
  1301. case 'all':
  1302. $cache_data['tags'] = ShareService::getShareTags($share_id,true);
  1303. $cache_data['collects'] = ShareService::getShareCollectUser($share_id,50);
  1304. $cache_data['comments'] = ShareService::getNewCommentIdsByShare($share_id,10);
  1305. $cache_data['imgs'] = ShareService::getShareImage($share_id,$share['share_data']);
  1306. break;
  1307. }
  1308. unset($share['share_data']);
  1309. $share['cache_data'] = serialize($cache_data);
  1310. FDB::update("share",$share,'share_id = '.$share_id);
  1311. }
  1312. public function updateShareMatch($share_id)
  1313. {
  1314. $share = ShareService::getShareById($share_id);
  1315. if(!in_array($share['share_data'],array('goods','photo','goods_photo')))
  1316. return;
  1317. $share['cache_data'] = unserialize($share['cache_data']);
  1318. $content_match = clearExpress($share['content']);
  1319. $content_match .= $share['title'];
  1320. if(isset($share['cache_data']['tags']['user']))
  1321. {
  1322. foreach($share['cache_data']['tags']['user'] as $tag)
  1323. {
  1324. $content_match.=$tag['tag_name'];
  1325. }
  1326. }
  1327. if(isset($share['cache_data']['tags']['admin']))
  1328. {
  1329. foreach($share['cache_data']['tags']['admin'] as $tag)
  1330. {
  1331. $content_match.=$tag['tag_name'];
  1332. }
  1333. }
  1334. if(isset($share['cache_data']['imgs']['all']))
  1335. {
  1336. foreach($share['cache_data']['imgs']['all'] as $img)
  1337. {
  1338. if(!empty($img['name']))
  1339. {
  1340. $content_match.=$img['name'];
  1341. }
  1342. }
  1343. }
  1344. //??????
  1345. $share_match = array();
  1346. $share_match['share_id'] = $share_id;
  1347. $share_match['content_match'] = segmentToUnicode(clearSymbol($content_match));
  1348. FDB::insert("share_match",$share_match,false,true);
  1349. }
  1350. /**
  1351. * ?????????
  1352. * @param int $share ??
  1353. * @return array
  1354. */
  1355. public function getIsEditShare(&$share)
  1356. {
  1357. static $edits = array();
  1358. if(!isset($edits[$share['share_id']]))
  1359. {
  1360. global $_FANWE;
  1361. $type = array('ask','bar');
  1362. $is_edit = 0;
  1363. $post = array('ask_post','bar_post');
  1364. if(in_array($share['type'],$post))
  1365. {
  1366. if($share['uid'] == $_FANWE['uid'])
  1367. $is_edit = 1;
  1368. if($share['type'] == 'ask_post')
  1369. $thread = FS('ask')->getTopicById($share['rec_id']);
  1370. else
  1371. $thread = FS('Topic')->getTopicById($share['rec_id']);
  1372. if($thread['uid'] == $_FANWE['uid'])
  1373. $is_edit = 2;
  1374. }
  1375. else
  1376. {
  1377. if(!in_array($share['type'],$type) && $share['uid'] == $_FANWE['uid'])
  1378. $is_edit = 1;
  1379. }
  1380. $edits[$share['share_id']] = $is_edit;
  1381. }
  1382. return $edits[$share['share_id']];
  1383. }
  1384. /*===========??????? END ==============*/
  1385. /*===========???? BEGIN ==============*/
  1386. /**
  1387. * ???????????
  1388. * @param int $share ??
  1389. * @return array
  1390. */
  1391. public function getIsEditTag(&$share)
  1392. {
  1393. global $_FANWE;
  1394. $_img_data = array('goods','photo','goods_photo');
  1395. $is_edit_tag = false;
  1396. if(in_array($share['share_data'],$_img_data) && $share['uid'] == $_FANWE['uid'])
  1397. $is_edit_tag = true;
  1398. return $is_edit_tag;
  1399. }
  1400. /**
  1401. * ??????
  1402. * @param int $share_id ????
  1403. * @return array
  1404. */
  1405. public function getShareTags($share_id,$is_update = false)
  1406. {
  1407. $share_id = (int)$share_id;
  1408. if(!$share_id)
  1409. return array();
  1410. static $list = array();
  1411. if(!isset($list[$share_id]) || $is_update)
  1412. {
  1413. $res = FDB::query('SELECT tag_name,is_admin
  1414. FROM '.FDB::table('share_tags').'
  1415. WHERE share_id = '.$share_id);
  1416. while($data = FDB::fetch($res))
  1417. {
  1418. $data['tag_name'] = addslashes($data['tag_name']);
  1419. if($data['is_admin'] == 0)
  1420. $list[$share_id]['user'][] = $data;
  1421. else
  1422. $list[$share_id]['admin'][] = $data;
  1423. }
  1424. }
  1425. return $list[$share_id];
  1426. }
  1427. public function tagsFormat(&$tags)
  1428. {
  1429. foreach($tags as $tk => $tag)
  1430. {
  1431. $tags[$tk]['url'] = FU('book/shopping',array('tag'=>urlencode($tag['tag_name'])));
  1432. }
  1433. }
  1434. /**
  1435. * ????????
  1436. * @param int $share_id ????
  1437. * @param array $tags = array(
  1438. 'user'=>??????,
  1439. 'admin'=>???????,(?????admin?????????????)
  1440. );
  1441. * @return array
  1442. */
  1443. public function updateShareTags($share_id,$tags)
  1444. {
  1445. global $_FANWE;
  1446. //?????????
  1447. FDB::delete('share_tags','share_id = '.$share_id.' AND is_admin = 0');
  1448. if(isset($tags['user']))
  1449. {
  1450. $tags['user'] = str_replace('?',' ',$tags['user']);
  1451. $tags['user'] = explode(' ',htmlspecialchars(trim($tags['user'])));
  1452. $tags['user'] = array_unique($tags['user']);
  1453. $tags['user'] = array_slice($tags['user'],0,$_FANWE['setting']['share_tag_count']);
  1454. $share_tags = array();
  1455. foreach($tags['user'] as $tag)
  1456. {
  1457. if(trim($tag) != '' && !in_array($tag,$share_tags))
  1458. {
  1459. array_push($share_tags,$tag);
  1460. //?????tags????
  1461. FDB::query('UPDATE '.FDB::table('goods_tags').'
  1462. SET count = count + 1
  1463. WHERE tag_name = \''.$tag.'\'');
  1464. //????100??????
  1465. FDB::query('UPDATE '.FDB::table('goods_tags').'
  1466. SET is_hot = 1
  1467. WHERE tag_name = \''.$tag.'\' AND count >= 100');
  1468. $tag_data = array();
  1469. $tag_data['share_id'] = $share_id;
  1470. $tag_data['tag_name'] = $tag;
  1471. FDB::insert('share_tags',$tag_data);
  1472. }
  1473. }
  1474. ShareService::updateShareCache($share_id,'tags');
  1475. }
  1476. //??????????
  1477. if(isset($tags['admin']))
  1478. {
  1479. FDB::delete('share_tags','share_id = '.$share_id.' AND is_admin = 1');
  1480. $tags['admin'] = str_replace('?',' ',$tags['admin']);
  1481. $tags['admin'] = explode(' ',htmlspecialchars(trim($tags['admin'])));
  1482. $tags['admin'] = array_unique($tags['admin']);
  1483. $share_tags = array();
  1484. foreach($tags['admin'] as $tag)
  1485. {
  1486. if(trim($tag) != '' && !in_array($tag,$share_tags))
  1487. {
  1488. array_push($share_tags,$tag);
  1489. //?????tags????
  1490. FDB::query('UPDATE '.FDB::table('goods_tags').'
  1491. SET count = count + 1
  1492. WHERE tag_name = \''.$tag.'\'');
  1493. //????100??????
  1494. FDB::query('UPDATE '.FDB::table('goods_tags').'
  1495. SET is_hot = 1
  1496. WHERE tag_name = \''.$tag.'\' AND count >= 100');
  1497. $tag_data = array();
  1498. $tag_data['sh…

Large files files are truncated, but you can click here to view the full file