Example #1
2
 public function run()
 {
     $tags = Tag::model()->findAll();
     if ($tags) {
         foreach ($tags as $tag) {
             $post = Post::model()->findAll("FIND_IN_SET(:tag, tags)", array(':tag' => $tag->tag_name));
             $image = Image::model()->findAll("FIND_IN_SET(:tag, tags)", array(':tag' => $tag->tag_name));
             $soft = Soft::model()->findAll("FIND_IN_SET(:tag, seo_keywords)", array(':tag' => $tag->tag_name));
             $video = Video::model()->findAll("FIND_IN_SET(:tag, seo_keywords)", array(':tag' => $tag->tag_name));
             if (!$post && !$image && !$soft && !$video) {
                 $tag->delete();
             } else {
                 $tag->data_count = count($post) + count($image) + count($soft);
                 $tag->save();
             }
         }
     }
     $tagdatas = TagData::model()->findAll();
     if ($tagdatas) {
         foreach ($tagdatas as $value) {
             $modelType = ModelType::model()->findByPk($value->type);
             $model = $modelType->model;
             $data = $model::model()->findByPk($value->content_id);
             if (!$data) {
                 $value->delete();
             }
         }
     }
     $this->controller->message('success', Yii::t('admin', 'Reset Tags Success'), $this->controller->createUrl('index'));
 }
Example #2
0
 public function run()
 {
     //SEO
     $this->controller->_seoTitle = $this->controller->_setting['seo_title'];
     $this->controller->_seoKeywords = $this->controller->_setting['seo_keywords'];
     $this->controller->_seoDescription = $this->controller->_setting['seo_description'];
     //头部banner
     $index_top_banner = Ad::model()->getAdOne(4);
     //中部banner
     $index_mid_banner = Ad::model()->getAdOne(3);
     //底部banner
     $index_bottom_banner = Ad::model()->getAdOne(5);
     //最新资讯
     $news_new = Post::model()->getList(array('limit' => 20));
     //热门资讯
     $news_hot = Post::model()->getList(array('order' => 't.view_count DESC, t.id DESC', 'limit' => 20));
     //最新图集
     $image_new = Image::model()->getList(array('limit' => 10));
     //热门图集
     $image_hot = Image::model()->getList(array('limit' => 10, 'order' => 'view_count DESC, t.id DESC'));
     //最新软件
     $soft_new = Soft::model()->getList(array('limit' => 20));
     //热门软件
     $soft_hot = Soft::model()->getList(array('limit' => 10, 'order' => 'down_count DESC, t.id DESC'));
     //最新视频
     $video_new = Video::model()->findAll("status=:status AND catalog_id = 13 ORDER BY id DESC Limit 20", array(':status' => 'Y'));
     //热门视频
     $video_hot = Video::model()->findAll("status=:status AND catalog_id = 13 ORDER BY view_count DESC, video_score DESC, id DESC Limit 20", array(':status' => 'Y'));
     //友情链接
     $link_logos = Link::model()->findAll("logo !='' AND status='Y'", array('order' => 'sortorder ASC, id DESC'));
     $link_texts = Link::model()->findAll("logo ='' AND status='Y'", array('order' => 'sortorder ASC, id DESC'));
     $this->controller->render('index', array('index_top_banner' => $index_top_banner, 'index_mid_banner' => $index_mid_banner, 'index_bottom_banner' => $index_bottom_banner, 'link_logos' => $link_logos, 'link_texts' => $link_texts, 'news_new' => $news_new, 'news_hot' => $news_hot, 'image_new' => $image_new, 'image_hot' => $image_hot, 'soft_new' => $soft_new, 'soft_hot' => $soft_hot, 'video_new' => $video_new, 'video_hot' => $video_hot));
 }
Example #3
0
 public function actionFoto($id)
 {
     $model = Image::model()->findByPk((int) $id);
     if (is_null($model)) {
         throw new CHttpException(404, Yii::t('gallery', 'Страница не найдена!'));
     }
     $this->render('foto', array('model' => $model));
 }
Example #4
0
 public function selectByRow($table, $row_id)
 {
     $criteria = new CDbCriteria();
     $criteria->select = 'path';
     $criteria->condition = 'row_id=:row_id AND `table`=:table';
     $criteria->params = array(':row_id' => $row_id, ':table' => $table);
     $result = Image::model()->find($criteria);
     //error_log(var_dump($data,1));
     return $result;
 }
