function hide_show_menu_item($id, $key, $default = '')
{
    if ($extend = Extend::field('page', $key, $id)) {
        return Extend::value($extend, $default);
    }
    return $default;
}
Exemple #2
0
function page_custom_field($key, $default = '')
{
    $id = Registry::prop('page', 'id');
    if ($extend = Extend::field('page', $key, $id)) {
        return Extend::value($extend, $default);
    }
    return $default;
}
Exemple #3
0
 public static function listing($category = null, $page = 1, $per_page = 10, $language = false)
 {
     // get total
     $query = static::left_join(Base::table('users'), Base::table('users.id'), '=', Base::table('posts.author'))->where(Base::table('posts.status'), '=', 'published');
     if ($category) {
         $query->where(Base::table('posts.category'), '=', $category->id);
     }
     $total = $query->count();
     // get posts
     $posts = $query->sort(Base::table('posts.created'), 'desc')->take($per_page)->skip(--$page * $per_page)->get(array(Base::table('posts.*'), Base::table('users.id as author_id'), Base::table('users.bio as author_bio'), Base::table('users.real_name as author_name')));
     $outputPosts = array();
     if ($language !== false) {
         for ($i = 0; $i < count($posts); $i++) {
             $post_lang = Extend::value(Extend::field('post', 'targetlanguage', $posts[$i]->data["id"]));
             if ($post_lang === $language) {
                 $outputPosts[] = $posts[$i];
             }
         }
     } else {
         $outputPosts = $posts;
     }
     return array($total, $outputPosts);
 }
