Exemple #1
0
 /**
  *
  * 执行登录检查,如果错误,将返回状态代码403
  *
  * @access public
  * @param 无
  * @return void
  */
 public function execute($request)
 {
     Logger::debug('----- ' . __CLASS__ . ' is started -----');
     // 验证 SessionKey
     $user_id = $request->getRequestParameter(Constants::PARAM_SESSION_KEY);
     $clientSendKey = $request->getRequestParameter(Constants::PARAM_USER_ID);
     $userCache = UserCache::getCacheInstance();
     $serverSaveKey = $userCache->getByKey($user_id, Constants::CURRENT_SESSION_KEY);
     if ($serverSaveKey !== $clientSendKey) {
         Logger::debug('Stopping ' . __CLASS__ . '. caused by: Invalid session key.');
         Logger::debug('server save session key: ', $serverSaveKey);
         Logger::debug('client send session key: ', $clientSendKey);
         $view = new JsonView();
         $view->setValue('result', Constants::RESP_RESULT_ERROR);
         $view->setValue('message', "session key not match");
         $view->display();
         throw new ForbiddenException("Session Key not match.");
     }
     // 登录检查
     /*if( !$authorizer->loginCheck($auth_param) )
       {
           Logger::debug( 'Stopping ' . __CLASS__ . '. caused by: The request not authenticated.' );
           throw new ForbiddenException();
       }*/
     Logger::debug(__CLASS__ . ' is success.');
     Logger::debug('----- ' . __CLASS__ . ' is finished -----');
 }
 public function testCanIterateOverEachTranslationKeys()
 {
     $translations = array();
     $iterator = new JsonView();
     foreach ($iterator->select(__DIR__ . '/data/json-view.json') as $key => $paramNames) {
         $translations[$key] = $paramNames;
     }
     $this->assertEquals(array('catalog:typicallySwissHotels' => null, 'catalog:wellnessAndSpaHotels' => null, 'catalog:kidsHotels' => null, 'catalog:swissDeluxeHotels' => null, 'catalog:affordableHotels' => null, 'catalog:swissHistoricHotels' => null, 'catalog:designAndLifestyleHotels' => null, 'catalog/url:typicallySwissHotels' => null, 'catalog/url:wellnessAndSpaHotels' => null, 'catalog/url:kidsHotels' => null, 'catalog/url:swissDeluxeHotels' => null, 'catalog/url:affordableHotels' => null, 'catalog/url:swissHistoricHotels' => null, 'catalog/url:designAndLifestyleHotels' => null), $translations);
 }
