示例#1
0
文件: main.php 项目: joyqi/logecho
            $date = $metas['date'];
            $list[$file] = $date;
        }
        asort($list);
        $index = 1;
        foreach ($list as $file => $date) {
            $info = pathinfo($file);
            $fileName = $info['filename'];
            $dir = $info['dirname'];
            if (preg_match("/^[0-9]{4}\\.(.+)\$/", $fileName, $matches)) {
                $fileName = $matches[1];
            }
            $source = realpath($file);
            $target = rtrim($dir, '/') . '/' . str_pad($index, 4, '0', STR_PAD_LEFT) . '.' . $fileName . '.md';
            if ($source != $target && !file_exists($target)) {
                le_console('info', basename($source) . ' => ' . basename($target));
                rename($source, $target);
            }
            $index++;
        }
    }
});
// watch
le_add_workflow('watch', function () use($context) {
    $lastSum = '';
    while (true) {
        // get sources
        $sources = ["\\/_theme\\/", "\\/_public\\/"];
        $sum = '';
        foreach ($context->config['blocks'] as $type => $block) {
            if (!isset($block['source']) || !is_string($block['source'])) {
示例#2
0
/**
 * @param $name
 * @return mixed
 */
function le_do_workflow($name)
{
    global $workflow, $context;
    $args = func_get_args();
    array_shift($args);
    $parts = explode('.', $name, 2);
    if (2 == count($parts)) {
        list($ns) = $parts;
    } else {
        $ns = le_get_current_namespace();
        $name = $ns . '.' . $name;
    }
    require_once __DIR__ . '/../workflow/' . $ns . '.php';
    if (!isset($workflow[$name])) {
        le_fatal('can not find workflow "%s"', $name);
    }
    $desc = implode(', ', array_map(function ($arg) {
        return is_string($arg) ? mb_strimwidth(str_replace(["\r", "\n"], '', $arg), 0, 10, '...', 'UTF-8') : '...';
    }, $args));
    le_console('debug', '%s%s', $name, empty($desc) ? '' : ': ' . $desc);
    return call_user_func_array($workflow[$name], $args);
}
示例#3
0
文件: compile.php 项目: joyqi/logecho
    file_put_contents($file, $html);
});
// compile post
le_add_workflow('compile_post', function ($type, $specific = NULL) use($context) {
    $block = $context->config['blocks'][$type];
    if (!isset($block['source']) || !is_string($block['source']) || empty($block['target'])) {
        le_fatal('block is not exists "%s"', $type);
    }
    $files = glob($context->dir . $block['source'] . '/*.md');
    $template = $type . '.twig';
    $target = $block['target'] . '/';
    if (isset($block['template'])) {
        $template = $block['template'];
    }
    foreach ($files as $file) {
        le_console('info', 'compile %s', preg_replace("/\\/+/", '/', $file));
        $key = pathinfo($file, PATHINFO_FILENAME);
        if (!empty($specific) && $key != $specific) {
            continue;
        }
        $post = array_merge(le_do_workflow('get_post', $type, $key), le_do_workflow('get_post_context', $type, $key));
        $currentTemplate = isset($post['template']) ? $post['template'] : $template;
        // add sitemap
        $context->sitemap[$post['url']] = 0.64;
        le_do_workflow('build', $currentTemplate, $target . $post['slug'] . '.' . $post['ext'], [$type => $post]);
    }
});
// compile posts
le_add_workflow('compile_posts', function () use($context) {
    foreach ($context->config['blocks'] as $type => $val) {
        if (isset($val['source']) && is_string($val['source'])) {
示例#4
0
文件: import.php 项目: joyqi/logecho
                    foreach ($comments as $c) {
                        if (isset($c['type']) && 'comment' != $c['type']) {
                            continue;
                        }
                        fwrite($wxr, "<item>\n    <title>{$post['title']}</title>\n    <link>" . sprintf($target, $post['wp_slug']) . "</link>\n    <dsq:thread_identifier>post:{$post['wp_slug']}</dsq:thread_identifier>\n    <wp:post_date_gmt>" . date('Y-m-d H:i:s', $post['dateCreated']->getTimestamp()) . "</wp:post_date_gmt>\n    <wp:comment_status>open</wp:comment_status>\n    <wp:comment>\n        <wp:comment_id>{$c['comment_id']}</wp:comment_id>\n        <wp:comment_author>{$c['author']}</wp:comment_author>\n        <wp:comment_author_email>{$c['author_email']}</wp:comment_author_email>\n        <wp:comment_author_url>{$c['author_url']}</wp:comment_author_url>\n        <wp:comment_author_IP>{$c['author_ip']}</wp:comment_author_IP>\n        <wp:comment_date_gmt>" . date('Y-m-d H:i:s', $c['date_created_gmt']->getTimestamp()) . "</wp:comment_date_gmt>\n        <wp:comment_content><![CDATA[{$c['content']}]]></wp:comment_content>\n        <wp:comment_approved>" . ('approve' == $c['status'] ? 1 : 0) . "</wp:comment_approved>\n        <wp:comment_parent>{$c['parent']}</wp:comment_parent>\n    </wp:comment>\n    </item>");
                    }
                    $offset += 100;
                } while (count($comments) == 100);
            }
        }
    }
    fwrite($wxr, '</channel>
</rss>');
    fclose($wxr);
    if (rename($wxrFile, $context->dir . '/wxr.xml')) {
        le_console('done', 'your comments WXR XML file has exported to %swxr.xml', $context->dir);
    }
});
// filter post
le_add_workflow('filter_post', function ($post, $categoriesConfig) {
    $text = (isset($post['description']) ? $post['description'] : '') . (isset($post['mt_text_more']) ? "\n\n<!--more-->\n\n" . $post['mt_text_more'] : '');
    $text = preg_replace("/<\\/p>\\s*<\\/p>/is", "</p>", $text);
    $text = preg_replace_callback("/<pre[^>]*><code[^>]*>(.+?)<\\/code><\\/pre>/is", function ($matches) {
        return '<pre>' . $matches[1] . '</pre>';
    }, $text);
    $text = preg_replace_callback("/<code[^>]*>(.+?)<\\/code>/is", function ($matches) {
        if (false !== strpos($matches[1], "\n")) {
            return '<pre>' . $matches[1] . '</pre>';
        }
        return '<code>' . $matches[1] . '</code>';
    }, $text);