Example #1
0
    }
    $cache_dir = CACHE_DIR . DIRECTORY_SEPARATOR . 'github_repo';
    try_mkdir($cache_dir);
    Hook::AddHook(Hook::FIND_POST_LIST, function (&$list) use($setting, $cache_dir) {
        $files = array();
        if (isset($setting['repos'])) {
            foreach ($setting['repos'] as $repostring) {
                $repo = new Repo($repostring);
                $helper = new RepoHelper($repo);
                $helper->setFileCacheDir($cache_dir);
                try {
                    $tree = $helper->getTreeInPath();
                    $tree = array_filter($tree, function ($item) {
                        return $item['type'] === 'blob' && ParserFactory::CanParse($item['path']);
                    });
                    $files = array_merge($files, $helper->getAllLocalBlob($tree));
                } catch (GitHubException $ex) {
                    throw $ex;
                }
            }
        }
        $list = array_merge($list, $files);
        // 删除其余文件
        $all = glob($cache_dir . DIRECTORY_SEPARATOR . '*');
        $remove = array_diff($all, $files);
        array_walk($remove, function ($fn) {
            unlink($fn);
        });
        //var_dump($files,$all,$remove);
    });
});
Example #2
0
<?php

use FeedWriter\Atom;
use FeedWriter\RSS2;
Hook::AddHook(Hook::RESOLVE_REQUEST, 'rssOratomAction');
Hook::AddHook(Hook::RESOLVE_POST, 'basic_post_resolver');
Hook::AddHook(Hook::FIND_POST_LIST, 'posts_in_post_dir');
Hook::AddHook(Hook::RESOLVE_REQUEST, 'update_action');
Hook::AddHook(Hook::GENERATE_HEADER, 'generate_default_header');
Hook::AddHook(Hook::GENERATE_HEADER, 'generate_default_footer');
/**
 * @param Request $request
 */
function rssOratomAction($request)
{
    if (false == $request->isAction()) {
        return;
    }
    $action = $request->getAction();
    if (false == ($action == 'rss' || $action == 'atom')) {
        return;
    }
    global $config, $postHelper;
    $action == 'rss' ? $feed = new RSS2() : ($feed = new Atom());
    $feed->setTitle(BLOG_TITLE);
    $feed->setLink(BLOG_URL);
    $feed->setEncoding('utf-8');
    if ($action == 'rss') {
        $feed->setDescription($config['meta_description']);
        $feed->setChannelElement('language', $config['language']);
        $feed->setChannelElement('pubDate', date(DATE_RSS, time()));
Example #3
0
<?php

namespace github_helper;

include_once __DIR__ . '/github_helper.php';
\Hook::AddHook(\Hook::BOOTSTRAP, function () {
    global $config;
    //  可能不存在,抑制该错误
    $setting = @$config[\Config::NS_PLUGINS][__NAMESPACE__];
    if (is_null($setting)) {
        $setting['auth'] = '';
        $config->addDefault(__NAMESPACE__, $setting, <<<EOT
github_helper 辅助插件:
设置:
\tauth 作为访问 github 的授权,使用 BasicAuth
\t\t 格式为 username:password

repo格式为 user/repo[:branch][/path][;auth=username:password][;readmeonly]
EOT
, \Config::NS_PLUGINS);
    }
});