protected function slugifiy($guess) { //ToDo: Because of translation we need to check for array, maybe its better to overwrite this class in TransaltionBundle if (is_array($guess)) { $guess = reset($guess); } $slugifier = new Slugifier(); return sprintf('/%s', $slugifier->slugify($guess)); }
/** * Generated the entry for the users table. * * @param string $user_login The user login slug * * @return array An associtive array of column/values for the "users" table. */ public static function generateUserTableDataFrom($user_login, array $userData = array()) { $utils = new Slugifier(); $login = $utils->slugify($user_login); $usersTableDefaults = array('user_login' => $login, 'user_pass' => WpPassword::instance()->make($user_login), 'user_nicename' => $user_login, 'user_email' => $login . "@example.com", 'user_url' => "http://{$login}.example.com", 'user_registered' => Date::now(), 'user_activation_key' => '', 'user_status' => '0', 'display_name' => $user_login); if (!empty($userData['user_pass'])) { $userData['user_pass'] = WpPassword::instance()->make($userData['user_pass']); } return array_merge($usersTableDefaults, array_intersect_key($userData, $usersTableDefaults)); }
protected function slugifiy($guess) { $slugifier = new Slugifier(); if (is_array($guess)) { foreach ($guess as $key => $value) { $guess[$key] = sprintf('/%s', $slugifier->slugify($value)); } return $guess; } return sprintf('/%s', $slugifier->slugify($guess)); }
/** * Slugify text * * Runs all defined filters in ASC order * * @example '.Zażółć gęślą jaźń-!-' -> 'zazolc-gesla-jazn' * @param $text * @return string */ public function slugify($text) { if (!is_string($text) || $text === '') { return ''; } $text = $this->uniDecode($text); $text = $this->slugifier->filter($text); foreach ($this->filters as $filter) { $text = $filter->filter($text); } return $text; }
private function getSlugifiedFilename($text) { $slugifier = new Slugifier(); $filePathinfo = pathinfo($text); $result = $slugifier->slugify($filePathinfo['filename']) . '.' . $filePathinfo['extension']; // $result = strtolower($text); // $result = preg_replace('/\s+/g', '-', $result); // Replace spaces with - // $result = preg_replace('/[^\w\-\.]+/g', '', $result); // Remove all non-word chars, keep . to preserve extension // $result = preg_replace('/\-\-+/g', '-', $result); // Replace multiple - with single - // $result = preg_replace('/^-+/', '', $result); // Trim - from start of text // $result = preg_replace('/-+$/', '', $result); // Trim - from end of text return $result; }
protected function slugifiy($guess) { $slugifier = new Slugifier(); return sprintf('/%s', $slugifier->slugify($guess)); }
/** * Adds an uploaded file to the database. $file can be one of the following: * - A string: expected to be absolute path + filename. An Exception will be thrown if the file doesn't exist or is * not readable for the apache user. File extension will be taken from the name, mime type will be determined * by Symfony MimeTypeGuesser. * - An instance of SplFileInfo. File extension will be taken from the name, mime type will be determined * by Symfony MimeTypeGuesser. * - An instance of Symfony types File or UploadedFile. Attributes will be determined by using the types member * functions. * * The file will be copied for storage, the original file will not be removed. * * The attributes mime type, extension, title (slug), file name and order can optionally be configured. If null, * they are generated automatically from the file. * Note: $title will always be slugified. * * The optional parameter $garbage sets the initial state of the garbage collector mark (default false). If it * remains true, the entry will be deleted by the garbage collector in the future (1 day minimum). This can be * useful for forms with ajax upload ahead of the total submit, when an uploaded file is not yet connected to a * parent object and the form might be cancelled leaving the file object unconnected and unused. * * @param string|\SplFileInfo|File|UploadedFile $file The file to add to the database * @param string|null $mimeType [optional] Mime type, overrides automatically * guessed mime type * @param string|null $fileExtension [optional] File extension, overrides automatically * determined extension * @param string|null $slug [optional] slug, overrides automatically determined * slug (from file name) * @param string|null $fileName [optional] File name, overrides automatically * determined file name * @param int|null $order [optional] File order index * @param bool $garbage [optional] Initial mark for garbage collector * @throws \Exception Thrown if file does not exist, is not readable, cannot be copied or parameter $file is of * unknown type. * @return EnhavoFile The generated doctrine entity object (already persisted). */ public function storeFile($file, $mimeType = null, $fileExtension = null, $slug = null, $fileName = null, $order = null, $garbage = false) { $fileInfo = $this->getFileInformation($file); if (!$fileInfo) { throw new \InvalidArgumentException("Invalid format on file parameter; possible formats: Symfony\\Component\\HttpFoundation\\File\\UploadedFile, Symfony\\Component\\HttpFoundation\\File\\File, \\SplFileInfo or string (absolute path + filename)"); } $slugifier = new Slugifier(); if ($mimeType == null) { $mimeType = $fileInfo['mime_type']; } if ($fileExtension == null) { $fileExtension = $fileInfo['extension']; } if ($slug == null) { $slug = $fileInfo['filename']; } $slug = $slugifier->slugify($slug) . '.' . $fileInfo['extension']; if ($fileName == null) { $fileName = $fileInfo['basename']; } $entityFile = new EnhavoFile(); $entityFile->setMimeType($mimeType); $entityFile->setExtension($fileExtension); $entityFile->setSlug($slug); $entityFile->setFilename($fileName); $entityFile->setOrder($order); $entityFile->setGarbage($garbage); $this->manager->persist($entityFile); $this->manager->flush(); try { copy($fileInfo['pathname'], $this->getDirectory($entityFile) . '/' . $entityFile->getId()); } catch (\Exception $exception) { $this->manager->remove($entityFile); $this->manager->flush(); throw $exception; } return $entityFile; }
protected function slugifiy($context) { $slugifier = new Slugifier(); return sprintf('/%s', $slugifier->slugify($context)); }
protected function parseBatchActions() { $authorizationChecker = $this->container->get('security.authorization_checker'); $batch_actions = $this->getConfig()->get('table.batch.actions'); if (!$batch_actions) { return array(); } if (count($batch_actions) > 0) { if (!isset($batch_actions[self::BATCH_ACTION_NONE_SELECTED])) { $batch_actions[self::BATCH_ACTION_NONE_SELECTED] = array('label' => 'table.batch.label.selectAction', 'confirm_message' => '', 'translation_domain' => 'EnhavoAppBundle'); } $translator = $this->container->get('translator'); $slugifier = new Slugifier(); $pos = 100; $batch_actions_parsed = array(); foreach ($batch_actions as $command => $value) { if (isset($value['permission']) && $value['permission']) { if (!$authorizationChecker->isGranted($value['permission'])) { continue; } } $command_parsed = $slugifier->slugify($command); $action_parsed = array(); if (isset($value['translation_domain']) && $value['translation_domain']) { $domain = $value['translation_domain']; } else { $domain = $this->getTranslationDomain(); } if (isset($value['label']) && $value['label']) { $action_parsed['label'] = $translator->trans($value['label'], array(), $domain); } else { $action_parsed['label'] = $command; } if (isset($value['confirm_message']) && $value['confirm_message']) { $action_parsed['confirm_message'] = $translator->trans($value['confirm_message'], array(), $domain); } else { $action_parsed['confirm_message'] = $translator->trans('table.batch.message.confirm.generic', array('%command%' => $command), 'EnhavoAppBundle'); } if (isset($value['position']) && is_int($value['position']) && $value['position'] >= 0) { $action_parsed['position'] = $value['position']; } else { if ($command == self::BATCH_ACTION_NONE_SELECTED) { $action_parsed['position'] = -1; } else { $action_parsed['position'] = $pos++; } } $batch_actions_parsed[$command_parsed] = $action_parsed; } uasort($batch_actions_parsed, function ($a, $b) { if ($a['position'] == $b['position']) { return 0; } return $a['position'] < $b['position'] ? -1 : 1; }); return $batch_actions_parsed; } return array(); }
/** * @param $className * @return string */ public function getFileName($className, $userArguments) { return $this->cacheDir . $this->slugifier->slugify($className) . '_' . $this->slugifier->slugify(json_encode($userArguments)) . '.php'; }