Ejemplo n.º 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=Board::model()->findByPk((int)$id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}
Ejemplo n.º 2
0
	public function beforeAction($action) {
		if (parent::beforeAction($action)) {
			$lang=Yii::app()->getRequest()->getPreferredLanguage();
			if($lang=="ru_ru" || $lang=="ru")
				Yii::app()->language="ru";
			else
				Yii::app()->language="en";
			$board_array=Yii::app()->cache->get('boards');
			if ($board_array===false) {
				// show boards in top menu
				$boards=Board::model()->findAll();
				foreach ($boards as $board) {
					$board_array[]=$action->getController()->boards[]=array('label'=> "/" . $board->slug . "/", 'url'=> array('/post/board', 'slug'=> $board->slug), 'linkOptions'=> array('title'=> $board->name));
				}
				Yii::app()->cache->set('boards', $board_array, 2592000); // 1 month
			}
			$action->getController()->boards=$board_array;
			return true;
		}
		else
			return false;
	}
Ejemplo n.º 3
0
	protected function beforeSave()
	{
		if(parent::beforeSave())
		{
			$board=Board::model()->findByPk($this->board);
			$links=array();
			preg_match_all("/>>\d+/",$this->content,$matches);
			
			$matches=$matches[0];
			foreach($matches as $match)
			{
				// delete >> symbols
				$links[]=substr($match, 8);
			}
			$links=array_unique($links);
			$posts=Post::model()->findAllByAttributes(array('board'=>$this->board,'vid'=>$links),array('order'=>'vid DESC'));
			foreach($posts as $post)
			{
				$_id=$post->parent_id?$post->parent_id:$post->vid;
				$url=array('post/thread','slug'=>$board->slug,'id'=>$_id);
				if($post->parent_id)
					$url=array('post/thread','slug'=>$board->slug,'id'=>$_id,'#'=>$post->vid);
				$search = ">>".$post->vid;
				$replace = CHtml::link(">>".$post->vid,$url,array('class'=>'ref'));
				$this->content=str_replace($search,$replace,$this->content);
			}
			// flush cache
			Yii::app()->cache->delete('board'.$board->slug);
			if($this->isNewRecord)
			{
				$this->content=nl2br($this->content);
				$this->created=time();
				if($this->parent_id)
				{
					$post=Post::model()->find('board=:boardId AND vid=:id', array(':boardId'=>$this->board,':id'=>$this->parent_id));
					$post->commentCount++;
					if(strlen($this->filename)>0)
						$post->commentWithImg++;
					$post->updated=$this->created;
					$post->save(false);

				}
				else
					$this->updated=$this->created;
			}
			return true;
		}
		else
			return false;
	}