Esempio n. 1
0
function evo_rules_get_article($str, $rules_info)
{
    $rules_info['theme_get_type'] = $rules_info['theme_get_type'] ? $rules_info['theme_get_type'] : 1;
    $get = 0;
    if ($rules_info['theme_get_type'] == 1 && $rules_info['content_get_type'] == 1) {
        $re = dom_single_article($str, array('title' => $rules_info['theme_rules'], 'content' => $rules_info['content_rules']));
        $data['title'] = $re['title'];
        $data['content'] = $re['content'];
        $get = 1;
    }
    if ($get != 1) {
        if ($rules_info['theme_get_type'] == 1) {
            $re = dom_single_article($str, array('content' => $rules_info['content_rules']));
            $data['title'] = $re['title'];
        } else {
            if ($rules_info['theme_get_type'] == 2) {
                $re = pregmessage($str, $rules_info['theme_rules'], 'title', -1);
                $data['title'] = $re[0];
            }
        }
        if ($rules_info['content_get_type'] == 1) {
            $re = dom_single_article($str, array('content' => $rules_info['content_rules']));
            $data['content'] = $re['content'];
        } else {
            if ($rules_info['content_get_type'] == 2) {
                $data['content'] = str_get_str($str, $rules_info['content_rules'], 'body', -1);
            }
        }
    }
    //过滤
    if ($rules_info['is_fiter_title'] == 1 && $data['title']) {
        $format_args = array('is_fiter' => $rules_info['is_fiter_title'], 'show_type' => 'title', 'result_data' => $data['title'], 'replace_rules' => $rules_info['title_replace_rules'], 'filter_data' => dunserialize($rules_info['title_filter_rules']), 'test' => 2, 'filter_html' => '');
        $data['title'] = filter_article($format_args);
    }
    if ($rules_info['is_fiter_content'] == 1 && $data['content']) {
        $format_args = array('is_fiter' => $rules_info['is_fiter_content'], 'show_type' => 'body', 'result_data' => $data['content'], 'replace_rules' => $rules_info['content_replace_rules'], 'filter_data' => dunserialize($rules_info['content_filter_rules']), 'test' => 2, 'filter_html' => dunserialize($rules_info['content_filter_html']));
        $data['content'] = filter_article($format_args);
    }
    return $data;
}
Esempio n. 2
0
                 $_POST['author'] = $_SESSION['save_search']['author'];
             }
         }
     } else {
         if (isset($_GET['q'])) {
             $q = filter_var($_GET['q'], FILTER_SANITIZE_STRING);
             $search_source = 'all';
             $search_target = 'all';
             $search_year = '';
         }
     }
     if (!empty($q)) {
         #search
         $query = makequery($q, $search_source, $search_target, $search_year);
         if ($search_source == 'article') {
             $query = filter_article($query);
         } else {
             if ($search_source == 'thesis') {
                 $query = filter_thesis($query);
             }
         }
     }
 }
 if (is_array($query) && !empty($query)) {
     #search
     $count = search($pdo, $query['count']);
     $data_count = 0;
     foreach ($count as $c) {
         $data_count = (int) $data_count + $c['count'];
     }
     //$count && !empty($count) && is_array($count) && $count[0] > 0 && end($count)
 //
 // Loop through new articles
 //
 $fetched = 0;
 foreach ($feed->items as $item) {
     // log the date
     echo date(' -Y-m-d H:i:s- ');
     $data = array('uid' => $item->id, 'title' => $item->title, 'source_id' => $source_id, 'url' => $item->url, 'date' => $item->date->format('c'), 'content' => $item->content, 'post_id' => 0, 'fetched_at' => date('Y-m-d H:i:s'), 'featured_img' => '');
     // Skip already added articles
     if (strtotime($data['date']) <= strtotime($latest_date)) {
         continue;
     }
     //
     // Filtering article content
     //
     $filtered = filter_article($data['content'], $data['source_id']);
     $data['content'] = $filtered['content'];
     $data['featured_img'] = $filtered['featured_img'];
     echo "Filtered... OK. ";
     //
     // Insert in database
     //
     $id = $db->insert('jobarticles', $data);
     $fetched += 1;
     // log
     echo sprintf("Added %d<br>", $id);
 }
 // Done. Final log
 if ($fetched) {
     echo sprintf("<br>New %d articles fetched<br>", $fetched);
 } else {
Esempio n. 4
0
function test_window($get_type, $url_test, $is_fiter, $rules, $replace_rules, $filter_data, $show_type, $login_cookie, $filter_html_arr)
{
    $url_test = rpc_str($url_test);
    $rules = rpc_str($rules);
    $replace_rules = rpc_str($replace_rules);
    $login_cookie = rpc_str(urlencode($login_cookie));
    foreach ($filter_data as $k => $v) {
        if ($v) {
            $filter_data[$k][1] = rpc_str($v[1]);
        }
    }
    $filter_html_arr = sarray_unique($filter_html_arr);
    //去重
    if ($show_type == 'title') {
        $show_name = milu_lang('title');
    } else {
        if ($show_type == 'body') {
            $show_name = milu_lang('body');
        } else {
            $show_name = milu_lang('reply');
        }
    }
    $contents = get_contents($url_test, array('cookie' => $login_cookie));
    $contents = dz_attach_format($url_test, $contents);
    $c_arr = format_article_imgurl($url_test, $contents);
    $contents = $c_arr['message'];
    if ($get_type == 1) {
        //dom
        if ($show_type == 'reply') {
            $result_data = dom_get_manytext($contents, $rules);
        } else {
            if ($show_type == 'title') {
                $dom_rules['title'] = $rules;
            } else {
                $dom_rules['content'] = $rules;
            }
            $re = dom_single_article($contents, $dom_rules);
            $result_data = $show_type == 'title' ? $re['title'] : $re['content'];
        }
    } else {
        if ($get_type == 2) {
            //字符串
            if ($contents != -1) {
                if ($show_type == 'reply') {
                    $rules = str_replace('[body]', '[reply]', $rules);
                    $result_data = str_get_str($contents, $rules, $show_type, -1);
                    unset($result_data[0]);
                } else {
                    $result_data = str_get_str($contents, $rules, $show_type, 1);
                }
            }
        } else {
            //智能获取
            if ($contents != -1) {
                $re = get_single_article($contents, $url_test);
                if ($show_type == 'title') {
                    $result_data = $re['title'];
                } else {
                    $result_data = $re['content'];
                }
            }
        }
    }
    if ($result_data == -1) {
        echo milu_lang('unable_pick');
        return;
    } else {
        if ($result_data == -2) {
            echo milu_lang('get_time_out');
            return;
        }
    }
    if (!$result_data) {
        echo milu_lang('no_get_data') . $show_name;
        return;
    }
    $format_args = array('is_fiter' => $is_fiter, 'show_type' => $show_type, 'result_data' => $result_data, 'replace_rules' => $replace_rules, 'filter_data' => $filter_data, 'test' => 1, 'filter_html' => $filter_html_arr);
    $result_data = filter_article($format_args);
    if ($show_type == 'reply') {
        $body = show_reply_output($result_data);
    } else {
        $body .= $result_data;
    }
    $body .= $notice;
    echo $body;
}
Esempio n. 5
0
 function format_reply($reply_data)
 {
     if (!$this->base_url) {
         $this->base_url = $this->now_url;
     }
     foreach ($reply_data as $k => $v) {
         //附件
         $v = dz_attach_format($this->base_url, $v);
         if ($this->p_arr['is_download_file'] == 1) {
             $v = attach_format($this->base_url, $v);
         }
         $v = media_format($v, $this->base_url);
         //
         $format_arr = format_article_imgurl($this->base_url, $v);
         //处理图片路径
         $reply_data[$k] = $format_arr['message'];
     }
     $reply_filter_html = $this->p_arr['reply_filter_html'];
     if ($this->p_arr['is_download_file'] == 1) {
         $a_key = array_search('0', $reply_filter_html);
         if (!$a_key) {
             unset($reply_filter_html[$a_key]);
         }
         //如果要下载附件,不要去除a标签
     }
     $format_args = array('is_fiter' => $this->p_arr['is_fiter_reply'], 'show_type' => 'reply', 'test' => 2, 'result_data' => $reply_data, 'replace_rules' => $this->p_arr['reply_replace_rules'], 'filter_html' => $reply_filter_html, 'filter_data' => $this->p_arr['reply_filter_rules']);
     $reply_data = filter_article($format_args);
     return $reply_data;
 }