Beispiel #1
0
function mcv_videos($url)
{
    $saveurl = md5($url);
    $path = ABSPATH . "videocache/{$saveurl}.json";
    $tpldir = get_bloginfo('template_directory');
    $content = "<li class=\"loading\"><div class=\"pts\">loading</div><a href=\"javascript:;\" class=\"videoPic\"><img src=\"{$tpldir}/images/mcv_loading.gif\" alt=\"null\" class=\"load\" /><time>00:00</time></a><a href=\"javascript:;\" data-onsite=\"{$url}\" class=\"title\" title=\"正在更新视频...\">正在更新视频...</a></li>\r\n\t";
    if (!file_exists($path)) {
        mcv_save(md5($url), curl_file($url));
        return $content;
    } else {
        $now = time();
        $ftime = filemtime($path);
        if ($now - $ftime > 3600) {
            /* 缓存文件有效期(秒) */
            mcv_save(md5($url), curl_file($url));
            return $content;
        } else {
            $filepath = file_get_contents($path);
            $json = json_decode($filepath, true);
            if ($json['status'] == 1) {
                return "<li class=\"{$json['type']}\"><div class=\"pts\">{$json['play']} pts</div><a href=\"javascript:;\" data-offsite=\"{$json['offsite']}\" data-oriurl=\"{$json['oriurl']}\" class=\"videoPic\"><img src=\"{$json['pic']}\" alt=\"{$json['title']}\" /><time>{$json['time']}</time></a><a href=\"javascript:;\" data-onsite=\"{$json['onsite']}\" class=\"title\" title=\"{$json['title']}\">{$json['title']}</a></li>";
            } else {
                return "<li class=\"null\"><div class=\"pts\">null</div><a href=\"javascript:;\" class=\"videoPic\"><img src=\"{$tpldir}/images/mcv_sad.png\" alt=\"null\" class=\"load\" /><time>00:00</time></a><a href=\"javascript:;\" data-onsite=\"{$url}\" class=\"title\" title=\"无法解析该视频\">无法解析该视频</a></li>\r\n\t";
            }
        }
    }
}
Beispiel #2
0
function makeWeather($saveFilePath = 'api', $openFile = '/weather.txt')
{
    //读取文件并过滤重复
    $handle = fopen($saveFilePath . $openFile, "r");
    if (!$handle) {
        exit('文件不存在。');
    }
    $temp_arr = array();
    do {
        $file = fgets($handle, 1024);
        $temp_arr[] = $file;
    } while (!feof($handle));
    fclose($handle);
    //遍历数组,取相同组,创建新数组,最后得到没有重复的数组,筛选完成
    $newArr = array();
    foreach ($temp_arr as $key => $value) {
        if (in_array($value, $arr)) {
            unset($newArr[$key]);
        } else {
            $newArr[] = $value;
        }
    }
    //去掉文件中空值,同时去掉最后一个空值被取到数组
    $cot = count($newArr);
    unset($newArr[$cot - 1]);
    //获取要采集的文件
    foreach ($newArr as $key => $value) {
        flush();
        $urlFile = str_replace(PHP_EOL, '', $value);
        //PHP自带过滤换行
        $urlFile = parse_url($urlFile, PHP_URL_PATH);
        $urlFile = $saveFilePath . $urlFile;
        $value = str_replace(PHP_EOL, '', $value);
        //PHP自带过滤换行
        //未成功写入则跳过
        if (saveFile($urlFile, curl_file($value))) {
            echo '<font color="#66CC00">写入成功</font> ' . $urlFile . '<br>';
            ob_flush();
        } else {
            continue;
        }
    }
    exit($openFile . '中文件采集执行完毕。');
}