Powerful and easy to use cms to build websites, blogs or ecommerce stores.
HTML backendblogblog-engineblog-platformbloggingcmscontent-managementcontent-management-systemecommerceecommerce-platformno-codepage-builderphpphp-cmsphp7php8self-hostedshopping-cartweb-applicationwebsite-builder
Rest API
givanzbae342b32306
diff --git a/config/rest-routes.php b/config/rest-routes.phpindex 4c160b6..8868afb 100644--- a/config/rest-routes.php+++ b/config/rest-routes.php@@ -24,38 +24,38 @@ return ['/rest/' => ['module' => 'index'],//posts- '/rest/posts' => ['module' => 'posts'],- '/rest/posts/#post_id#' => ['module' => 'posts/post/index'],- '/rest/posts/{slug}' => ['module' => 'posts/post/index'],+ '/rest/posts' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'post'],+ '/rest/posts/#post_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'post'],+ '/rest/posts/{slug}' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'post'],//revisions- '/rest/posts/#post_id#/revisions' => ['module' => 'posts/revisions/index'],- '/rest/posts/#post_id#/revisions/{created_at}' => ['module' => 'posts/revision/index'],+ '/rest/posts/#post_id#/revision' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'post_content_revision'],+ '/rest/posts/#post_id#/revision/{created_at}' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'post_content_revision'],//pages//comments- '/rest/posts/#post_id#/comments' => ['module' => 'posts/comments/index'],- '/rest/posts/#post_id#/comments/{created_at}' => ['module' => 'posts/comment/index'],+ '/rest/posts/#post_id#/comment' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'comment'],+ '/rest/posts/#post_id#/comment/{created_at}' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'comment'],//media'/rest/media' => ['module' => 'media'],'/rest/media/{file}' => ['module' => 'media/media/index'],//menus- '/rest/menus' => ['module' => 'menus'],- '/rest/menus/{menu_id}' => ['module' => 'menus/v/index'],+ '/rest/menus' => ['module' => 'menu'],+ '/rest/menus/{menu_id}' => ['module' => 'menu/menu/index'],//menu-items- '/rest/menu-items' => ['module' => 'menu-items'],- '/rest/menu-items/{menu_id}' => ['module' => 'menu-items/menu-items/index'],+ '/rest/menu-items' => ['module' => 'menu-item'],+ '/rest/menu-items/{menu_id}' => ['module' => 'menu-item/menu-item/index'],- //taxonomies- '/rest/taxonomies' => ['module' => 'taxonomies'],- '/rest/taxonomies/{menu_id}' => ['module' => 'taxonomies/taxonomies/index'],+ //taxonomy+ '/rest/taxonomies/' => ['module' => 'taxonomy'],+ '/rest/taxonomies//{menu_id}' => ['module' => 'taxonomy/taxonomy/index'],//tags//categories//users- '/rest/users' => ['module' => 'users'],- '/rest/users/#user_id#' => ['module' => 'users/user/index'],+ '/rest/users' => ['module' => 'user'],+ '/rest/users/#user_id#' => ['module' => 'user/user/index'],//search'/rest/search' => ['module' => 'search'],@@ -64,41 +64,148 @@ return ['/rest/settings' => ['module' => 'settings'],//themes- '/rest/themes' => ['module' => 'settings'],- '/rest/themes/{slug}' => ['module' => 'themes/themes/index'],+ '/rest/themes' => ['module' => 'theme'],+ '/rest/themes/{slug}' => ['module' => 'theme/theme/index'],//plugins- '/rest/plugins' => ['module' => 'plugins'],- '/rest/plugins/{slug}' => ['module' => 'plugins/plugins/index'],+ '/rest/plugins' => ['module' => 'plugin'],+ '/rest/plugins/{slug}' => ['module' => 'plugin/plugin/index'],//languages//ecommerce- //products- '/rest/products' => ['module' => 'products'],- '/rest/products/#product_id#' => ['module' => 'products/product/index'],- '/rest/products/{slug}' => ['module' => 'products/products/index'],-- //product attributes- //product reviews- //product questions- //taxonomies- //tags- //categories+ //cart+ '/rest/cart' => ['module' => 'cart/cart/', 'methods' => ['get', 'post']],+ '/rest/cart/{key}' => ['module' => 'cart/cart', 'methods' => ['get', 'post', 'put', 'patch', 'delete']],+ '/rest/cart/#product_id#' => ['module' => 'cart/cart', 'methods' => ['get', 'post', 'put', 'patch', 'delete']],- //orders- //coupons- //tax rates- //tax classes- //tax types- //returns- //zones- //countries- //currencies-- //payment methods- //shipping methods-- //stats+ //products+ '/rest/products' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'product'],+ '/rest/products/#product_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'product'],+ '/rest/products/{slug}' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'product'],++ '/rest/admin' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'admin'],+ '/rest/admin/#admin_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'admin'],+ '/rest/attributes' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'attribute'],+ '/rest/attributes/#attribute_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'attribute'],+ '/rest/attribute_groups' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'attribute_group'],+ '/rest/attribute_groups/#attribute_group_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'attribute_group'],+ '/rest/countries' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'country'],+ '/rest/countries/#country_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'country'],+ '/rest/coupons' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'coupon'],+ '/rest/coupons/#coupon_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'coupon'],+ '/rest/currencies' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'currency'],+ '/rest/currencies/#currency_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'currency'],+ '/rest/digital_assets' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'digital_asset'],+ '/rest/digital_assets/#digital_asset_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'digital_asset'],+ '/rest/digital_asset_logs' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'digital_asset_log'],+ '/rest/digital_asset_logs/#digital_asset_log_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'digital_asset_log'],+ '/rest/fields' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'field'],+ '/rest/fields/#field_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'field'],+ '/rest/field_groups' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'field_group'],+ '/rest/field_groups/#field_group_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'field_group'],+ '/rest/languages' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'language'],+ '/rest/languages/#language_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'language'],+ '/rest/length_types' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'length_type'],+ '/rest/length_types/#length_type_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'length_type'],+ '/rest/manufacturers' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'manufacturer'],+ '/rest/manufacturers/#manufacturer_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'manufacturer'],+ '/rest/media_content' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'media_content'],+ '/rest/media_content/#media_content_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'media_content'],+ '/rest/menus' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'menu'],+ '/rest/menus/#menu_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'menu'],+ '/rest/options' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'option'],+ '/rest/options/#option_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'option'],+ '/rest/option_value' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'option_value'],+ '/rest/option_value/#option_value_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'option_value'],+ '/rest/orders' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'order'],+ '/rest/orders/#order_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'order'],+ '/rest/order_log' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'order_log'],+ '/rest/order_log/#order_log_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'order_log'],+ '/rest/order_statuses' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'order_status'],+ '/rest/order_statuses/#order_status_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'order_status'],+ '/rest/payment_statuses' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'payment_status'],+ '/rest/payment_statuses/#payment_status_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'payment_status'],+ '/rest/post_content_meta' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'post_content_meta'],+ '/rest/post_content_meta/#post_content_meta_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'post_content_meta'],+ '/rest/post_content_revisions' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'post_content_revision'],+ '/rest/post_content_revisions/#post_content_revision_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'post_content_revision'],+ '/rest/post_meta' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'post_meta'],+ '/rest/post_meta/#post_meta_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'post_meta'],+ '/rest/product_attributes' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'product_attribute'],+ '/rest/product_attributes/#product_attribute_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'product_attribute'],+ '/rest/product_content_meta' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'product_content_meta'],+ '/rest/product_content_meta/#product_content_meta_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'product_content_meta'],+ '/rest/product_content_revision' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'product_content_revision'],+ '/rest/product_content_revision/#product_content_revision_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'product_content_revision'],+ '/rest/product_meta' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'product_meta'],+ '/rest/product_meta/#product_meta_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'product_meta'],+ '/rest/product_options' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'product_option'],+ '/rest/product_options/#product_option_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'product_option'],+ '/rest/product_option_values' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'product_option_value'],+ '/rest/product_option_values/#product_option_value_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'product_option_value'],+ '/rest/product_questions' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'product_question'],+ '/rest/product_questions/#product_question_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'product_question'],+ '/rest/product_reviews' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'product_review'],+ '/rest/product_reviews/#product_review_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'product_review'],+ '/rest/product_review_media' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'product_review_media'],+ '/rest/product_review_media/#product_review_media_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'product_review_media'],+ '/rest/product_subscriptions' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'product_subscription'],+ '/rest/product_subscriptions/#product_subscription_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'product_subscription'],+ '/rest/regions' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'region'],+ '/rest/regions/#region_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'region'],+ '/rest/region_groups' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'region_group'],+ '/rest/region_groups/#region_group_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'region_group'],+ '/rest/returns' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'return'],+ '/rest/return/#return_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'return'],+ '/rest/return_reasons' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'return_reason'],+ '/rest/return_reasons/#return_reason_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'return_reason'],+ '/rest/return_resolutions' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'return_resolution'],+ '/rest/return_resolution/#return_resolution_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'return_resolution'],+ '/rest/return_statuses' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'return_status'],+ '/rest/return_statuses/#return_status_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'return_status'],+ '/rest/roles' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'role'],+ '/rest/roles/#role_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'role'],+ '/rest/settings' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'setting'],+ '/rest/settings/#setting_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'setting'],+ '/rest/setting_content' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'setting_content'],+ '/rest/setting_content/#setting_content_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'setting_content'],+ '/rest/shipping_statuses' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'shipping_status'],+ '/rest/shipping_statuses/#shipping_status_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'shipping_status'],+ '/rest/stock_statuses' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'stock_status'],+ '/rest/stock_statuses/#stock_status_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'stock_status'],+ '/rest/subscriptions' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'subscription'],+ '/rest/subscriptions/#subscription_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'subscription'],+ '/rest/subscription_plans' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'subscription_plan'],+ '/rest/subscription_plans/#subscription_plan_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'subscription_plan'],+ '/rest/subscription_statuses' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'subscription_status'],+ '/rest/subscription_statuses/#subscription_status_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'subscription_status'],+ '/rest/taxonomies' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'taxonomy'],+ '/rest/taxonomies/#taxonomy_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'taxonomy'],+ '/rest/taxonomy_items' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'taxonomy_item'],+ '/rest/taxonomy_items/#taxonomy_item_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'taxonomy_item'],+ '/rest/tax_rates' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'tax_rate'],+ '/rest/tax_rates/#tax_rate_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'tax_rate'],+ '/rest/tax_rules' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'tax_rule'],+ '/rest/tax_rules/#tax_rule_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'tax_rule'],+ '/rest/tax_types' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'tax_type'],+ '/rest/tax_types/#tax_type_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'tax_type'],+ '/rest/users' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'user'],+ '/rest/users/#user_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'user'],+ '/rest/user_addresses' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'user_address'],+ '/rest/user_addresses/#user_address_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'user_address'],+ '/rest/user_groups' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'user_group'],+ '/rest/user_groups/#user_group_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'user_group'],+ '/rest/user_wishlists' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'user_wishlist'],+ '/rest/user_wishlists/#user_wishlist_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'user_wishlist'],+ '/rest/vendors' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'vendor'],+ '/rest/vendors/#vendor_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'vendor'],+ '/rest/vouchers' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'voucher'],+ '/rest/vouchers/#voucher_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'voucher'],+ '/rest/weight_types' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'weight_type'],+ '/rest/weight_types/#weight_type_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'weight_type'],++ '/rest/sites' => ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => 'site'],+ '/rest/sites/#site_id#' => ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => 'site'],];diff --git a/config/rest.php b/config/rest.phpnew file mode 100644index 0000000..810af1d--- /dev/null+++ b/config/rest.php@@ -0,0 +1,41 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++ return [+ 'auth' => [+ 'mode' => 'http',+ ],+ 'session' => [+ 'driver' => 'request',//stateless, handle session externally if needed. Change to php for session management if php session cookie can be sent with the request.+ ],+ 'email' => [+ 'driver' => 'mail',+ ],+ 'cache' => [+ 'driver' => 'file',+ 'servers' => [+ ],+ 'options' => [+ ],+ ],+ 'key' => 'Q8qJ6CVpUW4msSM8pHmdGwyXIkSvT6Lo',+ ];diff --git a/public/rest/default/openapi.json b/public/rest/default/openapi.jsonnew file mode 100644index 0000000..02470b9--- /dev/null+++ b/public/rest/default/openapi.json@@ -0,0 +1,45 @@+{+ "openapi": "3.1.0",+ "info": {+ "title": "Vvveb",+ "description": "Vvveb",+ "version": "1",+ "contact": {+ "name": "admin",+ "url": "https://www.vvveb.com",+ "email": "[email protected]"+ }+ },+ "servers": [+ {+ "url": "https://demo.vvveb.com/rest"+ }+ ],+ "tags": [+ {+ "name": "v1",+ "description": ""+ }+ ],+ "security": [+ {+ "basicAuth": []+ }+ ],+ "components": {+ "securitySchemes": {+ "basicAuth": {+ "type": "http",+ "scheme": "basic",+ "in": "header",+ "username": "demo",+ "password": "demo",+ "description": "Use admin user and password as credentials, user: demo password: demo"+ }+ },+ "schemas": {+ }+ },+ "paths": {+ }+}diff --git a/public/rest/index.php b/public/rest/index.phpnew file mode 100644index 0000000..ae8c7be--- /dev/null+++ b/public/rest/index.php@@ -0,0 +1,26 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++$PUBLIC_PATH = '/';+$PUBLIC_THEME_PATH = '/';++include __DIR__ . '/../../rest/index.php';diff --git a/rest/controller/base.php b/rest/controller/base.phpnew file mode 100644index 0000000..1b26e83--- /dev/null+++ b/rest/controller/base.php@@ -0,0 +1,141 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Controller;++use \Vvveb\System\Core\FrontController;+use function Vvveb\__;+use function Vvveb\config;+use function Vvveb\siteSettings;+use Vvveb\System\Core\Request;+use Vvveb\System\Core\Response;+use Vvveb\System\Event;+use Vvveb\System\Extensions\Plugins;+use Vvveb\System\Session;+use Vvveb\System\Traits\Permission;+use Vvveb\System\User\Admin;++#[\AllowDynamicProperties]+class Base {+ use Permission;++ protected $global = [];++ function auth() {+ $admin = Admin::current();++ if (! $admin) {+ $authMode = config(APP . '.auth.mode');++ if ($authMode == 'http') {+ if (isset($_SERVER['PHP_AUTH_USER'])) {+ $user = $_SERVER['PHP_AUTH_USER'];+ $password = $_SERVER['PHP_AUTH_PW'] ?? '';+ $loginData = compact('user', 'password');++ if ($userInfo = Admin::login($loginData)) {+ } else {+ $this->response->addHeader('WWW-Authenticate', 'Basic realm="REST Api"');+ $this->response->addHeader('HTTP/1.0 401 Unauthorized');+ FrontController::notFound(false, __('Auth failed!'), 403);+ }+ } else {+ $this->response->addHeader('WWW-Authenticate', 'Basic realm="REST Api"');+ $this->response->addHeader('HTTP/1.0 401 Unauthorized');+ FrontController::notFound(false, __('Auth failed!'), 403);+ }+ }+ }+ }++ protected function initEcommerce($countryId, $regionId) {+ $tax = \Vvveb\System\Cart\Tax::getInstance();+ $tax->setRegionRules($countryId, $regionId, 'store');+ }++ function init() {+ $this->response = Response::getInstance();+ $this->request = Request::getInstance();+ $this->session = Session::getInstance();++ $this->response->setType('json');++ if (! REST) {+ die($this->notFound(__('REST is disabled!'), 404));+ }++ $this->auth();++ //alow method override via get parameter to avoid issues with unsupported put and patch on some webservers+ $method = $this->request->get['_method'] ?? $this->request->getMethod();++ $permission = str_replace('/rest/', '', ($this->request->get['route'] ?? '') . '/' . $method);+ //Check permissions+ $className = get_class($this);++ if ($className != 'Vvveb\Controller\Error403') {+ $this->permission($permission);+ }++ Plugins :: loadPlugins();+ $site = siteSettings();++ list($site) = Event::trigger(__CLASS__, __FUNCTION__, $site);++ $this->global['site_id'] = SITE_ID ?? 1;+ $this->global['language_id'] = $this->session->get('language_id') ?? 1;+ $this->global['limit'] = 10;+ $this->global['start'] = 0;+ $this->global['user_id'] = $user['user_id'] ?? false;+ $this->global['user_group_id'] = $user['user_group_id'] ?? 1;+ $this->global['site'] = &$site;+ $this->global['user'] = $user ?? [];++ if (isset($site['country_id'])) {+ $this->initEcommerce($site['country_id'], $site['region_id']);+ }++ $this->global['site'] = &$site;++ list($this->global) = Event::trigger(__CLASS__, __FUNCTION__ . ':after', $this->global);++ if (in_array($method, ['post', 'put', 'delete', 'patch'])) {+ return $method;+ }+ }++ /**+ * Call this function if the requeste information was not found, for example if the specifed news, image, profile etc is not found then call this function.+ * It shows a "Not found" page and it also send 404 http status code, this is usefull for search engines etc.+ *+ * @param unknown_type $code+ * @param mixed $service+ * @param mixed $statusCode+ * @param null|mixed $message+ */+ protected function notFound($message = null, $statusCode = 404, $service = false) {+ $response = Response::getInstance();+ http_response_code($statusCode);++ return $response->output(is_array($message) ? $message : ['message' => $message]);+ }+}diff --git a/rest/controller/cart/cart.php b/rest/controller/cart/cart.phpnew file mode 100644index 0000000..a62a5a7--- /dev/null+++ b/rest/controller/cart/cart.php@@ -0,0 +1,47 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Controller\Cart;++include DIR_ROOT . 'app' . DS . 'controller' . DS . 'cart' . DS . 'coupon-trait.php';++include DIR_ROOT . 'app' . DS . 'controller' . DS . 'cart' . DS . 'cart.php';++class CartBase extends Cart {+ function index() {+ echo 'asd';++ die('asd');+ }++ function delete() {+ return $this->action('remove');+ }++ function put() {+ return $this->action('update');+ }++ function post() {+ return $this->action('add');+ }+}diff --git a/rest/controller/crud.php b/rest/controller/crud.phpnew file mode 100644index 0000000..5beb88f--- /dev/null+++ b/rest/controller/crud.php@@ -0,0 +1,137 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Controller;++use function Vvveb\__;+use function Vvveb\model;+use Vvveb\System\Traits\Crud as CrudTrait;++class Crud extends Base {+ use CrudTrait {+ CrudTrait::delete as remove;+ CrudTrait::index as get;+ }++ protected $fullPost = true;++ function validate($method, $ignoreMissing = false) {+ $model = model($this->type);+ $data = $this->request->post ?? [];++ if ($model) {+ $errors = $model->validate($data, $method, $this->type, $ignoreMissing);++ if ($errors) {+ return $errors;+ } else {+ return true;+ }+ }++ $this->redirect = false;++ return [sprintf(__('%s not found!'), ucfirst($this->type))];+ }++ function index() {+ $data = $this->get();++ if (! $data) {+ return $this->notFound(sprintf(__('%s not found!'), ucfirst($this->type)));+ }++ return $data;+ }++ //create+ function post() {+ if (($errors = $this->validate('add')) === true) {+ $this->redirect = false;++ return $this->save();+ } else {+ $this->notFound(['errors' => $errors], 500);+ }+ }++ //edit+ function patch() {+ if (($errors = $this->validate('edit')) === true) {+ $this->redirect = false;++ return $this->save();+ } else {+ $this->notFound(['errors' => $errors], 500);+ }+ }++ //upsert+ function put() {+ //if id update else create+ if (($errors = $this->validate('edit', true)) === true) {+ return $this->save();+ } else {+ $this->notFound(['errors' => $errors], 500);+ }+ }++ //delete+ function delete() {+ $type = $this->type;+ $type_id = $this->type_id ?? "{$type}_id";++ $data_id = $this->request->post[$type_id] ?? $this->request->get[$type_id] ?? false;+ $response = ['deleted' => false];++ if ($data_id) {+ if (is_numeric($data_id)) {+ $data_id = [$data_id];+ }++ if (! isset($this->modelName)) {+ $modelName = $type;+ }++ $model = model($modelName);+ $options = [$type_id => $data_id] + $this->global;+ $result = $model->delete($options);+ $name = ucfirst(__($type));++ if ($result && isset($result[$type])) {+ if ($result[$type]) {+ $response['deleted'] = true;+ } else {+ $response['message'] = 'No rows affected!';++ return $this->notFound($response, 410);+ }+ } else {+ $response['message'] = 'Error deleting %s!';++ return $this->notFound($response, 500);+ }+ }++ return $response;+ }+}diff --git a/rest/controller/default/crud.php b/rest/controller/default/crud.phpnew file mode 100644index 0000000..1e60c9a--- /dev/null+++ b/rest/controller/default/crud.php@@ -0,0 +1,39 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Controller\Default;++use Vvveb\Controller\Crud as CrudBase;++#[\AllowDynamicProperties]+class Crud extends CrudBase {+ protected $type = '';++ function __construct() {+ $urlData = \Vvveb\System\Routes::getUrlData();+ $this->type = $urlData['schema'];+ if ($this->type) {+ $this->module = $this->type;+ }+ }++}diff --git a/rest/controller/default/index.php b/rest/controller/default/index.phpnew file mode 100644index 0000000..e78fd05--- /dev/null+++ b/rest/controller/default/index.php@@ -0,0 +1,35 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Controller\Default;++use Vvveb\Controller\Listing;++#[\AllowDynamicProperties]+class Index extends Listing {+ protected $type = '';++ function __construct() {+ $urlData = \Vvveb\System\Routes::getUrlData();+ $this->type = $urlData['schema'];+ }+}diff --git a/rest/controller/error403.php b/rest/controller/error403.phpnew file mode 100644index 0000000..64a8106--- /dev/null+++ b/rest/controller/error403.php@@ -0,0 +1,32 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Controller;++#[\AllowDynamicProperties]+class Error403 extends Base {+ function index() {+ $this->response->setType('json');++ return ['message' => $this->view->message, 'code' => $this->view->code ?? 403];+ }+}diff --git a/rest/controller/error404.php b/rest/controller/error404.phpnew file mode 100644index 0000000..bf72bcf--- /dev/null+++ b/rest/controller/error404.php@@ -0,0 +1,40 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Controller;++#[\AllowDynamicProperties]+class Error404 extends Base {+ function index() {+ $this->response->setType('json');++ $return = ['message' => $this->view->message ?? 'Route not found!', 'code' => $this->view->code ?? 404];++ if (DEBUG) {+ if (isset($this->view->file)) {+ $return['file'] = $this->view->file;+ }+ }++ return $return;+ }+}diff --git a/rest/controller/error500.php b/rest/controller/error500.phpnew file mode 100644index 0000000..5481956--- /dev/null+++ b/rest/controller/error500.php@@ -0,0 +1,45 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Controller;++#[\AllowDynamicProperties]+class Error500 extends Base {+ function index() {+ $this->response->setType('json');++ if (DEBUG) {+ return [+ 'message' => $this->view->message,+ 'file' => $this->view->file,+ 'line_no' => $this->view->line_no,+ 'line' => $this->view->line,+ 'lines' => $this->view->lines,+ 'trace' => $this->view->trace,+ 'codeLines' => $this->view->code,+ 'code' => 500,+ ];+ } else {+ return ['message' => 'Internal server error!', 'code' => 500];+ }+ }+}diff --git a/rest/controller/index.php b/rest/controller/index.phpnew file mode 100644index 0000000..a66f996--- /dev/null+++ b/rest/controller/index.php@@ -0,0 +1,417 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Controller;++use function Vvveb\config;+use function Vvveb\isSecure;+use function Vvveb\reconstructJson;+use function Vvveb\siteSettings;+use Vvveb\System\Cache;+use Vvveb\System\Core\View;+use Vvveb\System\Event;+use Vvveb\System\Functions\Plural;+use Vvveb\System\Sites;+use Vvveb\System\Sqlp\Sqlp;+use function Vvveb\url;++#[\AllowDynamicProperties]+class Index extends Base {+ function type($type) {+ $type = strtolower($type);++ switch ($type) {+ case 'int':+ case 'tinyint':+ $type = 'integer';++ break;++ case 'varchar':+ case 'char':+ case 'datetime':+ case 'longtext':+ $type = 'string';++ break;+ }++ return $type;+ }++ function paths() {+ $routes = config('rest-routes');+ $paths = [];+ $sqlp = new Sqlp();+ $dirSQL = DIR_ROOT . 'admin' . DS . 'sql' . DS . DB_ENGINE . DS;++ $routeSchemas = [];++ foreach ($routes as $route => $options) {+ if (isset($options['schema'])) {+ $routeSchemas[$options['schema']] = $options['schema'];+ }+ }++ $routeSchemas = array_values($routeSchemas);++ $this->tables = [];+ $db = \Vvveb\System\Db::getInstance();+ $tables = $db->getTableNames(DB_NAME);+ $routesNew = [];++ foreach ($tables as $table) {+ $cols = [];+ $meta = $db->getColumnsMeta($table, true);++ foreach ($meta as $col) {+ $cols[$col['name']] = $col;+ }+ $this->tables[$table] = $cols;++ if (! in_array($table, $routeSchemas)) {+ if (file_exists($dirSQL . $table . '.sql')) {+ $plural = Plural::tablePlural($table);+ $routes['/rest/' . $plural] = ['module' => 'default', 'methods' => ['get', 'post'], 'schema' => $table];+ $routes['/rest/' . $plural . '/#' . $table . '_id#'] = ['module' => 'default/crud/index', 'methods' => ['get', 'post', 'put', 'patch', 'delete'], 'schema' => $table];+ }+ }+ }+ //echo var_export($routesNew, true);++ foreach ($routes as $route => $options) {+ $route = str_replace(['/rest', '/#', '#'], ['', '/{', '}'], $route);+ $data = [];+ $methods = $options['methods'] ?? ['get'];+ $actions = ['get' => 'get', 'post' => 'add', 'patch' => 'edit', 'put' => 'edit', 'delete' => 'delete'];++ foreach ($methods as $method) {+ $getParams = [];++ if (preg_match_all('/#([a-zA-Z]\w+)#/', $route, $matches)) {+ foreach ($matches[1] as $match) {+ $getParams[$match] = ['name' => $match, 'in' => 'path', 'schema' => ['type' => 'integer']];+ }+ }++ if (preg_match_all('/{(\w+)}/', $route, $matches)) {+ foreach ($matches[1] as $match) {+ $getParams[$match] = ['name' => $match, 'in' => 'path', 'schema' => ['type' => 'string']];+ }+ }++ //$responses+ $meth = ['responses' => []];+ $ok = [+ 'description' => 'OK',+ ];++ $params = [];+ $encoding = [];++ if (isset($options['schema'])) {+ $ok['content'] = [+ 'application/json' => [+ 'schema' => [+ '$ref' => '#/components/schemas/' . $options['schema'],+ ],+ ],+ ];++ $sqlp->parseSqlPfile($dirSQL . $options['schema'] . '.sql');+ $tree = $sqlp->getModel();++ $action = $actions[$method];++ if ($method == 'get' && ! isset($methods['delete'])) {+ $action = 'getAll';+ }++ if (($tree && isset($tree[$action])) &&+ ($method != 'get' || ($method == 'get' && ! $getParams))) {+ foreach ($tree[$action]['params'] as $p) {+ if ($p['in_out'] == 'OUT') {+ continue;+ }++ $param = [];++ if ($method == 'post') {+ $name = $p['name'];++ if ($name == $options['schema'] . '_id') {+ continue;+ }++ $params[$name]['type'] = $this->type($p['type'] ?? 'integer');++ if ($params[$name]['type'] == 'array' && isset($this->tables[$name])) {+ $encoding[$name]['explode'] = true;+ $encoding[$name]['style'] = 'deepObject';+ //$encoding[$name]['contentType'] = 'application/x-www-form-urlencoded';+ $params[$name]['type'] = 'object';+ $params[$name]['style'] = 'deepObject';+ $params[$name]['explode'] = true;+ //$params[$name]['contentEncoding'] = 'text/plain';++ $properties = [];++ foreach ($this->tables[$name] as $col) {+ if ($col['name'] == $options['schema'] . '_id') {+ continue;+ }++ //skip auto increment+ if ((isset($col['e']) && $col['e'] == 'auto_increment')) {+ continue;+ }+ $properties[$col['name']] = ['type' => $this->type($col['t'])];++ if ($col['d'] === NULL || $col['d'] == 'NULL') {+ $properties[$col['name']]['required'] = true;+ } else {+ $properties[$col['name']]['required'] = false;+ }+ }++ if (in_array($name,['post_content', 'product_content'])) {+ $params[$name]['type'] = 'array';+ $params[$name]['items']['type'] = 'object';+ $params[$name]['items']['explode'] = true;+ $params[$name]['items']['style'] = 'deepObject';+ $params[$name]['items']['properties'] = $properties;+ $encoding[$name]['items']['explode'] = true;+ $encoding[$name]['items']['style'] = 'deepObject';+ //$encoding[$name]['items']['type'] = 'object';+ //$encoding[$name]['type'] = 'array';+ } else {+ $params[$name]['properties'] = $properties;+ }+ }++ if ($params[$name]['type'] == 'array' && substr_compare($name, '_id', -3 ,3) === 0) {+ $params[$name]['items']['type'] = 'integer';+ //$params[$name]['items']['explode'] = true;+ $params[$name]['style'] = 'deepObject';+ $params[$name]['explode'] = true;+ $encoding[$name]['items']['explode'] = true;+ $encoding[$name]['items']['style'] = 'deepObject';+ $encoding[$name]['explode'] = true;+ $encoding[$name]['style'] = 'deepObject';+ //$encoding[$name]['items']['style'] = 'deepObject';+ }+ } else {+ $param['name'] = $p['name'];+ $param['in'] = 'query';+ $param['required'] = 'false';+ $param['description'] = $p['comment'] ?? '';+ $param['schema']['type'] = $this->type($p['type'] ?? 'integer');++ if ($param['schema']['type'] == 'array' && isset($this->tables[$param['name']])) {+ $param['schema']['$ref'] = '#/components/schemas/' . $param['name'];++ $properties = [];+ $param['explode'] = true;+ $param['style'] = 'deepObject';+ $param['schema']['type'] = 'object';++ foreach ($this->tables[$param['name']] as $col) {+ $properties[$col['name']] = ['type' => $this->type($col['t'])];++ if ($col['d'] === NULL || $col['d'] == 'NULL') {+ $properties[$col['name']]['required'] = true;+ } else {+ $properties[$col['name']]['required'] = false;+ }+ }++ //$param['name'] .= '[]';++ if ($param['name'] == 'post_content') {+ $param['schema']['type'] = 'array';+ $param['schema']['items']['type'] = 'object';+ $param['schema']['items']['explode'] = true;+ $param['schema']['items']['style'] = 'deepObject';+ $param['schema']['items']['properties'] = $properties;+ } else {+ $param['schema']['properties'] = $properties;+ }+ }++ if (! isset($getParams[$param['name']])) {+ $getParams[$param['name']] = $param;+ }+ }+ }+ }++ if ($method == 'post') {+ $meth['requestBody'] = [+ 'content' => [+ 'application/x-www-form-urlencoded' => [+ 'encoding' => $encoding,+ 'schema' => [+ 'type' => 'object',+ 'properties' => $params,+ ],+ ],+ ],+ ];+ }++ if ($getParams) {+ $meth['parameters'] = array_values($getParams);+ }+ }++ $meth['responses']['200'] = $ok;++ $data[$method] = $meth;+ }++ $paths[$route] = $data;+ }++ list($paths) = Event :: trigger(__CLASS__,__FUNCTION__, $paths);++ return $paths;+ $this->response->setType('json');+ $this->response->output($paths);+ }++ function schemas() {+ $db = \Vvveb\System\Db::getInstance();++ $tables = $db->getTableNames(DB_NAME);+ $schemas = [];++ foreach ($tables as $table) {+ $meta = $db->getColumnsMeta($table, true);+ $cols = [];++ foreach ($meta as $column) {+ $col = [];+ $col['name'] = $column['name'] ?? '';+ $col['description'] = $column['c'] ?? '';+ $col['type'] = $this->type($column['t'] ?? 'integer');++ switch ($col['type']) {+ case 'datetime':+ $col['format'] = 'date-time';+ }++ if (isset($column['c']) && $column['c'] == 'YES') {+ $col['type'] = [$col['type'], 'null'];+ }++ $cols[$column['name']] = $col;+ }++ $data = [+ 'title' => $table,+ 'type' => 'object',+ '$schema' => 'http://json-schema.org/draft-04/schema#',+ 'properties' => $cols,+ ];++ $schemas[$table] = $data;+ }++ //var_export($schemas);+ list($schemas) = Event :: trigger(__CLASS__,__FUNCTION__, $schemas);++ return $schemas;+ $this->response->setType('json');+ $this->response->output($schemas);+ }++ public static function getControllerList($app = APP) {+ $files = [];+ $path = [DIR_ROOT . $app . '/controller/*', DIR_PLUGINS . '*/' . $app . '/controller/*'];++ while (count($path) > 0) {+ $next = array_shift($path);+ //echo $next . "\n";+ foreach (glob("$next/*.json") as $file) {+ if (is_dir($file)) {+ $path[] = $file;+ }++ if (is_file($file)) {+ $files[] = $file;+ }+ }+ }++ list($files) = Event :: trigger(__CLASS__,__FUNCTION__, $files);++ return $files;+ }++ function renderJson() {+ $htmlView = new View();+ //$htmlView = clone $this->view;+ $htmlView->setTheme();+ $htmlView->set(['seo' => []]);+ $htmlView->template('openapi.json');+ $xml = $htmlView->render(true, false, true);++ if ($xml) {+ $sxml = \simplexml_load_string($xml, null, LIBXML_NOCDATA | LIBXML_DTDATTR);+ $array = reconstructJson($sxml, true);++ return $array;+ $json = json_encode($array, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);+ echo $json;+ }+ }++ function api() {+ $cache = Cache::getInstance();+ $json = $cache->cache(APP,'openapi',function () {+ $site = siteSettings();+ $data = Sites :: getSiteData();++ $json = $this->renderJson();+ $json['paths'] = $this->paths();+ $json['components']['schemas'] = $this->schemas();++ $site = siteSettings(SITE_ID, $this->global['language_id']);+ $urlParams = ['host' => $data['host'], 'scheme' => isSecure() ? 'https' : 'http'];+ $url = url('/',$urlParams);++ $json['info']['title'] = $site['description']['title'];+ $json['info']['contact']['email'] = $site['contact-email'];+ $json['info']['contact']['url'] = $url;+ $json['servers'][0]['url'] = url('',$urlParams);++ return $json;+ }, 259200);++ $this->response->setType('json');+ $this->response->output($json);+ }++ function index() {+ return $this->api();+ }+}diff --git a/rest/controller/listing.php b/rest/controller/listing.phpnew file mode 100644index 0000000..fe36ae8--- /dev/null+++ b/rest/controller/listing.php@@ -0,0 +1,76 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Controller;++use function Vvveb\model;+use Vvveb\System\Traits\Crud as CrudTrait;+use Vvveb\System\Traits\Listing as ListingTrait;++class Listing extends Base {+ use ListingTrait, CrudTrait {+ ListingTrait::index as get;+ CrudTrait::delete insteadof ListingTrait;+ }++ function __construct() {+ $this->redirect = false;+ $this->fullPost = true;+ }++ function post() {+ $model = model($this->type);+ $data = $this->request->post ?? [];++ if ($model) {+ $errors = $model->validate($data, 'add', $this->type);++ if ($errors) {+ $this->notFound(['errors' => $errors], 500);+ }+ }++ $this->redirect = false;+ $this->fullPost = true;++ return $this->save();+ }++ function index() {+ $results = $this->get();+ $this->view->success[] = '%s(s) deleted!';++ if (isset($results['count'])) {+ $count = $results['count'] ?: 0;+ $limit = $results['limit'] ?: 0;+ $page = $results['page'] ?: 1;+ //$pages = ($count && $limit) ? ceil($count / $limit) : 0;++ $this->response->addHeader('X-V-count', $count);+ $this->response->addHeader('X-V-limit', $limit);+ //$this->response->addHeader('X-V-page', $page);+ //$this->response->addHeader('X-V-pages', $pages);+ }++ return $results[$this->type] ?? [];+ }+}diff --git a/rest/controller/rest.php b/rest/controller/rest.phpnew file mode 100644index 0000000..1d2e4c6--- /dev/null+++ b/rest/controller/rest.php@@ -0,0 +1,155 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++namespace Vvveb\Controller;++use function Vvveb\getCurrency;+use function Vvveb\model;+use Vvveb\System\Cart\Currency;+use Vvveb\System\Cart\Tax;+use Vvveb\System\Images;++#[\AllowDynamicProperties]+class Rest extends Base {+ private $method = 'GET';++ private function processResource(&$resource) {+ if (isset($resource['images'])) {+ $resource['images'] = json_decode($resource['images'], 1);++ foreach ($resource['images'] as &$image) {+ $image = Images::image($image, $this->resource, $this->options['image_size'] ?? 'medium');+ }+ }++ if (isset($resource['product_image'])) {+ $resource['images'] = Images::images($resource['product_image'], 'product', $this->options['image_size'] ?? 'medium');+ }++ if (isset($resource['image'])) {+ $resource['image'] = Images::image($resource['image'], $this->resource, $this->options['image_size'] ?? 'medium');+ }++ if (isset($resource['password'])) {+ unset($resource['password']);+ }++ if (isset($resource['price'])) {+ $tax = Tax::getInstance();+ $currency = Currency::getInstance();+ $currentCurrency = getCurrency();++ $resource['price_tax'] = $tax->addTaxes($resource['price'], $resource['tax_type_id']);+ $resource['price_tax_formatted'] = $currency->format($resource['price_tax']);+ $resource['price_formatted'] = $currency->format($resource['price']);+ $resource['price_currency'] = $currentCurrency;+ }++ return $resource;+ }++ function index() {+ $this->method = $this->request->method;++ $this->resource = $this->request->get['resource'] ?? false;+ $this->id = $this->request->get['id'] ?? false;+ $this->slug = $this->request->get['slug'] ?? false;+ $this->options = $this->request->get ?? [];++ $page = $this->request->get['page'] ?? 1;+ $limit = $this->request->get['limit'] ?? 10;+ $this->global['start'] = ($page - 1) * $limit;+ $this->global['limit'] = $limit;++ unset($this->options['resource'], $this->options['id']);++ if ($this->resource) {+ $this->resource = rtrim($this->resource, 's');+ $model = model(rtrim($this->resource, 's')); //singular for model name++ if (! $model) {+ return;+ }+ }++ $output = [];+ $this->response->setType('json');++ switch ($this->method) {+ case 'GET':+ if ($this->id || $this->slug) {+ $options =[];++ if ($this->id) {+ $resource_id = $this->resource . '_id';+ $options[$resource_id] = $this->id;+ }++ if ($this->slug) {+ $options['slug'] = $this->slug;+ }++ $output = $model->get($options + $this->options + $this->global);++ if ($output ||+ (isset($output[$this->resource . '_id']) ||+ (isset($output[$this->resource]) ||+ $output[$this->resource]))) {+ if (isset($output[$this->resource])) {+ $output = $output[$this->resource];+ }++ $output = $this->processResource($output);+ } else {+ return $this->notFound();+ }+ } else {+ $result = $model->getAll($this->options + $this->global);++ if (isset($result[$this->resource . 's'])) {+ $collection = $result[$this->resource . 's'];++ foreach ($collection as $id => &$resource) {+ $output[] = $this->processResource($resource);+ }+ } else {+ return $this->notFound();+ }+ }++ break;++ case 'POST':+ break;++ case 'PUT':+ break;++ case 'DELETE':+ $this->action = 'delete';++ break;+ }++ $this->response->output($output);+ }+}diff --git a/rest/index.php b/rest/index.phpnew file mode 100644index 0000000..86e3201--- /dev/null+++ b/rest/index.php@@ -0,0 +1,26 @@+<?php++/**+ * Vvveb+ *+ * Copyright (C) 2022 Ziadin Givan+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++define('APP', 'rest');+//define('DISABLE_PLUGIN_ON_ERORR', true);++return include __DIR__ . '/../index.php';