/** * Get taxes percent * * @param tax_names array if present shows only percent of those taxes * @return integer total percent of taxes to apply */ public function getTaxesPercent($tax_names = array()) { $tax_names = is_array($tax_names) ? array_map(array('Gedmo\\Sluggable\\Util\\Urlizer', 'urlize'), $tax_names) : array(Urlizer::urlize($tax_names)); $total = 0; foreach ($this->getTaxes() as $tax) { if (count($tax_names) == 0 || in_array(Urlizer::urlize(str_replace(' ', '', $tax->getName())), $tax_names)) { $total += $tax->getValue(); } } return $total; }
public static function urlize($string, $separator = '-') { return Urlizer::urlize($string, $separator); }
/** * Przekształca także ze znakami rosyjskimi. * * @param string $text * @param string $delimiter * * @return string */ public static function toSlugg($str, $delimiter = '-') { $rep = array('ё' => 'yo', 'Ё' => 'Yo', 'ъ' => '', 'Ъ' => '', 'я' => 'ya', 'Я' => 'Ya', 'ш' => 'sh', 'Ш' => 'Sh', 'е' => 'e', 'Е' => 'E', 'р' => 'r', 'Р' => 'R', 'т' => 't', 'Т' => 'T', 'ы' => 'y', 'Ы' => 'Y', 'у' => 'u', 'У' => 'U', 'и' => 'i', 'И' => 'I', 'о' => 'o', 'О' => 'O', 'п' => 'p', 'П' => 'P', 'ю' => 'yu', 'Ю' => 'Yu', 'щ' => 'sch', 'Щ' => 'Sch', 'э' => 'e', 'Э' => 'E', 'а' => 'a', 'А' => 'A', 'с' => 's', 'С' => 'S', 'д' => 'd', 'Д' => 'D', 'ф' => 'f', 'Ф' => 'F', 'г' => 'g', 'Г' => 'G', 'ч' => 'ch', 'Ч' => 'Ch', 'й' => 'j', 'Й' => 'J', 'к' => 'k', 'К' => 'K', 'л' => 'l', 'Л' => 'L', 'ь' => '', 'Ь' => '', 'ж' => 'zh', 'Ж' => 'Zh', 'з' => 'z', 'З' => 'Z', 'х' => 'h', 'Х' => 'H', 'ц' => 'ts', 'Ц' => 'Ts', 'в' => 'v', 'В' => 'V', 'б' => 'b', 'Б' => 'B', 'н' => 'n', 'Н' => 'N', 'м' => 'm', 'М' => 'M'); $str = strtr($str, $rep); return Urlizer::urlize($str, $delimiter); // torchę nowsza logika vvv // return str_replace($rep, $rep2, $str); // // // setlocale(LC_ALL, 'en_US.UTF8'); // if( !empty($replace) ) { // $str = str_replace((array)$replace, ' ', $str); // } // // $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str); // $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean); // $clean = strtolower(trim($clean, '-')); // $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean); // // return $clean; // torchę nowsza logika ^^^ // ============= stara logika ========== vvv // $detect = $this->detectEncoding($text); // if ($detect !== 'ASCII') { // $text = mb_convert_encoding($text, 'UTF-8', $detect); // } // // $text = iconv(mb_detect_encoding($text), 'us-ascii//TRANSLIT//IGNORE', $text); // $text = $this->removeAccents($text); // $text = preg_replace("/[^a-z0-9]/i", $delimiter, $text); // $text = mb_strtolower(trim($text, $delimiter)); // $text = preg_replace("#$delimiter$delimiter+#", $delimiter, $text); // return $text; // ============= stara logika ========== ^^^ }
/** * method used to slugify text * * @param string $text text to slugify * * @return unknown|string */ public static function slugify($text) { $slug = Urlizer::urlize($text); if (!$slug) { return $text; } return $slug; }