Exemplo n.º 1
0
 public function actionCheck($id = null)
 {
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $id = $_POST['List']['collect_list_id'];
     }
     $ids = is_array($id) ? $id : array($id);
     $ids = array_filter($ids);
     if (!count($ids)) {
         $this->redirect[] = array('text' => '', 'href' => $_SERVER['HTTP_REFERER']);
         $this->message('请选择至少一项进行操作!', self::MSG_SUCCESS, true);
     }
     $value = intval($_REQUEST['value']) ? 1 : 0;
     //1审核0取消审核
     foreach ($ids as $id) {
         $list = CollectList::get_list_by_id($id, false);
         $task = CollectTask::get_task_by_id($list['collect_task_id'], false);
         $template = CollectTemplate::get_template_by_id($task['collect_template_id'], false);
         if ($value) {
             /*$sql = "INSERT INTO {{game_media_data}} SET 
             				`media_data_subject`='{$list[collect_list_title]}',
             				`media_data_href`='$list[collect_list_url]',
             				`media_data_thumb`='$list[collect_list_thumb]',
             				`media_data_dateline`=".time().",
             				`game_id`='{$list[game_id]}',
             				`content_class_id`='{$task[content_class_id]}',
             				`media_data_source`='{$template[collect_source_id]}',
             				`collect_data_time`=".strtotime($list['collect_list_day'])
             		;
             		$_cmd->execute();*/
             $_cmd = Yii::app()->db->createCommand()->insert('{{game_media_data}}', array('media_data_subject' => $list[collect_list_title], 'media_data_href' => $list[collect_list_url], 'media_data_thumb' => $list[collect_list_thumb], 'media_data_dateline' => time(), 'game_id' => $list[game_id], 'content_class_id' => $task[content_class_id], 'media_data_source' => $template[collect_source_id], 'collect_data_time' => strtotime($list['collect_list_day'])));
             $media_data_id = Yii::app()->db->getLastInsertID();
         } else {
             //取消审核
             $media_data_id = 0;
             if ($list["media_data_id"]) {
                 $sql = "DELETE FROM {{game_media_data}} WHERE media_data_id={$list[media_data_id]}";
                 $_cmd = Yii::app()->db->createCommand($sql);
                 $_cmd->execute();
             }
         }
         $_sql = "UPDATE {{collect_list}} SET `collect_list_check`={$value},`media_data_id`={$media_data_id} WHERE collect_list_id={$id}";
         $_cmd = Yii::app()->db->createCommand($_sql);
         $_cmd->execute();
     }
     if (!isset($_GET['ajax'])) {
         $this->redirect[] = array('text' => '', 'href' => $_SERVER['HTTP_REFERER']);
         $this->message('操作成功', self::MSG_SUCCESS, true);
     }
 }
Exemplo n.º 2
0
Arquivo: Task.php Projeto: nbaiwan/yav
 public function collectAction($id)
 {
     $task = CollectTaskModel::inst()->getTaskById($id);
     if (empty($task)) {
         $this->redirect[] = array('text' => '', 'href' => '/collect/task/index');
         $this->message('采集规则不存在或已被删除', self::MSG_ERROR, true);
     }
     if ($_GET['type'] == 'list') {
         $cacheKey = "jvod.collect.list.urls";
         if ($this->redis->llen($cacheKey) == 0) {
             $collect_list_urls = CollectTaskModel::getListUrls($task['collect_task_urls']);
             foreach ($collect_list_urls as $_k => $_v) {
                 $this->redis->lpush($cacheKey, $_v);
             }
         }
         for ($i = 0; $i < 20 && $this->redis->llen($cacheKey) > 0; $i++) {
             $collect_list_url = $this->redis->rpop($cacheKey);
             $collect_content_urls = CollectTaskModel::getContentUrls($collect_list_url, $task['collect_list_rules']['begin'], $task['collect_list_rules']['end']);
             $repeat_number = 0;
             $sql = "SELECT COUNT(collect_content_id) FROM {{collect_content}} WHERE collect_content_url=:collect_content_url";
             foreach ($collect_content_urls as $_k => $_v) {
                 if ($this->db->queryScalar($sql, array(':collect_content_url' => $_v)) == 0) {
                     $this->db->insert('{{collect_content}}', array('collect_content_id' => 0, 'collect_task_id' => $id, 'collect_content_url' => $_v, 'is_published' => 0, 'is_collected' => 0, 'lasttime' => $_SERVER['REQUEST_TIME'], 'dateline' => $_SERVER['REQUEST_TIME']));
                 } else {
                     $repeat_number++;
                 }
                 if ($repeat_number > 20) {
                     // 超过20个重复地址,退出内容地址采集
                     break;
                 }
             }
         }
     } else {
         $cacheKey = "jvod.collect.content.urls";
         if ($this->queue->llen($cacheKey) == 0) {
             $sql = "SELECT collect_content_id, collect_task_id, collect_content_url, is_collected, is_published, lasttime, dateline FROM {{collect_content}} WHERE collect_task_id=:collect_task_id AND is_collected=:is_collected";
             $ret = $this->db->queryAll($sql, array(':collect_task_id' => $id, ':is_collected' => 0));
             foreach ($ret as $_k => $_v) {
                 $this->queue->lpush($cacheKey, json_encode(array($_v['collect_content_id'], $_v['collect_content_url'])));
             }
         }
         for ($i = 0; $i < 20 && $this->queue->llen($cacheKey) > 0; $i++) {
             list($collect_content_id, $collect_content_url) = json_decode($this->queue->rpop($cacheKey));
             $collect_content_charset = 'utf-8';
             $collect_content_body = CollectTask::get_url_contents($collect_content_url, $collect_content_charset);
             if (strtolower($collect_content_charset) != 'utf-8') {
                 $collect_content_body = mb_convert_encoding($collect_content_body, 'UTF-8', $collect_content_charset);
             }
             $task['collect_content_data'] = array();
             $data = array('collect_content_id' => $collect_content_id);
             foreach ($task['collect_content_rules'] as $_k => $_v) {
                 if ($_v['begin'] && $_v['end']) {
                     preg_match("/{$_v['begin']}(.+?){$_v['end']}/s", $collect_content_body, $ret);
                     $data[$_v['collect_fields_identify']] = $ret[1] ? $ret[1] : '';
                 } else {
                     $data[$_v['collect_fields_identify']] = '';
                 }
             }
             $flag = $this->db->insert("{{collect_model_addons{$task['collect_model_identify']}}}", $data);
             if ($flag) {
                 $this->db->update("{{collect_content}}", array('is_collected' => 1), 'collect_content_url=:collect_content_url', array(':collect_content_url' => $collect_content_url));
             }
         }
     }
 }
