/** * @before _secure, memberLayout */ public function changeState($keyword_id, $live) { $keyword = Keyword::first(array("id = ?" => $keyword_id)); $this->_authority($keyword); if (!$keyword->serp) { $keyword->live = $live; $keyword->save(); } $this->redirect(RequestMethods::server('HTTP_REFERER', '/member')); }
/** * Makes GET request to the URL and return the results to the template’s $_text array, * where it will be rendered to the final template output * @param type $tree * @param type $content * @return type */ protected function _partial($tree, $content) { $address = trim($tree["raw"], " /"); if (StringMethods::indexOf($address, "http") != 0) { $host = RequestMethods::server("HTTP_HOST"); $address = "http://{$host}/{$address}"; } $request = new Request(); $response = addslashes(trim($request->get($address))); return "\$_text[] = \"{$response}\";"; }
/** * Make GET request to given URL and place the results * in the template file * @param array $tree Node from the template tree * @param mixed $content Content of node * @return string String to be included in template */ protected function _partial($tree, $content) { $address = trim($tree["raw"], " /"); // Convert a relative URl to an absolute URL if (StringMethods::indexOf($address, "http") != 0) { $host = RequestMethods::server("HTTP_HOST"); $address = "http://{$host}/{$address}"; } // Make GET request to URL and return results to // template $_text array $request = new Request(); $response = addslashes(trim($request->get($address))); return "\$_text[] = \"{$response}\";"; }
/** * Hook for determining if the request was XHR * also works as a direct method call * @protected */ public function _ajax() { // If request was XHR $request = RequestMethods::server('HTTP_X_REQUESTED_WITH'); if (isset($request) && $request === 'XMLHttpRequest') { $this->ajax = true; return true; } // If request was not manage the correct response // If ajax test was via @before hook $caller = list(, $caller) = debug_backtrace(false); if ($caller[1]['function'] == 'Framework\\{closure}' && $caller[1]['args'][1] == '@before') { throw new \Exception("NOT AJAX", 1); } else { // If ajax test was simple method call return false; } }
/** * Deletes any model with given id * * @before _secure, _admin * @param type $model the model object to be deleted * @param type $id the id of object to be deleted */ public function delete($model = NULL, $id = NULL, $redirect = true) { $view = $this->getActionView(); $this->JSONview(); $object = $model::first(array("id = ?" => $id)); $object->delete(); $view->set("deleted", true); if ($redirect) { $this->redirect(RequestMethods::server('HTTP_REFERER', '/admin')); } }
/** * @before _secure */ public function status($id, $value) { $m = strtolower($model); $trigger = Registry::get("MongoDB")->triggers; $live = (bool) (int) $value; if ($this->user->admin) { $trigger->update(array('trigger_id' => (int) $id), array('$set' => array('live' => $live))); parent::edit('trigger', $id, 'live', $value); } else { $trigger->update(array('trigger_id' => (int) $id, 'user_id' => $this->user->id), array('$set' => array('live' => $live))); $t = Trigger::first(array("id = ?" => $id, "user_id = ?" => $this->user->id)); if ($t) { $t->live = $value; $t->save(); } $this->redirect(RequestMethods::server('HTTP_REFERER', '/member')); } }
public function __construct($options = array()) { parent::__construct($options); $this->agent = RequestMethods::server("HTTP_USER_AGENT", "Curl/PHP " . PHP_VERSION); }
public static function addNew($type, $org, $view) { $fields = ['name', 'email', 'phone', 'password', 'country']; $user = new self(['country' => RequestMethods::server("HTTP_CF_IPCOUNTRY", "IN"), 'username' => RequestMethods::post("name", "USER"), 'currency' => 'USD', 'org_id' => $org->_id, 'type' => $type, 'live' => false]); foreach ($fields as $f) { $user->{$f} = RequestMethods::post($f, $user->{$f}); } if (!$user->validate()) { $view->set("errors", $user->errors); return false; } $u = self::first(["email = ?" => $user->email, "org_id = ?" => $org->_id]); if ($u) { $view->set("message", "User already exists!!"); $view->set('errors', ['email' => ['Duplicate Email']]); return false; } return $user; }
/** * @protected */ public function _verified() { $user = $this->getUser(); if (!$user) { Registry::get("session")->set('$beforeLogin', RequestMethods::server('REQUEST_URI', '/')); $this->redirect("/login.html"); } }
/** * @before _secure, _vendor */ public function changeStatus($model, $id, $property, $status) { $m = $model::first(array("id = ?" => $id, "organization_id = ?" => $this->organization->id)); if (!$m) { $this->redirect("/vendor"); } $m->{$property} = $status; $m->save(); $this->redirect(RequestMethods::server('HTTP_REFERER', '/vendor')); }
public static function getClientIp() { $headers = getallheaders(); $ip = ''; if (isset($headers['Cf-Connecting-Ip'])) { $ipaddr = $headers['Cf-Connecting-Ip']; $ip = explode(",", $ipaddr); $ip = $ip[0]; } else { $ip = RequestMethods::server('REMOTE_ADDR') ?? RequestMethods::server('HTTP_CLIENT_IP'); } return $ip; }