Ejemplo n.º 1
0
 public function actionAdd()
 {
     $orig_id = isset($_POST["orig_id"]) ? (int) $_POST["orig_id"] : (int) $_GET["orig_id"];
     $post_id = isset($_POST["post_id"]) ? (int) $_POST["post_id"] : (int) $_GET["post_id"];
     if ($orig_id) {
         $orig = Orig::model()->with("chap.book.membership")->findByPk($orig_id);
         if (!$orig) {
             throw new CHttpException(404, "Вы пытаетесь добавить несуществующий фрагмент оригинала в «мои обсуждения». Скорее всего, его удалили");
         } elseif (!$orig->chap->can("read")) {
             throw new CHttpException(403, "Вы не можете добавить этот фрагмент в «мои обсуждения» так как у вас больше нет доступа этот перевод.");
         } else {
             $orig->setTrack();
         }
     } elseif ($post_id) {
         $post = BlogPost::model()->with("book", "seen")->findByPk($post_id);
         if (!$post) {
             throw new CHttpException(404, "Вы пытаетесь добавить несуществующий пост в «мои обсуждения». Скорее всего, его удалили.");
         } else {
             if ($post->book_id != 0 and !$post->book->can("blog_r")) {
                 throw new CHttpException(403, "Вы не можете добавить этот пост в «мои обсуждения» так как у вас нет доступа в блог перевода.");
             } else {
                 $post->setTrack();
             }
         }
     } else {
         throw new CHttpException(500, "Неверный запрос.");
     }
     if ($_POST["ajax"]) {
         echo json_encode(array("status" => "ok", "id" => $orig_id ? $orig_id : $post_id));
         Yii::app()->end();
     } else {
         $this->redirect("/my/comments/?mode=" . ($orig_id ? "o" : "p"));
     }
 }
Ejemplo n.º 2
0
 public function actionIndex()
 {
     if (Yii::app()->user->isGuest) {
         if (Yii::app()->request->isPostRequest && isset($_POST["login"])) {
             $user = new User("login");
             $user->setAttributes($_POST["login"]);
             $user->remember = true;
             if ($user->login()) {
                 $this->redirect("/");
             } else {
                 Yii::app()->user->setFlash("error", $user->getError("pass"));
             }
         }
         if (p()['registerType'] == "INVITE") {
             $this->layout = "empty";
             $this->render("index_guest");
             return;
         }
     }
     $this->layout = "column1";
     $hot_key = sprintf("hot.%d.%d.%d", Yii::app()->user->ini["hot.s_lang"], Yii::app()->user->ini["hot.t_lang"], Yii::app()->user->ini["hot.img"]);
     if (!($hot = Yii::app()->cache->get($hot_key))) {
         $C = new CDbCriteria(array("condition" => "t.ac_read = 'a'", "order" => "t.last_tr DESC NULLS LAST"));
         $C->limit = Yii::app()->user->ini["hot.img"] ? 12 : 36;
         if (Yii::app()->user->ini["hot.s_lang"]) {
             $C->addCondition("t.s_lang = " . Yii::app()->user->ini["hot.s_lang"]);
         }
         if (Yii::app()->user->ini["hot.t_lang"]) {
             $C->addCondition("t.t_lang = " . Yii::app()->user->ini["hot.t_lang"]);
         }
         $hot = Book::model()->findAll($C);
         Yii::app()->cache->set($hot_key, $hot, 60);
     }
     if (!($announces = Yii::app()->cache->get("announces"))) {
         $announces = Announce::model()->with("book.cat", "book.owner", "seen")->findAll(array("condition" => "t.topics BETWEEN 80 AND 89 AND book.ac_read = 'a'", "order" => "t.cdate desc", "limit" => 5));
         Yii::app()->cache->set("announces", $announces, 90);
     }
     if (!($blog = Yii::app()->cache->get("blog"))) {
         $blog = BlogPost::model()->common()->findAll(["limit" => 10]);
         Yii::app()->cache->set("blog", $blog, 105);
     }
     $this->render('index', array("hot" => $hot, "searchTop" => $this->getSearchTop(), "announces" => $announces, "blog" => $blog));
 }
