_is_ajax = (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtoupper($_SERVER['HTTP_X_REQUESTED_WITH']) === 'XMLHTTPREQUEST'); $this->_page = !empty($_GET['page']) ? (string)$_GET['page'] : ''; $parts = explode('-', $this->_page); if (!empty($parts[1])) { $this->_controller = $parts[1]; } elseif (isset($_GET['controller'])) { $this->_controller = ucfirst($_GET['controller']); } else { $this->_controller = 'Settings'; } $this->_action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : (!empty($parts[2]) ? $parts[2] : ''); if ($this->_is_ajax && strpos($this->_action, $this->_ajax_prefix) === 0) { $this->_action = str_replace($this->_ajax_prefix, '', $this->_action); } } /** * @since 1.0.0 * @throws Exceptions\Runtime * @throws Exceptions\Validate */ public function navigate() { try { $controller_name = '\\' . __NAMESPACE__ . '\Controllers\\' . ucfirst($this->_controller); $action = $this->_action . '_action'; if (class_exists($controller_name)) { $controller = new $controller_name(); if (method_exists($controller, $action)) { $controller->$action(); return; } } if ($action === 'submit_amoform_action') { $controller = new Form(); $controller->submit_action(); } else { $controller = new Settings(); $controller->edit_fields_action(); } } catch (\Exception $e) { Helpers::handle_exception($e); } } public function navigate_ajax() { header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Content-type: application/json'); $this->navigate(); die; } /** * @return bool */ public function is_ajax() { return $this->_is_ajax; } }