Example #5
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  */
 public function loadModel()
 {
     if ($this->_model === null) {
         if (isset($_GET['id'])) {
             $this->_model = Image::model()->findbyPk($_GET['id']);
         }
         if ($this->_model === null) {
             throw new CHttpException(404, 'The requested page does not exist.');
         }
     }
     return $this->_model;
 }
Example #6
0
 public function actionImageDelete($id)
 {
     $model = Image::model()->findByPk((int) $id);
     if ($model) {
         $model->delete();
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
         }
     } else {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
 }
Example #7
0
 public function run()
 {
     $catalog_id = trim(Yii::app()->request->getParam('catalog_id'));
     $order = trim(Yii::app()->request->getParam('order'));
     if (!$order) {
         $order = 'id';
     }
     switch ($order) {
         case 'id':
             $order_by = 't.id DESC';
             break;
         case 'view_count':
             $order_by = 'view_count DESC';
             break;
         default:
             $order = 'id';
             $order_by = 't.id DESC';
             break;
     }
     //SEO
     $navs = array();
     $search_cats = '所有';
     if ($catalog_id) {
         $condition = ' AND catalog_id = ' . $catalog_id;
         $catalog = Catalog::model()->findByPk($catalog_id);
         if ($catalog) {
             $this->controller->_seoTitle = $catalog->seo_title ? $catalog->seo_title : $catalog->catalog_name . ' - ' . $this->controller->_setting['site_name'];
             $this->controller->_seoKeywords = $catalog->seo_keywords;
             $this->controller->_seoDescription = $catalog->seo_description;
             $navs[] = array('url' => $this->controller->createUrl('image/index', array('catalog_id' => $catalog->id)), 'name' => $catalog->catalog_name);
             //已搜索的分类
             $cat_parents = Catalog::getParantsCatalog($catalog_id);
             $search_cats = $cat_parents ? implode('>', $cat_parents) . '>' . $catalog->catalog_name : $catalog->catalog_name;
         }
     }
     if (!$navs) {
         $condition = '';
         $catalog = array();
         $seo = ModelType::getSEO('image');
         $this->controller->_seoTitle = $seo['seo_title'] . ' - ' . $this->controller->_setting['site_name'];
         $this->controller->_seoKeywords = $seo['seo_keywords'];
         $this->controller->_seoDescription = $seo['seo_description'];
         $navs[] = array('url' => Yii::app()->request->getUrl(), 'name' => $this->controller->_seoTitle);
     }
     //获取所有符合条件的图集
     $pages = array();
     $datalist = Image::model()->getList(array('condition' => $condition, 'limit' => 15, 'order' => $order_by, 'page' => true), $pages);
     //该栏目下最新的图集
     $last_images = Image::model()->getList(array('condition' => $condition, 'limit' => 10));
     $this->controller->render('index', array('navs' => $navs, 'catalog' => $catalog, 'datalist' => $datalist, 'pagebar' => $pages, 'last_images' => $last_images, 'order' => $order, 'search_cats' => $search_cats));
 }
Example #8
0
 /**
  * 
  * 重新统计标签,删除不匹配的标签
  * 
  */
 public function actionReset()
 {
     $tags = Tag::model()->findAll();
     foreach ((array) $tags as $tag) {
         $post = Post::model()->findAll("FIND_IN_SET(:tag, tags)", array(':tag' => $tag->tag_name));
         $image = Image::model()->findAll("FIND_IN_SET(:tag, tags)", array(':tag' => $tag->tag_name));
         $soft = Soft::model()->findAll("FIND_IN_SET(:tag, seo_keywords)", array(':tag' => $tag->tag_name));
         if (!$post && !$image && !$soft) {
             $tag->delete();
         } else {
             $tag->data_count = count($post) + count($image) + count($soft);
             $tag->save();
         }
     }
     $this->message('success', Yii::t('admin', 'Reset Tags Success'), $this->createUrl('index'));
 }
