/** * @ORM\PreFlush() */ public function preUpload() { if ($this->file) { if ($this->file instanceof FileUpload) { $basename = $this->file->getSanitizedName(); $basename = $this->suggestName($this->getFilePath(), $basename); $this->setName($basename); } else { $basename = trim(Strings::webalize($this->file->getBasename(), '.', FALSE), '.-'); $basename = $this->suggestName(dirname($this->file->getPathname()), $basename); $this->setName($basename); } if ($this->_oldPath && $this->_oldPath !== $this->path) { @unlink($this->getFilePathBy($this->_oldProtected, $this->_oldPath)); } if ($this->file instanceof FileUpload) { $this->file->move($this->getFilePath()); } else { copy($this->file->getPathname(), $this->getFilePath()); } return $this->file = NULL; } if (($this->_oldPath || $this->_oldProtected !== NULL) && ($this->_oldPath != $this->path || $this->_oldProtected != $this->protected)) { $oldFilePath = $this->getFilePathBy($this->_oldProtected !== NULL ? $this->_oldProtected : $this->protected, $this->_oldPath ?: $this->path); if (file_exists($oldFilePath)) { rename($oldFilePath, $this->getFilePath()); } } }
/** * @param $data */ public function insert($data, $code = NULL) { $this->cleanData($data); if (isset($data['map_coords'])) { $coords = Geolocation::getCoordsFromText($data['map_coords']); $data['lat'] = $coords[0]; $data['lon'] = $coords[1]; } $to_code = isset($data['locality_nickname']) ? $data['name'] . " " . $data['locality_nickname'] : $data['name']; $data['code'] = $code ? $code : \Nette\Utils\Strings::webalize($to_code); $data['stroller'] = isset($data['stroller']) ? 1 : 0; $data['visible'] = isset($data['visible']) ? 1 : 0; $data['show_in_catalogue'] = isset($data['show_in_catalogue']) ? 1 : 0; $data['show_in_calendar'] = isset($data['show_in_calendar']) ? 1 : 0; $data['created'] = new \DibiDateTime(time()); $cats = $data['categories']; $res = dibi::select('code')->from('subject')->where('code = %s', $data['code'])->fetch(); if ($res) { throw new \Exception("Duplicate entry '" . $data['code'] . "' for key 'code'", 1062); return false; } unset($data['categories']); dibi::begin(); dibi::query('INSERT INTO [subject]', $data); $id = dibi::insertId(); dibi::query('DELETE FROM [subject_x_category] WHERE [subject_id]=%i', $id); foreach ($cats as $k => $n) { dibi::query('INSERT INTO [subject_x_category] SET [subject_id]=%i', $id, ', [category_id]=%i', $n); } if (isset($data["user_id"])) { dibi::query('INSERT INTO [subject_x_user] SET [subject_id]=%i', $id, ', [user_id]=%i', $data["user_id"]); } dibi::commit(); return $id; }
public function renderDefault($id, $nazev) { $clanek = $this->clanky->get($this->id); if (empty($clanek) || empty($clanek['id'])) { throw new \Nette\Application\BadRequestException(); } $this->template->skupina = $this->clanky->getSouvisejici($id); $web_nazev = Nette\Utils\Strings::webalize($clanek['titulek']); if ($nazev != $web_nazev) { // throw new \Nette\Application\BadRequestException(); $this->redirect("this", array("id" => $clanek['id'], "nazev" => $web_nazev)); } $this->clanky->precteno($this->id); $this->template->clanek = $clanek; $this->template->title = $clanek['titulek']; $this->template->komentare = $this->komentare->getForClanek($this->id); $hodnoceni = $this->clanky->getHodnoceni($this->id); if (empty($hodnoceni['plus'])) { $hodnoceni['plus'] = 0; } if (empty($hodnoceni['minus'])) { $hodnoceni['minus'] = 0; } $this->template->hodnoceni = $hodnoceni; $this->template->moje_hodnoceni = $this->clanky->getHodnoceniByIp($this->id, $_SERVER['REMOTE_ADDR']); }
/** * @param string $path * @param string $find * @param int $depth */ public function addAutoloadConfig($path, $find = 'config.neon', $depth = -1) { // Development if (!$this->cacheConfig && $this->isDevelopment()) { foreach (Finder::find($find)->from($path)->limitDepth($depth) as $file) { $this->addConfig((string) $file); } return; } // Production $directory = $this->parameters['tempDir'] . '/cache/configs'; $cachePath = $directory . '/' . Strings::webalize(str_replace(dirname($this->parameters['appDir']), '', $path)) . '.neon'; if (file_exists($cachePath)) { $this->addConfig($cachePath); return; } $encoder = new Encoder(); $decoder = new Decoder(); @mkdir($directory); $content = []; foreach (Finder::find($find)->from($path)->limitDepth($depth) as $file) { $content = Helpers::merge($content, $decoder->decode(file_get_contents($file))); } file_put_contents($cachePath, $encoder->encode($content)); $this->addConfig($cachePath); }
public function setUrl($url = null) { if (!$url) { $url = Strings::webalize($this->id . " " . $this->title); } $this->setString("url", $url, 1, self::MAX_URL_LENGTH); }
protected function startup() { parent::startup(); $this->position = time(); $this->route->setLocalUrl(Strings::webalize(Strings::random())); $this->getRoute()->setPublished(TRUE); }
/** * @param string $name * @param Language $language */ public function __construct($name, Language $language) { $this->name = $name; $this->language = $language; $this->slug = Strings::webalize($name); $this->scenarios = new ArrayCollection(); }
public function startup() { parent::startup(); $this->dir = new DirEntity(); $this->dir->setInvisible(TRUE); $this->dir->setName(Strings::webalize(get_class($this)) . Strings::random()); }
/** * Vytvoreni nove galerie * @param type $values - name,editor_id,public[bool],start_public,stop_public * * @return type */ public function addGallery($files, $galleryName, $conf = NULL) { if (!is_array($conf)) { $params = $this->context->getParameters(); $driveConfigPath = $params['projectDir'] . '/config/drive.neon'; if (!is_file($driveConfigPath)) { $driveConfigPath = __DIR__ . '/examples/gal.neon'; } $conf = \Nette\Utils\Neon::decode(file_get_contents($driveConfigPath)); $conf = $conf['gallery']; } $this->setStorage('gallery'); $userId = 0; if ($this->presenter) { $userId = $this->presenter->user->isLoggedIn() ? $this->presenter->user->getId() : 0; } $galPath = isset($conf['path']) && !empty($conf['path']) ? Strings::webalize($conf['path']) : ''; $id = $this->createGallery($galleryName, $userId, $galPath, serialize($conf)); $galleryFolder = $this->relativePath; $this->mkDir($this->getFullPath(TRUE) . '/thumbs', FALSE, TRUE); $this->mkDir($this->getFullPath(TRUE) . '/originals', FALSE, TRUE); $this->_addFilesToGallery($galleryFolder, $files, $userId, $id, $conf); if (isset($conf['preserveOriginals']) && !$conf['preserveOriginals']) { $this->setPath($galleryFolder); $this->rmDir($this->getFullPath(TRUE) . '/originals/'); } return $id; }
public function handleUploadReciever() { $uploader = new \App\Pictures\UploadHandler(); $uploader->allowedExtensions = ['jpeg', 'jpg', 'png', 'gif']; $uploader->chunksFolder = __DIR__ . '/../../www/chunks'; $name = Nette\Utils\Strings::webalize($uploader->getName(), '.'); //TODO: picture optimalization (?) $result = $uploader->handleUpload(__DIR__ . '/../../www/uploads', $name); try { $picture = $this->pictures->findOneBy(['uuid' => $uploader->getUuid()]); if (!$picture) { //FIXME: toto není optimální (zejména kvůli rychlosti) $picture = new Picture(); } $picture->uuid = $uploader->getUuid(); $picture->name = $name; $picture->created = new \DateTime('now'); $this->pictures->save($picture); } catch (\Exception $exc) { $uploader->handleDelete(__DIR__ . '/../../www/uploads'); $this->sendResponse(new Nette\Application\Responses\JsonResponse(['error' => $exc->getMessage()])); } //TODO: napřed předat do šablony nová data $this->redrawControl('pictures'); $this->sendResponse(new Nette\Application\Responses\JsonResponse($result)); }
public function create(Product $product, FileUpload $fileUpload) { switch ($fileUpload->getContentType()) { case 'image/jpeg': $suffix = 'jpg'; break; case 'image/png': $suffix = 'png'; break; case 'image/gif': $suffix = 'gif'; break; default: throw new EntityInvalidArgumentException(sprintf('File is of an unknown type %s.', $fileUpload->getContentType())); } $baseName = sprintf('%s-%%s.%s', Strings::webalize($product->getName()), $suffix); do { $fileName = sprintf($baseName, Random::generate(5, '0-9a-zA-Z')); $path = sprintf('%s/%s', $this->imagesDir, $fileName); } while (file_exists($path)); $fileUpload->move($path); $image = new ProductImage($product, $fileName); $this->createEntity($image); $product->addImage($image); return $image; }
/** * @param $form * @param $values */ public function uploadImgFormSucceeded($form, $values) { $values = $form->getValues(); foreach ($values->img as $img) { // ActiveRow if ($img->isOk()) { $row = $this->imagesRepository->findAll()->insert(array('users_id' => $this->user->id, 'title' => $photoName = Strings::webalize($img->getName(), '.'), 'origin' => 'noSet', 'created_at' => new \DateTime())); $photo = Image::fromFile($img); $photoID = $row->getPrimary(); $photoX = $photo->height; $photoY = $photo->width; $path = __DIR__ . '/../../../web/images/' . $photoID; //mkdir('/var/www/m/' . $photoID, 0755, true); //mkdir('/var/www/skeleton/web/images/aaannn', 0755, true); if ($photoX > 102 or $photoY > 768) { $photo->resize(1024, 768, Image::SHRINK_ONLY); } mkdir($path, 0755, TRUE); $photo->save($path . '/' . $photoName); //$photoXGA = $photo->resize(1024, 768, Image::SHRINK_ONLY); //$photoSVGA->resize(800, 600, Image::SHRINK_ONLY); //$photoSVGA->resize(800, 600, Image::SHRINK_ONLY); //$imgName = $img->name; $this->flashMessage($this->translator->translate('ui.your-image-has-been-sent'), 'alert alert-success'); } } }
/** * @param $id * * @return AssetsLoader\Application\FileResponse|Application\Responses\TextResponse */ public function actionFiles($id) { if (NULL === ($item = $this->fileCache->getItem(Utils\Strings::webalize($id)))) { return new Application\Responses\TextResponse(''); } return new AssetsLoader\Application\FileResponse($item[Caching\FileCache::CONTENT]); }
private function getLogger($channel) { $l = $this->logger; if (isset($channel)) { $l = $l->channel(Strings::webalize($channel)); } return $l; }
/** * Funkce pro připravení bezpečného jména pro atributy, data fields atd. * @param $string * @return string */ public static function prepareSafeName($string) { $string = str_replace('-', '_', Strings::webalize($string, true)); while (strpos($string, '__') > 0) { $string = str_replace('__', '_', $string); } return trim($string, '_'); }
/** * @param \FlickrDownloadr\Photoset\Photoset $photoset * @param string $mask * @param boolean $noTitleSlug * @return string */ public function create(Photoset $photoset, $mask, $noTitleSlug = FALSE) { $title = $photoset->getTitle(); if (!$noTitleSlug) { $title = \Nette\Utils\Strings::webalize($title); } return strtr($mask, array('%id%' => $photoset->getId(), '%title%' => $title, '%year%' => date('Y', $photoset->getDateCreate()), '%month%' => date('m', $photoset->getDateCreate()), '%day%' => date('d', $photoset->getDateCreate()))); }
/** * @param string|array $file * @param int $time * @param bool $debugMode * * @return string */ public static function computeHash($file, $time, $debugMode) { $debug = $debugMode ? 1 : 0; $file = is_array($file) ? implode(',', $file) : $file; $md5Raw = md5("{$debug};{$file};{$time}", TRUE); $base64 = Strings::replace(base64_encode($md5Raw), '~\\W~'); return Strings::substring(Strings::webalize($base64), 0, 8); }
/** * @param \FlickrDownloadr\Photo\Photo $photo * @param boolean $noTitleSlug * @return string */ private function getTitle(Photo $photo, $noTitleSlug) { $title = $photo->getTitle(); if (!$noTitleSlug) { $title = \Nette\Utils\Strings::webalize($title); } return $title; }
public static function getSeoUrl($data, $suffix = '') { if (empty($suffix)) { return \Nette\Utils\Strings::webalize($data); } else { return \Nette\Utils\Strings::webalize($data) . '-' . $suffix; } }
public function __construct(NewsletterEntity $newsletter) { $this->newsletter = $newsletter; $this->dir = new DirEntity(); $this->dir->setParent($this->newsletter->route->getDir()); $this->dir->setInvisible(TRUE); $this->dir->setName(Strings::webalize(get_class($this)) . Strings::random()); }
public function email($first, $last) { if ($this->numberBetween(0, 100) > 90) { return Strings::webalize($first) . '@' . Strings::webalize($last) . '.' . $this->randomElement(['cz', 'cz', 'cz', 'cz', 'cz', 'cz', 'com', 'com', 'com', 'pro', 'name', 'info', 'net', 'org']); } else { return Strings::webalize("{$first}.{$last}", '.') . '@' . Internet::freeEmailDomain(); } }
/** * @param string $name */ public function setName($name) { $name = (string) $name; if ($name === '') { throw new EntityInvalidArgumentException('Name cannot be empty.'); } $this->name = $name; $this->path = Strings::webalize($name); }
/** * @param Form $form */ public function formSucceeded(Form $form) { $values = $form->getValues(); $galleries = new GalleriesEntity(); $galleries->name($values->name); $galleries->description($values->description); $galleries->url(Strings::webalize($values->name)); $this->galleriesRepository->save($galleries); }
public function setName($name) { if ($this->translator) { $name = $this->translator->translate($name); } $this->fixed_name = Strings::webalize($name); $this->name = $name; return $this; }
/** * Translates the given string. * @param string message * @param int plural count * @return string */ public function translate($message, $count = NULL) { $trans_key = \Nette\Utils\Strings::webalize($message); if (isset($this->_trans_table[$trans_key])) { return $this->_trans_table[$trans_key]; } else { return $message; } }
public function renderHeaderCell($sortingEnabled) { $tableHeader = $this->html->el('th', array('class' => 'cell-' . Strings::webalize($this->columnName))); $cellContent = $this->getCellData(); if ($sortingEnabled) { $cellContent = $this->getSortingAnchor(); } $tableHeader->setText($cellContent); return $tableHeader; }
public function createRoute($title, $contentId, $sectionId) { $route = array(); $route['contentId'] = $contentId; $webalize = \Nette\Utils\Strings::webalize($title); $webalize = \Nette\Utils\Strings::substring($webalize, 0, 50); $route['url'] = "program/" . $sectionId . "/" . $webalize; $route['creationTime'] = date("Y-m-d G:i:s"); return $route; }
public function remove($filename, $ext, $path) { $filename = Strings::webalize($filename) . '.' . Strings::webalize($ext); $absoluteFilename = $this->getAbsolutePath($path . $filename); if (file_exists($absoluteFilename)) { return unlink($absoluteFilename); } else { return TRUE; } }
/** * Send JSONP response to output * @param IRequest $httpRequest * @param IResponse $httpResponse * @throws \Drahak\Restful\InvalidArgumentException */ public function send(IRequest $httpRequest, IResponse $httpResponse) { $httpResponse->setContentType($this->contentType ? $this->contentType : 'application/javascript', 'UTF-8'); $data = array(); $data['response'] = $this->data; $data['status'] = $httpResponse->getCode(); $data['headers'] = $httpResponse->getHeaders(); $callback = $httpRequest->getQuery('jsonp') ? Strings::webalize($httpRequest->getQuery('jsonp'), NULL, FALSE) : ''; echo $callback . '(' . $this->mapper->stringify($data, $this->isPrettyPrint()) . ');'; }
/** * @param \App\type $id * @return \App\PresenterLinkSettings */ public function create($id) { $item = $this->menuItemDataSource->get($id, function (Selection $context) { $pageKey = ':menu_has_rubric.rubric.id'; $context->select('section.module, menu.section_id, menu.name'); $context->select("{$pageKey}"); $context->where("{$pageKey} IS NOT NULL"); }); return $this->presenterLinkSettingsFactory->create("Article:rubric", ['id' => $item->id, 'slug' => \Nette\Utils\Strings::webalize($item->name)]); }