Exemple #3
0
 /**
  * testRenderWithView method
  *
  * @return void
  */
 public function testRenderWithView()
 {
     App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)));
     $Request = new CakeRequest();
     $Response = new CakeResponse();
     $Controller = new Controller($Request, $Response);
     $Controller->name = $Controller->viewPath = 'Posts';
     $data = array('User' => array('username' => 'fake'), 'Item' => array(array('name' => 'item1'), array('name' => 'item2')));
     $Controller->set('user', $data);
     $View = new JsonView($Controller);
     $output = $View->render('index');
     $expected = json_encode(array('user' => 'fake', 'list' => array('item1', 'item2')));
     $this->assertIdentical($expected, $output);
     $this->assertIdentical('application/json', $Response->type());
 }
 public function selectPaymentOptionsAction()
 {
     $packages = $this->package->findAll();
     $payPal = $this->paymentProcessor->findByPk("PayPal");
     $allopass = $this->paymentProcessor->findByPk("Allopass");
     $allopassNumbers = array();
     foreach ($packages as &$package) {
         $details = "";
         if ($payPal->active) {
             $details .= " " . $package['amount'] . " " . $payPal->currency;
         }
         if ($payPal->active && $allopass->active && $package['allopassNumber']) {
             $details .= " or ";
         }
         if ($allopass->active && $package['allopassNumber']) {
             $details .= $package['allopassNumber'] . " Allopass";
         }
         $package['details'] = $details;
         $allopassNumbers[$package['packageId']] = $package['allopassNumber'];
     }
     $this->set("packages", $packages);
     $this->set("allopassNumbersJSON", JsonView::php2js($allopassNumbers));
     $c = new Criteria();
     $c->add("active", 1);
     $this->set("paymentProcessors", $this->paymentProcessor->getArray($c, "displayName"));
 }
 public function testNoModel()
 {
     //setup
     $view = JsonView::create()->setHexQuot(true)->setHexApos(true);
     //execution and check
     $this->assertEquals(json_encode(array(), JSON_HEX_QUOT | JSON_HEX_APOS), $view->toString());
 }
 /**
  * Renders file and returns json-encoded response
  *
  * @param null $view
  * @param null $layout
  * @return string
  */
 public function render($view = null, $layout = null)
 {
     parent::render($view, $layout);
     $options = 0;
     if (version_compare(PHP_VERSION, '5.4.0', '>=') && Configure::read('debug')) {
         $options = JSON_PRETTY_PRINT;
     }
     return json_encode($this->dtResponse, $options);
 }
 /**
  * @param Model $model
  * @return string
  */
 public function toString($model = null)
 {
     /*
      * Escaping warning datas
      */
     $this->setHexAmp(true);
     $this->setHexApos(true);
     $this->setHexQuot(true);
     $this->setHexTag(true);
     $json = JsonView::toString($model);
     $json = str_ireplace(array('u0022', 'u0027'), array('\\u0022', '\\u0027'), $json);
     $result = '<script type="text/javascript">' . "\n";
     $result .= "\t" . $this->prefix . $this->callback . '=\'' . $json . '\';' . "\n";
     $result .= '</script>' . "\n";
     return $result;
 }
 public function __construct(\Request $request, \Http\ErrorResponse $response)
 {
     $json = array();
     $json['url'] = $request->getUrl();
     $json['method'] = $request->getMethod();
     $json['module'] = $request->getModule();
     $json['code'] = $response->getCode();
     $json['phrase'] = $response->getPhrase();
     $json['backtrace'] = $response->getBacktrace();
     $json['exception'] = $response->getException();
     if (is_a($json['exception'], '\\Exception')) {
         $json['exception_code'] = $response->getException()->getCode();
         $json['exception_file'] = $response->getException()->getFile();
         $json['exception_line'] = $response->getException()->getLine();
         $json['exception_message'] = $response->getException()->getMessage();
     }
     parent::__construct(array('error' => $json));
 }
Exemple #9
0
 /**
  * @dataProvider buildOutputProvider
  *
  * @covers JsonView::buildOutput
  *
  * @param mixed $input
  * @param string $expected
  */
 public function testBuildOutput($input, $expected)
 {
     $view = new JsonView();
     $this->assertEquals($expected, $view->buildOutput($input));
 }
 /**
  * testRenderWithView method
  *
  * @return void
  */
 public function testRenderWithView()
 {
     App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)));
     $Request = new CakeRequest(null, false);
     $Request->params['named'] = array('page' => 2);
     $Response = new CakeResponse();
     $Controller = new Controller($Request, $Response);
     $Controller->name = $Controller->viewPath = 'Posts';
     $data = array('User' => array('username' => 'fake'), 'Item' => array(array('name' => 'item1'), array('name' => 'item2')));
     $Controller->set('user', $data);
     $View = new JsonView($Controller);
     $View->helpers = array('Paginator');
     $output = $View->render('index');
     $expected = array('user' => 'fake', 'list' => array('item1', 'item2'), 'paging' => array('page' => 2));
     $this->assertSame(json_encode($expected), $output);
     $this->assertSame('application/json', $Response->type());
     $View->request->query = array('jsonCallback' => 'jfunc');
     $Controller->set('_jsonp', 'jsonCallback');
     $View = new JsonView($Controller);
     $View->helpers = array('Paginator');
     $output = $View->render('index');
     $expected['paging']['?']['jsonCallback'] = 'jfunc';
     $expected = 'jfunc(' . json_encode($expected) . ')';
     $this->assertSame($expected, $output);
     $this->assertSame('application/javascript', $Response->type());
 }
