Example #1
0
 public function __construct($template, $vars = array())
 {
     // base path
     $base = PATH . 'themes' . DS . Config::meta('theme') . DS;
     // custom article and page templates
     if ($template == 'page' or $template == 'article') {
         if ($item = Registry::get($template)) {
             if (is_readable($base . $template . '-' . $item->slug . EXT)) {
                 $template .= '-' . $item->slug;
             } elseif (is_readable($base . $template . 's/' . $template . '-' . $item->slug . EXT)) {
                 $template .= 's/' . $template . '-' . $item->slug;
             } elseif (is_readable($base . $item->pagetype . EXT)) {
                 $template = $item->pagetype;
                 if (is_readable($base . $item->pagetype . '-' . $item->slug . EXT)) {
                     $template .= '-' . $item->slug;
                 }
             }
         }
     }
     if ($template == 'posts') {
         if ($item = Registry::get('post_category')) {
             if (is_readable($base . 'category-' . $item->slug . EXT)) {
                 $template = 'category';
                 $template .= '-' . $item->slug;
             }
         }
     }
     $this->path = $base . $template . EXT;
     $this->vars = array_merge($this->vars, $vars);
 }
Example #2
0
 public static function format($date, $format = null)
 {
     // set the meta format
     if (is_null($format)) {
         $format = Config::meta('date_format', 'jS F, Y');
     }
     $date = new DateTime($date, new DateTimeZone('GMT'));
     $date->setTimezone(new DateTimeZone(Config::app('timezone')));
     return $date->format($format);
 }
Example #3
0
function page_description($default = '')
{
    if ($title = Registry::prop('article', 'description')) {
        return $title;
    }
    if ($title = Config::meta('description')) {
        return $title;
    }
    return $default;
}
Example #4
0
 public static function version()
 {
     // first time
     if (!($last = Config::meta('last_update_check'))) {
         $last = static::setup();
     }
     // was update in the last 30 days
     if (strtotime($last) < time() - 60 * 60 * 24 * 30) {
         static::renew();
     }
 }
Example #5
0
 public static function migrations()
 {
     $current = Config::meta('current_migration');
     $migrate_to = Config::migrations('current');
     $migrations = new Migrations($current);
     $table = Base::table('meta');
     if (is_null($current)) {
         $number = $migrations->up($migrate_to);
         Query::table($table)->insert(array('key' => 'current_migration', 'value' => $number));
     } else {
         if ($current < $migrate_to) {
             $number = $migrations->up($migrate_to);
             Query::table($table)->where('key', '=', 'current_migration')->update(array('value' => $number));
         }
     }
 }
function search_next($text = 'Next', $default = '')
{
    $per_page = Config::meta('posts_per_page');
    $page = Registry::get('page_offset');
    $offset = ($page - 1) * $per_page;
    $total = Registry::get('total_posts');
    $pages = floor($total / $per_page);
    $search_page = Registry::get('page');
    $next = $page + 1;
    $term = Registry::get('search_term');
    Session::put(slug($term), $term);
    $url = base_url($search_page->slug . '/' . $term . '/' . $next);
    if ($page - 1 < $pages) {
        return '<a href="' . $url . '">' . $text . '</a>';
    }
    return $default;
}
Example #7
0
function search_prev($text = 'Previous', $default = '')
{
    $per_page = Config::meta('posts_per_page');
    $page = Registry::get('page_offset');
    $offset = ($page - 1) * $per_page;
    $total = Registry::get('total_posts');
    $pages = ceil($total / $per_page);
    $search_page = Registry::get('page');
    $prev = $page - 1;
    $term = Registry::get('search_term');
    Session::put(slug($term), $term);
    $url = base_url($search_page->slug . '/' . $term . '/' . $prev);
    if ($offset > 0) {
        return '<a href="' . $url . '">' . $text . '</a>';
    }
    return $default;
}
Example #8
0
function parse($str, $markdown = true)
{
    // process tags
    $pattern = '/[\\{\\{]{1}([a-z]+)[\\}\\}]{1}/i';
    if (preg_match_all($pattern, $str, $matches)) {
        list($search, $replace) = $matches;
        foreach ($replace as $index => $key) {
            $replace[$index] = Config::meta($key);
        }
        $str = str_replace($search, $replace, $str);
    }
    $str = html_entity_decode($str, ENT_NOQUOTES, System\Config::app('encoding'));
    //  Parse Markdown as well?
    if ($markdown === true) {
        $md = new Parsedown();
        $str = $md->text($str);
    }
    return $str;
}
Example #9
0
 public static function perPage()
 {
     return Config::meta('show_all_posts') ? self::count() + 1 : Config::meta('posts_per_page');
 }
