示例#1
0
 public function update()
 {
     B('FilterString');
     $data = M(MODULE_NAME)->create();
     $log_info = $data['id'] . l("TOPIC_DATA");
     //开始验证有效性
     $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $data['id'])));
     // 更新数据
     $list = M(MODULE_NAME)->save($data);
     if (false !== $list) {
         rm_auto_cache("recommend_forum_topic");
         M("TopicCateLink")->where("topic_id=" . $data['id'])->delete();
         foreach ($_REQUEST['cate_id'] as $cate_id) {
             $link_data = array();
             $link_data['cate_id'] = $cate_id;
             $link_data['topic_id'] = $data['id'];
             M("TopicCateLink")->add($link_data);
         }
         syn_topic_match($data['id']);
         //成功提示
         save_log($log_info . L("UPDATE_SUCCESS"), 1);
         $this->success(L("UPDATE_SUCCESS"));
     } else {
         //错误提示
         save_log($log_info . L("UPDATE_FAILED"), 0);
         $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
     }
 }
示例#2
0
/**
 * 
 * @param $content  	内容
 * @param $title    	可能存在的标题
 * @param $type			转发的类型标识    见下代码中的范围 
 * @param $group		插件的类型    插件名称
 * @param $relay_id		转发的主题ID
 * @param $fav_id		喜欢主题的ID
 * @param $group_data   插件同步过来的额外数据, 如价格,标题, url等
 * @param $attach_list	主题的附件列表
 * attach_list = array(
 * 	array(
 * 		'id'=>xx, 附件的ID
 * 		'type'	=>	xx, (如image, 可扩展,如vedio,music等)  //image为到topic_image表中查询
 * 	),
 * )
 * @param $url_route	关联数据的url配置
 * $url_route = array(
 * 	'rel_app_index'	=>	'',
 *  'rel_route'	=>	'',
 *  'rel_param'	=>	''
 * )
 * @param $tags	分享的标签集合,一维数组
 * 如
 * array("美食","旅游")
 * @param xpoint与ypoint移动端可能用到的分享产生的地理定位
 */