Exemple #11
0
 /**
  * JsonViewTest::testRenderJSONBoolFalse()
  *
  * @return void
  */
 public function testRenderJSONBoolFalse()
 {
     $Request = new CakeRequest();
     $Response = new CakeResponse();
     $Controller = new Controller($Request, $Response);
     // encoding a false, ensure this doesn't trigger exception
     $data = false;
     $Controller->set($data);
     $Controller->set('_serialize', 'data');
     $View = new JsonView($Controller);
     $output = $View->render();
     $this->assertSame('null', $output);
 }
Exemple #12
0
 /**
  * Display site edit form
  */
 function editAction($siteId)
 {
     $this->set("siteId", $siteId);
     $c = new Criteria();
     $c->add("siteId", $siteId);
     $site = $this->site->find($c);
     if (empty($site)) {
         return $this->return404();
     }
     $package = $site->packageId ? $this->package->findByPk($site->packageId) : null;
     $this->set("package", $package);
     // Decide to display link to remove image or not
     $this->set("displayRemoveImage", $site->imageSrc && !$site->ascreen ? true : false);
     $site->updateImageSrc(false);
     $site->categoryParentsData = $this->category->getParents($site->categoryId);
     $this->site->attachPhotos($site);
     $this->site->fillExtraFields($site);
     $this->site->attachKeywordIds($site);
     $site['additionalCategoryIds[]'] = $this->siteAdditionalCategory->getCategoryIdsBySiteId($site->siteId);
     $this->set("site", $site);
     $this->set("siteJson", JsonView::php2js($site));
     $c = new Criteria();
     $c->add("siteId", $siteId);
     $this->set("comments", $this->comment->findAll($c));
     $this->set("selectCategories", $this->category->createOptionsList());
     $c = new Criteria();
     $c->add("role", "webmaster");
     $this->set("webmasters", $this->user->getArray($c, "email"));
     $this->set("allKeywordsList", $this->keyword->generateSortedList());
     $this->set("yesNoOptions", array("0" => _t("No"), "1" => _t("Yes")));
     $this->set("priorites", range(0, 10));
     $this->set("adCriterias", $this->adCriteria->getSelectList());
     require CODE_ROOT_DIR . "config/flags.php";
     $this->set("countryFlags", $countryFlags);
 }
 function editAction($fieldId)
 {
     $extraField = $this->extraField->findByPk($fieldId);
     if (empty($extraField)) {
         $this->return404();
     }
     $extraField->options = $this->extraField->getOptions($fieldId);
     $config = unserialize($extraField->config);
     if (is_array($config)) {
         foreach ($config as $key => $value) {
             $extraField['config[' . $key . ']'] = $value;
         }
     }
     $this->set("extraField", $extraField);
     $this->set("extraFieldJson", JsonView::php2js($extraField));
     $this->set('returnUrl', $this->request->getRefererUrl());
 }
 /**
  * Renders file and returns json-encoded response
  *
  * @param null $view
  * @param null $layout
  * @return string
  */
 public function render($view = null, $layout = null)
 {
     parent::render($view, $layout);
     return json_encode($this->dtResponse);
 }
 function action_page()
 {
     require_once 'exts/simple_html_dom.php';
     $error = 0;
     $finds = null;
     $errormsg = '';
     $postUrl = $_POST['url'];
     $postSelector = $_POST['selector'];
     $html = null;
     try {
         $html = file_get_html($postUrl);
     } catch (Exception $e) {
         $error = -400;
     }
     if ($html === null) {
         $errormsg = "Can't load url";
     } else {
         $finds = $html->find($postSelector);
         if (count($finds) == 0) {
             $selparts = explode(' ', $postSelector);
             $finds = array($html);
             foreach ($selparts as $part) {
                 if (strcasecmp($part, ' ') == 0) {
                     continue;
                 }
                 $dotscount = substr_count($part, '.');
                 if ($dotscount > 1) {
                     $classes = array_filter(explode('.', $part));
                     $newfinds = array();
                     foreach ($finds as $el) {
                         $fndEls = $el->find('.' . reset($classes));
                         foreach ($fndEls as $fndEl) {
                             $elClasses = array_filter(explode(' ', $fndEl->class));
                             $num = 0;
                             foreach ($classes as $class) {
                                 if (in_array($class, $elClasses)) {
                                     $num = $num + 1;
                                 }
                             }
                             if ($num == count($classes)) {
                                 array_push($newfinds, $fndEl);
                             }
                         }
                     }
                     $finds = $newfinds;
                 } else {
                     $newfinds = array();
                     foreach ($finds as $el) {
                         $fndEls = $el->find($part);
                         foreach ($fndEls as $fndEl) {
                             array_push($newfinds, $fndEl);
                         }
                     }
                     $finds = $newfinds;
                 }
                 if (count($finds) == 0) {
                     break;
                 }
             }
         }
     }
     $data = array('error' => $error);
     if ($finds !== null && count($finds) != 0) {
         $arrEls = array();
         foreach ($finds as $el) {
             array_push($arrEls, $el->outertext);
         }
         $data['result'] = $arrEls;
     }
     if ($errormsg !== null) {
         $data['errormsg'] = $errormsg;
     }
     $view = new JsonView();
     $view->generate($data);
     if ($html != null) {
         $html->clear();
         unset($html);
     }
 }
