Esempio n. 1
0
 public static function sanitize($string, $suffix = null)
 {
     $string = EString::rus2translit($string);
     $string = preg_replace(array('/\\s+/is', '/[^\\w\\d\\.\\-]/is'), array('_', ''), $string);
     $string = preg_replace(array('/_{2,}/is'), array('_'), $string);
     $string = trim($string, '_');
     if (!empty($suffix)) {
         $string = $string . $suffix;
     }
     return $string;
 }
 public function run()
 {
     Yii::import($this->import);
     $id = Yii::app()->request->getParam('id', 0);
     if ($id <= 0) {
         echo '{}';
     } else {
         $models = Car::model()->findAll(array('condition' => 'brand_id=' . $id, 'order' => 'title'));
         $data = array('');
         foreach ($models as $m) {
             $data[$m->id] = $m->title . ' ' . EString::getYear($m->manufacture_start) . (empty($m->manufacture_end) ? '...' : ' - ' . EString::getYear($m->manufacture_end));
         }
         echo CJavaScript::jsonEncode($data);
     }
 }
 public function run()
 {
     if ($image = CUploadedFile::getInstanceByName($this->field)) {
         // Валидация по форме
         $v = new ImageForm();
         $v->image = true;
         $v->image_file = $image;
         if ($v->validate()) {
             $preid = Yii::app()->request->getPost('preid', date('Ymd'));
             $tmp = pathinfo($image->name);
             $filename = EString::strtolower(EFile::sanitize($tmp['filename']) . '_' . uniqid() . '.' . $tmp['extension']);
             $path = Yii::getPathOfAlias($this->folder . '.' . $this->field) . DIRECTORY_SEPARATOR . $preid . DIRECTORY_SEPARATOR;
             $result = Image::addFile($image, $filename, $path, $this->sizes, $preid, null, $this->watermark ? Yii::app()->params['watermark'] : false);
             echo '"' . Image::getFile($result, 'normal') . '"';
         } else {
             echo '{"error":"Файл не проходит валидацию, выберите другой."}';
         }
     } else {
         echo '{"error":"Ошибка загрузки файла."}';
     }
 }
Esempio n. 4
0
$this->pageTitle = Yii::app()->name . ' - Новости - ' . CHtml::encode($model->title);
$this->breadcrumbs = array('Новости' => array('articles/index'), $model->title);
?>

<!-- id <?php 
echo $model->id;
?>
 -->

<h2><?php 
echo $model->title;
?>
</h2>
<?php 
echo EString::getBackTime($model->publicated);
?>
<hr  class='space'/>

<?php 
echo $model->photo ? CHtml::image(Image::getFile($model->photo, 'main'), $model->title, array('align' => 'left', 'style' => 'margin-right:1em;border:1px solid #eee;')) : '';
echo $model->preamble_marked;
$this->widget('widgets.socials.socials', array('model' => $model, 'options' => array('title' => $model->title, 'url' => CHtml::normalizeUrl(array('articles/view', 'alias' => $model->alias)), 'description' => CHtml::encode($model->preamble), 'printUrl' => CHtml::normalizeUrl(array('articles/print', 'alias' => $model->alias)))));
?>
<hr class='space clear' />

<?php 
echo $model->text_marked;
?>

