/** * * @param string $token format requestId|deviceId|sign=sha1(requestId.deviceId.secretKey) * @param $requestId * @param bool $verifySign * @return UserDevice current device represented by token. * @throws \DbTableException */ public static function validate($token, &$requestId, $verifySign = true) { list($requestId, $deviceId, $sign) = explode('|', $token); if (!($requestId && $deviceId && $sign)) { return null; } $instance = static::instance(); $userDevice = $instance->getEntity($deviceId); if (!$userDevice) { \SystemLogger::warn("Invalid user device ID: [{$deviceId}]"); return null; } if ($verifySign) { if ($sign != self::sign($requestId, $deviceId, $userDevice->secret_key)) { \SystemLogger::warn("Signature not valid: ", $sign); return null; } $tableWhere = (new \DbTableWhere())->where('user_device_id', $userDevice->id)->where('request_id', $requestId)->setLimitAndOffset(1); if (count(UserDeviceReqManager::instance()->getEntitiesWhere($tableWhere))) { \SystemLogger::warn("duplicate request id: ", $requestId); return null; } } return $userDevice; }
public function lookupTimeZoneByGeoCode(GeoLocation $geoLocation) { foreach ($this->providers as $serviceProvier) { $timezone = $serviceProvier->getTimeZone($geoLocation); if ($timezone) { return $timezone; } else { if ($lastError = $serviceProvier->getLastError(true)) { \SystemLogger::warn("Error... {$lastError->getMessage()} TYPE: {$lastError->getType()}"); } } } }
private function extractTheatreMovieShowtimes($pageData, $limit, &$totalPages) { $startTime = microtime(true); \SystemLogger::debug("Begining extraction of data from file, size = ", strlen($pageData)); if ($limit <= 0) { \SystemLogger::warn("Invalid limit was supplied: ", $limit); return array(); } \SystemLogger::debug('Attempting to load into Query Path'); /* @var $moviePage DOMQuery */ $moviePage = \QueryPath::withHTML($pageData, null, array('convert_to_encoding' => "UTF-8", 'convert_from_encoding' => "UTF-8")); \SystemLogger::debug('Loaded into QueryPath'); /* @var $theatersDom DOMQuery */ $theatersDom = $moviePage->find("div.theater"); //get total pages $paginationDom = $moviePage->find("#navbar td"); $totalPages = $paginationDom->length ? $paginationDom->length - 2 : 1; \SystemLogger::debug("Found", $theatersDom->length, "theatres"); $theatreCinemas = array(); $foundTheatres = 0; \SystemLogger::debug('Loading data from Theatres DOM list'); for ($i = 0; $i < $theatersDom->length && $foundTheatres < $limit; $i++) { $theatre = array(); $theatreDom = new DOMQuery($theatersDom->get($i)); $theatre['name'] = trim($theatreDom->find("h2.name")->first()->text()); if (!$theatre['name']) { \SystemLogger::warn("Found no theatre at dom level: ", $i); continue; } \SystemLogger::debug("processing theatre: ", $theatre['name']); $addressText = $theatreDom->find(".info")->first()->text(); //echo $addressText, "<br>"; $tmp = explode(" - ", trim($addressText)); array_pop($tmp); $theatre['address'] = join(' ', $tmp); $theatreCinemas[] = array('theatre' => $theatre, 'movies' => $this->extractMovieShowtimes($theatreDom)); $foundTheatres++; } \SystemLogger::info('Extraction done, completed in ', microtime(true) - $startTime, 'ms'); return $theatreCinemas; }
private function computePhysicalDistance(GeoLocation $source, GeoLocation $destination, $shuffle = true) { if ($shuffle) { shuffle($this->serviceProviderList); } foreach ($this->serviceProviderList as $serviceProvier) { if (is_a($serviceProvier, '\\models\\services\\LocationDistanceCheckI')) { /* @var $serviceProvier LocationDistanceCheckI */ $distance = $serviceProvier->distanceLookup($source, $destination); if ($distance >= 0) { return $distance; } else { if ($lastError = $serviceProvier->getLastError(true)) { \SystemLogger::warn("Error... {$lastError->getMessage()} TYPE: {$lastError->getType()}"); if (!$lastError->isRateLimit()) { break; } } } } } return -1; }
/** * * Generates QRCode for the ticket URL of a particular showtime. * @param $showtimeId * @return null|string the path to the QRCode PNG file on success. * @throws \DbTableException */ public function getPNGQrCode($showtimeId) { $cached = $this->checkCache($showtimeId, true); if ($cached) { return $cached; } $showtime = $this->showtimeManager->getEntity($showtimeId); if ($showtime && $showtime->url) { try { $shorten = $this->getBitly()->shorten($showtime->url, 'j.mp'); } catch (\Exception $e) { \SystemLogger::warn(get_class($e), $e->getTraceAsString()); } $l = $shorten ? $shorten['url'] : \SystemConfig::getInstance()->site['redirect_base'] . $showtimeId; $filename = $this->cacheName($showtimeId, true); QRcode::png($l, $filename, QR_ECLEVEL_L, 4, 1); return $filename; } return null; }
public function logRequest($url, $response, array $headers, &$file = null) { $contentType = 'text/html'; foreach ($headers as $header) { if (preg_match('/^Content-Type/', $header)) { //Content-Type: application/json; charset=utf-8 $tmp1 = preg_split('/\\s*:\\s*/', $header); $contentType = trim(explode(';', $tmp1[1])[0]); break; } } if (preg_match('/html/i', $contentType)) { $ext = 'html'; } elseif (preg_match('/json/i', $contentType)) { $ext = 'json'; } elseif (preg_match('/xml/i', $contentType)) { $ext = 'xml'; } else { $ext = 'txt'; } $uriParts = parse_url($url); $fileDir = REQUESTS_LOG_DIR . $uriParts['host'] . DIRECTORY_SEPARATOR; if (!is_dir($fileDir) && !mkdir($fileDir, 0755, true)) { \SystemLogger::warn('Could not make directory:', $fileDir); return -1; } $file = $fileDir . join('.', [preg_replace('/[^A-Za-z0-9\\._\\-]+/', '', $uriParts['path']), microtime(true), $ext]); return file_put_contents($file, $response); }