<?php
/**
 * 下載種子網址中未下載內容模式
 *
 * @version        $Id: co_get_corule.php 1 17:13 2010年7月12日Z tianya $
 * @package        DedeCMS.Administrator
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
require_once(dirname(__FILE__)."/config.php");
CheckPurview('co_PlayNote');
require_once(DEDEINC.'/dedecollection.class.php');

if(empty($islisten)) $islisten = 0;
if(empty($glstart)) $glstart = 0;
if(empty($totalnum)) $totalnum = 0;
if(empty($notckpic)) $notckpic = 0;

$nid = (isset($nid) ? intval($nid) : 0);

//下載種子網址中未下載內容模式
/*-----------------------------
function Download_not_down() { }
------------------------------*/
if($islisten==0)
{
    $mrow = $dsql->GetOne("SELECT COUNT(*) AS dd FROM `#@__co_htmls` WHERE nid='$nid' ");
    $totalnum = $mrow['dd'];
    $gurl = "co_gather_start_action.php?notckpic=$notckpic&islisten=$islisten&nid=$nid&startdd=$startdd&pagesize=$pagesize&sptime=$sptime";
    if($totalnum <= 0)
    {
        ShowMsg("你指定的模式為：<font color='red'>[下載種子網址中未下載內容]</font>，<br />使用這個模式節點必須已經有種子網址，否則請使用其它模式！","javascript:;");
        exit();
    }
    else
    {
        ShowMsg("檢測節點正常，現轉向網頁採集...",$gurl."&totalnum=$totalnum");
        exit();
    }
}

//監控式採集（檢測新內容）
/*-----------------------------
function Download_new() { }
------------------------------*/
else if($islisten==1)
{
    $gurl = "co_gather_start_action.php?notckpic=$notckpic&islisten=1&nid=$nid&startdd=$startdd&pagesize=$pagesize&sptime=$sptime";
    $gurlList = "co_getsource_url_action.php?islisten=1&nid=0&pagesize=$pagesize&sptime=$sptime";
    //針對專門節點
    if(!empty($nid))
    {
        $co = new DedeCollection();
        $co->LoadNote($nid);
        $limitList = $co->GetSourceUrl(1,0,100);
        $row = $co->dsql->GetOne("SELECT COUNT(aid) AS dd FROM `#@__co_htmls` WHERE nid='$nid' ");
        $totalnum = $row['dd'];
        if($totalnum==0)
        {
            ShowMsg("在這節點中沒發現有新內容....","javascript:;");
            exit();
        }
        else
        {
            ShowMsg("已獲得所有種子網址，轉向網頁採集...",$gurl."&totalnum=$totalnum");
            exit();
        }
    }
    //針對所有節點
    else
    {
        $curpos = (isset($curpos) ? intval($curpos) : 0);
        $row = $dsql->GetOne("SELECT nid FROM `#@__co_note` ORDER BY nid ASC LIMIT $curpos,1");
        $nnid = $row['nid'];
        if(!is_array($row))
        {
            ShowMsg("完成所有節點檢測....","co_gather_start_action.php?notckpic=0&sptime=0&nid=0&startdd=0&pagesize=5&totalnum=".$totalnum);
            exit();
        }
        else
        {
            $co = new DedeCollection();
            $co->LoadNote($nnid);
            $limitList = $co->GetSourceUrl(1,0,100);
            $curpos++;
            ShowMsg("已檢測節點( {$nnid} )，繼續下一個節點...",$gurlList."&curpos=$curpos");
            exit();
        }
    }
}
//重新下載所有內容模式
/*-----------------------------
function Download_all() { }
------------------------------*/
else
{
    $gurl = "co_gather_start_action.php?notckpic=$notckpic&islisten=$islisten&nid=$nid&startdd=$startdd&pagesize=$pagesize&sptime=$sptime";
    $gurlList = "co_getsource_url_action.php?islisten=$islisten&nid=$nid&startdd=$startdd&pagesize=$pagesize&sptime=$sptime";
    $co = new DedeCollection();
    $co->LoadNote($nid);
    $limitList = $co->GetSourceUrl($islisten, $glstart, $pagesize);
    if($limitList==0)
    {
        $row = $co->dsql->GetOne("SELECT COUNT(aid) AS dd FROM `#@__co_htmls` WHERE nid='$nid'");
        $totalnum = $row['dd'];
        ShowMsg("已獲得所有種子網址，轉向網頁採集...",$gurl."&totalnum=$totalnum");
        exit();
    }
    if($limitList>0)
    {
        ShowMsg("採集列表剩餘：{$limitList} 個頁面，繼續採集...",$gurlList."&glstart=".($glstart+$pagesize),0,100);
        exit();
    }
}