<?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'); }); });
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); $validator = new Validator($input); $validator->add('duplicate', function ($str) { return Page::where('slug', '=', $str)->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/add'); } if (empty($input['name'])) { $input['name'] = $input['title']; } $input['show_in_menu'] = is_null($input['show_in_menu']) ? 0 : 1; $page = Page::create($input); Extend::process('page', $page->id); Notify::success(__('pages.created')); return Response::redirect('admin/pages'); }); /* Delete Page */ Route::get('admin/pages/delete/(:num)', function ($id) { Page::find($id)->delete(); Query::table(Base::table('page_meta'))->where('page', '=', $id)->delete(); Notify::success(__('pages.deleted')); return Response::redirect('admin/pages'); }); });
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); }); });
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'); }); });
<?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'); }); });
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'); }); });
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 () { $html = Input::get('html'); // apply markdown processing $md = new Markdown(); $output = Json::encode(array('html' => $md->transform($html))); return Response::create($output, 200, array('content-type' => 'application/json')); }); /* Delete post */ Route::get('admin/posts/delete/(:num)', function ($id) { Post::find($id)->delete(); Comment::where('post', '=', $id)->delete(); Notify::success(__('posts.deleted')); return Response::redirect('admin/posts'); }); });
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'])) { $input['status'] = 'draft'; } Post::update($id, $input); Extend::process('post', $id); 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'); // extended fields $vars['fields'] = Extend::fields('post'); $vars['statuses'] = array('published' => __('global.published'), 'draft' => __('global.draft'), 'archived' => __('global.archived')); $vars['categories'] = Category::dropdown(); $vars['companies'] = Company::dropdown(); $vars['departments'] = Department::dropdown(); // echo '<pre>'; // print_r($vars);exit; 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', '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) { 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 (is_null($input['comments'])) { $input['comments'] = 0; } if (empty($input['html'])) { $input['status'] = 'draft'; } $post = Post::create($input); Extend::process('post', $post->id); Notify::success(__('posts.created')); return Response::redirect('admin/posts'); }); /* Preview post */ Route::post('admin/posts/preview', function () { $html = Input::get('html'); // apply markdown processing $md = new Markdown(); $output = Json::encode(array('html' => $md->transform($html))); return Response::create($output, 200, array('content-type' => 'application/json')); }); /* Delete post */ Route::get('admin/posts/delete/(:num)', function ($id) { Post::find($id)->delete(); Comment::where('post', '=', $id)->delete(); Query::table(Base::table('post_meta'))->where('post', '=', $id)->delete(); Notify::success(__('posts.deleted')); return Response::redirect('admin/posts'); }); });
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'])) { $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 try and 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'])->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/add'); } 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(__('posts.created')); return Response::redirect('admin/dossiers'); }); /* Preview post */ Route::post('admin/dossiers/preview', function () { $html = Input::get('html'); // apply markdown processing $md = new Markdown(); $output = Json::encode(array('html' => $md->transform($html))); return Response::create($output, 200, array('content-type' => 'application/json')); }); /* Delete post */ Route::get('admin/dossiers/delete/(:num)', function ($id) { Post::find($id)->delete(); Comment::where('post', '=', $id)->delete(); Query::table(Base::table('post_meta'))->where('post', '=', $id)->delete(); Notify::success(__('posts.deleted')); return Response::redirect('admin/dossiers'); }); /* Upload a image */ Route::post('admin/(pages|posts)/upload', function () { $uploader = new Uploader(PATH . 'content', array('png', 'jpg', 'bmp', 'gif')); $file = $_FILES['upload']; $filepath = $uploader->upload($file); // $uri = Config::app('url', '/') . '/content/' . basename($filepath); $uri = '/content/' . basename($filepath); $output = array('uploaded' => 1, 'url' => $uri, 'fileName' => $file['name']); return Response::json($output); }); /* 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; return View::create('dossiers/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); });
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'); }); Route::get('admin/accueil/editTeamMember/(:num)', function ($id) { $vars['messages'] = Notify::read(); $vars['token'] = Csrf::token(); $vars['member'] = 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')); return View::create('accueil/editTeamMember', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); Route::post('admin/accueil/editTeamMember/(:num)', function ($id) { $currentPageCategoryId = getCurrentPageCategoryId('accueil'); $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['comments'] = 0; $input['category'] = $currentPageCategoryId; $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/accueil/editTeamMember/' . $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(__('accueil.teamMemberUpdated')); return Response::redirect('admin/accueil/editTeamMember/' . $id); }); Route::get('admin/accueil/deleteTeamMember/(:num)', function ($id) { Post::find($id)->delete(); Comment::where('post', '=', $id)->delete(); Query::table(Base::table('post_meta'))->where('post', '=', $id)->delete(); Notify::success(__('accueil.teamMemberDeleted')); return Response::redirect('admin/accueil'); }); /** * Accroche */ Route::get('admin/accueil/addCatch', 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/addCatch', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); Route::post('admin/accueil/addCatch', 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/addCatch'); } if (empty($input['created'])) { $input['created'] = Date::mysql('now'); } $post = Post::create($input); Extend::process('post', $post->id); Notify::success(__('accueil.created_catch')); return Response::redirect('admin/accueil'); }); Route::get('admin/accueil/editCatch/(:num)', function ($id) { $vars['messages'] = Notify::read(); $vars['token'] = Csrf::token(); $vars['post'] = 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('accueil/editCatch', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor'); }); Route::post('admin/accueil/editCatch/(:num)', function ($id) { $currentPageCategoryId = getCurrentPageCategoryId('accueil'); $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['comments'] = 0; $input['category'] = $currentPageCategoryId; $validator = new Validator($input); $validator->add('duplicate', function ($str) use($id) { return Post::where('slug', '=', $str)->where('id', '<>', $id)->count() == 0; }); // 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/accueil/editCatch/' . $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(__('accueil.catchUpdated')); return Response::redirect('admin/accueil/editCatch/' . $id); }); /** * Bio */ Route::get(array('admin/accueil/editBio'), function () { $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'] = 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['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['statuses'] = array('published' => __('global.published'), 'draft' => __('global.draft'), 'archived' => __('global.archived')); $vars['categories'] = Category::dropdown(); return View::create('accueil/editBio', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); Route::get(array('admin/accueil/editBio_en'), function () { $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'); }); /** * Person infos */ Route::get('admin/accueil/editInfo/(:any)', function ($key) { $vars['messages'] = Notify::read(); $vars['token'] = Csrf::token(); $vars['variableInfo'] = Query::table(Base::table('meta'))->where('key', '=', $key)->fetch(); return View::create('accueil/editInfo', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); Route::post('admin/accueil/editInfo/(:any)', function ($key) { $input = Input::get(array('value')); Query::table(Base::table('meta'))->where('key', '=', $key)->update($input); Notify::success(__('accueil.updated_info')); return Response::redirect('admin/accueil'); }); });
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); } User::where('id', '=', $id)->delete(); Query::table(Base::table('user_meta'))->where('user', '=', $id)->delete(); Notify::success(__('users.deleted')); return Response::redirect('admin/users'); }); });
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'])) { $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) { return Page::where('slug', '=', $str)->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']; } $input['show_in_menu'] = is_null($input['show_in_menu']) || empty($input['show_in_menu']) ? 0 : 1; $input['html'] = parse($input['markdown']); $page = Page::create($input); $id = $page->id; Extend::process('page', $id); // Notify::success(__('pages.created')); return Response::json(array('id' => $id, 'notification' => __('pages.created'), 'redirect' => Uri::to('admin/pages/edit/' . $id))); }); /* Delete Page */ Route::get('admin/pages/delete/(:num)', function ($id) { if (Page::count() > 1) { Page::find($id)->delete(); Query::table(Base::table('page_meta'))->where('page', '=', $id)->delete(); Notify::success(__('pages.deleted')); } else { Notify::error('Unable to delete page, you must have at least 1 page.'); } return Response::redirect('admin/pages'); }); });
<?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; }); });
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'); }); });
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 */ Route::get('admin/publications/deleteBook/(:num)', function ($id) { Post::find($id)->delete(); Comment::where('post', '=', $id)->delete(); Query::table(Base::table('post_meta'))->where('post', '=', $id)->delete(); Notify::success(__('posts.deleted')); return Response::redirect('admin/publications'); }); /* Delete publication */ Route::get('admin/publications/deletePublication/(:num)', function ($id) { Post::find($id)->delete(); Comment::where('post', '=', $id)->delete(); Query::table(Base::table('post_meta'))->where('post', '=', $id)->delete(); Notify::success(__('posts.deleted')); return Response::redirect('admin/publications'); }); /* Edit post */ Route::get('admin/publications/editBook/(:num)', function ($id) { $vars['messages'] = Notify::read(); $vars['token'] = Csrf::token(); $vars['book'] = 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')); return View::create('publications/editBook', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor'); }); Route::post('admin/publications/editBook/(:num)', function ($id) { $currentPageCategoryId = getCurrentPageCategoryId('publication'); $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); $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/publications/editBook/' . $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/publications/editBook/' . $id); }); /* Add new text publication */ Route::get('admin/publications/addPublication', 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/addPublication', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor'); }); Route::post('admin/publications/addPublication', 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/addPublication'); } 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'); }); /* Edit a text-only publication */ Route::get('admin/publications/editPublication/(:num)', function ($id) { $vars['messages'] = Notify::read(); $vars['token'] = Csrf::token(); $vars['publication'] = 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')); return View::create('publications/editPublication', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor'); }); Route::post('admin/publications/editPublication/(:num)', function ($id) { $currentPageCategoryId = getCurrentPageCategoryId('publication'); $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); $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/publications/editPublication/' . $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/publications/editPublication/' . $id); }); });
Route::collection(array('before' => 'auth,install_exists'), function () { /* List Metadata */ Route::get('admin/extend/metadata', function () { $vars['token'] = Csrf::token(); $vars['dashboard_page_options'] = array('panel' => 'Welcome', 'posts' => 'Posts', 'pages' => 'Pages'); $vars['meta'] = Config::get('meta'); $vars['pages'] = Page::dropdown(); $vars['themes'] = Themes::all(); return View::create('extend/metadata/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); /* Update Metadata */ Route::post('admin/extend/metadata', function () { $input = Input::get(array('sitename', 'description', 'home_page', 'posts_page', 'posts_per_page', 'auto_published_comments', 'theme', 'comment_notifications', 'comment_moderation_keys', 'show_all_posts', 'dashboard_page')); foreach ($input as $key => $value) { $input[$key] = eq($value); } $validator = new Validator($input); $validator->check('sitename')->is_max(3, __('metadata.sitename_missing')); $validator->check('description')->is_max(3, __('metadata.sitedescription_missing')); $validator->check('posts_per_page')->is_regex('#^[0-9]+$#', __('metadata.missing_posts_per_page', 'Please enter a number for posts per page')); if ($errors = $validator->errors()) { Input::flash(); Notify::error($errors); return Response::redirect('admin/extend/metadata'); } // convert double quotes so we dont break html $input['sitename'] = e($input['sitename'], ENT_COMPAT); $input['description'] = e($input['description'], ENT_COMPAT); foreach ($input as $key => $v) { $v = is_null($v) ? 0 : $v; Query::table(Base::table('meta'))->where('key', '=', $key)->update(array('value' => $v)); } Notify::success(__('metadata.updated')); return Response::redirect('admin/extend/metadata'); }); });
Route::collection(array('before' => 'auth,csrf,install_exists'), function () { /* List all posts and paginate through them */ Route::get(array('admin/posts', 'admin/posts/(:num)'), function ($page = 1) { $perpage = Config::get('admin.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['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 = Config::get('admin.posts_per_page'); $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['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::get('admin.posts_per_page'); $total = $query->count(); $posts = $query->sort('title')->take($perpage)->skip(($post - 1) * $perpage)->get(); $url = Uri::to('admin/posts/status/' . $status); $pagination = new Paginator($posts, $total, $post, $perpage, $url); $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['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('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', 'markdown', 'css', 'js', 'category', 'status', 'comments')); // 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('description', 'markdown', 'css', 'js'); 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 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::json(array('id' => $id, 'errors' => array_flatten($errors, array()))); } if (empty($input['comments'])) { $input['comments'] = 0; } if (empty($input['markdown'])) { $input['status'] = 'draft'; } $input['html'] = parse($input['markdown']); Post::update($id, $input); Extend::process('post', $id); // Notify::success(__('posts.updated')); return Response::json(array('id' => $id, 'notification' => __('posts.updated'))); }); /* Add new post */ Route::get('admin/posts/add', function () { $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('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', 'markdown', 'css', 'js', 'category', 'status', 'comments')); // 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('description', 'markdown', 'css', 'js'); foreach ($input as $key => &$value) { if (in_array($key, $dont_encode)) { continue; } $value = eq($value); } $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::json(array('id' => $id, 'errors' => array_flatten($errors, array()))); } if (empty($input['created'])) { $input['created'] = Date::mysql('now'); } $user = Auth::user(); $input['author'] = $user->id; if (empty($input['comments'])) { $input['comments'] = 0; } if (empty($input['markdown'])) { $input['status'] = 'draft'; } $input['html'] = parse($input['markdown']); $post = Post::create($input); $id = $post->id; Extend::process('post', $id); // Notify::success(__('posts.created')); if (Input::get('autosave') === 'true') { return Response::json(array('id' => $id, 'notification' => __('posts.updated'))); } else { return Response::json(array('id' => $id, 'notification' => __('posts.created'), 'redirect' => Uri::to('admin/posts/edit/' . $id))); } }); /* Preview post */ Route::post('admin/posts/preview', function () { $markdown = Input::get('markdown'); // apply markdown processing $md = new Markdown(); $output = Json::encode(array('markdown' => $md->transform($markdown))); return Response::create($output, 200, array('content-type' => 'application/json')); }); /* Delete post */ Route::get('admin/posts/delete/(:num)', function ($id) { Post::find($id)->delete(); Comment::where('post', '=', $id)->delete(); Query::table(Base::table('post_meta'))->where('post', '=', $id)->delete(); Notify::success(__('posts.deleted')); return Response::redirect('admin/posts'); }); });
Route::collection(array('before' => 'auth,csrf,install_exists'), function () { /* List Fields */ Route::get(array('admin/extend/fields', 'admin/extend/fields/(:num)'), function ($page = 1) { $vars['token'] = Csrf::token(); $vars['extend'] = Extend::paginate($page, Config::get('admin.posts_per_page')); return View::create('extend/fields/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); /* Add Field */ Route::get('admin/extend/fields/add', function () { $vars['token'] = Csrf::token(); $vars['types'] = Extend::$types; $vars['fields'] = Extend::$field_types; $vars['pagetypes'] = Query::table(Base::table('pagetypes'))->sort('key')->get(); return View::create('extend/fields/add', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); Route::post('admin/extend/fields/add', function () { $input = Input::get(array('type', 'field', 'key', 'label', 'attributes', 'pagetype')); if (empty($input['key'])) { $input['key'] = $input['label']; } $input['key'] = slug($input['key'], '_'); // an array of items that we shouldn't encode - they're no XSS threat $dont_encode = array('attributes'); foreach ($input as $key => &$value) { if (in_array($key, $dont_encode)) { continue; } $value = eq($value); } $validator = new Validator($input); $validator->add('valid_key', function ($str) use($input) { return Extend::where('key', '=', $str)->where('type', '=', $input['type'])->count() == 0; }); $validator->check('key')->is_max(1, __('extend.key_missing'))->is_valid_key(__('extend.key_exists')); $validator->check('label')->is_max(1, __('extend.label_missing')); if ($errors = $validator->errors()) { Input::flash(); Notify::error($errors); return Response::redirect('admin/extend/fields/add'); } if ($input['field'] == 'image') { $attributes = Json::encode($input['attributes']); } elseif ($input['field'] == 'file') { $attributes = Json::encode(array('attributes' => array('type' => $input['attributes']['type']))); } else { $attributes = ''; } Extend::create(array('type' => $input['type'], 'pagetype' => $input['pagetype'], 'field' => $input['field'], 'key' => $input['key'], 'label' => $input['label'], 'attributes' => $attributes)); Notify::success(__('extend.field_created')); return Response::redirect('admin/extend/fields'); }); /* Edit Field */ Route::get('admin/extend/fields/edit/(:num)', function ($id) { $vars['token'] = Csrf::token(); $vars['types'] = Extend::$types; $vars['fields'] = Extend::$field_types; $extend = Extend::find($id); if ($extend->attributes) { $extend->attributes = Json::decode($extend->attributes); } $vars['field'] = $extend; $vars['pagetypes'] = Query::table(Base::table('pagetypes'))->sort('key')->get(); return View::create('extend/fields/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); Route::post('admin/extend/fields/edit/(:num)', function ($id) { $input = Input::get(array('type', 'field', 'key', 'label', 'attributes', 'pagetype')); if (empty($input['key'])) { $input['key'] = $input['label']; } $input['key'] = slug($input['key'], '_'); array_walk_recursive($input, function (&$value) { $value = eq($value); }); $validator = new Validator($input); $validator->add('valid_key', function ($str) use($id, $input) { return Extend::where('key', '=', $str)->where('type', '=', $input['type'])->where('id', '<>', $id)->count() == 0; }); $validator->check('key')->is_max(1, __('extend.key_missing'))->is_valid_key(__('extend.key_exists')); $validator->check('label')->is_max(1, __('extend.label_missing')); if ($errors = $validator->errors()) { Input::flash(); Notify::error($errors); return Response::redirect('admin/extend/fields/edit/' . $id); } if ($input['field'] == 'image') { $attributes = Json::encode($input['attributes']); } elseif ($input['field'] == 'file') { $attributes = Json::encode(array('attributes' => array('type' => $input['attributes']['type']))); } else { $attributes = ''; } Extend::update($id, array('type' => $input['type'], 'pagetype' => $input['pagetype'], 'field' => $input['field'], 'key' => $input['key'], 'label' => $input['label'], 'attributes' => $attributes)); Notify::success(__('extend.field_updated')); return Response::redirect('admin/extend/fields/edit/' . $id); }); /* Delete Field */ Route::get('admin/extend/fields/delete/(:num)', function ($id) { $field = Extend::find($id); Query::table(Base::table($field->type . '_meta'))->where('extend', '=', $field->id)->delete(); $field->delete(); Notify::success(__('extend.field_deleted')); return Response::redirect('admin/extend/fields'); }); });
Route::collection(array('before' => 'auth,csrf'), function () { /* List Vars */ Route::get('admin/extend/variables', function () { $vars['messages'] = Notify::read(); $vars['token'] = Csrf::token(); $variables = array(); foreach (Query::table(Base::table('meta'))->sort('key')->get() as $meta) { if (strpos($meta->key, 'custom_') === 0) { $variables[] = $meta; } } $vars['variables'] = $variables; return View::create('extend/variables/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); /* Add Var */ Route::get('admin/extend/variables/add', function () { $vars['messages'] = Notify::read(); $vars['token'] = Csrf::token(); return View::create('extend/variables/add', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); Route::post('admin/extend/variables/add', function () { $input = Input::get(array('key', 'value')); $input['key'] = 'custom_' . slug($input['key'], '_'); $validator = new Validator($input); $validator->add('valid_key', function ($str) { return Query::table(Base::table('meta'))->where('key', '=', $str)->count() == 0; }); $validator->check('key')->is_max(8, __('extend.name_missing'))->is_valid_key(__('extend.name_exists')); if ($errors = $validator->errors()) { Input::flash(); Notify::error($errors); return Response::redirect('admin/extend/variables/add'); } Query::table(Base::table('meta'))->insert($input); Notify::success(__('extend.variable_created')); return Response::redirect('admin/extend/variables'); }); /* Edit Var */ Route::get('admin/extend/variables/edit/(:any)', function ($key) { $vars['messages'] = Notify::read(); $vars['token'] = Csrf::token(); $vars['variable'] = Query::table(Base::table('meta'))->where('key', '=', $key)->fetch(); // remove prefix $vars['variable']->user_key = substr($vars['variable']->key, strlen('custom_')); return View::create('extend/variables/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); Route::post('admin/extend/variables/edit/(:any)', function ($key) { $input = Input::get(array('key', 'value')); $input['key'] = 'custom_' . 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('meta'))->where('key', '=', $str)->count() == 0; }); $validator->check('key')->is_max(8, __('extend.name_missing'))->is_valid_key(__('extend.name_exists')); if ($errors = $validator->errors()) { Input::flash(); Notify::error($errors); return Response::redirect('admin/extend/variables/edit/' . $key); } Query::table(Base::table('meta'))->where('key', '=', $key)->update($input); Notify::success(__('extend.variable_updated')); return Response::redirect('admin/extend/variables'); }); /* Delete Var */ Route::get('admin/extend/variables/delete/(:any)', function ($key) { Query::table(Base::table('meta'))->where('key', '=', $key)->delete(); Notify::success(__('extend.variable_deleted')); return Response::redirect('admin/extend/variables'); }); });
<?php Route::collection(array('before' => 'auth,install_exists'), function () { /* List Menu Items */ Route::get('admin/menu', function () { $vars['pages'] = Page::where('show_in_menu', '=', 1)->sort('menu_order')->get(); return View::create('menu/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); /* Update order */ Route::post('admin/menu/update', function () { $sort = Input::get('sort'); foreach ($sort as $index => $id) { Page::where('id', '=', $id)->update(array('menu_order' => $index)); } return Response::json(array('result' => true)); }); });
Route::collection(array('before' => 'auth'), 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; $vars['categories'] = Category::sort('title')->get(); 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 = Config::meta('posts_per_page'); $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(); 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(); 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')); /** Valeurs en dur **/ $input['comments'] = 0; $input['status'] = 'published'; // 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; }); 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']); $input['slug'] = "abcd"; } // 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/posts/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/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'); // 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('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', 'category', 'status', 'comments')); /** Valeurs en dur **/ $input['comments'] = 0; $input['status'] = 'published'; // 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['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'] = 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_-]+$#', __('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 (is_null($input['comments'])) { $input['comments'] = 0; } $post = Post::create($input); Extend::process('post', $post->id); Notify::success(__('posts.created')); return Response::redirect('admin/posts'); }); /* Preview post */ Route::post('admin/posts/preview', function () { $html = Input::get('html'); // apply markdown processing $md = new Markdown(); $output = Json::encode(array('html' => $md->transform($html))); return Response::create($output, 200, array('content-type' => 'application/json')); }); /* Delete post */ Route::get('admin/posts/delete/(:num)', function ($id) { Post::find($id)->delete(); Comment::where('post', '=', $id)->delete(); Query::table(Base::table('post_meta'))->where('post', '=', $id)->delete(); Notify::success(__('posts.deleted')); return Response::redirect('admin/posts'); }); /* Upload a image */ Route::post('admin/(pages|posts)/upload', function () { $uploader = new Uploader(PATH . 'content', array('png', 'jpg', 'bmp', 'gif')); $file = $_FILES['upload']; $filepath = $uploader->upload($file); // $uri = Config::app('url', '/') . '/content/' . basename($filepath); $uri = '/content/' . basename($filepath); $output = array('uploaded' => 1, 'url' => $uri, 'fileName' => $file['name']); return Response::json($output); }); });
Route::collection(array('before' => 'auth,csrf'), function () { /* List users */ Route::get(array('admin/users', 'admin/users/(:num)'), function ($page = 1) { $vars['messages'] = Notify::read(); $vars['users'] = User::paginate($page, Config::get('meta.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['messages'] = Notify::read(); $vars['token'] = Csrf::token(); $vars['user'] = User::find($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', 'role')); $password_reset = false; 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); Notify::success(__('users.updated')); return Response::redirect('admin/users/edit/' . $id); }); /* Add user */ Route::get('admin/users/add', function () { $vars['messages'] = Notify::read(); $vars['token'] = Csrf::token(); $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', 'role')); $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::create($input); 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); } User::where('id', '=', $id)->delete(); Notify::success(__('users.deleted')); return Response::redirect('admin/users'); }); });
Route::collection(array('before' => 'auth,csrf'), function () { /* List Fields */ Route::get(array('admin/extend/fields', 'admin/extend/fields/(:num)'), function ($page = 1) { $vars['messages'] = Notify::read(); $vars['token'] = Csrf::token(); $vars['extend'] = Extend::paginate($page, Config::get('meta.posts_per_page')); return View::create('extend/fields/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); /* Add Field */ Route::get('admin/extend/fields/add', function () { $vars['messages'] = Notify::read(); $vars['token'] = Csrf::token(); return View::create('extend/fields/add', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); Route::post('admin/extend/fields/add', function () { $input = Input::get(array('type', 'field', 'key', 'label', 'attributes')); if (empty($input['key'])) { $input['key'] = $input['label']; } $input['key'] = slug($input['key'], '_'); $validator = new Validator($input); $validator->add('valid_key', function ($str) use($input) { return Extend::where('key', '=', $str)->where('type', '=', $input['type'])->count() == 0; }); $validator->check('key')->is_max(1, __('extend.key_missing'))->is_valid_key(__('extend.key_exists')); $validator->check('label')->is_max(1, __('extend.label_missing')); if ($errors = $validator->errors()) { Input::flash(); Notify::error($errors); return Response::redirect('admin/extend/fields/add'); } if ($input['field'] == 'image') { $attributes = Json::encode($input['attributes']); } else { if ($input['field'] == 'file') { $attributes = Json::encode(array('attributes' => array('type' => $input['attributes']['type']))); } else { $attributes = ''; } } Extend::create(array('type' => $input['type'], 'field' => $input['field'], 'key' => $input['key'], 'label' => $input['label'], 'attributes' => $attributes)); Notify::success(__('extend.field_created')); return Response::redirect('admin/extend/fields'); }); /* Edit Field */ Route::get('admin/extend/fields/edit/(:num)', function ($id) { $vars['messages'] = Notify::read(); $vars['token'] = Csrf::token(); $extend = Extend::find($id); if ($extend->attributes) { $extend->attributes = Json::decode($extend->attributes); } $vars['field'] = $extend; return View::create('extend/fields/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); }); Route::post('admin/extend/fields/edit/(:num)', function ($id) { $input = Input::get(array('type', 'field', 'key', 'label', 'attributes')); if (empty($input['key'])) { $input['key'] = $input['label']; } $input['key'] = slug($input['key'], '_'); $validator = new Validator($input); $validator->add('valid_key', function ($str) use($id, $input) { return Extend::where('key', '=', $str)->where('type', '=', $input['type'])->where('id', '<>', $id)->count() == 0; }); $validator->check('key')->is_max(1, __('extend.key_missing'))->is_valid_key(__('extend.key_exists')); $validator->check('label')->is_max(1, __('extend.label_missing')); if ($errors = $validator->errors()) { Input::flash(); Notify::error($errors); return Response::redirect('admin/extend/fields/add'); } if ($input['field'] == 'image') { $attributes = Json::encode($input['attributes']); } else { if ($input['field'] == 'file') { $attributes = Json::encode(array('attributes' => array('type' => $input['attributes']['type']))); } else { $attributes = ''; } } Extend::update($id, array('type' => $input['type'], 'field' => $input['field'], 'key' => $input['key'], 'label' => $input['label'], 'attributes' => $attributes)); Notify::success(__('extend.field_updated')); return Response::redirect('admin/extend/fields/edit/' . $id); }); /* Delete Field */ Route::get('admin/extend/fields/delete/(:num)', function ($id) { $field = Extend::find($id); Query::table(Base::table($field->type . '_meta'))->where('extend', '=', $field->id)->delete(); $field->delete(); Notify::success(__('extend.field_deleted')); return Response::redirect('admin/extend/fields'); }); });