public function constructUrl(Request $appRequest, Url $refUrl) { // Module prefix not match. if ($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) { return null; } $params = $appRequest->getParameters(); $urlStack = []; // Module prefix $moduleFrags = explode(":", Strings::lower($appRequest->getPresenterName())); $resourceName = array_pop($moduleFrags); $urlStack += $moduleFrags; // Resource $urlStack[] = Strings::lower($resourceName); // Id if (isset($params['id']) && is_scalar($params['id'])) { $urlStack[] = $params['id']; unset($params['id']); } // Set custom action if (isset($params['action']) && $this->_isApiAction($params['action'])) { unset($params['action']); } $url = $refUrl->getBaseUrl() . implode('/', $urlStack); // Add query parameters if (!empty($params)) { $url .= "?" . http_build_query($params); } return $url; }
private function copy($dir, $targetDir) { $files = []; /** @var $file \SplFileInfo */ foreach (Finder::find('*')->from($dir) as $file) { if ($file->isFile()) { $filename = $this->getRelativePath($file->getPathname(), $dir); $files[$filename] = $file; } } foreach ($files as $filename => $file) { $target = $targetDir . '/' . $filename; $dir = (new \SplFileInfo($target))->getPath(); if (!file_exists($dir)) { umask(00); mkdir($dir, 0777, true); } if (Strings::lower($file->getExtension()) == 'zip' && extension_loaded('zlib')) { $archive = new \ZipArchive(); $res = $archive->open($file->getRealPath()); if ($res === true) { $archive->extractTo($targetDir); $archive->close(); } continue; } @copy($file->getPathname(), $target); } }
/** * Method run before install * * @throws \Canterville\NonExistsException * @throws \Canterville\Exception\NotSetException */ protected function init() { $this->url = $this->getUrl($this->version); $this->distType = $this->getDistType($this->url); $this->targetDir = $this->getVendorDir() . self::AUTHOR_DIR . Strings::lower($this->name) . '/'; $calledClass = get_called_class(); if (!method_exists($calledClass, 'copyToBinFolder')) { throw new NotExistsException(sprintf('Method "' . $calledClass . '::%s" non exists.', 'copyToBinFolder')); } $errorMsg = 'Property "' . $calledClass . '::$%s" not set.'; if (!isset($this->name)) { throw new NotSetException($errorMsg, 'name'); } if (!isset($this->version)) { throw new NotSetException($errorMsg, 'version'); } if (!isset($this->url)) { throw new NotSetException($errorMsg, 'url'); } if (!isset($this->distType)) { throw new NotSetException($errorMsg, 'distType'); } if (!isset($this->targetDir)) { throw new NotSetException($errorMsg, 'targetDir'); } }
/** * Generuje hash hesla i se solicim retezcem * @return string */ public function generateHash($heslo, $salt = NULL) { if ($heslo === Strings::upper($heslo)) { // v pripade zapleho capslocku $heslo = Strings::lower($heslo); } return crypt($heslo, $salt ?: '$2a$07$' . Strings::random(23)); }
/** * Adds dynamic action * @param string $title * @param bool $ajax * @return DynamicAction */ public function addDynamicAction($title, $ajax = false) { $title = Strings::lower($title); $action = new \Gridder\Actions\DynamicAction($this, $title); $action->setTitle($title); $action->setAjax($ajax); return $action; }
public function isComposerVendorNameProtectionFree($composerFullName) { $composerVendor = NULL; if (($data = Strings::match($composerFullName, Addon::COMPOSER_NAME_RE)) !== NULL) { $composerVendor = Strings::lower($data['vendor']); } return !in_array($composerVendor, $this->protectedVendors); }
/** * @param string * @param string|NULL * @return string */ private function calculateAddonsPortalPasswordHash($password, $salt = NULL) { if ($password === Strings::upper($password)) { // perhaps caps lock is on $password = Strings::lower($password); } return crypt($password, $salt ?: '$2a$07$' . Strings::random(22)); }
/** * Computes password hash. * * @param string * @param string|NULL * @return string */ public static function calculateHash($password, $salt = NULL) { if ($password === Strings::upper($password)) { // perhaps caps lock is on $password = Strings::lower($password); } return crypt($password, $salt ?: '$2a$07$' . Strings::random(22)); }
public function setEmail($email) { /** * Not according to RFC 5321, but as per SO this is ok * @see http://stackoverflow.com/a/9808332/326257 */ $this->setValue('email', $email ? Strings::lower($email) : NULL); }
/** * Generuje hash hesla i se solicim retezcem * @return string */ public function generateHash($password, $salt = NULL) { if ($password === Strings::upper($password)) { // v pripade zapleho capslocku $password = Strings::lower($password); } return crypt($password, $salt ?: $this->user_salt . Strings::random(23)); }
/** * @param MacroNode $node * @param PhpWriter $writer * * @return string * * @throws CompileException */ public static function macroIfAllowedLink(MacroNode $node, PhpWriter $writer) { // This macro is allowed only as n:macro in <a ></a> element if (Utils\Strings::lower($node->htmlNode->name) != 'a') { throw new CompileException("Macro n:allowedHref is allowed only in link element, you used it in {$node->htmlNode->name}."); } return $writer->write('if($presenter->context->getByType("IPub\\Permissions\\Access\\LinkChecker")->isAllowed(%node.word)){'); }
/** * Computes salted password hash. * @param string * @return string */ public static function calculateHash($password, $salt = NULL) { if ($password === Strings::upper($password)) { // perhaps caps lock is on $password = Strings::lower($password); } $password = substr($password, 0, self::PASSWORD_MAX_LENGTH); return crypt($password, $salt ?: '$2a$07$' . Strings::random(22)); }
/** * Computes salted password hash. * * @param $password * @param null $options * @return string */ public static function hashPassword($password, $options = NULL) { if ($password === Nette\Utils\Strings::upper($password)) { // perhaps caps lock is on $password = Nette\Utils\Strings::lower($password); } $password = substr($password, 0, 4096); $options = $options ?: implode('$', ['algo' => PHP_VERSION_ID < 50307 ? '$2a' : '$2y', 'cost' => '07', 'salt' => Nette\Utils\Strings::random(22)]); return crypt($password, $options); }
/** * Converts the given string to `spinal-case` * @param string $string * @return string */ public static function spinalCase($string) { /** RegExp source http://stackoverflow.com/a/1993772 */ preg_match_all('/([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)/', $string, $matches); $matches = $matches[0]; foreach ($matches as &$match) { $match = $match == Strings::upper($match) ? Strings::lower($match) : Strings::firstLower($match); } return implode('-', $matches); }
/** * @param string $ext * @return string */ public static final function getIcon($ext) { $ext = \Nette\Utils\Strings::lower($ext); foreach (self::$ICONS as $icon => $extensions) { if (in_array($ext, $extensions)) { return $icon; } } return self::$DEFAULT_ICON; }
/** * Converts the given string to "camelCase". * @param string $string * @return string */ public static function toCamelCase($string) { static $canUse = null; if (is_null($canUse)) { $canUse = method_exists(Strings::class, 'firstLower'); // Nette/Utils >= 2.3 only } $pascal = self::toPascalCase($string); return $canUse ? Strings::firstLower($pascal) : Strings::lower(Strings::substring($pascal, 0, 1)) . Strings::substring($pascal, 1); }
/** * @param string * @return string */ public static function normalizeGithubRepositoryUrl($url) { self::assertGithubRepositoryUrl($url); $url = str_replace('github.com:', 'github.com/', $url); if (Strings::endsWith($url, '.git')) { $url = Strings::substring($url, 0, -4); } $match = Strings::match($url, '~' . self::GITHUB_REGEXP . '~'); return 'https://' . Strings::lower($match[0]); }
/** * Computes salted password hash. * @param string * @return string */ public static function hashPassword($password, $options = NULL) { if ($password === Strings::upper($password)) { // perhaps caps lock is on $password = Strings::lower($password); } $password = substr($password, 0, self::PASSWORD_MAX_LENGTH); $options = $options ?: implode('$', array('algo' => PHP_VERSION_ID < 50307 ? '$2a' : '$2y', 'cost' => '07', 'salt' => Strings::random(22))); return crypt($password, $options); }
/** * Returns true if the whole given string is one of the suggested items * and not only a substring of some * * @param string $query The string we try to find * @return bool */ public function isSuggested($query) { $query = preg_quote($query); foreach ($this->items as $item) { if (preg_match('/^' . $query . '$/', Strings::lower($item))) { return true; } } return false; }
private function getRulesOrderFormula($order) { $formulasArr = ['default' => 'rule_id', 'fui' => 'confidence DESC', 'conf' => 'confidence DESC', 'confidence' => 'confidence DESC', 'supp' => 'support DESC', 'support' => 'support DESC', 'add' => 'lift DESC', 'lift' => 'lift DESC', 'a' => 'a DESC', 'b' => 'b DESC', 'c' => 'c DESC', 'd' => 'd DESC']; $order = Strings::lower($order); if (isset($formulasArr[$order])) { return $formulasArr[$order]; } else { return 'rule_id'; } }
/** * Checks that the given string is valid SHA1 hash and normalizes it to lower case. * * @param string $hash Image hash to validate * @throws HashException If the hash is not valid image hash * @return string The valid image hash */ private function checkHash($hash) { if (!is_string($hash)) { throw new HashException($hash); } $hash = Strings::lower($hash); if (!preg_match('/^[0-9a-f]{40}$/', $hash)) { throw new HashException($hash); } return $hash; }
/** * @param string $dataType * @return string */ private static function encodeDbDataType($dataType) { $dataType = Strings::lower($dataType); if (Strings::contains($dataType, 'int(')) { return PpAttribute::TYPE_NUMERIC; } elseif (Strings::contains($dataType, 'float') || Strings::contains($dataType, 'double') || Strings::contains($dataType, 'real')) { return PpAttribute::TYPE_NUMERIC; } else { return PpAttribute::TYPE_NOMINAL; } }
private function loadTags() { try { $tags = $this->tagFacade->findAll(); foreach ($tags->items as $tag) { $this->tags[$tag->id] = Strings::lower($tag->name); } } catch (EntityNotFoundException $ex) { \Tracy\Debugger::log($ex); } }
/** * @param string|null $coin1 * @param string|null $coin2 * @param string $mode * @return string */ public static function buildPair(string $coin1 = null, string $coin2 = null, string $mode = self::UPPERCASE) : string { if (($coin1 === null || $coin2 === null) && $coin1 !== $coin2) { throw new LogicException('You must provide both or none of the coins.'); } $pair = $coin1 !== null ? sprintf('%s_%s', $coin1, $coin2) : ''; if ($mode === self::LOWERCASE) { $pair = Strings::lower($pair); } return $pair; }
/** * @param FileUpload $fileUpload * @return string */ public static function sanitizeFileName(FileUpload $fileUpload) { $filename = $fileUpload->getSanitizedName(); $filename = Strings::lower($filename); $fileInfo = new \SplFileInfo($filename); $suffix = $fileInfo->getExtension(); $basename = $fileInfo->getBasename(".{$suffix}"); $hash = md5($fileUpload->getContents()); $hash = Strings::substring($hash, 0, 9); return Strings::substring($basename, 0, 50) . "_{$hash}.{$suffix}"; }
public function __construct($metadata) { $map = array("cs/jquery-ajax" => 66, "cs/invoice-control" => 53, "cs/treeview" => 78, "cs/cnb" => 34, "cs/file-downloader" => 80, "cs/scriptloader" => 81, "cs/live-form-validation" => 55, "cs/multiplefileupload" => 11, "cs/webloader" => 39, "cs/confirmationdialog" => 65, "cs/prototype-ajax" => 83, "cs/headercontrol" => 9, "cs/curl-wrapper" => 69, "cs/pdfresponse" => 7, "cs/datetimepicker" => 84, "cs/gui-for-acl" => 85, "cs/mootools-ajax" => 86, "cs/pswdinput" => 4, "cs/multiplefileupload/jak-na-vlastni-interface" => 11, "cs/dependentselectbox" => 3, "cs/suggestinput" => 1, "cs/tabella" => 87, "cs/userpanel" => 88, "cs/navigationpanel" => 5, "cs/presenterlinkpanel" => 64, "cs/phpedpanel" => 63, "cs/template-translator" => 62, "cs/componenttreepanel" => 61, "cs/imageselectbox" => 89, "cs/bigfiletools" => 60, "cs/dateinput" => 59, "cs/gmapformcontrol" => 17, "cs/json-rpc" => 56, "cs/mailpanel" => 57, "cs/textcaptcha" => 79, "cs/twitter-control" => 2, "cs/json-rpc2" => 56, "cs/live-form-validation-for-nette-2-0" => 55, "en/live-form-validation-for-nette-2-0" => 55, "cs/form-container-replicator" => 68, "cs/xdebugtracepanel" => 20, "en/form-container-replicator" => 68, "cs/email-protection" => 90, "cs/twitter" => 14, "cs/eciovni" => 53, "en/eciovni" => 53, "cs/gotopanel" => 10, "en/gotopanel" => 10, "cs/nette-ajax-js" => 26, "en/nette-ajax-js" => 26, "cs/sessionpanel" => 38, "cs/markette-gopay" => 24, "cs/niftygrid" => 52, "cs/redis-storage" => 72, "cs/dropbox-api" => 51, "cs/extensions-list" => 50, "cs/composer-extension" => 13, "cs/google-oauth2" => 49, "cs/eventcalendar" => 48, "cs/gps-picker" => 35, "en/gps-picker" => 35, "cs/gitbranch-debug-panel" => 47, "cs/facebook-connect-for-nette" => 46, "cs/menu" => 22, "cs/multi-authenticator" => 25, "cs/header" => 9, "cs/grido" => 45, "cs/mail-library" => 44, "en/mail-library" => 44, "cs/pdfresponse2" => 43, "cs/thumbnail-helper" => 42, "cs/cachepanel" => 92); $metadata['id'] = array(self::PATTERN => '(cs|en)/[a-z0-9-]+', self::FILTER_IN => function ($slug) use($map) { if (!array_key_exists(Strings::lower($slug), $map)) { return NULL; } return $map[Strings::lower($slug)]; }); parent::__construct('<id>', $metadata, self::ONE_WAY); }
/** * @param type $name * @param \User $user * @return \Project * @throws \ExistingProjectException */ public function createProject($values, \User $user) { $project = new \Project(); $key = $this->keyGenerator->generateKey(); $name = Strings::webalize(Strings::lower(Strings::toAscii($values->caption))); $name = str_replace('-', '_', $name); $project->setCaption($values->caption)->setName($name)->setSourceLanguage($values->sourceLang)->setLink($values->link)->setKey($key); $project->setOwner($user); $this->dm->persist($project); $this->dm->flush(); return $project; }
public function getByEmail($email) { $email = Strings::lower($email); $res = $this->getBy(['email' => $email]); if ($res) { return $res; } $alias = $this->model->userAliases->getByEmail($email); if ($alias) { return $alias->user; } return NULL; }
/** * @return string */ protected function getModule() { if (!$this->module) { $this->module = ''; if ($this->getPresenter()) { $name = $this->getPresenter()->getName(); if (strpos($name, ':') !== FALSE) { $this->module = Strings::lower(substr($name, 0, strrpos($name, ':'))); } } } return $this->module; }
public function render() { if (isset($this->filter['text']) && $this->filter['text']) { $translatesLocale = $this->getPresenter()->translatesLocale->where('LOWER(translate) REGEXP ?', Strings::lower($this->filter['text']))->where('language_id', $this->getPresenter()->webLanguage); $translateId = array(); foreach ($translatesLocale as $tl) { $translateId[] = $tl['translate_id']; } if (!empty($translateId)) { $this->model->where('LOWER(text) REGEXP ? OR id IN ?', array(Strings::lower($this->filter['text']), $translateId)); } else { $this->model->where('LOWER(text) REGEXP ?', Strings::lower($this->filter['text'])); } } parent::render(); }