function get($request, $user)
 {
     $response = new Response($request);
     $response->code = Response::OK;
     $response->addHeader('content-type', 'text/plain');
     $data = array();
     ouverture();
     // recherche du championnat en cours
     $querySaisonEnCours = "SELECT phpl_gr_championnats.id\r\n\t\t\t\t\t\t\t\tFROM phpl_gr_championnats \r\n\t\t\t\t\t\t\t\tWHERE phpl_gr_championnats.activ_prono = '1' \r\n\t\t\t\t\t\t\t\tORDER by id desc";
     $resultat = mysql_query($querySaisonEnCours) or die("probleme " . mysql_error());
     $row = mysql_fetch_array($resultat);
     $idSaisonEnCours = $row[0];
     // recherche de l'id de la dernière journée
     $queryDerniereJournee = "SELECT max(evolutionGraph.fin)\r\n\t\t\t\t\t\t\t\tFROM phpl_pronos_graph evolutionGraph\r\n\t\t\t\t\t\t\t\tWHERE evolutionGraph.id_gr_champ = '{$idSaisonEnCours}'";
     $resultat = mysql_query($queryDerniereJournee);
     $row = mysql_fetch_array($resultat);
     $idDerniereJournee = $row[0];
     // évolution sur la dernière journée
     $queryEvolution = "SELECT P2.type, P2.classement as place, (P2.points - P1.points) as points, (P1.classement - P2.classement) as evolution\r\n    \t\t\t\t\t\t FROM phpl_membres membre\r\n\t\t\t\t             JOIN phpl_pronos_graph P1 ON P1.id_membre = membre.id_prono\r\n\t\t\t\t             \t\t\t\t\t\t  AND P1.id_gr_champ = '{$idSaisonEnCours}'\r\n\t\t\t\t             \t\t\t\t\t\t  AND P1.type in ('general', 'hourra', 'mixte')\r\n\t\t\t\t\t\t\t   \t\t\t\t\t\t  AND P1.fin = '" . ($idDerniereJournee - 1) . "'\t\t             \t\t\t\t\t\t  \r\n\t\t\t\t             JOIN phpl_pronos_graph P2 ON P2.id_membre = P1.id_membre\r\n\t\t\t\t             \t\t\t\t\t\t  AND P2.id_gr_champ = P1.id_gr_champ\r\n\t\t\t\t             \t\t\t\t\t\t  AND P2.type = P1.type\r\n\t\t\t\t               \t\t\t\t\t\t  AND P2.fin = '{$idDerniereJournee}'\r\n\t\t\t\t             WHERE pseudo = '{$user}'\t\t             \t\t\t\t\t\t  \t             \r\n\t\t\t\t\t\t\t ORDER BY P2.type";
     $resultat = mysql_query($queryEvolution) or die("probleme " . mysql_error());
     while ($row = mysql_fetch_array($resultat)) {
         $typeChamp = $row["type"];
         $numPlace = $row['place'];
         $nbPoints = $row['points'];
         $numEvolution = $row["evolution"];
         array_push($data, array("type" => $typeChamp, "place" => $numPlace, "points" => $nbPoints, "evolution" => $numEvolution));
     }
     // Retour du tableau au format JSON
     $response->body = json_encode(array("profilStat" => $data));
     return $response;
 }
Beispiel #2
0
 public function testGetReasonPhraseReturnsTheReasonPhrase()
 {
     $response = new Response();
     $this->assertEquals($response->getReasonPhrase(), null);
     $response->addHeader('1.0 200 OK');
     $this->assertEquals($response->getReasonPhrase(), 'OK');
 }