Example #9
0
 /**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionIndex()
 {
     //首页banner幻灯片
     $banner = Ad::model()->findAll('position_id=:pid', array(':pid' => 1));
     //SEO
     $this->_seoTitle = $this->_setting['seo_title'];
     $this->_seoKeywords = $this->_setting['seo_keywords'];
     $this->_seoDescription = $this->_setting['seo_description'];
     //加载css,js
     Yii::app()->clientScript->registerCssFile($this->_stylePath . "/css/index.css");
     Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.js");
     Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.easytabs.min.js");
     //头部banner
     $index_top_banner = Ad::model()->getAdOne(4);
     //中部banner
     $index_mid_banner = Ad::model()->getAdOne(3);
     //底部banner
     $index_bottom_banner = Ad::model()->getAdOne(5);
     //最新资讯
     Yii::app()->cache && ($news_new = Yii::app()->cache->get('news_new'));
     if ($news_new == false) {
         $news_new = Post::model()->getList(array('limit' => 20));
         Yii::app()->cache && Yii::app()->cache->set('news_new', $news_new);
     }
     //热门资讯
     Yii::app()->cache && ($news_hot = Yii::app()->cache->get('news_host'));
     if ($news_hot == false) {
         $news_hot = Post::model()->getList(array('order' => 't.view_count DESC, t.id DESC', 'limit' => 20));
         Yii::app()->cache && Yii::app()->cache->set('news_hot', $news_hot);
     }
     //最新图集
     $image_new = Image::model()->getList(array('limit' => 10));
     //热门图集
     $image_hot = Image::model()->getList(array('limit' => 10, 'order' => 'view_count DESC, t.id DESC'));
     //最新软件
     $soft_new = Soft::model()->getList(array('limit' => 20));
     //热门软件
     $soft_hot = Soft::model()->getList(array('limit' => 10, 'order' => 'down_count DESC, t.id DESC'));
     //最新视频
     //$video_new = Video::model()->findAll("status=:status AND catalog_id = 13 ORDER BY id DESC Limit 20", array(':status'=>'Y'));
     //热门视频
     //$video_hot = Video::model()->findAll("status=:status AND catalog_id = 13 ORDER BY view_count DESC, video_score DESC, id DESC Limit 20", array(':status'=>'Y'));
     //友情链接
     $link_logos = Link::model()->findAll("logo !='' AND status_is='Y'", array('order' => 'sortorder ASC, id DESC'));
     $link_texts = Link::model()->findAll("logo ='' or logo is null AND status_is='Y'", array('order' => 'sortorder ASC, id DESC'));
     $this->render('index', compact(array('index_top_banner', 'index_mid_banner', 'index_bottom_banner', 'link_logos', 'link_texts', 'news_new', 'news_hot', 'image_new', 'image_hot', 'soft_new', 'soft_hot', 'video_new', 'video_hot')));
 }
Example #10
0
 public function run()
 {
     $ids = Yii::app()->request->getParam('id');
     $command = Yii::app()->request->getParam('command');
     empty($ids) && $this->controller->message('error', Yii::t('admin', 'No Select'));
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     $criteria = new CDbCriteria();
     $criteria->addInCondition('id', $ids);
     switch ($command) {
         case 'delete':
             //删除
             foreach ((array) $ids as $id) {
                 //删除关联的标签
                 TagData::model()->deleteAll('content_id =:id AND type =:type', array(':id' => $id, ':type' => $this->controller->_type_ids['post']));
             }
             Image::model()->deleteAll($criteria);
             break;
         case 'show':
             //显示
             Image::model()->updateAll(['status' => 'Y'], $criteria);
             break;
         case 'hidden':
             //隐藏
             Image::model()->updateAll(['status' => 'N'], $criteria);
             break;
         case 'commend':
             //图集推荐
             $content_id = implode(',', $ids);
             $type_key = 'image';
             $this->controller->redirect($this->controller->createUrl('recommend/create', array('content_id' => $content_id, 'type_key' => $type_key)));
             break;
         case 'stick':
             //图集置顶
             Image::model()->updateAll(['top_line' => 'Y'], $criteria);
             break;
         case 'cancelStick':
             //图集取消置顶
             Image::model()->updateAll(['top_line' => 'N'], $criteria);
             break;
         default:
             $this->controller->message('error', Yii::t('admin', 'Error Operation'));
     }
     $this->controller->message('success', Yii::t('admin', 'Batch Operate Success'));
 }
Example #11
0
 public function run()
 {
     $this->controller->layout = false;
     $id = intval(Yii::app()->request->getParam('id'));
     $special = Special::model()->findByPk($id);
     if (!$special) {
         throw new Exception(Yii::t('common', 'The requested page does not exist.'));
     }
     $this->controller->_seoTitle = $special->seo_title ? $special->seo_title : $special->title . ' - ' . $this->controller->_setting['site_name'];
     $this->controller->_seoKeywords = $special->seo_keywords;
     $this->controller->_seoDescription = $special->seo_description;
     //专题资讯
     $special_news = Post::model()->findAll(array('select' => 'id, title', 'condition' => 'special_id =' . $id . ' AND status ="' . Post::STATUS_SHOW . '"', 'limit' => 30));
     //专题图集
     $special_images = Image::model()->findAll(array('select' => 'id, title', 'condition' => 'special_id =' . $id . ' AND status ="' . Image::STATUS_SHOW . '"', 'limit' => 30));
     $this->controller->render('index', array('special' => $special, 'special_news' => $special_news, 'special_images' => $special_images));
 }
Example #12
0
 public function selectBySingerId($singer_id)
 {
     $criteria = new CDbCriteria();
     $criteria->select = '*';
     $criteria->condition = 'id=:singer_id';
     $criteria->params = array(':singer_id' => $singer_id);
     $result = Singer::model()->find($criteria);
     $image = Image::model()->selectByRow('singer', $singer_id);
     $style = Style::model()->selectBySingerId($singer_id);
     $result = $result['attributes'];
     if ($image) {
         $result['path'] = $image->path;
     }
     if ($style) {
         $result['style'] = $style;
     }
     return $result;
 }
Example #13
0
 public function run()
 {
     $id = Yii::app()->request->getParam('id');
     $post = Image::model()->findByPk(intval($id));
     if (false == $post || $post->status == 'N') {
         throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.'));
     }
     //更新浏览次数
     $post->updateCounters(array('view_count' => 1), 'id=:id', array('id' => $id));
     //seo信息
     $this->controller->_seoTitle = empty($post->seo_title) ? $post->title . ' - ' . $this->controller->_setting['site_name'] : $post->seo_title;
     $this->controller->_seoKeywords = empty($post->seo_keywords) ? $post->tags : $post->seo_keywords;
     $this->controller->_seoDescription = empty($post->seo_description) ? $this->controller->_seoDescription : $post->seo_description;
     //最近的图集
     $last_images = Image::model()->findAll(array('condition' => 'catalog_id = ' . $post->catalog_id, 'order' => 'id DESC', 'limit' => 10));
     //nav
     $navs = array();
     $navs[] = array('url' => $this->controller->createUrl('image/view', array('id' => $id)), 'name' => $post->title);
     $tplVar = array('post' => $post, 'navs' => $navs, 'last_images' => $last_images);
     $this->controller->render('view', $tplVar);
 }
Example #14
0
 /**
  * Ajax/Get-обёртка для редактирования изображения:
  *
  * @param int $id - id-изображения
  *
  * @return void
  **/
 public function actionEditImage($id = null)
 {
     if (($image = Image::model()->findByPk($id)) === null || $image->canChange() === false) {
         throw new CHttpException(404, Yii::t('GalleryModule.gallery', 'Page was not found!'));
     }
     if ((Yii::app()->getRequest()->getIsPostRequest() || Yii::app()->getRequest()->getIsAjaxRequest()) && Yii::app()->getRequest()->getPost('Image') !== null) {
         $image->setAttributes(Yii::app()->getRequest()->getPost('Image'));
         if ($image->validate() && $image->save()) {
             $message = Yii::t('GalleryModule.gallery', 'Image #{id} edited', ['{id}' => $id]);
             if (Yii::app()->getRequest()->getIsPostRequest() && Yii::app()->getRequest()->getIsAjaxRequest()) {
                 Yii::app()->ajax->success(['message' => $message, 'type' => 'saved']);
             }
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, $message);
             $this->redirect(['/gallery/gallery/show', 'id' => $image->gallery->id]);
         }
     }
     if (Yii::app()->getRequest()->getIsPostRequest() && Yii::app()->getRequest()->getIsAjaxRequest()) {
         Yii::app()->ajax->success(['form' => $this->renderPartial('_form', ['model' => $image], true)]);
     }
     $this->render('edit-image', ['model' => $image]);
 }
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $photo = Image::model()->findAllByAttributes(array('imageid' => $id));
     if (isset($_POST['News'])) {
         $photos = CUploadedFile::getInstancesByName('images');
         $url = array();
         foreach ($photos as $files) {
             $fn = $files->getTempName();
             $client_id = "c633cc927c486e6";
             $handle = fopen($fn, "r");
             $data = fread($handle, filesize($fn));
             $pvars = array('image' => base64_encode($data));
             $timeout = 30;
             $curl = curl_init();
             curl_setopt($curl, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
             curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
             curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id));
             curl_setopt($curl, CURLOPT_POST, 1);
             curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
             curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
             $out = curl_exec($curl);
             curl_close($curl);
             $pms = json_decode($out, true);
             array_push($url, $pms['data']['link']);
         }
         $model->attributes = $_POST['News'];
         if ($model->save()) {
             foreach ($url as $path) {
                 $model_image = new Image();
                 $model_image->imageid = $model->id;
                 $model_image->path = $path;
                 $model_image->save();
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model, 'photo' => $photo));
 }
