Пример #1
0
        $sum = '';
        foreach ($context->config['blocks'] as $type => $block) {
            if (!isset($block['source']) || !is_string($block['source'])) {
                continue;
            }
            $source = trim($block['source'], '/');
            $source = empty($source) ? '/' : '/' . $source . '/';
            $sources[] = preg_quote($source, '/');
        }
        if (!empty($sources)) {
            $regex = "/^" . preg_quote(rtrim($context->dir, '/')) . "(" . implode('|', $sources) . ")/";
            $files = le_get_all_files($context->dir);
            foreach ($files as $file => $path) {
                if (!preg_match($regex, $path) || $file[0] == '.') {
                    continue;
                }
                $sum .= md5_file($path);
            }
            $sum = md5($sum . md5_file($context->dir . 'config.yaml'));
            if ($lastSum != $sum) {
                exec($context->cmd . ' build ' . $context->dir);
                $lastSum = $sum;
            }
        }
        sleep(1);
    }
});
// import
le_add_workflow('import', function () use($context) {
    le_do_workflow('import.init');
});
Пример #2
0
<?php

/**
 * index.php - logecho-main
 * 
 * @author joyqi
 */
require_once 'vendor/autoload.php';
le_do_workflow('main.run');
Пример #3
0
});
// generate sitemap
le_add_workflow('generate_sitemap', function () use($context) {
    $fp = fopen($context->dir . '_target/sitemap.xml', 'wb');
    if (!$fp) {
        le_fatal('can not write sitemap.xml');
    }
    $base = isset($context->data['url']) ? rtrim($context->data['url'], '/') : '/';
    fwrite($fp, '<?xml version="1.0" encoding="UTF-8"?>
<urlset
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">');
    foreach ($context->sitemap as $url => $priority) {
        $priority = number_format($priority, 2, '.', '');
        $url = $base . '/' . ltrim($url, '/');
        fwrite($fp, "\n    <url>\n        <loc>{$url}</loc>\n        <changefreq>daily</changefreq>\n        <priority>{$priority}</priority>\n    </url>");
    }
    fwrite($fp, '
</urlset>');
    fclose($fp);
});
// compile
le_add_workflow('compile', function () use($context) {
    le_do_workflow('compile_index');
    le_do_workflow('compile_metas');
    le_do_workflow('compile_posts');
    le_do_workflow('generate_feeds');
    le_do_workflow('generate_sitemap');
});
Пример #4
0
 if (in_array('metaWeblog.getRecentPosts', $methods)) {
     le_console('info', 'fetching posts');
     $posts = $xmlrpc->query('metaWeblog.getRecentPosts', $blogId, $username, $password, 1000);
     $source = $context->dir . $context->config['blocks']['post']['source'];
     $target = rtrim($context->config['globals']['url'], '/') . '/' . trim(isset($context->config['blocks']['post']['target']) ? $context->config['blocks']['post']['target'] : 'post', '/') . '/%s.' . (isset($context->config['blocks']['post']['ext']) ? $context->config['blocks']['post']['ext'] : 'html');
     if (!is_dir($source)) {
         if (!mkdir($source, 0755, true)) {
             le_fatal('can not make post target directory: %s', $source);
         }
     }
     foreach ($posts as $post) {
         if ('publish' != $post['post_status']) {
             continue;
         }
         le_console('info', 'add %s', $post['wp_slug']);
         $content = le_do_workflow('filter_post', $post, $context->config['blocks']['category']['source']);
         file_put_contents($source . '/' . $post['wp_slug'] . '.md', $content);
         if (in_array('wp.getComments', $methods)) {
             $offset = 0;
             le_console('info', 'fetching comments: %s', $post['postid']);
             do {
                 $comments = $xmlrpc->query('wp.getComments', $blogId, $username, $password, ['post_id' => $post['postid'], 'number' => 100, 'offset' => $offset]);
                 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);
         }