public function up()
 {
     $this->renameClass('ReportContent', ReportContent::className());
     // Only allow posts during upgrade to namespaced version
     $this->delete('report_content', ['!=', 'object_model', 'Post']);
     // Namespace object_model
     $this->update('report_content', ['object_model' => Post::className()], ['object_model' => 'Post']);
     // Remove all open notifications
     $this->delete('notification', ['class' => 'NewReportAdminNotification']);
     $this->delete('notification', ['class' => 'NewReportNotification']);
 }
 public function testPublicContent()
 {
     $this->becomeUser('User2');
     $space = Space::findOne(['id' => 2]);
     $post1 = new Post();
     $post1->message = "Private Post";
     $post1->content->setContainer($space);
     $post1->content->visibility = Content::VISIBILITY_PRIVATE;
     $post1->save();
     $w1 = $post1->content->getFirstWallEntryId();
     $post2 = new Post();
     $post2->message = "Public Post";
     $post2->content->setContainer($space);
     $post2->content->visibility = Content::VISIBILITY_PUBLIC;
     $post2->save();
     $w2 = $post2->content->getFirstWallEntryId();
     $this->becomeUser('Admin');
     $ids = $this->getStreamActionIds($space, 2);
     $this->assertFalse(in_array($w1, $ids));
     $this->assertTrue(in_array($w2, $ids));
 }
Esempio n. 3
0
 public function actionEdit()
 {
     $id = Yii::$app->request->get('id');
     $edited = false;
     $model = Post::findOne(['id' => $id]);
     if (!$model->content->canWrite()) {
         throw new HttpException(403, Yii::t('PostModule.controllers_PostController', 'Access denied!'));
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->save()) {
         // Reload record to get populated updated_at field
         $model = Post::findOne(['id' => $id]);
         return $this->renderAjaxContent($model->getWallOut(['justEdited' => true]));
     }
     return $this->renderAjax('edit', array('post' => $model, 'edited' => $edited));
 }
 /**
  * Handles AJAX Post Request to submit new ReportContent
  */
 public function actionReport()
 {
     $this->forcePostRequest();
     Yii::$app->response->format = 'json';
     $json = array();
     $json['success'] = false;
     $form = new ReportReasonForm();
     if ($form->load(Yii::$app->request->post()) && $form->validate() && ReportContent::canReportPost($form->object_id)) {
         $report = new ReportContent();
         $report->created_by = Yii::$app->user->id;
         $report->reason = $form->reason;
         $report->object_model = Post::className();
         $report->object_id = $form->object_id;
         if ($report->save()) {
             $json['success'] = true;
         }
     }
     return $json;
 }
 /**
  * Executes the widget.
  */
 public function run()
 {
     if (get_class($this->content) == Post::className() && ReportContent::canReportPost($this->content->id)) {
         return $this->render('reportSpamLink', array('object' => $this->content, 'model' => new ReportReasonForm()));
     }
 }
