Beispiel #1
0
function cloud_match_rules($get_type, $url, $content)
{
    global $_G;
    pload('F:fastpick');
    $setting = get_pick_set();
    $pick_config = $_G['cache']['evn_milu_pick']['pick_config'];
    $server_cache_time = $pick_config['index_server_cache_time'];
    if ($get_type == '3') {
        //智能学习规则索引过期时间比较短
        $server_cache_time = $pick_config['evo_index_server_cache_time'];
    }
    $milu_set = pick_common_get();
    if ($setting['open_cloud_pick'] != 1) {
        return FALSE;
    }
    pload('F:copyright');
    $host_info = GetHostInfo($url);
    $domain = $host_info['host'];
    $domain_hash = md5($domain);
    $url_temp = preg_replace('/\\d+/', '', $url);
    $arr_temp = parse_url($url_temp);
    $path_hash = md5($arr_temp['path']);
    $over_dateline = $_G['timestamp'] - $server_cache_time;
    $count = DB::result(DB::query("SELECT COUNT(*) FROM " . DB::table('strayer_searchindex') . " WHERE  domain_hash='" . $domain_hash . "' AND path_hash='" . $path_hash . "' AND type='" . $get_type . "3' AND dateline > {$over_dateline}"), 0);
    //3是服务端 4是本地的缓存
    if ($count) {
        return FALSE;
    }
    $args = array('get_type' => $get_type, 'url' => $url);
    $rpcClient = rpcClient();
    $client_info = get_client_info();
    $re = $rpcClient->cloud_match_rules($args, $client_info);
    if (is_object($re) || $re->Number == 0) {
        if ($re->Message) {
            return milu_lang('phprpc_error', array('msg' => $re->Message));
        }
        $re = (array) $re;
    }
    $data = array();
    if ($re['data_type'] == 1) {
        //返回规则
        $rules_info = $re['data'];
        if ($get_type == 3) {
            $data = evo_rules_get_article($content, $rules_info);
        } else {
            $data = rules_get_article($content, $rules_info);
        }
        if ($data || $data['content'] && $get_type == 3) {
            //规则验证有效,下载到本地
            if ($get_type == 3) {
                $data_id = import_evo_data($rules_info);
            } else {
                $data_id = import_fastpick_data($rules_info);
            }
            if ($data_id) {
                //先清除之前的索引
                DB::query('DELETE FROM ' . DB::table('strayer_searchindex') . " WHERE domain_hash='" . $domain_hash . "' AND path_hash='" . $path_hash . "'");
                add_search_index($domain_hash, $path_hash, $get_type . '4', $data_id);
                //添加索引
            }
        }
    } else {
        if ($re['data_type'] == 2) {
            //返回内容
            $data = $re['data'];
        } else {
            //一无所获,那也要告诉客户端,别再骚扰服务端了
            add_search_index($domain_hash, $path_hash, $get_type . '3', 0);
        }
    }
    return $data;
}
Beispiel #2
0
function forum_downremotefile($arr, $old_arr)
{
    global $_G;
    $evo_img_no = $_G['cache']['evn_milu_pick']['evo_img_no'];
    $config = get_pick_set();
    $get_file_ext_arr = $config['get_file_ext'] ? explode('|', $config['get_file_ext']) : array();
    $arr['is_download_file'] = $arr['is_download_file'] ? $arr['is_download_file'] : $arr['p_arr']['is_download_file'];
    $arr['message'] = dstripslashes($arr['content']);
    //print_r($arr);
    //$arr['message'] = str_replace(array("\r", "\n"), array($_GET['wysiwyg'] ? '<br />' : '', "\\n"), $arr['message']);
    preg_match_all("/\\[img\\]\\s*([^\\[\\<\r\n]+?)\\s*\\[\\/img\\]|\\[img=\\d{1,4}[x|\\,]\\d{1,4}\\]\\s*([^\\[\\<\r\n]+?)\\s*\\[\\/img\\]/is", $arr['message'], $image1, PREG_SET_ORDER);
    //preg_match_all("/\<img.+src=('|\"|)?(.*)(\\1)([\s].*)?\>/ismUe", $arr['message'], $image2, PREG_SET_ORDER);
    preg_match_all("/\\<img.+src=('|\"|)?(.*)(\\1)(.*)?\\>/isU", $arr['message'], $image2, PREG_SET_ORDER);
    $temp = $aids = $existentimg = $attach_arr = array();
    if (is_array($image1) && !empty($image1)) {
        foreach ($image1 as $value) {
            $v = trim(!empty($value[1]) ? $value[1] : $value[2]);
            $no_remote = 0;
            if (!filter_something($v, $evo_img_no)) {
                //存在
                $no_remote = 1;
            }
            if ($no_remote == 0) {
                $temp[] = array('0' => $value[0], '1' => $v);
            }
        }
    }
    if (is_array($image2) && !empty($image2)) {
        foreach ($image2 as $v) {
            $no_remote = 0;
            $v[2] = trim(strip_tags($v[2]));
            if (!filter_something($v[2], $evo_img_no)) {
                //存在
                $no_remote = 1;
            }
            if ($no_remote == 0) {
                $temp[] = array('0' => $v[0], '1' => $v[2]);
            }
        }
    }
    if ($arr['is_download_file'] == 1) {
        $attach_arr = get_attach_data($arr['page_url'], $arr['message']);
    }
    $attach_arr = $attach_arr ? $attach_arr : array();
    $temp = $temp ? $temp : array();
    $temp = array_merge($temp, $attach_arr);
    //if(VIP) $arr['message'] = post($arr['message'], array('cookie' => $arr['cookie'], 'page_url' => $arr['page_url'], 'cid' => $arr['cid']));
    $del_a = 0;
    if ($arr['content_filter_html'][0] == 0 && $arr['content_filter_html']) {
        $del_a = 1;
    }
    //print_r($arr['message']);exit();
    require_once libfile('class/image');
    if (is_array($temp) && !empty($temp)) {
        if (file_exists(libfile('class/upload'))) {
            require_once libfile('class/upload');
        } else {
            require_once libfile('discuz/upload', 'class');
        }
        $upload = new discuz_upload();
        $attachaids = array();
        $threadimage_flag = 0;
        $content_md5_arr = array();
        foreach ($temp as $key => $value) {
            $snoopy_args['cookie'] = $arr['cookie'];
            $snoop_obj = get_snoopy_obj($snoopy_args);
            $imageurl = $value[1];
            $hash = md5($imageurl);
            if (strlen($imageurl)) {
                $imagereplace['oldimageurl'][] = $value[0];
                if (!isset($existentimg[$hash])) {
                    $existentimg[$hash] = $imageurl;
                    $attach['ext'] = $upload->fileext($imageurl);
                    if ($upload->is_image_ext($attach['ext']) == 1 && $arr['is_download_img'] != 1) {
                        $imagereplace['newimageurl'][] = $value[0];
                        continue;
                    }
                    if (!$upload->is_image_ext($attach['ext'])) {
                        $ext = 'no_get';
                    }
                    if (preg_match('/^(http:\\/\\/|\\.)/i', $imageurl)) {
                        if ($imageurl && snoop_obj) {
                            $content_re = get_img_content($imageurl, $snoop_obj, $ext);
                        }
                        if (is_array($content_re)) {
                            $content = $content_re['content'];
                            $file_name = $attach['name'] = $content_re['file_name'] ? $content_re['file_name'] : ($value[2] ? _striptext($value[2]) : time() . '.' . $content_re['file_ext']);
                            $attach['ext'] = $content_re['file_ext'] ? $content_re['file_ext'] : trim($upload->fileext($file_name));
                            $file_name = $attach['name'] = $file_name;
                        } else {
                            $content = $content_re;
                        }
                        if (in_array(md5($content), $content_md5_arr)) {
                            $imagereplace['newimageurl'][] = '';
                            continue;
                        }
                        $content_md5_arr[] = md5($content);
                    } elseif (preg_match('/^(' . preg_quote(getglobal('setting/attachurl'), '/') . ')/i', $imageurl)) {
                        $imagereplace['newimageurl'][] = $value[0];
                    }
                    if (empty($content)) {
                        if ($value[4] == 1) {
                            if ($del_a == 1) {
                                $imagereplace['newimageurl'][] = $value[2];
                            } else {
                                unset($imagereplace['oldimageurl'][$key]);
                            }
                        } else {
                            $imagereplace['newimageurl'][] = '';
                        }
                        continue;
                    }
                    if (!$attach['name']) {
                        $patharr = explode('/', $imageurl);
                        $attach['name'] = trim($patharr[count($patharr) - 1]);
                    }
                    $patharr = explode('/', $imageurl);
                    if (!$attach['name']) {
                        $attach['name'] = trim($patharr[count($patharr) - 1]);
                    }
                    $attach['thumb'] = '';
                    $attach['ext'] = trim($attach['ext']);
                    //不加这个有些还真不行
                    $attach['isimage'] = $upload->is_image_ext($attach['ext']);
                    if ($attach['isimage'] == 1 && $arr['is_download_img'] != 1) {
                        $imagereplace['newimageurl'][] = $value[0];
                        continue;
                    }
                    $attach['extension'] = $upload->get_target_extension($attach['ext']);
                    $attach['attachdir'] = $upload->get_target_dir('forum');
                    $attach['attachment'] = $attach['attachdir'] . $upload->get_target_filename('forum') . '.' . $attach['extension'];
                    $attach['target'] = getglobal('setting/attachdir') . './forum/' . $attach['attachment'];
                    if (!in_array($attach['ext'], $get_file_ext_arr) && $get_file_ext_arr && $attach['isimage'] == 0) {
                        if ($value[4] == 1) {
                            if ($del_a == 1) {
                                $imagereplace['newimageurl'][] = $value[2];
                            } else {
                                unset($imagereplace['oldimageurl'][$key]);
                            }
                        } else {
                            $imagereplace['newimageurl'][] = '';
                        }
                        continue;
                    }
                    if (!@($fp = fopen($attach['target'], 'wb'))) {
                        continue;
                    } else {
                        flock($fp, 2);
                        fwrite($fp, $content);
                        fclose($fp);
                    }
                    if (!$upload->get_image_info($attach['target']) && $attach['isimage'] == 1) {
                        @unlink($attach['target']);
                        continue;
                    }
                    $attach['size'] = filesize($attach['target']);
                    $upload->attach = $attach;
                    $thumb = $width = 0;
                    if ($upload->attach['isimage']) {
                        if ($_G['setting']['thumbstatus']) {
                            $image = new image();
                            $thumb = $image->Thumb($upload->attach['target'], '', $_G['setting']['thumbwidth'], $_G['setting']['thumbheight'], $_G['setting']['thumbstatus'], $_G['setting']['thumbsource']) ? 1 : 0;
                            $width = $image->imginfo['width'];
                        }
                        if ($_G['setting']['thumbsource'] || !$_G['setting']['thumbstatus']) {
                            list($width) = @getimagesize($upload->attach['target']);
                        }
                        if ($_G['setting']['watermarkstatus'] && empty($_G['forum']['disablewatermark']) && $arr['is_water_img'] == 1) {
                            $image = new image();
                            $image->Watermark($attach['target'], '', 'forum');
                        }
                    }
                    $desc = $value[3];
                    $arr['public_time'] = $arr['public_time'] ? $arr['public_time'] : $arr['dateline'];
                    $arr['public_time'] = $arr['public_time'] ? $arr['public_time'] : $_G['timestamp'];
                    $remote = 0;
                    $setarr = array('uid' => $arr['uid'], 'tid' => $arr['tid'], 'pid' => $arr['pid'], 'filename' => daddslashes($upload->attach['name']), 'attachment' => $upload->attach['attachment'], 'filesize' => $upload->attach['size'], 'thumb' => $thumb, 'remote' => $remote, 'picid' => $picid, 'isimage' => $attach['isimage'], 'description' => $desc, 'readperm' => 0, 'price' => 0, 'width' => $width, 'dateline' => $arr['public_time']);
                    $setimg_arr = array('tid' => $arr['tid'], 'attachment' => $upload->attach['attachment'], 'remote' => $remote);
                    $set_att = array('downloads' => rand(1, 15), 'tableid' => getattachtableid($arr['tid']), 'uid' => $arr['uid'], 'pid' => $arr['pid'], 'tid' => $arr['tid']);
                    if ($threadimage_flag == 0 && !$arr['is_post'] && $attach['isimage'] == 1) {
                        DB::insert('forum_threadimage', $setimg_arr, true);
                        $threadimage_flag = 1;
                    }
                    $setarr['aid'] = $newaids[] = DB::insert('forum_attachment', $set_att, true);
                    $at[] = $setarr['aid'];
                    $attachnew_arr[$setarr['aid']] = array('description' => $setarr['description']);
                    DB::insert(getattachtablebytid($arr['tid']), $setarr, true);
                    $attachaids[$hash] = $imagereplace['newimageurl'][] = '[attach]' . $setarr['aid'] . '[/attach]';
                } else {
                    $imagereplace['newimageurl'][] = $attachaids[$hash];
                }
            }
        }
        if ($_G['setting']['ftp']['on'] == 1) {
            require_once libfile('function/post');
            ftpupload($newaids, $arr['uid']);
        }
        if (count($at) > 0) {
            $arr['attachment'] = 2;
        }
        $arr['message'] = str_replace($imagereplace['oldimageurl'], $imagereplace['newimageurl'], $arr['message']);
        if ($del_a == 1) {
            $arr['message'] = clear_html_script($arr['message'], array(0));
        }
        forum_article_content($arr);
    }
}
 function evo_set($info)
 {
     global $_G;
     if (!$info) {
         return;
     }
     if (strlen($info['text']['html']) < 200 || strlen($info['title']['html']) < 10) {
         return;
     }
     //标题和内容太短都不行
     $link_count = own_link_count($info['text']['html'], $this->url);
     if ($link_count > 10) {
         return FALSE;
     }
     //有10个指向自己的链接,就不行
     $milu_set = pick_common_get();
     if ($milu_set['fp_open_evo'] != 1) {
         return FALSE;
     }
     $text_info = $this->dom_info_arr[$info['text']['key']];
     $title_info = $this->dom_info_arr[$info['title']['key']];
     $text_info['html'] = $info['text']['html'];
     $title_info['html'] = $info['title']['html'];
     $info['title_split_arr'] = $this->get_split_arr($title_info);
     $info['text_split_arr'] = $split_arr = $this->get_split_arr($text_info);
     unset($text_info['outertext'], $text_info['parent']['outertext'], $title_info['outertext'], $title_info['parent']['outertext'], $text_info['html'], $title_info['html']);
     if (strlen($split_arr[0]) < 14) {
         return FALSE;
     }
     pload('F:copyright');
     $host_info = GetHostInfo($this->url);
     $domain = $host_info['host'];
     $domain_hash = md5($domain);
     if (preg_match('/\\d+/', $split_arr[0])) {
         $s_arr = preg_split("/[\\d]+/", $split_arr[0]);
         $split_arr[0] = $s_arr[0];
         foreach ((array) $s_arr as $k => $v) {
             if (strlen($v) > strlen($split_arr[0])) {
                 $split_arr[0] = $v;
             }
         }
     }
     if (!$title_info) {
         return FALSE;
     }
     $result_info['evo_title_info'] = $title_info;
     $setarr = array('content_get_type' => 0, 'detail_ID' => $split_arr[0], 'detail_ID_hash' => md5($split_arr[0]), 'detail_ID_test' => $this->url, 'content_rules' => '', 'evo_text_info' => serialize($text_info), 'evo_title_info' => serialize($title_info), 'domain_hash' => $domain_hash, 'domain' => $domain, 'status' => 0, 'dateline' => $_G['timestamp']);
     $setarr = paddslashes($setarr);
     $base_sql = "SELECT * FROM " . DB::table('strayer_evo') . " WHERE domain_hash='{$domain_hash}' AND detail_ID_hash='" . $setarr['detail_ID_hash'] . "' AND status=0";
     $data_info = DB::fetch_first($base_sql . " AND detail_ID_test!='{$this->url}'");
     $data_info = pstripslashes($data_info);
     if (!$data_info) {
         //还没有资料
         if (!($check = DB::result(DB::query("SELECT COUNT(*) FROM " . DB::table('strayer_evo') . " WHERE domain_hash='{$domain_hash}' AND detail_ID_hash='" . $setarr['detail_ID_hash'] . "' AND status=0 AND detail_ID_test='{$this->url}'"), 0))) {
             DB::insert('strayer_evo', $setarr, TRUE);
         }
         $result_info['status'] = 'no';
         return $result_info;
     } else {
         //有了资料
         $title_rules = $this->get_rules($info, $title_info, $data_info, 'title');
         $text_rules = $this->get_rules($info, $text_info, $data_info, 'text');
         //删除之前的一些记录,防止没有索引的情况下重复生成规则
         $check_info = DB::fetch_first("SELECT * FROM " . DB::table('strayer_evo') . " WHERE domain_hash='{$domain_hash}' AND detail_ID_hash='" . $setarr['detail_ID_hash'] . "' AND status=1");
         DB::query('DELETE FROM ' . DB::table('strayer_evo') . " WHERE id='{$check_info['id']}'");
         DB::query('DELETE FROM ' . DB::table('strayer_searchindex') . " WHERE id='{$check_info['id']}' AND type='34'");
         if ($text_rules) {
             $setarr = array('content_get_type' => $text_rules['get_type'], 'content_rules' => $text_rules['rules'], 'theme_get_type' => $title_rules['get_type'], 'theme_rules' => $title_rules['rules'], 'status' => 1);
             DB::update("strayer_evo", $setarr, array("id" => $data_info['id']));
             $pash_hash = get_path_hash($this->url);
             add_search_index($domain_hash, $path_hash, 34, $data_info['id']);
             //添加索引 4是本地缓存
             $pick_set = get_pick_set();
             if ($pick_set['open_cloud_pick'] == 1) {
                 //开启云采集,将规则上传到服务端
                 $rpcClient = rpcClient();
                 unset($setarr['status']);
                 $data_info['content_get_type'] = $setarr['content_get_type'];
                 $data_info['content_rules'] = $setarr['content_rules'];
                 $data_info['theme_get_type'] = $setarr['theme_get_type'];
                 $data_info['theme_rules'] = $setarr['theme_rules'];
                 $client_info = get_client_info();
                 $re = $rpcClient->upload_evo_data($data_info, $client_info);
             }
             del_search_index(3);
             $result_info['status'] = 'ok';
             return $result_info;
         }
     }
 }