Example #16
0
 public function actionRepair()
 {
     $images = Image::model()->findAll();
     foreach ($images as $image) {
         $c = new Comment();
         $c->img_id = $image->img_id;
         $c->create_time = time();
         $c->save();
     }
 }
Example #17
0
	</table>
</div>
<hr />

<?php 
$this->widget('zii.widgets.CListView', array('dataProvider' => $dataProvider, 'ajaxUpdate' => false, 'enablePagination' => false, 'itemsCssClass' => 'resultsholderfast', 'itemView' => '_thumbviewFast', 'viewData' => array()));
echo CHtml::endForm();
?>

<div id="metadataboxcontainer">
<?php 
// This is only processed once, when the results page is loaded for the first time
// the actual _metadatabox mouseover renderings are processed by the _thumbview
if (isset($dataProvider->data[0])) {
    if (isset($_GET['imageid'])) {
        $this->renderPartial('_metadatabox', array('dataProvider' => Image::model()->findByPk($_GET['imageid']), 'fastedit' => true));
    } else {
        $this->renderPartial('_metadatabox', array('dataProvider' => $dataProvider->data[0], 'fastedit' => true));
    }
} else {
    echo "Ei hakutuloksia.";
    // FIXME FIXME
}
?>
</div>

<div style="position:absolute;bottom:10px;right:10px;">
	<p>

	</p>