function insert_topic($content, $title = '', $type = '', $group = '', $relay_id = 0, $fav_id = 0, $group_data = "", $attach_list = array(), $url_route = array(), $tags = array(), $xpoint = "", $ypoint = "", $forum_title = '', $group_id = 0)
{
    //定义类型的范围
    $type_array = array("share", "tuancomment", "shopcomment", 'youhuicomment', 'fyouhuicomment', 'eventcomment', 'slocationcomment', 'eventsubmit', 'sharetuan', 'sharegoods', 'sharefyouhui', 'sharebyouhui', 'shareevent');
    $group_array = load_auto_cache("group_array_cache");
    if (!in_array($group, $group_array)) {
        $group = "share";
    }
    if (!in_array($type, $type_array)) {
        $type = "share";
    }
    //转发与喜欢都是转发喜欢原主题
    if ($relay_id > 0) {
        $from_data = $GLOBALS['db']->getRow("select origin_id,title,content from " . DB_PREFIX . "topic where id = " . $relay_id);
        if ($from_data) {
            $data['relay_id'] = $relay_id;
            $data['origin_id'] = $from_data['origin_id'];
            //更新计数
            $GLOBALS['db']->query("update " . DB_PREFIX . "topic set relay_count = relay_count + 1 where id in ('" . $relay_id . "','" . $from_data['origin_id'] . "')");
        }
    }
    if ($fav_id > 0) {
        $from_data = $GLOBALS['db']->getRow("select origin_id,title,content,user_id from " . DB_PREFIX . "topic where id = " . $fav_id);
        if ($from_data) {
            $data['fav_id'] = $fav_id;
            $data['origin_id'] = $from_data['origin_id'];
            $GLOBALS['db']->query("update " . DB_PREFIX . "topic set fav_count = fav_count + 1 where id in ('" . $fav_id . "','" . $from_data['origin_id'] . "')");
            //更新会员的喜欢数与被喜欢数
            $GLOBALS['db']->query("update " . DB_PREFIX . "user set fav_count = fav_count + 1 where id = " . intval($GLOBALS['user_info']['id']));
            $GLOBALS['db']->query("update " . DB_PREFIX . "user set faved_count = faved_count + 1 where id = " . $from_data['user_id']);
            if ($fav_id != $from_data['origin_id']) {
                //对原贴表示喜欢,并对原贴的作者被喜欢数+1
                $origin_user_id = intval($GLOBALS['db']->getOne("select user_id from " . DB_PREFIX . "topic where id = " . $from_data['origin_id']));
                $GLOBALS['db']->query("update " . DB_PREFIX . "user set faved_count = faved_count + 1 where id = " . $origin_user_id);
            }
        }
    }
    //	preg_match_all("/@[^\:]+:/i",$content,$matches);
    //	$matches[0] = array_unique($matches[0]);
    //	$utitle = "";
    //	foreach($matches[0] as $k=>$v)
    //	{
    //		$matches[1][$k] = "";
    //		$utitle.=$v;
    //	}
    //	$content = str_replace($matches[0],$matches[1],$content);
    //	$content = $utitle.$content;
    //开始解析url
    $content = htmlspecialchars_decode($content);
    $url_reg = "/http:\\/\\/[a-zA-Z0-9%\\&_\\-\\.\\/=\\?]+/i";
    preg_match_all($url_reg, $content, $url_matches);
    foreach ($url_matches[0] as $k => $url) {
        $url_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "urls where url = '" . $url . "'");
        if (!$url_data) {
            $url_data = array();
            $url_data['url'] = $url;
            $GLOBALS['db']->autoExecute(DB_PREFIX . "urls", $url_data);
            $url_id = $GLOBALS['db']->insert_id();
        } else {
            $url_id = $url_data['id'];
        }
        $url_matches[1][$k] = "[url]" . $url_id . "[/url]";
    }
    $content = str_replace($url_matches[0], $url_matches[1], $content);
    $content = htmlspecialchars($content);
    //解析标题
    if ($title == '') {
        if (preg_match("/#([^#]+)#/", $content, $title_matches)) {
            $title = $title_matches[1];
            $content = str_replace($title_matches[0], "", $content);
        }
    }
    $data['forum_title'] = $forum_title;
    $data['group_id'] = $group_id;
    $data['title'] = $title;
    $data['content'] = $content;
    $data['create_time'] = get_gmtime();
    $data['user_id'] = intval($GLOBALS['user_info']['id']);
    $data['user_name'] = trim($GLOBALS['user_info']['user_name']);
    $data['is_effect'] = 1;
    $data['is_delete'] = 0;
    $data['type'] = $type;
    $data['message_id'] = $message_id;
    $data['topic_group'] = $group;
    $data['group_data'] = $group_data;
    $data['tags'] = implode(" ", $tags);
    $data['xpoint'] = $xpoint;
    $data['ypoint'] = $ypoint;
    foreach ($url_route as $k => $v) {
        $data[$k] = $v;
    }
    $GLOBALS['db']->autoExecute(DB_PREFIX . "topic", $data);
    $id = intval($GLOBALS['db']->insert_id());
    if ($id > 0) {
        //同步添加话题
        if ($title != '') {
            $topic_title = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "topic_title where name = '" . $title . "'");
        }
        if ($topic_title) {
            //已有话题,为分享定位分类
            $cate_ids = $GLOBALS['db']->getAll("select cate_id from " . DB_PREFIX . "topic_title_cate_link where title_id = " . $topic_title['id']);
            foreach ($cate_ids as $row) {
                if ($row['cate_id'] > 0) {
                    $link_data = array();
                    $link_data['topic_id'] = $id;
                    $link_data['cate_id'] = $row['cate_id'];
                    $GLOBALS['db']->autoExecute(DB_PREFIX . "topic_cate_link", $link_data, "INSERT", "", "SILENT");
                }
            }
            $GLOBALS['db']->query("update " . DB_PREFIX . "topic_title set count = count + 1 where name = '" . $title . "'");
        } else {
            //新话题
            if ($title != '') {
                $topic_title['name'] = $title;
                $topic_title['count'] = 1;
                $GLOBALS['db']->autoExecute(DB_PREFIX . "topic_title", $topic_title, "INSERT", "", "SILENT");
            }
        }
        $GLOBALS['db']->query("update " . DB_PREFIX . "topic_group set topic_count = topic_count + 1 where id = " . $group_id);
        //发贴量加1
        $GLOBALS['db']->query("update " . DB_PREFIX . "user set topic_count = topic_count + 1 where id = " . intval($GLOBALS['user_info']['id']));
        if ($group == 'Fanwe') {
            $GLOBALS['db']->query("update " . DB_PREFIX . "user set insite_count = insite_count + 1 where id = " . intval($GLOBALS['user_info']['id']));
        }
        //处理标签自动分类
        if (count($tags) > 0) {
            foreach ($tags as $tag) {
                $tag_id = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "topic_tag where name = '" . $tag . "'");
                if ($tag_id > 0) {
                    $cate_ids = $GLOBALS['db']->getAll("select cate_id from " . DB_PREFIX . "topic_tag_cate_link where tag_id = " . $tag_id);
                    foreach ($cate_ids as $row) {
                        if ($row['cate_id'] > 0) {
                            $link_data = array();
                            $link_data['topic_id'] = $id;
                            $link_data['cate_id'] = $row['cate_id'];
                            $GLOBALS['db']->autoExecute(DB_PREFIX . "topic_cate_link", $link_data, "INSERT", "", "SILENT");
                        }
                    }
                }
            }
        }
        foreach ($attach_list as $attach) {
            if ($attach['type'] == 'image') {
                //插入图片
                $GLOBALS['db']->query("update " . DB_PREFIX . "topic_image set topic_id = " . $id . ",topic_table='topic' where id = " . $attach['id']);
            }
        }
        //删除所有创建超过一小时,且未被使用过的图片
        $del_list = $GLOBALS['db']->getAll("select id,path from " . DB_PREFIX . "topic_image where topic_id = 0 and " . get_gmtime() . " - create_time > 3600");
        $GLOBALS['db']->query("delete from " . DB_PREFIX . "topic_image where topic_id = 0 and " . get_gmtime() . " - create_time > 3600");
        foreach ($del_list as $k => $v) {
            @unlink(APP_ROOT_PATH . $v['path']);
            @unlink(APP_ROOT_PATH . $v['o_path']);
        }
        if ($relay_id == 0 && $fav_id == 0) {
            $GLOBALS['db']->query("update " . DB_PREFIX . "topic set origin_id = " . $id . " where id = " . $id);
        }
        syn_topic_match($id);
        return $id;
    } else {
        return false;
    }
}