public function edit($id)
 {
     if ($id == NULL) {
         $view = $this->__common(new View(ArticleListView));
         $view->title = 'Craiglist | ' . 'My Posts';
         $view->isLoggedIn = Authentification::isLoggedIn();
         $model = new ArticleModel();
         $view->articles = $model->getArticlesForUserById($_SESSION['id']);
         $view->articles_number = count($view->articles);
         $view->control_method = '/article/edit/';
         print $view->display();
         return;
     }
     $view = $this->__common(new View(EditArticleView));
     $view->title = 'Craiglist | ' . 'Edit Post';
     $view->isLoggedIn = Authentification::isLoggedIn();
     $article_model = new ArticleModel();
     $view->article = $article_model->getArticleByID($id);
     $category_model = new CategoryModel();
     $view->categories = $category_model->getCategoryFullList();
     if (isset($_POST['submit'])) {
         if (isset($_POST['title'])) {
             $article_model->updateArticle($id, $_POST['title'], $_POST['content'], $_POST['category']);
             header('Location:' . SERVER_ROOT_URL . '/article/index/' . $id);
         }
     }
     print $view->display();
 }
 public function view($category, $subcategory)
 {
     $view = $this->__common(new View(ArticleListView));
     $view->title = 'Craiglist | ' . 'Articles';
     $view->isLoggedIn = Authentification::isLoggedIn();
     $model = new ArticleModel();
     $view->articles = $model->getArticleListByCategory($category, $subcategory);
     $view->articles_number = count($view->articles);
     $view->control_method = '/article/index/';
     print $view->display();
 }
 public function password()
 {
     // ->INITIALIZE SESSION
     session_start();
     // ->CHECK AUTHORIZATION
     if (Authentification::isLoggedIn()) {
         $username = $_SESSION['username'];
         $password = $_POST['password'];
         ProfileModel::setPassword($username, $password);
     }
     header('Location:' . SERVER_ROOT_URL . '/login/logout');
 }
 public function index()
 {
     $view = $this->__common(new View(RegisterView));
     $view->isLoggedIn = Authentification::isLoggedIn();
     $view->title = 'Craiglist | ' . 'Sign Up!';
     session_start();
     if (isset($_POST['register'])) {
         $register = new Registration(array('username' => $_POST['ruser'], 'password' => $_POST['rpass'], 'token' => $_POST['token'], 'role' => $role));
         $register->process() == true ? header('Location:' . SERVER_ROOT_URL . '/login') : ($view->errors = $register->show_errors());
     }
     $view->token = $_SESSION['token'] = md5(uniqid(mt_rand(), true));
     print $view->display();
 }
 public function search($substring)
 {
     if ($substring == NULL) {
         return;
     }
     $view = $this->__common(new View(ArticleListView));
     $view->isLoggedIn = Authentification::isLoggedIn();
     $view->title = 'Craiglist | ' . 'Article';
     $model = new ArticleModel();
     $view->articles = $model->getArticlesByTitle($substring);
     $view->articles_number = count($view->articles);
     $view->control_method = '/article/index/';
     print $view->display();
 }
 public function index($receiver_id = NULL)
 {
     $view = new XView(Message_View);
     $view->receiver_id = $receiver_id;
     $view->title = 'Messages';
     session_start();
     $view->isLoggedIn = Authentification::isLoggedIn();
     if ($_POST['post_message']) {
         MessageModel::newMessage($_POST['content'], $_SESSION['id'], $receiver_id);
     }
     if ($receiver_id != null) {
         $view->messages = MessageModel::getMessageListByAuthorToSender($_SESSION['id'], $receiver_id);
     } else {
         $view->messages = array();
     }
     $view->users = ProfileModel::getUserList();
     $this->__common($view);
 }
 public function __common(XView $view)
 {
     // INSTALLING THE SESSION
     session_start();
     $isLoggedIn = Authentification::isLoggedIn();
     $view->isLoggedIn = $isLoggedIn;
     // юмюкхг лернднб йкюяяю
     $list = get_class_methods($this);
     $sidebar = explode(' ', trim(WidgetModel::get('sidebar')));
     // янонярюбкемхе юдпеяю осрел оепеанпю лернднб йнмрпнккепю
     foreach ($list as $method) {
         if ($method != '__common') {
             $view->{$name} = SERVER_ROOT_URL . '/' . $method;
         }
     }
     $view->stylesheet = STYLESHEET_FOLDER;
     switch ($_GET['relative_address']) {
         case 'widget':
             print '<div class="clear">';
             print $view->display();
             print '</div>';
             break;
         case "inscribed":
             print '<div class="clear" data-content data-content-type="inscribed">';
             print $view->display();
             print '</div>';
             break;
         default:
             require_once $view->getHeader();
             require_once $view->getSidebar();
             print '<div class="col-md-8" data-content data-content-type="inscribed">';
             //print Template::construct('div')->apply('class', 'col-md-8' )->append( $view->display() )->display();
             print $view->display();
             print '</div>';
             require_once $view->getFooter();
             break;
     }
     return $view;
 }
 public function logout()
 {
     Authentification::logout();
     header('Location:' . SERVER_ROOT_URL);
 }
 public function view($id, $args = NULL)
 {
     if ($_POST['post_comment']) {
         CommentModel::add($_POST['content'], $_POST['parent_comment'], $_POST['author_id'], $_POST['article_id']);
     }
     session_start();
     if (Authentification::isLoggedIn()) {
         ViewsModel::incrementView($id, $_SESSION['id']);
     }
     $view = new XView(Article_View);
     $view->title = 'Article | View';
     $view->article = ArticleModel::getArticleById($id);
     $view->comments = CommentModel::getCommentTreeByArticleID($id, -1);
     $view->likes = LikesModel::getLikeNumber($id);
     $view->parent_comment = $args;
     $this->__common($view);
 }