PATH:
home
/
letacommog
/
laindinois
/
wp-content
/
plugins
/
wiloke-listing-tools
/
app
/
Framework
/
Routing
<?php namespace WilokeListingTools\Framework\Routing; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use WilokeListingTools\Framework\Helpers\AddListingFieldSkeleton; use WilokeListingTools\Framework\Helpers\DebugStatus; use WilokeListingTools\Framework\Helpers\General; abstract class Controller { /* * As the default, it always die if the payment parameter is wrong, but some cases, we simply return false; */ public $isNotDieIfFalse; protected $aMiddleware = []; protected function isWP53() { global $wp_version; return version_compare($wp_version, '5.2', '>') && (!function_exists('kc_admin_enable') || (function_exists('kc_admin_enable') && !kc_admin_enable())); } protected function isAdminQuery() { if (is_admin() && !wp_doing_ajax()) { return true; } if (wp_doing_ajax()) { if (isset($_POST['action'])) { $action = $_POST['action']; } elseif (isset($_GET['action'])) { $action = $_GET['action']; } if (!isset($action) || (strpos($action, 'wilcity') === false && strpos($action, 'wil_') !== 0)) { return true; } } // only use filter through ajax. It helps to resolve 404 error if (function_exists('wilcityIsSearchPage') && wilcityIsSearchPage()) { return true; } return false; } public function isDisableMetaBlock($aParams) { if (defined('WILCITY_SHOW_ALL_META_BLOCKS') && WILCITY_SHOW_ALL_META_BLOCKS) { return false; } $postType = $this->getCurrentAdminPostType(); $oAddListingSkeleton = new AddListingFieldSkeleton($postType); if (empty($oAddListingSkeleton->getField($aParams['fieldKey']))) { return true; } if (isset($aParams['param'])) { return empty($oAddListingSkeleton->getFieldParam($aParams['fieldKey'], $aParams['param'])); } return false; } protected function createWPQuery($aArgs) { if (class_exists('\WilcityRedis\Controllers\SearchController')) { $result = apply_filters( 'wilcity/filter/get-query-values', null, $aArgs ); if (!empty($result)) { return $result; } } return new \WP_Query($aArgs); } protected function isAdminEditing() { if (!isset($_GET['action']) || $_GET['action'] !== 'edit') { return false; } return true; } protected function isPostType($postType) { if (!isset($_GET['post']) || get_post_type($_GET['post']) !== $postType) { return false; } return true; } protected function getCurrentAdminPostType() { if (!is_admin()) { return null; } if (isset($_GET['post_type'])) { return $_GET['post_type']; } if (isset($_GET['post']) && !empty($_GET['post'])) { return get_post_type($_GET['post']); } return null; } protected function isCurrentAdminListingType($excludeEvents = false) { $postType = $this->getCurrentAdminPostType(); if (empty($postType)) { return false; } $aListingTypes = General::getPostTypeKeys(false, $excludeEvents); return in_array($postType, $aListingTypes); } protected function checkAdminReferrer() { if (isset($_GET['meta-box-loader'])) { return check_admin_referer('meta-box-loader', 'meta-box-loader-nonce'); } if (isset($_REQUEST['_locale']) && current_user_can('administrator')) { return true; } if (!isset($_REQUEST['wilcity_admin_nonce_field']) || !General::isAdmin()) { return false; } return check_admin_referer('wilcity_admin_security', 'wilcity_admin_nonce_field'); } public function middleware($aMiddleware, array $aOptions = []) { if ((!DebugStatus::status('WILOKE_LISTING_TOOLS_CHECK_EVEN_ADMIN') && current_user_can('administrator')) || DebugStatus::status('WILOKE_LISTING_TOOLS_PASSED_MIDDLEWARE') ) { return true; } /* * All Controller must be passed this middleware first */ do_action('wiloke-listing-tools/top-middleware'); $msg = esc_html__('You do not have permission to access this page', 'wiloke-listing-tools'); $aOptions['userID'] = isset($aOptions['userID']) ? $aOptions['userID'] : get_current_user_id(); foreach ($aMiddleware as $middleware) { $middlewareClass = $this->getMiddleware($middleware); if (class_exists($middlewareClass)) { $instMiddleware = new $middlewareClass; $status = $instMiddleware->handle($aOptions); if (!$status) { if (isset($aOptions['isBoolen'])) { return false; } else if (isset($aOptions['isAjax']) || wp_doing_ajax()) { wp_send_json_error( [ 'msg' => property_exists($instMiddleware, 'msg') ? $instMiddleware->msg : $msg ] ); } elseif (isset($aOptions['isRedirect'])) { $url = property_exists($instMiddleware, 'redirectTo') ? $instMiddleware->redirectTo : null; Redirector::to($url); } elseif ((isset($aOptions['isBoolean']) && ($aOptions['isBoolean'] == 'yes' || $aOptions['isBoolean'])) || (isset($aOptions['isApp']) && ($aOptions['isApp'] == 'yes' || $aOptions['isApp'])) ) { return [ 'status' => 'error', 'msg' => property_exists($instMiddleware, 'msg') ? $instMiddleware->msg : $msg ]; } else { throw new AccessDeniedHttpException($msg); } } } else { if (wp_doing_ajax()) { wp_send_json_error( [ 'msg' => sprintf( esc_html__("Class %s does not exists", 'wiloke-listing-tools'), $middleware ) ] ); } else { if ((isset($aOptions['isBoolean']) && ($aOptions['isBoolean'] == 'yes' || $aOptions['isBoolean'])) || (isset($aOptions['isApp']) && ($aOptions['isApp'] == 'yes' || $aOptions['isApp'])) ) { return [ 'status' => 'error', 'msg' => sprintf( esc_html__("Class %s does not exists", 'wiloke-listing-tools'), $middleware ) ]; } else { throw new NotFoundHttpException; } } } } if (isset($aOptions['isBoolean']) && ($aOptions['isBoolean'] == 'yes' || $aOptions['isBoolean'])) { return [ 'status' => 'success' ]; } return true; } public function validate($aInput, $aRules) { foreach ($aRules as $name => $rule) { switch ($rule) { case 'required': if (!isset($aInput[$name]) || empty($aInput[$name])) { if (wp_doing_ajax()) { wp_send_json_error( [ 'msg' => sprintf(esc_html__("The %s is required", 'wiloke-listing-tools'), $name) ] ); } else { throw new AccessDeniedHttpException(esc_html__( "The %s is required", 'wiloke-listing-tools' )); } } break; case 'email': if (!isset($aInput[$name]) || empty($aInput[$name]) || !is_email($aInput[$name])) { if (wp_doing_ajax()) { wp_send_json_error( [ 'msg' => sprintf(esc_html__( "You provided an invalid email address", 'wiloke-listing-tools' ), $name) ] ); } else { throw new AccessDeniedHttpException(esc_html__( "You provided an invalid email address", 'wiloke-listing-tools' )); } } break; default: do_action('wiloke-listing-tools/app/Framework/Routing/Controller/validate', $aInput, $name, $rule); break; } } } public function getMiddleware($middleware) { return wilokeListingToolsRepository()->get('middleware:'.$middleware); } /** * Handle Calls to missing methods on the control * * @param array $aParameters * * @return mixed * * @throws \BadMethodCallException */ public function __call($method, $aParameters) { throw new \BadMethodCallException(esc_html__("Method [{{$method}}] does not exist", 'wiloke')); } }
[+]
..
[-] InterfaceMiddleware.php
[edit]
[-] Controller.php
[edit]
[-] RouteAfterItemInserted.php
[edit]
[-] Redirector.php
[edit]