<hr class='space clear'/>
 public function actionNomenclature()
 {
     ini_set('memory_limit', '650M');
     set_time_limit(0);
     $tyresForm = new ImportForm();
     $result = array();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['ImportForm'])) {
         $tyresForm->attributes = $_POST['ImportForm'];
         if ($tyresForm->validate()) {
             # Вот тут начинается импорт
             Yii::import('ext.markdown.*');
             Yii::import('ext.markdownify.*');
             Yii::import('webroot.helpers.*');
             #$tyresForm->file = CUploadedFile::getInstance($tyresForm, 'file');
             /* Первая страница
              * 1. CAI
              * 2. Производитель
              * 3. Модель
              * 4. Сезон
              * 5. Применяемость
              * 6. Тип протектора
              * 7. Шипованность
              * 8. Ширина профиля(мм)
              * 9. Высота профиля (%)
              * 10. Диаметр (,R)
              * 11. Индекс скорости
              * 12. Индекс нагрузки
              * 13. Цена
              * 14. Фото, большое
              * 15. Фото, мелкое
             */
             $uploaded = Yii::app()->file->set('ImportForm[file]');
             Yii::app()->file->set(Yii::getPathOfAlias('webroot.files.' . $this->id . '.' . $this->action->id))->createDir();
             $newfile = $uploaded->copy(strtolower(Yii::getPathOfAlias('webroot.files.' . $this->id . '.' . $this->action->id)) . '/' . $uploaded->basename);
             $newfile->filename = $newfile->filename . '.' . date('YmdHis');
             Yii::import('ext.phpexcelreader.EPhpExcelReader');
             $data = new EPhpExcelReader($newfile->realpath, false);
             $rowcount = $data->rowcount();
             #$colcount = $data->colcount();
             #$rowcount = 3;
             $r = 2;
             while ($r <= $rowcount) {
                 $producer_alias = EString::strtolower(EString::sanitize($data->val($r, 2)));
                 if (!($producer = TyreProducers::model()->find('alias=:alias', array(':alias' => $producer_alias)))) {
                     $producer = new TyreProducers();
                     @($result['new_producers'] += 1);
                 } else {
                     @($result['old_producers'] += 1);
                 }
                 $producer->title = $data->val($r, 2);
                 $producer->alias = $producer_alias;
                 if (!$producer->save()) {
                     $result['errors']['producer:' . $data->val($r, 1)] = $producer->errors;
                 }
                 $tyre_alias = EString::strtolower(EString::sanitize($data->val($r, 3)));
                 if (!($tyre = Tyre::model()->find('alias=:alias', array(':alias' => $tyre_alias)))) {
                     $tyre = new Tyre();
                     @($result['new_tyres'] += 1);
                 } else {
                     @($result['old_tyres'] += 1);
                 }
                 $tyre->producer_id = $producer->id;
                 $tyre->title = $data->val($r, 3);
                 $tyre->alias = $tyre_alias;
                 $tyre->new = true;
                 $tyre->currency = L::r_item('tyreCurrency', $data->val($r, 5)) ? L::r_item('tyreCurrency', $data->val($r, 5)) : 0;
                 if ($data->val($r, 4) == 'зимние') {
                     $tyre->season = L::r_item('tyreSeason', 'winter');
                 }
                 if ($data->val($r, 4) == 'летние') {
                     $tyre->season = L::r_item('tyreSeason', 'summer');
                 }
                 if ($data->val($r, 4) == 'всесезонные') {
                     $tyre->season = L::r_item('tyreSeason', 'yearround');
                 }
                 $tyre->stud = $data->val($r, 7) ? 1 : 0;
                 $tyre->construction_type = 1;
                 $tyre->runflat_type = 0;
                 // загрузка картинок...
                 $alias = EString::sanitize($producer_alias . '_' . $tyre_alias);
                 $path0 = Yii::getPathOfAlias('webroot.files.' . EString::strtolower('Tyre') . '.' . 'photo') . DIRECTORY_SEPARATOR;
                 $f = false;
                 $tmp_image = str_replace('.jpg', '.png', $data->val($r, 14));
                 if (!empty($tmp_image) && empty($tyre->photo)) {
                     #d($tmp_image);
                     #d($tyre->photo);
                     foreach (Tyre::model()->images['photo']['sizes'] as $key => $size) {
                         $pic = null;
                         // папка в которой будет хранится картинка
                         $path = $path0 . $key . DIRECTORY_SEPARATOR;
                         // создаю папку если ее не было
                         EFile::set($path)->createDir();
                         $pic = @file_get_contents('http://www.4tochki.ru' . $tmp_image);
                         $info = pathinfo($tmp_image);
                         #$row['pic_file'] - 117*(65-88) (лента слева)
                         if (empty($pic)) {
                             continue;
                         }
                         $fullpath = $path . $alias . '.jpg';
                         file_put_contents($fullpath, $pic);
                         $pic = Yii::app()->image->load($fullpath);
                         $pic->thumb(isset($size[0]) ? $size[0] : 0, isset($size[1]) ? $size[1] : 0, true, '#FFFFFF');
                         if ($key == 'big') {
                             $pic->watermark(Yii::getPathOfAlias('webroot') . Yii::app()->params['watermark'], 5);
                         }
                         $pic->save($fullpath);
                         $f = true;
                     }
                     if ($f) {
                         if (!($image = Image::model()->find('filename=:alias', array(':alias' => '/files/tyre/photo/::size::/' . $alias . '.jpg')))) {
                             $image = new Image();
                         }
                         $image->created = date('Y-m-d H:i:s', strtotime($row['add_date']));
                         $image->filename = '/files/tyre/photo/::size::/' . $alias . '.jpg';
                         $image->title = $producer->title . ' ' . $tyre->title;
                         $image->alt = $producer->title . ' ' . $tyre->title;
                         $image->save();
                         $tyre->photo = '/files/tyre/photo/::size::/' . $alias . '.jpg';
                     } else {
                         $tyre->photo = null;
                     }
                 }
                 if (!$tyre->save()) {
                     $result['errors']['tyre:' . $data->val($r, 1)] = $tyre->errors;
                 }
                 $cai = $data->val($r, 1);
                 if (!($size = TyreSizes::model()->find('code=:code', array(':code' => $cai)))) {
                     $size = new TyreSizes();
                     $size->alias = uniqid();
                     $size->save(false);
                     @($result['new_size'] += 1);
                 } else {
                     @($result['old_size'] += 1);
                 }
                 $size->tyre_id = $tyre->id;
                 $size->code = $cai;
                 $size->width = $data->val($r, 8);
                 $size->height = $data->val($r, 9);
                 $size->diameter = $data->val($r, 10);
                 $size->speed_rating = preg_replace('/[0-9]/isU', '', $data->val($r, 11));
                 $size->load_index = preg_replace('/[a-z]/isU', '', $data->val($r, 12));
                 $size->price = 0;
                 $size->rest = 0;
                 #d($size->attributes);
                 $size->alias = $size->id . '-' . $size->width . '-' . $size->height . '-' . $size->diameter . '-' . $size->speed_rating . $size->load_index;
                 # Сохраняю...
                 if (!$size->save()) {
                     $result['errors']['size:' . $data->val($r, 1)] = $size->errors;
                 }
                 $r++;
             }
             #$this->redirect(array('view','id'=>$model->id));
         }
     }
     $this->render('nomenclature', array('model' => $tyresForm, 'results' => $result));
 }
 public function beforeSave()
 {
     $this->alias = EString::strtolower($this->alias);
     if ($this->description) {
         Yii::import('ext.mardown.*');
         $md = new EMarkdown();
         $this->description_marked = $md->transform($this->description);
     }
     return parent::beforeSave();
 }
 /**
  * Загрузка картинки
  */
 protected function uploadImage($field, $name, $sizes, $alt = '', $title = '', $addWatermark = false, $bg = '#FFFFFF', $file_type = 'jpg', $saveOld = false)
 {
     /*
      * @string $field Имя виртуального поля в котром хранится файл
      * @string $name Имя файла, который будет сохранен на диске
      */
     $owner = $owner = $this->getOwner();
     if ($owner->{$field} instanceof CUploadedFile) {
         $filename = EString::strtolower(EFile::sanitize($name) . '.' . $file_type);
         $path = Yii::getPathOfAlias('webroot.files.' . EString::strtolower(get_class($owner)) . '.' . $field) . DIRECTORY_SEPARATOR;
         return $owner->{$field} = Image::addFile($owner->{$field}, $filename, $path, $sizes, $alt, $title, $addWatermark, $bg, $file_type, $saveOld);
     }
 }
 public function actionNomenclature()
 {
     ini_set('memory_limit', '650M');
     set_time_limit(0);
     $tyresForm = new ImportForm();
     $result = array();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['ImportForm'])) {
         $tyresForm->attributes = $_POST['ImportForm'];
         if ($tyresForm->validate()) {
             # Вот тут начинается импорт
             $uploaded = Yii::app()->file->set('ImportForm[file]');
             Yii::app()->file->set(Yii::getPathOfAlias('webroot.files.' . $this->id . '.' . $this->action->id))->createDir();
             $newfile = $uploaded->copy(strtolower(Yii::getPathOfAlias('webroot.files.' . $this->id . '.' . $this->action->id)) . '/' . $uploaded->basename);
             $newfile->filename = $newfile->filename . '.' . date('YmdHis');
             Yii::import('ext.phpexcelreader.EPhpExcelReader');
             $data = new EPhpExcelReader($newfile->realpath, false);
             $sheet = 1;
             $rowcount = $data->rowcount($sheet);
             #$colcount = $data->colcount();
             #$rowcount = 10;
             $r = 2;
             while ($r <= $rowcount) {
                 $cai = $data->val($r, 1);
                 if (empty($cai)) {
                     $r++;
                     continue;
                 }
                 $producer_alias = EString::strtolower(EString::sanitize($data->val($r, 2)));
                 if (!($producer = DiskProducers::model()->find('alias=:alias', array(':alias' => $producer_alias)))) {
                     $producer = new DiskProducers();
                     @($result['new_producers'] += 1);
                 } else {
                     @($result['old_producers'] += 1);
                 }
                 $producer->title = $data->val($r, 2);
                 $producer->alias = $producer_alias;
                 if (!$producer->save()) {
                     $result['errors']['producer:' . $data->val($r, 1)] = $producer->errors;
                 }
                 $disk_alias = EString::strtolower(EString::sanitize($data->val($r, 3)));
                 if (!($disk = Disk::model()->find('alias=:alias', array(':alias' => $disk_alias)))) {
                     $disk = new Disk();
                     @($result['new_disks'] += 1);
                 } else {
                     @($result['old_disks'] += 1);
                 }
                 $disk->producer_id = $producer->id;
                 $disk->title = $data->val($r, 3);
                 $disk->alias = $disk_alias;
                 $disk->color = 1;
                 $disk->construction_type = L::r_item('diskConstructionType', 'alloy');
                 if ($data->val($r, 5)) {
                     $disk->construction_type = L::r_item('diskConstructionType', 'forged');
                 }
                 /*
                 if($data->val($r, 4) && $data->val($r,5))
                 	$disk->construction_type = L::r_item('diskConstructionType', 'scratched');
                 if(!($data->val($r, 4)) && !($data->val($r,5)) ))
                 	$disk->construction_type = L::r_item('diskConstructionType', 'stamped');
                 */
                 // загрузка картинок...
                 $alias = EString::sanitize($producer_alias . '_' . $disk_alias);
                 $path0 = Yii::getPathOfAlias('webroot.files.' . EString::strtolower('Disk') . '.' . 'photo') . DIRECTORY_SEPARATOR;
                 $f = false;
                 $tmp_image = str_replace('.jpg', '.png', $data->val($r, 12));
                 if (!empty($tmp_image) && empty($disk->photo)) {
                     #d($tmp_image);
                     #d($tyre->photo);
                     foreach (Disk::model()->images['photo']['sizes'] as $key => $size) {
                         $pic = null;
                         // папка в которой будет хранится картинка
                         $path = $path0 . $key . DIRECTORY_SEPARATOR;
                         // создаю папку если ее не было
                         EFile::set($path)->createDir();
                         $pic = @file_get_contents('http://www.4tochki.ru' . $tmp_image);
                         $info = pathinfo($tmp_image);
                         #$row['pic_file'] - 117*(65-88) (лента слева)
                         if (empty($pic)) {
                             continue;
                         }
                         $fullpath = $path . $alias . '.jpg';
                         file_put_contents($fullpath, $pic);
                         $pic = Yii::app()->image->load($fullpath);
                         $pic->thumb(isset($size[0]) ? $size[0] : 0, isset($size[1]) ? $size[1] : 0, true, '#FFFFFF');
                         if ($key == 'big') {
                             $pic->watermark(Yii::getPathOfAlias('webroot') . Yii::app()->params['watermark'], 5);
                         }
                         $pic->save($fullpath);
                         $f = true;
                     }
                     if ($f) {
                         if (!($image = Image::model()->find('filename=:alias', array(':alias' => '/files/disk/photo/::size::/' . $alias . '.jpg')))) {
                             $image = new Image();
                         }
                         $image->created = date('Y-m-d H:i:s', strtotime($row['add_date']));
                         $image->filename = '/files/disk/photo/::size::/' . $alias . '.jpg';
                         $image->title = $producer->title . ' ' . $disk->title;
                         $image->alt = $producer->title . ' ' . $disk->title;
                         $image->save();
                         $disk->photo = '/files/disk/photo/::size::/' . $alias . '.jpg';
                     } else {
                         $disk->photo = null;
                     }
                 }
                 if (!$disk->save()) {
                     $result['errors']['disk:' . $data->val($r, 1)] = $disk->errors;
                 }
                 if (!($size = DiskSizes::model()->find('code=:code', array(':code' => $cai)))) {
                     $size = new DiskSizes();
                     $size->alias = uniqid();
                     $size->save(false);
                     @($result['new_size'] += 1);
                 } else {
                     @($result['old_size'] += 1);
                 }
                 $size->disk_id = $disk->id;
                 $size->code = $cai;
                 /*
                  * 1. cae	
                  * 2. producer.name
                  * 3. model.name
                  * 4. lit
                  * 5. kov
                  * 6. sh
                  * 7. d	
                  * 8. pcd
                  * 9. pcd2
                  * 10.vil
                  * 11.dia
                  */
                 $width_fl_point = preg_replace("/,/", ".", $data->val($r, 6));
                 $width_c = floatval(preg_replace("/^[^0-9\\.]/", "", $width_fl_point));
                 $size->width = $width_c;
                 $size->diameter = $data->val($r, 7);
                 $ET_fl_point = preg_replace("/,/", ".", $data->val($r, 10));
                 $ET_c = floatval(preg_replace("/^[^0-9\\.\\-]/", "", $ET_fl_point));
                 $size->ET = floatval($ET_c);
                 list($size->PCD_screws, $PCD_diameter_fl_point) = preg_split('/[^\\d,\\.]+/i', $data->val($r, 8));
                 $PCD_diameter_fl_point = preg_replace("/,/", ".", $PCD_diameter_fl_point);
                 $PCD_diameter_c = floatval(preg_replace("/^[^0-9\\.]/", "", $PCD_diameter_fl_point));
                 $size->PCD_diameter = $PCD_diameter_c;
                 $DIA_fl_point = preg_replace("/,/", ".", $data->val($r, 11));
                 $DIA_c = floatval(preg_replace("/^[^0-9\\.]/", "", $DIA_fl_point));
                 $size->DIA = $DIA_c;
                 $size->price = 0;
                 $size->rest = 0;
                 $size->alias = $size->id . '-' . $size->width . '-' . $size->diameter . '-' . $size->PCD_screws . '-' . $size->PCD_diameter . '-ET' . $size->ET . '-' . $size->DIA;
                 if (!$size->save()) {
                     $size->delete();
                     $result['errors']['size:' . $data->val($r, 1)] = $size->errors;
                 }
                 $r++;
             }
             #$this->redirect(array('view','id'=>$model->id));
         }
     }
     $this->render('nomenclature', array('model' => $tyresForm, 'results' => $result));
 }
