Esempio n. 1
0
 public function sitmap()
 {
     $this->load->library('Sitemap');
     // 基礎設定
     $domain = 'http://www.zeusdesign.com.tw';
     $sit_map = new Sitemap($domain);
     $sit_map->setPath(FCPATH . 'sitemap' . DIRECTORY_SEPARATOR);
     $sit_map->setDomain($domain);
     // main pages
     $sit_map->addItem('/', '0.5', 'weekly', date('c'));
     $sit_map->addItem('/abouts/', '0.5', 'weekly', date('c'));
     $sit_map->addItem('/contacts/', '0.5', 'weekly', date('c'));
     $sit_map->addItem('/works/', '0.8', 'daily', date('c'));
     $sit_map->addItem('/articles/', '0.8', 'daily', date('c'));
     // all articles
     foreach (Article::find('all', array('select' => 'id, title, updated_at', 'order' => 'id DESC', 'conditions' => array('is_visibled = ? AND destroy_user_id IS NULL', Article::IS_VISIBLED))) as $article) {
         $sit_map->addItem('/article/' . $article->site_show_page_last_uri(), '1', 'daily', $article->updated_at->format('c'));
     }
     // all article tags
     foreach (ArticleTag::all(array('select' => 'id')) as $tag) {
         $sit_map->addItem('/article-tag/' . $tag->id . '/articles/', '0.8', 'daily', date('c'));
     }
     // all works
     foreach (Work::find('all', array('select' => 'id, title, updated_at', 'order' => 'id DESC', 'conditions' => array('is_enabled = ? AND destroy_user_id IS NULL', Work::ENABLE_YES))) as $work) {
         $sit_map->addItem('/work/' . $work->site_show_page_last_uri(), '1', 'daily', $work->updated_at->format('c'));
     }
     // all work tags
     foreach (WorkTag::all(array('select' => 'id')) as $tag) {
         $sit_map->addItem('/work-tag/' . $tag->id . '/works/', '0.8', 'daily', date('c'));
     }
     $sit_map->createSitemapIndex($domain . '/sitemap/', date('c'));
 }
Esempio n. 2
0
 public function __construct()
 {
     parent::__construct();
     if (!(($id = $this->uri->rsegments(3, 0)) && (is_numeric($id) ? $this->tag = ArticleTag::find_by_id($id) : ($this->tag = ArticleTag::find_by_name(trim(urldecode($id))))))) {
         return redirect_message(array('articles'), array('_flash_message' => '找不到該筆資料。'));
     }
     if (in_array($this->uri->rsegments(2, 0), array('edit', 'update', 'destroy', 'sort'))) {
         if (!(($id = $this->uri->rsegments(4, 0)) && ($this->article = Article::find_by_id($id)))) {
             return redirect_message(array('articles', $this->tag->id, 'articles'), array('_flash_message' => '找不到該筆資料。'));
         }
     }
     $this->add_js(resource_url('resource', 'javascript', 'jquery-timeago_v1.3.1', 'jquery.timeago.js'))->add_js(resource_url('resource', 'javascript', 'jquery-timeago_v1.3.1', 'locales', 'jquery.timeago.zh-TW.js'));
 }
Esempio n. 3
0
 public function destroy()
 {
     $tag = $this->tag;
     $delete = ArticleTag::transaction(function () use($tag) {
         return $tag->destroy();
     });
     if (!$delete) {
         return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '刪除失敗!'));
     }
     $this->_clean_cell();
     return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '刪除成功!'));
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionEdit($id)
 {
     $model = $this->loadModel($id);
     $setting = ArticleSetting::model()->findByPk(1, array('select' => 'type_active, media_limit, meta_keyword'));
     $tag = ArticleTag::model()->findAll(array('condition' => 'article_id = :id', 'params' => array(':id' => $model->article_id)));
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['Articles'])) {
         $model->attributes = $_POST['Articles'];
         /*
         if($model->article_type == 1 && $setting->media_limit != 1) {
         	$jsonError = CActiveForm::validate($model);
         	if(strlen($jsonError) > 2) {
         		$errors = $model->getErrors();
         		$summary['msg'] = "<div class='errorSummary'><strong>".Yii::t('phrase', 'Please fix the following input errors:')."</strong>";
         		$summary['msg'] .= "<ul>";
         		foreach($errors as $key => $value) {
         			$summary['msg'] .= "<li>{$value[0]}</li>";
         		}
         		$summary['msg'] .= "</ul></div>";
         
         		$message = json_decode($jsonError, true);
         		$merge = array_merge_recursive($summary, $message);
         		$encode = json_encode($merge);
         		echo $encode;
         
         	} else {
         		if(isset($_GET['enablesave']) && $_GET['enablesave'] == 1) {
         			if($model->save()) {
         				echo CJSON::encode(array(
         					'type' => 0,
         					'msg' => '<div class="errorSummary success"><strong>'.Yii::t('phrase', 'Article success updated.').'</strong></div>',
         				));
         			} else {
         				print_r($model->getErrors());
         			}
         		}
         	}
         	Yii::app()->end();
         
         } else {
         */
         if ($model->save()) {
             Yii::app()->user->setFlash('success', Yii::t('phrase', 'Article success updated.'));
             $this->redirect(array('edit', 'id' => $model->article_id));
         }
         //}
     }
     $this->pageTitle = Phrase::trans(26032, 1) . ': ' . $model->title;
     $this->pageDescription = '';
     $this->pageMeta = '';
     $this->render('admin_edit', array('model' => $model, 'setting' => $setting, 'tag' => $tag));
 }
