/** * Prepares a string so that it can be used in urls. * * @param string $value The value that should be urlised. * * @return string The urlised string. */ public static function getUrl($value) { // convert cyrlic, greek or other caracters to ASCII characters $value = Transliterator::transliterate($value); // make a clean url out of it return Transliterator::urlize($value); }
public function import($file, OutputInterface $output) { $csvFile = new CsvFile($file); $csv = $csvFile->getCsv(); $cpt = 0; $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration(); if (!$configuration) { $configuration = new Configuration(); $configuration->setId(Configuration::PREFIX); } foreach ($csv as $data) { $produit = new Produit(); $produit->setIdentifiant(strtoupper(Transliterator::urlize(trim(preg_replace("/[ ]+/", " ", $data[self::CSV_NOM]))))); $produit->setNom(ucfirst(strtolower($data[self::CSV_NOM]))); $produit->setConditionnement($data[self::CSV_CONDITIONNEMENT]); $produit->setPrixHt($data[self::CSV_PRIX_HT]); $produit->setPrixPrestation($data[self::CSV_PRIX_PRESTATION]); $produit->setPrixVente($data[self::CSV_PRIX_VENTE]); if ($data[self::CSV_STATUT]) { $produit->setStatut(Produit::PRODUIT_ACTIF); } else { $produit->setStatut(Produit::PRODUIT_INACTIF); } $configuration->addProduit($produit); $this->dm->persist($configuration); } $this->dm->flush(); }
public function import($file, OutputInterface $output) { $csvFile = new CsvFile($file); $csv = $csvFile->getCsv(); $cpt = 0; $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration(); if (!$configuration) { $configuration = new Configuration(); $configuration->setId(Configuration::PREFIX); $this->dm->persist($configuration); $this->dm->flush(); } foreach ($csv as $data) { $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration(); $founded = false; foreach ($configuration->getPrestationsArray() as $prestaConf) { if ($prestaConf->getNom() == $data[self::CSV_NOM]) { $founded = true; } } if ($founded) { continue; } if ($data[self::CSV_ID]) { $prestation = new Prestation(); $prestation->setIdentifiant(strtoupper(Transliterator::urlize(trim(preg_replace("/[ ]+/", " ", $data[self::CSV_ID]))))); $prestation->setNom($data[self::CSV_NOM]); $prestation->setNomCourt($data[self::CSV_NOM_COURT]); $configuration->addPrestation($prestation); $this->dm->flush(); } } }
/** * Generates canonical text for step text. * * @param string $stepText * * @return string */ private function generateCanonicalText($stepText) { $canonicalText = preg_replace(array_keys(self::$replacePatterns), '', $stepText); $canonicalText = Transliterator::transliterate($canonicalText, ' '); $canonicalText = preg_replace('/[^a-zA-Z\\_\\ ]/', '', $canonicalText); $canonicalText = str_replace(' ', '', ucwords($canonicalText)); return $canonicalText; }
public function updateCodes() { $settings = $this->container->get("doctrine")->getRepository("CoreBundle:UserSetting")->findAll(); $manager = $this->container->get("doctrine")->getManager(); foreach ($settings as $setting) { $setting->setCode(Transliterator::transliterate($setting->getName())); $manager->persist($setting); } $manager->flush(); }
/** * {@inheritdoc} */ public function generate($name, $parentId = null) { $taxonSlug = Transliterator::transliterate($name); if (null === $parentId) { return $taxonSlug; } /** @var TaxonInterface $parent */ $parent = $this->taxonRepository->find($parentId); Assert::notNull($parent, sprintf('There is no parent taxon with id %d.', $parentId)); return $parent->getSlug() . self::SLUG_SEPARATOR . $taxonSlug; }
public function createFilename(FeatureNode $feature, ScenarioInterface $scenario, OutlineNode $outline = null) { $filename = Transliterator::transliterate($feature->getTitle(), $this->separator) . DIRECTORY_SEPARATOR; if ($outline) { $filename .= Transliterator::transliterate($outline->getTitle(), $this->separator) . DIRECTORY_SEPARATOR . $this->separator; } $filename .= Transliterator::transliterate($scenario->getTitle(), $this->separator); if ($outline) { $filename .= $this->separator; } return $filename; }
/** * Translaterates UTF-8 string to ASCII. (北京 to 'Bei Jing') * * Accepts language parameter that maps to a configurable array of special transliteration rules if present. * * @param string $text Text to transliterate * @param string $language Optional language for specific rules (falls back to current locale if not provided) * @return string */ public function transliterate($text, $language = null) { $language = $language ?: $this->localizationService->getConfiguration()->getCurrentLocale()->getLanguage(); if (isset($this->transliterationRules[$language])) { // Apply special transliteration (not supported in library) $text = strtr($text, $this->transliterationRules[$language]); } // Transliterate (transform 北京 to 'Bei Jing') if (preg_match('/[\\x80-\\xff]/', $text) && Transliterator::validUtf8($text)) { $text = Transliterator::utf8ToAscii($text); } return $text; }
/** * Transforms a text (for example a node title) into a valid node name by removing invalid characters and * transliterating special characters if possible. * * @param string $name The possibly invalid node name * @return string A valid node name */ public static function renderValidNodeName($name) { // Check if name already match name pattern to prevent unnecessary transliteration if (preg_match(NodeInterface::MATCH_PATTERN_NAME, $name) === 1) { return $name; } // Transliterate (transform 北京 to 'Bei Jing') $name = Transliterator::transliterate($name); // Urlization (replace spaces with dash, special special characters) $name = Transliterator::urlize($name); // Ensure only allowed characters are left $name = preg_replace('/[^a-z0-9\\-]/', '', $name); return $name; }
public function hardSave($directory, $path) { $basePath = rtrim($this->settings->path, '/') . '/' . Transliterator::urlize($directory); $baseUrl = rtrim($this->settings->urlPath, '/') . '/' . Transliterator::urlize($directory); if (!file_exists($basePath)) { mkdir($basePath, 0755, true); } $savePath = $basePath . '/' . basename($path); $saveUrl = $baseUrl . '/' . basename($path); if (rename($path, $savePath)) { $this->savedFiles[$savePath] = $saveUrl; return true; } return false; }
/** * Generates a URI path segment for a given node taking it's language dimension into account * * @param NodeInterface $node Optional node to determine language dimension * @param string $text Optional text * @return string */ public function generateUriPathSegment(NodeInterface $node = null, $text = null) { if ($node) { $text = $text ?: $node->getLabel() ?: $node->getName(); $dimensions = $node->getContext()->getDimensions(); if (array_key_exists('language', $dimensions) && $dimensions['language'] !== array()) { $locale = new Locale($dimensions['language'][0]); $language = $locale->getLanguage(); } } elseif (strlen($text) === 0) { throw new Exception('Given text was empty.', 1457591815); } $text = $this->transliterationService->transliterate($text, isset($language) ? $language : null); return Transliterator::urlize($text); }
/** * @param string $text * @return array */ public static function analyse($text) { // to lowercase $text = mb_strtolower(trim($text), 'utf-8'); // remove accents $text = Transliterator::unaccent($text); // considering very special chars as spaces $text = str_replace(array('@', '.', ',', '¿', '♠', '♣', '♥', '♦', '-', '+', '←', '↑', '→', '↓', "'", '’', '´', '●', '•', '¼', '½', '¾', '“', '”', '„', '°', '™', '©', '®', '³', '²'), ' ', $text); // remove multiple spaces $text = preg_replace('/\\s+/', ' ', $text); if ($text) { return explode(' ', $text); } return []; }
public function import($file, OutputInterface $output) { $csvFile = new CsvFile($file); $progress = new ProgressBar($output, 100); $progress->start(); $csv = $csvFile->getCsv(); $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration(); $prestationsArray = $configuration->getPrestationsArray(); $i = 0; $cptTotal = 0; foreach ($csv as $data) { $contrat = $this->cm->getRepository()->findOneByIdentifiantReprise($data[self::CSV_OLD_ID_CONTRAT]); if (!$contrat) { $i++; $cptTotal++; continue; } $prestationNom = strtoupper(Transliterator::urlize(str_replace('#', '', $data[self::CSV_PRESTATION]))); if (!array_key_exists($prestationNom, $prestationsArray)) { $i++; $cptTotal++; $output->writeln(sprintf("<comment>La prestation '%s' du contrat %s n'existe pas en base!</comment>", $prestationNom, $contrat->getId())); continue; } $prestationConf = $prestationsArray[$prestationNom]; $prestation = clone $prestationConf; $prestation->setNbPassages(0); $contrat->addPrestation($prestation); $i++; $cptTotal++; if ($cptTotal % (count($csv) / 100) == 0) { $progress->advance(); } if ($i >= 1000) { $this->dm->flush(); $this->dm->clear(); gc_collect_cycles(); $i = 0; } } $this->dm->flush(); $progress->finish(); }
/** * @dataProvider provideUrlizationCases */ public function testUrlization($input, $expected) { $this->assertSame($expected, Transliterator::urlize($input)); }
/** * @return string */ public function getSlug() { return Transliterator::transliterate($this->getTitle()); }
public function testTranslit() { $url = 'это тестовый title с названием'; $this->assertSame('eto-tiestovyi-title-s-nazvaniiem', \Behat\Transliterator\Transliterator::transliterate($url)); }
/** * Set nom * * @param string $nom * @return self */ public function setNom($nom) { $this->nom = $nom; $this->setIdentifiant(strtoupper(Transliterator::urlize($nom))); return $this; }
/** * @Route("/passage/pdf-missions-massif", name="passage_pdf_missions_massif") */ public function pdfMissionsMassifAction(Request $request) { $fm = $this->get('facture.manager'); $pm = $this->get('passage.manager'); $dm = $this->get('doctrine_mongodb')->getManager(); if ($request->get('technicien')) { $technicien = $dm->getRepository('AppBundle:Compte')->findOneById($request->get('technicien')); $passages = $pm->getRepository()->findAllPlanifieByPeriodeAndIdentifiantTechnicien($request->get('dateDebut'), $request->get('dateFin'), $technicien); $filename = sprintf("suivis_client_%s_%s_%s.pdf", $request->get('dateDebut'), $request->get('dateFin'), strtoupper(Transliterator::urlize($technicien->getIdentite()))); } else { $passages = $pm->getRepository()->findAllPlanifieByPeriode($request->get('dateDebut'), $request->get('dateFin')); $filename = sprintf("suivis_client_%s_%s.pdf", $request->get('dateDebut'), $request->get('dateFin')); } $passagesHistories = array(); foreach ($passages as $passage) { $passagesHistories[$passage->getId()] = $pm->getRepository()->findHistoriqueByEtablissementAndPrestationsAndNumeroContrat($passage->getContrat(), $passage->getEtablissement(), $passage->getPrestations()); } $html = $this->renderView('passage/pdfMissionsMassif.html.twig', array('passages' => $passages, 'passagesHistories' => $passagesHistories)); if ($request->get('output') == 'html') { return new Response($html, 200); } return new Response($this->get('knp_snappy.pdf')->getOutputFromHtml($html, $this->getPdfGenerationOptions()), 200, array('Content-Type' => 'application/pdf', 'Content-Disposition' => 'attachment; filename="' . $filename . '"')); }
public function createFilename(FeatureNode $feature, ScenarioInterface $scenario, OutlineNode $outline = null) { return $this->directory . DIRECTORY_SEPARATOR . Transliterator::transliterate(implode($this->separator, $scenario->getTags()), $this->separator); }
/** * Return a translitared name for a project * * @param string $projectPath Project directory * * @return string */ public function getProjectName($projectPath) { $project = basename(realpath($projectPath)); $project = Transliterator::transliterate($project, '-'); return $project; }
public function getPaiementUniqueParLibelle() { $paiementsUnique = array(); foreach ($this->getPaiement() as $paiement) { if (!$paiement->getLibelle() || $paiement->getLibelle() == "") { $key = md5(microtime() . rand()); $paiementsUnique[$key] = clone $paiement; } else { $key = Transliterator::urlize($paiement->getMoyenPaiement() . '-' . $paiement->getLibelle()); if (!array_key_exists($key, $paiementsUnique)) { $paiementsUnique[$key] = clone $paiement; $paiementsUnique[$key]->setMontantTemporaire($paiement->getMontant()); } else { $paiementsUnique[$key]->addMontantTemporaire($paiement->getMontant()); } $paiementsUnique[$key]->addFactureTemporaire($paiement->getFacture()); } } return $paiementsUnique; }
public function setName($name) { $this->name = $name; $this->slug = Transliterator::urlize($name); return $this; }
/** * Returns the filename sanitized to minimize issues with various platforms * @return string the sanitized filename */ public function getSanitizedFileName() { return Transliterator::transliterate($this->_fileName) . '.' . $this->getExtension(); }
/** * @param string $name */ public function __construct($name) { $this->name = Transliterator::urlize($name); $this->threshold = []; $this->excludeCategories = []; $this->excludeQuestions = []; $this->initialized(); }
/** * Generates a slug of the text after transliterating the UTF-8 string to ASCII. * * Unaccent umlauts/accents prior to transliteration. * Uses transliteration tables to convert any kind of utf8 character. * * @param string $text * @param string $separator * * @return string $text */ public static function transliterate($text, $separator = '-') { $text = parent::unaccent($text); return parent::transliterate($text, $separator); }
private function importSubjects($languageCode) { if (empty($this->settings[$languageCode]['categories'])) { return array(); } $subjects = []; $categoryIds = unserialize($this->settings[$languageCode]['categories']); if (!is_array($categoryIds)) { return []; } foreach ($categoryIds as $categoryId) { $categorySql = "SELECT locale, setting_value FROM " . "controlled_vocab_entry_settings WHERE " . "controlled_vocab_entry_id = :categoryId"; $categoryStatement = $this->dbalConnection->prepare($categorySql); $categoryStatement->bindValue('categoryId', $categoryId); $categoryStatement->execute(); $pkpCategorySettings = $categoryStatement->fetchAll(); $categorySettings = []; foreach ($pkpCategorySettings as $pkpSetting) { $locale = !empty($pkpSetting['locale']) ? $pkpSetting['locale'] : $languageCode; $value = $pkpSetting['setting_value']; $categorySettings[$locale] = $value; } $slug = Transliterator::urlize(array_values($categorySettings)[0]); $tags = str_replace(' ', ', ', strtolower(array_values($categorySettings)[0])); $subject = $this->em->getRepository('OjsJournalBundle:Subject')->findOneBy(['slug' => $slug]); if (!$subject) { $subject = new Subject(); $subject->setSlug($slug); $subject->setTags($tags); foreach ($categorySettings as $locale => $value) { $subject->setCurrentLocale(mb_substr($locale, 0, 2, 'UTF-8')); $subject->setSubject($value); $this->em->persist($subject); $this->em->flush(); } } $subjects[] = $subject; } return $subjects; }
/** * Set filename * * @param mixed $value * @param bool $overwrite [optional] Default overwrite is true * @param string $separator [optional] Default separator is an underscore '_' * @return void */ public function setFilename($value, $overwrite = true, $separator = '_') { // recast to string if $value is array if (is_array($value)) { $value = implode($separator, $value); } // trim unneeded values $value = trim($value, $separator); // remove all spaces $value = preg_replace('/\\s+/', $separator, $value); // if value is empty, stop here if (empty($value)) { return; } // decode value + lowercase the string $value = strtolower($this->decode($value)); // urlize this part $value = Transliterator::urlize($value); // overwrite filename or add to filename using a prefix in between $this->filename = $overwrite ? $value : $this->filename . $separator . $value; }
/** * {@inheritdoc} */ public function setSlug($slug) { //$this->slug = $slug; if (empty($slug)) { $slug = $this->title; } $this->slug = Transliterator::transliterate($slug); return $this; }
while (($line = fgets($handle)) !== false) { $found_any_delimiters = 0; foreach ($delimiters as $key) { $test = preg_match('/<' . $key[0] . ' ' . $key[1] . '/', $line); if ($test == 1) { //echo "found: ".$test.":".$line; $found_any_delimiters = 1; $part = \explode($key[0] . ' ' . $key[1] . '="', $line); //print_r($part); //echo "count: ".count($part); if (count($part) > 1) { $altered .= $part[0] . $key[0] . ' ' . $key[1] . '="'; //echo "altered-1: ".$part[0] . $key[0].' '.$key[1].'="'; $subpart = \explode('"', $part[1], 2); if (count($subpart) > 1) { $trans = Transliterator::utf8ToAscii($subpart[0]); $altered .= $trans . '"' . $subpart[1]; //echo "\naltered-2: ".$trans . '"'. $subpart[1]; } else { $altered .= $part[1]; //echo "\naltered-2: ".$part[1]; } //echo "\n"; } else { $altered .= $line; } } } if ($found_any_delimiters == 0) { $altered .= $line; }
/** * Does not transliterate correctly eastern languages * * @param string $text * @param string $separator * * @return string */ public static function urlize($text, $separator = '-', $excludeTwig = false) { $text = parent::unaccent($text); return self::postProcessText($text, $separator, $excludeTwig); }