Ejemplo n.º 3
0
 public function beforeValidate()
 {
     // Alias
     if ($this->alias) {
         $this->alias = makeAlias($this->alias);
     } else {
         $this->alias = makeAlias($this->title);
     }
     if ($this->isNewRecord) {
         // Check if we already have an alias with those parameters
         if (BlogPost::model()->exists('alias=:alias', array(':alias' => $this->alias))) {
             $this->addError('alias', at('There is already a page with that alias.'));
         }
     } else {
         // Check if we already have an alias with those parameters
         if (BlogPost::model()->exists('alias=:alias AND id!=:id', array(':id' => $this->id, ':alias' => $this->alias))) {
             $this->addError('alias', at('There is already a page with that alias.'));
         }
     }
     return parent::beforeValidate();
 }
Ejemplo n.º 4
0
 public function actionPosts($id)
 {
     $user = $this->loadUser($id);
     $posts = new CActiveDataProvider(BlogPost::model()->user($user->id)->with("book.membership", "seen"), array("criteria" => array("order" => "t.cdate desc"), "pagination" => array("pageSize" => 10)));
     $this->render("posts", array("user" => $user, "posts" => $posts));
 }
Ejemplo n.º 5
0
 public function actionRemove($post_id)
 {
     $post_id = (int) $post_id;
     if (!$_POST["really"]) {
         $this->redirect("/blog");
     }
     $post = BlogPost::model()->findByPk($post_id);
     if (!$post) {
         throw new CHttpException(404, "Поста не существует. Возможно, его уже удалили.");
     }
     if ($post->user_id != Yii::app()->user->id and !Yii::app()->user->can("blog_moderate")) {
         throw new CHttpException(403, "Вы можете удалять только собственные посты");
     }
     $post->delete();
     $this->redirect("/blog");
 }
Ejemplo n.º 6
0
 public function actionRemove($book_id, $post_id)
 {
     $post_id = (int) $post_id;
     $this->loadBook($book_id);
     if (!Yii::app()->user->can("blog_moderate")) {
         throw new CHttpException(403, "Только модераторы блогов Нотабеноида могут удалять анонсы.");
     }
     if (!$_POST["really"]) {
         $this->redirect($this->book->getUrl("announces"));
     }
     $post = BlogPost::model()->findByPk($post_id, "t.topics BETWEEN 80 AND 89 AND t.book_id = :book_id", array(":book_id" => $this->book->id));
     if (!$post) {
         throw new CHttpException(404, "Анонса не существует. Возможно, его уже удалили.");
     }
     $post->book = $this->book;
     $post->delete();
     $this->redirect($this->book->getUrl("announces"));
 }
Ejemplo n.º 7
0
 /**
  * Delete page action
  */
 public function actionDelete()
 {
     // Check Access
     checkAccessThrowException('op_blog_deleteposts');
     if (isset($_GET['id']) && ($model = BlogPost::model()->findByPk($_GET['id']))) {
         alog(at("Deleted Blog Post '{name}'.", array('{name}' => $model->title)));
         $model->delete();
         fok(at('Page Deleted.'));
         $this->redirect(array('blog/index'));
     } else {
         $this->redirect(array('blog/index'));
     }
 }
Ejemplo n.º 8
0
 public function actionRemove($book_id, $post_id)
 {
     $this->loadBook($book_id);
     $post_id = (int) $post_id;
     if (!$this->book->can("blog_r") || !$this->book->can("blog_w")) {
         throw new CHttpException(403, "Вы не можете удалять посты в блоге этого перевода. " . $this->book->getWhoCanDoIt("blog_w"));
     }
     if (!$_POST["really"]) {
         $this->redirect("/blog");
     }
     $post = BlogPost::model()->findByPk($post_id);
     if (!$post) {
         throw new CHttpException(404, "Поста не существует. Возможно, его уже удалили.");
     }
     if ($post->user_id != Yii::app()->user->id and !Yii::app()->user->can("blog_moderate")) {
         throw new CHttpException(403, "Вы можете удалять только собственные посты.");
     }
     if ($post->isAnnounce) {
         throw new CHttpException(404, "Поста не существует. Возможно, его уже удалили.");
     }
     $post->book_id = $this->book->id;
     $post->book = $this->book;
     $post->delete();
     $this->redirect($this->book->getUrl("blog"));
 }
Ejemplo n.º 9
0
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }