当前位置: 首页>>代码示例>>PHP>>正文


PHP Route::collection方法代码示例

本文整理汇总了PHP中Route::collection方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::collection方法的具体用法?PHP Route::collection怎么用?PHP Route::collection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Route的用法示例。


在下文中一共展示了Route::collection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: function

<?php

Route::collection(array('before' => 'auth,csrf'), function () {
    Route::get('admin/panel', function ($page = 1) {
        $vars['messages'] = Notify::read();
        $vars['token'] = Csrf::token();
        return View::create('panel', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
});
开发者ID:moje-s,项目名称:anchor-cms,代码行数:9,代码来源:panel.php

示例2: function

Route::collection(array('before' => 'auth,csrf'), function () {
    /*
    	List Pages
    */
    Route::get(array('admin/pages', 'admin/pages/(:num)'), function ($page = 1) {
        $perpage = Config::meta('posts_per_page');
        $total = Page::count();
        $pages = Page::sort('title')->take($perpage)->skip(($page - 1) * $perpage)->get();
        $url = Uri::to('admin/pages');
        $pagination = new Paginator($pages, $total, $page, $perpage, $url);
        $vars['messages'] = Notify::read();
        $vars['pages'] = $pagination;
        $vars['status'] = 'all';
        return View::create('pages/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    /*
    	List pages by status and paginate through them
    */
    Route::get(array('admin/pages/status/(:any)', 'admin/pages/status/(:any)/(:num)'), function ($status, $page = 1) {
        $query = Page::where('status', '=', $status);
        $perpage = Config::meta('posts_per_page');
        $total = $query->count();
        $pages = $query->sort('title')->take($perpage)->skip(($page - 1) * $perpage)->get();
        $url = Uri::to('admin/pages/status');
        $pagination = new Paginator($pages, $total, $page, $perpage, $url);
        $vars['messages'] = Notify::read();
        $vars['pages'] = $pagination;
        $vars['status'] = $status;
        return View::create('pages/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    /*
    	Edit Page
    */
    Route::get('admin/pages/edit/(:num)', function ($id) {
        $vars['messages'] = Notify::read();
        $vars['token'] = Csrf::token();
        $vars['page'] = Page::find($id);
        $vars['pages'] = Page::dropdown(array('exclude' => array($id), 'show_empty_option' => true));
        $vars['statuses'] = array('published' => __('global.published'), 'draft' => __('global.draft'), 'archived' => __('global.archived'));
        // extended fields
        $vars['fields'] = Extend::fields('page', $id);
        return View::create('pages/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor');
    });
    Route::post('admin/pages/edit/(:num)', function ($id) {
        $input = Input::get(array('parent', 'name', 'title', 'slug', 'content', 'status', 'redirect', 'show_in_menu'));
        // if there is no slug try and create one from the title
        if (empty($input['slug'])) {
            $input['slug'] = $input['title'];
        }
        // convert to ascii
        $input['slug'] = slug($input['slug']);
        // encode title
        $input['title'] = htmlspecialchars($input['title'], ENT_QUOTES, Config::app('encoding'), false);
        $validator = new Validator($input);
        $validator->add('duplicate', function ($str) use($id) {
            return Page::where('slug', '=', $str)->where('id', '<>', $id)->count() == 0;
        });
        $validator->check('title')->is_max(3, __('pages.title_missing'));
        $validator->check('slug')->is_max(3, __('pages.slug_missing'))->is_duplicate(__('pages.slug_duplicate'))->not_regex('#^[0-9_-]+$#', __('pages.slug_invalid'));
        if ($input['redirect']) {
            $validator->check('redirect')->is_url(__('pages.redirect_missing'));
        }
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/pages/edit/' . $id);
        }
        if (empty($input['name'])) {
            $input['name'] = $input['title'];
        }
        // encode title
        $input['title'] = e($input['title'], ENT_COMPAT);
        $input['show_in_menu'] = is_null($input['show_in_menu']) ? 0 : 1;
        Page::update($id, $input);
        Extend::process('page', $id);
        Notify::success(__('pages.updated'));
        return Response::redirect('admin/pages/edit/' . $id);
    });
    /*
    	Add Page
    */
    Route::get('admin/pages/add', function () {
        $vars['messages'] = Notify::read();
        $vars['token'] = Csrf::token();
        $vars['pages'] = Page::dropdown(array('exclude' => array(), 'show_empty_option' => true));
        $vars['statuses'] = array('published' => __('global.published'), 'draft' => __('global.draft'), 'archived' => __('global.archived'));
        // extended fields
        $vars['fields'] = Extend::fields('page');
        return View::create('pages/add', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor');
    });
    Route::post('admin/pages/add', function () {
        $input = Input::get(array('parent', 'name', 'title', 'slug', 'content', 'status', 'redirect', 'show_in_menu'));
        // if there is no slug try and create one from the title
        if (empty($input['slug'])) {
            $input['slug'] = $input['title'];
        }
        // convert to ascii
        $input['slug'] = slug($input['slug']);
        // encode title
        $input['title'] = e($input['title'], ENT_COMPAT);
//.........这里部分代码省略.........
开发者ID:gautamkrishnar,项目名称:Anchor-CMS-openshift-quickstart,代码行数:101,代码来源:pages.php

示例3: function

Route::collection(array('before' => 'auth,csrf'), function () {
    /*
    	List Comments
    */
    Route::get(array('admin/comments', 'admin/comments/(:num)'), function ($page = 1) {
        $query = Query::table(Base::table(Comment::$table));
        $perpage = Config::meta('posts_per_page');
        $count = $query->count();
        $results = $query->take($perpage)->skip(($page - 1) * $perpage)->sort('date', 'desc')->get();
        $vars['comments'] = new Paginator($results, $count, $page, $perpage, Uri::to('admin/comments'));
        $vars['messages'] = Notify::read();
        $vars['statuses'] = array(array('url' => '', 'lang' => 'global.all', 'class' => 'active'), array('url' => 'pending', 'lang' => 'global.pending', 'class' => 'pending'), array('url' => 'approved', 'lang' => 'global.approved', 'class' => 'approved'), array('url' => 'spam', 'lang' => 'global.spam', 'class' => 'spam'));
        return View::create('comments/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    /*
    	List Comments by status
    */
    Route::get(array('admin/comments/(pending|approved|spam)', 'admin/comments/(pending|approved|spam)/(:num)'), function ($status = '', $page = 1) {
        $query = Query::table(Base::table(Comment::$table));
        $perpage = Config::meta('posts_per_page');
        if (in_array($status, array('pending', 'approved', 'spam'))) {
            $query->where('status', '=', $status);
        }
        $count = $query->count();
        $results = $query->take($perpage)->skip(($page - 1) * $perpage)->sort('date', 'desc')->get();
        $vars['comments'] = new Paginator($results, $count, $page, $perpage, Uri::to('admin/comments/' . $status));
        $vars['messages'] = Notify::read();
        $vars['status'] = $status;
        $vars['statuses'] = array(array('url' => '', 'lang' => 'global.all', 'class' => ''), array('url' => 'pending', 'lang' => 'global.pending', 'class' => 'pending'), array('url' => 'approved', 'lang' => 'global.approved', 'class' => 'approved'), array('url' => 'spam', 'lang' => 'global.spam', 'class' => 'spam'));
        return View::create('comments/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    /*
    	Edit Comment
    */
    Route::get('admin/comments/edit/(:num)', function ($id) {
        $vars['messages'] = Notify::read();
        $vars['token'] = Csrf::token();
        $vars['comment'] = Comment::find($id);
        $vars['statuses'] = array('approved' => __('global.approved'), 'pending' => __('global.pending'), 'spam' => __('global.spam'));
        return View::create('comments/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    Route::post('admin/comments/edit/(:num)', function ($id) {
        $input = Input::get(array('name', 'email', 'text', 'status'));
        $validator = new Validator($input);
        $validator->check('name')->is_max(3, __('comments.name_missing'));
        $validator->check('text')->is_max(3, __('comments.text_missing'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/comments/edit/' . $id);
        }
        Comment::update($id, $input);
        Notify::success(__('comments.updated'));
        return Response::redirect('admin/comments/' . $input['status']);
    });
    /*
    	Delete Comment
    */
    Route::get('admin/comments/delete/(:num)', function ($id) {
        $comment = Comment::find($id);
        $status = $comment->status;
        $comment->delete();
        Notify::success(__('comments.deleted'));
        return Response::redirect('admin/comments/' . $status);
    });
});
开发者ID:biggtfish,项目名称:anchor-cms,代码行数:66,代码来源:comments.php

示例4: function

Route::collection(array('before' => 'auth,csrf'), function () {
    Route::get(array('admin/departments', 'admin/departments/(:num)'), function ($page = 1) {
        $vars['messages'] = Notify::read();
        $vars['departments'] = Department::paginate($page, Config::get('meta.posts_per_page'));
        return View::create('departments/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    Route::get('admin/departments/edit/(:num)', function ($id) {
        $vars['messages'] = Notify::read();
        $vars['token'] = Csrf::token();
        $vars['department'] = Department::find($id);
        $vars['fields'] = Extend::fields('department', $id);
        return View::create('departments/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    Route::post('admin/departments/edit/(:num)', function ($id) {
        $input = Input::get(array('title', 'slug', 'description'));
        $validator = new validator($input);
        $validator->check('title')->is_max(3, __('departments.title_missing'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/departments/edit/' . $id);
        }
        if (empty($input['slug'])) {
            $input['slug'] = $input['title'];
        }
        $input['slug'] = slug($input['slug']);
        department::update($id, $input);
        Extend::process('department', $id);
        Notify::successs(__('departments.update'));
        return Response::redirect('admin/departments/edit/' . $id);
    });
    Route::get('admin/departments/add', function () {
        $vars['messages'] = Notify::read();
        $vars['token'] = Csrf::token();
        $vars['fields'] = Extend::fields('department');
        return View::create('departments/add', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    Route::post('admin/departments/add', function () {
        $input = Input::get(array('title', 'slug', 'description'));
        $validator = new validator($input);
        $validator->check('title')->is_max(3, __('departments.title_missing'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/departments/add');
        }
        if (empty($input['slug'])) {
            $input['slug'] = $input['title'];
        }
        $input['slug'] = slug($input['slug']);
        $department = department::create($input);
        Extend::process('department', $department->id);
        Notify::success(__('departments.created'));
        return Response::redirect('admin/departments');
    });
    Route::get('admin/departments/delete/(:num)', function ($id) {
        $total = department::count();
        if ($total == 1) {
            Notify::error(__('departments.delete_error'));
            return Response::redirect('admin/departments/edit/' . $id);
        }
        $department = department::where('id', '<>', $id)->fetch();
        department::find($id)->delete();
        Post::where('department', '=', $id)->update(array('department' => $department->id));
        Notify::success(__('departments.deleted'));
        return Response::redirect('admin/departments');
    });
});
开发者ID:pepfi,项目名称:anchor-cms,代码行数:68,代码来源:departments.php

示例5: function

<?php

Route::collection(array('before' => 'auth,csrf,install_exists'), function () {
    /*
        List all plugins
    */
    Route::get('admin/extend/plugins', function ($page = 1) {
        $vars['token'] = Csrf::token();
        return View::create('extend/plugins/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
});
开发者ID:anchorcms,项目名称:anchor-cms,代码行数:11,代码来源:plugins.php

示例6: function

Route::collection(array('before' => 'auth,csrf,install_exists'), function () {
    /*
        List Categories
    */
    Route::get(array('admin/categories', 'admin/categories/(:num)'), function ($page = 1) {
        $vars['categories'] = Category::paginate($page, Config::get('admin.posts_per_page'));
        return View::create('categories/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    /*
        Edit Category
    */
    Route::get('admin/categories/edit/(:num)', function ($id) {
        $vars['token'] = Csrf::token();
        $vars['category'] = Category::find($id);
        // extended fields
        $vars['fields'] = Extend::fields('category', $id);
        return View::create('categories/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    Route::post('admin/categories/edit/(:num)', function ($id) {
        $input = Input::get(array('title', 'slug', 'description'));
        foreach ($input as $key => &$value) {
            $value = eq($value);
        }
        $validator = new Validator($input);
        $validator->check('title')->is_max(3, __('categories.title_missing'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/categories/edit/' . $id);
        }
        if (empty($input['slug'])) {
            $input['slug'] = $input['title'];
        }
        $input['slug'] = slug($input['slug']);
        Category::update($id, $input);
        Extend::process('category', $id);
        Notify::success(__('categories.updated'));
        return Response::redirect('admin/categories/edit/' . $id);
    });
    /*
        Add Category
    */
    Route::get('admin/categories/add', function () {
        $vars['token'] = Csrf::token();
        // extended fields
        $vars['fields'] = Extend::fields('category');
        return View::create('categories/add', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    Route::post('admin/categories/add', function () {
        $input = Input::get(array('title', 'slug', 'description'));
        foreach ($input as $key => &$value) {
            $value = eq($value);
        }
        $validator = new Validator($input);
        $validator->check('title')->is_max(3, __('categories.title_missing'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/categories/add');
        }
        if (empty($input['slug'])) {
            $input['slug'] = $input['title'];
        }
        $input['slug'] = slug($input['slug']);
        $category = Category::create($input);
        Extend::process('category', $category->id);
        Notify::success(__('categories.created'));
        return Response::redirect('admin/categories');
    });
    /*
        Delete Category
    */
    Route::get('admin/categories/delete/(:num)', function ($id) {
        $total = Category::count();
        if ($total == 1) {
            Notify::error(__('categories.delete_error'));
            return Response::redirect('admin/categories/edit/' . $id);
        }
        // move posts
        $category = Category::where('id', '<>', $id)->fetch();
        // delete selected
        Category::find($id)->delete();
        // update posts
        Post::where('category', '=', $id)->update(array('category' => $category->id));
        Notify::success(__('categories.deleted'));
        return Response::redirect('admin/categories');
    });
});
开发者ID:anchorcms,项目名称:anchor-cms,代码行数:88,代码来源:categories.php

示例7: function

Route::collection(array('before' => 'auth,csrf'), function () {
    /*
    	List all posts and paginate through them
    */
    Route::get(array('admin/posts', 'admin/posts/(:num)'), function ($page = 1) {
        $perpage = Config::meta('posts_per_page');
        $total = Post::count();
        $posts = Post::sort('created', 'desc')->take($perpage)->skip(($page - 1) * $perpage)->get();
        $url = Uri::to('admin/posts');
        $pagination = new Paginator($posts, $total, $page, $perpage, $url);
        $vars['messages'] = Notify::read();
        $vars['posts'] = $pagination;
        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();
        $vars['token'] = Csrf::token();
        $vars['article'] = Post::find($id);
        $vars['page'] = Registry::get('posts_page');
        return View::create('posts/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor');
    });
    Route::post('admin/posts/edit/(:num)', function ($id) {
        $input = Input::get(array('title', 'slug', 'description', 'created', 'html', 'css', 'js'));
        // if there is no slug try and create one from the title
        if (empty($input['slug'])) {
            $input['slug'] = $input['title'];
        }
        // convert to ascii
        $input['slug'] = slug($input['slug']);
        // encode title
        $input['title'] = e($input['title'], ENT_COMPAT);
        $validator = new Validator($input);
        $validator->add('duplicate', function ($str) use($id) {
            return Post::where('slug', '=', $str)->where('id', '<>', $id)->count() == 0;
        });
        $validator->check('title')->is_max(3, __('posts.title_missing'));
        $validator->check('slug')->is_max(3, __('posts.slug_missing'))->is_duplicate(__('posts.slug_duplicate'))->not_regex('#^[0-9_-]+$#', __('posts.slug_invalid'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/posts/edit/' . $id);
        }
        if ($input['created']) {
            $input['created'] = Date::mysql($input['created']);
        } else {
            unset($input['created']);
        }
        Post::update($id, $input);
        Notify::success(__('posts.updated'));
        return Response::redirect('admin/posts/edit/' . $id);
    });
    /*
    	Add new post
    */
    Route::get('admin/posts/add', function () {
        $vars['messages'] = Notify::read();
        $vars['token'] = Csrf::token();
        $vars['page'] = Registry::get('posts_page');
        return View::create('posts/add', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor');
    });
    Route::post('admin/posts/add', function () {
        $input = Input::get(array('title', 'slug', 'description', 'created', 'html', 'css', 'js'));
        // if there is no slug try and create one from the title
        if (empty($input['slug'])) {
            $input['slug'] = $input['title'];
        }
        // convert to ascii
        $input['slug'] = slug($input['slug']);
        // encode title
        $input['title'] = e($input['title'], ENT_COMPAT);
        $validator = new Validator($input);
        $validator->add('duplicate', function ($str) {
            return Post::where('slug', '=', $str)->count() == 0;
        });
        $validator->check('title')->is_max(3, __('posts.title_missing'));
        $validator->check('slug')->is_max(3, __('posts.slug_missing'))->is_duplicate(__('posts.slug_duplicate'))->not_regex('#^[0-9_-]+$#', __('posts.slug_invalid'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/posts/add');
        }
        if (empty($input['created'])) {
            $input['created'] = Date::mysql('now');
        }
        $user = Auth::user();
        $input['author'] = $user->id;
        if (empty($input['html'])) {
            $input['status'] = 'draft';
        }
        $post = Post::create($input);
        Notify::success(__('posts.created'));
        return Response::redirect('admin/posts');
    });
    /*
    	Preview post
    */
    Route::post('admin/posts/preview', function () {
//.........这里部分代码省略.........
开发者ID:ericluwj,项目名称:lco,代码行数:101,代码来源:posts.php

示例8: function

Route::collection(array('before' => 'auth,csrf'), function () {
    /*
    	List all posts and paginate through them
    */
    Route::get(array('admin/posts', 'admin/posts/(:num)'), function ($page = 1) {
        $perpage = Post::perPage();
        $total = Post::count();
        $posts = Post::sort('created', 'desc')->take($perpage)->skip(($page - 1) * $perpage)->get();
        $url = Uri::to('admin/posts');
        $pagination = new Paginator($posts, $total, $page, $perpage, $url);
        $vars['messages'] = Notify::read();
        $vars['posts'] = $pagination;
        $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 category and paginate through them
    */
    Route::get(array('admin/posts/category/(:any)', 'admin/posts/category/(:any)/(:num)'), function ($slug, $page = 1) {
        if (!($category = Category::slug($slug))) {
            return Response::error(404);
        }
        $query = Post::where('category', '=', $category->id);
        $perpage = Post::perPage();
        $total = $query->count();
        $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();
        $vars['token'] = Csrf::token();
        $vars['article'] = Post::find($id);
        $vars['page'] = Registry::get('posts_page');
        // extended fields
        $vars['fields'] = Extend::fields('post', $id);
        $vars['statuses'] = array('published' => __('global.published'), 'draft' => __('global.draft'), 'archived' => __('global.archived'));
        $vars['categories'] = Category::dropdown();
        $vars['companies'] = Company::dropdown();
        $vars['departments'] = Department::dropdown();
        return View::create('posts/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor');
    });
    Route::post('admin/posts/edit/(:num)', function ($id) {
        $input = Input::get(array('title', 'slug', 'description', 'created', 'html', 'css', 'js', 'category', 'status', 'comments', 'company', 'department'));
        // if there is no slug try and create one from the title
        if (empty($input['slug'])) {
            $input['slug'] = $input['title'];
        }
        // convert to ascii
        $input['slug'] = slug($input['slug']);
        // encode title
        $input['title'] = e($input['title'], ENT_COMPAT);
        $validator = new Validator($input);
        $validator->add('duplicate', function ($str) use($id) {
            return Post::where('slug', '=', $str)->where('id', '<>', $id)->count() == 0;
        });
        $validator->check('title')->is_max(3, __('posts.title_missing'));
        $validator->check('slug')->is_max(3, __('posts.slug_missing'))->is_duplicate(__('posts.slug_duplicate'))->not_regex('#^[0-9_-]+$#', __('posts.slug_invalid'));
        $validator->check('created')->is_regex('#^[0-9]{4}\\-[0-9]{2}\\-[0-9]{2} [0-9]{2}\\:[0-9]{2}\\:[0-9]{2}$#', __('posts.time_invalid'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/posts/edit/' . $id);
        }
        $current_post = Post::find($id);
        if ($current_post->status == 'draft') {
            $input['created'] = Date::mysql('now');
        } else {
            unset($input['created']);
        }
        if (is_null($input['comments'])) {
            $input['comments'] = 0;
        }
        if (empty($input['html'])) {
//.........这里部分代码省略.........
开发者ID:pepfi,项目名称:anchor-cms,代码行数:101,代码来源:posts.php

示例9: function

Route::collection(array('before' => 'auth'), function () {
    /*
        Edit post
    */
    Route::get('admin/dossiers/edit/(:num)', function ($id) {
        $vars['messages'] = Notify::read();
        $vars['token'] = Csrf::token();
        $vars['article'] = Post::find($id);
        $vars['page'] = Registry::get('posts_page');
        // extended fields
        $vars['fields'] = Extend::fields('post', $id);
        $vars['statuses'] = array('published' => __('global.published'), 'draft' => __('global.draft'), 'archived' => __('global.archived'));
        $vars['categories'] = Category::dropdown();
        return View::create('dossiers/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor');
    });
    Route::post('admin/dossiers/edit/(:num)', function ($id) {
        $currentPageCategoryId = getCurrentPageCategoryId('dossier');
        $input = Input::get(array('title', 'slug', 'description', 'created', 'html', 'css', 'js', 'category', 'status', 'comments'));
        /** Valeurs en dur **/
        $input['comments'] = 0;
        $input['category'] = $currentPageCategoryId;
        // encode title
        $input['title'] = e($input['title'], ENT_COMPAT);
        $extend = Input::get(array('extend'));
        $typeofproblem = $extend['extend']['typeofproblem'];
        $validator = new Validator($input);
        $validator->add('duplicate', function ($str) use($id) {
            return Post::where('slug', '=', $str)->where('id', '<>', $id)->count() == 0;
        });
        if (is_null($input['description']) || empty($input['description'])) {
            $input['description'] = " ";
        }
        if (is_null($input['css']) || empty($input['css'])) {
            $input['css'] = " ";
        }
        if (is_null($input['js']) || empty($input['js'])) {
            $input['js'] = " ";
        }
        // if there is no slug, create one from title
        if (empty($input['slug'])) {
            $input['slug'] = slug($input['title']);
        }
        // convert to ascii
        $input['slug'] = slug($input['slug']);
        do {
            //Check for duplication
            $isDuplicate = Post::where('slug', '=', $input['slug'])->where('id', '<>', $id)->count() > 0;
            if ($isDuplicate) {
                $input['slug'] = slug(noise(10));
            }
        } while ($isDuplicate);
        $validator->check('slug')->not_regex('#^[0-9_-]+$#', __('posts.slug_invalid'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/dossiers/edit/' . $id);
        }
        if ($input['created']) {
            $input['created'] = Date::mysql($input['created']);
        } else {
            unset($input['created']);
        }
        if (is_null($input['comments'])) {
            $input['comments'] = 0;
        }
        Post::update($id, $input);
        Extend::process('post', $id);
        Notify::success(__('posts.updated'));
        return Response::redirect('admin/dossiers/edit/' . $id);
    });
    /*
        Add new post
    */
    Route::get('admin/dossiers/add', function () {
        $vars['messages'] = Notify::read();
        $vars['token'] = Csrf::token();
        $vars['page'] = Registry::get('posts_page');
        // extended fields
        $vars['fields'] = Extend::fields('post');
        $vars['statuses'] = array('published' => __('global.published'), 'draft' => __('global.draft'), 'archived' => __('global.archived'));
        $vars['categories'] = Category::dropdown();
        return View::create('dossiers/add', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor');
    });
    Route::post('admin/dossiers/add', function () {
        $currentPageCategoryId = getCurrentPageCategoryId('dossier');
        $input = Input::get(array('title', 'slug', 'description', 'created', 'html', 'css', 'js', 'status', 'comments'));
        /** Valeurs en dur **/
        $input['comments'] = 0;
        $input['category'] = $currentPageCategoryId;
        // convert to ascii
        $input['slug'] = slug($input['slug']);
        // encode title
        $input['title'] = e($input['title'], ENT_COMPAT);
        $extend = Input::get(array('extend'));
        $typeofproblem = $extend['extend']['typeofproblem'];
        $validator = new Validator($input);
        $validator->add('duplicate', function ($str) {
            return Post::where('slug', '=', $str)->count() == 0;
        });
        if (is_null($input['description']) || empty($input['description'])) {
//.........这里部分代码省略.........
开发者ID:Rictus,项目名称:CMS_Prod,代码行数:101,代码来源:dossier.php

示例10: function

Route::collection(array('before' => 'auth'), function () {
    /**
     * Main page
     */
    Route::get('admin/accueil', function () {
        $currentPageCategoryId = getCurrentPageCategoryId('accueil');
        $biopage = Page::slug('biographie');
        $vars['messages'] = Notify::read();
        $vars['token'] = Csrf::token();
        $vars['page'] = Registry::get('posts_page');
        $vars['biopage'] = $biopage;
        $vars['team'] = array();
        $vars['accroche'] = false;
        $postsAccueil = Post::where('category', '=', $currentPageCategoryId)->sort('created', 'asc')->get();
        for ($i = 0; $i < count($postsAccueil); $i++) {
            $memberId = $postsAccueil[$i]->data["id"];
            $teammembername_extend = Extend::value(Extend::field('post', 'teammembername', $memberId));
            $teammemberjob_extend = Extend::value(Extend::field('post', 'teammemberjob', $memberId));
            $teammemberjob_en_extend = Extend::value(Extend::field('post', 'teammemberjob_en', $memberId));
            $catchphrase_extend = Extend::value(Extend::field('post', 'catchphrase', $memberId));
            $catchimage_extend = Extend::value(Extend::field('post', 'catchimage', $memberId));
            $catchphrase_en_extend = Extend::value(Extend::field('post', 'catchphrase_en', $memberId));
            if (!is_null($teammembername_extend) && !is_null($teammemberjob_extend)) {
                $postsAccueil[$i]->data['teammembername'] = $teammembername_extend;
                $postsAccueil[$i]->data['teammemberjob'] = $teammemberjob_extend;
                $postsAccueil[$i]->data['teammemberjob_en'] = $teammemberjob_en_extend;
                $vars['team'][] = $postsAccueil[$i];
            } else {
                if (!is_null($catchimage_extend) && !is_null($catchphrase_extend) && !is_null($catchphrase_en_extend)) {
                    $postsAccueil[$i]->data['catchphrase'] = $catchphrase_extend;
                    $postsAccueil[$i]->data['catchphrase_en'] = $catchphrase_en_extend;
                    $postsAccueil[$i]->data['catchimage'] = $catchimage_extend;
                    $vars['accroche'] = $postsAccueil[$i];
                }
            }
        }
        $vars['bioimage'] = Extend::value(Extend::field('page', 'bioimage', $biopage->id));
        $vars['biofirstpart'] = Extend::value(Extend::field('page', 'biofirstpart', $biopage->id));
        $vars['biosecondpart'] = Extend::value(Extend::field('page', 'biosecondpart', $biopage->id));
        $vars['biothirdpart'] = Extend::value(Extend::field('page', 'biothirdpart', $biopage->id));
        $vars['bioimage_en'] = Extend::value(Extend::field('page', 'bioimage_en', $biopage->id));
        $vars['biofirstpart_en'] = Extend::value(Extend::field('page', 'biofirstpart_en', $biopage->id));
        $vars['biosecondpart_en'] = Extend::value(Extend::field('page', 'biosecondpart_en', $biopage->id));
        $vars['biothirdpart_en'] = Extend::value(Extend::field('page', 'biothirdpart_en', $biopage->id));
        return View::create('accueil/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    /**
     * Team Member
     */
    Route::get('admin/accueil/addTeamMember', function () {
        $vars['messages'] = Notify::read();
        $vars['token'] = Csrf::token();
        $vars['page'] = Registry::get('posts_page');
        // extended fields
        $vars['fields'] = Extend::fields('post');
        $vars['statuses'] = array('published' => __('global.published'), 'draft' => __('global.draft'), 'archived' => __('global.archived'));
        $vars['categories'] = Category::dropdown();
        return View::create('accueil/addTeamMember', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    Route::post('admin/accueil/addTeamMember', function () {
        $currentPageCategoryId = getCurrentPageCategoryId('accueil');
        $user = Auth::user();
        $input = Input::get(array('title', 'slug', 'description', 'created', 'html', 'css', 'js', 'category', 'status', 'comments'));
        /** Valeurs en dur **/
        $input['comments'] = 0;
        $input['status'] = 'published';
        $input['title'] = "";
        $input['description'] = "";
        $input['css'] = "";
        $input['html'] = "";
        $input['js'] = "";
        $input['slug'] = slug($input['slug']);
        $input['comments'] = 0;
        $input['author'] = $user->id;
        $input['category'] = $currentPageCategoryId;
        do {
            //Check for duplication
            $isDuplicate = Post::where('slug', '=', $input['slug'])->count() > 0;
            if ($isDuplicate) {
                $input['slug'] = slug(noise(10));
            }
        } while ($isDuplicate);
        $validator = new Validator($input);
        $validator->add('duplicate', function ($str) {
            return Post::where('slug', '=', $str)->count() == 0;
        });
        $validator->check('slug')->not_regex('#^[0-9_-]+$#', __('posts.slug_invalid'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/posts/addTeamMember');
        }
        if (empty($input['created'])) {
            $input['created'] = Date::mysql('now');
        }
        $post = Post::create($input);
        Extend::process('post', $post->id);
        Notify::success(__('accueil.TeamMemberCreated'));
        return Response::redirect('admin/accueil');
    });
//.........这里部分代码省略.........
开发者ID:Rictus,项目名称:CMS_Prod,代码行数:101,代码来源:accueil.php

示例11: function

Route::collection(array('before' => 'auth,csrf,install_exists'), function () {
    /*
        List users
    */
    Route::get(array('admin/users', 'admin/users/(:num)'), function ($page = 1) {
        $vars['users'] = User::paginate($page, Config::get('admin.posts_per_page'));
        return View::create('users/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    /*
        Edit user
    */
    Route::get('admin/users/edit/(:num)', function ($id) {
        $vars['token'] = Csrf::token();
        $vars['user'] = User::find($id);
        // extended fields
        $vars['fields'] = Extend::fields('user', $id);
        $vars['statuses'] = array('inactive' => __('global.inactive'), 'active' => __('global.active'));
        $vars['roles'] = array('administrator' => __('global.administrator'), 'editor' => __('global.editor'), 'user' => __('global.user'));
        return View::create('users/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    Route::post('admin/users/edit/(:num)', function ($id) {
        $input = Input::get(array('username', 'email', 'real_name', 'bio', 'status'));
        $password_reset = false;
        // Force admin for now
        $input['role'] = 'administrator';
        // A little higher to avoid messing with the password
        foreach ($input as $key => &$value) {
            $value = eq($value);
        }
        if ($password = Input::get('password')) {
            $input['password'] = $password;
            $password_reset = true;
        }
        $validator = new Validator($input);
        $validator->add('safe', function ($str) use($id) {
            return $str != 'inactive' and Auth::user()->id == $id;
        });
        $validator->check('username')->is_max(2, __('users.username_missing', 2));
        $validator->check('email')->is_email(__('users.email_missing'));
        if ($password_reset) {
            $validator->check('password')->is_max(6, __('users.password_too_short', 6));
        }
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/users/edit/' . $id);
        }
        if ($password_reset) {
            $input['password'] = Hash::make($input['password']);
        }
        User::update($id, $input);
        Extend::process('user', $id);
        Notify::success(__('users.updated'));
        return Response::redirect('admin/users/edit/' . $id);
    });
    /*
        Add user
    */
    Route::get('admin/users/add', function () {
        $vars['token'] = Csrf::token();
        // extended fields
        $vars['fields'] = Extend::fields('user');
        $vars['statuses'] = array('inactive' => __('global.inactive'), 'active' => __('global.active'));
        $vars['roles'] = array('administrator' => __('global.administrator'), 'editor' => __('global.editor'), 'user' => __('global.user'));
        return View::create('users/add', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    Route::post('admin/users/add', function () {
        $input = Input::get(array('username', 'email', 'real_name', 'password', 'bio', 'status'));
        // Force admin for now
        $input['role'] = 'administrator';
        foreach ($input as $key => &$value) {
            if ($key === 'password') {
                continue;
            }
            // Can't avoid, so skip.
            $value = eq($value);
        }
        $validator = new Validator($input);
        $validator->check('username')->is_max(3, __('users.username_missing', 2));
        $validator->check('email')->is_email(__('users.email_missing'));
        $validator->check('password')->is_max(6, __('users.password_too_short', 6));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/users/add');
        }
        $input['password'] = Hash::make($input['password']);
        $user = User::create($input);
        Extend::process('user', $user->id);
        Notify::success(__('users.created'));
        return Response::redirect('admin/users');
    });
    /*
        Delete user
    */
    Route::get('admin/users/delete/(:num)', function ($id) {
        $self = Auth::user();
        if ($self->id == $id) {
            Notify::error(__('users.delete_error'));
            return Response::redirect('admin/users/edit/' . $id);
//.........这里部分代码省略.........
开发者ID:anchorcms,项目名称:anchor-cms,代码行数:101,代码来源:users.php

示例12: function

Route::collection(array('before' => 'auth,csrf,install_exists'), function () {
    /*
        List Pages
    */
    Route::get(array('admin/pages', 'admin/pages/(:num)'), function ($page = 1) {
        $perpage = Config::get('admin.posts_per_page');
        $total = Page::where(Base::table('pages.parent'), '=', '0')->count();
        $pages = Page::sort('title')->where(Base::table('pages.parent'), '=', '0')->take($perpage)->skip(($page - 1) * $perpage)->get();
        $url = Uri::to('admin/pages');
        $pagination = new Paginator($pages, $total, $page, $perpage, $url);
        $vars['pages'] = $pagination;
        $vars['status'] = 'all';
        return View::create('pages/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    /*
        List pages by status and paginate through them
    */
    Route::get(array('admin/pages/status/(:any)', 'admin/pages/status/(:any)/(:num)'), function ($status, $page = 1) {
        $query = Page::where('status', '=', $status);
        $perpage = Config::get('admin.posts_per_page');
        $total = $query->count();
        $pages = $query->sort('title')->take($perpage)->skip(($page - 1) * $perpage)->get();
        $url = Uri::to('admin/pages/status');
        $pagination = new Paginator($pages, $total, $page, $perpage, $url);
        $vars['pages'] = $pagination;
        $vars['status'] = $status;
        return View::create('pages/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    /*
        Edit Page
    */
    Route::get('admin/pages/edit/(:num)', function ($id) {
        $vars['token'] = Csrf::token();
        $vars['deletable'] = Page::count() > 1 && Page::home()->id != $id && Page::posts()->id != $id;
        $vars['page'] = Page::find($id);
        $vars['pages'] = Page::dropdown(array('exclude' => array($id), 'show_empty_option' => true));
        $vars['pagetypes'] = Query::table(Base::table('pagetypes'))->sort('key')->get();
        $vars['statuses'] = array('published' => __('global.published'), 'draft' => __('global.draft'), 'archived' => __('global.archived'));
        // extended fields
        $vars['fields'] = Extend::fields('page', $id, $vars['page']->pagetype);
        return View::create('pages/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor');
    });
    Route::post('admin/pages/edit/(:num)', function ($id) {
        $input = Input::get(array('parent', 'name', 'title', 'slug', 'markdown', 'status', 'redirect', 'show_in_menu', 'pagetype'));
        // if there is no slug try and create one from the title
        if (empty($input['slug'])) {
            $input['slug'] = $input['title'];
        }
        // convert to ascii
        $input['slug'] = slug($input['slug']);
        // an array of items that we shouldn't encode - they're no XSS threat
        $dont_encode = array('markdown');
        foreach ($input as $key => &$value) {
            if (in_array($key, $dont_encode)) {
                continue;
            }
            $value = eq($value);
        }
        $validator = new Validator($input);
        $validator->add('duplicate', function ($str) use($id) {
            return Page::where('slug', '=', $str)->where('id', '<>', $id)->count() == 0;
        });
        $validator->check('title')->is_max(3, __('pages.title_missing'));
        $validator->check('slug')->is_max(3, __('pages.slug_missing'))->is_duplicate(__('pages.slug_duplicate'))->not_regex('#^[0-9_-]+$#', __('pages.slug_invalid'));
        if ($input['redirect']) {
            $validator->check('redirect')->is_url(__('pages.redirect_missing'));
        }
        if ($errors = $validator->errors()) {
            Input::flash();
            // Notify::error($errors);
            return Response::json(array('id' => $id, 'errors' => array_flatten($errors, array())));
        }
        if (empty($input['name'])) {
            $input['name'] = $input['title'];
        }
        // encode title
        $input['title'] = e($input['title'], ENT_COMPAT);
        $input['show_in_menu'] = is_null($input['show_in_menu']) || empty($input['show_in_menu']) ? 0 : 1;
        $input['html'] = parse($input['markdown']);
        Page::update($id, $input);
        Extend::process('page', $id);
        // Notify::success(__('pages.updated'));
        return Response::json(array('id' => $id, 'notification' => __('pages.updated')));
    });
    /*
        Add Page
    */
    Route::get('admin/pages/add', function () {
        $vars['token'] = Csrf::token();
        $vars['pages'] = Page::dropdown(array('exclude' => array(), 'show_empty_option' => true));
        $vars['pagetypes'] = Query::table(Base::table('pagetypes'))->sort('key')->get();
        $vars['statuses'] = array('published' => __('global.published'), 'draft' => __('global.draft'), 'archived' => __('global.archived'));
        // extended fields
        $vars['fields'] = Extend::fields('page');
        return View::create('pages/add', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor');
    });
    Route::post('admin/pages/add', function () {
        $input = Input::get(array('parent', 'name', 'title', 'slug', 'markdown', 'status', 'redirect', 'show_in_menu', 'pagetype'));
        // if there is no slug try and create one from the title
        if (empty($input['slug'])) {
//.........这里部分代码省略.........
开发者ID:anchorcms,项目名称:anchor-cms,代码行数:101,代码来源:pages.php

示例13: function

<?php

Route::collection(array('before' => 'auth,csrf'), function () {
    /*
    	List all plugins
    */
    Route::get('admin/extend/plugins', function ($page = 1) {
        $vars['messages'] = Notify::read();
        $vars['token'] = Csrf::token();
        return View::create('extend/plugins/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
});
Route::collection(array('before' => 'auth'), function () {
    Route::get('admin/bookz', function ($page = 1) {
        require APP . 'bookz/bookz' . EXT;
    });
    Route::post('admin/bookz', function ($page = 1) {
        require APP . 'bookz/bookz' . EXT;
    });
});
开发者ID:svita-cz,项目名称:web,代码行数:20,代码来源:plugins.php

示例14: function

Route::collection(array('before' => 'auth,csrf,install_exists'), function () {
    /*
        List Vars
    */
    Route::get('admin/extend/pagetypes', function () {
        $vars['token'] = Csrf::token();
        $vars['pagetypes'] = Query::table(Base::table('pagetypes'))->sort('key')->get();
        return View::create('extend/pagetypes/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    /*
        Add Var
    */
    Route::get('admin/extend/pagetypes/add', function () {
        $vars['token'] = Csrf::token();
        return View::create('extend/pagetypes/add', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    Route::post('admin/extend/pagetypes/add', function () {
        $input = Input::get(array('key', 'value'));
        $input['key'] = slug($input['key'], '_');
        $validator = new Validator($input);
        $validator->add('valid_key', function ($str) {
            return Query::table(Base::table('pagetypes'))->where('key', '=', $str)->count() == 0;
        });
        $validator->check('key')->is_max(2, __('extend.key_missing'))->is_valid_key(__('extend.key_exists'));
        $validator->check('value')->is_max(1, __('extend.name_missing'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/extend/pagetypes/add');
        }
        Query::table(Base::table('pagetypes'))->insert($input);
        Notify::success(__('extend.pagetype_created'));
        return Response::redirect('admin/extend/pagetypes');
    });
    /*
        Edit Var
    */
    Route::get('admin/extend/pagetypes/edit/(:any)', function ($key) {
        $vars['token'] = Csrf::token();
        $vars['pagetype'] = Query::table(Base::table('pagetypes'))->where('key', '=', $key)->fetch();
        return View::create('extend/pagetypes/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    Route::post('admin/extend/pagetypes/edit/(:any)', function ($key) {
        $input = Input::get(array('key', 'value'));
        $input['key'] = slug($input['key'], '_');
        $validator = new Validator($input);
        $validator->add('valid_key', function ($str) use($key) {
            // no change
            if ($str == $key) {
                return true;
            }
            // check the new key $str is available
            return Query::table(Base::table('pagetypes'))->where('key', '=', $str)->count() == 0;
        });
        $validator->check('key')->is_max(2, __('extend.key_missing'))->is_valid_key(__('extend.key_exists'));
        $validator->check('value')->is_max(1, __('extend.name_missing'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/extend/pagetypes/edit/' . $key);
        }
        Query::table(Base::table('pagetypes'))->where('key', '=', $key)->update($input);
        Notify::success(__('extend.pagetype_updated'));
        return Response::redirect('admin/extend/pagetypes');
    });
    /*
        Delete Var
    */
    Route::get('admin/extend/pagetypes/delete/(:any)', function ($key) {
        Query::table(Base::table('pagetypes'))->where('key', '=', $key)->delete();
        Notify::success(__('extend.pagetype_deleted'));
        return Response::redirect('admin/extend/pagetypes');
    });
});
开发者ID:anchorcms,项目名称:anchor-cms,代码行数:74,代码来源:pagetypes.php

示例15: function

Route::collection(array('before' => 'auth'), function () {
    /*
        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
        $vars['fields'] = Extend::fields('post');
        $vars['statuses'] = array('published' => __('global.published'), 'draft' => __('global.draft'), 'archived' => __('global.archived'));
        $vars['categories'] = Category::dropdown();
        return View::create('publications/addBook', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor');
    });
    Route::post('admin/publications/addBook', function () {
        $currentPageCategoryId = getCurrentPageCategoryId('publication');
        $input = Input::get(array('title', 'slug', 'description', 'created', 'html', 'css', 'js', 'status', 'comments'));
        $extends = Input::get(array('extend'));
        /** Valeurs en dur **/
        $input['comments'] = 0;
        $input['category'] = $currentPageCategoryId;
        // convert to ascii
        $input['slug'] = slug($input['slug']);
        // encode title
        $input['title'] = e($input['title'], ENT_COMPAT);
        $validator = new Validator($input);
        $validator->add('duplicate', function ($str) {
            return Post::where('slug', '=', $str)->count() == 0;
        });
        if (is_null($input['description']) || empty($input['description'])) {
            $input['description'] = " ";
        }
        if (is_null($input['html']) || empty($input['html'])) {
            $input['html'] = " ";
        }
        if (is_null($input['css']) || empty($input['css'])) {
            $input['css'] = " ";
        }
        if (is_null($input['js']) || empty($input['js'])) {
            $input['js'] = " ";
        }
        // if there is no slug try and create one from title
        if (empty($input['slug'])) {
            $input['slug'] = $input['title'];
        }
        // convert to ascii
        $input['slug'] = slug($input['slug']);
        do {
            //Check for duplication
            $isDuplicate = Post::where('slug', '=', $input['slug'])->count() > 0;
            if ($isDuplicate) {
                $input['slug'] = slug(noise(10));
            }
        } while ($isDuplicate);
        $validator->check('slug')->not_regex('#^[0-9_-]+$#', __('publications.slug_invalid'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/publications/addBook');
        }
        if (empty($input['created'])) {
            $input['created'] = Date::mysql('now');
        }
        $user = Auth::user();
        $input['author'] = $user->id;
        if (is_null($input['comments'])) {
            $input['comments'] = 0;
        }
        $post = Post::create($input);
        Extend::process('post', $post->id);
        Notify::success(__('publications.created_book'));
        return Response::redirect('admin/publications');
    });
    /*
        Delete post
    */
//.........这里部分代码省略.........
开发者ID:Rictus,项目名称:CMS_Prod,代码行数:101,代码来源:publications.php


注:本文中的Route::collection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。