Exemplo n.º 3
0
<?php

/**
 * 关注/取消关注
 */
require_once 'lib/WriteLog.lib.php';
try {
    require_once 'tasks/Collect/CollectTask.class.php';
    $nType = isset($_GET['type']) ? $_GET['type'] : 0;
    $collect = new CollectTask();
    if ($nType == 0) {
        $result = $collect->getMyDesigner();
    }
    if ($nType == 1) {
        $result = $collect->getDesigner();
    }
    echo $result;
} catch (Exception $e) {
    Log::write('designer exception:' . $e->getMessage(), 'log');
    echo get_rsp_result(false, 'designer exception');
}
Exemplo n.º 4
0
 /**
  * 采集
  * @param int $id  collect_task_id
  * @url  string  需要读取的文件地址
  * @task  array  采集任务记录数组
  */
 public function ContentReg($id, $url, $task)
 {
     $re = CollectTask::read_html($url);
     if ($re['success']) {
         $content = $re['content'];
     } else {
         echo '<script>alert("' . $re['error'] . '");window.close();</script>';
         exit;
     }
     $url_arr = parse_url($url);
     if ($url_arr['path']) {
         $a = array_filter(explode("/", $url_arr['path']));
         array_pop($a);
         $pa = implode("/", $a) . "/";
     } else {
         $pa = "";
     }
     $content = CollectTask::re2ab($content, $url_arr['scheme'] . "://" . $url_arr['host'] . "/" . $pa);
     $template = CollectTemplate::get_template_by_id($task['collect_template_id'], false);
     if ($task['collect_task_totalpagereg']) {
         $totalpagereg = $task['collect_task_totalpagereg'];
     } elseif ($template['collect_template_totalpagereg']) {
         $totalpagereg = $template['collect_template_totalpagereg'];
     } else {
         $totalpagereg = "";
     }
     $pagerule = $task['collect_task_pagerule'] ? $task['collect_task_pagerule'] : $template['collect_template_pagerule'];
     $totalpage = 0;
     if ($totalpagereg) {
         $totalpagereg = preg_replace("/\\[.*\\]/U", "(\\d)", $totalpagereg);
         preg_match("/" . $totalpagereg . "/", $content, $p);
         if (intval($p[1])) {
             $totalpage = intval($p[1]);
         }
     }
     $pageurl_arr = array();
     if ($totalpage) {
         for ($i = 2; $i <= $totalpage; $i++) {
             $pageurl_arr[] = preg_replace("/{$pagerule}\\d/", $pagerule . $i, $url);
         }
     } else {
         //不是js分页时,则查找分页地址
         $pagestart = $task['collect_task_pagestart'] ? $task['collect_task_pagestart'] : $template['collect_template_pagestart'];
         $pageend = $task['collect_task_pageend'] ? $task['collect_task_pageend'] : $template['collect_template_pageend'];
         if ($pagestart && $pageend) {
             $page_area_reg = str_replace("/", "\\/", $pagestart) . "([\\s\\S]*)" . str_replace("/", "\\/", $pageend);
             preg_match("/{$page_area_reg}/Ui", $content, $mm);
             if ($mm[1]) {
                 preg_match_all('/\\<a.*href=["|\'](.*)?["|\'].*\\>(.*)\\<\\/a\\>/iU', $content, $arr);
                 if (count($arr[1])) {
                     $links = array_unique($arr[1]);
                     sort($links);
                     $source_url = preg_replace("/{$pagerule}\\d/", "", $url);
                     if ($pagerule) {
                         foreach ($links as $k => $v) {
                             if ($v != $url) {
                                 $baseurl = preg_replace("/{$pagerule}\\d/", "", $v);
                                 if ($baseurl == $source_url && $v != $url) {
                                     $pageurl_arr[] = $v;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (is_array($pageurl_arr) && count($pageurl_arr)) {
         //取得所有分页内容
         foreach ($pageurl_arr as $v) {
             $c = CollectTask::read_html($v);
             if ($c['content']) {
                 $c['content'] = CollectTask::re2ab($c['content'], $url_arr['scheme'] . "://" . $url_arr['host'] . "/");
                 $content .= $c['content'];
             }
         }
     }
     $content = str_replace("none", "block", $content);
     //有些分页是默认不显示内容的
     $filter = array();
     if ($task['collect_task_filter']) {
         $filter = array_merge($filter, json_decode($task['collect_task_filter']));
     }
     if ($template['collect_template_filter']) {
         $filter = array_merge($filter, json_decode($template['collect_template_filter']));
     }
     $_charset = CollectTask::get_charset();
     $content = mb_convert_encoding($content, "UTF-8", "gb2312,gbk,utf-8");
     if (count($filter)) {
         foreach ($filter as $f) {
             $f = preg_replace("/\\[.*\\]/U", "([\\s\\S]*)", $f);
             $f = str_replace("/", "\\/", $f);
             $content = preg_replace("/" . $f . "/Ui", " ", $content);
         }
     }
     if ($task['collect_task_rulearr']) {
         eval('$task_rule_arr = ' . $task['collect_task_rulearr'] . ';');
         $task_rule_arr = array_filter($task_rule_arr);
     } else {
         $task_rule_arr = array();
     }
     if ($template['collect_template_fieldsreg']) {
         eval('$template_rule_arr = ' . $template['collect_template_fieldsreg'] . ';');
     }
     if (count($task_rule_arr)) {
         foreach ($task_rule_arr as $k => $v) {
             $template_rule_arr[$k] = $v;
         }
     }
     $template_rule_arr = array_filter($template_rule_arr);
     $fields = array();
     if (count($template_rule_arr) && is_array($template_rule_arr)) {
         foreach ($template_rule_arr as $k => $v) {
             $reg = preg_replace("/\\[.*\\]/U", "([\\s\\S]*)", $v);
             $reg = str_replace("/", "\\/", $reg);
             preg_match_all("/" . $reg . "/U", $content, $ma);
             if (count($ma[1])) {
                 foreach ($ma[1] as $k2 => $v2) {
                     if (CollectTask::is_image($v2)) {
                         if ($task['collect_task_saveimg']) {
                             $ma[1][$k2] = CollectTask::save_image($v2);
                         } else {
                             $ma[1][$k2] = $v2;
                         }
                     } else {
                         if ($task['collect_task_saveimg']) {
                             preg_match_all('/<img.*src=["|\']+(.*)?["|\']+>/Ui', $v2, $arr);
                             //正则出所有图片保存替换
                             if (is_array($arr[1]) && count($arr[1])) {
                                 foreach ($arr[1] as $img) {
                                     $ma[1][$k2] = str_replace($img, CollectTask::save_image($img), $v2);
                                 }
                             }
                         }
                     }
                 }
                 preg_match("/\\[(.*)\\]/U", $v, $match);
                 $fields[] = array('identify' => $k, 'name' => $match[1], 'value' => $ma[1][0]);
             }
         }
     }
     return $fields;
 }
Exemplo n.º 5
0
<?php

/**
 * 关注/取消关注
 */
require_once 'lib/WriteLog.lib.php';
try {
    require_once 'tasks/Collect/CollectTask.class.php';
    $collect = new CollectTask();
    $nCollect = isset($_GET['collect']) ? $_GET['collect'] : 0;
    #0取消关注/1添加关注/2获取关注状态
    if ($nCollect == 2) {
        $result = $collect->getCollect($nCollect);
    } else {
        $result = $collect->setCollect($nCollect);
    }
    echo $result;
} catch (Exception $e) {
    Log::write('collect exception:' . $e->getMessage(), 'log');
    echo get_rsp_result(false, 'collect exception');
}
Exemplo n.º 6
0
    if (is_array($f['value'])) {
        foreach ($f['value'] as $v) {
            if (CollectTask::is_image($v)) {
                //echo CollectTask::signName($v).".".CollectTask::getFileType($v);
                ?>
			<img src='<?php 
                echo $v;
                ?>
' /><br />
			<?php 
            } else {
                echo $v . '<br />';
            }
        }
    } else {
        if (CollectTask::is_image($f['value'])) {
            ?>
			<img src='<?php 
            echo $v;
            ?>
' /><br />
			<?php 
        } else {
            echo $v . '<br />';
        }
    }
    ?>
                        </td>
		</tr>
                <?php 
}