Exemple #16
0
 /**
  * Destructor.
  */
 public function __destruct()
 {
     parent::__destruct();
 }
Exemple #17
0
<?php

define('APP_FOLDER_PATH', dirname(__FILE__) . '/../..');
include APP_FOLDER_PATH . '/inc/init.php';
$trip_rows = GTFS::getTripsByMinute($_GET['hhmm']);
JsonView::dump($trip_rows);
Exemple #18
0
 function __construct()
 {
     $this->mode = 'json';
     self::$ob_level = ob_get_level();
     ob_start();
 }
 /**
  * Display category edit form
  */
 function editAction($categoryId)
 {
     $category = $this->category->findByPk($categoryId);
     $this->set("category", $category);
     $this->set("categoryJson", JsonView::php2js($category));
     $this->set("categoryExtraFields", $this->extraField->getCategoryFields($categoryId));
     $this->set("categoriesSelect", $this->category->createOptionsList());
 }
Exemple #20
0
 /**
  * Display sites which containt searched phrase
  */
 function searchAction($searchQuery = "")
 {
     //set adPage for ads
     Display::set("adPage", "search");
     Display::set("searchPanel", true);
     $searchedItems = array();
     $this->request->fromArray($_GET);
     $searchValues = $this->request->toArray();
     $this->set("searchValuesJson", JsonView::php2js($searchValues));
     $page = !empty($this->request->page) ? $this->request->page : 1;
     $resultsCount = 0;
     //if something was searched
     if (!empty($searchValues)) {
         //get sites which containt searched phrase
         $searchedItems = $this->siteSearcher->searchValidated($searchValues, $page);
         $resultsCount = $this->siteSearcher->getFoundRowsCount();
         //if this phrase have matched sites save tag
         if (!empty($searchedItems) && !empty($this->request->phrase)) {
             $this->searchTag->addSearchTag($this->request->phrase, $searchedItems[0]);
         }
         $this->set('searchValues', $searchValues);
         //prepare data for pagination
         $totalPages = empty($searchedItems) ? 0 : ceil($resultsCount / Config::get("sitesPerPageInSearch"));
     } else {
         //nothing was searched
         $searchedItems = array();
         $totalPages = 0;
         $page = 1;
     }
     $this->set("resultsCount", $resultsCount);
     $this->set("searchedSites", $searchedItems);
     $searchArray = array();
     foreach (explode("&", ltrim($searchQuery, "?")) as $searchPair) {
         if (strpos($searchPair, "=") === false) {
             continue;
         }
         list($key, $value) = explode("=", $searchPair);
         if (!$value || in_array($key, array("page", "search"))) {
             continue;
         }
         $searchArray[urldecode($key)] = urldecode($value);
     }
     $paginationBaseLink = "/site/search/?" . str_replace("%", "%%", http_build_query($searchArray)) . "&page=";
     $this->set("pageNavigation", array("baseLink" => $paginationBaseLink, "totalPages" => $totalPages, "currentPage" => $page));
 }
 /**
  * @param Model $model
  * @return string
  */
 public function toString($model = null)
 {
     Assert::isNotEmpty($this->callback, 'callback can not be empty!');
     $json = parent::toString($model);
     return $this->callback . '(' . $json . ');';
 }
