コード例 #1
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.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = ArticleMedia::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Phrase::trans(193, 0));
     }
     return $model;
 }
コード例 #2
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.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = ArticleMedia::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('phrase', 'The requested page does not exist.'));
     }
     return $model;
 }
コード例 #3
0
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionView($id)
 {
     $setting = ArticleSetting::model()->findByPk(1, array('select' => 'meta_keyword'));
     $model = $this->loadModel($id);
     Articles::model()->updateByPk($id, array('view' => $model->view + 1));
     $photo = ArticleMedia::model()->findAll(array('condition' => 'article_id = :id', 'params' => array(':id' => $model->article_id), 'order' => 'media_id DESC'));
     //Random Article
     $criteria = new CDbCriteria();
     $criteria->condition = 'publish = :publish AND published_date <= curdate() AND article_id <> :id';
     $criteria->params = array(':publish' => 1, ':id' => $id);
     $criteria->compare('cat_id', $model->cat_id);
     $criteria->order = 'RAND()';
     $criteria->limit = 4;
     $random = Articles::model()->findAll($criteria);
     $this->pageTitleShow = true;
     $this->pageTitle = $model->title;
     $this->pageDescription = Utility::shortText(Utility::hardDecode($model->body), 300);
     $this->pageMeta = ArticleTag::getKeyword($setting->meta_keyword, $id);
     if ($model->media_id != 0 && $model->cover->media != '') {
         if (in_array($model->article_type, array('1', '3'))) {
             $media = Yii::app()->request->baseUrl . '/public/article/' . $id . '/' . $model->cover->media;
         } else {
             if ($model->article_type == 2) {
                 $media = 'http://www.youtube.com/watch?v=' . $model->cover->media;
             }
         }
         $this->pageImage = $media;
     }
     $this->render('front_view', array('model' => $model, 'photo' => $photo, 'random' => $random));
 }
コード例 #4
0
 /**
  * After save attributes
  */
 protected function afterSave()
 {
     parent::afterSave();
     $article_path = "public/article/" . $this->article_id;
     if ($this->isNewRecord && in_array($this->article_type, array(1, 3))) {
         // Add article directory
         if (!file_exists($article_path)) {
             @mkdir($article_path, 0777, true);
             // Add file in article directory (index.php)
             $newFile = $article_path . '/index.php';
             $FileHandle = fopen($newFile, 'w');
         }
     }
     if ($this->article_type == 1) {
         if ($this->isNewRecord || !$this->isNewRecord && ArticleSetting::getInfo('media_limit') == 1) {
             $this->media = CUploadedFile::getInstance($this, 'media');
             if ($this->media instanceof CUploadedFile) {
                 $fileName = time() . '_' . $this->article_id . '_' . Utility::getUrlTitle($this->title) . '.' . strtolower($this->media->extensionName);
                 if ($this->media->saveAs($article_path . '/' . $fileName)) {
                     if ($this->isNewRecord || !$this->isNewRecord && $this->media_id == 0) {
                         $images = new ArticleMedia();
                         $images->article_id = $this->article_id;
                         $images->cover = 1;
                         $images->media = $fileName;
                         $images->save();
                     } else {
                         if ($this->old_media != '' && file_exists($article_path . '/' . $this->old_media)) {
                             rename($article_path . '/' . $this->old_media, 'public/article/verwijderen/' . $this->article_id . '_' . $this->old_media);
                         }
                         $images = ArticleMedia::model()->findByPk($this->media_id);
                         $images->media = $fileName;
                         $images->update();
                     }
                 }
             }
         }
     } else {
         if ($this->article_type == 2) {
             if ($this->isNewRecord) {
                 $video = new ArticleMedia();
                 $video->article_id = $this->article_id;
                 $video->cover = 1;
                 $video->media = $this->video;
                 $video->save();
             } else {
                 if ($this->media_id == 0) {
                     $video = new ArticleMedia();
                     $video->article_id = $this->article_id;
                     $video->cover = 1;
                     $video->media = $this->video;
                     if ($video->save()) {
                         $data = Articles::model()->findByPk($this->article_id);
                         $data->media_id = $video->media_id;
                         $data->update();
                     }
                 } else {
                     $video = ArticleMedia::model()->findByPk($this->media_id);
                     $video->media = $this->video;
                     $video->update();
                 }
             }
         }
     }
     $this->file = CUploadedFile::getInstance($this, 'file');
     if ($this->file instanceof CUploadedFile) {
         $fileName = time() . '_' . $this->article_id . '_' . Utility::getUrlTitle($this->title) . '.' . strtolower($this->file->extensionName);
         if ($this->file->saveAs($article_path . '/' . $fileName)) {
             if (!$this->isNewRecord && $this->media_file != '' && file_exists($article_path . '/' . $this->old_file)) {
                 rename($article_path . '/' . $this->old_file, 'public/article/verwijderen/' . $this->article_id . '_' . $this->old_file);
             }
             $article = Articles::model()->findByPk($this->article_id);
             $article->media_file = $fileName;
             $article->update();
         }
     }
     // Add Keyword
     if (!$this->isNewRecord) {
         if ($this->keyword != '') {
             $model = OmmuTags::model()->find(array('select' => 'tag_id, body', 'condition' => 'publish = 1 AND body = :body', 'params' => array(':body' => $this->keyword)));
             $tag = new ArticleTag();
             $tag->article_id = $this->article_id;
             if ($model != null) {
                 $tag->tag_id = $model->tag_id;
             } else {
                 $data = new OmmuTags();
                 $data->body = $this->keyword;
                 if ($data->save()) {
                     $tag->tag_id = $data->tag_id;
                 }
             }
             $tag->save();
         }
     }
     // Reset headline
     if (ArticleSetting::getInfo('headline') == 1) {
         if ($this->headline == 1) {
             self::model()->updateAll(array('headline' => 0), array('condition' => 'article_id != :id AND cat_id = :cat', 'params' => array(':id' => $this->article_id, ':cat' => $this->cat_id)));
         }
     } else {
     }
 }
コード例 #5
0
$this->breadcrumbs = array('Articles' => array('manage'), Phrase::trans($model->cat->name, 2), $model->title);
$cs = Yii::app()->getClientScript();
$cs->registerScriptFile(Yii::app()->request->baseUrl . '/externals/article/plugin/jquery.jcarousellite.min.js', CClientScript::POS_END);
$js = <<<EOP
\t\t\$("#module .slider-box").jCarouselLite({
\t\t\tbtnNext: ".slider .next",
\t\t\tbtnPrev: ".slider .prev",
\t\t\tspeed: 800,
\t\t\tvisible: 4
\t\t});
EOP;
count($photo > 1) ? $cs->registerScript('jcarousellite', $js, CClientScript::POS_END) : '';
if ($model->media_id != 0 && !isset($_GET['photo'])) {
    $images = Yii::app()->request->baseUrl . '/public/article/' . $model->article_id . '/' . $model->cover->media;
} else {
    $mediaPhoto = ArticleMedia::model()->findByPk($_GET['photo']);
    $images = Yii::app()->request->baseUrl . '/public/article/' . $mediaPhoto->article_id . '/' . $mediaPhoto->media;
}
?>

<div class="meta">
	<i class="fa fa-calendar-check-o"></i><?php 
echo Utility::dateFormat($model->published_date);
?>
	<i class="fa fa-bookmark-o"></i><?php 
echo $model->user->displayname;
?>
	<?php 
if ($model->media_file != '') {
    ?>
<i class="fa fa-download"></i><?php