Beispiel #1
0
function extra_products()
{
    global $dir;
    //目录: products
    $path = './products';
    $save_dir = $dir . '/products';
    if (!file_exists($save_dir)) {
        mkdir($save_dir, 0777);
    }
    $file_index = $path . '/index.html';
    if (!file_exists($file_index)) {
        die("index.html does not exists!\n");
    }
    $cat1 = extra_cat_level_1($file_index);
    if ($cat1 && is_array($cat1) && count($cat1) > 0) {
        //保存一级类
        $str = implode("\n", $cat1);
        file_put_contents($save_dir . '/categories.txt', $str);
        echo "save main categories success \n\n";
        foreach ($cat1 as $val) {
            $val = str_replace(' ', '_', dealwith_kw($val));
            $path1 = $path . '/' . strtolower($val);
            $file_index2 = $path1 . '/index.html';
            if (!file_exists($file_index2)) {
                continue;
            }
            //抽取2级类
            $cat2 = extra_cat_level_2($file_index2);
            if ($cat2 && is_array($cat2) && count($cat2) > 0) {
                $dir_cat = $save_dir . '/' . strtolower($val);
                if (!file_exists($dir_cat)) {
                    mkdir($dir_cat, 0777);
                }
                file_put_contents($dir_cat . '/categories.txt', implode("\n", $cat2));
                //保存2级分类
                echo "save secondary categories success \n\n";
                foreach ($cat2 as $k => $v) {
                    $path2 = '.' . $k;
                    $filename_index = $path2 . '/index.html';
                    if (!file_exists($filename_index)) {
                        continue;
                    }
                    $words = extra_words_from_page($filename_index, $path2);
                    if ($words && count($words) > 0) {
                        $filename = trim(preg_replace('/[^a-z0-9]+/i', '_', strtolower($v)), '_') . '.txt';
                        file_put_contents($dir_cat . '/' . $filename, implode("\n", $words));
                        echo "save secondary words success \n\n";
                    }
                }
            }
        }
    }
    echo "finish!\n";
}
Beispiel #2
0
function get_rand_words($level = 0)
{
    global $DB;
    $words = array();
    //次数
    $gold_total = rand(3, 7);
    $bigend = 5;
    if ($level >= 200) {
        $bigend = 1;
    } else {
        if ($level >= 100) {
            $bigend = 2;
        } else {
            if ($level >= 50) {
                $bigend = 3;
            } else {
                if ($level >= 30) {
                    $bigend = 4;
                }
            }
        }
    }
    //金币点数值大小
    $gold_points = array();
    for ($i = 0; $i < $gold_total; $i++) {
        //$gold_points[$i] = $u == true ? getRand(5) : rand(1, 5);
        $gold_points[$i] = rand(1, $bigend);
    }
    //所有金子总和
    $total_points1 = array_sum($gold_points);
    //找几个有points的词
    $total_points = 0;
    foreach ($gold_points as $key => $val) {
        $sql = "select * from dig_gold_words where points={$val} order by rand() limit 1";
        $rs = $DB->fetch_arrays($sql);
        if ($rs) {
            $id = $rs[0]['id'];
            $words[$id]['word'] = dealwith_kw($rs[0]['word']);
            $words[$id]['points'] = $rs[0]['points'];
            $words[$id]['dig'] = 0;
            $total_points += $rs[0]['points'];
        }
    }
    //找100-$gold_total 个 points=0的词
    $sql = "select count(id) from dig_gold_words where points='0'";
    $rs = $DB->fetch_arrays($sql);
    //从表1中取点
    $limit = 100 - $gold_total - 20;
    $max = $rs[0][0] - 300;
    $min = 500;
    $begin = rand($min, $max);
    $sql = "select * from dig_gold_words where points='0' limit {$begin}, {$limit}";
    $rs = $DB->fetch_arrays($sql);
    if ($rs && is_array($rs) && count($rs) > 0) {
        foreach ($rs as $key => $val) {
            $words[$val['id']]['word'] = dealwith_kw($val['word']);
            $words[$val['id']]['points'] = 0;
            $words[$val['id']]['dig'] = 0;
        }
    }
    //从表2里去点
    $begin = rand(1, 480);
    $sql = "select * from dig_gold_words_2 limit {$begin}, 20";
    $rs = $DB->fetch_arrays($sql);
    if ($rs && is_array($rs) && count($rs) > 0) {
        foreach ($rs as $key => $val) {
            $words[$val['id']]['word'] = dealwith_kw($val['word']);
            $words[$val['id']]['points'] = 0;
            $words[$val['id']]['dig'] = 0;
        }
    }
    return array('word' => array_shuffle($words), 'total_points' => $total_points);
}