Example #1
0
 public static function handle(Exception $e)
 {
     switch (get_class($e)) {
         case 'HTTP_Exception_404':
             // Посылаем статус страницы 404
             $response = new Response();
             $response->status(404);
             $response->protocol('HTTP/1.1');
             // Посылаем корректный статус 404 ошибки
             /* header('HTTP/1.0 404 Not Found');
                header('HTTP/1.1 404 Not Found');
                header('Status: 404 Not Found'); */
             // Создаем вид для отображения 404 ошибки
             $view = new View_Error_404('error/404');
             $view->message = $e->getMessage();
             // Если шаблон есть - отображаем страницу ошибки
             if (!empty($view)) {
                 // Выводим шаблон
                 echo $response->send_headers()->body($view->render());
             } else {
                 echo $response->body('<h1>Не найден шаблон для View_Error_404</h1>');
             }
             return true;
             break;
         default:
             Kohana_Exception::handler($e);
     }
 }
 /**
  * Test the content type is sent when set
  * 
  * @test
  */
 public function test_content_type_when_set()
 {
     $content_type = 'application/json';
     $response = new Response();
     $response->headers('content-type', $content_type);
     $headers = $response->send_headers()->headers();
     $this->assertSame($content_type, (string) $headers['content-type']);
 }
Example #3
0
 /**
  * Tests that send headers processes the headers sent to PHP correctly
  * 
  * @dataProvider provider_send_headers
  *
  * @param   array     state in
  * @param   array     expected out
  * @return  void
  */
 public function test_send_headers(array $state, array $expected, $expose)
 {
     Kohana::$expose = $expose;
     $response = new Response();
     $response->headers($state);
     $this->assertSame($expected, $response->send_headers(FALSE, array($this, 'send_headers_handler')));
 }
Example #4
0
 /**
  * Tests that the default content type is sent if not set
  * 
  * @test
  */
 public function test_default_content_type_when_not_set()
 {
     $response = new Response();
     $headers = $response->send_headers()->headers();
     $this->assertSame(Kohana::$content_type . '; charset=' . Kohana::$charset, (string) $headers['content-type']);
 }
Example #5
0
 /**
  * Tests that the default content type is sent if not set
  * 
  * @test
  */
 public function test_default_content_type_when_not_set()
 {
     $this->markTestSkipped('send_headers() can only be executed once, test will never pass in current API');
     $response = new Response();
     $headers = $response->send_headers()->headers();
     $this->assertSame(Kohana::$content_type . '; charset=' . Kohana::$charset, (string) $headers['content-type']);
 }
Example #6
0
 public function action_exportinvalidleads($data_id)
 {
     $headings = array('Dialler ID' => 'dialler_lead_id', 'Title' => 'title', 'First Name' => 'first_name', 'Last Name' => 'last_name', 'Number' => 'phone_number', 'Alt Number' => 'alt_phone', 'Status' => 'number_data');
     $headingArray = array();
     $headingCounts = array();
     $headingNames = array();
     foreach ($headings as $heading => $dbcolumn) {
         $headingCounts[] = $dbcolumn;
         $headingNames[] = $heading;
     }
     list($validLeads, $validCount, $filterCount) = \Data\Model_Data::get_leads($data_id, -1, 0, 'dialler_lead_id', 'asc', '=');
     $invalidArray = array();
     $makeArray = array();
     foreach ($validLeads as $singleLead) {
         $singleArray = array();
         foreach ($headings as $heading) {
             if ($heading == 'number_data') {
                 $allData = unserialize($singleLead[$heading]);
                 $diallerIDs = array();
                 if (isset($allData['duplicates']['data_list_ids'])) {
                     foreach ($allData['duplicates']['data_list_ids'] as $did) {
                         $diallerListIDQuery = \DB::select('dialler_id')->from('data')->where('id', $did)->execute()->as_array();
                     }
                     if (count($diallerListIDQuery) > 0) {
                         $diallerIDs[] = $diallerListIDQuery[0]['dialler_id'];
                     }
                 }
                 if (isset($allData['duplicates']['list_ids'])) {
                     foreach ($allData['duplicates']['list_ids'] as $did) {
                         $diallerIDs[] = $did;
                     }
                 }
                 $singleArray[] = count($diallerIDs) > 0 ? 'Duplicate from list(s) ' . implode("/", $diallerIDs) : 'TPS Match';
             } else {
                 $singleArray[] = $singleLead[$heading];
             }
         }
         $makeArray[] = $singleArray;
     }
     $data = implode(",", $headingNames) . "\n";
     foreach ($makeArray as $oneLine) {
         $data .= implode(",", $oneLine) . "\n";
     }
     //$data = \Format::forge($makeArray)->to_csv();
     $response = new \Response();
     $response->set_header('Content-Type', 'text/csv');
     $response->set_header('Content-Disposition', 'attachment; filename="' . $data_id . '_' . date('Ymd-Hi') . '.csv"');
     // $response->body($data);
     //return $response;
     $response->send_headers();
     echo $data;
     return "";
 }