Esempio n. 6
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $postCount = Content::find()->where(['object_model' => Post::className(), 'contentcontainer_id' => $this->space->contentContainerRecord->id])->count();
     return $this->render('header', array('space' => $this->space, 'postCount' => $postCount));
 }
 /**
  * Load all posted files from the database and get an array of them.
  *
  * @param array $filesOrder
  *            orderBy array appended to the files query
  * @param array $foldersOrder
  *            currently unused
  * @return Ambigous <multitype:, multitype:\yii\db\ActiveRecord >
  */
 protected function getAllPostedFilesList($filesOrder = NULL, $foldersOrder = NULL)
 {
     // set ordering default
     if (!$filesOrder) {
         $filesOrder = ['file.updated_at' => SORT_DESC, 'file.title' => SORT_ASC];
     }
     // Get Posted Files
     $query = \humhub\modules\file\models\File::find();
     // join comments to the file if available
     $query->join('LEFT JOIN', 'comment', '(file.object_id=comment.id AND file.object_model=' . Yii::$app->db->quoteValue(Comment::className()) . ')');
     // join parent post of comment or file
     $query->join('LEFT JOIN', 'content', '(comment.object_model=content.object_model AND comment.object_id=content.object_id) OR (file.object_model=content.object_model AND file.object_id=content.object_id)');
     if (version_compare(Yii::$app->version, '1.1', 'lt')) {
         // select only the one for the given content container for Yii version < 1.1
         if ($this->contentContainer instanceof \humhub\modules\user\models\User) {
             $query->andWhere(['content.user_id' => $this->contentContainer->id]);
             $query->andWhere(['IS', 'content.space_id', new \yii\db\Expression('NULL')]);
         } else {
             $query->andWhere(['content.space_id' => $this->contentContainer->id]);
         }
     } else {
         // select only the one for the given content container for Yii version >= 1.1
         $query->andWhere(['content.contentcontainer_id' => $this->contentContainer->contentContainerRecord->id]);
     }
     // only accept Posts as the base content, so stuff from sumbmodules like files itsself or gallery will be excluded
     $query->andWhere(['or', ['=', 'comment.object_model', Post::className()], ['=', 'file.object_model', Post::className()]]);
     // Get Files from comments
     return ['postedFiles' => $query->orderBy($filesOrder)->all()];
 }
 /**
  * Own profile content should appear with visibility Private & Public
  */
 public function testOwnContent()
 {
     $this->becomeUser('Admin');
     $post1 = new Post();
     $post1->message = "Own Private Post";
     $post1->content->container = Yii::$app->user->getIdentity();
     $post1->content->visibility = Content::VISIBILITY_PRIVATE;
     $post1->save();
     $w1 = $post1->content->getFirstWallEntryId();
     $post2 = new Post();
     $post2->message = "Own Public Post";
     $post2->content->container = Yii::$app->user->getIdentity();
     $post2->content->visibility = Content::VISIBILITY_PUBLIC;
     $post2->save();
     $w2 = $post2->content->getFirstWallEntryId();
     $ids = $this->getStreamActionIds(2);
     $this->assertEquals($ids, array($w2, $w1));
 }
