diff options
Diffstat (limited to 'public/app/routes')
| -rw-r--r-- | public/app/routes/.gitkeep | 0 | ||||
| -rw-r--r-- | public/app/routes/backend.php | 113 | ||||
| -rw-r--r-- | public/app/routes/frontend.php | 209 |
3 files changed, 153 insertions, 169 deletions
diff --git a/public/app/routes/.gitkeep b/public/app/routes/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/public/app/routes/.gitkeep diff --git a/public/app/routes/backend.php b/public/app/routes/backend.php index 475f52b..ed02295 100644 --- a/public/app/routes/backend.php +++ b/public/app/routes/backend.php @@ -5,17 +5,25 @@ use app\controllers\admin\Course_admin; use app\models\admin\Privilege_model; use app\extends\Cache_service; + +/** admin pages + * ----------------------------------------------------------------------------- + * NOTE: + * All adminitration routes MUST INCLUDE an Auth::allowRoles() check + */ + // admin panel -// --- -Route::add('/admin', function () { +//////////////////////////////////////////////////////////////////////////////// + +Route::add('/admin', function () { // admin panel Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles Render::view('admin/skeleton', [ 'title' => 'Διαχείριση Classroom', 'action' => 'panel', ]); }); -Route::add('/admin/panel', function () { - Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles +Route::add('/admin/panel', function () { // admin panel #2 + Auth::allowRoles([1, 2, 3]); Render::view('admin/skeleton', [ 'title' => 'Διαχείριση Classroom', 'action' => 'panel', @@ -24,8 +32,9 @@ Route::add('/admin/panel', function () { // admin lessons -// --- -Route::add('/admin/lessons', function () { +//////////////////////////////////////////////////////////////////////////////// + +Route::add('/admin/lessons', function () { // request admin-lessons page Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles Render::view('admin/skeleton', [ 'title' => 'Διαχείριση Μαθημάτων', @@ -34,12 +43,11 @@ Route::add('/admin/lessons', function () { }); -// admin categories (=courses) ///////////////////////////////////////////////// -// ----------------------------------------------------------------------------- +// admin categories (=courses) +//////////////////////////////////////////////////////////////////////////////// -// manage categories page -// --- -Route::add('/admin/categories', function () { + +Route::add('/admin/categories', function () { // manage categories page Auth::allowRoles([1, 2, 3]); Render::view('admin/skeleton', [ 'title' => 'Διαχείριση Κεφαλαίων', @@ -48,37 +56,29 @@ Route::add('/admin/categories', function () { }); -// ajax: get all categories (courses; with breadcrumbs) -// --- -Route::add('/admin/api/categories', function () { + +Route::add('/admin/api/categories', function () { // ajax: get all courses; with breadcrumbs Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles Course_admin::breadcrumbs(); }); - -// ajax: add new category (course) -// --- -Route::add('/admin/api/categories/add', function () { - Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles +Route::add('/admin/api/categories/add', function () { // ajax: add new category (course) + Auth::allowRoles([1, 2, 3]); Course_admin::add_course(); }, 'post'); -// ajax: edit category (course) -// --- -Route::add('/admin/api/categories/update', function () { - Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles - Course_admin::update_course(); - }, - 'post' -); +Route::add('/admin/api/categories/update', function () { // ajax: edit category (course) + Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles + Course_admin::update_course(); +}, +'post'); -// admin privileges //////////////////////////////////////////////////////////// -// ----------------------------------------------------------------------------- +// admin privileges +//////////////////////////////////////////////////////////////////////////////// -// manage privileges page -// --- -Route::add('/admin/privileges', function () { + +Route::add('/admin/privileges', function () { // manage privileges page Auth::allowRoles([1, 2, 3]); Render::view('admin/skeleton', [ 'title' => 'Διαχείριση Δικαιωμάτων Πρόσβασης', @@ -88,7 +88,6 @@ Route::add('/admin/privileges', function () { // ajax: get all privileges (courses; with breadcrumbs) // use proxy (cache results); send as json -// --- Route::add('/admin/api/privileges', function () { Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles Render::json( Cache_service::privileges_hierarchy() ); @@ -100,13 +99,12 @@ Route::add('/admin/api/privileges', function () { -// admin lesson //////////////////////////////////////////////////////////////// -// ----------------------------------------------------------------------------- +// admin lesson +//////////////////////////////////////////////////////////////////////////////// -// new lesson // --- -Route::add('/admin/edit_lesson', function () { +Route::add('/admin/edit_lesson', function () { // new lesson form Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles Render::view('admin/skeleton', [ 'title' => 'Νέο Μάθημα', @@ -114,10 +112,8 @@ Route::add('/admin/edit_lesson', function () { ]); }); -// edit lesson (give lesson-id) -// --- -Route::add('/admin/edit_lesson/([0-9]*)', function ($id) { - Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles +Route::add('/admin/edit_lesson/([0-9]*)', function ($id) { // edit lesson form + Auth::allowRoles([1, 2, 3]); Render::view('admin/skeleton', [ 'title' => 'Επεξεργασία Μαθήματος', 'action' => 'edit_lesson', @@ -125,39 +121,35 @@ Route::add('/admin/edit_lesson/([0-9]*)', function ($id) { ]); }); -// ajax: get lesson -// --- -Route::add('/admin/api/lesson/([0-9]*)', function ($id) { + +Route::add('/admin/api/lesson/([0-9]*)', function ($id) { // ajax: get lesson Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles Course_admin::get_lesson($id); }); -// ajax: add lesson -// --- -Route::add('/admin/api/lesson/add', function () { + +Route::add('/admin/api/lesson/add', function () { // ajax: add lesson Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles Course_admin::add_lesson(); }, 'post'); -// ajax: update lesson -// --- -Route::add('/admin/api/lesson/update', function () { + +Route::add('/admin/api/lesson/update', function () { // ajax: update lesson Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles Course_admin::update_lesson(); }, 'post'); -// ajax: get all lessons -// --- -Route::add('/admin/api/lessons', function () { + +Route::add('/admin/api/lessons', function () { // ajax: get all lessons Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles Course_admin::all_lessons(); }); -// admin files ///////////////////////////////////////////////////////////////// +// admin files //////////////////////////////////////////////////////////////////////////////// -Route::add('/admin/files', function () { +Route::add('/admin/files', function () { // admin-files panel Auth::allowRoles([1, 2, 3]); Render::view('admin/skeleton', [ 'title' => 'Διαχείριση Μέσων (media)', @@ -165,10 +157,9 @@ Route::add('/admin/files', function () { ]); }); -// ajax: get lesson -// --- -Route::add('/admin/api/files', function () { - Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles + +Route::add('/admin/api/files', function () { // ajax: get lesson + Auth::allowRoles([1, 2, 3]); Render::json(Course_admin::files()); }); @@ -179,7 +170,3 @@ Route::add('/admin/api/file_upload', function () { Render::json(Course_admin::upload_file()); }, 'post'); - - - - diff --git a/public/app/routes/frontend.php b/public/app/routes/frontend.php index f9e74db..33fe401 100644 --- a/public/app/routes/frontend.php +++ b/public/app/routes/frontend.php @@ -6,22 +6,45 @@ use app\controllers\cms\Course; use app\models\cms\Course_model; use app\extends\Cache_service; + // Home/Welcome -// --- -Route::add('/', function() { // echo 'Welcome!'; }); - Render::view('welcome', [ // cache categories (while retrieving) +//////////////////////////////////////////////////////////////////////////////// + +Route::add('/', function() { + Render::view('welcome', [ 'categories' => Cache_service::courses_struct()['tree'] ]); - // header('Location: /some/default/url', true, 302); + // need redirect?... header('Location: /some/default/url', true, 302); }); -// Error Pages -// --- -Route::notFound( function() { +// Error pages +//////////////////////////////////////////////////////////////////////////////// + +Route::notFound( function() { // 404 error page header("HTTP/1.0 404 Not Found"); Render::view('error/404', ['message' => 'nobody knows it (but you got a secret smile;)']); -}); // 404 +}); + + + +// Common content +//////////////////////////////////////////////////////////////////////////////// + + +Route::add('/course/([0-9]*)', // request course by course-id + function($id) { Course::course($id); } +); + +Route::add('/lesson/([0-9]*)', // request lesson by lesson-id + function($id) { Course::lesson($id); } +); + +Route::add('/serve/file/([0-9a-zA-Z-_\.\/]*)', // serve file by path + function ($path) { Course::serve_file($path); } // (also ?type= is sent) +); + + @@ -42,36 +65,8 @@ Route::notFound( function() { -// Resolve urls -// --- -- -- - - - -Route::add('/course/([0-9]*)', - function($id) { Course::course($id); } -); - -Route::add('/lesson/([0-9a-f]*)/([0-9a-zA-Z-_]*)', - function($ticket, $lesson) { Lesson::show([$lesson, $ticket]); } -); - -Route::add('/media/([0-9a-f]*)/([0-9a-zA-Z-_]*)/([0-9]*)/', - function($ticket, $type, $id) { Media::serve([$type, $id, $ticket]); } -); - - -// 4-th level paths belong to products -// --- -Route::add('/about/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', - function($a, $b, $c) { Page::show([$a, $b, $c]); } -); - - -// serve file -// --- -Route::add('/serve/file/([0-9a-zA-Z-_\.\/]*)', function ($path) { - Course::serve_file($path); -}); - -/** URL-format Proposal: +/** URL-format Proposals and common Route regex solutions * ----------------------------------------------------------------------------- * * Page (almost-static content): @@ -88,80 +83,82 @@ Route::add('/serve/file/([0-9a-zA-Z-_\.\/]*)', function ($path) { * * Category * /{category}/[ {subcategory}[ /{group}]] -Route::add('/([0-9a-zA-Z-_]*)', function($a) { Category::url([$a]); }; -Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b) { Category::url([$a, $b]); }); -Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b, $c) { Category::url([$a, $b, $c]); }); - * ----------------------------------------------------------------------------- - */ - +# Route::add('/([0-9a-zA-Z-_]*)', function($a) { Category::url([$a]); }; +# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b) { Category::url([$a, $b]); }); +# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b, $c) { Category::url([$a, $b, $c]); }); + * + * othet routes used in some user-cases -/* EXAMPLES (use it for brainsrtorming) +# Route::add('/lesson/([0-9a-f]*)/([0-9a-zA-Z-_]*)', +# function($ticket, $lesson) { Lesson::show([$lesson, $ticket]); } +# ); +# +# Route::add('/media/([0-9a-f]*)/([0-9a-zA-Z-_]*)/([0-9]*)/', +# function($ticket, $type, $id) { Media::serve([$type, $id, $ticket]); } +# ); + * + * 4-th level paths belong to products +# Route::add('/about/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', +# function($a, $b, $c) { Page::show([$a, $b, $c]); } +# ); + * + * + * OTHER EXAMPLES (use it for brainsrtorming) * ----------------------------------------------------------------------------- * - // Typical Use - // --- - Route::add('/art', function() { Art::blah(); }); - Route::add('/art/db', function() { Art::fromDatabase(); }); - Route::add('/art/([0-9]*)', function($id) { Art::getInfo($id); }); - - - // Get-Post route example - // --- - Route::add('/contact-form', function() { - echo '<form method="post"><input type="text" name="test" /><input type="submit" value="send" /></form>'; - }, 'get'); + * +# // Typical Use +# // --- +# Route::add('/art', function() { Art::blah(); }); +# Route::add('/art/db', function() { Art::fromDatabase(); }); +# Route::add('/art/([0-9]*)', function($id) { Art::getInfo($id); }); + * + * Get-Post route example +# Route::add('/contact-form', function() { +# echo '<form method="post"><input type="text" name="test" /><input type="submit" value="send" /></form>'; +# }, 'get'); Route::add('/contact-form', function() { echo 'Hey! The form has been sent:<br/>'; print_r($_POST); }, 'post'); - - - // Accept number as parameter - // --- - Route::add('/foo/([0-9]*)/bar', function($var1) { - // echo $var1.' is a number!'; + * + * Accept number as parameter +# Route::add('/foo/([0-9]*)/bar', function($var1) { +# // echo $var1.' is a number!'; echo "{$var1} is a number!"; - }); - - - // About pages - // --- - Route::add('/about/([0-9a-zA-Z-_]*)', function($page) { - InfoPage::render('about/'.page); - }); - - - // handle a request like: /foo/123/bar/3254-lefki-zaxari-marata-1kg - // where first-numeric-part of last-uri-section (3254) is the product number - // --- - Route::add('/foo/([0-9]*)/bar/([0-9]*)-([0-9a-zA-Z-_]*)', function($num, $id, $name) { - echo $num .' is some nomber, id = '. $id .' and label = '. $name; - }); - - - // handle a request like: /zaxares-glykantika/lefki-zaxari-year-2022-45678 - // where last-numeric-part of last-uri-section (45678) is the product number - // --- - Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)-([0-9]*)', - function($category, $subcategory, $group, $label, $id) { - Shop::product([$$category, $subcategory, $group, $label], $id); - }); - - - // last chance to resolve (some friendly url) - // --- - Route::add('/([0-9a-zA-Z-_]*)', function($a) { Resolve::uri([$a]); }); - Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b) { Resolve::uri([$a, $b]); }); - Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b, $c) { Resolve::uri([$a, $b, $c]); }); - - - // Product page - // handle a request like: /pantopoleio/zaxares/lefki-zaxari/lefki-zaxari-year-2022-45678 - // where last-numeric-part of last-uri-section (45678) is the product number - // --- - Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)-([0-9]*)', - function($category, $subcategory, $group, $label, $id) { - Shop::product([$$category, $subcategory, $group, $label], $id); - }); -* ------------------------------------------------------------------------------ -*/ +# }); + * + * About pages +# Route::add('/about/([0-9a-zA-Z-_]*)', function($page) { +# InfoPage::render('about/'.page); +# }); + * + * handle a request like: /foo/123/bar/3254-lefki-zaxari-marata-1kg + * where first-numeric-part of last-uri-section (3254) is the product number +# Route::add('/foo/([0-9]*)/bar/([0-9]*)-([0-9a-zA-Z-_]*)', function($num, $id, $name) { +# echo $num .' is some nomber, id = '. $id .' and label = '. $name; +# }); + * + * handle a request like: /zaxares-glykantika/lefki-zaxari-year-2022-45678 + * where last-numeric-part of last-uri-section (45678) is the product number +# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)-([0-9]*)', +# function($category, $subcategory, $group, $label, $id) { +# Shop::product([$$category, $subcategory, $group, $label], $id); +# }); + * + * last chance to resolve (some friendly url) +# Route::add('/([0-9a-zA-Z-_]*)', function($a) { Resolve::uri([$a]); }); +# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b) { Resolve::uri([$a, $b]); }); +# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b, $c) { Resolve::uri([$a, $b, $c]); }); + * + * + * Product page + * handle a request like: /pantopoleio/zaxares/lefki-zaxari/lefki-zaxari-year-2022-45678 + * where last-numeric-part of last-uri-section (45678) is the product number +# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)-([0-9]*)', +# function($category, $subcategory, $group, $label, $id) { +# Shop::product([$$category, $subcategory, $group, $label], $id); +# }); + * + * ------------------------------------------------------------------------------ + */ |