Esempio n. 5
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));
     //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->order = 'RAND()';
     $criteria->addInCondition('cat_id', $model->cat_id);
     $criteria->limit = 4;
     $random = Articles::model()->findAll($criteria);
     $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, 'random' => $random));
 }
Esempio n. 6
0
 public function update()
 {
     if (!$this->has_post()) {
         return redirect_message(array('admin', $this->get_class(), $this->article->id, 'edit'), array('_flash_message' => '非 POST 方法,錯誤的頁面請求。'));
     }
     $posts = OAInput::post();
     $posts['content'] = OAInput::post('content', false);
     $cover = OAInput::file('cover');
     if (!((string) $this->article->cover || $cover)) {
         return redirect_message(array('admin', $this->get_class(), $this->article->id, 'edit'), array('_flash_message' => '請選擇圖片(gif、jpg、png)檔案!', 'posts' => $posts));
     }
     if ($msg = $this->_validation_posts($posts)) {
         return redirect_message(array('admin', $this->get_class(), $this->article->id, 'edit'), array('_flash_message' => $msg, 'posts' => $posts));
     }
     if ($columns = array_intersect_key($posts, $this->article->table()->columns)) {
         foreach ($columns as $column => $value) {
             $this->article->{$column} = $value;
         }
     }
     $article = $this->article;
     $update = ArticleTag::transaction(function () use($article, $cover) {
         if (!$article->save()) {
             return false;
         }
         if ($cover && !$article->cover->put($cover)) {
             return false;
         }
         return true;
     });
     if (!$update) {
         return redirect_message(array('admin', $this->get_class(), $this->article->id, 'edit'), array('_flash_message' => '更新失敗!', 'posts' => $posts));
     }
     $ori_ids = column_array($article->mappings, 'article_tag_id');
     if (($del_ids = array_diff($ori_ids, $posts['tag_ids'])) && ($mappings = ArticleTagMapping::find('all', array('select' => 'id, article_tag_id', 'conditions' => array('article_id = ? AND article_tag_id IN (?)', $article->id, $del_ids))))) {
         foreach ($mappings as $mapping) {
             ArticleTagMapping::transaction(function () use($mapping) {
                 return $mapping->destroy();
             });
         }
     }
     if (($add_ids = array_diff($posts['tag_ids'], $ori_ids)) && ($tags = ArticleTag::find('all', array('select' => 'id', 'conditions' => array('id IN (?)', $add_ids))))) {
         foreach ($tags as $tag) {
             ArticleTagMapping::transaction(function () use($tag, $article) {
                 return verifyCreateOrm(ArticleTagMapping::create(Array_intersect_key(array('article_tag_id' => $tag->id, 'article_id' => $article->id), ArticleTagMapping::table()->columns)));
             });
         }
     }
     if ($article->sources) {
         foreach ($article->sources as $source) {
             ArticleSource::transaction(function () use($source) {
                 return $source->destroy();
             });
         }
     }
     if ($posts['sources']) {
         foreach ($posts['sources'] as $i => $source) {
             ArticleSource::transaction(function () use($i, $source, $article) {
                 return verifyCreateOrm(ArticleSource::create(array_intersect_key(array_merge($source, array('article_id' => $article->id, 'sort' => $i)), ArticleSource::table()->columns)));
             });
         }
     }
     $this->_clean_cell($article);
     return redirect_message(($url = Session::getData('admin_articles_index_url')) ? $url : array('admin', $this->get_class()), array('_flash_message' => '更新成功!'));
 }