Esempio n. 9
0
 /**
  * Setup additional filters
  */
 public function setupFilters()
 {
     if (in_array('entry_files', $this->filters)) {
         $fileSelector = (new \yii\db\Query())->select(["id"])->from('file')->where('file.object_model=content.object_model AND file.object_id=content.object_id')->limit(1);
         $fileSelectorSql = Yii::$app->db->getQueryBuilder()->build($fileSelector)[0];
         $this->activeQuery->andWhere('(' . $fileSelectorSql . ') IS NOT NULL');
     }
     // Setup Post specific filters
     if (in_array('posts_links', $this->filters)) {
         $this->activeQuery->leftJoin('post', 'content.object_id=post.id AND content.object_model=:postModel', ['postModel' => \humhub\modules\post\models\Post::className()]);
         $this->activeQuery->andWhere("post.url is not null");
     }
     // Only apply archived filter when we should load more than one entry
     if ($this->limit != 1) {
         if (!in_array('entry_archived', $this->filters)) {
             $this->activeQuery->andWhere("(content.archived != 1 OR content.archived IS NULL)");
         }
     }
     // Show only mine items
     if (in_array('entry_mine', $this->filters) && $this->user !== null) {
         $this->activeQuery->andWhere(['content.created_by' => $this->user->id]);
     }
     // Show only items where the current user is involed
     if (in_array('entry_userinvoled', $this->filters) && $this->user !== null) {
         $this->activeQuery->leftJoin('user_follow', 'content.object_model=user_follow.object_model AND content.object_id=user_follow.object_id AND user_follow.user_id = :userId', ['userId' => $this->user->id]);
         $this->activeQuery->andWhere("user_follow.id IS NOT NULL");
     }
     if (in_array('model_posts', $this->filters)) {
         $this->activeQuery->andWhere(["content.object_model" => \humhub\modules\post\models\Post::className()]);
     }
     // Visibility filters
     if (in_array('visibility_private', $this->filters)) {
         $this->activeQuery->andWhere(['content.visibility' => Content::VISIBILITY_PRIVATE]);
     }
     if (in_array('visibility_public', $this->filters)) {
         $this->activeQuery->andWhere(['content.visibility' => Content::VISIBILITY_PUBLIC]);
     }
 }
 public function up()
 {
     $this->renameClass('Post', Post::className());
 }
 /**
  * Checks if the given or current user can report post with given id.
  *
  * @param
  *            int postId
  */
 public static function canReportPost($postId, $userId = "")
 {
     if (Yii::$app->user->isGuest) {
         return false;
     }
     $post = Post::findOne(['id' => $postId]);
     if (!$post) {
         return false;
     }
     if ($userId != "") {
         $user = User::findOne(['id' => $userId]);
     } else {
         $user = Yii::$app->user->getIdentity();
     }
     if (!$user) {
         return false;
     }
     if ($user->super_admin) {
         return false;
     }
     if ($post->created_by == $user->id) {
         return false;
     }
     if ($post->content->container instanceof Space && ($post->content->getContainer()->isAdmin($user->id) || $post->content->getContainer()->isAdmin($post->created_by))) {
         return false;
     }
     if (ReportContent::findOne(['object_model' => Post::className(), 'object_id' => $post->id, 'created_by' => $user->id]) !== null) {
         return false;
     }
     if (User::findOne(['id' => $post->created_by, 'super_admin' => 1]) !== null) {
         return false;
     }
     return true;
 }
Esempio n. 12
0
 public function testOrder()
 {
     /**
      * @todo FIXME, change time in database instead of sleeping
      */
     sleep(1);
     $post1 = new Post();
     $post1->message = "P1";
     $post1->content->setContainer(Yii::$app->user->getIdentity());
     $post1->save();
     $post1wallEntryId = $post1->content->getFirstWallEntryId();
     sleep(1);
     $post2 = new Post();
     $post2->message = "P2";
     $post2->content->setContainer(Yii::$app->user->getIdentity());
     $post2->save();
     $post2wallEntryId = $post2->content->getFirstWallEntryId();
     sleep(1);
     $post1->message = "P1b";
     $post1->save();
     $baseStreamAction = new Stream('stream', Yii::$app->controller);
     $baseStreamAction->limit = 2;
     $baseStreamAction->init();
     $wallEntries = $baseStreamAction->getWallEntries();
     $wallEntryIds = array_map(create_function('$entry', 'return $entry->id;'), $wallEntries);
     $this->assertEquals(array($post2wallEntryId, $post1wallEntryId), $wallEntryIds);
     $baseStreamAction = new Stream('stream', Yii::$app->controller);
     $baseStreamAction->limit = 2;
     $baseStreamAction->sort = Stream::SORT_UPDATED_AT;
     $baseStreamAction->init();
     $wallEntries = $baseStreamAction->getWallEntries();
     $wallEntryIds = array_map(create_function('$entry', 'return $entry->id;'), $wallEntries);
     $this->assertEquals(array($post1wallEntryId, $post2wallEntryId), $wallEntryIds);
 }
Esempio n. 13
0
 /**
  * Get the post the file is connected to.
  * @param File $basefile the file.
  */
 public static function getBasePost($file = null)
 {
     if ($file === null) {
         return null;
     }
     $searchItem = $file;
     // if the item is connected to a Comment, we have to search for the corresponding Post
     if ($file->object_model === Comment::className()) {
         $searchItem = Comment::findOne(['id' => $file->object_id]);
     }
     $return = Post::findOne(['id' => $searchItem->object_id]);
 }