diff options
18 files changed, 121 insertions, 213 deletions
@@ -1,8 +1,8 @@ # x-anom (another MVC framework) -An open-source, fast, small, secure, full-featured, modern, easy to setup, easy to learn, -easy to extend, php 8+, OOP, MVC framework +An open-source, fast, super-light, secure, full-featured, modern, easy to setup, easy to learn, +highly extendable, php 8+, OOP MVC framework for the php-developer. diff --git a/core/README.md b/core/README.md index 8dee940..2fdd951 100644 --- a/core/README.md +++ b/core/README.md @@ -19,8 +19,25 @@ Main advantages of the framework: * Some webserver (Apache/Nginx) * Some SQL server (MySQL/MariaDB/Postgress) * Basic knowledge of php and SQL +* Baasic knowlege of OOP +### Code standards + +Amon uses the PSR-1 code standard with a few enchansements: + +Controllers are named like + + class SomeController + // or... + class SomeController_something + +where ```something``` indicates some special operational role of the contoller +ex. ```_user```, ```_service```, ```manager``` etc + +As a result all model classes are suffixed with ```_model```: + + class SomeModelName_model; ### What is included diff --git a/public/app/controllers/Admin.php b/public/app/controllers/Admin.php deleted file mode 100644 index 6f6858c..0000000 --- a/public/app/controllers/Admin.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php -namespace app\controllers; - -use Registry; -use Render; - -// user classes and models -use app\extends\Classroom_user; -use app\extends\Classroom_manager; -use app\models\admin\User_model; - -use app\extends\Send_mail; -use app\extends\Mail_jet; - - -/** class Auth - * - * handles user's Authentication and Authorizarion - * - */ -class Admin { - - /** admin cateogories - * - */ - public static function categories() - { - Render::view('admin/categories'); - } - - - /** admin lessons - * - */ - public static function lessons() - { - - } - - - /** admin pages - * - */ - public static function pages() - { - - } - - /** admin users - * - */ - public static function users() - { - - } - - -}
\ No newline at end of file diff --git a/public/app/controllers/Auth.php b/public/app/controllers/Auth.php index 4a6b9ed..aeec41c 100644 --- a/public/app/controllers/Auth.php +++ b/public/app/controllers/Auth.php @@ -7,7 +7,7 @@ use Render; // user classes and models use app\extends\Classroom_user; use app\extends\Classroom_manager; -use app\models\admin\User_model; +use app\models\User_model; use app\extends\Send_mail; use app\extends\Mail_jet; diff --git a/public/app/controllers/cms/Course.php b/public/app/controllers/Cms.php index ad8a0fb..306bc88 100644 --- a/public/app/controllers/cms/Course.php +++ b/public/app/controllers/Cms.php @@ -1,14 +1,21 @@ <?php -namespace app\controllers\cms; +namespace app\controllers; use Registry; use Render; use app\controllers\Auth; -use app\models\cms\Course_model; +use app\models\Cms_model; use app\extends\Cache_service; -class Course { +/** CMS class + * (Content Management System) + * + * Serves the content; + * Reponds to all front-end front-office requests + * + */ +class Cms { ## PERMITION @@ -120,7 +127,7 @@ class Course { $cache = Cache_service::courses_struct(); $tree = $cache['tree']; $breadcrumbs = $cache['breadcrumbs']; - $lessons = Course_model::lessons_of_course(intval($id)); + $lessons = Cms_model::lessons_of_course(intval($id)); // find parent_ids of current category (to open the menu tree) // --- @@ -162,7 +169,7 @@ class Course { { $id = intval($id); // lesson id - $lesson = Course_model::lesson($id); // get lesson + $lesson = Cms_model::lesson($id); // get lesson $course_id = $lesson['course_id']; // get course id $pri_id = $lesson['privilege_id']; // privilege needed @@ -219,6 +226,10 @@ class Course { } + ## PAGES + ## ------------------------------------------------------------------------- + + /** lesson * * check if user is authorized to view the content; @@ -245,7 +256,4 @@ class Course { } - - - -}
\ No newline at end of file +} diff --git a/public/app/controllers/admin/Course_admin.php b/public/app/controllers/CmsAdmin.php index fcf38c9..aa6ff6f 100644 --- a/public/app/controllers/admin/Course_admin.php +++ b/public/app/controllers/CmsAdmin.php @@ -4,10 +4,10 @@ namespace app\controllers\admin; use Registry; use Render; -use app\models\cms\Course_model; +use app\models\Cms_model; use app\extends\Cache_service; -class Course_admin { +class CmsAdmin { ## ------------------------------------------------------------------------- diff --git a/public/app/controllers/admin/.gitkeep b/public/app/controllers/admin/.gitkeep deleted file mode 100644 index e69de29..0000000 --- a/public/app/controllers/admin/.gitkeep +++ /dev/null diff --git a/public/app/controllers/admin/Users_admin.php b/public/app/controllers/admin/Users_admin.php deleted file mode 100644 index 4e335c1..0000000 --- a/public/app/controllers/admin/Users_admin.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -namespace app\controllers\admin; - -use Registry; -use Render; - - -class Users_admin { - - /** privileges - * --- - * get all privileges - * - * @param void - * @return privileges (array) - */ - public static function privileges() - { - return Registry::use('database')->runQuery( - "SELECT * FROM privilege",[] - ); - } - - /** edit privileges - * --- - */ - public static function edit_privileges() - { - // TODO: ... - } - - - /** update course - * --- - */ - public static function update_course() - { - // TODO: ... - } - -}
\ No newline at end of file diff --git a/public/app/controllers/cli/CliContoller.php b/public/app/controllers/cli/CliContoller.php index 4549b50..949985d 100644 --- a/public/app/controllers/cli/CliContoller.php +++ b/public/app/controllers/cli/CliContoller.php @@ -39,12 +39,12 @@ class CliContoller if (php_sapi_name() != 'cli') return false; # PROXY call: - # CMS \ Course_model::courses_struct(): + # CMS \ Cms_model::courses_struct(): # + Refresh Cache # -------------------------------------- echo textColor("Creating category_products tree Cache ... ", \NORMAL); $reply = proxy( - [\app\models\cms\Course_model::class, 'courses_struct'], + [\app\models\Cms_model::class, 'courses_struct'], [], \CACHE_ROOT_TTL, \PROXY_IGNORE_CACHE ); diff --git a/public/app/extends/Cache_service.php b/public/app/extends/Cache_service.php index 52311f3..e372e1e 100644 --- a/public/app/extends/Cache_service.php +++ b/public/app/extends/Cache_service.php @@ -1,7 +1,7 @@ <?php namespace app\extends; -use app\models\cms\Course_model; +use app\models\Cms_model; use app\models\admin\Privilege_model; /** Cache service @@ -20,7 +20,7 @@ class Cache_service public static function courses_struct( $options = 0 ) { return proxy( // cache-get courses - [\app\models\cms\Course_model::class, 'courses_struct'], + [\app\models\Cms_model::class, 'courses_struct'], [], CACHE_ROOT_TTL, $options ); @@ -29,7 +29,7 @@ class Cache_service public static function files_attributes( $options = 0 ) { return proxy( - [\app\models\cms\Course_model::class, 'files'], + [\app\models\Cms_model::class, 'files'], [], CACHE_ROOT_TTL, $options ); @@ -48,7 +48,7 @@ class Cache_service public static function pages_list( $options = 0 ) { return proxy( - [\app\models\cms\Course_model::class, 'pages'], + [\app\models\Cms_model::class, 'pages'], [], CACHE_ROOT_TTL, $options ); @@ -72,7 +72,7 @@ class Cache_service // TODO: needs testing before release // return proxy( - // [\app\models\admin\Course_model::class, $entity], + // [\app\models\Cms_model::class, $entity], // [], CACHE_ROOT_TTL, // $options // ); diff --git a/public/app/models/cms/Course_model.php b/public/app/models/Cms_model.php index 6614993..fad11b8 100644 --- a/public/app/models/cms/Course_model.php +++ b/public/app/models/Cms_model.php @@ -1,10 +1,10 @@ <?php -namespace app\models\cms; +namespace app\models; use \Registry; -class Course_model { +class Cms_model { /** COURSES * ------------------------------------------------------------------------- @@ -143,7 +143,7 @@ class Course_model { * * NOTE: * --- - * Course_model::all_breadcrumbs returns an indexed super-array; + * Cms_model::all_breadcrumbs returns an indexed super-array; * each array item includes a banch of information: [ * breadcrumb, * rec: [ id , title ], diff --git a/public/app/models/admin/User_model.php b/public/app/models/User_model.php index 2885dc1..f799dd9 100644 --- a/public/app/models/admin/User_model.php +++ b/public/app/models/User_model.php @@ -1,13 +1,16 @@ <?php -namespace app\models\admin; +namespace app\models; use \Registry; -use app\models\admin\History_model as History; +use app\models\admin\History_model; class User_model { + ## User methods + ## ------------------------------------------------------------------------- + /** check user (by index key) * * @param $indexKey (string) : key for user identification @@ -165,7 +168,7 @@ class User_model self::set_user_role($new_user_id, 5); // update history - History::trackUserAccess($new_user_id, TRACK_ACCOUNT, 'Create User Account'); + History_model::trackUserAccess($new_user_id, TRACK_ACCOUNT, 'Create User Account'); // return success and user id return [ @@ -176,6 +179,11 @@ class User_model } + + ## Set permission methods + ## ------------------------------------------------------------------------- + + /** set_user_privileges * * @param $privileges (array) @@ -236,13 +244,17 @@ class User_model ); // update history - History::trackUserAccess($user['id'], TRACK_ACCOUNT, 'User Account Activated'); + History_model::trackUserAccess($user['id'], TRACK_ACCOUNT, 'User Account Activated'); return true; } + ## documention methods + ## methods related to properties that determin user's access + ##-------------------------------------------------------------------------- + } /* example query getUser (super-array) diff --git a/public/app/models/cms/Media_model.php b/public/app/models/cms/Media_model.php deleted file mode 100644 index 6a4a681..0000000 --- a/public/app/models/cms/Media_model.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -namespace app\models\cms; - -use \Registry; - - -class Media_model -{ - public static function serve($type, $id, $ticket) - { - - // get media data - // [ type =>, rights =>, path => ] - - // validate ticket - // ValidateAccess::for($ticket) - - // serve - // header("Content-type: type"); - // passthru('cat $media_path'); - - - return Registry::use('database')->query( - "SELECT * FROM pages - WHERE FullFriendlyUrl = :url AND IsActive = 1", - [ ':url' => $url ] - )->getFirst(); - } - -} - - - -// check: -// https://stackoverflow.com/questions/1353850/serve-image-with-php-script-vs-direct-loading-an-image
\ No newline at end of file diff --git a/public/app/models/cms/Page_model.php b/public/app/models/cms/Page_model.php deleted file mode 100644 index fda5fb1..0000000 --- a/public/app/models/cms/Page_model.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -namespace app\models\cms; - -use \Registry; - -class Page_model -{ - public static function fromUrl($url) - { - return Registry::use('database')->query( - "SELECT * FROM pages - WHERE FullFriendlyUrl = :url AND IsActive = 1", - [ ':url' => $url ] - )->getFirst(); - } - -}
\ No newline at end of file diff --git a/public/app/models/ideas.md b/public/app/models/ideas.md new file mode 100644 index 0000000..300612d --- /dev/null +++ b/public/app/models/ideas.md @@ -0,0 +1,24 @@ +# interesting projects + +projects for brainstorming + +## php ORM projects + +* [riverside\php-orm](https://github.com/riverside/php-orm) seems the lightest and most promissing + +* https://github.com/mareimorsy/DB + +* https://propelorm.org/ + +* https://redbeanphp.com/index.php?p=/download + +* you can find more in a [related github topic](https://github.com/topics/php-orm) + + +Thoughts: +create a DatabaseModel class (??) based on the riverside\php-orm then use it in anom framerok + + +## php micro-framework + +* [riverside\php-express](https://github.com/riverside/php-express) seems quite interesting diff --git a/public/app/models/todo.md b/public/app/models/todo.md index 89ea113..5a18f38 100644 --- a/public/app/models/todo.md +++ b/public/app/models/todo.md @@ -3,36 +3,38 @@ Rearange -- #1 -- -app\controllers\cms\Course -> [*] app\controllers\Course +[ok] app\controllers\cms\Course -> [*] app\controllers\Course -app\controllers\admin\Users_admin -> [delete] +[ok] app\controllers\admin\Users_admin -> [delete] -app\controllers\Admin -> [delete] +[ok] app\controllers\Admin -> [delete] -app\controllers\admin\Course_admin -> [*] app\controllers\Course_admin +[ok] app\controllers\admin\Course_admin -> [*] app\controllers\Course_admin -app\models\admin\User_model -> [*] app\models\User_model +[ok] app\models\admin\User_model -> [*] app\models\User_model app\models\admin\Privilege_model -> [merge_to] -> [**] app\models\User_model app\models\admin\History_model -> [*] app\models\History_model -app\models\cms\Page_model -> [delete] +[ok] app\models\cms\Page_model -> [delete] -app\models\cms\Media_model -> [delete] +[ok] app\models\cms\Media_model -> [delete] -app\models\cms\Course_model -> [*] app\models\Course_model +[ok] app\models\cms\Course_model -> [*] app\models\Course_model [*] = move -- #2 -- -app\controllers\Course -> [r] app\controllers\Cms +[ok] app\controllers\Course -> [rename] app\controllers\Cms + +[ok] app\controllers\Course_admin -> [rename] app\controllers\CmsAdmin + +[ok] app\models\Course_model -> [rename] app\models\Cms_model -app\controllers\Course_admin -> [r] app\controllers\Cms_admin -app\models\Course_model -> app\models\Cms_model diff --git a/public/app/routes/backend.php b/public/app/routes/backend.php index 2bbd056..027c50a 100644 --- a/public/app/routes/backend.php +++ b/public/app/routes/backend.php @@ -1,7 +1,7 @@ <?php use app\controllers\Auth; -use app\controllers\admin\Course_admin; +use app\controllers\CmsAdmin; use app\models\admin\Privilege_model; use app\extends\Cache_service; @@ -45,17 +45,17 @@ Route::add('/admin/categories', function () { // manage categories page 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(); + CmsAdmin::breadcrumbs(); }); Route::add('/admin/api/categories/add', function () { // ajax: add new category (course) Auth::allowRoles([1, 2, 3]); - Course_admin::add_course(); + CmsAdmin::add_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(); + CmsAdmin::update_course(); }, 'post'); @@ -116,25 +116,25 @@ Route::add('/admin/edit_lesson/([0-9]*)', function ($id) { // edit lesson f 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); + CmsAdmin::get_lesson($id); }); Route::add('/admin/api/lesson/add', function () { // ajax: add lesson Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles - Render::json(['success' => Course_admin::add_lesson()]); + Render::json(['success' => CmsAdmin::add_lesson()]); }, 'post'); Route::add('/admin/api/lesson/update', function () { // ajax: update lesson Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles - Render::json(['success' => Course_admin::update_lesson()]); + Render::json(['success' => CmsAdmin::update_lesson()]); }, 'post'); Route::add('/admin/api/lessons', function () { // ajax: get all lessons Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles - Course_admin::all_lessons(); + CmsAdmin::all_lessons(); }); @@ -153,14 +153,14 @@ Route::add('/admin/files', function () { // admin-files panel Route::add('/admin/api/files', function () { // ajax: get lesson Auth::allowRoles([1, 2, 3]); - Render::json(Course_admin::files()); + Render::json(CmsAdmin::files()); }); // ajax: file-upload // --- Route::add('/admin/api/file_upload', function () { Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles - Render::json(Course_admin::upload_file()); + Render::json(CmsAdmin::upload_file()); }, 'post'); @@ -198,24 +198,24 @@ Route::add('/admin/edit_page/([0-9]*)', function ($id) { // edit page form Route::add('/admin/api/page/([0-9]*)', function ($id) { // ajax: get page Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles - Course_admin::get_page($id); + CmsAdmin::get_page($id); }); Route::add('/admin/api/page/add', function () { // ajax: add page Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles - Render::json(['success' => Course_admin::add_page()]); + Render::json(['success' => CmsAdmin::add_page()]); }, 'post'); Route::add('/admin/api/page/update', function () { // ajax: update page Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles - Render::json(['success' => Course_admin::update_page()]); + Render::json(['success' => CmsAdmin::update_page()]); }, 'post'); Route::add('/admin/api/pages', function () { // ajax: get all pages Auth::allowRoles([1, 2, 3]); // allow few admin-panel roles - Course_admin::all_pages(); + CmsAdmin::all_pages(); }); diff --git a/public/app/routes/frontend.php b/public/app/routes/frontend.php index be06b1c..96e9786 100644 --- a/public/app/routes/frontend.php +++ b/public/app/routes/frontend.php @@ -2,8 +2,7 @@ use app\controllers\Auth; use app\controllers\Classroom_user; -use app\controllers\cms\Course; -use app\models\cms\Course_model; +use app\controllers\Cms; use app\extends\Cache_service; @@ -34,19 +33,19 @@ Route::notFound( function() { // 404 error page Route::add('/course/([0-9]*)', // request course by course-id - function($id) { Course::course($id); } + function($id) { Cms::course($id); } ); Route::add('/lesson/([0-9]*)', // request lesson by lesson-id - function($id) { Course::lesson($id); } + function($id) { Cms::lesson($id); } ); Route::add('/page/([0-9]*)', // request lesson by lesson-id - function($id) { Course::page($id); } + function($id) { Cms::page($id); } ); Route::add('/serve/file/([0-9a-zA-Z-_\.\/]*)', // serve file by path - function ($path) { Course::serve_file($path); } // (also ?type= is sent) + function ($path) { Cms::serve_file($path); } // (also ?type= is sent) ); |