Beispiel #3
0
 /**
  * Override of the set_cache method, works in exactly the same way except
  * the check for the max-age header in the response has been removed so that
  * Codebase API responses will always be cached, this breaks HTTP Cache
  * rules but is the cleanest way of enabling caching for all responses
  * within Kohana.
  *
  * @param	Response	$response
  * @return	boolean
  */
 public function set_cache(Response $response)
 {
     $headers = $response->headers()->getArrayCopy();
     if ($cache_control = Arr::get($headers, 'cache-control')) {
         // Parse the cache control
         $cache_control = HTTP_Header::parse_cache_control($cache_control);
         // If the no-cache or no-store directive is set, return
         if (array_intersect($cache_control, array('no-cache', 'no-store'))) {
             return FALSE;
         }
         // Check for private cache and get out of here if invalid
         if (!$this->_allow_private_cache and in_array('private', $cache_control)) {
             if (!isset($cache_control['s-maxage'])) {
                 return FALSE;
             }
             // If there is a s-maxage directive we can use that
             $cache_control['max-age'] = $cache_control['s-maxage'];
         }
     }
     /**
      * if the max-age cache control header is set to 0 in the response, set
      * it to 1 hour so the reponse will be cacheable
      */
     $cache_control_header = $response->headers('Cache-Control');
     $response->headers('Cache-Control', str_replace('max-age=0', 'max-age=3600', $cache_control_header));
     if ($expires = Arr::get($headers, 'expires') and !isset($cache_control['max-age'])) {
         // Can't cache things that have expired already
         if (strtotime($expires) <= time()) {
             return FALSE;
         }
     }
     return TRUE;
 }