Exemple #22
0
<?php

require_once './ViewEngine.php';
require_once './JsonView.php';
require_once './HtmlView.php';
$json_view = new JsonView();
$json_view->render();
$html_view = new HtmlView();
$html_view->render();
Exemple #23
0
 /**
  * 基于API,返回规范的JSON响应信息,包含错误类型
  *
  * @access protected
  * @param JsonView $view
  * @param string $msg 信息
  * @return string JSON
  */
 protected function getViewByJson($view, $msg = '', $result_type, $api_type)
 {
     if (!$view instanceof JsonView) {
         throw new Exception("Parameter must be instance of JsonView.");
     }
     $view->setValue('result', $result_type);
     $view->setValue('tenone_api_type', $api_type);
     $view->setValue('message', $msg);
     return $view;
 }
Exemple #24
0
<?php

// inclue the various view classes
include 'views.php';
include 'actions.php';
// work out what format they want
$accept = explode(',', $_SERVER['HTTP_ACCEPT']);
if ($accept[0] == 'text/html') {
    $view = new HtmlView();
} elseif ($accept[0] == 'text/xml') {
    $view = new XmlView();
} else {
    $view = new JsonView();
}
// route the request (filter input!)
$action = $_GET['action'];
$library = new Actions();
// OBVIOUSLY you would filter input at this point
$data = $library->{$action}($_GET);
// output appropriately
$view->render($data);
 /**
  * Display edit form
  */
 function editSiteAction($siteId)
 {
     $site = $this->site->findByPk($siteId);
     if (empty($site) || $site->webmasterId != $this->userId) {
         $this->return404();
     }
     $this->site->attachPhotos($site);
     $this->site->fillExtraFields($site);
     $this->site->attachKeywordIds($site);
     $this->set("edit", true);
     $this->set("item", $site);
     $this->set("itemJson", JsonView::php2js($site));
     $this->set("siteType", $site->siteType);
     $package = $site->packageId ? $this->package->findByPk($site->packageId) : null;
     $this->set("package", $package);
     require CODE_ROOT_DIR . "config/flags.php";
     $this->set("countryFlags", $countryFlags);
     $this->set("allKeywordsList", $this->keyword->generateSortedList());
     $this->viewFile = "submitWebsite";
 }
Exemple #26
0
<?php

define('APP_FOLDER_PATH', dirname(__FILE__) . '/../..');
include APP_FOLDER_PATH . '/inc/init.php';
if (isset($_GET['file'])) {
    $file = APP_FOLDER_PATH . '/geojson/' . $_GET['file'];
    if (file_exists($file)) {
        $json = file_get_contents($file);
    } else {
        error_log('GeoJSON error: ' . $file . ' not found !');
        $json = array('error' => 'Cannot load ' . $_GET['file'] . ' !');
    }
} else {
    $json = array('error' => 'Missing file parameter, i.e. file=stations.geojson');
}
JsonView::dump($json);
Exemple #27
0
 function editPackageAction($packageId)
 {
     $package = $this->package->findByPk($packageId);
     $this->set('displayRemoveImage', $package->imageSrc ? true : false);
     $package->updateImageSrc();
     $this->set("package", $package);
     $this->set("packageJSON", JsonView::php2js($package));
     $this->set("priorities", range(0, 10));
 }