Пример #1
0
/**
 * Updates feed.rss with the $lim most recent posts
 *
 * @param  int     $lim   Max number to include
 * @param  string  $name  Name of file output
 * @return void
 */
function update_rss($lim = 10, $name = 'feed.rss')
{
    if (!is_int($lim)) {
        $lim = 10;
    }
    $pdo = \shgysk8zer0\Core\PDO::load('connect');
    if ($pdo->connected) {
        $url = \shgysk8zer0\Core\URL::load(URL);
        $rss = new \shgysk8zer0\DOM\XML('rss', null, '1.0', 'UTF-8');
        $head = $pdo->nameValue('head');
        $posts = $pdo->fetchArray("SELECT `title`, `url`, `description`, `created`\n\t\t\tFROM `posts`\n\t\t\tWHERE `url` != ''\n\t\t\tORDER BY `created` DESC\n\t\t\tLIMIT {$lim};");
        $posts = new \shgysk8zer0\Core\ArrayObject($posts);
        $rss->documentElement->version = '2.0';
        $channel = $rss->documentElement->append('channel');
        $site = array('title' => htmlspecialchars($head->title, ENT_XML1, $rss->encoding), 'description' => htmlspecialchars($head->description, ENT_XML1, $rss->encoding), 'link' => URL, 'lastBuildDate' => date(DATE_RSS), 'laneguage' => 'en-us');
        array_map([$channel, 'append'], array_keys($site), array_values($site));
        $posts->reduce(function (\DOMElement $feed, \stdClass $post) use($url) {
            $item = $feed->append('item');
            $item->append('title', htmlspecialchars($post->title, ENT_XML1, $feed->ownerDocument->encoding));
            $item->append('link', "{$url}posts/{$post->url}");
            $item->append('description', htmlspecialchars($post->description, ENT_XML1, $feed->ownerDocument->encoding));
            $item->append('pubDate', date(DATE_RSS, strtotime($post->created)));
            $item->append('guid', "{$url}posts/{$post->url}");
            return $feed;
        }, $rss->documentElement);
        $rss->save(BASE . DIRECTORY_SEPARATOR . $name);
    }
}
Пример #2
0
    header('Content-Type: text/plain');
    http_response_code(500);
    exit('PHP version ' . getenv('MIN_PHP_VERSION') . ' or greater is required');
}
define('BASE', __DIR__);
if (PHP_SAPI === 'cli') {
    require_once __DIR__ . DIRECTORY_SEPARATOR . 'std-php-functions' . DIRECTORY_SEPARATOR . 'autoloader.php';
}
init();
if (!defined('THEME')) {
    define('THEME', 'default-theme');
}
define_UA();
set_exception_handler(new \shgysk8zer0\Core\ExceptionLog());
$redirect = false;
$URL = \shgysk8zer0\Core\URL::load();
$headers = \shgysk8zer0\Core\Headers::load();
if ($URL->host === 'localhost' and BROWSER === 'Chrome') {
    $URL->host = '127.0.0.1';
    $redirect = true;
} elseif (substr($URL->host, 0, 4) === 'www.') {
    $URL->host = substr($URL->host, 4);
    $redirect = true;
} elseif (array_key_exists('tags', $_REQUEST)) {
    $URL->path .= 'tags/' . urlencode($_REQUEST['tags']);
    $redirect = true;
}
if ($redirect) {
    unset($URL->user, $URL->pass, $URL->query, $URL->fragment);
    http_response_code(301);
    $headers->Location = "{$URL}";