</div>
Example #18
0
 public function loadModel($id)
 {
     $model = Image::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.'));
     }
     return $model;
 }
Example #19
0
 public function run()
 {
     $this->controller->layout = false;
     $view_url = Yii::app()->request->getParam('view_url');
     $content_id = Yii::app()->request->getParam('content_id');
     $topic_type = Yii::app()->request->getParam('topic_type');
     $cur_url = Yii::app()->request->hostinfo . Yii::app()->request->getUrl();
     $post = false;
     //评论类型
     switch ($topic_type) {
         case 'post':
             $post = Post::model()->findByPk($content_id);
             break;
         case 'image':
             $post = Image::model()->findByPk($content_id);
             break;
         case 'soft':
             $post = Soft::model()->findByPk($content_id);
             break;
         case 'video':
             $post = Video::model()->findByPk($content_id);
             break;
     }
     if (!$post) {
         throw new CHttpException(404, Yii::t('admin', 'Loading Error'));
     }
     //评论内容
     $model = new Comment('create');
     $criteria = new CDbCriteria();
     $criteria->with = array('user');
     $criteria->addColumnCondition(array('content_id' => $content_id));
     $criteria->addColumnCondition(array('t.status' => Comment::STATUS_SHOW));
     $criteria->addColumnCondition(array('type' => $this->controller->_type_ids[$topic_type]));
     $criteria->addCondition('u.uid > 0');
     $criteria->order = 't.id DESC';
     $criteria->select = 't.id, user_id, content_id, content, t.create_time ';
     //分页
     $count = $model->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 10;
     $criteria->limit = $pages->pageSize;
     $criteria->offset = $pages->currentPage * $pages->pageSize;
     $comments = $model->findAll($criteria);
     //回复
     if ($comments) {
         foreach ($comments as $c) {
             $replies[$c->id] = Reply::model()->with('user')->findAll(array('condition' => 'cid = ' . $c->id . ' AND t.status = "' . Reply::STATUS_SHOW . '" AND u.uid > 0', 'order' => 'id'));
         }
     } else {
         $comments = array();
         $replies = array();
     }
     if (Yii::app()->request->isPostRequest) {
         $uid = Yii::app()->user->id;
         if (!$uid) {
             $this->message('script', Yii::t('common', 'You Need Login'));
         }
         $model->attributes = $_POST['Comment'];
         $model->content_id = $content_id;
         $model->type = $this->controller->_type_ids[$topic_type];
         $model->user_id = $uid;
         $model->status = 'N';
         $model->client_ip = Yii::app()->request->userHostAddress;
         $model->create_time = time();
         $ret_url = $_POST['ret_url'];
         if ($model->save()) {
             $this->controller->message('script', Yii::t('common', 'Submit Success, Waiting Pass'), $ret_url);
         }
     }
     $data = array('model' => $model, 'view_url' => $view_url, 'cur_url' => $cur_url, 'comments' => $comments, 'pagebar' => $pages, 'replies' => $replies);
     $this->controller->render('create', $data);
 }
 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));
 }
