本文整理汇总了PHP中CMS::translit方法的典型用法代码示例。如果您正苦于以下问题:PHP CMS::translit方法的具体用法?PHP CMS::translit怎么用?PHP CMS::translit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMS
的用法示例。
在下文中一共展示了CMS::translit方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: duplicateProduct
/**
* Duplicate one product and return model
*
* @param ShopProduct $model
* @return ShopProduct
*/
public function duplicateProduct(ShopProduct $model)
{
$product = new ShopProduct(null);
// Add "null" by PANIX
$product->attributes = $model->attributes;
$behaviors = $model->behaviors();
foreach ($behaviors['TranslateBehavior']['translateAttributes'] as $attr) {
$product->{$attr} = $model->{$attr};
}
$product->name .= $this->getSuffix();
$product->seo_alias .= CMS::translit($this->getSuffix()) . '-' . time();
if ($product->validate()) {
if ($product->save(false, false)) {
foreach ($this->duplicate as $feature) {
$method_name = 'copy' . ucfirst($feature);
if (method_exists($this, $method_name)) {
$this->{$method_name}($model, $product);
}
}
return $product;
} else {
die(__FUNCTION__ . ': Error save');
return false;
}
} else {
// print_r($product->getErrors());die;
}
}
示例2: alert
public function alert($type, $text, $close = true)
{
$id = 'alert' . md5($type . CMS::translit($text));
if (!isset($_COOKIE[$id])) {
$str = implode(', ', $this->types);
if (in_array($type, $this->types)) {
$this->render('_' . __FUNCTION__, array('type' => $type, 'message' => $text, 'close' => $close));
} else {
throw new CHttpException(403, Yii::t('app', 'ERROR_TPL_' . strtoupper(__FUNCTION__), array('{tpl}' => __FUNCTION__, '{type}' => $type, '{types}' => CHtml::encode($str))));
}
}
}
示例3: validateAttribute
protected function validateAttribute($object, $attribute)
{
$config = Yii::app()->settings->get('core');
if (isset($object->translateAttributes)) {
if (in_array($this->translitAttribute, $object->translateAttributes)) {
$p = array();
foreach ($object->translateAttributes as $param) {
$p[$param] = $param;
}
$attr = $p[$this->translitAttribute];
}
} else {
$attr = $this->translitAttribute;
if (!$object->hasAttribute($attr)) {
throw new CException(Yii::t('yii', 'Active record "{class}" is trying to select an invalid column "{column}". Note, the column must exist in the table or be an expression with alias.', array('{class}' => get_class($object), '{column}' => $attr)));
}
}
if ($config['translate_object_url']) {
Yii::import('mod.core.components.yandexTranslate');
$t = new yandexTranslate();
$tr = $t->translitUrl(array('ru', 'en'), $object->getAttribute($attr));
//die($tr);
} else {
$tr = CMS::translit($object->getAttribute($attribute));
}
if ($object->isNewRecord) {
$model = $object::model()->find(array('condition' => '`t`.`' . $attribute . '`=:alias', 'params' => array(':alias' => $tr)));
} else {
$model = $object::model()->find(array('condition' => '`t`.`' . $attribute . '`=:alias AND `t`.`id`!=' . $object->id, 'params' => array(':alias' => $tr)));
}
if (isset($model)) {
$this->addError($object, $attribute, Yii::t('app', 'ERROR_DUPLICATE_URL', array('{url}' => $tr)));
} else {
$object->{$attribute} = $tr;
}
}
示例4: importCategories
/**
* @param $data
* @param null|ShopCategory $parent
*/
public function importCategories($data, $parent = null)
{
foreach ($data->{"Группа"} as $category) {
// Find category by external id
$model = C1ExternalFinder::getObject(C1ExternalFinder::OBJECT_TYPE_CATEGORY, $category->{"Ид"});
if (!$model) {
$model = new ShopCategory();
$model->name = $category->{"Наименование"};
$model->seo_alias = CMS::translit($category->{"Наименование"});
$model->appendTo($this->getRootCategory());
$this->createExternalId(C1ExternalFinder::OBJECT_TYPE_CATEGORY, $model->id, $category->{"Ид"});
}
if ($parent === null) {
$model->moveAsLast($this->getRootCategory());
} else {
$model->moveAsLast($parent);
}
$model->saveNode();
// Process subcategories
if (isset($category->{"Группы"})) {
$this->importCategories($category->{"Группы"}, $model);
}
}
}
示例5: change
public function change($id, $data, $item)
{
if (is_object($item)) {
$item->id = $id;
}
$file = $_FILES['value'];
$name = trim($file['name']);
$tmp_name = trim($file['tmp_name']);
if ($tmp_name != '') {
$dir = "./" . Core::option('files_name') . "/vars/{$id}";
CMS::mkdirs($dir, 0775);
foreach (IO_FS::Dir($dir) as $f) {
@IO_FS::rm($f->path);
}
$name = CMS::translit(mb_strtolower($name));
$name = preg_replace('{\\s+}', '_', $name);
$name = trim(preg_replace('{[^a-z0-9_\\.\\-]}', '', $name));
if ($name == '') {
$name = 'noname';
}
if ($name[0] == '.') {
$name = "noname.{$name}";
}
move_uploaded_file($tmp_name, "{$dir}/{$name}");
chmod("{$dir}/{$name}", 0775);
$rc = CMS::vars()->on_change_call($id, $value, $data);
if (is_string($rc)) {
$item->valuesrc = $data['valuesrc'];
return $rc;
}
$item->value = "{$dir}/{$name}";
$item->update_value();
}
}
示例6: actionUpdate
/**
* Create/update product
* @param bool $new
* @throws CHttpException
*/
public function actionUpdate($new = false)
{
$this->topButtons = false;
$config = Yii::app()->settings->get('shop');
if ($new === true) {
$model = new ShopProduct();
} else {
$model = ShopProduct::model()->language(Yii::app()->language->active)->findByPk($_GET['id']);
}
if (!$model) {
throw new CHttpException(404, Yii::t('ShopModule.admin', 'NO_FOUND_PRODUCT'));
}
$oldImage = $model->image;
if (!$model->isNewRecord) {
$this->topButtons = array(array('label' => Yii::t('ShopModule.admin', 'VIEW_PRODUCT'), 'url' => $model->getAbsoluteUrl(), 'htmlOptions' => array('class' => 'btn btn-info', 'target' => '_blank')));
}
// Apply use_configurations, configurable_attributes, type_id
if (isset($_GET['ShopProduct'])) {
$model->attributes = $_GET['ShopProduct'];
}
$title = $model->isNewRecord ? Yii::t('ShopModule.admin', 'CREATE_PRODUCT') : Yii::t('ShopModule.admin', 'UPDATE_PRODUCT');
if ($model->type) {
$title .= ' "' . Html::encode($model->type->name) . '"';
}
$this->pageName = $title;
$this->breadcrumbs = array(Yii::t('ShopModule.default', 'MODULE_NAME') => array('/admin/shop'), Yii::t('ShopModule.admin', 'PRODUCTS') => $this->createUrl('index'), $this->pageName);
// On create new product first display "Choose type" form first.
if ($model->isNewRecord && isset($_GET['ShopProduct']['type_id'])) {
if (ShopProductType::model()->countByAttributes(array('id' => $model->type_id)) === '0') {
throw new CHttpException(404, Yii::t('ShopModule.admin', 'ERR_PRODUCT_TYPE'));
}
}
// Set main category id to have categories drop-down selected value
if ($model->mainCategory) {
$model->main_category_id = $model->mainCategory->id;
}
// Or set selected category from type pre-set.
if ($model->type && !Yii::app()->request->isPostRequest && $model->isNewRecord) {
$model->main_category_id = $model->type->main_category;
}
// Set configurable attributes on new record
if ($model->isNewRecord) {
if ($model->use_configurations && isset($_GET['ShopProduct']['configurable_attributes'])) {
$model->configurable_attributes = $_GET['ShopProduct']['configurable_attributes'];
}
}
$form = new TabForm($model->getForm(), $model);
// $form->positionTabs = 'vertical';
// Set additional tabs
$form->additionalTabs[$model->t('TAB_CAT')] = array('content' => $this->renderPartial('_tree', array('model' => $model), true));
$form->additionalTabs[$model->t('TAB_IMG')] = array('content' => $this->renderPartial('_images', array('model' => $model, 'uploadModel' => $uploadModel), true));
$form->additionalTabs[$model->t('TAB_ATTR')] = array('content' => $this->renderPartial('_attributes', array('model' => $model), true));
$form->additionalTabs[$model->t('TAB_REL')] = array('content' => $this->renderPartial('_relatedProducts', array('exclude' => $model->id, 'product' => $model), true));
//if (Yii::app()->getModule('shop')->variations)
$form->additionalTabs[Yii::t('ShopModule.admin', 'UPDATE_PRODUCT_TAB_VARIANTS')] = array('content' => $this->renderPartial('_variations', array('model' => $model), true));
// if($this->isInstallModule('comments')){
// $form->additionalTabs['icon-comment'] = array(
// 'content' => $this->renderPartial('_comments', array('model' => $model), true)
// );
// }
/* $form->additionalTabs = array(
'icon-folder-open' => array(
'content' => $this->renderPartial('_tree', array('model' => $model), true)
),
'icon-copy-3' => array(
'content' => $this->renderPartial('_relatedProducts', array('exclude' => $model->id, 'product' => $model), true)
),
'icon-images' => array(
'content' => $this->renderPartial('_images', array('model' => $model, 'uploadModel' => $uploadModel), true)
),
'icon-paragraph-justify' => array(
'content' => $this->renderPartial('_attributes', array('model' => $model), true),
'visible'=>false
),
Yii::t('ShopModule.admin', 'Варианты') => array(
'content' => $this->renderPartial('_variations', array('model' => $model), true)
),
'icon-comment' => array(
'content' => $this->renderPartial('_comments', array('model' => $model), true)
),
); */
if ($model->use_configurations) {
$form->additionalTabs[Yii::t('ShopModule.admin', 'UPDATE_PRODUCT_TAB_CONF')] = array('content' => $this->renderPartial('_configurations', array('product' => $model), true));
}
if (isset($_GET['ShopProduct']['main_category_id'])) {
$model->main_category_id = $_GET['ShopProduct']['main_category_id'];
}
if (Yii::app()->request->isPostRequest) {
$model->attributes = $_POST['ShopProduct'];
// Handle related products
$model->setRelatedProducts(Yii::app()->getRequest()->getPost('RelatedProductId', array()));
if ($config['auto_gen_url']) {
$model->name = ShopCategory::model()->findByPk($model->main_category_id)->name . ' ' . ShopManufacturer::model()->findByPk($model->manufacturer_id)->name . ' ' . $model->sku;
$model->seo_alias = CMS::translit($model->name);
// die($model->name.$model->seo_alias);
//.........这里部分代码省略.........
示例7: md5
?>
<?php
if ($close) {
?>
alert-dismissible fade in<?php
}
?>
" id="alert<?php
echo md5($type . CMS::translit($message));
?>
">
<?php
if ($close) {
?>
<button type="button" onClick="alertClose('<?php
echo md5($type . CMS::translit($message));
?>
'); return false;" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<?php
}
?>
<?php
if ($type == 'success') {
$icon = 'fa-check';
} elseif ($type == 'danger') {
$icon = 'flaticon-warning';
} elseif ($type == 'info') {
$icon = 'flaticon-info';
}
?>
<i class="<?php
示例8: uploaded_filename
protected function uploaded_filename($name, $data, $file)
{
return CMS::translit(preg_replace('{[\\s+]+}', '-', trim($file['name'])));
}
示例9: validate_filename
protected function validate_filename($name)
{
$name = trim($name);
$name = preg_replace('{\\s+}sm', ' ', $name);
$name = str_replace(' ', '_', $name);
$name = CMS::translit($name);
return $name;
}
示例10: getManufacturerIdByName
/**
* Find or create manufacturer
* @param $name
* @return integer
*/
public function getManufacturerIdByName($name)
{
if (isset($this->manufacturerCache[$name])) {
return $this->manufacturerCache[$name];
}
$cr = new CDbCriteria();
$cr->with = array('man_translate');
$cr->compare('man_translate.name', $name);
$model = ShopManufacturer::model()->find($cr);
if (!$model) {
$model = new ShopManufacturer();
$model->name = $name;
$model->seo_alias = CMS::translit($name);
if ($model->validate()) {
$model->save(false, false);
}
}
$this->manufacturerCache[$name] = $model->id;
return $model->id;
}
示例11: importRow
/**
* Create/update product from key=>value array
* @param $data array of product attributes
*/
protected function importRow($data)
{
if (!isset($data['category']) || empty($data['category'])) {
$data['category'] = 'root';
}
$newProduct = false;
$category_id = $this->getCategoryByPath($data['category']);
// Search product by name, category
// or create new one
$cr = new CDbCriteria();
$cr->with = array('translate');
// if (isset($data['seo_alias']) && !empty($data['seo_alias']) && $data['seo_alias'] != '')
// $cr->compare('t.seo_alias', $data['seo_alias']);
if (isset($data['sku']) && !empty($data['sku']) && $data['sku'] != '') {
$cr->compare('t.sku', $data['sku']);
} else {
$cr->compare('translate.name', $data['name']);
}
$model = ShopProduct::model()->applyCategories($category_id)->find($cr);
if (!$model) {
$newProduct = true;
$model = new ShopProduct(null);
// Add "null" by PANIX
$this->stats['date_create']++;
} else {
$this->stats['date_update']++;
}
$model->seo_alias = CMS::translit($data['name']);
// Process product type
$model->type_id = $this->getTypeIdByName($data['type']);
// Manufacturer
if (isset($data['manufacturer']) && !empty($data['manufacturer'])) {
$model->manufacturer_id = $this->getManufacturerIdByName($data['manufacturer']);
}
// Update product variables and eav attributes.
$attributes = new CsvAttributesProcessor($model, $data);
if ($model->validate()) {
$categories = array($category_id);
if (isset($data['additionalCategories'])) {
$categories = array_merge($categories, $this->getAdditionalCategories($data['additionalCategories']));
}
if (!$newProduct) {
foreach ($model->categorization as $c) {
$categories[] = $c->category;
}
$categories = array_unique($categories);
}
// Save product
$model->save(false, false);
// Update EAV data
$attributes->save();
// Update categories
$model->setCategories($categories, $category_id);
// Process product main image if product doesn't have one
if (isset($data['image']) && !empty($data['image'])) {
$image = CsvImage::create($data['image']);
if ($image && $model->mainImage === null) {
$model->addImage($image);
}
if ($image && $this->deleteDownloadedImages) {
$image->deleteTempFile();
}
}
} else {
$errors = $model->getErrors();
$error = array_shift($errors);
$this->errors[] = array('line' => $this->line, 'error' => $error[0]);
}
}