Esempio n. 9
0
		<?php 
if ($options['select'] != 'Brand' && $options['select'] != 'Car') {
    ?>
		
		<div id='<?php 
    echo $this->id;
    ?>
_modification' style='display: none;'>
			<label for='model_id'><?php 
    echo Characteristic::model()->getAttributeLabel('modification_id');
    ?>
</label><br />
			<?php 
    echo CHtml::dropDownList(get_class($model) . '[modification_id]', '', array());
    ?>
			<img src='/images/loader.gif' class='loader' style='display: none;'>
		</div>
		
		<?php 
}
?>
	
		<?php 
Yii::app()->getClientScript()->registerScript($this->id, "jQuery('#{$this->id}').catalogSelect({\r\n\t\t\t\tid:'{$this->id}', \r\n\t\t\t\tmodel_id:'" . $model->{$name} . "', \r\n\t\t\t\tselect: '" . EString::strtolower($options['select']) . "',\r\n\t\t\t\tmodel:'{$options['select']}',\r\n\t\t\t\tbrandSelect: \$('#" . get_class($model) . "_brand_id'),\r\n\t\t\t\tmodelSelect: \$('#" . get_class($model) . "_model_id'),\r\n\t\t\t\tmodificationSelect: \$('#" . get_class($model) . "_modification_id'),\r\n\t\t\t\turlCatalog: '{$options['urlCatalog']}',\r\n\t\t\t\turlBrand: '{$options['urlBrand']}',\r\n\t\t\t\turlModel: '{$options['urlModel']}',\r\n\t\t\t\tallowEmpty: " . ($options['allowEmpty'] ? 'true' : 'false') . "\r\n\t\t\t});");
?>
	</div>
	<?php 
