コード例 #1
0
function breadcrumbs($query)
{
    global $_PATH;
    global $_CONFIG;
    $_q = explode('/', $query);
    $_c = [];
    // Helper array
    $_crumbs = ['<a href="' . $_PATH['url'] . '">' . $_CONFIG['title'] . '</a>'];
    foreach ($_q as $_i) {
        if (!empty($_i)) {
            $_c[] = $_i;
            // Get the file where the title is
            $_ci = $_PATH['content'] . implode('/', $_c);
            $_ci .= is_dir($_ci) ? '/index.md' : '.md';
            // Get the title
            $_ci_contents = extract_content($_ci);
            $_ci_name = ucfirst(str_replace('-', ' ', $_i));
            // Default based on filename
            $_ci_name = !empty($_ci_contents['metadata']['title']) ? $_ci_contents['metadata']['title'] : $_ci_name;
            unset($_ci_contents);
            // Create the link
            $_ci_link = str_replace($_PATH['content'], '', $_ci);
            $_ci_link = $_PATH['url'] . str_replace('.md', '', $_ci_link);
            if (substr($_ci_link, -5) == 'index') {
                $_ci_link = substr($_ci_link, 0, -5);
            } else {
                $_ci_link .= PHP_SAPI == "cli" ? '.html' : '';
            }
            // Add it
            $_crumbs[] = '<a href="' . $_ci_link . '">' . $_ci_name . '</a>';
        }
    }
    return $_crumbs;
}
コード例 #2
0
ファイル: functions.php プロジェクト: Levikov/weixiguang
function extract_li($contents, &$array, &$id, $start_index, $start_offset, $end_index, $end_offset)
{
    while (strpos($contents, "<li>") != null) {
        $link = extract_content($contents, "jobsHtml", 9, "html", -1);
        $title = extract_content($contents, "title", 7, ">", -1);
        array_push($array, $title);
        array_push($id, $link);
        $contents = substr($contents, strpos($contents, "</li>") + 5);
    }
}
コード例 #3
0
function load_data($lemmata)
{
    if (!empty($lemmata['lemmata'])) {
        $lemmata = $lemmata['lemmata'];
        $lemmata = str_replace(["\r\n", "\r", "\n"], "\n", $lemmata);
        $lemmata = explode("\n", $lemmata);
        $lemmata = array_map('trim', $lemmata);
        $lemmata = array_map('urlencode', $lemmata);
        foreach ($lemmata as $lemma) {
            $html = get_content($lemma);
            if (false !== $html) {
                echo extract_content($html);
                flush();
            }
        }
    }
}
コード例 #4
0
ファイル: update_list.php プロジェクト: Levikov/weixiguang
function update_zhaopin()
{
    include "functions.php";
    require "db.php";
    $sqlschool = mysql_query("select * from job_config", $dbh);
    while ($rowschool = mysql_fetch_array($sqlschool)) {
        $school = $rowschool["src"];
        $sqlconfig = mysql_query("select * from job_config where src='" . $school . "'", $dbh);
        $sqlconfigRs = mysql_fetch_assoc($sqlconfig);
        $contents = file_get_contents($sqlconfigRs["list"]);
        if ($sqlconfigRs["encode"] == "GB2312") {
            $contents = iconv("gb2312", "utf-8//IGNORE", $contents);
        }
        $contents = extract_content($contents, $sqlconfigRs["li_start_index"], $sqlconfigRs["li_start_offset"], $sqlconfigRs["li_end_index"], $sqlconfigRs["li_end_offset"]);
        $a = array();
        $b = array();
        $c = array();
        while (!(strpos($contents, $sqlconfigRs["item_start_index"]) === false)) {
            $contents = substr($contents, strpos($contents, $sqlconfigRs["item_start_index"]) + $sqlconfigRs["item_start_offset"]);
            $date = extract_content($contents, $sqlconfigRs["date_start_index"], $sqlconfigRs["date_start_offset"], $sqlconfigRs["date_end_index"], $sqlconfigRs["date_end_offset"]);
            $link = extract_content($contents, $sqlconfigRs["url_start_index"], $sqlconfigRs["url_start_offset"], $sqlconfigRs["url_end_index"], $sqlconfigRs["url_end_offset"]);
            $title = extract_content($contents, $sqlconfigRs["title_start_index"], $sqlconfigRs["title_start_offset"], $sqlconfigRs["title_end_index"], $sqlconfigRs["title_end_offset"]);
            $title = trim($title);
            array_push($a, $title);
            array_push($b, $link);
            array_push($c, $date);
        }
        $max = 0;
        for ($i = 0; $i < count($a); $i++) {
            if ((int) $sqlconfigRs["topid"] < (int) $b[$i]) {
                mysql_query("insert into job_news (title,src,id,date) VALUES('" . $a[$i] . "','" . $school . "','" . $b[$i] . "','" . $c[$i] . "')", $dbh);
            }
            if ($max < (int) $b[$i]) {
                $max = (int) $b[$i];
            }
        }
        mysql_query("update job_config set topid={$max} where src='" . $school . "'", $dbh);
    }
}
コード例 #5
0
ファイル: index.php プロジェクト: alterebro/mosquito
$_PATH = array('path' => PHP_SAPI == "cli" ? $_CONFIG['dist_url'] : dirname($_SERVER['PHP_SELF']) . (dirname($_SERVER['PHP_SELF']) == '/' ? '' : '/'), 'url' => PHP_SAPI == "cli" ? $_CONFIG['dist_url'] : 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . (dirname($_SERVER['PHP_SELF']) == '/' ? '' : '/'), 'root' => DIRECTORY_SEPARATOR . get_absolute_path(dirname(__FILE__)) . DIRECTORY_SEPARATOR, 'content' => DIRECTORY_SEPARATOR . get_absolute_path(dirname(__FILE__)) . DIRECTORY_SEPARATOR . $_CONFIG['content_folder']);
$_DATA = array('site' => $_CONFIG, 'path' => $_PATH, 'file' => $_PATH['content'] . 'index' . $_CONFIG['file_extension'], 'content' => '', 'is_404' => false, 'metadata' => ['title' => false, 'description' => false, 'image' => false, 'tags' => false, 'layout' => 'index', 'timestamp' => false, 'url' => false]);
$_default_metadata = $_DATA['metadata'];
// Get the Query URL Parameter.
$_QUERY = !empty($_GET['q']) ? $_GET['q'] : '';
$_QUERY = trim($_QUERY, '/');
// _file
// -------------------
$_DATA['file'] = is_dir($_PATH['content'] . $_QUERY) ? '/' . trim($_PATH['content'] . $_QUERY, '/') . '/index' . $_CONFIG['file_extension'] : '/' . trim($_PATH['content'], '/') . '/' . $_QUERY . $_CONFIG['file_extension'];
// _is_404
// -------------------
$_DATA['is_404'] = file_exists($_DATA['file']) ? false : true;
// _extract_content
// -------------------
$file_to_extract = file_exists($_DATA['file']) ? $_DATA['file'] : $_PATH['content'] . '404' . $_CONFIG['file_extension'];
$c = extract_content($file_to_extract);
$_DATA['metadata'] = array_merge($_default_metadata, $c['metadata']);
$_DATA['metadata']['url'] = $_PATH['url'] . $_QUERY;
$_DATA['content'] = $c['content'];
// _render
// -------------------
function render_template($template, $data, $minify = false, $render = true)
{
    $output = new div($template, $data);
    if ($minify) {
        $output = preg_replace('/(?>[^\\S ]\\s*|\\s{2,})(?=(?:(?:[^<]++|<(?!\\/?(?:textarea|pre)\\b))*+)
        (?:<(?>textarea|pre)\\b|\\z))/ix', '', $output);
    }
    if (!$render) {
        return $output;
    }
コード例 #6
0
function build($data)
{
    print "\n";
    print " ----------- ";
    print "\n";
    print ' - mosquito msg : init building ' . "\n";
    $target_folder = $data['path']['root'] . $data['site']['dist_folder'];
    // If already exists, remove all to create a clean generated site.
    if (is_dir($target_folder)) {
        print ' - Removing existing content on distributable folder' . "\n";
        recursive_remove_dir($target_folder);
        print ' - Existing content on distributable folder erased from existence' . "\n";
    }
    // Create the distributable folder
    if (!is_dir($target_folder)) {
        print ' - Creating distributable folder content...' . "\n";
        mkdir($target_folder, 0755, true);
    }
    // Copy theme and media folders
    recurse_copy($data['path']['root'] . 'theme', $target_folder . 'theme', ['DS_store', 'html', 'less']);
    recurse_copy($data['path']['root'] . 'media', $target_folder . 'media');
    $content_iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($data['path']['content'], RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD);
    $_files = [];
    foreach ($content_iterator as $content_item) {
        // Files
        if ($content_item->isFile() && $content_item->getBasename('.md') != $content_item->getFilename()) {
            $_files[] = ['source' => $content_item->getPathname(), 'target' => dirname(str_replace($data['site']['content_folder'], $data['site']['dist_folder'], $content_item->getPathname())) . DIRECTORY_SEPARATOR . $content_item->getBasename('.md') . $data['site']['dist_extension']];
        }
        // Folders
        if ($content_item->isDir()) {
            $dest_dir = str_replace($data['site']['content_folder'], $data['site']['dist_folder'], $content_item) . DIRECTORY_SEPARATOR;
            if (!is_dir($dest_dir)) {
                mkdir($dest_dir, 0755, true);
            }
        }
    }
    $the_md = $data['metadata'];
    // The Loop
    foreach ($_files as $render_file) {
        $c = extract_content($render_file['source']);
        $data['metadata'] = array_merge($the_md, $c['metadata']);
        $data['content'] = $c['content'];
        // Construct Query if needed for breadcrumbs
        if ($data['site']['use_breadcrumbs']) {
            $_q = str_replace($data['path']['content'], '', $render_file['source']);
            $_q = str_replace('.md', '', $_q);
            $_q = str_replace('/index', '', $_q);
            $_q = $_q == 'index' ? '' : $_q;
            $data['breadcrumbs'] = implode(' / ', breadcrumbs($_q));
        }
        $output = render_template('theme/' . $data['site']['theme'] . '/' . $data['metadata']['layout'] . '.html', $data, $data['site']['minify_output'], false);
        file_put_contents($render_file['target'], $output);
        print ' - File created : ' . $render_file['target'] . "\n";
    }
    print ' - mosquito msg : site built! ' . "\n";
    print " ----------- " . "\n";
    print ' - Your site can now be reached at : ' . $data['site']['dist_url'] . "\n";
    print " ----------- " . "\n";
    print "\n";
}