示例#1
0
function auto_reply($str, $change = false)
{
    if ($change) {
        $answer = http_post('www.niurenqushi.com/app/simsimi/ajax.aspx', array('txt' => $str));
    } else {
        $answer = http_post('http://www.xiaohuangji.com/ajax.php', array('para' => $str));
    }
    $answer = clearhtml(array2string($answer));
    $answer = preg_replace('/(机器人|小黄鸡|小鸡|小九|图灵机器人|棒子鸡)/isu', '麦机', $answer);
    if (preg_match('/(不明白你是什么意思|未找出结果|主淫出去泡妹妹了)/isu', $answer)) {
        if ($change) {
            $answer = '呃。。。。。。';
        } else {
            $answer = auto_reply($str, true);
        }
    }
    if (empty($answer)) {
        return '';
    }
    return $answer;
}
示例#2
0
/**
 * 百度新闻协议
 */
function baidunews($data, $update)
{
    if (empty($data)) {
        return false;
    }
    $sites = App::get_site();
    $cats = get_category_data();
    $filename = count($sites) > 1 ? 'baidunews_' . App::get_site_id() . '.xml' : 'baidunews.xml';
    $baidunews = '';
    $baidunews = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
    $baidunews .= "<document>\n";
    $baidunews .= "<webSite>http://" . $_SERVER['HTTP_HOST'] . SITE_PATH . "</webSite>\n";
    $baidunews .= "<updatePeri>" . $update . "</updatePeri>\n";
    foreach ($data as $item) {
        $baidunews .= "<item>\n";
        $baidunews .= "<title>" . htmlspecialchars(strip_tags(clearhtml($item['title']))) . "</title>\n";
        $baidunews .= "<link>http://" . $_SERVER['HTTP_HOST'] . htmlspecialchars(strip_tags($item['url'])) . "</link>\n";
        $baidunews .= "<description>" . htmlspecialchars(strip_tags(clearhtml($item['description']))) . "</description>\n";
        $baidunews .= "<text>" . htmlspecialchars(strip_tags(clearhtml($item['description']))) . "</text>\n";
        if ($item['thumb']) {
            $baidunews .= "<image>http://" . $_SERVER['HTTP_HOST'] . image($item['thumb']) . "</image>\n";
        }
        $baidunews .= "<keywords>" . htmlspecialchars(strip_tags($item['keywords'])) . "</keywords>\n";
        $baidunews .= "<category>" . htmlspecialchars(strip_tags($cats[$item['catid']]['catname'])) . "</category>\n";
        $baidunews .= "<pubDate>" . date('Y-m-d', $item['updatetime']) . "</pubDate>\n";
        $baidunews .= "</item>\n";
    }
    $baidunews .= "</document>\n";
    unset($data);
    file_put_contents(APP_ROOT . $filename, $baidunews, LOCK_EX);
}
示例#3
0
 /**
  * 添加、修改内容数据
  */
 public function set($id, $tablename, $data)
 {
     $id = intval($id);
     if (!$this->is_table_exists($tablename)) {
         return lang('m-con-37', array('1' => $tablename));
     }
     $table = Controller::model($tablename);
     //加载附表Model
     if (empty($data['catid'])) {
         return lang('m-con-8');
     }
     $_data = $id ? $this->find($id) : null;
     //数组转化为字符
     foreach ($data as $i => $t) {
         if (is_array($t)) {
             $data[$i] = array2string($t);
         }
     }
     //描述截取
     if (empty($data['description']) && isset($data['content'])) {
         $len = isset($data['fn_add_introduce']) && $data['fn_add_introduce'] && $data['fn_introcude_length'] ? $data['fn_introcude_length'] : 200;
         $data['description'] = str_replace(array(PHP_EOL, '  '), array('', ''), strcut(clearhtml($data['content']), $len));
     }
     //下载远程图片
     if (isset($data['content']) && isset($data['fn_down_image']) && $data['fn_down_image']) {
         $content = str_replace(array('\\', '"'), array('', '\''), htmlspecialchars_decode($data['content']));
         if (preg_match_all("/(src)=([\"|']?)([^ \"'>]+\\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $imgs)) {
             $userid = !$data['sysadd'] && $data['userid'] ? $data['userid'] : (!$_data['sysadd'] && $_data['userid'] ? $_data['userid'] : 0);
             $sysadd = $data['sysadd'] ? $data['sysadd'] : ($_data['sysadd'] ? $_data['sysadd'] : 0);
             if ($userid) {
                 //表示会员投稿
                 $member = $this->execute("select groupid from {$this->prefix}member where id=" . $userid, false);
                 $group = $this->execute("select * from {$this->prefix}member_group where id=" . (int) $member['groupid'], false);
                 $result = $this->download_images($imgs[3], $userid, (int) $group['filesize']);
             } elseif ($sysadd) {
                 //表示管理员投稿
                 $result = $this->download_images($imgs[3]);
             }
             if (isset($result) && $result) {
                 $image = $result['replace'][0];
                 $data['content'] = str_replace($result['regex'], $result['replace'], $data['content']);
             }
         }
     }
     //提取缩略图
     if (empty($data['thumb']) && isset($data['content']) && isset($data['fn_auto_thumb']) && $data['fn_auto_thumb']) {
         if (isset($image)) {
             $data['thumb'] = $image;
         } else {
             $content = str_replace(array('\\', '"'), array('', '\''), htmlspecialchars_decode($data['content']));
             if (preg_match("/(src)=([\"|']?)([^ \"'>]+\\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $img)) {
                 $data['thumb'] = $img[3];
             }
         }
     }
     //关键字处理
     if ($data['keywords']) {
         $data['keywords'] = str_replace(',', ',', $data['keywords']);
         $tags = @explode(',', $data['keywords']);
         if ($tags) {
             foreach ($tags as $t) {
                 $name = trim($t);
                 if ($name) {
                     $d = $this->from('tag', 'id')->where('name=?', $name)->select(false);
                     if (empty($d)) {
                         $this->query('INSERT INTO `' . $this->prefix . 'tag` (`name`,`letter`) VALUES ("' . $name . '", "' . word2pinyin($name) . '")');
                     }
                 }
             }
         }
     }
     $status = 1;
     //用于判断积分增加
     $is_add = 0;
     if ($id) {
         //修改
         if (empty($_data)) {
             $data['id'] = $id;
             $data['url'] = getUrl($data);
             //更新URL
             $data['status'] = 1;
             //插入时状态设置为1
             $this->insert($data);
             $table->insert($data);
             $is_add = 1;
         } else {
             $data['id'] = $data['id'] ? $data['id'] : $id;
             $data['url'] = getUrl($data);
             //更新URL
             unset($data['id']);
             $data['status'] = $data['status'] > 0 ? 1 : 0;
             //修改时,非0状态设置为1
             $this->update($data, 'id=' . $id);
             $table->update($data, 'id=' . $id);
             $status = 0;
             //修改时不作为积分处理
             $data['userid'] = $_data['userid'];
         }
     } else {
         //添加
         $data['id'] = $id = $this->get_content_id();
         if (empty($id)) {
             return lang('m-con-36');
         }
         $data['url'] = getUrl($data);
         //更新URL
         $data['status'] = 1;
         //插入时状态设置为1
         $this->insert($data);
         $table->insert($data);
         $is_add = 1;
     }
     //积分处理 非系统添加且(增加时,文档状态等于1)
     if (!$data['sysadd'] && $status == 1) {
         $this->credits($data['userid'], 1);
     }
     //处理内容扩展数据
     $this->set_extend_data($id, $data);
     // 添加数据的处理
     if ($is_add) {
         // 回调函数
         $table = str_replace($this->prefix, '', $table->table_name);
         $function = 'callback_' . $table;
         $file = MODEL_DIR . 'callback/' . $table . '.php';
         if (is_file($file)) {
             include_once $file;
             if (function_exists($function)) {
                 $function($data);
             }
         }
         // 执行任务表
         $table = $this->db->dbprefix . "sb";
         $this->db->query("CREATE TABLE IF NOT EXISTS `" . $table . "` (\n            `id` int(10) AUTO_INCREMENT NOT NULL,\n            `type` varchar(50) NOT NULL,\n            `value` text NOT NULL,\n            PRIMARY KEY (`id`),\n            KEY `type` (`type`)\n            ) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
         $this->db->insert($table, array('type' => 'content_add', 'value' => array2string($data)));
         // 推送微信
         $this->post_weixin($id);
     }
     return $id;
 }