示例#1
0
/**
 * 广度便利树形目录,找到code=>学科中文名字和树形结构
 */
function trivalIndex($url, &$className)
{
    $isReadCache = false;
    global $cacheDir;
    $pattern1 = '/<a.*?onclick="ClickNode\\(\'(.*?)\',.*?>(.*?)<\\/a>/';
    //目录的根节点
    $pattern2 = '/<input type="checkbox" id="selectbox" value="(.*?)".*?name="(.*?)" .*?>/';
    //有子目录的节点
    $dir = get_code($url);
    $fileName = "./index/{$cacheDir}/" . $dir . ".html";
    $content = "";
    if (file_exists($fileName)) {
        echo "get file {$fileName} from cache\n";
        $content = file_get_contents($fileName);
        $isReadCache = true;
    } else {
        echo "get file {$fileName} from network\n";
        $content = @file_get_contents($url);
        save($fileName, $content);
        $isReadCache = false;
    }
    $match = array();
    $ret = preg_match_all($pattern1, $content, $match);
    if (!$ret) {
        $ret = preg_match_all($pattern2, $content, $match);
        echo "[WARNNING] use pattern 2\n {$content}\n";
        if (!$ret) {
            //echo "not found $url\n";
            save("./index/{$cacheDir}/{$cacheDir}.log", $url . "\n" . $content . "\n\n", "a+");
            return;
        }
    }
    $code = $match[1];
    $name = $match[2];
    for ($i = 0; $i < count($code); $i++) {
        $namei = $name[$i];
        $codei = $code[$i];
        //var_dump($codei);
        echo "\n{$namei} => {$codei}\n";
        addCode($namei, $codei);
        $className[$namei] = array();
        $url = replace_code($codei);
        trivalIndex($url, $className[$namei]);
        if ($isReadCache == false) {
            sleep(4);
        }
    }
}
示例#2
0
function get_content($url, $config)
{
    $html = get_curl($url);
    $html = str_replace(array("\r", "\n"), "", $html);
    foreach ($config['fields'] as $field => $_c) {
        if (isset($_c['func'])) {
            $tmp = cut_html($html, $_c['start'], $_c['end']);
            $func = $_c['func'];
            $data[$field] = $func($tmp, $_c['func_result']);
        } else {
            $data[$field] = cut_html($html, $_c['start'], $_c['end']);
            if (isset($_c['replace_code'])) {
                $data[$field] = replace_code($data[$field], $_c['replace_code']);
            }
        }
    }
    return $data;
}
示例#3
0
$smarty->cache_lifetime = 1800;
if ($exist) {
    # Cache de 1 dia
    if (!$smarty->is_cached($tpl, $pattern)) {
        # Paginas
        $ab_page = new ab_pageTable();
        $rows = $ab_page->readDataSQL("SELECT idab_page,ab_page FROM ab_page ORDER BY orden");
        $smarty->assign('ab_pages', $rows);
        unset($rows);
        # Entradas
        $entrada = new ab_entryTable();
        $entrada->readEnv();
        list($row) = $entrada->readDataFilter("idab_entry = " . $entrada->request['idab_entry'] . " AND public IS TRUE");
        if (count($row)) {
            $row['seo_title'] = generate_seo_link($row['ab_entry']);
            $row['body'] = replace_code($row['body']);
            $smarty->assign('entrada', $row);
            $smarty->assign('title', $row['ab_entry']);
        }
        $comentarioent = new ab_commentTable();
        $comentarioent->order = 'sentdate DESC';
        $comentarioent->filter = '';
        if ($row) {
            $rows = $comentarioent->readDataFilter("ab_comment.public IS TRUE AND ab_comment.idab_entry = " . $row['idab_entry']);
            $pgs = ceil($comentarioent->getVar("SELECT count(idab_comment) FROM ab_comment WHERE ab_comment.public IS TRUE AND ab_comment.idab_entry = " . $row['idab_entry']) / AB_COMMENT_PAGE);
            $smarty->assign('pg', 1);
            $smarty->assign('prev_num', 1);
            $smarty->assign('pgs', $pgs);
            $smarty->assign('comentarios', $rows);
        }
        unset($row);