Exemple #4
0
     List all posts and paginate through them
 */
 Route::get(array('admin/publications', 'admin/publications/(:num)'), function ($page = 1) {
     $currentPageCategoryId = getCurrentPageCategoryId('publication');
     $perpage = Config::meta('posts_per_page');
     $total = Post::where('category', '=', $currentPageCategoryId)->count();
     $posts = Post::where('category', '=', $currentPageCategoryId)->sort('created', 'desc')->take($perpage)->skip(($page - 1) * $perpage)->get();
     $url = Uri::to('admin/publications');
     //Doing something
     //Adding extend fields for each posts
     for ($i = 0; $i < count($posts); $i++) {
         $posts[$i]->typeofpublication = Extend::value(Extend::field('post', 'typeofpublication', $posts[$i]->id));
         $posts[$i]->bookimage = Extend::value(Extend::field('post', 'bookimage', $posts[$i]->id));
         $posts[$i]->externallink = Extend::value(Extend::field('post', 'externallink', $posts[$i]->id));
         $posts[$i]->customdate = Extend::value(Extend::field('post', 'customdate', $posts[$i]->id));
         $posts[$i]->publicofpublication = Extend::value(Extend::field('post', 'publicofpublication', $posts[$i]->id));
     }
     $pagination = new Paginator($posts, $total, $page, $perpage, $url);
     $vars['messages'] = Notify::read();
     $vars['posts'] = $pagination;
     $vars['categories'] = Category::sort('title')->get();
     return View::create('publications/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
 });
 /*
     Add new book
 */
 Route::get('admin/publications/addBook', function () {
     $vars['messages'] = Notify::read();
     $vars['token'] = Csrf::token();
     $vars['page'] = Registry::get('posts_page');
     // extended fields
Exemple #5
0
     $vars['messages'] = Notify::read();
     $vars['token'] = Csrf::token();
     $vars['page'] = Registry::get('posts_page');
     $biopage = Page::slug('biographie');
     $vars['biopage'] = $biopage;
     // extended fields
     $vars['fields'] = Extend::fields('post');
     $vars['page_fields'] = array();
     $vars['page_fields']['bioimage_en'] = Extend::field('page', 'bioimage_en', $biopage->id);
     $vars['page_fields']['biofirstpart_en'] = Extend::field('page', 'biofirstpart_en', $biopage->id);
     $vars['page_fields']['biosecondpart_en'] = Extend::field('page', 'biosecondpart_en', $biopage->id);
     $vars['page_fields']['biothirdpart_en'] = Extend::field('page', 'biothirdpart_en', $biopage->id);
     $vars['page_fields']['bioimage'] = Extend::field('page', 'bioimage', $biopage->id);
     $vars['page_fields']['biofirstpart'] = Extend::field('page', 'biofirstpart', $biopage->id);
     $vars['page_fields']['biosecondpart'] = Extend::field('page', 'biosecondpart', $biopage->id);
     $vars['page_fields']['biothirdpart'] = Extend::field('page', 'biothirdpart', $biopage->id);
     $vars['statuses'] = array('published' => __('global.published'), 'draft' => __('global.draft'), 'archived' => __('global.archived'));
     $vars['categories'] = Category::dropdown();
     return View::create('accueil/editBio_en', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
 });
 Route::post(array('admin/accueil/editBio'), function () {
     $page = Page::slug('biographie');
     Extend::process('page', $page->id);
     Notify::success(__('accueil.updated_bio'));
     return Response::redirect('admin/accueil');
 });
 Route::post(array('admin/accueil/editBio_en'), function () {
     $page = Page::slug('biographie');
     Extend::process('page', $page->id);
     Notify::success(__('accueil.updated_bio'));
     return Response::redirect('admin/accueil');
Exemple #6
0
 /*
     List all posts and paginate through them
 */
 Route::get(array('admin/dossiers', 'admin/dossiers/(:num)', 'admin/dossiers/(:num)/(:any)'), function ($page = 1, $lang = 'all') {
     $lang = $lang == 'fr' || $lang == 'en' || ($lang = 'all') ? $lang : 'all';
     $currentPageCategoryId = getCurrentPageCategoryId('dossier');
     $url = Uri::to('admin/dossiers');
     $perpage = Config::meta('posts_per_page');
     $allPosts = Post::where('category', '=', $currentPageCategoryId)->sort('created', 'asc')->get();
     $allPostsSelectedLanguage = [];
     $curPagePosts = [];
     $indexFirstOk = ($page - 1) * $perpage;
     $indexLastOk = $indexFirstOk + $perpage;
     for ($i = 0; $i < count($allPosts); $i++) {
         //Getting all posts for selected language
         $allPosts[$i]->targetlanguage = Extend::value(Extend::field('post', 'targetlanguage', $allPosts[$i]->id));
         if ($lang == 'all' || $allPosts[$i]->targetlanguage == $lang) {
             $allPostsSelectedLanguage[] = $allPosts[$i];
         }
     }
     $i = $indexFirstOk;
     while ($i < count($allPostsSelectedLanguage) && $i < $indexLastOk) {
         //Getting all posts for current page
         $curPagePosts[] = $allPostsSelectedLanguage[$i];
         $i++;
     }
     $pagination = new Paginator($curPagePosts, count($allPostsSelectedLanguage), $page, $perpage, $url, $lang);
     $vars['messages'] = Notify::read();
     $vars['posts'] = $pagination;
     $vars['categories'] = Category::sort('title')->get();
     $vars['choosenlanguage'] = $lang;
Exemple #7
0
    Registry::set('currentPageNumber', $pageNumber);
    return new Template('page');
});
/**
 * Blog Page
 */
Route::get(array('blog', 'blog/(:any)'), function ($pageNumber = 1) {
    $page = Page::slug('blog');
    $category = Category::slug('blog');
    $per_page = Config::meta('posts_per_page');
    list($total, $posts) = Post::listing($category, $pageNumber, $per_page);
    //     get the last page
    $max_page = $total > $per_page ? ceil($total / $per_page) : 1;
    for ($i = 0; $i < count($posts); $i++) {
        $postId = $posts[$i]->data["id"];
        $posts[$i]->data['lang'] = Extend::value(Extend::field('post', 'targetlanguage', $postId));
    }
    // stop users browsing to non existing ranges
    if ($pageNumber > $max_page or $pageNumber < 1) {
        return Response::create(new Template('404'), 404);
    }
    Registry::set('posts', $posts);
    Registry::set('page', $page);
    Registry::set('category', $category);
    Registry::set('total_posts', $total);
    Registry::set('maxPageNumber', $max_page);
    Registry::set('currentPageNumber', $pageNumber);
    return new Template('page');
});
Route::get('upload/numpy', function () {
    return new Template('upload/send');
Exemple #8
0
/**
 * Get a custom field value
 *
 * @param  string
 * @param  string
 * @return string
 */
function article_custom_field($key, $default = '', $id = null)
{
    if ($id == null) {
        $id = Registry::prop('article', 'id');
    }
    if ($extend = Extend::field('post', $key, $id)) {
        return Extend::value($extend, $default);
    }
    return $default;
}