function copyImage($img) { $img_path = IMG_TEMP_FOLDER . md5($img); $img_type = substr($img, strrpos($img, '.') + 1); if ($img_type != 'jpg') { exit; } if (copy($img, $img_path . '.' . $img_type)) { return $img_path . '.' . $img_type; } else { copyImage($img); } }
<?php if (!isset($_REQUEST['http_url']) || empty($_REQUEST['http_url']) || $_REQUEST['http_url'] == "http://") { exit; } //http://localhost/share_tu/services/service.php?m=share&a=uploadhttpfile&http_url=http://file.weipic.com/uploadfile/20110706/photo_23vs24_2011070603184014.jpg $result = array(); $pic = $_REQUEST['http_url']; $o_img = copyImage($pic, md5(microtime(true)) . random('6') . ".jpg", array(), 'temp', false, 0); //$pic=GrabImage($pic, ""); //echo $pic;exit; ////URL是远程的完整图片地址,不能为空, $filename 是另存为的图片名字 ////默认把图片放在以此脚本相同的目录里 //function GrabImage($url, $filename=""){ ////$url 为空则返回 false; //if($url == ""){return false;} //$ext = strrchr($url, ".");//得到图片的扩展名 //if($ext != ".gif" && $ext != ".jpg" && $ext != ".bmp"){echo "格式不支持!";return false;} //if($filename == ""){$filename = time()."$ext";}//以时间戳另起名 ////开始捕捉 //ob_start(); //readfile($url); //$img = ob_get_contents(); //ob_end_clean(); //$size = strlen($img); //$fp2 = fopen($filename , "a"); //fwrite($fp2, $img); //fclose($fp2); //return $filename; //} if ($o_img) {
cancelImage($option); break; case 'orderup': orderImages(intval($cid[0]), -1, $option); break; case 'orderdown': orderImages(intval($cid[0]), 1, $option); break; case 'saveorder': saveOrder($cid); break; case 'reset_hits': resetHits($cid); break; case 'copy_images': copyImage($cid, $option); break; case 'move_images': moveImages($cid, $option); break; case 'showImages': showImages($option); break; default: showImages($option); } /** * Compiles a list of records * @param database A database connector object */ function showImages($option)
function createThumbnail($srcFile, $destFile, $width, $quality = 75) { $thumbnail = ''; if (file_exists($srcFile) && isset($destFile)) { $size = getimagesize($srcFile); $w = number_format($width, 0, ',', ''); $h = number_format($size[1] / $size[0] * $width, 0, ',', ''); $thumbnail = copyImage($srcFile, $destFile, $w, $h, $quality); } // return the thumbnail file name on success or blank on fail return basename($thumbnail); }
<?php $_FANWE['request']['uid'] = $_FANWE['uid']; $data = array(); $data['share_id'] = intval($_FANWE['request']['share_id']); $data['content'] = htmlspecialchars($_FANWE['request']['content']); $data['album_id'] = intval($_FANWE['request']['albumid']); $data['old_album_id'] = intval($_FANWE['request']['old_album_id']); $o_img = copyImage(FANWE_ROOT . $_FANWE['request']['img_url'], md5(microtime(true)) . random('6') . ".jpg", 'share', true, $_FANWE['request']['share_id']); $data['img'] = $o_img['url']; $data['photo_id'] = intval($_FANWE['request']['photo_id']); if (empty($data['content']) || empty($data['album_id']) || empty($data['photo_id'])) { $result['status'] = 0; outputJson($result); } $upImg = false; if (!empty($data['img'])) { $upImg = true; } $share_sql = "update " . FDB::table("share") . " set content = '" . $data['content'] . "',share_content_match = '" . segmentToUnicode(clearSymbol($data['content'])) . "' where share_id = " . $data['share_id']; $share_photo_sql = "update " . FDB::table("share_photo") . " set img = '" . $data['img'] . "',img_width = " . $o_img['width'] . ",img_height = " . $o_img['height'] . " where photo_id = " . $data['photo_id']; $album_share_sql = "select * from " . FDB::table("album_share") . " where album_id = " . $data['album_id'] . " and share_id = " . $data['share_id']; if (!FDB::fetchFirst($album_share_sql)) { FDB::query("delete from " . FDB::table("album_share") . " where share_id =" . $data['share_id']); FDB::query("update " . FDB::table("album") . " set share_count = share_count - 1 where id =" . $data['old_album_id']); FDB::query("update " . FDB::table("album") . " set share_count = share_count + 1 where id =" . $data['album_id']); $cid = FDB::resultFirst("select cid from " . FDB::table("album") . " where id = " . $data['album_id']); if ($cid) { $album_data = array(); $album_data['album_id'] = $data['album_id']; $album_data['share_id'] = $data['share_id'];
/** * Add or edit and entry. * * @param array $data * @param string $action * @return bool */ function processEntry($data, $action) { global $wpdb, $connections; $entry = new cnEntry(); //if ( isset($_GET['action']) ) $action = $_GET['action']; // The modification file date that image will be deleted. to maintain compatibility with 0.6.2.1 and older. $compatiblityDate = mktime(0, 0, 0, 6, 1, 2010); // If copying/editing an entry, the entry data is loaded into the class // properties and then properties are overwritten by the POST data as needed. if ( isset($_GET['id']) ) { $entry->set(esc_attr($_GET['id'])); } if ( isset($data['entry_type']) ) $entry->setEntryType($data['entry_type']); if ( isset($data['family_name']) ) $entry->setFamilyName($data['family_name']); if ( isset($data['family_member']) ) $entry->setFamilyMembers($data['family_member']); if ( isset($data['honorific_prefix']) ) $entry->setHonorificPrefix($data['honorific_prefix']); if ( isset($data['first_name']) ) $entry->setFirstName($data['first_name']); if ( isset($data['middle_name']) ) $entry->setMiddleName($data['middle_name']); if ( isset($data['last_name']) ) $entry->setLastName($data['last_name']); if ( isset($data['honorific_suffix']) ) $entry->setHonorificSuffix($data['honorific_suffix']); if ( isset($data['title']) ) $entry->setTitle($data['title']); if ( isset($data['organization']) ) $entry->setOrganization($data['organization']); if ( isset($data['department']) ) $entry->setDepartment($data['department']); if ( isset($data['contact_first_name']) ) $entry->setContactFirstName($data['contact_first_name']); if ( isset($data['contact_last_name']) ) $entry->setContactLastName($data['contact_last_name']); if ( isset($data['address']) ) $entry->setAddresses($data['address']); if ( isset($data['phone_numbers']) ) $entry->setPhoneNumbers($data['phone_numbers']); if ( isset($data['email']) ) $entry->setEmailAddresses($data['email']); if ( isset($data['im']) ) $entry->setIm($data['im']); if ( isset($data['social_media']) ) $entry->setSocialMedia($data['social_media']); if ( isset($data['website']) ) $entry->setWebsites($data['website']); if ( isset($data['birthday_day']) && isset($data['birthday_month']) ) $entry->setBirthday($data['birthday_day'], $data['birthday_month']); if ( isset($data['anniversary_day']) && isset($data['anniversary_month']) ) $entry->setAnniversary($data['anniversary_day'], $data['anniversary_month']); if ( isset($data['bio']) ) $entry->setBio($data['bio']); if ( isset($data['notes']) ) $entry->setNotes($data['notes']); if ( isset($data['visibility']) ) $entry->setVisibility($data['visibility']); /* * Process the logo upload --> START <-- */ if ($_FILES['original_logo']['error'] != 4) { // If an entry is being updated and a new logo is uploaded, the old logo needs to be deleted. if ($entry->getLogoName() != NULL) { unlink( CN_IMAGE_PATH . $entry->getLogoName() ); } // Process the newly uploaded logo. $logoProcessResults = processLogo(); // If there were no errors processing the logo, set the values. if ($logoProcessResults) { $entry->setLogoLinked(TRUE); $entry->setLogoDisplay(TRUE); $entry->setLogoName( $logoProcessResults['name'] ); } else { $entry->setLogoLinked(FALSE); $entry->setLogoDisplay(FALSE); } } else { // Don't do this if an entry is being updated. if ( $action !== 'update' ) { // If an entry is being copied and there is a logo, the logo will be duplicated for the new entry. // That way if an entry is deleted, only the entry specific logo will be deleted. if ($entry->getLogoName() != NULL) $entry->setLogoName( copyImage( $entry->getLogoName() ) ); } } /* * Process the logo upload --> END <-- */ /* * If copying an entry, the logo visibility property is set based on the user's choice. * NOTE: This must come after the logo processing. */ if (isset($data['logoOptions'])) { switch ($data['logoOptions']) { case 'remove': $entry->setLogoDisplay(FALSE); $entry->setLogoLinked(FALSE); /* * Delete logo assigned to the entry. */ if ( is_file( CN_IMAGE_PATH . $entry->getLogoName() ) ) { unlink( CN_IMAGE_PATH . $entry->getLogoName() ); } $entry->setLogoName(NULL); break; case 'hidden': $entry->setLogoDisplay(FALSE); break; case 'show': $entry->setLogoDisplay(TRUE); break; default: $entry->setLogoDisplay(FALSE); break; } } // Process the entry image upload. if ($_FILES['original_image']['error'] != 4) { // If an entry is being updated and a new image is uploaded, the old images need to be deleted. if ($entry->getImageNameOriginal() != NULL) { if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameOriginal() ) ) { unlink( CN_IMAGE_PATH . $entry->getImageNameOriginal() ); } } if ($entry->getImageNameThumbnail() != NULL) { if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameThumbnail() ) ) { unlink( CN_IMAGE_PATH . $entry->getImageNameThumbnail() ); } } if ($entry->getImageNameCard() != NULL) { if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameCard() ) ) { unlink( CN_IMAGE_PATH . $entry->getImageNameCard() ); } } if ($entry->getImageNameProfile() != NULL) { if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameProfile() ) ) { unlink( CN_IMAGE_PATH . $entry->getImageNameProfile() ); } } // Process the newly uploaded image. $image_proccess_results = processImages(); // If there were no errors processing the image, set the values. if ($image_proccess_results) { $entry->setImageLinked(true); $entry->setImageDisplay(true); $entry->setImageNameThumbnail($image_proccess_results['image_names']['thumbnail']); $entry->setImageNameCard($image_proccess_results['image_names']['entry']); $entry->setImageNameProfile($image_proccess_results['image_names']['profile']); $entry->setImageNameOriginal($image_proccess_results['image_names']['original']); } else { $entry->setImageLinked(false); $entry->setImageDisplay(false); } } else { // Don't do this if an entry is being updated. if ( $action !== 'update' ) { // If an entry is being copied and there is an image, the image will be duplicated for the new entry. // That way if an entry is deleted, only the entry specific images will be deleted. if ($entry->getImageNameOriginal() != NULL) $entry->setImageNameOriginal( copyImage( $entry->getImageNameOriginal() ) ); if ($entry->getImageNameThumbnail() != NULL) $entry->setImageNameThumbnail( copyImage( $entry->getImageNameThumbnail() ) ); if ($entry->getImageNameCard() != NULL) $entry->setImageNameCard( copyImage( $entry->getImageNameCard() ) ); if ($entry->getImageNameProfile() != NULL) $entry->setImageNameProfile( copyImage( $entry->getImageNameProfile() ) ); } } // If copying an entry, the image visibility property is set based on the user's choice. // NOTE: This must come after the image processing. if (isset($data['imgOptions'])) { switch ($data['imgOptions']) { case 'remove': $entry->setImageDisplay(false); $entry->setImageLinked(false); /* * Delete images assigned to the entry. * * Versions previous to 0.6.2.1 did not not make a duplicate copy of images when * copying an entry so it was possible multiple entries could share the same image. * Only images created after the date that version .0.7.0.0 was released will be deleted, * plus a couple weeks for good measure. */ if ( is_file( CN_IMAGE_PATH . $entry->getImageNameOriginal() ) ) { if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameOriginal() ) ) { unlink( CN_IMAGE_PATH . $entry->getImageNameOriginal() ); } } if ( is_file( CN_IMAGE_PATH . $entry->getImageNameThumbnail() ) ) { if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameThumbnail() ) ) { unlink( CN_IMAGE_PATH . $entry->getImageNameThumbnail() ); } } if ( is_file( CN_IMAGE_PATH . $entry->getImageNameCard() ) ) { if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameCard() ) ) { unlink( CN_IMAGE_PATH . $entry->getImageNameCard() ); } } if ( is_file( CN_IMAGE_PATH . $entry->getImageNameProfile() ) ) { if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameProfile() ) ) { unlink( CN_IMAGE_PATH . $entry->getImageNameProfile() ); } } $entry->setImageNameOriginal(NULL); $entry->setImageNameThumbnail(NULL); $entry->setImageNameCard(NULL); $entry->setImageNameProfile(NULL); break; case 'hidden': $entry->setImageDisplay(false); break; case 'show': $entry->setImageDisplay(true); break; default: $entry->setImageDisplay(false); break; } } switch ($action) { case 'add': if ($entry->save() == FALSE) { $connections->setErrorMessage('entry_added_failed'); return FALSE; } else { $connections->setSuccessMessage('entry_added'); $entryID = (int) $connections->lastInsertID; } break; case 'update': if ($entry->update() == FALSE) { $connections->setErrorMessage('entry_updated_failed'); return FALSE; } else { $connections->setSuccessMessage('entry_updated'); $entryID = (int) $entry->getId(); } break; } /* * Save the entry category(ies). If none were checked, send an empty array * which will add the entry to the default category. */ if ( isset($data['entry_category']) ) { $connections->term->setTermRelationships($entryID, $data['entry_category'], 'category'); } else { $connections->term->setTermRelationships($entryID, array(), 'category'); } unset($entry); return TRUE; }
/** * 保存分享数据 * 注:所有图片地址经处理过并转存过的临时图片或远程图片 * $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) { 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_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']; $share_server_code = array(); 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); //保存分享图片 $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 = FS("Image")->getImageUrl($share_photo_data['img'], 1); $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++; } } $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['url'] = ''; if (!empty($goods['shop_logo'])) { if (FS("Image")->getIsServer() && !empty($goods['shop_server_code'])) { $server = FS("Image")->getServer($goods['shop_server_code']); if (!empty($server)) { $args = array(); $args['pic_url'] = $goods['shop_logo']; $server = FS("Image")->getImageUrlToken($args, $server, 1); $body = FS("Image")->sendRequest($server, 'saveshop', true); if (!empty($body)) { $shop_logo = unserialize($body); FS("Image")->setServerUploadCount($shop_logo['server_code']); $shop_logo['url'] = str_replace('./', './' . $shop_logo['server_code'] . '/', $shop_logo['url']); } } } else { $shop_logo = copyFile($goods['shop_logo'], 'shop', true); } } $shop_data['shop_name'] = $goods['shop_name']; $shop_data['shop_logo'] = $shop_logo['url']; $shop_data['server_code'] = $goods['shop_server_code']; $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; } } if (FS("Image")->getIsServer() && !empty($goods['server_code'])) { $server = FS("Image")->getServer($goods['server_code']); if (!empty($server)) { $server_args['share_id'] = $share_id; $server_args['img_path'] = $goods['img']; $server = FS("Image")->getImageUrlToken($server_args, $server, 1); $body = FS("Image")->sendRequest($server, 'saveshare', true); if (!empty($body)) { $goods_img = unserialize($body); FS("Image")->setServerUploadCount($goods_img['server_code']); $share_server_code[] = $goods_img['server_code']; $goods_img['url'] = str_replace('./', './' . $goods_img['server_code'] . '/', $goods_img['url']); $weibo_img_url = FS("Image")->getImageUrl($goods_img['url'], 1); } } } else { $goods_img = copyImage($goods['img'], array(), 'share', true, $share_id); $weibo_img_url = FS("Image")->getImageUrl($goods_img['url'], 1); } if (!empty($goods_img)) { if ($goods['sort'] < $weibo_img_sort) { $weibo_img = $weibo_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']; $share_goods_data['img_width'] = $goods_img['width']; $share_goods_data['img_height'] = $goods_img['height']; $share_goods_data['server_code'] = $goods['server_code']; 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 = $weibo_img = FS("Image")->getImageUrl($share_goods_data['img'], 1); $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'; } else { $share_data_type = 'default'; } $update_share = array(); $update_share['share_data'] = $share_data_type; if (count($share_server_code) > 0) { $share_server_code = array_unique($share_server_code); $update_share['server_code'] = implode(',', $share_server_code); } if ($share_album_id > 0 && in_array($share_data_type, array('goods', 'photo', 'goods_photo'))) { $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); //更新会员统计 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'))) { //更新会员发布的有图分享编号 //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'))) { 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; }