Example #21
0
 public function actionShareApi($img_id)
 {
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $image = Image::model()->findByPk($img_id);
         $image->shares++;
         $image->saveAttributes(array('shares'));
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollback();
         throw $e;
     }
     $this->echoJsonData(array('isSuccess' => TRUE));
 }
Example #22
0
 /**
  * 提交评论
  *
  * @return [type] [description]
  */
 public function actionCreate()
 {
     $this->layout = false;
     $view_url = $this->_request->getParam('view_url');
     $topic_id = $this->_request->getParam('topic_id');
     $topic_type = $this->_request->getParam('topic_type');
     $cur_url = $this->_request->hostinfo . $this->_request->getUrl();
     $post = false;
     //评论类型
     switch ($topic_type) {
         case 'post':
             $post = Post::model()->findByPk($topic_id);
             break;
         case 'image':
             $post = Image::model()->findByPk($topic_id);
             break;
         case 'soft':
             $post = Soft::model()->findByPk($topic_id);
             break;
         case 'video':
             $post = Video::model()->findByPk($topic_id);
             break;
     }
     if (!$post) {
         throw new CHttpException(404, Yii::t('admin', 'Submit Error'));
         break;
     }
     //评论内容
     $model = new Comment('create');
     $criteria = new CDbCriteria();
     $condition = "topic_id={$topic_id} AND status='Y' AND type={$this->_type_ids[$topic_type]}";
     $criteria->condition = $condition;
     $criteria->order = 'id DESC';
     $criteria->select = "id, user_id, topic_id, content, create_time ";
     //分页
     $count = $model->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 10;
     $criteria->limit = $pages->pageSize;
     $criteria->offset = $pages->currentPage * $pages->pageSize;
     $comments = $model->findAll($criteria);
     //回复
     if ($comments) {
         foreach ((array) $comments as $c) {
             $replies[$c->id] = Reply::model()->findAll('cid=:cid AND status=:status ORDER BY id', array(':cid' => $c->id, ':status' => 'Y'));
         }
     }
     //加载css,js
     Yii::app()->clientScript->registerCssFile($this->_stylePath . "/css/comment.css");
     Yii::app()->clientScript->registerCssFile($this->_static_public . "/js/kindeditor/code/prettify.css");
     Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.js");
     Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/kindeditor/code/prettify.js", CClientScript::POS_END);
     if ($this->_request->isPostRequest) {
         $uid = Yii::app()->user->id;
         if (!$uid) {
             $this->message('script', Yii::t('common', 'You Need Login'));
         }
         $model->attributes = $_POST['Comment'];
         $model->topic_id = $topic_id;
         $model->type = $this->_type_ids[$topic_type];
         $model->user_id = $uid;
         $model->status = 'N';
         $model->client_ip = $this->_request->userHostAddress;
         $model->create_time = time();
         $ret_url = $_POST['ret_url'];
         if ($model->save()) {
             $this->message('script', Yii::t('common', 'Submit Success, Waiting Pass'), $ret_url);
             //$this->redirect($ret_url);
         }
     }
     $data = array('model' => $model, 'view_url' => $view_url, 'cur_url' => $cur_url, 'comments' => $comments, 'pagebar' => $pages, 'replies' => $replies);
     $this->render('create', $data);
 }
 /**
  * Ajax/Get-обёртка для удаления изображения:
  *
  * @param int $id - id-изображения
  * @param string $method - тип с помощью чего удаляем
  *
  * @return void
  *
  * @throws CHttpException
  **/
 public function actionDeleteImage($id = null, $method = null)
 {
     if (($image = Image::model()->findByPk($id)) === null || $image->canChange() === false) {
         throw new CHttpException(404, Yii::t('GalleryModule.gallery', 'Page was not found!'));
     }
     $message = Yii::t('GalleryModule.gallery', 'Image #{id} {result} deleted', ['{id}' => $id, '{result}' => ($result = $image->delete()) ? Yii::t('GalleryModule.gallery', 'success') : Yii::t('GalleryModule.gallery', 'not')]);
     if (Yii::app()->getRequest()->getIsPostRequest() && Yii::app()->getRequest()->getIsAjaxRequest) {
         $result === true ? Yii::app()->ajax->success($message) : Yii::app()->ajax->failure($message);
     }
     Yii::app()->getUser()->setFlash($result ? yupe\widgets\YFlashMessages::SUCCESS_MESSAGE : yupe\widgets\YFlashMessages::ERROR_MESSAGE, $message);
     $this->redirect(Yii::app()->getRequest()->urlReferer($this->createAbsoluteUrl('gallery/default/images')));
 }