echo CHtml::error($model, $name);
?>
</div>
Esempio n. 10
0
<?php

$this->breadcrumbs = array('Комментарии' => array('index'), $model->id);
$this->menu = array(array('label' => 'Обновить комментарий', 'url' => array('update', 'id' => $model->id)), array('label' => 'Удалить комментарий', 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Вы уверены что хотите удалить комментарий?')), array('label' => 'Управление комментариями', 'url' => array('admin')));
?>

<h1>Подробнее о комментарии #<?php 
echo $model->id;
?>
</h1>

<?php 
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', array('name' => 'object_type', 'value' => L::ruitem('CommentType', $model->object_type)), array('name' => 'parentTitle', 'value' => $model->object->title), array('name' => 'url', 'type' => 'raw', 'value' => CHtml::link(@$model->object->url, @$model->object->url)), array('name' => 'author', 'type' => 'raw', 'value' => $model->author), 'text_marked:raw', array('name' => 'created', 'type' => 'text', 'value' => EString::getBackTime($model->created)), 'rating', array('name' => 'status', 'value' => L::ruitem('CommentStatus', $model->status)))));
Esempio n. 11
0
 /**
  * Загрузка картинки
  */
 public function uploadImage($field, $name, $sizes, $alt = '', $title = '')
 {
     /*
      * @string $field Имя виртуального поля в котром хранится файл
      * @string $name Имя файла, который будет сохранен на диске
      */
     if ($image = CUploadedFile::getInstance($this, $field)) {
         $orig_field = str_replace('_file', '', $field);
         $filename = EString::strtolower(EFile::sanitize($name) . '.' . $image->extensionName);
         $path = Yii::getPathOfAlias('webroot.files.' . EString::strtolower(__CLASS__) . '.' . $orig_field) . DIRECTORY_SEPARATOR;
         Image::deleteFile($this->{$orig_field}, $sizes);
         $this->{$orig_field} = Image::addFile($image, $filename, $path, $sizes, $alt, $title, false, '#FFFFFF');
     }
 }
Esempio n. 12
0
<center>
<font size=2><a href='/tape' />Статьи</a>: 
<i><a href='/'><?php 
echo Yii::app()->name;
?>
</a> <?php 
echo CHtml::link($model->url, $model->url);
?>
</i></font><br>
<font size=2><b><?php 
echo EString::ucfirst(EString::getBackTime($model->publicated));
?>
</b></font><br>
<h3><?php 
echo $model->title;
?>
</h3>
</center>

<?php 
echo $model->preamble_marked;
?>
 

<?php 
echo strip_tags($model->text_marked, '<p><strong><b><a>');
 public function beforeSave()
 {
     $this->alias = EString::strtolower($this->alias);
     if ($this->description) {
         Yii::import('ext.mardown.*');
         $md = new EMarkdown();
         $this->description_marked = $md->transform($this->description);
     }
     #$this->uploadImage('logo_file', $this->alias, $this->logo_sizes, $this->title, 'Логотип: '.$this->title);
     return parent::beforeSave();
 }
Esempio n. 14
0
foreach ($this->model->{$this->name} as $comment) {
    ?>
	<li style='margin-left: <?php 
    echo $comment->level * 20;
    ?>
px;'>
		<a name='<?php 
    echo 'comment-' . $comment->id;
    ?>
'></a>
		<div class='comment'>
			<?php 
    echo $comment->author;
    ?>
, <?php 
    echo EString::getBackTime($comment->created);
    ?>
			<a class='ans' href='#<?php 
    echo 'comment-' . $comment->id;
    ?>
' rel='<?php 
    echo $comment->id;
    ?>
' author='<?php 
    echo $comment->author;
    ?>
'>ответить</a>
			<hr style="border-bottom: 2px solid white;">
			<?php 
    echo $comment->text_marked;
    ?>