/startZine/src/main/core/service/share.service.php
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
- <?php
- // +----------------------------------------------------------------------
- // | ?????????? (Build on ThinkPHP)
- // +----------------------------------------------------------------------
- // | Copyright (c) 2011 http://fanwe.com All rights reserved.
- // +----------------------------------------------------------------------
-
- /**
- * share.service.php
- *
- * ?????
- *
- * @package service
- * @author awfigq <awfigq@qq.com>
- */
- class ShareService
- {
- /*===========??????? Begin==============*/
- /**
- * ?????????
- * @param string $content ????
- * @param string $type content,title,tag ????
- * @return array(
- * 'error_code' => '????'
- * 'error_msg' => ????
- * )
- */
- public function checkWord(&$content,$type)
- {
- $result = array('error_code'=>0,'error_msg'=>'');
- $server = FS("ContentCheck");
- if($server->check($content) > 0)
- {
- $words_found = implode("?", $server->words_found);
- $tt_str = lang('share','word_'.$type);
- $result['error_code'] = $server->result;
- $result['error_msg'] = sprintf(lang('share','word_tips_'. $server->result),$tt_str,$words_found);
- }
- return $result;
- }
-
- /**
- * ??????????????
- * @param mix $_POST ??????? $_POST['type'] default:??,bar:??,ershou:??,ask:??
- * $_POST['share_data'] = photo ?? goods ??? goods_photo:????? default:???
- * * ??
- * array(
- * 'status' => xxx ?? bool
- * 'share_id' => share_id
- * 'error_code' => '????'
- * 'error_msg' => ????
- * )
- */
- public function submit($_POST,$is_check = true,$is_score = true,$is_album = FALSE)
- {
- //??????
- global $_FANWE;
- $share_content = htmlspecialchars(trim($_POST['content']));
- $share_data = array();
- $share_data['content'] = $share_content;
-
- $share_data['uid'] = intval($_FANWE['uid']);
- $share_data['parent_id'] = intval($_POST['parent_id']); //?????
- $share_data['rec_id'] = intval($_POST['rec_id']); //?????
- $share_data['base_id'] = intval($_POST['base_id']);
- $share_data['albumid'] = intval($_POST['albumid']);
-
- if($is_check)
- {
- $check_result = ShareService::checkWord($share_data['content'],'content');
- if($check_result['error_code'] == 1)
- {
- $check_result['status'] = false;
- return $check_result;
- }
- }
-
- /*//????????????ID
- if($share_data['parent_id'] > 0 && $share_data['base_id'] == 0)
- {
- $base_id = intval(FDB::resultFirst('SELECT base_id
- FROM '.FDB::table("share").'
- WHERE share_id = '.$share_data['parent_id']));
-
- $share_data['base_id'] = $base_id == 0 ? $share_data['parent_id'] : $base_id;
- }*/
-
- if(isset($_POST['type']))
- $share_data['type'] = $_POST['type'];
-
- $share_data['title'] = isset($_POST['title']) ? htmlspecialchars(trim($_POST['title'])) : '';
- if(!empty($share_data['title']) && $is_check)
- {
- $check_result = ShareService::checkWord($share_data['title'],'title');
- if($check_result['error_code'] == 1)
- {
- $check_result['status'] = false;
- return $check_result;
- }
- }
-
- $data['share'] = $share_data;
-
- //????????
- $share_goods_data = array();
- if(isset($_POST['goods']) && is_array($_POST['goods']) && count($_POST['goods']) > 0)
- {
- $share_goods = $_POST['goods'];
- foreach($share_goods as $goods)
- {
- $goods = unserialize(authcode($goods,'DECODE'));
- $gkey = $goods['item']['key'];
- $c_data = array();
- $c_data['img'] = $goods['item']['img'];
- $c_data['goods_key'] = $gkey;
- $c_data['name'] = addslashes(htmlspecialchars($goods['item']['name']));
- $c_data['url'] = $goods['item']['url'];
- $c_data['taoke_url'] = $goods['item']['taoke_url'];
- $c_data['price'] = $goods['item']['price'];
- $c_data['sort'] = isset($_POST['goods_sort'][$gkey]) ? intval($_POST['goods_sort'][$gkey]) : 10;
- $c_data['shop_name'] = addslashes(htmlspecialchars($goods['shop']['name']));
- $c_data['shop_logo'] = $goods['shop']['logo'];
- $c_data['shop_url'] = $goods['shop']['url'];
- $c_data['shop_taoke_url'] = $goods['shop']['taoke_url'];
- array_push($share_goods_data,$c_data);
- }
- }
- $data['share_goods'] = $share_goods_data;
- //??????
- $share_photos_data = array();
- if(isset($_POST['pics']) && is_array($_POST['pics']) && count($_POST['pics']) > 0)
- {
- $share_photos = $_POST['pics'];
- foreach($share_photos as $pkey => $photo)
- {
- $photo = authcode($photo,'DECODE');
- $photo = unserialize($photo);
- $c_data = array();
- $c_data['img'] = $photo['path'];
-
- $type = $photo['type'];
- if(empty($type) || !in_array($type,array('default', 'dapei', 'look')))
- $type = 'default';
- $c_data['type'] = $type;
- $c_data['sort'] = isset($_POST['pics_sort'][$pkey]) ? intval($_POST['pics_sort'][$pkey]) : 10;
- array_push($share_photos_data,$c_data);
- }
- }
- $data['share_photo'] = $share_photos_data;
-
- if($share_data['albumid'] > 0 && count($share_photos_data) == 0 && count($share_goods_data) == 0)
- exit;
-
- $data['share_tag'] = array();
-
- if(isset($_POST['tags']) && trim($_POST['tags']) != '')
- {
- $tags = htmlspecialchars(trim($_POST['tags']));
- if($is_check)
- {
- $check_result = ShareService::checkWord($tags,'tag');
- if($check_result['error_code'] == 1)
- {
- $check_result['status'] = false;
- return $check_result;
- }
- }
- $tags = str_replace('?',' ',$tags);
- $data['share_tag'] = explode(' ',$tags);
- }
-
- $data['pub_out_check'] = intval($_POST['pub_out_check']); //???????
- $result = ShareService::save($data,$is_score,$is_album);
- return $result;
- }
-
- /**
- * ??????
- * ??????????????????????????
- * $data = array( //???????
- * 'share'=>array(
- * 'uid'=> xxx, //?????ID
- * 'parent_id' => xxx //?????ID
- * 'content' => xxx //?????
- * 'type'=> xxx //?????????default
- * 'title' => xxx //?????
- * 'base_id' => xxx //??ID
- * ),
- *
- * 'share_photo'=>array( //?? #??#
- * array( //???
- * 'img' => xxx //??
- * )
- * ),
- * 'share_goods'=>array( //????? #??#
- * array(
- * 'img' => xxx //???
- * 'name' => xxx //??
- * 'url' => xxx //????
- * 'price' => xxx //??
- * 'shop_name' => xxx //????
- * 'shop_logo' => xxx //???logo
- * 'shop_url' => xxx //????
- * ) //????
- * ),
- * 'share_tag' => array(xxx,xxx,xxx), //??????
- * );
- *
- * ??
- * array(
- * 'status' => xxx ?? bool
- * 'share_id' => share_id
- * )
- */
- public function save($data,$is_score = true,$is_album = FALSE)
- {
- global $_FANWE;
- //??????
- $share_data = $data['share'];
- $share_album_id = (int)$share_data['albumid'];
- unset($share_data['albumid']);
- $share_data['create_time'] = TIME_UTC;
- $share_data['day_time'] = getTodayTime();
- $share_data['share_content_match'] = segmentToUnicode(strtolower(clearSymbol($share_data['content'])));
-
-
- $share_id = FDB::insert('share',$share_data,true);
-
- if(intval($share_id)>0)
- {
- $share_data_now_type = $share_data['type'];
- $share_data_rec_id = $share_data['rec_id'];
- if(empty($share_data_now_type))
- $share_data_now_type = 'default';
-
- /*//????? ?? ? ????????
- if(intval($share_data['parent_id']) > 0)
- {
- $base_share_id = FDB::resultFirst("select uid from ".FDB::table('share')." where share_id = ".$share_data['parent_id']);
- $result = FDB::query("INSERT INTO ".FDB::table('user_notice')."(uid, type, num, create_time) VALUES('$base_share_id',3,1,'".TIME_UTC."')", 'SILENT');
- if(!$result)
- FDB::query("UPDATE ".FDB::table('user_notice')." SET num = num + 1, create_time='".TIME_UTC."' WHERE uid='$base_share_id' AND type=3");
- }*/
-
- //????
- $is_event = false;
- $event_list = array();
- $pattern = "/#([^\f\n\r\t\v]{1,80}?)#/";
- preg_match_all($pattern,$share_data['content'],$event_list);
- if(!empty($event_list[1]))
- {
- array_unique($event_list[1]);
- foreach($event_list[1] as $v)
- {
- $event_id = (int)FDB::resultFirst("select id from ".FDB::table("event")." where `title`='".$v."'");
- if($event_id == 0)
- {
- $event_data = array();
- $event_data['uid'] = $share_data['uid'];
- $event_data['title'] = $v;
- $event_data['share_id'] = $share_id;
- $event_data['create_time'] = TIME_UTC;
- $event_data['last_share'] = $share_id;
- $event_data['last_time'] = TIME_UTC;
- FDB::insert("event",$event_data);
- }
- else
- {
- $event_data = array();
- $event_data['event_id'] = $event_id;
- $event_data['uid'] = $share_data['uid'];
- $event_data['share_id'] = $share_id;
- FDB::insert("event_share",$event_data);
- FDB::query("update ".FDB::table("event")." set thread_count = thread_count+1,last_share=".$share_id.",last_time=".TIME_UTC." where id = $event_id");
- }
- }
- }
-
- $share_cates = array();
- $result['status'] = true;
- $result['share_id'] = $share_id;
-
- /*$content_match = FS('Words')->segment(clearExpress($share_data['content']),100);
- $title_tags = FS('Words')->segment($share_data['title'],100);
- if(!empty($title_tags))
- $content_match = array_merge($content_match, $title_tags);*/
-
- $content_match = clearExpress($share_data['content']);
- $content_match .= $share_data['title'];
-
- $is_rel_imgage = false;
- $weibo_img = '';
- $weibo_img_sort = 100000;
- $photo_count = 0;
-
- $server_args = array();
- FS("Image")->getImageArgs(&$server_args);
-
- //??????
- if(isset($data['share_photo'])){
- $share_photo = $data['share_photo'];
- foreach($share_photo as $k=>$photo)
- {
- if($photo_count >= $_FANWE['setting']['share_pic_count'])
- break;
-
- $o_img = false;
- if(FS("Image")->getIsServer() && !empty($photo['server_code']))
- {
- $server = FS("Image")->getServer($photo['server_code']);
- if(!empty($server))
- {
- $server_args['share_id'] = $share_id;
- $server_args['img_path'] = $photo['img'];
- $server = FS("Image")->getImageUrlToken($server_args,$server,1);
- $body = FS("Image")->sendRequest($server,'saveshare',true);
- if(!empty($body))
- {
- $o_img = unserialize($body);
- FS("Image")->setServerUploadCount($o_img['server_code']);
- $share_server_code[] = $o_img['server_code'];
- $o_img['url'] = str_replace('./','./'.$o_img['server_code'].'/',$o_img['url']);
- $weibo_img_url = FS("Image")->getImageUrl($o_img['url'],1);
- }
- }
- }
- else
- {
- $o_img = copyImage($photo['img'],array(),'share',true,$share_id);
- $weibo_img_url = FS("Image")->getImageUrl($o_img['url'],1);
- }
-
- if(!empty($o_img))
- {
- if($photo['sort'] < $weibo_img_sort)
- {
- $weibo_img = $weibo_img_url;
- $weibo_img_sort = $photo['sort'];
- }
- $share_photo_data['uid'] = $_FANWE['uid'];
- $share_photo_data['share_id'] = $share_id;
- $share_photo_data['img'] = $o_img['url'];
- $share_photo_data['type'] = $photo['type'];
- $share_photo_data['sort'] = $photo['sort'];
- $share_photo_data['img_width'] = $o_img['width'];
- $share_photo_data['img_height'] = $o_img['height'];
- $share_photo_data['server_code'] = $photo['server_code'];
- FDB::insert('share_photo',$share_photo_data,true);
- $photo_count++;
- }
- }
- }
-
- //??????
- if(isset($data['rel_photo']))
- {
- $share_photo = $data['rel_photo'];
- foreach($share_photo as $share_photo_data)
- {
- if($photo_count >= $_FANWE['setting']['share_pic_count'])
- break;
-
- $is_rel_imgage = true;
- if($share_photo_data['sort'] < $weibo_img_sort)
- {
- $weibo_img = $share_photo_data['img'];
- $weibo_img_sort = $share_photo_data['sort'];
- }
-
- $share_photo_data['uid'] = $_FANWE['uid'];
- $share_photo_data['share_id'] = $share_id;
- FDB::insert('share_photo',$share_photo_data,true);
- $photo_count++;
- }
- }
- //??????
- $post_count=0;
- if(isset($data['share_posts'])){
- $share_posts=$data['share_posts'];
- foreach($share_posts as $post){
- $share_post_data['uid'] = $_FANWE['uid'];
- $share_post_data['share_id'] = $share_id;
- $share_post_data['post_title'] = $post['post_title'];
- $share_post_data['post_content'] = $post['post_content'];
- $share_post_data['post_excerpt'] = $post['post_excerpt'];
- $share_post_data['post_type'] = $post['type'];
- $share_post_data['sort'] = $post['sort'];
- if(isset($post['feature_img']))
- $share_post_data['feature_img']=$post['feature_img'];
- FDB::insert('share_posts',$share_post_data,true);
- $post_count++;
- }
- }
- //??????
-
- $shop_ids = array();
- $goods_count = 0;
- //???????
- if(isset($data['share_goods']))
- {
- $share_goods = $data['share_goods'];
- foreach($share_goods as $goods)
- {
- if($goods_count >= $_FANWE['setting']['share_goods_count'])
- break;
-
- $shop_id = 0;
- if(!empty($goods['shop_url']))
- {
- $shop_id = FDB::resultFirst('SELECT shop_id
- FROM '.FDB::table('shop').'
- WHERE shop_url = \''.$goods['shop_url'].'\'');
-
- if(intval($shop_id) == 0)
- {
- $content_match .= $goods['shop_name'];
- $shop_logo = copyFile(FANWE_ROOT.$goods['shop_logo'],'shop',md5(microtime(true)).random('6').'.jpg',true);
- $shop_data['shop_name'] = $goods['shop_name'];
- $shop_data['shop_logo'] = $shop_logo['url'];
- $shop_data['shop_url'] = $goods['shop_url'];
- $shop_data['taoke_url'] = $goods['shop_taoke_url'];
- $shop_id = FDB::insert('shop',$shop_data,true);
- }
-
- if($shop_id > 0)
- $shop_ids[] = $shop_id;
- }
-
- $goods_img = copyImage(FANWE_ROOT.$goods['img'],md5(microtime(true)).random('6').'.jpg',array(),'share',true,$share_id);
- if(!empty($goods_img))
- {
- if($goods['sort'] < $weibo_img_sort)
- {
- $weibo_img = $goods_img['url'];
- $weibo_img_sort = $goods['sort'];
- }
-
- $shop_id = intval($shop_id);
- //?????????
- $share_goods_data['uid'] = $_FANWE['uid'];
- $share_goods_data['share_id'] = $share_id;
- $share_goods_data['shop_id'] = $shop_id;
- $share_goods_data['img'] = $goods_img['url'];
- $share_goods_data['name'] = $goods['name'];
- $share_goods_data['url'] = $goods['url'];
- $share_goods_data['price'] = $goods['price'];
- $share_goods_data['sort'] = $goods['sort'];
- $share_goods_data['taoke_url'] = $goods['taoke_url'];
- $share_goods_data['goods_key'] = $goods['goods_key'];
- FDB::insert('share_goods',$share_goods_data,true);
-
- $goods_tags = FS('Words')->segment($goods['name'],10);
- if(!empty($goods_tags))
- {
- $share_cates[] = ShareService::getCateByTags($goods_tags);
- }
- $content_match .= $goods['name'];
- $goods_count++;
- }
- }
- }
-
- //??????
- if(isset($data['rel_goods']))
- {
- $share_goods = $data['rel_goods'];
- foreach($share_goods as $share_goods_data)
- {
- if($goods_count >= $_FANWE['setting']['share_goods_count'])
- break;
-
- $is_rel_imgage = true;
- $shop_ids[] = $share_goods_data['shop_id'];
- if($share_goods_data['sort'] < $weibo_img_sort)
- {
- $weibo_img = $share_goods_data['img'];
- $weibo_img_sort = $share_goods_data['sort'];
- }
-
- $share_goods_data['uid'] = $_FANWE['uid'];
- $share_goods_data['share_id'] = $share_id;
- FDB::insert('share_goods',$share_goods_data,true);
- $goods_tags = FS('Words')->segment($goods['name'],10);
- if(!empty($goods_tags))
- {
- $share_cates[] = ShareService::getCateByTags($goods_tags);
- }
- $content_match .= $goods['name'];
- $goods_count++;
- }
- }
-
- if($goods_count > 0 && $photo_count > 0)
- $share_data_type = 'goods_photo';
- elseif($goods_count > 0)
- $share_data_type = 'goods';
- elseif($photo_count > 0)
- $share_data_type = 'photo';
- elseif($post_count>0)
- $share_data_type='post';
- else
- $share_data_type = 'default';
-
- $update_share = array();
- $update_share['share_data'] = $share_data_type;
-
- if($share_album_id > 0 && in_array($share_data_type,array('goods','photo','goods_photo','post')))
- {
- $album = FDB::fetchFirst('SELECT cid,id,title FROM '.FDB::table('album').' WHERE id = '.$share_album_id);
- if($album)
- {
- $update_share['type'] = 'album_item';
- $share_data_now_type = 'album_item';
- $share_data_rec_id = $album['id'];
- $share_data_rec_cate = $album['cid'];
- $update_share['rec_id'] = $album['id'];
- $update_share['title'] = addslashes($album['title']);
- }
- else
- {
- $update_share['rec_id'] = 0;
- $share_data_rec_id = 0;
- }
- }
- else
- $share_data_rec_id = 0;
-
- FDB::update("share",$update_share,"share_id=".$share_id);
-
- //??????---?????? $is_album = true
- if(!$is_album)
- FDB::query('UPDATE '.FDB::table('user_count').'
- SET shares = shares + 1,goods = goods + '.$goods_count.',photos = photos + '.$photo_count.'
- WHERE uid = '.$share_data['uid']);
-
- FS('Medal')->runAuto($share_data['uid'],'shares');
- FS('User')->medalBehavior($share_data['uid'],'continue_share');
-
- switch($share_data_type)
- {
- case 'goods_photo':
- FS('Medal')->runAuto($share_data['uid'],'goods');
- FS('User')->medalBehavior($share_data['uid'],'continue_goods');
- FS('Medal')->runAuto($share_data['uid'],'photos');
- FS('User')->medalBehavior($share_data['uid'],'continue_photo');
- break;
- case 'goods':
- FS('Medal')->runAuto($share_data['uid'],'goods');
- FS('User')->medalBehavior($share_data['uid'],'continue_goods');
- break;
- case 'photo':
- FS('Medal')->runAuto($share_data['uid'],'photos');
- FS('User')->medalBehavior($share_data['uid'],'continue_photo');
- break;
- }
-
- if(in_array($share_data_type,array('goods','photo','goods_photo','post')))
- {
- //?????????????
- //FS('User')->setShareIds($share_data['uid'],$share_id);
-
- if(!empty($share_cates))
- {
- $cids = ShareService::getCidsByCates($share_cates);
- }
-
- if(!empty($data['share_tag']))
- {
- if(empty($cids))
- {
- $share_cates = array();
- $share_cates[] = ShareService::getCateByTags($data['share_tag']);
- $cids = ShareService::getCidsByCates($share_cates);
- }
-
- //$content_match = array_merge($content_match, $data['share_tag']);
- }
-
- //????
- $share_tags = array();
- foreach($data['share_tag'] as $tag)
- {
- if(trim($tag) != '' && !in_array($tag,$share_tags))
- {
- array_push($share_tags,$tag);
-
- //?????tags????
- FDB::query('UPDATE '.FDB::table('goods_tags').'
- SET count = count + 1
- WHERE tag_name = \''.$tag.'\'');
-
- //????100??????
- FDB::query('UPDATE '.FDB::table('goods_tags').'
- SET is_hot = 1
- WHERE tag_name = \''.$tag.'\' AND count >= 100');
-
- $content_match.=$tag;
- $tag_data = array();
- $tag_data['share_id'] = $share_id;
- $tag_data['tag_name'] = $tag;
- FDB::insert('share_tags',$tag_data);
- }
- }
- unset($share_tags);
-
- if(!empty($cids))
- {
- foreach($cids as $cid)
- {
- $cate_data = array();
- $cate_data['share_id'] = $share_id;
- $cate_data['cate_id'] = $cid;
- FDB::insert('share_category',$cate_data);
- }
- }
-
- //??????
- $share_match['share_id'] = $share_id;
- $share_match['content_match'] = segmentToUnicode(clearSymbol($content_match));
- FDB::insert("share_match",$share_match);
- }
-
- ShareService::updateShareCache($share_id);
-
- if($share_data_rec_id > 0)
- {
- $album_share = array();
- $album_share['album_id'] = $share_data_rec_id;
- $album_share['share_id'] = $share_id;
- $album_share['cid'] = $share_data_rec_cate;
- $album_share['create_day'] = getTodayTime();
- FDB::insert("album_share",$album_share);
-
- FS('Album')->updateAlbumByShare($share_data_rec_id,$share_id);
- FS('Album')->updateAlbum($share_data_rec_id);
- }
-
- if(count($shop_ids) > 0)
- FS("Shop")->updateShopStatistic($shop_ids);
-
- //??????
- $atme_share_type = FDB::resultFirst("select `type` from ".FDB::table("share")." where `share_id`='".$share_id."'");
- if($atme_share_type != "fav")
- {
- $atme_list = array();
- $pattern = "/@([^\f\n\r\t\v@ ]{2,20}?)(?:\:| )/";
- preg_match_all($pattern,$share_data['content'],$atme_list);
- if(!empty($atme_list[1]))
- {
- $atme_list[1] = array_unique($atme_list[1]);
- $users = array();
- foreach($atme_list[1] as $user)
- {
- if(!empty($user))
- {
- $users[] = $user;
- }
- }
-
- $res = FDB::query('SELECT uid
- FROM '.FDB::table('user').'
- WHERE user_name '.FDB::createIN($users));
- while($data = FDB::fetch($res))
- {
- FS("User")->setUserTips($data['uid'],4,$share_id);
- }
- }
- }
-
- if($is_score && !in_array($share_data_now_type,array('fav','album_best','album_rec')))
- {
- if(!$is_rel_imgage && in_array($share_data_type,array('goods','photo','goods_photo','post')))
- FS("User")->updateUserScore($share_data['uid'],'share','image',$share_data['content'],$share_id);
- else
- FS("User")->updateUserScore($share_data['uid'],'share','default',$share_data['content'],$share_id);
- }
-
- if($data['pub_out_check'])
- {
- $weibo = array();
- $weibo['content'] = $share_data['content'];
- $weibo['img'] = $weibo_img;
- $weibo['ip'] = $_FANWE['client_ip'];
- $weibo['url'] = $_FANWE['site_url'].FU('note/index',array('sid'=>$share_id));
- $weibo['url'] = str_replace('//','/',$weibo['url']);
- $weibo['url'] = str_replace(':/','://',$weibo['url']);
- $weibo = base64_encode(serialize($weibo));
- if(empty($share_data['type']))
- $share_data['type'] = 'default';
-
- //???????
- $uid = $_FANWE['uid'];
- $user_binds = FS("User")->getUserBindList($uid);
- $is_open = false;
- foreach($user_binds as $class => $bind)
- {
- if($bind['sync'] && file_exists(FANWE_ROOT."login/".$class.".php"))
- {
- $check_field = "";
- if(in_array($share_data['type'],array('bar','ask')))
- $check_field = "topic";
- elseif($share_data['type'] == 'default')
- $check_field = "weibo";
-
- if($bind['sync'][$check_field] == 1)
- {
- $is_open = true;
- //????
- $schedule['uid'] = $uid;
- $schedule['type'] = $class;
- $schedule['data'] = $weibo;
- $schedule['pub_time'] = TIME_UTC;
- FDB::insert('pub_schedule',$schedule,true);
- }
- }
- }
-
- if($is_open)
- {
- $fp=fsockopen($_SERVER['HTTP_HOST'],80,&$errno,&$errstr,5);
- if($fp)
- {
- $request = "GET ".SITE_URL."login.php?loop=true&uid=".$uid." HTTP/1.0\r\n";
- $request .= "Host: ".$_SERVER['HTTP_HOST']."\r\n";
- $request .= "Connection: Close\r\n\r\n";
- fwrite($fp, $request);
- while(!feof($fp))
- {
- fgets($fp, 128);
- break;
- }
- fclose($fp);
- }
- }
- }
- }
- else
- {
- $result['status'] = false;
- }
- return $result;
- }
-
- /*??????????*/
- public function getCateByTags($tags)
- {
- static $tag_cates = array();
-
- $tags = array_unique($tags);
-
- $cates = array();
- foreach($tags as $tag)
- {
- if(!empty($tag))
- {
- if(isset($tag_cates[$tag]))
- {
- foreach($tag_cates[$tag] as $data)
- {
- if(isset($cates[$data['cate_id']]))
- $cates[$data['cate_id']] += $data['weight'];
- else
- $cates[$data['cate_id']] = $data['weight'];
- }
- continue;
- }
-
- $is_bln = true;
- $res = FDB::query('SELECT gct.cate_id,gct.weight
- FROM '.FDB::table('goods_tags').' AS gt
- LEFT JOIN '.FDB::table('goods_category_tags')." AS gct ON gct.tag_id = gt.tag_id
- WHERE gt.tag_name = '$tag'");
- while($data = FDB::fetch($res))
- {
- if($data['weight'] < 1)
- $data['weight'] = 1;
-
- if(isset($cates[$data['cate_id']]))
- $cates[$data['cate_id']] += $data['weight'];
- else
- $cates[$data['cate_id']] = $data['weight'];
-
- $tag_cates[$tag][] = $data;
- $is_bln = false;
- }
-
- if($is_bln)
- {
- $like_tag = fMysqlLikeQuote($tag);
- $res = FDB::query('SELECT gct.cate_id,gct.weight
- FROM '.FDB::table('goods_tags').' AS gt
- LEFT JOIN '.FDB::table('goods_category_tags')." AS gct ON gct.tag_id = gt.tag_id
- WHERE gt.tag_name LIKE '%".$like_tag."%' OR INSTR('$tag',gt.tag_name) > 0");
- while($data = FDB::fetch($res))
- {
- if($data['weight'] < 1)
- $data['weight'] = 1;
-
- if(isset($cates[$data['cate_id']]))
- $cates[$data['cate_id']] += $data['weight'];
- else
- $cates[$data['cate_id']] = $data['weight'];
-
- $tag_cates[$tag] = $data;
- }
- }
- }
- }
-
- if(empty($cates))
- return array();
-
- $cids = array();
- foreach($cates as $cate_id => $weight)
- {
- $cids[$weight][] = $cate_id;
- }
-
- krsort($cids);
- return each($cids);
- }
-
- public function getCidsByCates($cates)
- {
- $list = array();
- $cids = array();
- foreach($cates as $cate)
- {
- foreach($cate['value'] as $cid)
- {
- if(isset($cids[$cid]))
- $cids[$cid] = $cate['key'];
- else
- $cids[$cid] += $cate['key'];
- }
- }
-
- foreach($cates as $cate)
- {
- $id = 0;
- $weight = 0;
- foreach($cate['value'] as $cid)
- {
- if($cids[$cid] > $weight)
- $id = $cid;
- }
-
- if($id > 0)
- $list[] = $id;
- }
-
- return array_unique($list);
- }
-
- public function deleteShare($share_id,$is_score = true)
- {
- $share = ShareService::getShareById($share_id);
- if(!empty($share))
- {
- $goods_count = FDB::resultFirst('SELECT COUNT(goods_id) FROM '.FDB::table('share_goods').' WHERE share_id = '.$share_id);
- $photo_count = FDB::resultFirst('SELECT COUNT(photo_id) FROM '.FDB::table('share_photo').' WHERE share_id = '.$share_id);
- $collect_count = FDB::resultFirst('SELECT COUNT(c_uid) FROM '.FDB::table('user_collect').' WHERE share_id = '.$share_id);
-
- FDB::delete('share','share_id = '.$share_id);
- FDB::delete('share_goods','share_id = '.$share_id);
- //FDB::delete('share_photo','share_id = '.$share_id);
- FDB::delete('share_category','share_id = '.$share_id);
- FDB::delete('share_comment','share_id = '.$share_id);
- FDB::delete('share_match','share_id = '.$share_id);
- FDB::delete('share_tags','share_id = '.$share_id);
- FDB::delete('user_collect','share_id = '.$share_id);
-
- $pattern = "/#([^\f\n\r\t\v]{1,80}?)#/";
- if(preg_match($pattern,$share['content']))
- {
- FS("Event")->deleteEvent($share_id);
- }
-
- $pattern = "/@([^\f\n\r\t\v@ ]{2,20}?)(?:\:| )/";
- if(preg_match($pattern,$share['content']))
- {
- FDB::delete('atme','share_id = '.$share_id);
- }
-
- if(defined('MANAGE_HANDLER') && MANAGE_HANDLER && $is_score)
- {
- if(!in_array($share['type'],array('fav','album_best','album_rec')))
- {
- if($share['rec_uid'] == 0 && in_array($share['share_data'],array('goods','photo','goods_photo')))
- FS("User")->updateUserScore($share['uid'],'delete_share','image',$share['content'],$share_id);
- else
- FS("User")->updateUserScore($share['uid'],'delete_share','default',$share['content'],$share_id);
- }
- }
-
- FDB::query('UPDATE '.FDB::table('user_count').' SET
- shares = shares - 1,
- photos = photos - '.$photo_count.',
- goods = goods - '.$goods_count.',
- collects = collects - '.$collect_count.' WHERE uid = '.$share['uid']);
-
- $key = getDirsById($share_id);
- clearCacheDir('share/'.$key);
-
- $count = (int)FDB::resultFirst('SELECT COUNT(share_id) FROM '.FDB::table('share_rec').' WHERE share_id = '.$share_id);
- if($count == 0)
- clearDir(PUBLIC_ROOT.'./upload/share/'.$key,true);
- }
- }
-
- public function deleteShareCache()
- {
-
- }
-
- /**
- * ????????
- * @param int $share_id ????
- * @return array
- */
- public function getShareById($share_id)
- {
- $share_id = (int)$share_id;
- if(!$share_id)
- return false;
-
- static $list = array();
- if(!isset($list[$share_id]))
- {
- $share = FDB::fetchFirst('SELECT * FROM '.FDB::table('share').' WHERE share_id = '.$share_id);
- if($share)
- $share['url'] = FU('note/index',array('sid'=>$share_id));
- $list[$share_id] = $share;
- }
- return $list[$share_id];
- }
-
- /**
- * ??????
- * @param int $share_id ????
- * @return void
- */
- public function updateShare($share_id,$title,$content)
- {
- if(empty($title) && empty($content))
- return;
-
- $data = array();
- if(!empty($title))
- $data['title'] = $title;
-
- if(!empty($content))
- $data['content'] = $content;
-
- FDB::update('share',$data,"share_id = '$share_id'");
- ShareService::updateShareMatch($share_id);
- }
-
- /**
- * ??????
- * @param int $share_id ????
- * @return array
- */
- public function getShareDetail($share_id,$is_collect = false,$is_tag = false,$collect_count = 20)
- {
- $share = ShareService::getShareById($share_id);
- if($share)
- {
- $share['cache_data'] = unserialize($share['cache_data']);
- $share['authoritys'] = ShareService::getIsEditShare($share);
- $share['time'] = getBeforeTimelag($share['create_time']);
- ShareService::shareImageFormat($share);
- }
- return $share;
- }
-
- /**
- * ?????????
- * @param int $share_id ????
- * @return array
- */
- public function getShareDynamic($share_id)
- {
- $dynamic = FDB::fetchFirst('SELECT collect_count,comment_count,relay_count,click_count
- FROM '.FDB::table('share').'
- WHERE share_id = '.$share_id);
- return $dynamic;
- }
-
- /**
- * ????????
- * @param array $list ????
- * @param bool $is_parent ????????
- * @param bool $is_collect ?????????
- * @param bool $is_parent ????????
- * @return array
- */
- 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)
- {
- global $_FANWE;
- $shares = array();
- $share_ids = array();
- $rec_shares_ids = array();
- $share_users = array();
- $share_collects = array();
- $share_comments = array();
- $share_follows = array();
-
- foreach($list as $item)
- {
- $share_id = $item['share_id'];
- $share_ids[] = $share_id;
- $item['cache_data'] = unserialize($item['cache_data']);
- $item['authoritys'] = ShareService::getIsEditShare($item);
- $item['time'] = getBeforeTimelag($item['create_time']);
- $item['url'] = FU('note/index',array('sid'=>$share_id));
- ShareService::shareImageFormat($item);
- $shares[$share_id] = $item;
- unset($shares[$share_id]['cache_data']);
-
- //????
- if($is_user)
- {
- $shares[$share_id]['user'] = &$share_users[$item['uid']];
- if($item['rec_uid'] > 0)
- $shares[$share_id]['rec_user'] = &$share_users[$item['rec_uid']];
- }
-
- //????
- if($is_comment)
- {
- $shares[$share_id]['comments'] = array();
- if(!empty($item['cache_data']['comments']))
- {
- $comment_ids = array_slice($item['cache_data']['comments'],0,$comment_count);
- foreach($comment_ids as $comment_id)
- {
- $shares[$share_id]['comments'][$comment_id] = &$share_comments[$comment_id];
- }
- }
- }
-
- //???????
- if($is_collect)
- {
- $shares[$share_id]['collects'] = array();
- if(!empty($item['cache_data']['collects']))
- {
- $collect_ids = array_slice($item['cache_data']['collects'],0,$collect_count);
- foreach($collect_ids as $collect_uid)
- {
- if($is_user)
- $shares[$share_id]['collects'][$collect_uid] = &$share_users[$collect_uid];
- else
- $shares[$share_id]['collects'][$collect_uid] = $collect_uid;
- }
- }
- }
-
- if($is_tag)
- {
- $shares[$share_id]['is_eidt_tag'] = ShareService::getIsEditTag($item);
- $shares[$share_id]['tags'] = $item['cache_data']['tags'];
- ShareService::tagsFormat($shares[$share_id]['tags']['user']);
- }
-
- $shares[$share_id]['is_relay'] = false;
- $shares[$share_id]['is_parent'] = false;
-
- if($is_parent)
- {
- if($item['base_id'] > 0)
- {
- $shares[$share_id]['is_relay'] = true;
- $rec_shares_ids[$item['base_id']] = false;
- $shares[$share_id]['relay_share'] = &$rec_shares_ids[$item['base_id']];
-
- if($item['parent_id'] > 0 && $item['parent_id'] != $item['base_id'])
- {
- $shares[$share_id]['is_parent'] = true;
- $rec_shares_ids[$item['parent_id']] = false;
- $shares[$share_id]['parent_share'] = &$rec_shares_ids[$item['parent_id']];
- }
- }
- }
- }
-
- $rec_ids = array_keys($rec_shares_ids);
- if(count($rec_ids) > 0)
- {
- $intersects = array_intersect($share_ids,$rec_ids);
- $temp_ids = array();
- foreach($intersects as $share_id)
- {
- $rec_shares_ids[$share_id] = $shares[$share_id];
- $temp_ids[] = $share_id;
- }
-
- $diffs = array_diff($rec_ids,$temp_ids);
- if(count($diffs) > 0)
- {
- $res = FDB::query('SELECT * FROM '.FDB::table('share').' WHERE share_id IN ('.implode(',',$diffs).')');
- while($item = FDB::fetch($res))
- {
- $share_id = $item['share_id'];
- $share_ids[] = $share_id;
- $item['cache_data'] = unserialize($item['cache_data']);
- $item['authoritys'] = ShareService::getIsEditShare($item);
- $item['time'] = getBeforeTimelag($item['create_time']);
- $item['url'] = FU('note/index',array('sid'=>$share_id));
- ShareService::shareImageFormat($item);
- $rec_shares_ids[$share_id] = $item;
- unset($rec_shares_ids[$share_id]['cache_data']);
-
- //????
- if($is_user)
- {
- $rec_shares_ids[$share_id]['user'] = &$share_users[$item['uid']];
- if($item['rec_uid'] > 0)
- $rec_shares_ids[$share_id]['rec_user'] = &$share_users[$item['rec_uid']];
- }
-
- //????
- if($is_comment)
- {
- $rec_shares_ids[$share_id]['comments'] = array();
- if(!empty($item['cache_data']['comments']))
- {
- $comment_ids = array_slice($item['cache_data']['comments'],0,$comment_count);
- foreach($comment_ids as $comment_id)
- {
- $rec_shares_ids[$share_id]['comments'][$comment_id] = &$share_comments[$comment_id];
- }
- }
- }
-
- //???????
- if($is_collect)
- {
- $rec_shares_ids[$share_id]['collects'] = array();
- if(!empty($item['cache_data']['collects']))
- {
- $collect_ids = array_slice($item['cache_data']['collects'],0,$collect_count);
- foreach($collect_ids as $collect_uid)
- {
- if($is_user)
- $rec_shares_ids[$share_id]['collects'][$collect_uid] = &$share_users[$collect_uid];
- else
- $rec_shares_ids[$share_id]['collects'][$collect_uid] = $collect_uid;
- }
- }
- }
-
- if($is_tag)
- {
- $rec_shares_ids[$share_id]['is_eidt_tag'] = ShareService::getIsEditTag($item);
- $rec_shares_ids[$share_id]['tags'] = $item['cache_data']['tags'];
- ShareService::tagsFormat($rec_shares_ids[$share_id]['tags']['user']);
- }
- }
- }
- }
-
- $comment_ids = array_keys($share_comments);
- if(count($comment_ids) > 0)
- {
- $res = FDB::query("SELECT * FROM ".FDB::table('share_comment').' WHERE comment_id IN ('.implode(',',$comment_ids).')');
- while($item = FDB::fetch($res))
- {
- $item['time'] = getBeforeTimelag($item['create_time']);
- $share_comments[$item['comment_id']] = $item;
- if($is_user)
- $share_comments[$item['comment_id']]['user'] = &$share_users[$item['uid']];
- }
- }
-
- if($is_user)
- FS('User')->usersFormat($share_users);
-
- return $shares;
- }
-
- /**
- * ???????
- */
- public function getShareImage($share_id,$data_type)
- {
- $share_id = (int)$share_id;
- $list = array();
- switch($data_type)
- {
- case 'goods':
- $sql = 'SELECT share_id,goods_id AS id,img,\'g\' AS type,name,url,price,taoke_url
- FROM '.FDB::table('share_goods').'
- WHERE share_id = '.$share_id.' ORDER BY sort ASC';
- $res = FDB::query($sql);
- while($data = FDB::fetch($res))
- {
- $data['name'] = addslashes($data['name']);
- $data['url'] = addslashes($data['url']);
- $pkey = $data['type'].$data['id'];
- $list['all'][$pkey] = $data;
- }
- break;
- case 'photo':
- $sql = 'SELECT share_id,photo_id AS id,img,type AS ptype,\'m\' AS type,\'\' AS name,\'\' AS url,0 AS price
- FROM '.FDB::table('share_photo').'
- WHERE share_id = '.$share_id.' ORDER BY sort ASC';
- $res = FDB::query($sql);
- while($data = FDB::fetch($res))
- {
- $pkey = $data['type'].$data['id'];
- $ptype = $data['ptype'];
- unset($data['ptype']);
- $list['all'][$pkey] = $data;
- if($ptype != 'default')
- {
- $list[$ptype][] = $pkey;
- }
- }
- break;
- case 'goods_photo':
- $sql = '(SELECT share_id,goods_id AS id,img,\'default\' AS ptype,\'g\' AS type,name,url,price,taoke_url,sort
- FROM '.FDB::table('share_goods').'
- WHERE share_id = '.$share_id.')
- UNION
- (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
- FROM '.FDB::table('share_photo').'
- WHERE share_id = '.$share_id.')
- ORDER BY sort ASC';
-
- $res = FDB::query($sql);
- while($data = FDB::fetch($res))
- {
- $data['name'] = addslashes($data['name']);
- $data['url'] = addslashes($data['url']);
- $pkey = $data['type'].$data['id'];
- $ptype = $data['ptype'];
- unset($data['ptype']);
- unset($data['sort']);
- $list['all'][$pkey] = $data;
- if($ptype != 'default')
- {
- $list[$ptype][] = $pkey;
- }
- }
- break;
- }
- return $list;
- }
-
- /**
- * ?????????
- */
- public function getShareImages(&$share_datas)
- {
- foreach($share_datas as $share_data => $share_ids)
- {
- if($share_data == 'default' || count($share_ids) == 0)
- continue;
-
- $share_ids = array_keys($share_ids);
- $list = array();
- switch($share_data)
- {
- case 'goods':
- $sql = 'SELECT share_id,goods_id AS id,img,\'g\' AS type,name,url,price,taoke_url
- FROM '.FDB::table('share_goods').'
- WHERE share_id IN ('.implode(',',$share_ids).') ORDER BY sort ASC';
- $res = FDB::query($sql);
- while($data = FDB::fetch($res))
- {
- $list[$data['share_id']]['all'][] = $data;
- }
- break;
- case 'photo':
- $sql = 'SELECT share_id,photo_id AS id,img,type AS ptype,\'m\' AS type,\'\' AS name,\'\' AS url,0 AS price
- FROM '.FDB::table('share_photo').'
- WHERE share_id IN ('.implode(',',$share_ids).') ORDER BY sort ASC';
- $res = FDB::query($sql);
- while($data = FDB::fetch($res))
- {
- $pkey = $data['type'].$data['id'];
- $ptype = $data['ptype'];
- unset($data['ptype']);
- $list[$data['share_id']]['all'][$pkey] = $data;
- if($ptype != 'default')
- {
- $list[$data['share_id']][$ptype][] = $pkey;
- }
- }
- break;
- case 'goods_photo':
- $sql = '(SELECT share_id,goods_id AS id,img,\'default\' AS ptype,\'g\' AS type,name,url,price,taoke_url,sort
- FROM '.FDB::table('share_goods').'
- WHERE share_id IN ('.implode(',',$share_ids).'))
- UNION
- (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
- FROM '.FDB::table('share_photo').'
- WHERE share_id IN ('.implode(',',$share_ids).'))
- ORDER BY sort ASC';
-
- $res = FDB::query($sql);
- while($data = FDB::fetch($res))
- {
- $pkey = $data['type'].$data['id'];
- $ptype = $data['ptype'];
- unset($data['ptype']);
- unset($data['sort']);
- $list[$data['share_id']]['all'][$pkey] = $data;
- if($ptype != 'default')
- {
- $list[$data['share_id']][$ptype][] = $pkey;
- }
- }
- break;
- }
-
- foreach($list as $share_id => $item)
- {
- foreach($item['all'] as $ik => $img)
- {
- if($img['type'] == 'g')
- {
- $img['goods_url'] = $img['url'];
- if(empty($img['taoke_url']))
- $img['to_url'] = FU('tgo',array('url'=>$img['url']));
- else
- $img['to_url'] = FU('tgo',array('url'=>$img['taoke_url']));
-
- $img['price_format'] = priceFormat($img['price']);
- }
-
- $img['url'] = FU('note/'.$img['type'],array('sid'=>$img['share_id'],'id'=>$img['id']));
- $item['all'][$ik] = $img;
- }
- $share_datas[$share_data][$share_id] = $item;
- }
- }
- }
-
- public function shareImageFormat(&$share,$pic_num = 0)
- {
- $images = $share['cache_data']['imgs'];
- foreach($images['all'] as $ik => $img)
- {
- if($img['type'] == 'g')
- {
- $img['goods_url'] = $img['url'];
- if(empty($img['taoke_url']))
- $img['to_url'] = FU('tgo',array('url'=>$img['url']));
- else
- $img['to_url'] = FU('tgo',array('url'=>$img['taoke_url']));
-
- $img['price_format'] = priceFormat($img['price']);
- }
-
- $img['url'] = FU('note/'.$img['type'],array('sid'=>$img['share_id'],'id'=>$img['id']));
- $images['all'][$ik] = $img;
- $share['imgs'][] = $img;
- }
-
- foreach($images['dapei'] as $ik)
- {
- $share['dapei_imgs'][] = $images['all'][$ik];
- }
-
- foreach($images['look'] as $ik)
- {
- $share['look_imgs'][] = $images['all'][$ik];
- }
-
- if($pic_num > 0 && count($share['imgs']) > $pic_num)
- $share['imgs'] = array_slice($share['imgs'],0,$pic_num);
- unset($images);
- }
-
- /**
- * ?????????????????
- * @param array $_POST ?????
- * @return array(
- 'prev'=>?????,
- 'next'=>?????,
- )
- */
- public function getPrevNextShares($uid,$share_id)
- {
- $arr = array('prev'=>0,'next'=>0);
- $share_ids = FS('User')->getShareIds($uid);
-
- $key = array_search($share_id,$share_ids);
- if($key !== false)
- {
- $count = count($share_ids);
- if($count > 1)
- {
- if($key == 0)
- {
- $arr['prev'] = $share_ids[$count - 1];
- $arr['next'] = $share_ids[$key + 1];
- }
- elseif($key == $count - 1)
- {
- $arr['prev'] = $share_ids[$key - 1];
- $arr['next'] = $share_ids[0];
- }
- else
- {
- $arr['prev'] = $share_ids[$key - 1];
- $arr['next'] = $share_ids[$key + 1];
- }
- }
- }
- return $arr;
- }
-
- public function updateShareCache($share_id,$type = 'all')
- {
- $share_id = (int)$share_id;
- if(!$share_id)
- return;
-
- $share = FDB::fetchFirst('SELECT cache_data,share_data FROM '.FDB::table('share').' WHERE share_id = '.$share_id);
- if(!$share)
- return;
-
- $cache_data = unserialize($share['cache_data']);
- switch($type)
- {
- case 'tags':
- $cache_data['tags'] = ShareService::getShareTags($share_id,true);
- break;
-
- case 'collects':
- $cache_data['collects'] = ShareService::getShareCollectUser($share_id,50);
- break;
-
- case 'comments':
- $cache_data['comments'] = ShareService::getNewCommentIdsByShare($share_id,10);
- break;
-
- case 'imgs':
- $cache_data['imgs'] = ShareService::getShareImage($share_id,$share['share_data']);
- break;
-
- case 'all':
- $cache_data['tags'] = ShareService::getShareTags($share_id,true);
- $cache_data['collects'] = ShareService::getShareCollectUser($share_id,50);
- $cache_data['comments'] = ShareService::getNewCommentIdsByShare($share_id,10);
- $cache_data['imgs'] = ShareService::getShareImage($share_id,$share['share_data']);
- break;
- }
- unset($share['share_data']);
- $share['cache_data'] = serialize($cache_data);
- FDB::update("share",$share,'share_id = '.$share_id);
- }
-
- public function updateShareMatch($share_id)
- {
- $share = ShareService::getShareById($share_id);
- if(!in_array($share['share_data'],array('goods','photo','goods_photo')))
- return;
-
- $share['cache_data'] = unserialize($share['cache_data']);
-
- $content_match = clearExpress($share['content']);
- $content_match .= $share['title'];
-
- if(isset($share['cache_data']['tags']['user']))
- {
- foreach($share['cache_data']['tags']['user'] as $tag)
- {
- $content_match.=$tag['tag_name'];
- }
- }
-
- if(isset($share['cache_data']['tags']['admin']))
- {
- foreach($share['cache_data']['tags']['admin'] as $tag)
- {
- $content_match.=$tag['tag_name'];
- }
- }
-
- if(isset($share['cache_data']['imgs']['all']))
- {
- foreach($share['cache_data']['imgs']['all'] as $img)
- {
- if(!empty($img['name']))
- {
- $content_match.=$img['name'];
- }
- }
- }
-
- //??????
- $share_match = array();
- $share_match['share_id'] = $share_id;
- $share_match['content_match'] = segmentToUnicode(clearSymbol($content_match));
- FDB::insert("share_match",$share_match,false,true);
- }
-
- /**
- * ?????????
- * @param int $share ??
- * @return array
- */
- public function getIsEditShare(&$share)
- {
- static $edits = array();
- if(!isset($edits[$share['share_id']]))
- {
- global $_FANWE;
- $type = array('ask','bar');
- $is_edit = 0;
- $post = array('ask_post','bar_post');
- if(in_array($share['type'],$post))
- {
- if($share['uid'] == $_FANWE['uid'])
- $is_edit = 1;
-
- if($share['type'] == 'ask_post')
- $thread = FS('ask')->getTopicById($share['rec_id']);
- else
- $thread = FS('Topic')->getTopicById($share['rec_id']);
-
- if($thread['uid'] == $_FANWE['uid'])
- $is_edit = 2;
- }
- else
- {
- if(!in_array($share['type'],$type) && $share['uid'] == $_FANWE['uid'])
- $is_edit = 1;
- }
-
- $edits[$share['share_id']] = $is_edit;
- }
-
- return $edits[$share['share_id']];
- }
- /*===========??????? END ==============*/
-
- /*===========???? BEGIN ==============*/
- /**
- * ???????????
- * @param int $share ??
- * @return array
- */
- public function getIsEditTag(&$share)
- {
- global $_FANWE;
- $_img_data = array('goods','photo','goods_photo');
- $is_edit_tag = false;
- if(in_array($share['share_data'],$_img_data) && $share['uid'] == $_FANWE['uid'])
- $is_edit_tag = true;
- return $is_edit_tag;
- }
-
- /**
- * ??????
- * @param int $share_id ????
- * @return array
- */
- public function getShareTags($share_id,$is_update = false)
- {
- $share_id = (int)$share_id;
- if(!$share_id)
- return array();
-
- static $list = array();
- if(!isset($list[$share_id]) || $is_update)
- {
- $res = FDB::query('SELECT tag_name,is_admin
- FROM '.FDB::table('share_tags').'
- WHERE share_id = '.$share_id);
- while($data = FDB::fetch($res))
- {
- $data['tag_name'] = addslashes($data['tag_name']);
- if($data['is_admin'] == 0)
- $list[$share_id]['user'][] = $data;
- else
- $list[$share_id]['admin'][] = $data;
- }
- }
-
- return $list[$share_id];
- }
-
- public function tagsFormat(&$tags)
- {
- foreach($tags as $tk => $tag)
- {
- $tags[$tk]['url'] = FU('book/shopping',array('tag'=>urlencode($tag['tag_name'])));
- }
- }
-
- /**
- * ????????
- * @param int $share_id ????
- * @param array $tags = array(
- 'user'=>??????,
- 'admin'=>???????,(?????admin?????????????)
- );
- * @return array
- */
- public function updateShareTags($share_id,$tags)
- {
- global $_FANWE;
- //?????????
- FDB::delete('share_tags','share_id = '.$share_id.' AND is_admin = 0');
- if(isset($tags['user']))
- {
- $tags['user'] = str_replace('?',' ',$tags['user']);
- $tags['user'] = explode(' ',htmlspecialchars(trim($tags['user'])));
- $tags['user'] = array_unique($tags['user']);
- $tags['user'] = array_slice($tags['user'],0,$_FANWE['setting']['share_tag_count']);
-
- $share_tags = array();
- foreach($tags['user'] as $tag)
- {
- if(trim($tag) != '' && !in_array($tag,$share_tags))
- {
- array_push($share_tags,$tag);
-
- //?????tags????
- FDB::query('UPDATE '.FDB::table('goods_tags').'
- SET count = count + 1
- WHERE tag_name = \''.$tag.'\'');
-
- //????100??????
- FDB::query('UPDATE '.FDB::table('goods_tags').'
- SET is_hot = 1
- WHERE tag_name = \''.$tag.'\' AND count >= 100');
-
- $tag_data = array();
- $tag_data['share_id'] = $share_id;
- $tag_data['tag_name'] = $tag;
- FDB::insert('share_tags',$tag_data);
- }
- }
- ShareService::updateShareCache($share_id,'tags');
- }
-
- //??????????
- if(isset($tags['admin']))
- {
- FDB::delete('share_tags','share_id = '.$share_id.' AND is_admin = 1');
-
- $tags['admin'] = str_replace('?',' ',$tags['admin']);
- $tags['admin'] = explode(' ',htmlspecialchars(trim($tags['admin'])));
- $tags['admin'] = array_unique($tags['admin']);
-
- $share_tags = array();
- foreach($tags['admin'] as $tag)
- {
- if(trim($tag) != '' && !in_array($tag,$share_tags))
- {
- array_push($share_tags,$tag);
-
- //?????tags????
- FDB::query('UPDATE '.FDB::table('goods_tags').'
- SET count = count + 1
- WHERE tag_name = \''.$tag.'\'');
-
- //????100??????
- FDB::query('UPDATE '.FDB::table('goods_tags').'
- SET is_hot = 1
- WHERE tag_name = \''.$tag.'\' AND count >= 100');
-
- $tag_data = array();
- $tag_data['sh…
Large files files are truncated, but you can click here to view the full file