diff --git a/application/config/foreign_chars.php b/application/config/foreign_chars.php index 14b0d737..f714304d 100644 --- a/application/config/foreign_chars.php +++ b/application/config/foreign_chars.php @@ -10,54 +10,360 @@ $foreign_characters = array( '/ä|æ|ǽ/' => 'ae', '/ö|œ/' => 'oe', - '/ü/' => 'ue', - '/Ä/' => 'Ae', - '/Ü/' => 'Ue', - '/Ö/' => 'Oe', - '/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ/' => 'A', - '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª/' => 'a', + '/ü/' => 'u', + '/Ä/' => 'A', + '/Ü/' => 'U', + '/Ö/' => 'O', + '/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ|Α|Ά|Ả|Ạ|Ầ|Ẫ|Ẩ|Ậ|Ằ|Ắ|Ẵ|Ẳ|Ặ|А/' => 'A', + '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|α|ά|ả|ạ|ầ|ấ|ẫ|ẩ|ậ|ằ|ắ|ẵ|ẳ|ặ|а/' => 'a', + '/Б/' => 'B', + '/б/' => 'b', '/Ç|Ć|Ĉ|Ċ|Č/' => 'C', '/ç|ć|ĉ|ċ|č/' => 'c', - '/Ð|Ď|Đ/' => 'D', - '/ð|ď|đ/' => 'd', - '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě/' => 'E', - '/è|é|ê|ë|ē|ĕ|ė|ę|ě/' => 'e', - '/Ĝ|Ğ|Ġ|Ģ/' => 'G', - '/ĝ|ğ|ġ|ģ/' => 'g', + '/Д/' => 'D', + '/д/' => 'd', + '/Ð|Ď|Đ|Δ/' => 'Dj', + '/ð|ď|đ|δ/' => 'dj', + '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Ε|Έ|Ẽ|Ẻ|Ẹ|Ề|Ế|Ễ|Ể|Ệ|Е|Э/' => 'E', + '/è|é|ê|ë|ē|ĕ|ė|ę|ě|έ|ε|ẽ|ẻ|ẹ|ề|ế|ễ|ể|ệ|е|э/' => 'e', + '/Ф/' => 'F', + '/ф/' => 'f', + '/Ĝ|Ğ|Ġ|Ģ|Γ|Г|Ґ/' => 'G', + '/ĝ|ğ|ġ|ģ|γ|г|ґ/' => 'g', '/Ĥ|Ħ/' => 'H', '/ĥ|ħ/' => 'h', - '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ/' => 'I', - '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı/' => 'i', + '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|Η|Ή|Ί|Ι|Ϊ|Ỉ|Ị|И|Ы/' => 'I', + '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|η|ή|ί|ι|ϊ|ỉ|ị|и|ы|ї/' => 'i', '/Ĵ/' => 'J', '/ĵ/' => 'j', - '/Ķ/' => 'K', - '/ķ/' => 'k', - '/Ĺ|Ļ|Ľ|Ŀ|Ł/' => 'L', - '/ĺ|ļ|ľ|ŀ|ł/' => 'l', - '/Ñ|Ń|Ņ|Ň/' => 'N', - '/ñ|ń|ņ|ň|ʼn/' => 'n', - '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ/' => 'O', - '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º/' => 'o', - '/Ŕ|Ŗ|Ř/' => 'R', - '/ŕ|ŗ|ř/' => 'r', - '/Ś|Ŝ|Ş|Š/' => 'S', - '/ś|ŝ|ş|š|ſ/' => 's', - '/Ţ|Ť|Ŧ/' => 'T', - '/ţ|ť|ŧ/' => 't', - '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ/' => 'U', - '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ/' => 'u', - '/Ý|Ÿ|Ŷ/' => 'Y', - '/ý|ÿ|ŷ/' => 'y', + '/Ķ|Κ|К/' => 'K', + '/ķ|κ|к/' => 'k', + '/Ĺ|Ļ|Ľ|Ŀ|Ł|Λ|Л/' => 'L', + '/ĺ|ļ|ľ|ŀ|ł|λ|л/' => 'l', + '/М/' => 'M', + '/м/' => 'm', + '/Ñ|Ń|Ņ|Ň|Ν|Н/' => 'N', + '/ñ|ń|ņ|ň|ʼn|ν|н/' => 'n', + '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|Ο|Ό|Ω|Ώ|Ỏ|Ọ|Ồ|Ố|Ỗ|Ổ|Ộ|Ờ|Ớ|Ỡ|Ở|Ợ|О/' => 'O', + '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|ο|ό|ω|ώ|ỏ|ọ|ồ|ố|ỗ|ổ|ộ|ờ|ớ|ỡ|ở|ợ|о/' => 'o', + '/П/' => 'P', + '/п/' => 'p', + '/Ŕ|Ŗ|Ř|Ρ|Р/' => 'R', + '/ŕ|ŗ|ř|ρ|р/' => 'r', + '/Ś|Ŝ|Ş|Ș|Š|Σ|С/' => 'S', + '/ś|ŝ|ş|ș|š|ſ|σ|ς|с/' => 's', + '/Ț|Ţ|Ť|Ŧ|τ|Т/' => 'T', + '/ț|ţ|ť|ŧ|т/' => 't', + '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ|Ũ|Ủ|Ụ|Ừ|Ứ|Ữ|Ử|Ự|У/' => 'U', + '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|υ|ύ|ϋ|ủ|ụ|ừ|ứ|ữ|ử|ự|у/' => 'u', + '/Ý|Ÿ|Ŷ|Υ|Ύ|Ϋ|Ỳ|Ỹ|Ỷ|Ỵ|Й/' => 'Y', + '/ý|ÿ|ŷ|ỳ|ỹ|ỷ|ỵ|й/' => 'y', + '/В/' => 'V', + '/в/' => 'v', '/Ŵ/' => 'W', '/ŵ/' => 'w', - '/Ź|Ż|Ž/' => 'Z', - '/ź|ż|ž/' => 'z', + '/Ź|Ż|Ž|Ζ|З/' => 'Z', + '/ź|ż|ž|ζ|з/' => 'z', '/Æ|Ǽ/' => 'AE', - '/ß/'=> 'ss', + '/ß/' => 'ss', '/IJ/' => 'IJ', '/ij/' => 'ij', '/Œ/' => 'OE', - '/ƒ/' => 'f' + '/ƒ/' => 'f', + '/ξ/' => 'ks', + '/π/' => 'p', + '/β/' => 'v', + '/μ/' => 'm', + '/ψ/' => 'ps', + '/Ё/' => 'Yo', + '/ё/' => 'yo', + '/Є/' => 'Ye', + '/є/' => 'ye', + '/Ї/' => 'Yi', + '/Ж/' => 'Zh', + '/ж/' => 'zh', + '/Х/' => 'Kh', + '/х/' => 'kh', + '/Ц/' => 'Ts', + '/ц/' => 'ts', + '/Ч/' => 'Ch', + '/ч/' => 'ch', + '/Ш/' => 'Sh', + '/ш/' => 'sh', + '/Щ/' => 'Shch', + '/щ/' => 'shch', + '/Ъ|ъ|Ь|ь/' => '', + '/Ю/' => 'Yu', + '/ю/' => 'yu', + '/Я/' => 'Ya', + '/я/' => 'ya' +); + +// str_replace is faster than preg_replace, so if you need extra speed comment out the bit above +$transliteration = array( + 'ä' => 'ae', + 'æ' => 'ae', + 'ǽ' => 'ae', + 'ö' => 'o', + 'œ' => 'oe', + 'ü' => 'u', + 'Ä' => 'Ae', + 'Ü' => 'U', + 'Ö' => 'O', + 'À' => 'A', + 'Á' => 'A', + 'Â' => 'A', + 'Ã' => 'A', + 'Å' => 'A', + 'Ǻ' => 'A', + 'Ā' => 'A', + 'Å' => 'A', + 'Ă' => 'A', + 'Ą' => 'A', + 'Ǎ' => 'A', + 'Ä' => 'Ae', + 'à' => 'a', + 'á' => 'a', + 'â' => 'a', + 'ã' => 'a', + 'å' => 'a', + 'ǻ' => 'a', + 'ā' => 'a', + 'ă' => 'a', + 'ą' => 'a', + 'ǎ' => 'a', + 'ª' => 'a', + 'Ç' => 'C', + 'Ć' => 'C', + 'Ĉ' => 'C', + 'Ċ' => 'C', + 'Č' => 'C', + 'ç' => 'c', + 'ć' => 'c', + 'ĉ' => 'c', + 'ċ' => 'c', + 'č' => 'c', + 'Ð' => 'D', + 'Ď' => 'D', + 'Đ' => 'D', + 'ð' => 'd', + 'ď' => 'd', + 'đ' => 'd', + 'È' => 'E', + 'É' => 'E', + 'Ê' => 'E', + 'Ë' => 'E', + 'Ē' => 'E', + 'Ĕ' => 'E', + 'Ė' => 'E', + 'Ę' => 'E', + 'Ě' => 'E', + 'Ë' => 'E', + 'è' => 'e', + 'é' => 'e', + 'ê' => 'e', + 'ë' => 'e', + 'ē' => 'e', + 'ĕ' => 'e', + 'ė' => 'e', + 'ę' => 'e', + 'ě' => 'e', + 'Ĝ' => 'G', + 'Ğ' => 'G', + 'Ġ' => 'G', + 'Ģ' => 'G', + 'Ґ' => 'G', + 'ĝ' => 'g', + 'ğ' => 'g', + 'ġ' => 'g', + 'ģ' => 'g', + 'ґ' => 'g', + 'Ĥ' => 'H', + 'Ħ' => 'H', + 'ĥ' => 'h', + 'ħ' => 'h', + 'І' => 'I', + 'Ì' => 'I', + 'Í' => 'I', + 'Î' => 'I', + 'Ї' => 'Yi', + 'Ï' => 'I', + 'Ĩ' => 'I', + 'Ī' => 'I', + 'Ĭ' => 'I', + 'Ǐ' => 'I', + 'Į' => 'I', + 'İ' => 'I', + 'і' => 'i', + 'ì' => 'i', + 'í' => 'i', + 'î' => 'i', + 'ï' => 'i', + 'ї' => 'yi', + 'ĩ' => 'i', + 'ī' => 'i', + 'ĭ' => 'i', + 'ǐ' => 'i', + 'į' => 'i', + 'ı' => 'i', + 'Ĵ' => 'J', + 'ĵ' => 'j', + 'Ķ' => 'K', + 'ķ' => 'k', + 'Ĺ' => 'L', + 'Ļ' => 'L', + 'Ľ' => 'L', + 'Ŀ' => 'L', + 'Ł' => 'L', + 'ĺ' => 'l', + 'ļ' => 'l', + 'ľ' => 'l', + 'ŀ' => 'l', + 'ł' => 'l', + 'Ñ' => 'N', + 'Ń' => 'N', + 'Ņ' => 'N', + 'Ň' => 'N', + 'ñ' => 'n', + 'ń' => 'n', + 'ņ' => 'n', + 'ň' => 'n', + 'ʼn' => 'n', + 'Ò' => 'O', + 'Ó' => 'O', + 'Ô' => 'O', + 'Õ' => 'O', + 'Ō' => 'O', + 'Ŏ' => 'O', + 'Ǒ' => 'O', + 'Ő' => 'O', + 'Ơ' => 'O', + 'Ø' => 'O', + 'Ǿ' => 'O', + 'Ö' => 'O', + 'ò' => 'o', + 'ó' => 'o', + 'ô' => 'o', + 'õ' => 'o', + 'ō' => 'o', + 'ŏ' => 'o', + 'ǒ' => 'o', + 'ő' => 'o', + 'ơ' => 'o', + 'ø' => 'o', + 'ǿ' => 'o', + 'º' => 'o', + 'Ŕ' => 'R', + 'Ŗ' => 'R', + 'Ř' => 'R', + 'ŕ' => 'r', + 'ŗ' => 'r', + 'ř' => 'r', + 'Ś' => 'S', + 'Ŝ' => 'S', + 'Ş' => 'S', + 'Ș' => 'S', + 'Š' => 'S', + 'ẞ' => 'SS', + 'ś' => 's', + 'ŝ' => 's', + 'ş' => 's', + 'ș' => 's', + 'š' => 's', + 'ſ' => 's', + 'Ţ' => 'T', + 'Ț' => 'T', + 'Ť' => 'T', + 'Ŧ' => 'T', + 'ţ' => 't', + 'ț' => 't', + 'ť' => 't', + 'ŧ' => 't', + 'Ù' => 'U', + 'Ú' => 'U', + 'Û' => 'U', + 'Ũ' => 'U', + 'Ū' => 'U', + 'Ŭ' => 'U', + 'Ů' => 'U', + 'Ű' => 'U', + 'Ų' => 'U', + 'Ư' => 'U', + 'Ǔ' => 'U', + 'Ǖ' => 'U', + 'Ǘ' => 'U', + 'Ǚ' => 'U', + 'Ǜ' => 'U', + 'Ü' => 'U', + 'ù' => 'u', + 'ú' => 'u', + 'û' => 'u', + 'ũ' => 'u', + 'ū' => 'u', + 'ŭ' => 'u', + 'ů' => 'u', + 'ű' => 'u', + 'ų' => 'u', + 'ư' => 'u', + 'ǔ' => 'u', + 'ǖ' => 'u', + 'ǘ' => 'u', + 'ǚ' => 'u', + 'ǜ' => 'u', + 'Ý' => 'Y', + 'Ÿ' => 'Y', + 'Ŷ' => 'Y', + 'ý' => 'y', + 'ÿ' => 'y', + 'ŷ' => 'y', + 'Ŵ' => 'W', + 'ŵ' => 'w', + 'Ź' => 'Z', + 'Ż' => 'Z', + 'Ž' => 'Z', + 'ź' => 'z', + 'ż' => 'z', + 'ž' => 'z', + 'Æ' => 'AE', + 'Ǽ' => 'AE', + 'ß' => 'ss', + 'IJ' => 'IJ', + 'ij' => 'ij', + 'Œ' => 'OE', + 'ƒ' => 'f', + 'Þ' => 'TH', + 'þ' => 'th', + 'Є' => 'Ye', + 'є' => 'ye', + 'ß' => 'ss', + 'IJ' => 'IJ', + 'ij' => 'ij', + 'Œ' => 'OE', + 'ƒ' => 'f', + 'ξ' => 'ks', + 'π' => 'p', + 'β' => 'v', + 'μ' => 'm', + 'ψ' => 'ps', + 'Ё' => 'Yo', + 'ё' => 'yo', + 'Є' => 'Ye', + 'є' => 'ye', + 'Ї' => 'Yi', + 'Ж' => 'Zh', + 'ж' => 'zh', + 'Х' => 'Kh', + 'х' => 'kh', + 'Ц' => 'Ts', + 'ц' => 'ts', + 'Ч' => 'Ch', + 'ч' => 'ch', + 'Ш' => 'Sh', + 'ш' => 'sh', + 'Щ' => 'Shch', + 'щ' => 'shch', + 'Ŵ' => 'W', + 'ŵ' => 'w', ); /* End of file foreign_chars.php */ diff --git a/application/datamapper/tools.php b/application/datamapper/tools.php index d8e8fef7..a6bff733 100644 --- a/application/datamapper/tools.php +++ b/application/datamapper/tools.php @@ -4,8 +4,11 @@ class tools { public function rule_stub($object, $field, $param = '') { + $CI = & get_instance(); + $CI->load->helper('inflector'); $object->$field = strtolower(str_replace(" ", "_", $object->$field)); - $object->$field = preg_replace('/[^a-z0-9_]/i', '', $object->$field); + $object->$field = slugify($object->$field); + $object->$field = preg_replace('/[^a-z-0-9_]/i', '', $object->$field); } public function rule_checkbox($object, $field, $param = '') @@ -15,11 +18,15 @@ public function rule_checkbox($object, $field, $param = '') public function stub($input) { + $CI = & get_instance(); + $CI->load->helper('inflector'); + log_message('info', print_r($input, true)); if(isset($input->stub)) $val = $input->stub; else if(isset($input->to_stub)) $val = $input->to_stub; else $val = $input->name; $val = strtolower(str_replace(" ", "_", trim($val))); - return preg_replace('/[^a-z0-9_]/i', '', $val); + $val = slugify($val); + return preg_replace('/[^a-z-0-9_]/i', '', $val); } public function logged_id() diff --git a/application/helpers/inflector_helper.php b/application/helpers/inflector_helper.php index 25d093ef..f261c30d 100644 --- a/application/helpers/inflector_helper.php +++ b/application/helpers/inflector_helper.php @@ -232,5 +232,49 @@ function humanize($str) } } +/** + * Slugify + * + * Takes a string and slugifies it. E.g Старый падуб -> Stariy-padub + * + * @access public + * @param string + * @author pushrbx + * @return str + */ +if(!function_exists('slugify')) +{ + function slugify($string, $replacement = '-') + { + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) + { + include(APPPATH.'config'.DS.ENVIRONMENT.DS.'foreign_chars.php'); + } + elseif (is_file(APPPATH.'config'.DS.'foreign_chars.php')) + { + include(APPPATH.'config'.DS.'foreign_chars.php'); + } + + $string = html_entity_decode($string, ENT_QUOTES, 'UTF-8'); + $quotedReplacement = preg_quote($replacement, '/'); + + $map = array( + '/[^\s\p{Zs}\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]/mu' => ' ', + '/[\s\p{Zs}]+/mu' => $replacement, + sprintf('/^[%s]+|[%s]+$/', $quotedReplacement, $quotedReplacement) => '', + ); + + $string = preg_replace(array_keys($map), array_values($map), $string); + + if (isset($transliteration)) + $string = str_replace(array_keys($transliteration), array_values($transliteration), $string); + + if (isset($foreign_characters)) + return preg_replace(array_keys($foreign_characters), array_values($foreign_characters), $string); + + return strtolower($string); + } +} + /* End of file inflector_helper.php */ /* Location: ./application/helpers/inflector_helper.php */ \ No newline at end of file diff --git a/application/models/comic.php b/application/models/comic.php index 1f9df0b2..ff60ee48 100644 --- a/application/models/comic.php +++ b/application/models/comic.php @@ -17,8 +17,9 @@ class Comic extends DataMapper 'placeholder' => 'required', ), 'stub' => array( - 'rules' => array('required', 'stub', 'unique', 'max_length' => 256), - 'label' => 'Stub' + 'rules' => array('stub', 'unique', 'max_length' => 256), + 'label' => 'Stub', + 'type' => 'input' ), 'uniqid' => array( 'rules' => array('required', 'max_length' => 256), @@ -151,6 +152,32 @@ function help_lang() $this->validation['customchapter']['help'] = _('Replace the default chapter title with a custom format. Example: "{num}{ord} Stage" returns "2nd Stage"'); } + /** + * This function sets the correct slug for the comic when the user specifies + * a name with non italic letters. + * + * @author pushrbx + * @return void + */ + private function fix_stub_for_foreign_name($input_name) + { + // if (!isset($input_name)) + // return; + + // if ($this->stub == '_' || preg_match('/^[-\' \p{L}]+$/u', $input_name) === 1) + // { + // $CI = &get_instance(); + // $CI->load->helper('inflector'); + // if ($input_name != "") + // $this->stub = slugify($input_name); + + // if (str_replace(" ", "", $this->stub) == "") + // { + // $this->stub = $this->uniqid; + // } + // } + } + /** * Overwrite of the get() function to add filters to the search. @@ -326,6 +353,11 @@ public function add($data = array()) $this->to_stub = $data['name']; // Uniqid to prevent directory clash $this->uniqid = uniqid(); + + // in case the user specified a stub + if (array_key_exists('stub', $data) && isset($data['stub']) && $data['stub'] != "") + $this->to_stub = $data['stub']; + // stub() checks for to_stub and makes a stub. $this->stub = $this->stub(); @@ -358,22 +390,27 @@ public function add($data = array()) */ public function remove() { + $result = array(); // Remove the directory through function if (!$this->remove_comic_dir()) { log_message('error', 'remove_comic: failed to delete dir'); - return false; + $result[] = false; } + else + $result[] = true; // Remove database entry through function if (!$this->remove_comic_db()) { log_message('error', 'remove_comic: failed to delete database entry'); - return false; + $result[] = false; } + else + $result[] = true; - return true; + return (bool)array_product($result); } @@ -416,6 +453,7 @@ public function update_comic_db($data = array()) // always set the editor name $this->editor = $this->logged_id(); + $input_stub = $data["stub"]; // Unset sensible variables unset($data["creator"]); @@ -451,6 +489,12 @@ public function update_comic_db($data = array()) $this->stub = $this->stub(); } + // stub changed by user + if ($input_stub != "" && ($this->stub != $input_stub || $old_stub != $input_stub)) + { + $this->stub = $input_stub; + $this->stub = $this->stub(); + } // Make so there's no intersecting stubs, and make a stub with a number in case of duplicates // In case this chapter already has a stub and it wasn't changed, don't change it! @@ -480,7 +524,6 @@ public function update_comic_db($data = array()) } } - // This is necessary to make the checkbox work. /** * @todo make the checkbox work consistently across the whole framework diff --git a/index.php b/index.php index 0f678438..58f58463 100644 --- a/index.php +++ b/index.php @@ -19,6 +19,7 @@ * */ define('ENVIRONMENT', 'production'); + define('DS', DIRECTORY_SEPARATOR); /* *--------------------------------------------------------------- * ERROR REPORTING