Exemple #1
0
$lang = $data['lang'];
$posts = $data['posts'];
$collection = $data['collection'];
if ($lang) {
    $temp = $posts;
    $posts = [];
    foreach ($temp as $item) {
        $post = array();
        foreach ($item as $prop => $value) {
            //echo $prop . '_' . $lang .'   /   ';
            $propNoLang = explode('_', $prop)[0];
            if (isset($item[$prop . '_' . $lang]) && $item[$prop . '_' . $lang] != '') {
                $post[$prop] = $item[$prop . '_' . $lang];
            } else {
                if (!isset($post[$propNoLang])) {
                    $post[$prop] = $value;
                }
            }
            if (isset($post[$prop]) && preg_match('/site:|src="/', $post[$prop])) {
                $post[$prop] = replaceSrcAttributes($post[$prop], UPLOADS . '/');
            }
        }
        $post['path'] = $lang . '/' . strtolower($collection) . '/' . stringToNiceUrl($post['title']);
        setlocale(LC_TIME, $lang . "_" . strtoupper($lang));
        $date = explode(' ', strftime("%d %b %Y", $post['created']));
        $post['date'] = (object) array('day' => $date[0], 'month' => $date[1], 'year' => $date[2], 'formatted' => strftime("%d %b %Y", $post['created']));
        array_push($posts, $post);
    }
}
echo json_encode($posts, true);
Exemple #2
0
//include cockpit
require '../vendor/autoload.php';
require '../config.php';
require '../manage/bootstrap.php';
require 'utils/Utils.php';
// ------------------------------------------------o Create App
$app = new \Slim\Slim(array('templates.path' => 'views/'));
$app->get('(/)(/:params+)', function ($params = array()) use($app) {
    if (MULTILINGUAL == true) {
        $lang = array_shift($params);
    }
    $collection = ucfirst(array_shift($params));
    $view = 'index';
    $posts = collection('Blog')->find(['public' => true])->toArray();
    if (count($params) >= 1) {
        $path = $params[0];
        $view = 'article';
        $currentPost = array();
        foreach ($posts as $post) {
            $title = $post['title_' . $lang] != '' ? $post['title_' . $lang] : $post['title'];
            if ($path == stringToNiceUrl($title)) {
                $currentPost = $post;
                break;
            }
        }
        $app->render('article.php', array('post' => $currentPost, 'lang' => $lang, 'collection' => $collection));
    } else {
        $app->render('index.php', array('posts' => $posts, 'lang' => $lang, 'collection' => $collection));
    }
});
$app->run();