Beispiel #4
0
 function _ini_config($pid = 0, $is_cron = 0)
 {
     global $_G;
     $this->error = '';
     if ($pid == 0 && $is_cron > 0) {
         $this->error = 1;
         return;
     }
     $this->pid = $pid > 0 ? intval($pid) : intval($_GET['pid']);
     $this->pick_cache_data = load_cache('pick' . $this->pid);
     $this->i = $this->pick_cache_data['i'] ? $this->pick_cache_data['i'] : 1;
     $this->v_i = $this->pick_cache_data['v_i'] ? $this->pick_cache_data['v_i'] : 0;
     $this->a = $this->pick_cache_data['a'] ? $this->pick_cache_data['a'] : 0;
     $this->v_a = $this->pick_cache_data['v_a'] ? $this->pick_cache_data['v_a'] : 0;
     $this->all_get_time = $this->pick_cache_data['all_get_time'] ? $this->pick_cache_data['all_get_time'] : 0;
     $this->temp_arr['have_reply'] = 0;
     $this->plugin_set = get_pick_set();
     if ($is_cron > 0 && $this->plugin_set['is_log_cron'] > 0) {
         $is_log = 1;
     }
     $this->msg_args = array('is_cron' => $is_cron, 'pid' => $this->pid, 'is_log' => $is_log);
     if ($this->i == 1) {
         show_pick_info(milu_lang('pick_start'), '', $this->msg_args);
     }
     $p_arr = get_pick_info($this->pid);
     $p_arr = pstripslashes($p_arr);
     //if(!VIP) unset($p_arr['reply_rules'],$p_arr['reply_is_extend'], $p_arr['content_page_rules']);
     if ($p_arr['rules_type'] == 3) {
         $p_arr['url_range_type'] = '';
     }
     //新增
     $this->pick_set = pick_common_get();
     //插件设置
     $this->pick_config = $_G['cache']['evn_milu_pick'];
     $p_arr['rules_var'] = dstripslashes(unserialize($p_arr['rules_var']));
     $p_arr['many_page_list'] = dstripslashes(unserialize($p_arr['many_page_list']));
     $p_arr['title_filter_rules'] = dstripslashes(unserialize($p_arr['title_filter_rules']));
     $p_arr['content_filter_rules'] = dstripslashes(unserialize($p_arr['content_filter_rules']));
     $p_arr['reply_filter_rules'] = dstripslashes(unserialize($p_arr['reply_filter_rules']));
     $p_arr['content_filter_html'] = dstripslashes(unserialize($p_arr['content_filter_html']));
     $p_arr['reply_filter_html'] = dstripslashes(unserialize($p_arr['reply_filter_html']));
     $p_arr['public_class'] = dstripslashes(unserialize($p_arr['public_class']));
     //发布分类
     //if(!VIP) $p_arr['is_auto_public'] = 0;
     if ($p_arr['is_login'] == 2) {
         $p_arr['login_cookie'] = '';
     }
     if (!$p_arr['reply_max_num']) {
         $p_arr['reply_max_num'] = 200000;
     }
     //如果没有设置回复,这个就是最大数目了
     if ($p_arr['reply_is_extend']) {
         //继承内容规则
         $p_arr['reply_get_type'] = $p_arr['content_get_type'];
         $p_arr['reply_rules'] = $p_arr['content_rules'];
         if ($p_arr['is_fiter_content'] == 1) {
             //内容是过滤的
             if ($p_arr['is_fiter_reply'] == 1) {
                 //回复是过滤的
                 $p_arr['reply_replace_rules'] = array_merge((array) $p_arr['reply_replace_rules'], (array) $p_arr['content_replace_rules']);
                 $p_arr['reply_filter_rules'] = array_merge((array) $p_arr['content_filter_rules'], (array) $p_arr['reply_filter_rules']);
                 $p_arr['reply_filter_html'] = array_merge((array) $p_arr['content_filter_html'], (array) $p_arr['reply_filter_html']);
             } else {
                 //内容过滤,回复不过滤
                 $p_arr['reply_replace_rules'] = $p_arr['content_replace_rules'];
                 $p_arr['reply_filter_rules'] = $p_arr['content_filter_rules'];
                 $p_arr['reply_filter_html'] = $p_arr['content_filter_html'];
                 $p_arr['is_fiter_reply'] = 1;
             }
         }
     }
     $p_arr['stop_time'] = explode(',', $p_arr['stop_time']);
     $p_arr['stop_time'] = array_map('intval', $p_arr['stop_time']);
     $this->p_arr = $p_arr;
     $rules_hash = $this->p_arr['rules_hash'];
     if ($this->p_arr['is_auto_public'] == 1 && !$this->p_arr['public_class'][0]) {
         //既设置了自动发布,又没有设置发布栏目
         $this->error = 1;
         show_pick_info(milu_lang('no_set_public_class'), 'exit', $this->msg_args);
         return;
     }
     if ($this->p_arr['is_auto_public'] == 1 && $this->p_arr['is_word_replace'] == 1) {
         //即自动发布,又设置了同义词替换
         $this->words = get_replace_words();
     }
     pload('F:rules');
     if ($rules_hash) {
         $r_arr = get_rules_info($rules_hash);
     }
     $r_arr = pstripslashes($r_arr);
     $r_arr['url_var'] = dstripslashes(unserialize($r_arr['url_var']));
     $this->r_arr = $r_arr;
     $this->rid = $r_arr['rid'];
     $this->now_level = $this->pick_cache_data['now_level'];
     $this->max_level = $this->pick_cache_data['max_level'];
     if (!$this->pick_cache_data) {
         update_times($this->pid);
     }
     if (!$this->pick_cache_data['start_time']) {
         $this->pick_cache_data['start_time'] = TIMESTAMP;
     }
     $this->cache_time = PICK_ENABLE_CACHE ? 3600 * 24 : -1;
     //缓存
 }