Esempio n. 7
0
 /**
  * Load instances of Article entities that is tagged with the ArticleTag indicated by the tag param
  *
  * @access public
  * @param ArticleTag $tag
  * @param array $options (Optional) Read documentation on parseOptions for details
  * @return array
  */
 public function allWithTag(ArticleTag $tag, $options = null)
 {
     $tagDAO = ArticleTagDAO::getInstance();
     $taggedDAO = TaggedArticleDAO::getInstance();
     $this->resetQueryStrings();
     $this->query_reset_lock = true;
     $this->query_joins = " INNER JOIN {$taggedDAO->getTableName()} ON {$this->tableName}.id = {$taggedDAO->getTableName()}.articleId INNER JOIN {$tagDAO->getTableName()} ON {$taggedDAO->getTableName()}.tagId = {$tagDAO->getTableName()}.id ";
     $this->query_where = "WHERE {$tagDAO->getTableName()}.id = ?";
     $this->query_params = array($tag->getId());
     $result_array = $this->all($options);
     $this->query_reset_lock = false;
     return $result_array;
 }
 /**
  * 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 = ArticleTag::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('phrase', 'The requested page does not exist.'));
     }
     return $model;
 }
Esempio n. 9
0
' placeholder='請輸入標題..' maxlength='200' pattern='.{1,200}' required title='輸入標題!' autofocus />
        </td>
      </tr>

      <tr>
        <th>封 面:</th>
        <td>
          <?php 
echo (string) $article->cover ? img($article->cover->url('100x100c'), false, 'class="cover"') : '';
?>
          <input type='file' name='cover' value='' />
        </td>
      </tr>

<?php 
if ($tags = ArticleTag::all()) {
    ?>
        <tr>
          <th>標 籤:</th>
          <td>
      <?php 
    $tag_ids = isset($posts['tag_ids']) ? $posts['tag_ids'] : column_array($article->mappings, 'article_tag_id');
    foreach ($tags as $tag) {
        ?>
              <label><input type='checkbox' name='tag_ids[]' value='<?php 
        echo $tag->id;
        ?>
'<?php 
        echo $tag_ids && in_array($tag->id, $tag_ids) ? ' checked' : '';
        ?>
/><div><?php 
 /**
  * Run method with main page logic
  * 
  * Populate template and display form for creating a new article entry. For POST requests,
  * validate form data and save information to database. Available to admins only
  * @access public
  */
 public function run()
 {
     $session = Session::getInstance();
     $user = $session->getUser();
     if (!$user || !$user->isAdmin()) {
         $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR);
         header("Location: " . BASE_URL);
         return;
     }
     $form_errors = array();
     $form_values = array("title" => "", "content" => "", "postDate" => "", "published" => "", "tags" => "");
     $articleDAO = ArticleDAO::getInstance();
     $tagDAO = ArticleTagDAO::getInstance();
     if (!empty($_POST)) {
         $form_values["title"] = isset($_POST["title"]) ? trim($_POST["title"]) : "";
         $form_values["content"] = isset($_POST["content"]) ? trim($_POST["content"]) : "";
         $form_values["postDate"] = isset($_POST["postDate"]) ? trim($_POST["postDate"]) : "";
         $form_values["published"] = isset($_POST["published"]) ? trim($_POST["published"]) : "";
         $form_values["tags"] = isset($_POST["tags"]) ? trim($_POST["tags"]) : "";
         if (empty($form_values["title"])) {
             $form_errors["title"] = "No title specified";
         }
         if (empty($form_values["content"])) {
             $form_errors["content"] = "No content specified";
         }
         if (empty($form_values["postDate"])) {
             $form_errors["postDate"] = "No post date specified";
         } else {
             if (strtotime($_POST["postDate"]) == 0) {
                 $form_errors["postDate"] = "An invalid post date was specified";
                 $form_values["postDate"] = "";
             }
         }
         if ($form_values["published"] != "true" && $form_values["published"] != "false") {
             $form_errors["published"] = "Invalid published choice";
         }
         if (empty($form_errors)) {
             $article = new Article();
             $article->setTitle($form_values["title"]);
             $article->setContent($form_values["content"]);
             $article->setPostDate(strtotime($form_values["postDate"]));
             $article->setUpdateDate(0);
             $published = $form_values["published"] == "true" ? 1 : 0;
             $article->setPublished($published);
             $article->setUserId($user->id);
             //$article->setTags ($form_values["tags"]);
             $sorted_tag_array = ArticleTag::tagsFromString($form_values["tags"]);
             $sorted_tags = implode(" ", $sorted_tag_array);
             $article->setTags($sorted_tags);
             if ($articleDAO->insert($article)) {
                 $tagDAO->updateTags($article);
                 $session->setMessage("Article details saved");
                 header("Location: edit_article.php?id={$article->id}");
                 return;
             } else {
                 $session->setMessage("Article details could not be saved", Session::MESSAGE_ERROR);
             }
         }
     }
     $this->template->render(array("title" => "Create Article", "extra_header" => joinPath("headers", "jscal_header_tpl.php"), "main_page" => "create_article_tpl.php", "session" => $session, "form_errors" => $form_errors, "form_values" => $form_values));
 }