Example #24
0
 /**
  * nextCdId gives the cd and id values for the next uploaded image,
  * as in, the first blank spot on the database
  * @return array with cd and id which are the next blank row on the database
  */
 public function nextCdId($cdbox)
 {
     // Constructs a criteria which selects the maximum cd column value
     $criteria = new CDbCriteria();
     $criteria->select = "MAX(cd) as max";
     $maxcd = Image::model()->find($criteria);
     // if the user has defined his cdbox, the defined cd will be used
     if ($cdbox != 'false') {
         $maxcd->max = str_pad($cdbox, 4, '0', STR_PAD_LEFT);
     }
     // Constructs a criteria which selects the maximum id column value WITH the max cd value
     $idcriteria = new CDbCriteria();
     $idcriteria->select = "MAX(id) as max";
     $idcriteria->condition = 'cd=:cd';
     // the cd value must be the highest cd value
     $idcriteria->params = array(':cd' => $maxcd->max);
     $maxid = Image::model()->find($idcriteria);
     // calculates the cd and id values for the next image, always one more to id
     // and if id is 9999, spins the cd value to the next higher and id to 0001
     if ($maxid->max == 9999) {
         // this must be as a string value, if inserted as 0001 the leading zeroes will
         // disappear, leading to malfunctioning filenames
         $nextid = '0001';
         $nextcd = $maxcd->max + 1;
     } else {
         $nextcd = $maxcd->max;
         // as above, this needs padding, leading zeroes are added
         $nextid = $maxid->max + 1;
         $nextid = str_pad($nextid, 4, '0', STR_PAD_LEFT);
     }
     return array('cd' => $nextcd, 'id' => $nextid);
 }
Example #25
0
 /**
  * 浏览详细内容
  */
 public function actionView($id)
 {
     $post = Image::model()->findByPk(intval($id));
     if (false == $post || $post->status == 'N') {
         throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.'));
     }
     //更新浏览次数
     $post->updateCounters(array('view_count' => 1), 'id=:id', array('id' => $id));
     //seo信息
     $this->_seoTitle = empty($post->seo_title) ? $post->title . ' - ' . $this->_setting['site_name'] : $post->seo_title;
     $this->_seoKeywords = empty($post->seo_keywords) ? $post->tags : $post->seo_keywords;
     $this->_seoDescription = empty($post->seo_description) ? $this->_seoDescription : $post->seo_description;
     $catalogArr = Catalog::model()->findByPk($post->catalog_id);
     //加载css,js
     Yii::app()->clientScript->registerCssFile($this->_stylePath . "/css/view.css");
     Yii::app()->clientScript->registerCssFile($this->_static_public . "/js/kindeditor/code/prettify.css");
     Yii::app()->clientScript->registerCssFile($this->_static_public . "/js/discuz/zoom.css");
     Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.js");
     Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/discuz/common.js");
     Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/discuz/zoom.js");
     Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/kindeditor/code/prettify.js", CClientScript::POS_END);
     //最近的图集
     $last_images = Image::model()->findAll(array('condition' => 'catalog_id = ' . $post->catalog_id, 'order' => 'id DESC', 'limit' => 10));
     //nav
     $navs = array();
     $navs[] = array('url' => $this->createUrl('image/view', array('id' => $id)), 'name' => $post->title);
     $tplVar = array('post' => $post, 'navs' => $navs, 'last_images' => $last_images);
     $this->render('view', $tplVar);
 }
