function imagecreatetruecolortrans($x, $y) { $i = @imagecreatetruecolor($x, $y) or debugMode(__LINE__, 'Cannot Initialize new GD image stream', '', 0, 'Make sure you have the latest version of GD2 installed'); $b = imagecreatefromstring(base64_decode(blankpng())); imagealphablending($i, false); imagesavealpha($i, true); imagecopyresized($i, $b, 0, 0, 0, 0, $x, $y, imagesx($b), imagesy($b)); imagealphablending($i, true); return $i; }
/** * Send a cURL request. * * @param string $url URL to call * @param array $options cURL options (optional) * @param array $timeout Request timeout in seconds (optional) * @return mixed Result */ public static function runCurl($url, $options = array(), $timeout = 30) { // Prepare the timeout option $options[CURLOPT_TIMEOUT] = intval($timeout); // Initialize the cURL connection self::initCurl($url, $options); // Execute the call $curlResult = curl_exec(self::$curl); // In case of an unsuccessful request, set the result to false if (!in_array(curl_getinfo(self::$curl, CURLINFO_HTTP_CODE), array(200, 204, 301, 302, 304))) { // In case debug mode is enabled, throw an error if (debugMode()) { ErrorHandler::error(500, curl_getinfo(self::$curl, CURLINFO_HTTP_CODE) . ': ' . curl_error(self::$curl)); } $curlResult = false; } // Return the call result return $curlResult; }
public function import() { // Set the script execution settings $importSize = String::formatBytes(VISUALIZATION_IMPORT_SIZE, 'mB'); setExecutionSettings($importSize + 256); $result = false; $error = null; $fileName = File::handleUpload(DIR_TEMP, 'importFile', null, array(), VISUALIZATION_IMPORT_SIZE); if ($fileName) { $fileInfo = pathinfo($fileName); $fileNameNew = str_replace(' ', '_', substr(strtolower($fileInfo['filename']), 0, 22)) . '_' . Date::format('now', 'Ymd_His') . '.' . $fileInfo['extension']; $destinationDir = '\\\\db-images\\data.spotzi.com\\import\\' . $this->user['UserName']; if (!is_dir($destinationDir)) { mkdir($destinationDir); } $destination = $destinationDir . '\\' . $fileNameNew; if (is_dir($destinationDir) && copy(DIR_TEMP . $fileName, $destination)) { $importName = $this->getParam('importName'); if (!$importName) { $importName = ucwords(substr(str_replace('_', ' ', $fileName), 0, strrpos($fileName, '.'))); } $dataUrl = 'http://data.spotzi.com/import/' . $this->user['UserName'] . '/' . $fileNameNew; $this->vizDb->insert(self::DB_CONNECTION_VIZ_WRITE, 'VisualizationImport', array('Service' => 'geonovum', 'UserName' => $this->user['UserName'], 'Email' => $this->user['Email'], 'Name' => $importName, 'DataUrl' => $dataUrl, 'DebugImport' => debugMode())); $webserviceUrl = String::prepare('%svisualization/wo/import?user=%s&password=%s&userName=%s&userKey=%s&callback=%s&format=application/json', WEBSERVICE_URL, WEBSERVICE_USER, WEBSERVICE_PASSWORD, $this->user['UserName'], $this->user['ApiKey'], Url::buildPlatformURL(false, 'import', 'import', 'finish')); Connectivity::runCurlAsync($webserviceUrl); $result = true; } else { $error = __('An error occured while preparing the file'); } File::delete(DIR_TEMP . $fileName); } else { $error = __('An error occured while uploading the file'); } if ($result === false) { ErrorHandler::error(E_NOTICE, "The import failed, file name: %s\nerror: %s", $fileName, $error); } return array(REQUEST_RESULT => $result, REQUEST_ERROR => $error); }
/** * Activate our custom error handler. */ public static function setCustomErrorHandling() { // Activate our custom error handler set_error_handler(array(get_class(), 'handle')); // Set the error handling level depending on debug/production mode error_reporting(debugMode() ? E_ALL | E_STRICT : E_ALL); }
/** * Handle a database error. * * @param string $message Error Message */ public function error($message) { $message = '<pre>' . print_r($message, true) . '</pre>'; ErrorHandler::error(E_ERROR, 3, debugMode() ? $message : 'Invalid data source response'); }
<?php /** * 入口 * * @author * @copyright */ use Demo\Bootstrap; use Phalcon\Http\Response; use Phalcon\DI\FactoryDefault; try { include __DIR__ . '/../Config/Define.php'; include SDK_DIR . '/SDK.php'; include APP_DIR . '/Bootstrap.php'; $application = new Bootstrap(); $application->run(); } catch (\Phalcon\Mvc\Dispatcher\Exception $e) { $logger = Phalcon\DI\FactoryDefault::getDefault()->get('logger'); $logger->notice($e->getMessage()); $response = new Response(); $response->setStatusCode(404, 'Not Found')->send(); } catch (\Exception $e) { $logger = Phalcon\DI\FactoryDefault::getDefault()->get('logger'); $message = 'Exception: ' . $e->getMessage(); $logger->error($message); $response = new Response(); $response->setStatusCode(503, debugMode() ? $message : null)->send(); }
/** * 默认服务依赖注入 * */ protected function commonServices() { $mode = $this->mode; $di = $this->mode === 'CLI' ? new Cli() : new FactoryDefault(); // 日志 $di->set('logger', function () { $config = load('logger'); $adapter = $config['adapter']; $filename = $config[$adapter]['filename']; $filedir = dirname($filename); if (empty($config)) { throw new \Exception('logger config Require failed'); } if (!is_dir($filedir)) { mkdir($filedir, 0755, true); } $logger = new File($filename); $formatter = new Line(null, 'Y-m-d H:i:s'); $loglevel = config('app.loglevel'); $logger->setFormatter($formatter); $logger->setLogLevel($loglevel ? $loglevel : \Phalcon\Logger::ERROR); return $logger; }, true); $this->application->setDI($di); // 命名空间 $di->set('dispatcher', function () use($mode) { $dispatcher = new Dispatcher(); $dispatcher = $mode === 'CLI' ? new \Phalcon\CLI\Dispatcher() : new Dispatcher(); $bootstrap = load('bootstrap'); $default = $bootstrap['dispatcher']; $dispatcher->setDefaultNamespace($mode === 'CLI' ? $default['cli'] : $default['default']); return $dispatcher; }, true); // 路由 if ($load = load('router', null, true)) { if ($load instanceof Router) { $di->set('router', $load); } } // 视图 $di->set('view', function () { $view = new View(); $view->setViewsDir(APP_VIEW); return $view; }, true); // 加解密 if ($config = config('crypt')) { $di->set('crypt', function () use($config) { $crypt = new Crypt(); $crypt->setKey($config['authkey']); return $crypt; }, true); } // 默认缓存 if ($config = config('cache')) { $di->set('cache', function () use($config) { $cache = null; $adapter = strtolower($config['adapter']); $options = $config[$adapter]; $frontend = new Data(array('lifetime' => $config['lifetime'])); switch ($adapter) { case 'memcache': $cache = new Memcache($frontend, $options); break; case 'redis': if (empty($options['auth'])) { unset($options['auth']); } $cache = new \Phalcon\Extend\Cache\Backend\Redis($frontend, $options); break; } return $cache; }, true); } // Cookies if ($config = config('cookies')) { $di->set('cookies', function () use($config) { $cookies = new \Phalcon\Extend\Http\Response\Cookies($config); if (!config('crypt.authkey')) { $cookies->useEncryption(false); } return $cookies; }, true); } // Session if ($config = config('session')) { $di->set('session', function () use($config) { if (!empty($config['options'])) { foreach ($config['options'] as $name => $value) { ini_set("session.{$name}", $value); } } $adapter = strtolower($config['adapter']); $options = $config[$adapter]; switch ($adapter) { case 'memcache': $session = new SessionMemcache($options); break; case 'redis': $session = new \Phalcon\Extend\Session\Adapter\Redis($options); break; default: $session = new SessionFiles(); break; } $session->start(); return $session; }, true); } // Db if ($config = config('db')) { $di->set('db', function () use($config) { $mysql = new Mysql($config); if (debugMode()) { $eventsManager = new Manager(); $logger = new File(APP_LOG . DS . 'Mysql' . LOGEXT); $formatter = new Line(null, 'Y-m-d H:i:s'); $logger->setFormatter($formatter); $eventsManager->attach('db', function ($event, $mysql) use($logger) { if ($event->getType() == 'beforeQuery') { $logger->log($mysql->getSQLStatement(), Logger::INFO); } if ($event->getType() == 'afterQuery') { } }); $mysql->setEventsManager($eventsManager); } return $mysql; }, true); } // DB 元信息 if ($config = config('metadata')) { $di->set('modelsMetadata', function () use($config) { $modelsMetadata = null; $adapter = strtolower($config['adapter']); $options = $config[$adapter]; switch ($adapter) { case 'memcache': $modelsMetadata = new MetaDataMemcache($options); break; case 'redis': if (empty($options['auth'])) { unset($options['auth']); } $modelsMetadata = new MetaDataRedis($options); break; } return $modelsMetadata; }, true); } $this->application->setDI($di); }
function setColor($image, $color, $trans = 0) { $red = 100; $green = 100; $blue = 100; $ret = array(); if (preg_match("/[#]?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i", $color, $ret)) { $red = hexdec($ret[1]); $green = hexdec($ret[2]); $blue = hexdec($ret[3]); } // Get a transparent color if trans > 0 if ($trans > 0) { $color_index = @imageColorAllocateAlpha($image, $red, $green, $blue, $trans) or debugMode(__LINE__, $php_errormsg); } else { // Damn, we cannot supress this function... $color_index = imageColorAllocate($image, $red, $green, $blue); } return $color_index; }
if (typeof bounds !== 'object') { bounds = bounds.split(','); bounds = L.latLngBounds([[bounds[1], bounds[0]], [bounds[3], bounds[2]]]); } map.fitBounds(bounds, { maxZoom: <?php echo VISUALIZATION_ZOOM_MAX; ?> }); } // General function logError(err) { <?php if (debugMode()) { ?> console.log(err || '<?php _e('An unexpected error has occured.<br>If this error keeps occuring, please contact our webmaster at info@spotzi.com for assistance.'); ?> '); <?php } ?> } function setTopLocation(url, home, modal) { if (home === true) $.localStorage.setItem('home', true); if (modal) $.localStorage.setItem('modal', modal); setLocation(url, true);