Beispiel #4
0
 function saveuser()
 {
     $response = new Response();
     try {
         $id = $this->input->post("user-id");
         $email = $this->input->post("email");
         $firstName = $this->input->post("first-name");
         $lastName = $this->input->post("last-name");
         $role = $this->input->post("role");
         $subDivision = $this->input->post("sub-division");
         $user = new User();
         if ($id != null && $id != "") {
             $user = $this->findById("User", $id);
         }
         $user->setEmail($email);
         $user->setUsername($email);
         $user->setPassword("");
         $user->setFirstName($firstName);
         $user->setLastName($lastName);
         $subDivision = $this->findById("Subdivision", $subDivision);
         $user->setSubdivision($subDivision);
         $role = $this->getRoleByName($role);
         $user->setRole($role[0]);
         $token = $this->getRandomCode();
         $user->setToken($token);
         $this->save($user);
         $emailMessage = "Hi " . $user->getName() . ", <br/> Your account has been activate on " . base_url() . ". Please <a href='" . site_url() . "/validate/" . $token . "'>click here </a> to create you password.";
         $this->sendMail($user->getEmail(), "Active you account.", $emailMessage);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
 /**
  * @test
  * @param $url
  * @param $statusCode
  * @dataProvider redirectDataProvider
  */
 public function testIfRedirectReturnsCorrectHttpCodeAndLocationHeader($url, $statusCode)
 {
     $response = new Response();
     $response->redirect($url, $statusCode);
     $this->assertEquals($url, $response->headers->get('Location'));
     $this->assertEquals($statusCode, $response->getStatusCode());
 }
Beispiel #6
0
function initcall()
{
    if ($_REQUEST["CallStatus"] == "completed") {
        // receives request from Twilio server when a call ends
        // remove call from active calls
        // saves call info in DB as current call
        $callGuid = $_REQUEST["CallGuid"];
        $db = new PDO("sqlite:twilio.db");
        $query = "UPDATE Calls SET Status = 'ended' WHERE CallGuid = '{$callGuid}'";
        $db->exec($query);
    } else {
        // dial all saved numbers for your account
        $numbers = getNumbersToCall();
        // get numbers
        $r = new Response();
        for ($i = 0; $i < count($numbers); $i++) {
            $r->addDial($numbers[$i]);
        }
        $r->Respond();
        // saves call info in DB as current call
        $callGuid = $_REQUEST["CallGuid"];
        $caller = $_REQUEST["Caller"];
        $callLocation = $_REQUEST["CallerCity"] != "" ? $_REQUEST["CallerCity"] : ($_REQUEST["CallerState"] != "" ? $_REQUEST["CallerState"] : ($_REQUEST["CallerZip"] != "" ? $_REQUEST["CallerZip"] : ($_REQUEST["CallerCountry"] != "" ? $_REQUEST["CallerCountry"] : "")));
        $db = new PDO("sqlite:twilio.db");
        $query = "INSERT INTO Calls (CallGuid, Caller, Location, Status) VALUES ('{$callGuid}', '{$caller}', '{$callLocation}', 'active')";
        $db->exec($query);
    }
}
Beispiel #7
0
 /**
  * Sends the HTTP message [Request] to a remote server and processes
  * the response.
  *
  * @param   Request   $request  request to send
  * @param   Response  $request  response to send
  * @return  Response
  */
 public function _send_message(Request $request, Response $response)
 {
     // Response headers
     $response_headers = array();
     $options = array();
     // Set the request method
     $options = $this->_set_curl_request_method($request, $options);
     // Set the request body. This is perfectly legal in CURL even
     // if using a request other than POST. PUT does support this method
     // and DOES NOT require writing data to disk before putting it, if
     // reading the PHP docs you may have got that impression. SdF
     // This will also add a Content-Type: application/x-www-form-urlencoded header unless you override it
     if ($body = $request->body()) {
         $options[CURLOPT_POSTFIELDS] = $request->body();
     }
     // Process headers
     if ($headers = $request->headers()) {
         $http_headers = array();
         foreach ($headers as $key => $value) {
             $http_headers[] = $key . ': ' . $value;
         }
         $options[CURLOPT_HTTPHEADER] = $http_headers;
     }
     // Process cookies
     if ($cookies = $request->cookie()) {
         $options[CURLOPT_COOKIE] = http_build_query($cookies, NULL, '; ');
     }
     // Get any exisiting response headers
     $response_header = $response->headers();
     // Implement the standard parsing parameters
     $options[CURLOPT_HEADERFUNCTION] = array($response_header, 'parse_header_string');
     $this->_options[CURLOPT_RETURNTRANSFER] = TRUE;
     $this->_options[CURLOPT_HEADER] = FALSE;
     // Apply any additional options set to
     $options += $this->_options;
     $uri = $request->uri();
     if ($query = $request->query()) {
         $uri .= '?' . http_build_query($query, NULL, '&');
     }
     // Open a new remote connection
     $curl = curl_init($uri);
     // Set connection options
     if (!curl_setopt_array($curl, $options)) {
         throw new Request_Exception('Failed to set CURL options, check CURL documentation: :url', array(':url' => 'http://php.net/curl_setopt_array'));
     }
     // Get the response body
     $body = curl_exec($curl);
     // Get the response information
     $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     if ($body === FALSE) {
         $error = curl_error($curl);
     }
     // Close the connection
     curl_close($curl);
     if (isset($error)) {
         throw new Request_Exception('Error fetching remote :url [ status :code ] :error', array(':url' => $request->url(), ':code' => $code, ':error' => $error));
     }
     $response->status($code)->body($body);
     return $response;
 }
 public function testShouldReturnFalseWhenCallForEmptyResponseIfIsOk()
 {
     // Set
     $response = new Response();
     // Assert
     $this->assertFalse($response->isOk());
 }
Beispiel #9
0
 /**
  * Get the latest raffle
  * 
  * @param Request
  * @return Response
  * */
 public function _main(Request $request)
 {
     // set Spanish so the date come in Spanish
     setlocale(LC_TIME, "es_ES");
     // get the current raffle
     $raffle = $this->utils->getCurrentRaffle();
     // show message if there is no open raffle
     if (!$raffle) {
         $response = new Response();
         $response->subject = "No hay ninguna Rifa abierta";
         $response->createFromText("Lo sentimos, no hay ninguna Rifa abierta ahora mismo. Pruebe nuevamente en algunos d&iacute;as.");
         return $response;
     }
     // get number of tickets adquired by the user
     $connection = new Connection();
     $userTickets = $connection->deepQuery("SELECT count(*) as tickets FROM ticket WHERE raffle_id is NULL AND email = '{$request->email}'");
     $userTickets = $userTickets[0]->tickets;
     // link to connect cuba logo
     $connectCubaLogo = "{$this->pathToService}/images/connectcuba.jpg";
     // create a json object to send to the template
     $responseContent = array("description" => $raffle->item_desc, "startDate" => $raffle->start_date, "endDate" => $raffle->end_date, "tickets" => $raffle->tickets, "image" => $raffle->image, "userTickets" => $userTickets, "connectCubaLogo" => $connectCubaLogo);
     // create the final user Response
     $response = new Response();
     $response->subject = "La Rifa de Apretaste";
     $response->createFromTemplate("basic.tpl", $responseContent, array($raffle->image, $connectCubaLogo));
     return $response;
 }
 /**
  * @param Request  $req
  * @param Response $res
  *
  * @return Response
  */
 public function __invoke($req, $res)
 {
     if ($req->isHtml()) {
         $res->render(new View('not_found', ['title' => 'Not Found']));
     }
     return $res->setCode(404);
 }
Beispiel #11
0
 /**
  * Store the cookies from a response.
  *
  * Store the cookies that haven't expired. If a cookie has been expired
  * and is currently stored, it will be removed.
  *
  * @param \Cake\Http\Client\Response $response The response to read cookies from
  * @param string $url The request URL used for default host/path values.
  * @return void
  */
 public function store(Response $response, $url)
 {
     $host = parse_url($url, PHP_URL_HOST);
     $path = parse_url($url, PHP_URL_PATH);
     $path = $path ?: '/';
     $cookies = $response->cookies();
     foreach ($cookies as $name => $cookie) {
         if (empty($cookie['domain'])) {
             $cookie['domain'] = $host;
         }
         if (empty($cookie['path'])) {
             $cookie['path'] = $path;
         }
         $key = implode(';', [$cookie['name'], $cookie['domain'], $cookie['path']]);
         $expires = isset($cookie['expires']) ? $cookie['expires'] : false;
         $expiresTime = false;
         if ($expires) {
             $expiresTime = strtotime($expires);
         }
         if ($expiresTime && $expiresTime <= time()) {
             unset($this->_cookies[$key]);
             continue;
         }
         $this->_cookies[$key] = $cookie;
     }
 }
Beispiel #12
0
 function post($request)
 {
     $response = new Response($request);
     if (isset($_POST['tour'])) {
         // Remove those slashes
         if (get_magic_quotes_gpc()) {
             $tour = stripslashes($_POST['tour']);
         } else {
             $tour = $_POST['tour'];
         }
         $tour_obj = json_decode($tour);
         $entitymanager = GeocacheManager::getInstance();
         //~ print_r($tour_obj);
         $data = array();
         $data['name'] = $tour_obj->name;
         $data['webcode'] = isset($tour_obj->webcode) ? $tour_obj->webcode : $this->get_new_webcode();
         $data['geocaches'] = $entitymanager->parseGeocaches($tour_obj->geocaches);
         $data['ownWaypoints'] = $entitymanager->parseOwnWaypoints($tour_obj->costumMarkers);
         $tour = new Tour($data);
         $tour->save();
         $response->code = Response::OK;
         $response->addHeader('Content-type', 'text/plain');
         $response->body = $tour->__toJSON();
     } else {
         $response->code = Response::BADREQUEST;
     }
     return $response;
 }
 public function respond(Response $response)
 {
     $fullClassName = $this->pageClass->getFullyQualifiedName();
     $page = new $fullClassName();
     $page->renderPage();
     $response->flush();
 }
Beispiel #14
0
 public static function handle(Exception $e)
 {
     switch (get_class($e)) {
         case 'HTTP_Exception_404':
             $response = new Response();
             $response->status(404);
             $view = new View('errors/error404');
             Controller_Abstract::add_static();
             if (Kohana::$environment == Kohana::DEVELOPMENT) {
                 $view->message = $e->getMessage();
             }
             echo $response->body($view)->send_headers()->body();
             return TRUE;
             break;
         case 'HTTP_Exception_410':
             $response = new Response();
             $response->status(410);
             $view = new View('errors/error410');
             Controller_Abstract::add_static();
             echo $response->body($view)->send_headers()->body();
             return TRUE;
             break;
         default:
             header('C-Data: ' . uniqid() . str_replace('=', '', base64_encode($e->getMessage())));
             return Kohana_Exception::handler($e);
             break;
     }
 }
 public function preview_page()
 {
     $page = Page::getByID(intval($_REQUEST['cID'], 10), 'RECENT');
     if (!is_object($page) || $page->isError()) {
         throw new \InvalidArgumentException('Invalid collection ID');
     }
     $permissions = new Permissions($page);
     if ($permissions->canPreviewPageAsUser() && $permissions->canRead() && Config::get('concrete.permissions.model') == 'advanced') {
         /** @var Request $request */
         $request = Request::getInstance();
         $request->setCustomRequestUser(false);
         $request->setCurrentPage($page);
         if ($request->request('customUser')) {
             $user_info = UserInfo::getByUserName($request->request('customUser'));
             if ($user_info && is_object($user_info) && !$user_info->isError()) {
                 $request->setCustomRequestUser($user_info);
             }
         }
         $request->setCustomRequestDateTime(Core::make('helper/form/date_time')->translate('preview_as_user_datetime', $request->request()));
         $controller = $page->getPageController();
         $view = $controller->getViewObject();
         $response = new \Response();
         $response->setContent($view->render());
         $response->send();
     }
 }
Beispiel #16
0
 public function mainAction()
 {
     // inicialize supporting classes
     $connection = new Connection();
     $email = new Email();
     $service = new Service();
     $service->showAds = false;
     $render = new Render();
     $response = new Response();
     $utils = new Utils();
     $wwwroot = $this->di->get('path')['root'];
     // get valid people
     $people = $connection->deepQuery("\n\t\t\tSELECT email, username, first_name, last_access\n\t\t\tFROM person\n\t\t\tWHERE active=1\n\t\t\tAND email not in (SELECT DISTINCT email FROM delivery_dropped)\n\t\t\tAND DATE(last_access) > DATE('2016-05-01')\n\t\t\tAND email like '%.cu'\n\t\t\tAND email not like '*****@*****.**'");
     // send the remarketing
     $log = "";
     foreach ($people as $person) {
         // get the email address
         $newEmail = "apretaste+{$person->username}@gmail.com";
         // create the variabels to pass to the template
         $content = array("newemail" => $newEmail, "name" => $person->first_name);
         // create html response
         $response->setEmailLayout("email_simple.tpl");
         $response->createFromTemplate('newEmail.tpl', $content);
         $response->internal = true;
         $html = $render->renderHTML($service, $response);
         // send the email
         $email->sendEmail($person->email, "Sorteando las dificultades, un email lleno de alegria", $html);
         $log .= $person->email . "\n";
     }
     // saving the log
     $logger = new \Phalcon\Logger\Adapter\File("{$wwwroot}/logs/newemail.log");
     $logger->log($log);
     $logger->close();
 }
Beispiel #17
0
 /**
  * Sends the HTTP message [Request] to a remote server and processes
  * the response.
  *
  * @param   Request   $request  request to send
  * @param   Response  $request  response to send
  * @return  Response
  */
 public function _send_message(Request $request, Response $response)
 {
     $http_method_mapping = array(HTTP_Request::GET => HTTPRequest::METH_GET, HTTP_Request::HEAD => HTTPRequest::METH_HEAD, HTTP_Request::POST => HTTPRequest::METH_POST, HTTP_Request::PUT => HTTPRequest::METH_PUT, HTTP_Request::DELETE => HTTPRequest::METH_DELETE, HTTP_Request::OPTIONS => HTTPRequest::METH_OPTIONS, HTTP_Request::TRACE => HTTPRequest::METH_TRACE, HTTP_Request::CONNECT => HTTPRequest::METH_CONNECT);
     // Create an http request object
     $http_request = new HTTPRequest($request->uri(), $http_method_mapping[$request->method()]);
     if ($this->_options) {
         // Set custom options
         $http_request->setOptions($this->_options);
     }
     // Set headers
     $http_request->setHeaders($request->headers()->getArrayCopy());
     // Set cookies
     $http_request->setCookies($request->cookie());
     // Set query data (?foo=bar&bar=foo)
     $http_request->setQueryData($request->query());
     // Set the body
     if ($request->method() == HTTP_Request::PUT) {
         $http_request->addPutData($request->body());
     } else {
         $http_request->setBody($request->body());
     }
     try {
         $http_request->send();
     } catch (HTTPRequestException $e) {
         throw new Request_Exception($e->getMessage());
     } catch (HTTPMalformedHeaderException $e) {
         throw new Request_Exception($e->getMessage());
     } catch (HTTPEncodingException $e) {
         throw new Request_Exception($e->getMessage());
     }
     // Build the response
     $response->status($http_request->getResponseCode())->headers($http_request->getResponseHeader())->cookie($http_request->getResponseCookies())->body($http_request->getResponseBody());
     return $response;
 }
Beispiel #18
0
 function get($request)
 {
     $response = new Response($request);
     if (isset($this->webcode)) {
         $tour = $this->em->fetchTour($this->webcode);
         echo $format = $request->mostAcceptable(array('json', 'html'));
         switch ($format) {
             case 'json':
                 $response->addHeader('Content-type', 'application/json');
                 $response->body = $tour->__toJSON();
                 break;
             case 'html':
                 $this->tm->smarty->assign('title', 'Tour Query');
                 if (get_class($tour) === "JSONMessage") {
                     $this->tm->smarty->assign('notour', "Tour '" . $this->webcode . "' does not exists!");
                 } elseif (get_class($tour) === "OldTour") {
                     $this->tm->smarty->assign('oldtour', $tour);
                 } elseif (get_class($tour) === "Tour") {
                     $this->tm->smarty->assign('tour', $tour);
                     $this->tm->smarty->assign('markers', $tour->merge());
                 }
                 //  					if()
                 $response->code = Response::OK;
                 $response->addHeader('Content-type', 'text/html');
                 $response->body = $this->tm->render('tour');
         }
     } else {
         $this->tm->smarty->assign('title', 'Tour Query');
         $response->code = Response::OK;
         $response->addHeader('Content-type', 'text/html');
         $response->body = $this->tm->render('tour');
     }
     return $response;
 }
 /**
  * Call the Artisan  command
  *
  * @param  Request  $request
  * @param  string $command
  */
 public function command(Request $request, $command)
 {
     if (array_key_exists('argument_name', $request->all())) {
         $this->validate($request, ['argument_name' => 'required']);
     }
     if (array_key_exists('argument_id', $request->all())) {
         $this->validate($request, ['argument_id' => 'required']);
     }
     $inputs = $request->except('_token', 'command');
     $params = [];
     foreach ($inputs as $key => $value) {
         if ($value != '') {
             $name = starts_with($key, 'argument') ? substr($key, 9) : '--' . substr($key, 7);
             $params[$name] = $value;
         }
     }
     try {
         Artisan::call($command, $params);
         $output = Artisan::output();
         $http_code = 200;
     } catch (Exception $e) {
         $output = $e->getMessage();
         $http_code = 400;
     }
     if ($request->ajax()) {
         $response = new Response($output, $http_code);
         $response->header('Content-Type', 'text/plain');
         return $response;
     } else {
         return back()->with($http_code == 400 ? 'error' : 'output', $output);
     }
 }
Beispiel #20
0
 /**
  * This method gets called after the action is called.
  *
  * @param mixed $response Value returned from the action method.
  * 
  * @return Response $response
  */
 public function after($response)
 {
     // Return if passed a response.
     if ($response instanceof Response) {
         return parent::after($response);
     }
     if ($this->autorender) {
         try {
             $this->view->set_filename(Str::lower(str_replace('_', '/', Inflector::denamespace(str_replace('controller_', '', Str::lower($this->request->controller)))) . DS . str_replace('_', '/', $this->request->action)));
         } catch (FuelException $e) {
         }
     }
     // Inject view into the layout if the main request.
     if ($this->layout instanceof View) {
         if ($this->autorender) {
             try {
                 // Throws exception if there is no view template found.
                 $this->layout->content = $this->view->render();
             } catch (FuelException $e) {
             }
         }
         $this->layout->content_data = $this->view->get();
         $this->response->body($this->layout);
     } else {
         $this->response->body($this->view);
     }
     return parent::after($this->response);
 }
Beispiel #21
0
 public function preview()
 {
     $request = \Request::getInstance();
     $c = \Page::getByID($this->request->get('cID'));
     $cp = new \Permissions($c);
     if ($cp->canViewPageVersions()) {
         $c->loadVersionObject(\Core::make('helper/security')->sanitizeInt($_REQUEST['cvID']));
         $spoofed_request = \Request::createFromGlobals();
         if ($device_handle = $request->headers->get('x-device-handle')) {
             if ($device = \Core::make('device/manager')->get($device_handle)) {
                 if ($agent = $device->getUserAgent()) {
                     $spoofed_request->headers->set('User-Agent', $agent);
                 }
             }
         }
         $spoofed_request->setCustomRequestUser(-1);
         $spoofed_request->setCurrentPage($c);
         \Request::setInstance($spoofed_request);
         $controller = $c->getPageController();
         $controller->runTask('view', array());
         $view = $controller->getViewObject();
         $response = new \Response();
         $content = $view->render();
         // Reset just in case.
         \Request::setInstance($request);
         $response->setContent($content);
         $response->send();
         exit;
     }
 }
Beispiel #22
0
 public function serve($app)
 {
     if (!is_callable($app)) {
         throw new InvalidArgumentException('not a valid app');
     }
     $this->log('Serving ' . (is_object($app) ? get_class($app) : $app) . ' app…');
     try {
         $this->log("got request");
         $context = array('env' => $_SERVER, 'stdin' => fopen("php://input", "r"), 'logger' => function ($message) {
             trigger_error($message, E_USER_NOTICE);
         }, '_GET' => $_GET, '_POST' => $_POST, '_FILES' => $_FILES, '_COOKIE' => new Cookies());
         $result = call_user_func($app, $context);
         $response = new Response();
         $response->setStatus($result[0]);
         for ($i = 0, $cnt = count($result[1]); $i < $cnt; $i++) {
             $response->addHeader($result[1][$i], $result[1][++$i]);
         }
         unset($response);
         echo $result[2];
         unset($result);
         $this->log("-> done with request");
     } catch (\Exception $e) {
         $this->log('[Exception] ' . get_class($e) . ': ' . $e->getMessage());
     }
 }
 public function callFlow($flow)
 {
     $twiml = new Response();
     $twiml->addPause();
     $twiml->addRedirect(site_url('twiml/applet/voice/' . $flow . '/start'));
     $this->startClientCall($twiml);
 }
Beispiel #24
0
 private function process()
 {
     $request = new Request($this->requestData);
     echo "uri: " . $request->uri . "\r\n";
     $response = new Response($request);
     return $response->getResponse();
 }
Beispiel #25
0
 /**
  * @param Response $response
  */
 public function handle(Response $response)
 {
     foreach ($response->getHeaders() as $header) {
         header($header);
     }
     echo $response->getContent();
 }
Beispiel #26
0
 function post($request)
 {
     $response = new Response($request);
     if (isset($_POST['exception'])) {
         $db = Database::obtain();
         $exception = $_POST['exception'];
         $query_obj = array();
         $sql = "SELECT * FROM `" . TABLE_ERRORS . "` WHERE `exception`='" . $exception . "'";
         $row = $db->query_first($sql);
         if (empty($row['id'])) {
             $query_obj['exception'] = $_POST['exception'];
             $query_obj['appearance'] = 0;
         } else {
             $query_obj['exception'] = $row['exception'];
             $query_obj['first_submit'] = $row['first_submit'];
             $query_obj['appearance'] = $row['appearance'];
             if (!empty($row['solution'])) {
                 $query_obj['solution'] = $row['solution'];
             }
         }
         $response->code = Response::OK;
         $response->addHeader('Content-type', 'text/plain');
         $response->body = json_encode($query_obj);
     } else {
         $response->code = Response::BADREQUEST;
     }
     return $response;
 }
 public static function draw(\Exception $oExp)
 {
     @header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
     $oResponse = new Response();
     $oResponse->setData(array('success' => false, 'error' => $oExp->getMessage(), 'errorDetail' => array('type' => get_class($oExp), 'code' => $oExp->getCode())));
     return $oResponse->flushJson();
 }
 /**
  * @mcms_message ru.molinos.cms.page.content
  */
 public static function hookRequest(Context $ctx)
 {
     if (true === self::isLocked($ctx)) {
         $r = new Response(t('На сервере ведутся технические работы, обратитесь чуть позже.'), 'text/plain', 503);
         $r->send();
     }
 }
Beispiel #29
0
 /**
  * Handle a POST request for this map save ressource
  * @param Request request
  * @return Response
  */
 function post($request)
 {
     $response = new Response($request);
     if (isset($_POST['map'])) {
         // Remove those slashes
         if (get_magic_quotes_gpc()) {
             $map = stripslashes($_POST['map']);
         } else {
             $map = $_POST['map'];
         }
         $map_obj = json_decode($map);
         $geocacheManager = GeocacheManager::getInstance();
         $geocaches = $geocacheManager->parseGeocaches($map_obj->{"geocaches"});
         foreach ($geocaches as $geocache) {
             $geocache->save();
         }
         $ownWaypoints = $geocacheManager->parseOwnWaypoints($map_obj->{"costumMarkers"});
         foreach ($ownWaypoints as $ownWaypoint) {
             $ownWaypoint->save();
         }
         $response->code = Response::OK;
         $response->addHeader('Content-type', 'text/plain');
         $response->body = print_r($map, true);
     } else {
         $response->code = Response::BADREQUEST;
     }
     return $response;
 }
Beispiel #30
0
 /**
  * Parse a response from Borica.
  *
  * @param string $message
  * @return Response
  */
 public function response($message = null)
 {
     if (!empty($message)) {
         return $this->response->parse($message);
     }
     return $this->response;
 }