/** * Handles autoloading PHP classes. This is the default way for all classes to be * loaded in Caffeine. * * This method is called due to spl_autoload_register() being set to this method. * * Module Format: * MyModule = mymodule/mymodule.php * * Module Sub-Class Format: * MyModule_Foo = mymodule/mymodule_foo.php * MyModule_FooBar = mymodule/mymodule_foo_bar.php * * Controller Format: * MyModule_HelloController = mymodule/controllers/hello.php * MyModule_HelloWorldController = mymodule/controllers/hello_world.php * MyModule_Hello_World_Controller = mymodule/controllers/hello_world.php * * Model Format: * Same as controller format, except replace "Controller" with "Model" in class names. * * @param string $class The class name to find and attempt to load. */ public static function auto($class) { $dir = strtolower($class); $file = $dir; // Class contains underscore, determine if its a sub class, controller or model if (strstr($class, '_')) { $bits = explode('_', $class, 2); // Only explode first underscore, ignore rest $dir = strtolower($bits[0]); // Check for controller if (String::endsWith($bits[1], 'Controller')) { $file = self::_formatController($bits[1]); } elseif (String::endsWith($bits[1], 'Model')) { $file = self::_formatModel($bits[1]); } else { $file = $dir . '_' . self::_formatSubClass($bits[1]); } } foreach (self::$_modulePaths as $path) { $filePath = sprintf('%s%s/%s%s', $path, $dir, $file, EXT); if (file_exists($filePath)) { require_once $filePath; return; } } }
/** * @param string $glob */ public function __construct($glob) { if (String::endsWith('/', $glob)) { $glob .= '**'; } $this->glob = $glob; }
/** * has filename required suffix? * * @param string * @param string * @return bool */ public static function hasSuffix($filename, $suffix) { // if (preg_match("/.*\.$suffix$/", $filename)) { // return TRUE; // } // return FALSE; return String::endsWith($filename, ".{$suffix}"); }
/** * endsWith test. * @return void */ public function testEndswith() { $this->assertTrue(String::endsWith('123', NULL), "String::endsWith('123', NULL)"); $this->assertTrue(String::endsWith('123', ''), "String::endsWith('123', '')"); $this->assertTrue(String::endsWith('123', '3'), "String::endsWith('123', '3')"); $this->assertFalse(String::endsWith('123', '2'), "String::endsWith('123', '2')"); $this->assertTrue(String::endsWith('123', '123'), "String::endsWith('123', '123')"); $this->assertFalse(String::endsWith('123', '1234'), "String::endsWith('123', '1234')"); }
/** * Returns property value. Do not call directly. * support for models [e.g. rolesModel] * @param string property name * @return mixed property value */ public function &__get($name) { $className = ucfirst($name); if (String::endsWith($className, 'Model') && class_exists($className)) { if (!isset(self::$models[$className])) { self::$models[$className] = new $className(); } return self::$models[$className]; } return parent::__get($name); }
public function setPropositionLayer() { $propositionResult = false; if ($this->visualization[REQUEST_PARAMETER_MYMAP]) { $vizJSON = $this->getVisualizationJSON(); $propositionsLayer = array(); if (isset($vizJSON['layers'])) { $layer = end($vizJSON['layers']); if (isset($layer['type']) && $layer['type'] === 'layergroup') { foreach ($layer['options']['layer_definition']['layers'] as $groupLayer) { // substr: remove the date from the end of the layer name (Ymd_His) if (isset($groupLayer['options']['layer_name']) && String::endsWith(substr($groupLayer['options']['layer_name'], 0, -16), '_propose')) { $propositionsLayer = $groupLayer; break; } } } } if (!$propositionsLayer) { $vizResult = Connectivity::runCurl(String::prepare('http://%s.spotzi.me/api/v1/viz/%s?api_key=%s', $this->user['UserName'], $this->visualization[REQUEST_PARAMETER_VIZ_ID], $this->user['ApiKey'])); if ($vizResult) { $visualization = json_decode($vizResult, true); if (isset($visualization['related_tables'])) { $table = reset($visualization['related_tables']); $tableId = $table['id']; $tableResult = Connectivity::runCurl(String::prepare('http://%s.spotzi.me/api/v1/tables/%s?api_key=%s', $this->user['UserName'], $tableId, $this->user['ApiKey'])); if ($tableResult) { $originalTable = json_decode($tableResult, true); // substr: retrieve the base table name and date from the original table name (Ymd_His) $originalName = substr($originalTable['name'], 0, -16); $originalDate = substr($originalTable['name'], -15); // the_geom_type: geometry, multipolygon, point, multilinestring $createTableResult = Connectivity::runCurl(String::prepare('http://%s.spotzi.me/api/v1/tables?api_key=%s', $this->user['UserName'], $this->user['ApiKey']), array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array('name' => substr($originalName, 0, 22) . '_propose_' . $originalDate, 'description' => __('Update propositions for %s', $originalTable['name']), 'tags' => 'update,propose,propositions'))); if ($createTableResult) { $newTable = json_decode($createTableResult, true); $newTableName = $newTable['name']; Connectivity::runCurl(String::prepare('http://%s.spotzi.me/api/v1/tables/%s?api_key=%s', $this->user['UserName'], $newTable['id'], $this->user['ApiKey']), array(CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_HTTPHEADER => array('Content-Type: application/json'), CURLOPT_POSTFIELDS => json_encode(array('privacy' => 'PUBLIC')))); Connectivity::closeCurl(); $columns = array(' ADD COLUMN user_id text NOT NULL', ' ADD COLUMN visualization_id text NOT NULL', ' ADD COLUMN column_data text', ' ADD COLUMN the_geom_old geometry'); $columnQuery = "ALTER TABLE \"{$newTableName}\"" . implode(',', $columns) . ';'; $sqlResult = Connectivity::runCurl(String::prepare('http://%s.spotzi.me/api/v2/sql', $this->user['UserName']), array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array('q' => $columnQuery, 'api_key' => $this->user['ApiKey']))); $layerParams = array('kind' => 'carto', 'order' => 2, 'options' => array('table_name' => $newTableName, 'user_name' => $this->user['UserName'], 'interactivity' => 'cartodb_id', 'visible' => false, 'style_version' => '2.1.1', 'tile_style' => "#{$newTableName} {\n // points\n [mapnik-geometry-type=point] {\n marker-fill: #77BBDD;\n marker-opacity: 0.5;\n marker-width: 12;\n marker-line-color: #222222;\n marker-line-width: 3;\n marker-line-opacity: 1;\n marker-placement: point;\n marker-type: ellipse;\n marker-allow-overlap: true;\n }\n\n //lines\n [mapnik-geometry-type=linestring] {\n line-color: #77BBDD;\n line-width: 2;\n line-opacity: 0.5;\n }\n\n //polygons\n [mapnik-geometry-type=polygon] {\n polygon-fill: #77BBDD;\n polygon-opacity: 0.5;\n line-opacity: 1;\n line-color: #222222;\n }\n}")); $layerCreateResult = Connectivity::runCurl(String::prepare('http://%s.spotzi.me/api/v1/maps/%s/layers?api_key=%s', $this->user['UserName'], $visualization['map_id'], $this->user['ApiKey']), array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array('Content-Type: application/json'), CURLOPT_POSTFIELDS => json_encode($layerParams))); $propositionResult = (bool) $layerCreateResult; } } } } } } return array(REQUEST_RESULT => $propositionResult); }
private function isTestActionFilter($name) { return String::endsWith($name, 'TestAction'); }
/** * @test */ public function endsWith() { $this->assertTrue(String::endsWith('Foo', 'Foo')); $this->assertTrue(String::endsWith('Foo123', '123')); $this->assertFalse(String::endsWith(' Foo123 ', '123')); }
/** * Handle a file uploaded by the client. * * @param string $targetDirectory Target directory * @param string $parameterName Parameter name as used in the form element * @param string $fileName Target file name (optional) * @param array $allowedTypes List containing allowed file types (optional) * @param int $sizeLimit File size limit in bytes (optional) * @return boolean True on success, false otherwise */ public static function handleUpload($targetDirectory, $parameterName, $fileName = null, $allowedTypes = array(), $sizeLimit = 512000) { if (!String::endsWith($targetDirectory, '/')) { $targetDirectory = "{$targetDirectory}/"; } $files = $_FILES; if (empty($files) || !file_exists($targetDirectory) && !mkdir($targetDirectory, 0777, true)) { return false; } foreach ($files as $index => $fileCollection) { if (is_array($files[$index]['name'])) { $files[$index] = Collection::diverse($fileCollection); } } $bracketStartPos = strpos($parameterName, '['); if ($bracketStartPos) { $bracketEndPos = strpos($parameterName, ']'); $parameterCollection = substr($parameterName, 0, $bracketStartPos); $parameterName = substr($parameterName, $bracketStartPos + 1, $bracketEndPos - $bracketStartPos - 1); $file = isset($files[$parameterCollection][$parameterName]) ? $files[$parameterCollection][$parameterName] : false; } else { $file = isset($files[$parameterName]) ? $files[$parameterName] : false; } if (!$file || $file['error'] !== UPLOAD_ERR_OK || !empty($allowedTypes) && !in_array($file['type'], $allowedTypes) || $sizeLimit > 0 && $file['size'] > $sizeLimit) { return false; } if (!$fileName) { $fileName = basename($file['name']); } return move_uploaded_file($file['tmp_name'], $targetDirectory . $fileName) ? $fileName : false; }
if (!doesHaveMembership() && isLoginId(getBlogId(), $_POST['loginid'])) { $showPasswordReset = true; } } else { if (!doesHaveOwnership()) { $message = _text('서비스의 회원이지만 이 블로그의 구성원이 아닙니다. 주소를 확인해 주시기 바랍니다.'); } } } } } $authResult = fireEvent('LOGIN_try_auth', false); if (doesHaveOwnership() || doesHaveMembership()) { if (doesHaveOwnership() && !empty($_POST['requestURI'])) { $url = parse_url($_POST['requestURI']); if ($url && isset($url['host']) && !String::endsWith('.' . $url['host'], '.' . $context->getProperty('service.domain'))) { $redirect = $context->getProperty('uri.blog') . "/login?requestURI=" . rawurlencode($_POST['requestURI']) . '&session=' . rawurlencode(session_id()); } else { $redirect = $_POST['requestURI']; } } else { $redirect = $_POST['refererURI']; } if (empty($_SESSION['lastloginRedirected']) || $_SESSION['lastloginRedirected'] != $redirect) { $_SESSION['lastloginRedirected'] = $redirect; } else { unset($_SESSION['lastloginRedirected']); } header('Location: ' . $redirect); exit; }
/** * Flash handler for images * * @example [* flash.swf 200x150 .(alternative content) *] * * @param TexyHandlerInvocation handler invocation * @param TexyImage * @param TexyLink * @return TexyHtml|string|FALSE */ public function flashHandler($invocation, $image, $link) { if (!String::endsWith($image->URL, ".swf")) { return $invocation->proceed(); } $template = $this->createTemplate()->setFile(APP_DIR . "/templates/inc/@flash.phtml"); $template->url = Texy::prependRoot($image->URL, $this->imageModule->root); $template->width = $image->width; $template->height = $image->height; if ($image->modifier->title) { $template->title = $image->modifier->title; } return $this->protect((string) $template, Texy::CONTENT_BLOCK); }
/** * @covers Panadas\Util\String::endsWith() */ public function testEndsWith() { $this->assertTrue(String::endsWith("bar", "foobar")); $this->assertFalse(String::endsWith("foo", "foobar")); }
public function endsWith() { $str = new String('www.m�ller.com'); $this->assertTrue($str->endsWith('.com')); $this->assertTrue($str->endsWith('�ller.com')); $this->assertFalse($str->endsWith('.co')); $this->assertFalse($str->endsWith('m�ller')); }
/** * Generated from @assert ("", "abcdef") == false. * * @covers String::endsWith */ public function testEndsWith5() { $this->assertFalse(String::endsWith("", "abcdef")); }
public function useFile($file) { $file = CONFIG_PATH . $file; if (file_exists($file)) { // need extra string utilities $fileStr = new String($file); if ($fileStr->endsWith('.ser')) { // serialize $configIn = unserialize(file_get_contents($file)); if ($configIn === false) { return self::$LOAD_ERR; } else { self::$cache[$file] = array_merge(self::$cache[$file], $configIn); return yes; } } else { if ($fileStr->endsWith('.json')) { // json $configIn = json_decode(file_get_contents($file), yes); if ($configIn === null) { return self::$LOAD_ERR; } else { self::$cache[$file] = array_merge(self::$cache[$file], $configIn); return yes; } } else { return self::$NO_METHOD; } } } else { return self::$FILE_DNE; } }
/** * Genera una TestSuite con los TestCase definidos para esta aplicacion. */ public function loadTests() { $dir = dir($this->path . '/tests'); $testCases = array(); // Recorre directorio de la aplicacion while (false !== ($test = $dir->read())) { //echo $test.'<br/>'; // Se queda solo con los nombres de los directorios if (is_file($this->path . '/tests/' . $test) && String::endsWith($test, 'class.php')) { $testCases[] = $test; } } // Crea instancias de las clases testcase $suite = new TestSuite(); foreach ($testCases as $testCaseFile) { $fi = FileNames::getFilenameInfo($testCaseFile); $clazz = $fi['name']; //print_r($fi); YuppLoader::load($fi['package'], $clazz); $suite->addTestCase(new $clazz($suite)); } return $suite; }
/** * Returns the applications host address. * * @return String */ public static function getHostUri() { $sheme = self::getHostParam("HTTPS") == "on" ? "https" : "http"; $serverName = new String(self::getHostParam("HTTP_HOST")); $serverPort = self::getHostParam("SERVER_PORT"); $serverPort = $serverPort != 80 && $serverPort != 443 ? ":" . $serverPort : ""; if ($serverName->endsWith($serverPort)) { $serverName = $serverName->replace($serverPort, ""); } return new String($sheme . "://" . $serverName . $serverPort); }
/** * Convert date to RFC822 * @param string|date $date * @return string */ public static function prepareDate($date) { if ($date instanceof DateTime) { $date = $date->getTimestamp(); } if (is_string($date) && $date === (string) (int) $date) { $date = (int) $date; } if (is_string($date) && !String::endsWith($date, "GMT")) { $date = strtotime($date); } if (is_int($date)) { $date = gmdate('D, d M Y H:i:s', $date) . " GMT"; } return $date; }
private function scanTemporaryUploadPath(Io_Path $path_, $subPath_ = '') { if (false === String::isEmpty($subPath_) && false === String::endsWith($subPath_, '/')) { $subPath_ .= '/'; } foreach ($path_ as $entry) { if ($entry->isDot()) { continue; } if ($entry->isFile()) { $this->stashFile($entry->asFile(), $subPath_); } else { if ($entry->isDirectory()) { $this->scanTemporaryUploadPath($entry, $subPath_ . $entry->getName()); } } } $path_->delete(true); }