function posts_per_page()
{
    return min(Registry::get('total_posts'), Config::meta('posts_per_page'));
}
Example #11
0
        </hgroup>
        <hgroup class="wrap"><h1>Fran├žais</h1></hgroup>
        <ul class="main list">
            <?php 
$introParts = ['custom_address1', 'custom_address2', 'custom_mail', 'custom_telnumber'];
foreach ($introParts as $part) {
    echo "<li>" . "<a href='" . Uri::to('admin/accueil/editInfo/' . $part) . "'>" . "<strong>" . strip_tags(Config::meta($part)) . "</strong>" . "</a>" . "</li>";
}
?>
        </ul>
        <hgroup class="wrap"><h1>Anglais</h1></hgroup>
        <ul class="main list">
            <?php 
$introParts = ['custom_address1_en', 'custom_address2_en', 'custom_mail_en', 'custom_telnumber_en'];
foreach ($introParts as $part) {
    echo "<li>" . "<a href='" . Uri::to('admin/accueil/editInfo/' . $part) . "'>" . "<strong>" . strip_tags(Config::meta($part)) . "</strong>" . "</a>" . "</li>";
}
?>
        </ul>
    </section>

    <section class="wrap">
        <hgroup class="wrap">
            <h1>Votre biographie</h1>
            <nav>
                <!--            --><?php 
//echo Html::link('admin/accueil/addBio', __('accueil.create_bio'), array('class' => 'btn'));
?>
            </nav>
        </hgroup>
        <hgroup class="wrap"><h1>Fran├žais</h1></hgroup>
 public static function posts()
 {
     return static::find(Config::meta('posts_page'));
 }
