From 3521a992a1b0f5bcbb478f2a224e11931b6c80f8 Mon Sep 17 00:00:00 2001 From: ChidoW Date: Fri, 13 Jan 2023 01:19:17 +0200 Subject: [PATCH] updated to wpoow 2.0 --- .gitignore | 5 +- composer.json | 2 +- src/wpOOW/Core/Elements/Autoloader.php | 2 + src/wpOOW/Core/Elements/BaseElement.php | 9 +- src/wpOOW/Core/Elements/Checkbox/Checkbox.php | 4 + src/wpOOW/Core/Elements/Link/Link.php | 4 + .../Core/Elements/MultiSelect/MultiSelect.php | 4 + .../Elements/RichTextArea/RichTextArea.php | 4 + src/wpOOW/Core/Elements/Select/Select.php | 4 + src/wpOOW/Core/Elements/Text/Text.php | 4 + src/wpOOW/Core/Elements/TextArea/TextArea.php | 4 + src/wpOOW/Core/Elements/Uploader/Uploader.php | 4 + .../Elements/wpAPIDateTime/wpAPIDateTime.php | 4 + src/wpOOW/Core/PageTypes/Menu.php | 2 + src/wpOOW/Core/PageTypes/PostType.php | 7 + src/wpOOW/Core/PageTypes/SubMenu.php | 4 + src/wpOOW/Core/PageTypes/SubMenuSeparator.php | 2 + src/wpOOW/Core/wpAPIBasePage.php | 4 + src/wpOOW/Core/wpAPIObjects.php | 2 + src/wpOOW/Core/wpAPIUtilities.php | 2 + src/wpOOW/Core/wpQueryObject.php | 8 +- src/wpOOW/Utilities/versionDetails.php | 30 -- src/wpOOW/wpAPI.php | 306 +----------------- 23 files changed, 88 insertions(+), 333 deletions(-) delete mode 100644 src/wpOOW/Utilities/versionDetails.php diff --git a/.gitignore b/.gitignore index ffd9378..56bceb3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -vendors/* -build/ \ No newline at end of file +vendor/ +build/ +.idea/ \ No newline at end of file diff --git a/composer.json b/composer.json index 05fcc3b..407ccdc 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ }, "autoload": { "psr-4": { - "wpOOW": "./src/wpOOW" + "wpOOW\\": "./src/wpOOW" } } } diff --git a/src/wpOOW/Core/Elements/Autoloader.php b/src/wpOOW/Core/Elements/Autoloader.php index c582b2d..a8e9f06 100644 --- a/src/wpOOW/Core/Elements/Autoloader.php +++ b/src/wpOOW/Core/Elements/Autoloader.php @@ -1,5 +1,7 @@ getShortName(). URL_SEPARATOR; } // register events @@ -262,7 +267,7 @@ function __construct($id, $label="", $permissions=[], $elementPath = '', $elemen //TODO: Make this global - $loader = new \Twig\Loader\FilesystemLoader(dirname((new ReflectionClass($this))->getFileName()). $elementPath); + $loader = new \Twig\Loader\FilesystemLoader(dirname((new \ReflectionClass($this))->getFileName()). $elementPath); $this->twigTemplate = new \Twig\Environment($loader); wpAPIObjects::GetInstance()->AddObject(sprintf("_element_%s", $this->id), $this); diff --git a/src/wpOOW/Core/Elements/Checkbox/Checkbox.php b/src/wpOOW/Core/Elements/Checkbox/Checkbox.php index bd16e01..7d82b99 100644 --- a/src/wpOOW/Core/Elements/Checkbox/Checkbox.php +++ b/src/wpOOW/Core/Elements/Checkbox/Checkbox.php @@ -1,5 +1,9 @@ queryArgs ); + $loop = new \WP_Query( $this->queryArgs ); while ( $loop->have_posts() ) : $loop->the_post(); @@ -84,7 +86,7 @@ public function Fetch() */ #TODO: Really think about this. The proper way of implementing. The class is no longer generic -class PostTypeRow extends ArrayObject +class PostTypeRow extends \ArrayObject { private $parent_slug = ""; @@ -154,7 +156,7 @@ public function __unset($name) public function getIterator() { - return new ArrayIterator($this->storage); + return new \ArrayIterator($this->storage); } } \ No newline at end of file diff --git a/src/wpOOW/Utilities/versionDetails.php b/src/wpOOW/Utilities/versionDetails.php deleted file mode 100644 index b4f7df9..0000000 --- a/src/wpOOW/Utilities/versionDetails.php +++ /dev/null @@ -1,30 +0,0 @@ -major_number = $version_number[0]; - $this->minor_number = $version_number[1]; - $this->patch_number = $version_number[2]; - $this->build_number = $version_number[3]; - $this->build_date = $composer_package_details["build_date"]; - } - - public function GetFullVersion() - { - return implode(".", [$this->major_number, $this->minor_number, $this->patch_number,$this->build_number]); - } - - public function __toString(){ - return sprintf("%s (%s)", $this->GetFullVersion(), $this->build_date); - } -} \ No newline at end of file diff --git a/src/wpOOW/wpAPI.php b/src/wpOOW/wpAPI.php index 2b4f8f1..b6f22b0 100755 --- a/src/wpOOW/wpAPI.php +++ b/src/wpOOW/wpAPI.php @@ -1,19 +1,18 @@ type = $type; - $this->path_content = $path_content; - $this->data = array_merge($this->data, $data); - $this->base_path = $base_path != null ? $base_path : ABSPATH; - - } - - /** - * - * Method that renders the twig template - * - */ - function Render() - { - - if ($this->type == self::PATH) - { - //TODO: Make this global - - $loader = new Twig_Loader_Filesystem($this->base_path); - $twig = new Twig_Environment($loader); - - echo $twig->render($this->path_content, $this->data); - } - else if ($this->type == self::CONTENT) - { - - $loader = new Twig_Loader_Array(array( - 'page.html' => $this->path_content, - )); - - $twig = new Twig_Environment($loader); - - echo $twig->render('page.html', $this->data); - - } - - - - } - - /** - * - * Allows you to set the key, value data to be used when rendering the view. - * The data can either be appended to already existing data, or replace already existing data. - * - * @param $data - * @param bool $append - */ - function SetData($data, $append=true) - { - if ($append) { - $this->data = array_merge($this->data, $data); - } - else - { - $this->data = $data; - } - - } -} - -/** - * Class WP_PERMISSIONS - * - * wrapper for the main wordpress permissions - * @package wpAPI\Base - */ -class WP_PERMISSIONS -{ - - CONST MANAGE_OPTIONS = "manage_options"; -} - - -/** - * Class wpAPIPermissions - * - * Permission class used for the wpAPI_VIEW. - * wpAPI Elements can set of permissions which will be linked to the wpAPI_VIEW permissions (viewstate) for a page. - * Based on this, elements can either have create, read, update delete rights. - * - * For the wpAPI there are 5 viewstates that a wpAPI page can have. The view of a page can set using by setting the - * global $CURRENT_VIEW_STATE when the page is created. By default this permission/viewsate is @EditPage. These - * viewstates are detailed below. It must be noted that these can be used arbitrarily. The names are more suggestive - * as to when to use them - * - * ViewPage - Can be use for a custom page when it is in read only mode. Not always usually useful for wordpress - * as most pages are not readonly - * AddPage - Can be used on a custom page when adding elements. In this case, not always useful in wordpress. - * - When you use the wpAPI post type this is set when you add a new post - * EditPage - This is default view state set for all pages. Can be used on a custom page when editing elements. - * - When you use the wpAPI post type this is set when you editing a new post - * ViewTable - Can be used on a custom page when you have a table/grid layout - * - When you use the wpAPI post type this is set when you are view all your post types - * EditTable - Can be used on a custom page when you have a edited inline table/grid layout - * - TODO: enable on wordpress inline editing - * - * For each of these viewstate and element can either create, read and update permissions set. By default all viewstates - * for an element are set to create, read, update. i.e - * - * element.WP_PERMISSIONS = [ - wpAPIPermissions::ViewPage => "cru", - wpAPIPermissions::AddPage => "cru", - wpAPIPermissions::EditPage => "cru", - wpAPIPermissions::EditTable => "cru", - wpAPIPermissions::ViewTable => "cru", - - ]; - * - * when a page is rendered the permission of each wpAPI element is is computed dependant on the page viewstate. The - * element is - * - presented if read permissions are true. - * - editable if update permissions are true and the viewstate matches. - * - editable if create permissions are true and the viewstate matches. - * - * @package wpAPI\Base - */ - - -class wpAPIPermissions -{ - - const ViewPage = "ViewPage"; - const AddPage = "AddPage"; - const EditPage = "EditPage"; - const ViewTable = "ViewTable"; - const EditTable = "EditTable"; - - // cru - create - read - update - /** - * @var array - */ - private $permissionMatrix = [ - wpAPIPermissions::ViewPage => "cru", - wpAPIPermissions::AddPage => "cru", - wpAPIPermissions::EditPage => "cru", - wpAPIPermissions::EditTable => "cru", - wpAPIPermissions::ViewTable => "cru", - - ]; - - /** - * An array with viewstate -> permission relations to be set for the element such as the field. Example Below - * - * [ - * "EditTable" = > "cr" - * "EditPage" = > "cru" - * "ViewTable" = > "cru" - * "ViewPage" = > "cru" - * ] - * - * Note:- for viewstates you can use the const i.e wpAPIPermissions::EditTable => "cru" - * Also note by default all viewstates have the permission cru. - * because of this you don't have to specify all viewstates. Only the one you want - * - * - * @param array $permissions - * @return wpAPIPermissions - * @throws Exception - */ - public static function SetPermission($permissions = []) - { - if (!is_array($permissions)) { - throw new Exception("Permission should be an array with the 4 view states EditTable, EditPage, ViewTable, ViewPage"); - } - $wP = new wpAPIPermissions(); - - - foreach ($permissions as $pageState => $permission) { - $wP->permissionMatrix[$pageState] = $permission; - } - return $wP; - } - - - /** - * Get the permission of a pagestate - * - * @param $pageState - * @return mixed - */ - public function GetPermission($pageState) - { - //TODO: consider returning an object - return $this->permissionMatrix[$pageState]; - } - - //TODO: Rename this to check permission - /** - * See is for the given page state an action is allow. Action can either be u(pdate), or r(ead), v(iew) - * - * @param $pageState - * @param $action - * @return bool|int - */ - public function CheckPermissionAction($pageState, $action) - { - return strpos($this->permissionMatrix[$pageState], $action); - } - - public function CanEdit($pageState) - { - return strpos($this->permissionMatrix[$pageState], 'u'); - } - - public function CanRead($pageState) - { - return strpos($this->permissionMatrix[$pageState], 'r'); - } - - public function CanCreate($pageState) - { - return strpos($this->permissionMatrix[$pageState], 'c'); - } - - -} - -class_alias('wpAPIPermissions', 'wpPer'); -