Beispiel #1
0
	private function processAction($dao, $v)
	{
		if ( !isset($this->params[0])) {
			$action = 'list'; // default action
		} else {
			$action = trim($this->params[0]);
		}
		$err = '';
		
		if ( in_array($action, array('list','show','edit')) )
		{
			if ($action == 'list') {
				$html = BaseController::callController(BASEEXT.'/blog', 'BlogList', array());
			}
			else {
				$postId = trim(sanitizeString($this->params[1]));				
				if ($action == 'show') {
					$html = BaseController::callController(BASEEXT.'/blog', 'BlogShow', array($postId));
				}
				else if ($action == 'edit') {					
					$html = BaseController::callController(BASEEXT.'/blog', 'BlogEdit', array($postId));
				}
			}
			$v->assign('inc_content', 'blank.html');
			$v->assign('content', $html);
		}
		else {
			if ($action == 'remove')
			{				
				// ex: requesting: /blog/delete/2
				$id = trim(sanitizeString($this->params[1]));
				if (isDemoMode() && $id == 1) $err = '<span id="msgWarn">Demo Mode: removing entry #1 is not allowed!</span>';
				if ($err == '') {
					$dao->removeById($id);
				}
			}
			else if ($action == 'add')
			{
				$randNum = mt_rand(0, 99999);
				$dbNow = date( 'Y-m-d H:i:s' );
				$newPost = new Post(
								array('title' => 'Blog entry '.$randNum,
									'description' => 'description '.$randNum,
									'content' => 'content '.$randNum,
									'createTime' => $dbNow)
							);				
				$dao->execute("INSERT INTO post(title, description, content, createTime)
							VALUES(:title, :description, :content, :createTime)", $newPost->getFields());
			}
			$posts = $dao->getAll();

			$v->assign('inc_content', BASEEXT.'/blog/view/admin.html');
			$v->assign('err', $err);
	        $v->assign('posts', $posts);
	        $v->assign('totalPosts', $dao->countAll());
	        $v->assign('content', '');
		}
		return $html;
	}
Beispiel #2
0
 public function view()
 {
     if ($this->isPosting()) {
         return $this->processPost();
     }
     session_start();
     if (getLoggedInUsername() != '') {
         if (isset($this->params[0])) {
             $viewToEdit = $this->params[0];
             $viewPath = BASEVIEW . '/' . currentViewDir() . '/' . $viewToEdit;
             if (file_exists($viewPath)) {
                 $viewContent = file_get_contents($viewPath);
                 if (isDemoMode()) {
                     $viewContent .= "<p/><b>Demo Mode: This page is set to readonly in demo mode.</b>";
                 }
             }
             $html = file_get_contents_with_vars(BASEEXT . '/editor/page_editor.html', array('{$viewFile}' => $viewToEdit, '{$viewContent}' => $viewContent));
             echo $html;
         }
     } else {
         echo '';
     }
 }