Example #13
0
function site_meta($key, $default = '')
{
    return Config::meta('custom_' . $key, $default);
}
Example #14
0
function is_postspage()
{
    return Registry::prop('page', 'id') == Config::meta('posts_page');
}
function my_full_theme_url($file = '')
{
    $theme_folder = Config::meta('theme');
    $base = 'themes' . '/' . $theme_folder . '/';
    return full_url($base . ltrim($file, '/'));
}
Example #16
0
        Notify::error($errors);
        return Response::redirect('admin/reset/' . $key);
    }
    User::update($user, array('password' => Hash::make($password)));
    Session::erase('user');
    Session::erase('token');
    Notify::success(__('users.password_reset'));
    return Response::redirect('admin/login');
}));
/*
	Upgrade
*/
Route::get('admin/upgrade', function () {
    $vars['messages'] = Notify::read();
    $vars['token'] = Csrf::token();
    $version = Config::meta('update_version');
    $url = 'https://github.com/anchorcms/anchor-cms/archive/%s.zip';
    $vars['version'] = $version;
    $vars['url'] = sprintf($url, $version);
    return View::create('upgrade', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
});
/*
	List extend
*/
Route::get('admin/extend', array('before' => 'auth', 'main' => function ($page = 1) {
    $vars['messages'] = Notify::read();
    $vars['token'] = Csrf::token();
    return View::create('extend/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
}));
Route::get('admin/posts/edit/ckeditor/plugins/imageuploader/', array('before' => 'auth', 'main' => function () {
    return View::create('imageuploaded');
Example #17
0
        $input['status'] = 'spam';
    }
    $comment = Comment::create($input);
    Notify::success(__('comments.created'));
    // dont notify if we have marked as spam
    if (!$spam and Config::meta('comment_notifications')) {
        $comment->notify();
    }
    return Response::redirect($posts_page->slug . '/' . $slug . '#comment');
});
/**
 * Rss feed
 */
Route::get(array('rss', 'feeds/rss'), function () {
    $uri = 'http://' . $_SERVER['HTTP_HOST'];
    $rss = new Rss(Config::meta('sitename'), Config::meta('description'), $uri, Config::app('language'));
    $query = Post::where('status', '=', 'published')->sort(Base::table('posts.created')->take(25), 'desc');
    foreach ($query->get() as $article) {
        $rss->item($article->title, Uri::full(Registry::get('posts_page')->slug . '/' . $article->slug), $article->description, $article->created);
    }
    $xml = $rss->output();
    return Response::create($xml, 200, array('content-type' => 'application/xml'));
});
/**
 * Json feed
 */
Route::get('feeds/json', function () {
    $json = Json::encode(array('meta' => Config::get('meta'), 'posts' => Post::where('status', '=', 'published')->sort(Base::table('posts.created')->take(25), 'desc')->get()));
    return Response::create($json, 200, array('content-type' => 'application/json'));
});
/**
 * Search
 */
Route::get(array('search', 'search/(:any)', 'search/(:any)/(:num)'), function ($slug = '', $offset = 1) {
    // mock search page
    $page = new Page();
    $page->id = 0;
    $page->title = 'Search';
    $page->slug = 'search';
    // get search term
    $term = filter_var($slug, FILTER_SANITIZE_STRING);
    Session::put(slug($term), $term);
    //$term = Session::get($slug); //this was for POST only searches
    // revert double-dashes back to spaces
    $term = str_replace('--', ' ', $term);
    if ($offset > 0) {
        list($total, $posts) = Post::search($term, $offset, Config::meta('posts_per_page'));
    } else {
        return Response::create(new Template('404'), 404);
    }
    // search templating vars
    Registry::set('page', $page);
    Registry::set('page_offset', $offset);
    Registry::set('search_term', $term);
    Registry::set('search_results', new Items($posts));
    Registry::set('total_posts', $total);
    return new Template('search');
});
Route::post('search', function () {
    // search and save search ID
    $term = filter_var(Input::get('term', ''), FILTER_SANITIZE_STRING);
    // replace spaces with double-dash to pass through url
Example #19
0
     $posts = $query->sort('created', 'desc')->take($perpage)->skip(($page - 1) * $perpage)->get();
     $url = Uri::to('admin/posts/category/' . $category->slug);
     $pagination = new Paginator($posts, $total, $page, $perpage, $url);
     $vars['messages'] = Notify::read();
     $vars['posts'] = $pagination;
     $vars['category'] = $category;
     $vars['categories'] = Category::sort('title')->get();
     $vars['status'] = 'all';
     return View::create('posts/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
 });
 /*
 	List posts by status and paginate through them
 */
 Route::get(array('admin/posts/status/(:any)', 'admin/posts/status/(:any)/(:num)'), function ($status, $post = 1) {
     $query = Post::where('status', '=', $status);
     $perpage = Config::meta('posts_per_page');
     $total = $query->count();
     $posts = $query->sort('title')->take($perpage)->skip(($post - 1) * $perpage)->get();
     $url = Uri::to('admin/posts/status');
     $pagination = new Paginator($posts, $total, $post, $perpage, $url);
     $vars['messages'] = Notify::read();
     $vars['posts'] = $pagination;
     $vars['status'] = $status;
     $vars['categories'] = Category::sort('title')->get();
     return View::create('posts/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
 });
 /*
 	Edit post
 */
 Route::get('admin/posts/edit/(:num)', function ($id) {
     $vars['messages'] = Notify::read();
Example #20
0
    Route::get(array('/', $home_page->slug), function () use($home_page) {
        Registry::set('page', $home_page);
        return new Template('page');
    });
}
/**
 * Post listings page
 */
$routes = array($posts_page->slug, $posts_page->slug . '/(:num)');
if ($home_page->id == $posts_page->id) {
    array_unshift($routes, '/');
}
Route::get($routes, function ($offset = 1) use($posts_page) {
    if ($offset > 0) {
        // get public listings
        list($total, $posts) = Post::listing(null, $offset, $per_page = Config::meta('posts_per_page'));
    } else {
        return Response::create(new Template('404'), 404);
    }
    // get the last page
    $max_page = $total > $per_page ? ceil($total / $per_page) : 1;
    // stop users browsing to non existing ranges
    if ($offset > $max_page or $offset < 1) {
        return Response::create(new Template('404'), 404);
    }
    $posts = new Items($posts);
    Registry::set('posts', $posts);
    Registry::set('total_posts', $total);
    Registry::set('page', $posts_page);
    Registry::set('page_offset', $offset);
    return new Template('posts');
Example #21
0
">

		<?php 
echo Notify::read();
?>

		<header class="top">
			<div class="wrap">
				<?php 
if (Auth::user()) {
    ?>
				<nav>
					<ul>
						<li class="logo">
							<?php 
    $page = in_array(Config::meta('dashboard_page'), array('panel', 'pages', 'posts')) ? Config::meta('dashboard_page') : 'panel';
    ?>
							<a href="<?php 
    echo Uri::to('admin/' . $page);
    ?>
">Anchor CMS</a>
						</li>

						<?php 
    $menu = array('posts', 'comments', 'pages', 'categories', 'users', 'extend');
    ?>
						<?php 
    foreach ($menu as $url) {
        ?>
						<li <?php 
        if (strpos(Uri::current(), $url) !== false) {
Example #22
0
function vapor_posts_next()
{
    $total = Registry::get('total_posts');
    $offset = Registry::get('page_offset');
    $per_page = Config::meta('posts_per_page');
    $page = Registry::get('page');
    if ($offset > 1) {
        $offset = '/' . ($offset - 1);
    } else {
        $offset = '';
    }
    if ($category = Registry::get('post_category')) {
        $url = base_url('category/' . $category->slug . $offset);
    } else {
        $url = base_url($page->slug . $offset);
    }
    if ($offset != '') {
        return '<a class="older-posts" href="' . $url . '">Newer <i class="fa fa-chevron-circle-right"></i></a>';
    } else {
        return NULL;
    }
}
Example #23
0
<!doctype html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title><?php 
echo __('global.manage');
?>
 <?php 
echo Config::meta('sitename');
?>
</title>

		<script src="<?php 
echo asset('anchor/views/assets/js/zepto.js');
?>
"></script>

		<link rel="stylesheet" href="<?php 
echo asset('anchor/views/assets/css/reset.css');
?>
">
		<link rel="stylesheet" href="<?php 
echo asset('anchor/views/assets/css/admin.css');
?>
">
		<link rel="stylesheet" href="<?php 
echo asset('anchor/views/assets/css/login.css');
?>
">
		<link rel="stylesheet" href="<?php 
echo asset('anchor/views/assets/css/notifications.css');
Example #24
0
<?php

header("X-XSS-Protection: 0");
?>
<!doctype html>
<html lang="fr">
<head>
    <meta charset="utf-8">
    <?php 
echo '<title>' . __('global.manage') . " " . Config::meta('sitename') . '</title>';
addScriptTag('anchor/views/assets/js/zepto.js');
addStylesheetTag('anchor/views/assets/css/reset.css');
addStylesheetTag('anchor/views/assets/css/login.css');
addStylesheetTag('anchor/views/assets/css/notifications.css');
addStylesheetTag('anchor/views/assets/css/bootstrap-datepicker.min.css');
addStylesheetTag('anchor/views/assets/css/bootstrap.min.css');
addStylesheetTag('anchor/views/assets/css/small.css', '(max-width: 980px), (max-device-width: 480px)');
addStylesheetTag('anchor/views/assets/css/admin.css');
addStylesheetTag('anchor/views/assets/css/forms.css');
?>
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <meta name="viewport" content="width=600">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body class="<?php 
echo Auth::guest() ? 'login' : 'admin';
?>
">

<header class="top">
    <div class="wrap">