Example #7
0
 /**
  * redirect to url that contain language
  * example:
  * http://localhost/ -> http://localhost/en
  * http://localhost/page -> http://localhost/en/page
  *
  * @author Vee Winch.
  * @license MIT
  * @link http://rundiz.com The author's website.
  * @package Fuel Start
  */
 public function redirectLanguageUri()
 {
     $locales = \Config::get('locales');
     $default_lang = \Config::get('language');
     if (is_array($locales) && !empty($locales)) {
         if (!count($this->segments)) {
             // current uri is in root web. the url is http://domain.tld/fuelphp_root_web/
             $need_redirect = true;
             // redirect to http://domain.tld/fuelphp_root_web/{lang}
             $redirect_url = $default_lang;
         } else {
             // current url is in dir or /lang
             $uri_exp = explode('/', \Input::uri());
             // the \Input::uri will return uri segments with / at the start. when explode it, the first array might be null.
             // check that first array of exploded uri is not null.
             if (isset($uri_exp[0]) && $uri_exp[0] != null) {
                 $first_uri = $uri_exp[0];
             } elseif (isset($uri_exp[1])) {
                 $first_uri = $uri_exp[1];
             } else {
                 // in case that \Input::uri with exploded / is not array or something wrong.
                 $first_uri = $default_lang;
             }
             // if first uri is NOT in locales.
             if (!array_key_exists($first_uri, $locales)) {
                 // first uri segment is not lang. the url is http://domain.tld/fuelphp_root_web/page
                 $need_redirect = true;
                 // redirect to http://domain.tld/fuelphp_root_web/{lang}/page
                 $redirect_url = $default_lang . '/' . implode('/', $this->segments);
             }
         }
         // if need to redirect.
         if (isset($need_redirect) && $need_redirect === true) {
             // set no cache header.
             $response = new Response();
             $response->set_header('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate');
             $response->set_header('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
             $response->set_header('Pragma', 'no-cache');
             $response->send_headers();
             // clean vars.
             unset($default_lang, $first_uri, $locales, $need_redirect);
             // go! redirect. (do not use fuelphp redirect because it generate error 404 in home page)
             $redirect_url = self::createNL($redirect_url);
             // use redirect manually.
             $response->set_status(301);
             $response->set_header('Location', $redirect_url);
             $response->send(true);
             exit;
         }
         // clean vars.
         unset($default_lang, $locales);
     }
     // clean vars.
     unset($default_lang, $locales);
 }
Example #8
0
 private function _readfile_laravel_chunked($path, $name = null, array $headers = array())
 {
     if (is_null($name)) {
         $name = basename($path);
     }
     // Prepare the headers
     $headers = array_merge(array('Content-Description' => 'File Transfer', 'Content-Type' => \File::mime(\File::extension($path)), 'Content-Transfer-Encoding' => 'binary', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'public', 'Content-Length' => \File::size($path)), $headers);
     $response = new \Response('', 200, $headers);
     $response->header('Content-Disposition', $response->disposition($name));
     // If there's a session we should save it now
     if (\Config::get('session.driver') !== '') {
         \Session::save();
     }
     // Send the headers and the file
     ob_end_clean();
     $response->send_headers();
     if ($fp = fread($path, 'rb')) {
         while (!feof($fp) and connection_status() == 0) {
             echo fread($fp, 8192);
             flush();
         }
     }
     // Finish off, like Laravel would
     \Event::fire('laravel.done', array($response));
     $response->foundation->finish();
     exit;
 }
Example #9
0
 /**
  * @runInSeparateProcess
  */
 public function testSend_headers()
 {
     $this->pixie->cookie->set('fairy', 'test', 4, '/', 'phpixie.com', true, true);
     $this->object->send_headers();
     $data = headers_list();
 }
    /**
     * Out put relation json
     *
     * @access  public
     * @return  Response
     */
    public function action_relationjson($introduced_user_id)
    {
        $me = Session::get('user', null);
        $introduced_user = Model_User::find($introduced_user_id);
        $query = \DB::query('SELECT `users`.`id` as `post_user_id`, `users`.`url`, `users`.`name`, `introductions`.*,
			(`introductions`.`distance` + `introductions`.`humanity`+ `introductions`.`ability`) as goodpoint
			FROM `users`
				LEFT JOIN
					`introductions`
					ON
					`users`.`id` = `introductions`.`user_id`
					AND
					`introductions`.`introduced_user_id` = :introduced_user_id
			WHERE `users`.`id` != :introduced_user_id
			ORDER BY goodpoint desc', \DB::SELECT);
        $users = $query->bind('introduced_user_id', $introduced_user_id)->execute();
        unset($query);
        $query = \DB::query("SELECT `introductions`.*\n\t\t\tFROM `users`\n\t\t\t\tLEFT JOIN\n\t\t\t\t\t`introductions`\n\t\t\t\t\tON\n\t\t\t\t\t`users`.`id` = `introductions`.`user_id`\n\t\t\t\t\tAND\n\t\t\t\t\t`introductions`.`user_id` = " . $introduced_user_id . "\n\t\t\t\t\tAND\n\t\t\t\t\t`introductions`.`introduced_user_id` != " . $introduced_user_id . " WHERE `users`.`id` = " . $introduced_user_id, \DB::SELECT);
        $my_relations = $query->execute();
        $bond = array();
        foreach ($my_relations as $key => $intro) {
            $bond[$intro['introduced_user_id']] = (int) $intro['distance'];
        }
        $data = array();
        $data['default']['nodes'] = array();
        $data['default']['links'] = array();
        $data['default']['introductions'] = array();
        $nodes_i = 1;
        $data['default']['nodes'][] = array('name' => $introduced_user['name'], 'size' => 80, 'id' => (int) $introduced_user['id'], 'url' => $introduced_user['url'], 'nodetype' => 'person', 'fixed' => true, 'x' => 600, 'y' => 350);
        $links = array();
        foreach ($users as $key => $user) {
            if (empty($user['id'])) {
                continue;
            }
            $nodes_i++;
            $links[(int) $user['user_id']] = $nodes_i;
            $data['default']['nodes'][] = array('name' => $user['name'], 'size' => 80, 'id' => (int) $user['user_id'], 'url' => $user['url'], 'nodetype' => 'person');
            $bondStrength = !empty($bond[(int) $user['user_id']]) ? $bond[(int) $user['user_id']] : 0;
            $bondStrength = $bondStrength + (int) $user['distance'];
            if ($bondStrength >= 10) {
                $bondType = 3;
            } elseif ($bondStrength >= 7) {
                $bondType = 2;
            } else {
                $bondType = 1;
            }
            $data['default']['links'][] = array('source' => $nodes_i - 1, 'target' => 0, 'bondType' => $bondType, 'text' => $user['feature'], 'id' => 1000 + $user['id']);
        }
        foreach ($users as $key => $user) {
            if (empty($user['id'])) {
                continue;
            }
            $nodes_i++;
            $bondType = !empty($bond[(int) $user['introduced_user_id']]) ? (int) $user['introduced_user_id'] : 0;
            $bondType = $bondType + (int) $user['distance'];
            $data['default']['nodes'][] = array('name' => '紹介', 'size' => 150, 'id' => (int) $user['user_id'] + 1000, 'introduced' => array('feature' => $user['feature'], 'charm' => $user['charm'], 'skilfull' => $user['skillfull']), 'nodetype' => 'introduced');
            $data['default']['introductions'][] = array('id' => (int) $user['user_id'] + 1000, 'div' => $this->intro_dl($user), 'bondType' => $bondType);
            $data['default']['links'][] = array('source' => $nodes_i - 1, 'target' => $links[(int) $user['user_id']] - 1, 'bondType' => 0, 'text' => '', 'id' => 10000 + $user['id']);
        }
        $response = new Response();
        $response->set_header('Content-type', 'application/json');
        $response->send_headers();
        return Response::forge(View::forge('user/relationjson', array('data' => $data)));
    }