Example #26
0
 /**
  * Loads a specific image model.
  * @param integer $id the image id.
  * @return Image
  */
 public function load($id)
 {
     return Image::model()->findByPk($id);
 }
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
Example #28
0
 /**
  * Возвращает модель по указанному идентификатору
  * Если модель не будет найдена - возникнет HTTP-исключение.
  *
  * @param integer $id идентификатор нужной модели
  *
  * @return void
  *
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     if (($model = Image::model()->findByPk($id)) === null) {
         throw new CHttpException(404, Yii::t('ImageModule.image', 'Requested page was not found!'));
     }
     return $model;
 }
Example #29
0
 public function actionSendGiftApi($item_id, $aid, $img_id = NULL, $is_shake = FALSE)
 {
     $itemList = Util::loadConfig('items');
     $item = $itemList[$item_id];
     if (isset($item)) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $user = User::model()->findByPk($this->usr_id);
             $ex_gold = $user->gold;
             $ex_exp = $user->exp;
             $ex_lv = $user->lv;
             if (!$is_shake) {
                 $items = unserialize($user->items);
                 if (isset($items[$item_id]) && $items[$item_id] > 0) {
                     $items[$item_id]--;
                     $user->items = serialize($items);
                     $user->saveAttributes(array('items'));
                 } else {
                     throw new PException('礼物数量不足');
                 }
             }
             $user->sendGift($is_shake);
             $circle = Circle::model()->findByPk(array('aid' => $aid, 'usr_id' => $this->usr_id));
             if (isset($circle)) {
                 $ex_rank = $circle->rank;
                 $circle->t_contri += $item['rq'];
                 $circle->m_contri += $item['rq'];
                 $circle->w_contri += $item['rq'];
                 $circle->d_contri += $item['rq'];
                 $user->contributionChange($circle);
                 $circle->saveAttributes(array('t_contri', 'm_contri', 'w_contri', 'd_contri'));
             }
             $animal = Animal::model()->findByPk($aid);
             $animal->d_rq += $item['rq'];
             $animal->m_rq += $item['rq'];
             $animal->w_rq += $item['rq'];
             $animal->t_rq += $item['rq'];
             if ($animal->d_rq < 0) {
                 $animal->d_rq = 0;
             }
             if ($animal->m_rq < 0) {
                 $animal->m_rq = 0;
             }
             if ($animal->w_rq < 0) {
                 $animal->w_rq = 0;
             }
             if ($animal->t_rq < 0) {
                 $animal->t_rq = 0;
             }
             $a_items = unserialize($animal->items);
             if (isset($a_items[$item_id])) {
                 $a_items[$item_id]++;
             } else {
                 $a_items[$item_id] = 1;
             }
             $animal->items = serialize($a_items);
             $animal->saveAttributes(array('d_rq', 'm_rq', 'w_rq', 't_rq', 'items'));
             if (isset($img_id)) {
                 $image = Image::model()->findByPk($img_id);
                 $image->gifts++;
                 if (isset($image->senders) && $image->senders != '') {
                     $image->senders = $this->usr_id . ',' . $image->senders;
                 } else {
                     $image->senders = $this->usr_id;
                 }
                 $image->saveAttributes(array('gifts', 'senders'));
             }
             if ($is_shake) {
                 $session = Yii::app()->session;
                 if (isset($session[$aid . '_shake_count'])) {
                     $session[$aid . '_shake_count'] -= 1;
                 } else {
                     $session[$aid . '_shake_count'] = 3;
                 }
             }
             $news = new News();
             $news->aid = $aid;
             $news->type = $item['rq'] >= 0 ? 4 : 7;
             $news->create_time = time();
             $news->content = serialize(array('usr_id' => $user->usr_id, 'u_name' => $user->name, 'rank' => isset($circle) ? $circle->rank : -1, 'item_id' => $item_id, 'rq' => $item['rq']));
             $news->save();
             $transaction->commit();
             $this->echoJsonData(array('exp' => $user->exp - $ex_exp, 'gold' => $user->gold - $ex_gold, 'lv' => $user->lv - $ex_lv, 'rank' => isset($circle) ? $circle->rank - $ex_rank : -1));
         } catch (Exception $e) {
             $transaction->rollback();
             throw $e;
         }
     } else {
         throw new PException('礼物不存在');
     }
 }
 public function loadModel($id)
 {
     if (($model = Image::model()->findByPk($id)) === null) {
         throw new CHttpException(404, 'Страница не найдена');
     }
     return $model;
 }