private function slugify($slug) { if ($this->translit) { return Inflector::slug(TransliteratorHelper::process($slug), '-', true); } else { return $this->slug($slug, '-', true); } }
/** * @inheritdoc */ public function rules() { return [[['id', 'created_at', 'updated_at', 'created_by', 'updated_by', 'lock'], 'integer'], [['title'], 'string', 'max' => 1024], [['alias'], 'filter', 'filter' => 'trim'], [['alias'], 'filter', 'filter' => function ($value) { if (empty($value)) { return Inflector::slug(TransliteratorHelper::process($this->title)); } else { return Inflector::slug($value); } }], [['alias'], 'unique'], [['alias'], 'required', 'enableClientValidation' => false], [['alias', 'note'], 'string', 'max' => 255]]; }
/** * @inheritdoc */ public function rules() { return [[['title', 'status'], 'required'], [['status', 'created_at', 'updated_at', 'created_by', 'updated_by', 'hits', 'lock'], 'integer'], [['title'], 'string', 'max' => 100], [['group'], 'filter', 'filter' => function ($value) { // если во вьюхе используется select2, отфильтровываем значение из массива [0 => 'значение'] -> 'значение' return is_array($value) ? reset($value) : $value; }], [['alias', 'group', 'metakey'], 'string', 'max' => 255], [['metadesc'], 'string', 'max' => 2048], [['alias'], 'filter', 'filter' => 'trim'], [['alias'], 'filter', 'filter' => function ($value) { if (empty($value)) { return Inflector::slug(TransliteratorHelper::process($this->title)); } else { return Inflector::slug($value); } }], [['alias'], 'unique'], [['alias'], 'required', 'enableClientValidation' => false]]; }
/** * @inheritdoc */ public function rules() { return [[['title', 'detail_text', 'status'], 'required'], [['preview_text', 'detail_text'], 'string'], [['detail_text'], 'filter', 'filter' => 'yii\\helpers\\HtmlPurifier::process'], [['parent_id', 'created_at', 'updated_at', 'status', 'created_by', 'updated_by', 'lft', 'rgt', 'level', 'ordering', 'hits', 'lock'], 'integer'], [['title'], 'string', 'max' => 1024], [['title'], 'filter', 'filter' => 'strip_tags'], [['alias', 'metakey'], 'string', 'max' => 255], [['metadesc'], 'string', 'max' => 2048], [['alias'], 'filter', 'filter' => 'trim'], [['alias'], 'filter', 'filter' => function ($value) { if (empty($value)) { return Inflector::slug(TransliteratorHelper::process($this->title)); } else { return Inflector::slug($value); } }], [['alias'], 'unique', 'filter' => function ($query) { /** @var $query \yii\db\ActiveQuery */ if ($parent = self::findOne($this->parent_id)) { $query->andWhere('lft>=:lft AND rgt<=:rgt AND level=:level', ['lft' => $parent->lft, 'rgt' => $parent->rgt, 'level' => $parent->level + 1]); } }], [['alias'], 'string', 'max' => 250], [['alias'], 'required', 'enableClientValidation' => false], [['tags', 'versionNote', 'lock'], 'safe'], [['ordering'], 'filter', 'filter' => 'intVal']]; }
/** * @inheritdoc */ public function rules() { return [[['language', 'title', 'status'], 'required'], [['status', 'created_at', 'updated_at', 'created_by', 'updated_by', 'hits', 'lock'], 'integer'], [['language'], 'string', 'max' => 7], [['title'], 'string', 'max' => 100], [['alias', 'group', 'metakey'], 'string', 'max' => 255], [['metadesc'], 'string', 'max' => 2048], [['alias'], 'filter', 'filter' => 'trim'], [['alias'], 'filter', 'filter' => function ($value) { if (empty($value)) { return Inflector::slug(TransliteratorHelper::process($this->title)); } else { return Inflector::slug($value); } }], [['alias'], 'unique', 'filter' => function ($query) { /** @var $query \yii\db\ActiveQuery */ $query->andWhere(['language' => $this->language]); }], [['alias'], 'required', 'enableClientValidation' => false], [['translation_id'], 'unique', 'filter' => function ($query) { /** @var $query \yii\db\ActiveQuery */ $query->andWhere(['language' => $this->language]); }, 'message' => Yii::t('gromver.platform', 'Локализация ({language}) для записи (ID:{id}) уже существует.', ['language' => $this->language, 'id' => $this->translation_id])]]; }
/** * @param string $title Text to transliteration * * @return string */ public function genSlug() { $slug = $this->name; $slug = trim($slug); $slug = str_replace(["я", "Я"], "ya", $slug); $slug = str_replace(["ю", "Ю"], "yu", $slug); $slug = str_replace(["ш", "Ш"], "sh", $slug); $slug = str_replace(["щ", "Щ"], "sch", $slug); $slug = str_replace(["ж", "Ж"], "zh", $slug); $slug = str_replace(["ч", "Ч"], "ch", $slug); $slug = TransliteratorHelper::process($slug, '-', 'en'); $slug = str_replace(["ʹ", '?', '.', ',', '@', '!', '#', '$', '%', '^', '&', '*', '(', ')', '{', '}', '[', ']', '+', ':', ';', '"', "'", '`', '~', '\\', '/', '|', '№'], "", $slug); $slug = str_replace(" ", "-", $slug); $slug = strtolower($slug); return $slug; }
/** * @inheritdoc */ public function rules() { return [[['language', 'title', 'detail_text', 'status'], 'required'], [['preview_text', 'detail_text'], 'string'], [['parent_id', 'created_at', 'updated_at', 'status', 'created_by', 'updated_by', 'lft', 'rgt', 'level', 'ordering', 'hits', 'lock'], 'integer'], [['language'], 'string', 'max' => 7], [['title'], 'string', 'max' => 1024], [['alias', 'metakey'], 'string', 'max' => 255], [['metadesc'], 'string', 'max' => 2048], [['alias'], 'filter', 'filter' => 'trim'], [['alias'], 'filter', 'filter' => function ($value) { if (empty($value)) { return Inflector::slug(TransliteratorHelper::process($this->title)); } else { return Inflector::slug($value); } }], [['alias'], 'unique', 'filter' => function ($query) { /** @var $query \yii\db\ActiveQuery */ if ($parent = self::findOne($this->parent_id)) { $query->andWhere('lft>=:lft AND rgt<=:rgt AND level=:level AND language=:language', ['lft' => $parent->lft, 'rgt' => $parent->rgt, 'level' => $parent->level + 1, 'language' => $this->language]); } }], [['alias'], 'string', 'max' => 250], [['alias'], 'required', 'enableClientValidation' => false], [['translation_id'], 'unique', 'filter' => function ($query) { /** @var $query \yii\db\ActiveQuery */ $query->andWhere(['language' => $this->language]); }, 'message' => Yii::t('gromver.platform', 'Локализация ({language}) для записи (ID:{id}) уже существует.', ['language' => $this->language, 'id' => $this->translation_id])], [['tags', 'versionNote', 'lock'], 'safe'], [['ordering'], 'filter', 'filter' => 'intVal']]; }
/** * @inheritdoc */ public function rules() { return [[['parent_id', 'created_at', 'updated_at', 'status', 'created_by', 'updated_by', 'lft', 'rgt', 'level', 'ordering', 'hits', 'lock'], 'integer'], [['preview_text', 'detail_text'], 'string'], [['title', 'preview_image', 'detail_image'], 'string', 'max' => 1024], [['alias', 'metakey'], 'string', 'max' => 255], [['path', 'metadesc'], 'string', 'max' => 2048], [['published_at'], 'date', 'format' => 'dd.MM.yyyy HH:mm', 'timestampAttribute' => 'published_at', 'when' => function () { return is_string($this->published_at); }], [['published_at'], 'integer', 'enableClientValidation' => false], [['language'], 'required'], [['language'], 'string', 'max' => 7], [['parent_id'], 'exist', 'targetAttribute' => 'id'], [['parent_id'], 'compare', 'compareAttribute' => 'id', 'operator' => '!='], [['alias'], 'filter', 'filter' => 'trim'], [['alias'], 'filter', 'filter' => function ($value) { if (empty($value)) { return Inflector::slug(TransliteratorHelper::process($this->title)); } else { return Inflector::slug($value); } }], [['alias'], 'unique', 'filter' => function ($query) { /** @var $query \yii\db\ActiveQuery */ if ($parent = self::findOne($this->parent_id)) { $query->andWhere('lft>=:lft AND rgt<=:rgt AND level=:level AND language=:language', ['lft' => $parent->lft, 'rgt' => $parent->rgt, 'level' => $parent->level + 1, 'language' => $this->language]); } }], [['alias'], 'string', 'max' => 250], [['alias'], 'required', 'enableClientValidation' => false], [['translation_id'], 'unique', 'filter' => function ($query) { /** @var $query \yii\db\ActiveQuery */ $query->andWhere(['language' => $this->language]); }, 'message' => Yii::t('gromver.platform', 'Localization ({language}) for item (ID: {id}) already exists.', ['language' => $this->language, 'id' => $this->translation_id])], [['title', 'detail_text', 'status'], 'required'], [['tags', 'versionNote'], 'safe']]; }
/** * @inheritdoc */ protected function getValue($event) { $isNewSlug = true; if ($this->attribute !== null) { $attributes = (array) $this->attribute; /* @var $owner BaseActiveRecord */ $owner = $this->owner; if (!empty($owner->{$this->slugAttribute})) { $isNewSlug = false; if (!$this->immutable) { foreach ($attributes as $attribute) { if ($owner->isAttributeChanged($attribute)) { $isNewSlug = true; break; } } } } if ($isNewSlug) { $slugParts = []; foreach ($attributes as $attribute) { $slugParts[] = $owner->{$attribute}; } $transliteratedSlug = TransliteratorHelper::process(implode('-', $slugParts)); $slug = Inflector::slug($transliteratedSlug); } else { $slug = $owner->{$this->slugAttribute}; } } else { $slug = parent::getValue($event); } if ($this->ensureUnique && $isNewSlug) { $baseSlug = $slug; $iteration = 0; while (!$this->validateSlug($slug)) { $iteration++; $slug = $this->generateUniqueSlug($baseSlug, $iteration); } } return $slug; }
/** * @inheritdoc */ public function rules() { return [[['status', 'category_id', 'title', 'detail_text', 'language'], 'required'], [['category_id', 'created_at', 'updated_at', 'status', 'created_by', 'updated_by', 'ordering', 'hits', 'lock'], 'integer'], [['preview_text', 'detail_text'], 'string'], [['language'], 'string', 'max' => 7], [['title', 'preview_image', 'detail_image'], 'string', 'max' => 1024], [['alias', 'metakey'], 'string', 'max' => 255], [['metadesc'], 'string', 'max' => 2048], [['published_at'], 'date', 'format' => 'dd.MM.yyyy HH:mm', 'timestampAttribute' => 'published_at', 'when' => function () { return is_string($this->published_at); }], [['published_at'], 'integer', 'enableClientValidation' => false], [['category_id'], 'exist', 'targetClass' => Category::className(), 'targetAttribute' => 'id', 'filter' => function ($query) { /** @var $query \gromver\platform\common\models\CategoryQuery */ $query->noRoots(); }], [['alias'], 'filter', 'filter' => 'trim'], [['alias'], 'filter', 'filter' => function ($value) { if (empty($value)) { return Inflector::slug(TransliteratorHelper::process($this->title)); } else { return Inflector::slug($value); } }], [['alias'], 'unique', 'filter' => function ($query) { /** @var $query \yii\db\ActiveQuery */ $query->andWhere(['category_id' => $this->category_id, 'language' => $this->language]); }, 'message' => '{attribute} - Another article from this category has the same alias'], [['translation_id'], 'unique', 'filter' => function ($query) { /** @var $query \yii\db\ActiveQuery */ $query->andWhere(['language' => $this->language]); }, 'message' => Yii::t('gromver.platform', 'Локализация ({language}) для записи (ID:{id}) уже существует.', ['language' => $this->language, 'id' => $this->translation_id])], [['tags', 'versionNote'], 'safe']]; }
public function translitToString($string) { $string = $this->replaceSpaces(TransliteratorHelper::process($string, '', 'en')); $string = preg_replace('/[^a-zA-Z0-9=\\s—–-]+/u', '', $string); return $string; }
private function normalize($str) { return TransliteratorHelper::process($str); }
/** * @inheritdoc */ public function rules() { return [[['menu_type_id', 'parent_id', 'status', 'link_type', 'secure', 'created_at', 'updated_at', 'created_by', 'updated_by', 'lft', 'rgt', 'level', 'ordering', 'hits', 'lock'], 'integer'], [['menu_type_id'], 'required'], [['menu_type_id'], 'exist', 'targetAttribute' => 'id', 'targetClass' => MenuType::className()], [['language'], 'required'], [['language'], 'string', 'max' => 7], [['language'], function ($attribute) { if (($parent = self::findOne($this->parent_id)) && !$parent->isRoot() && $parent->language != $this->language) { $this->addError($attribute, Yii::t('gromver.platform', 'Language has to match with the parental.')); } }], [['title', 'link', 'layout_path'], 'string', 'max' => 1024], [['alias', 'note', 'metakey'], 'string', 'max' => 255], [['metadesc'], 'string', 'max' => 2048], [['access_rule', 'robots'], 'string', 'max' => 50], [['parent_id'], 'exist', 'targetAttribute' => 'id'], [['parent_id'], 'compare', 'compareAttribute' => 'id', 'operator' => '!='], [['parent_id'], function ($attribute) { if (($parent = self::findOne($this->parent_id)) && !$parent->isRoot() && $parent->menu_type_id != $this->menu_type_id) { $this->addError($attribute, Yii::t('gromver.platform', 'Parental point of the menu doesn\'t correspond to the chosen menu type.')); } }], [['status'], function ($attribute) { if ($this->status == self::STATUS_MAIN_PAGE && $this->link_type == self::LINK_HREF) { $this->addError($attribute, Yii::t('gromver.platform', 'Alias of the menu item can\'t be a main page.')); } }], [['alias'], 'filter', 'filter' => 'trim'], [['alias'], 'filter', 'filter' => function ($value) { if (empty($value)) { return Inflector::slug(TransliteratorHelper::process($this->title)); } else { return Inflector::slug($value); } }], [['alias'], 'unique', 'filter' => function ($query) { /** @var $query \yii\db\ActiveQuery */ if ($parent = self::findOne($this->parent_id)) { $query->andWhere('lft>=:lft AND rgt<=:rgt AND level=:level AND language=:language', ['lft' => $parent->lft, 'rgt' => $parent->rgt, 'level' => $parent->level + 1, 'language' => $this->language]); } }], [['alias'], 'string', 'max' => 255], [['alias'], 'required', 'enableClientValidation' => false], [['translation_id'], 'unique', 'filter' => function ($query) { /** @var $query \yii\db\ActiveQuery */ $query->andWhere(['language' => $this->language]); }, 'message' => Yii::t('gromver.platform', 'Localization ({language}) for item (ID: {id}) already exists.', ['language' => $this->language, 'id' => $this->translation_id])], [['title', 'link', 'status'], 'required']]; }
/** * @inheritdoc */ public function rules() { return [[['menu_type_id', 'parent_id', 'status', 'link_type', 'link_weight', 'secure', 'created_at', 'updated_at', 'created_by', 'updated_by', 'lft', 'rgt', 'level', 'ordering', 'hits', 'lock'], 'integer'], [['menu_type_id'], 'required'], [['menu_type_id'], 'exist', 'targetAttribute' => 'id', 'targetClass' => MenuType::className()], [['layout_path'], 'filter', 'filter' => function ($value) { // если во вьюхе используется select2, отфильтровываем значение из массива [0 => 'значение'] -> 'значение' return is_array($value) ? reset($value) : $value; }], [['title', 'link', 'layout_path', 'metaimg'], 'string', 'max' => 1024], [['alias', 'note', 'metakey'], 'string', 'max' => 255], [['metadesc'], 'string', 'max' => 2048], [['access_rule', 'robots'], 'string', 'max' => 50], [['parent_id'], function ($attribute) { if (($parent = self::findOne($this->parent_id)) && !$parent->isRoot() && $parent->menu_type_id != $this->menu_type_id) { $this->addError($attribute, Yii::t('gromver.platform', 'Parental point of the menu doesn\'t correspond to the chosen menu type.')); } }], [['status'], function ($attribute) { if ($this->status == self::STATUS_MAIN_PAGE && $this->link_type == self::LINK_HREF) { $this->addError($attribute, Yii::t('gromver.platform', 'Alias of the menu item can\'t be a main page.')); } }], [['alias'], 'filter', 'filter' => 'trim'], [['alias'], 'filter', 'filter' => function ($value) { if (empty($value)) { return Inflector::slug(TransliteratorHelper::process($this->title)); } else { return Inflector::slug($value); } }], [['alias'], 'unique', 'filter' => function ($query) { /** @var $query \yii\db\ActiveQuery */ if ($parent = self::findOne($this->parent_id)) { $query->andWhere('lft>=:lft AND rgt<=:rgt AND level=:level', ['lft' => $parent->lft, 'rgt' => $parent->rgt, 'level' => $parent->level + 1]); } }], [['alias'], 'string', 'max' => 255], [['alias'], 'required', 'enableClientValidation' => false], [['title', 'link', 'status'], 'required'], [['ordering'], 'filter', 'filter' => 'intVal']]; }
public function beforeValidate() { if (empty($this->alias)) { $this->alias = Inflector::slug(TransliteratorHelper::process($this->title), '-'); } return parent::beforeValidate(); }
public function translit($string) { return TransliteratorHelper::process($string, '_', 'en'); }