public function get() { $page = Request::getQuery('page', 1); $per = Configuration::getInstance()->per; $start = ($page - 1) * $per; return array('personas' => Personas::all(null, array('inscripcion' => 'DESC'), array($start, $per)), 'count' => Personas::count(), 'start' => $start, 'page' => $page, 'per' => $per); }
protected function connect() { $this->oauth->setToken($this->token, $this->tokenSecret); $accessToken = $this->oauth->getAccessToken(self::URL_ACCESS . (Request::hasQuery('oauth_verifier') ? '?oauth_verifier=' . Request::getQuery('oauth_verifier') : '')); $this->state = self::STATE_CONNECTED; $this->token = $accessToken['oauth_token']; $this->tokenSecret = $accessToken['oauth_token_secret']; Session::set('Twitter_Token', $this->token); Session::set('Twitter_TokenSecret', $this->tokenSecret); Session::set('Twitter_State', $this->state); TwCensus::redirect('/'); }
public function get() { $page = Request::getQuery('page', 1); $per = Configuration::getInstance()->per; $start = ($page - 1) * $per; $paginas = array(); $count = 0; $pos = 0; if ($this->inmueble->found()) { $paginas = Inmuebles_Paginas::allContenido(array('inmueble_id' => $this->inmueble->id), array($start, $per)); $count = Inmuebles_Paginas::count(array('inmueble_id' => $this->inmueble->id)); $pos = Inmuebles_Paginas::pos($this->inmueble->id); } return array('idiomas' => Translate::all(), 'codigo' => $this->codigo, 'inmueble' => $this->inmueble, 'paginas' => $paginas, 'count' => $count, 'start' => $start, 'page' => $page, 'per' => $per, 'pos' => $pos); }
public function get() { $page = Request::getQuery('page', 1); $per = Configuration::getInstance()->per; $start = ($page - 1) * $per; $fotos = array(); $count = 0; $pos = 0; if ($this->inmueble->found()) { $fotos = Inmuebles_Fotos::all(array('inmueble_id' => $this->inmueble->id), array('posicion'), array($start, $per)); $count = Inmuebles_Fotos::count(array('inmueble_id' => $this->inmueble->id)); $pos = Inmuebles_Fotos::pos($this->inmueble->id); } return array('codigo' => $this->codigo, 'inmueble' => $this->inmueble, 'fotos' => $fotos, 'count' => $count, 'start' => $start, 'page' => $page, 'per' => $per, 'pos' => $pos); }
/** * Overriding parent * * @param string $name * @return mixed */ public function __get($name) { if ($name == 'session') { if ($this->_session === null) { $req = $this->request; Loader::load('Session', 'core'); $ns = $req->getController(); $subdir = str_replace('/', '_', $req->getControllerSubDirectory()); if ($subdir != '') { $ns = $subdir . '_' . $ns; } $this->_session = new Session($ns); } return $this->_session; } if ($name == 'post') { if (!array_key_exists($name, $this->_caches)) { $this->_caches[$name] = $this->request->getPost(); } return $this->_caches[$name]; } if ($name == 'query') { if (!array_key_exists($name, $this->_caches)) { $this->_caches[$name] = $this->request->getQuery(); } return $this->_caches[$name]; } if ($name == 'params') { if (!array_key_exists($name, $this->_caches)) { $this->_caches[$name] = $this->request->getParams(); } return $this->_caches[$name]; } if ($name == 'controller') { if (!array_key_exists($name, $this->_caches)) { $this->_caches[$name] = $this->request->getController(); } return $this->_caches[$name]; } if ($name == 'action') { if (!array_key_exists($name, $this->_caches)) { $this->_caches[$name] = $this->request->getAction(); } return $this->_caches[$name]; } return parent::__get($name); }
/** * HTTP GET METHOD (static) * * @param string $url * @param array $query * @param array $headers * @param mixed $body * @param array|Traversable $clientOptions * @return Response|bool */ public static function get($url, $query = [], $headers = [], $body = null, $clientOptions = null) { if (empty($url)) { return false; } $request = new Request(); $request->setUri($url); $request->setMethod(Request::METHOD_GET); if (!empty($query) && is_array($query)) { $request->getQuery()->fromArray($query); } if (!empty($headers) && is_array($headers)) { $request->getHeaders()->addHeaders($headers); } if (!empty($body)) { $request->setContent($body); } return static::getStaticClient($clientOptions)->send($request); }
/** * Set Request instance * * @param Request $request * @return void */ public function setRequest(Request $request) { $this->_request = $request; if ($this->_url == null) { $url = $request->getPath() . '/?p=%page%'; $this->setUrl($url); } $page = $request->getQuery('p'); if (is_numeric($page)) { $this->setCurrentPage($page); } }
<?php $root = realpath(dirname(__FILE__)); include_once "{$root}/config.php"; include_once "{$root}/common.php"; $data = Db::query("SELECT s.id\n , s.query\n , s.ids\n FROM search s\n WHERE s.id = '" . Request::getQuery('id') . "'"); if ($data) { $id = $data[0]['id']; $ids = $data[0]['ids']; $query = $data[0]['query']; # $query = $search['query']; # $query = strtolower( $query ); # $query = str_replace(' ', '%', $query); $data = Db::query("SELECT s.id\n , s.filename\n , s.ext\n , s.frame\n , s.comment\n , s.credits\n , s.downloads\n , s.time\n FROM subs s\n WHERE s.id IN ( {$ids} )\n ORDER BY s.downloads DESC"); if ($data) { Db::query("UPDATE search\n SET time = '" . time() . "'\n , cant = cant + 1\n WHERE id = '{$id}'"); Theme::_('Results', array('title' => $query, 'data' => $data)); exit; } } Theme::_('NotFound');
public function testGetQuery() { $request = new Request(array('q1' => 'query1')); $this->assertEquals('query1', $request->getQuery('q1', false)); }
/** * @param $html */ public function appendRendarDebug(&$html) { $tmp = <<<'EOM' {strip} <style type="text/css"> .pmp_debug{ padding:60px 0 0 ; } .pmp_debug_area{ font-size:12px; line-height:140%; position: fixed; left: 0; bottom:0; width: 100%; padding:0 0 0 60px; color:#fff; background: #555; border-top: solid 1px #333; z-index:10000; } .pmp_debug_menu{ float: left; white-space: nowrap; border-right:solid 1px #888; position: relative; } .pmp_debug_menu .pmp_menu{ padding: 12px 20px; display: block; cursor:pointer; } .pmp_debug_menu .pmp_menu_value{ position: absolute; display: none; left: 0; bottom: 42px; background: #FFF; border:solid 1px #666; padding:20px; margin:0; z-index:10; list-style: none; min-width:500px; max-height:400px; overflow:auto; color:#333; } .pmp_debug_menu .pmp_menu_value li{ padding:3px 0px; margin:0; border-top:solid 1px #CCC; list-style: none; } .pmp_debug_menu .pmp_menu_value li:first-child{ border-top:none; } .pmp_debug_menu:hover .pmp_menu_value{ display: block; } </style> <div class="pmp_debug"> <div class="pmp_debug_area"> <div class="pmp_debug_menu"> <div class="pmp_menu">Server</div> <ul class="pmp_menu_value"> {foreach $SERVER as $key => $val} <li>{$key} : {if(is_array($val))}{dump($val)}{else}{$val}{/if}</li> {/foreach} </ul> </div> <div class="pmp_debug_menu"> <div class="pmp_menu">Request</div> <ul class="pmp_menu_value"> {foreach $REQUEST as $key => $val} <li>{$key} : {if(is_array($val))}{dump($val)}{else}{$val}{/if}</li> {/foreach} </ul> </div> <div class="pmp_debug_menu"> <div class="pmp_menu">Get</div> <ul class="pmp_menu_value"> {foreach $GET as $key => $val} <li>{$key} : {if(is_array($val))}{dump($val)}{else}{$val}{/if}</li> {/foreach} </ul> </div> <div class="pmp_debug_menu"> <div class="pmp_menu">Session</div> <div class="pmp_menu_value"> <pre>{dump($SESSION)}</pre> </div> </div> </div> </div> {/strip} EOM; $tp = new Template(); // template value $tp->assign("SERVER", Request::getServer()->getVars()); $tp->assign("REQUEST", Request::getRequest()->getVars()); $tp->assign("GET", Request::getQuery()->getVars()); $tp->assign("SESSION", $_SESSION); // template set $tp->setTemplateStr($tmp); $html = preg_replace("/(<\\/body>)/", $tp->get_display_template(true) . "\$1", $html); }
/** * Returns true if the query string of both specified requests match. * * @param Request $first First request to match. * @param Request $second Second request to match. * * @return boolean True if the query string of both specified requests match. */ public static function matchQueryString(Request $first, Request $second) { return $first->getQuery() === $second->getQuery(); }
<?php $root = realpath(dirname(__FILE__)); include_once "{$root}/config.php"; include_once "{$root}/common.php"; $data = Db::query("SELECT s.id\n , s.filename\n , s.ext\n , s.frame\n , s.comment\n , s.credits\n , s.downloads\n , s.time\n FROM subs s\n WHERE s.credits = '" . urldecode(Request::getQuery('name')) . "'\n ORDER BY s.downloads DESC"); if ($data) { Theme::_('Results', array('title' => $data[0]['credits'], 'data' => $data)); exit; } Theme::_('NotFound');
public static function getApiOrQueryParam($param) { return Request::getApiParam($param) ? Request::getApiParam($param) : Request::getQuery($param); }
<?php $root = realpath(dirname(__FILE__)); include_once "{$root}/config.php"; include_once "{$root}/common.php"; $data = Db::query("SELECT s.source\n , s.downloads\n FROM sources s\n WHERE s.source = '" . Request::getQuery('file') . "'\n LIMIT 1"); if ($data) { Db::query("UPDATE sources\n SET downloads = downloads + 1\n WHERE source = '" . Request::getQuery('file') . "'"); $fullpath = "{$root}/sources/{$data[0]['source']}.zip"; header('Cache-Control: public, must-revalidate'); header('Pragma: hack'); header('Content-Type: application/octet-stream'); header('Content-Length: ' . strval(filesize($fullpath))); header('Content-Disposition: attachment; filename="subavi-' . $data[0]['source'] . '.zip"'); header('Content-Transfer-Encoding: binary'); readfile($fullpath); } else { Theme::_('NotFound'); }
} $oResponse->setData($result); $oResponse->flushJson(); } if (Request::getApiParam('mode') === 'addfolder') { $path = Request::getApiParam('path'); $name = Request::getApiParam('name'); $result = $oFtp->mkdir($path . '/' . $name); if (!$result) { throw new Exception("Unknown error creating this folder"); } $oResponse->setData($result); $oResponse->flushJson(); } if (Request::getApiParam('mode') === 'compress' || Request::getApiParam('mode') === 'extract') { $oResponse->setData(true); $oResponse->flushJson(); } if (Request::getQuery('mode') === 'download') { $download = Request::getQuery('preview') === 'true' ? '' : 'attachment;'; $filePath = Request::getQuery('path'); $fileName = explode('/', $filePath); $fileName = end($fileName); $tmpFilePath = $oFtp->downloadTemp($filePath); if ($fileContent = @file_get_contents($tmpFilePath)) { $oResponse->setData($fileContent); $oResponse->setHeaders(array('Content-Type' => @mime_content_type($tmpFilePath), 'Content-disposition' => sprintf('%s filename="%s"', $download, $fileName))); } $oResponse->flush(); } throw new \Exception('This action is not available in the demo');
<?php $root = realpath(dirname(__FILE__)); include_once "{$root}/config.php"; include_once "{$root}/common.php"; $data = Db::query("SELECT s.id\n , s.filename\n , s.ext\n FROM subs s\n WHERE s.id = '" . Request::getQuery('id') . "'\n LIMIT 1"); if ($data) { Db::query("UPDATE subs\n SET downloads = downloads + 1\n WHERE id = '{$data[0]['id']}'"); $fullpath = "{$root}/upload/{$data[0]['id']}"; # $fullpath = "/var/www/subs/{$data[0]['id']}"; header('Cache-Control: public, must-revalidate'); header('Pragma: hack'); header('Content-Type: application/octet-stream'); header('Content-Length: ' . strval(filesize($fullpath))); header('Content-Disposition: attachment; filename="' . $data[0]['filename'] . '.' . $data[0]['ext'] . '"'); header('Content-Transfer-Encoding: binary'); readfile($fullpath); } else { Theme::_('NotFound'); }
protected function actionWebsite() { // Default action // $this->action = ''; $this->mappy = new Mappy(); $this->twitter = new Twitter(); if (Request::isPost()) { $saved = false; if (Request::hasPost('save') && $this->twitter->connected()) { $idCountry = Request::getPost('country', 0); $idArea = Request::getPost('area', 0); $idLocality = Request::getPost('locality', 0); if (!$idCountry) { $countryName = Request::getPost('country_name', ''); $countryISO = Request::getPost('country_iso', ''); $countryCode = self::encode($countryName); $country = Db::fetchRow("SELECT countries.id_country\n , countries.code\n , countries.name\n , countries.iso\n FROM twcensus_countries AS countries\n WHERE countries.code = '{$countryCode}'\n AND countries.iso = '{$countryISO}'"); if ($country) { $idCountry = $country['id_country']; } else { $idCountry = Db::insert('twcensus_countries', array('code' => $countryCode, 'name' => $countryName, 'iso' => $countryISO)); } } if (!$idArea) { $areaName = Request::getPost('area_name', ''); $areaCode = self::encode($areaName); $area = Db::fetchRow("SELECT areas.id_area\n , areas.code\n , areas.name\n FROM twcensus_areas AS areas\n WHERE areas.id_country = '{$idCountry}'\n AND areas.code = '{$areaCode}'"); if ($area) { $idArea = $area['id_area']; } else { $idArea = Db::insert('twcensus_areas', array('id_country' => $idCountry, 'code' => $areaCode, 'name' => $areaName)); } } if (!$idLocality) { $localityName = Request::getPost('locality_name', ''); $localityCode = self::encode($localityName); $locality = Db::fetchRow("SELECT localities.id_locality\n , localities.code\n , localities.name\n FROM twcensus_localities AS localities\n WHERE localities.id_area = '{$idArea}'\n AND localities.code = '{$localityCode}'"); if ($locality) { $idLocality = $locality['id_locality']; } else { $idLocality = Db::insert('twcensus_localities', array('id_area' => $idArea, 'code' => $localityCode, 'name' => $localityName)); } } $info = array('id_country' => $idCountry, 'id_area' => $idArea, 'id_locality' => $idLocality, 'address' => Request::getPost('address', ''), 'x' => Request::getPost('coord_x', 0), 'y' => Request::getPost('coord_y', 0), 'sex' => Request::getPost('sex', 0), 'age' => Request::getPost('age', 0), 'saved' => time()); Db::update('twcensus_users', $info, array('id_user' => $this->twitter->getID())); $saved = true; } TwCensus::redirect('/' . ($saved ? '?saved' : '')); } elseif (Request::hasQuery('destroy')) { $this->twitter->destroy(); } elseif ($this->twitter->connected()) { $data = $this->twitter->credentials(); $info = array('name' => $data['name'], 'username' => $data['username'], 'location' => $data['location'], 'description' => $data['description'], 'image' => $data['image'], 'url' => $data['url'], 'token' => $this->twitter->getToken(), 'secret' => $this->twitter->getTokenSecret()); if ($this->exists($data['id'])) { $info['modified'] = time(); Db::update('twcensus_users', $info, array('id_user' => $data['id'])); } else { $info['id_user'] = $data['id']; $info['created'] = time(); Db::insert('twcensus_users', $info); } $this->select($data['id']); } elseif (Request::hasQuery('area')) { $this->area = Db::fetchRow("SELECT areas.id_area\n , areas.code\n , areas.name\n FROM twcensus_areas AS areas\n INNER JOIN twcensus_countries AS countries\n ON countries.id_country = areas.id_country\n AND countries.iso = '" . self::$config['country'] . "'\n WHERE areas.code = '" . Request::getQuery('area', '') . "'\n LIMIT 1"); } }
/** * */ protected function rendarParamSet() { // set template $this->template->assign_vars(array("PATH" => Application::getBaseUrl(), "PPATH" => Application::getBaseUrl("/" . $this->project), "ROOT" => Application::getWebUrl(), "PROOT" => Application::getWebUrl("/" . $this->project), "HOST" => Application::getHostname(), "URL" => Application::getHostUrl(), "PROJECT_NAME" => $this->project, "CLASS_NAME" => get_class($this), "SELF" => Application::getBaseUrl() . Request::getUri(), "SERVER" => Request::getServer()->getVars(), "REQUEST" => Request::getRequest()->getVars(), "POST" => Request::post()->getVars(), "GET" => Request::getQuery()->getVars(), "FLASH" => Session::getFlashData())); Session::clearFlash(); }
/** * Returns true if the query string of both specified requests match. * * @param Request $first First request to match. * @param Request $second Second request to match. * * @return boolean True if the query string of both specified requests match. */ public static function matchQueryString(Request $first, Request $second) { if (null !== $first->getQuery(true) && $first->getQuery(true) != $second->getQuery(true)) { return false; } return true; }
<?php $root = realpath(dirname(__FILE__)); include_once "{$root}/config.php"; include_once "{$root}/common.php"; $EmpresaId = Request::getQuery("id"); if (!is_numeric($EmpresaId)) { $EmpresaId = 1; } $Tipo = Request::getQuery("Tipo"); if ($Tipo != 1 && $Tipo != 2 && $Tipo != 3) { $Tipo = 0; } $empresa = Db::query("SELECT * FROM empresas where id={$EmpresaId} and activo=1"); if (count($empresa) == 0) { Theme::_('empresas-notfound'); exit; } $productos = Db::query("SELECT * FROM productos where id_empresa={$EmpresaId} and activo=1"); $query = "SELECT \n temas.id,\n temas.id_empresa,\n temas.id_producto,\n usuarios.usuario,\n temas.tipo,\n temas.titulo,\n temas.fecha,\n count(temas_respuestas.id) as respuestas\n FROM temas \n inner join usuarios on\n temas.id_usuario=usuarios.id \n left join temas_respuestas on\n temas.id=temas_respuestas.id_tema\n where \n temas.id_empresa={$EmpresaId} and\n temas.activo=1 "; if ($Tipo != 0) { $query .= "and temas.tipo={$Tipo} "; } $query .= "group by\n temas.id,\n temas.id_empresa,\n temas.id_producto,\n usuarios.usuario,\n temas.tipo,\n temas.titulo,\n temas.fecha\n "; $temas = Db::query($query); $datos = array(); $datos["TipoTemas"] = array(); $datos["TipoTemas"]["Q"] = "pregunta"; $datos["TipoTemas"]["I"] = "idea"; $datos["TipoTemas"]["P"] = "problema"; $datos["Empresa"] = $empresa[0];
<?php $root = realpath(dirname(__FILE__)); include_once "{$root}/config.php"; include_once "{$root}/common.php"; $id = Request::getQuery('id'); if (is_numeric($id)) { $where = "empresas.id = '{$id}'"; } else { $where = "empresas.abbr = '{$id}'"; } $empresas = Db::query("SELECT empresas.id\n , empresas.nombre\n , empresas.slogan\n , empresas.logo\n , empresas.descripcion\n , empresas.web\n FROM empresas\n WHERE {$where}\n AND empresas.activo = 1\n LIMIT 1"); if (!$empresas) { Theme::_('empresas-notfound'); exit; } $styles = array('q' => 'Pregunta', 'i' => 'Idea', 'p' => 'Problema'); $style = substr(strtolower(Request::getQuery('style', 'q')), 0, 1); $styleName = $styles[$style]; $styleWhere = " AND productos.admite_" . strtolower($styleName) . "s = 1"; $productos = Db::query("SELECT productos.id\n , productos.nombre\n , productos.logo\n FROM productos\n WHERE productos.activo = 1\n {$styleWhere}\n ORDER BY productos.nombre"); Theme::_('temas-agregar', array('title' => $style == 'p' ? "Nuevo {$styleName}" : "Nueva {$styleName}", 'empresa' => $empresas[0], 'productos' => $productos));
/** * Converts Request to Curl console command * * @param Request $request * @return string */ public static function convertRequestToCurlCommand(Request $request) { $message = 'curl -X' . strtoupper($request->getMethod()) . ' '; $message .= '\'http://' . $request->getConnection()->getHost() . ':' . $request->getConnection()->getPort() . '/'; $message .= $request->getPath(); $query = $request->getQuery(); if (!empty($query)) { $message .= '?' . http_build_query($query); } $message .= '\''; $data = $request->getData(); if (!empty($data)) { $message .= ' -d \'' . json_encode($data) . '\''; } return $message; }
public static function init() { if (!self::$init) { if (self::$mode == self::MODE_REQUEST) { if ($_SERVER['SERVER_PORT'] == 443 || !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { $secure = true; } else { $secure = false; } if (WEB_SUB_FOLDER == '/') { //WTF? //print_stacktrace(); die; } if (session_id() == '') { session_set_cookie_params(0, WEB_SUB_FOLDER, null, $secure, true); session_name('Controller'); @session_start(); } date_default_timezone_set(ConfigValue::get('Timezone', 'Africa/Johannesburg')); } self::check_quotes(); self::$salt = ConfigValue::get('Salt', 'Change this to something random!'); //TODO jrgns: Don't know if I like this here... $user = BackendUser::check(); //Debugging self::$debug = false; if (SITE_STATE != 'production' || $user && in_array('superadmin', $user->roles)) { switch (true) { case array_key_exists('debug', self::$query_vars): //Default to lowest level self::$debug = is_numeric(self::$query_vars['debug']) ? (int) self::$query_vars['debug'] : 1; break; } } if ($config_debug = ConfigValue::get('Debug', false)) { self::$debug = $config_debug; } Backend::add('debug', self::$debug); if (SITE_STATE != 'production' || self::$debug) { ini_set('display_errors', 1); ini_set('error_reporting', E_ALL | E_STRICT); } else { ini_set('display_errors', 0); } //q in the payload overrides the q in the query string $query = array_key_exists('q', self::$payload) ? self::$payload['q'] : (array_key_exists('q', self::$query_vars) ? self::$query_vars['q'] : ''); $query = self::checkQuery(Request::getQuery($query)); $query = Hook::run('init', 'pre', array($query)); self::parseQuery($query); //View self::$view = View::getInstance(); if (!self::$view instanceof View) { self::$view = View::getInstance(ConfigValue::get('DefaultView', 'HtmlView')); self::whoops('Unrecognized Request', array('message' => 'Could not find a View for the Request', 'code_hint' => 406)); if (self::$debug) { print_stacktrace(); var_dump(self::$query_vars, $query, $_REQUEST, $_SERVER); } } //Sessions if (array_key_exists('error', $_SESSION)) { Backend::addError($_SESSION['error']); } if (array_key_exists('notice', $_SESSION)) { Backend::addNotice($_SESSION['notice']); } if (array_key_exists('success', $_SESSION)) { Backend::addSuccess($_SESSION['success']); } Hook::run('init', 'post'); self::$init = true; } }