Esempio n. 11
0
 /**
  * Determine new tags for an article and now unused tags for an Article. Insert new ArticleTag and TaggedArticle entities and delete any unused tags by deleting the associated TaggedArticle entities
  *
  * @access public
  * @param Article $article
  */
 public function updateTags(Article $article)
 {
     $articleDAO = ArticleDAO::getInstance();
     $taggedDAO = TaggedArticleDAO::getInstance();
     // Obtain current tags for an article
     $this->resetQueryStrings();
     $this->query_reset_lock = true;
     $this->query_joins = " INNER JOIN {$taggedDAO->getTableName()} ON {$this->tableName}.id = {$taggedDAO->getTableName()}.tagId INNER JOIN {$articleDAO->getTableName()} ON {$taggedDAO->getTableName()}.articleId = {$articleDAO->getTableName()}.id ";
     $this->query_where = "WHERE {$articleDAO->getTableName()}.id = ?";
     $this->query_params = array($article->getId());
     $current_tags_array = $this->all();
     $this->query_reset_lock = false;
     // Remove unused tags
     $updated_tags = ArticleTag::tagsFromString($article->getTags());
     $tags_to_remove = array();
     foreach ($current_tags_array as $tag) {
         if (!in_array($tag->getName(), $updated_tags)) {
             $tags_to_remove[] = $tag->getId();
         }
     }
     //print_r ($tags_to_remove);
     if (!empty($tags_to_remove)) {
         $status = $taggedDAO->deleteByTagged($tags_to_remove, $article->id);
     }
     //print_r ($updated_tags);
     // Create new tags
     $this->resetQueryStrings();
     $this->query_reset_lock = true;
     $current_tags_string_array = array();
     foreach ($current_tags_array as $tag) {
         $current_tags_string_array[] = $tag->name;
     }
     //print_r ($current_tags_string_array);
     foreach ($updated_tags as $tag) {
         if (!in_array($tag, $current_tags_string_array)) {
             //$newtag = new ArticleTag ();
             //$newtag->setName ($tag);
             $newtag = $this->loadByName($tag);
             if (!$newtag) {
                 $newtag = new ArticleTag();
                 $newtag->setName($tag);
                 $this->insert($newtag);
             }
             // Insert new tag. Will fail if tag name already exists.
             //if ($this->insert ($newtag)) {
             //print_r ($newtag);
             //}
             // Tag already exists. Load it
             //else {
             //    $newtag = $this->loadByName ($newtag->name);
             //print_r ($newtag);
             // }
             $tagged = new TaggedArticle();
             $tagged->setArticleId($article->getId());
             $tagged->setTagId($newtag->getId());
             $status = $taggedDAO->insert($tagged);
         }
     }
     $this->query_reset_lock = false;
     return null;
 }
 /**
  * Run method with main page logic
  * 
  * Populate template and display form for editing an article entry. For POST requests,
  * check user credentials, check if article exists and then update entry in database.
  * Available to admins only
  * @access public
  */
 public function run()
 {
     $session = Session::getInstance();
     $user = $session->getUser();
     if (!$user || !$user->isAdmin()) {
         $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR);
         header("Location: " . BASE_URL);
         return;
     }
     $form_errors = array();
     $form_values = array("id" => "", "title" => "", "content" => "", "postDate" => "", "updateDate" => "", "published" => "", "tags" => "");
     $articleDAO = ArticleDAO::getInstance();
     $tagDAO = ArticleTagDAO::getInstance();
     $article = null;
     if (!empty($_POST)) {
         $form_values["id"] = isset($_POST["id"]) && is_numeric($_POST["id"]) ? intval($_POST["id"]) : "";
         $form_values["title"] = isset($_POST["title"]) ? trim($_POST["title"]) : "";
         $form_values["content"] = isset($_POST["content"]) ? trim($_POST["content"]) : "";
         $form_values["postDate"] = isset($_POST["postDate"]) ? trim($_POST["postDate"]) : "";
         $form_values["updateDate"] = isset($_POST["updateDate"]) ? trim($_POST["updateDate"]) : "";
         $form_values["published"] = isset($_POST["published"]) ? trim($_POST["published"]) : "";
         $form_values["tags"] = isset($_POST["tags"]) ? trim($_POST["tags"]) : "";
         if (empty($form_values["id"])) {
             $form_errors["id"] = "No id specified";
         }
         if (empty($form_values["title"])) {
             $form_errors["title"] = "No title specified";
         }
         if (empty($form_values["content"])) {
             $form_errors["content"] = "No content specified";
         }
         if (empty($form_values["postDate"])) {
             $form_errors["postDate"] = "No post date specified";
         } else {
             if (strtotime($form_values["postDate"]) == 0) {
                 $form_errors["postDate"] = "An invalid post date was specified";
                 $form_values["postDate"] = "";
             }
         }
         if (!empty($form_values["updateDate"]) && strtotime($form_values["updateDate"]) == 0) {
             $form_errors["updateDate"] = "An invalid update date was specified";
             $form_values["updateDate"] = "";
         }
         if ($form_values["published"] != "true" && $form_values["published"] != "false") {
             $form_errors["published"] = "Invalid published choice";
         }
         if (empty($form_errors)) {
             $article = $articleDAO->load($form_values["id"]);
             if ($article && ($user->isAdmin() || $article->userId == $user->id)) {
                 $article->setTitle($form_values["title"]);
                 $article->setContent($form_values["content"]);
                 $article->setPostDate(strtotime($form_values["postDate"]));
                 if (!empty($form_values["updateDate"])) {
                     $article->setUpdateDate(strtotime($form_values["updateDate"]));
                 }
                 //$article->setUpdateDate (time ());
                 $published = $form_values["published"] == "true" ? 1 : 0;
                 $article->setPublished($published);
                 $article->setUserId($user->id);
                 $sorted_tag_array = ArticleTag::tagsFromString($form_values["tags"]);
                 $sorted_tags = implode(" ", $sorted_tag_array);
                 $article->setTags($sorted_tags);
                 //print_r ($article);
                 if ($articleDAO->save($article)) {
                     $tagDAO->updateTags($article);
                     $session->setMessage("Article details saved");
                     header("Location: edit_article.php?id={$article->id}");
                     return;
                 } else {
                     $session->setMessage("Article details could not be saved", Session::MESSAGE_ERROR);
                 }
             } else {
                 $session->setMessage("Do not have permission to edit the article", Session::MESSAGE_ERROR);
                 header("Location: " . BASE_URL);
                 return;
             }
         } else {
             if (empty($form_errors["id"])) {
                 $article = $articleDAO->load($form_values["id"]);
             }
         }
     } else {
         if (!empty($_GET)) {
             $form_values["id"] = isset($_GET["id"]) ? $_GET["id"] : "";
             if (empty($form_values["id"])) {
                 header("Location: " . BASE_URL);
                 return;
             } else {
                 $article = $articleDAO->load($form_values["id"]);
                 // Article does not exist. Pass null to template
                 if (!$article) {
                 } else {
                     if (!$user->isAdmin() && $article->userId != $user->id) {
                         $session->setMessage("Do not have permission to edit article", Session::MESSAGE_ERROR);
                         header("Location: " . BASE_URL);
                         return;
                     } else {
                         $form_values["id"] = $article->getId();
                         $form_values["title"] = $article->getTitle();
                         $form_values["content"] = $article->getContent();
                         $form_values["published"] = $article->getPublished() == true ? "true" : "false";
                         $form_values["postDate"] = strftime("%d %B %Y", $article->getPostDate());
                         $form_values["updateDate"] = $article->getUpdateDate() > 0 ? strftime("%d %B %Y", $article->getUpdateDate()) : "";
                         $form_values["tags"] = $article->getTags();
                     }
                 }
             }
         }
     }
     $this->template->render(array("title" => "Edit Article", "extra_header" => joinPath("headers", "jscal_header_tpl.php"), "main_page" => "edit_article_tpl.php", "session" => $session, "article" => $article, "form_errors" => $form_errors, "form_values" => $form_values));
 }
 /**
  * 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 {
     }
 }
 public function tags()
 {
     $tags = ArticleTag::all(array('order' => 'RAND()'));
     return $this->setUseCssList(true)->load_view(array('tags' => $tags));
 }