public function actionEdit()
 {
     $id = (int) Yii::$app->request->get('id');
     $page = WikiPage::find()->contentContainer($this->contentContainer)->readable()->where(['wiki_page.id' => $id])->one();
     if ($page === null) {
         $page = new WikiPage();
         $page->content->setContainer($this->contentContainer);
         $page->content->visibility = Content::VISIBILITY_PRIVATE;
         $page->title = Yii::$app->request->get('title');
     }
     if ($page->admin_only && !$page->canAdminister()) {
         throw new HttpException(403, 'Page not editable!');
     }
     $revision = $page->createRevision();
     if ($page->load(Yii::$app->request->post()) && $revision->load(Yii::$app->request->post())) {
         $page->content->container = $this->contentContainer;
         if ($page->validate()) {
             $page->save();
             File::attachPrecreated($page, Yii::$app->request->post('fileUploaderHiddenGuidField'));
             $revision->wiki_page_id = $page->id;
             if ($revision->validate()) {
                 $revision->save();
                 return $this->redirect($this->contentContainer->createUrl('view', array('title' => $page->title)));
             }
         }
     }
     return $this->render('edit', ['page' => $page, 'revision' => $revision, 'homePage' => $this->getHomePage(), 'contentContainer' => $this->contentContainer]);
 }
Пример #2
0
 public static function onUserDelete($event)
 {
     foreach (File::findAll(array('created_by' => $event->sender->id)) as $file) {
         $file->delete();
     }
     return true;
 }
Пример #3
0
 /**
  * Handles AJAX Post Request to submit new Comment
  */
 public function actionPost()
 {
     $this->forcePostRequest();
     if (Yii::$app->user->isGuest) {
         throw new HttpException(403, 'Guests can not comment.');
     }
     if (!Yii::$app->getModule('comment')->canComment($this->parentContent->content)) {
         throw new HttpException(403, 'You are not allowed to comment.');
     }
     $message = Yii::$app->request->post('message');
     $files = Yii::$app->request->post('fileList');
     if (trim($message) === '' && trim($files) === '') {
         // do not create empty comments
         return '';
     }
     $comment = new Comment();
     $comment->message = $message;
     $comment->object_model = $this->parentContent->className();
     $comment->object_id = $this->parentContent->getPrimaryKey();
     $comment->save();
     \humhub\modules\file\models\File::attachPrecreated($comment, $files);
     // Reload comment to get populated created_at field
     $comment->refresh();
     return $this->renderAjaxContent(\humhub\modules\comment\widgets\Comment::widget(['comment' => $comment, 'justEdited' => true]));
 }
Пример #4
0
 /**
  * Draw the widget
  */
 public function run()
 {
     $files = array();
     if ($this->object !== null) {
         $files = \humhub\modules\file\models\File::getFilesOfObject($this->object);
     }
     return $this->render('fileUploadList', array('uploaderId' => $this->uploaderId, 'files' => $files));
 }
Пример #5
0
 /**
  * Executes the widget.
  */
 public function run()
 {
     $blacklisted_objects = explode(',', Setting::GetText('showFilesWidgetBlacklist', 'file'));
     if (!in_array(get_class($this->object), $blacklisted_objects)) {
         $files = \humhub\modules\file\models\File::getFilesOfObject($this->object);
         return $this->render('showFiles', array('files' => $files, 'maxPreviewImageWidth' => Setting::Get('maxPreviewImageWidth', 'file'), 'maxPreviewImageHeight' => Setting::Get('maxPreviewImageHeight', 'file'), 'hideImageFileInfo' => Setting::Get('hideImageFileInfo', 'file')));
     }
 }
 public function up()
 {
     foreach (\humhub\modules\file\models\File::find()->all() as $file) {
         $oldFileName = $file->getPath() . DIRECTORY_SEPARATOR . $file->getFileName();
         $newFileName = $file->getPath() . DIRECTORY_SEPARATOR . 'file';
         if (!file_exists($newFileName) && file_exists($oldFileName) && is_writable($file->getPath())) {
             rename($oldFileName, $newFileName);
         }
     }
 }
Пример #7
0
 protected function handleInternalUrls($url)
 {
     // Handle urls to file
     if (substr($url, 0, 10) === "file-guid-") {
         $guid = str_replace('file-guid-', '', $url);
         $file = File::findOne(['guid' => $guid]);
         if ($file !== null) {
             return $file->getUrl();
         }
     }
     return $url;
 }
Пример #8
0
 /**
  * Draw the widget
  */
 public function run()
 {
     $files = array();
     if ($this->object !== null) {
         if ($this->object->isNewRecord && $this->object->getRelation('content', false) !== null) {
             $files = File::findAll(['guid' => array_map('trim', explode(',', $this->object->content->attachFileGuidsAfterSave))]);
         } else {
             $files = File::getFilesOfObject($this->object);
         }
     }
     return $this->render('fileUploadList', array('uploaderId' => $this->uploaderId, 'files' => $files));
 }
 public function actionEdit()
 {
     $this->adminOnly();
     $page = ContainerPage::find()->contentContainer($this->contentContainer)->where(['custom_pages_container_page.id' => Yii::$app->request->get('id')])->one();
     if ($page === null) {
         $page = new ContainerPage();
         $page->content->container = $this->contentContainer;
         $page->type = (int) Yii::$app->request->get('type');
     }
     if ($page->load(Yii::$app->request->post()) && $page->validate() && $page->save()) {
         \humhub\modules\file\models\File::attachPrecreated($page, Yii::$app->request->post('fileUploaderHiddenGuidField'));
         return $this->redirect($this->contentContainer->createUrl('list'));
     }
     return $this->render('edit', array('page' => $page));
 }
 public function actionEdit()
 {
     $page = Page::findOne(['id' => Yii::$app->request->get('id')]);
     if ($page === null) {
         $page = new Page();
         $page->type = (int) Yii::$app->request->get('type');
     }
     if ($page->load(Yii::$app->request->post()) && $page->validate() && $page->save()) {
         if ($page->type == Page::TYPE_MARKDOWN) {
             \humhub\modules\file\models\File::attachPrecreated($page, Yii::$app->request->post('fileUploaderHiddenGuidField'));
         }
         return $this->redirect(['index']);
     }
     return $this->render('edit', array('page' => $page));
 }
 /**
  * Executes the widget.
  */
 public function run()
 {
     if ($this->object instanceof ContentActiveRecord) {
         $widget = $this->object->getWallEntryWidget();
         // File widget disabled in this wall entry
         if ($widget->showFiles === false) {
             return;
         }
     }
     $blacklisted_objects = explode(',', Setting::GetText('showFilesWidgetBlacklist', 'file'));
     if (!in_array(get_class($this->object), $blacklisted_objects)) {
         $files = \humhub\modules\file\models\File::getFilesOfObject($this->object);
         return $this->render('showFiles', array('files' => $files, 'maxPreviewImageWidth' => Setting::Get('maxPreviewImageWidth', 'file'), 'maxPreviewImageHeight' => Setting::Get('maxPreviewImageHeight', 'file'), 'hideImageFileInfo' => Setting::Get('hideImageFileInfo', 'file')));
     }
 }
Пример #12
0
 /**
  * Handles AJAX Post Request to submit new Comment
  */
 public function actionPost()
 {
     $this->forcePostRequest();
     $message = Yii::$app->request->post('message');
     if ($message != "" && !Yii::$app->user->isGuest) {
         $comment = new Comment();
         $comment->message = $message;
         $comment->object_model = $this->parentContent->className();
         $comment->object_id = $this->parentContent->getPrimaryKey();
         $comment->save();
         \humhub\modules\file\models\File::attachPrecreated($comment, Yii::$app->request->post('fileList'));
         // Reload comment to get populated created_at field
         $comment = Comment::findOne(['id' => $comment->id]);
         return $this->renderAjaxContent(\humhub\modules\comment\widgets\Comment::widget(['comment' => $comment, 'justEdited' => true]));
     }
 }
Пример #13
0
 public function getItemById($itemId)
 {
     $params = explode('_', $itemId);
     if (sizeof($params) < 2) {
         return null;
     }
     list($type, $id) = explode('_', $itemId);
     if ($type == 'file') {
         return models\File::findOne(['id' => $id]);
     } elseif ($type == 'folder') {
         return models\Folder::findOne(['id' => $id]);
     } elseif ($type == 'baseFile') {
         return \humhub\modules\file\models\File::findOne(['id' => $id]);
     }
     return null;
 }
Пример #14
0
 public function getBaseFile()
 {
     $query = $this->hasOne(\humhub\modules\file\models\File::className(), ['object_id' => 'id']);
     $query->andWhere(['file.object_model' => self::className()]);
     return $query;
 }
Пример #15
0
 public function afterSave($insert, $changedAttributes)
 {
     // Loop over each eall entry and make sure its update_at / update_by
     // will also updated. (Sorting wall against update)
     foreach ($this->getWallEntries() as $wallEntry) {
         $wallEntry->save();
     }
     if ($insert) {
         foreach ($this->notifyUsersOfNewContent as $user) {
             $this->getPolymorphicRelation()->follow($user->id);
         }
         $notification = new \humhub\modules\content\notifications\ContentCreated();
         $notification->source = $this->getPolymorphicRelation();
         $notification->originator = $this->user;
         $notification->sendBulk($this->notifyUsersOfNewContent);
         if (!$this->getPolymorphicRelation() instanceof \humhub\modules\activity\models\Activity) {
             $activity = new \humhub\modules\content\activities\ContentCreated();
             $activity->source = $this->getPolymorphicRelation();
             $activity->create();
         }
     }
     \humhub\modules\file\models\File::attachPrecreated($this->getPolymorphicRelation(), $this->attachFileGuidsAfterSave);
     return parent::afterSave($insert, $changedAttributes);
 }
Пример #16
0
 public function actionDelete()
 {
     $this->forcePostRequest();
     $guid = Yii::$app->request->post('guid');
     $file = File::findOne(['guid' => $guid]);
     if ($file == null) {
         throw new HttpException(404, Yii::t('FileModule.controllers_FileController', 'Could not find requested file!'));
     }
     if (!$file->canDelete()) {
         throw new HttpException(401, Yii::t('FileModule.controllers_FileController', 'Insufficient permissions!'));
     }
     $file->delete();
 }
 /**
  * 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()];
 }
 /**
  * Load all posted files from the database and get an array of them.
  * @return Ambigous <multitype:, multitype:\yii\db\ActiveRecord >
  */
 protected function getAllPostedFiles()
 {
     // Get Posted Files
     $query = \humhub\modules\file\models\File::find();
     $query->join('LEFT JOIN', 'comment', '(file.object_id=comment.id)');
     $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)');
     $query->andWhere(['content.space_id' => $this->contentContainer->id]);
     $query->andWhere(['<>', 'file.object_model', File::className()]);
     $query->orderBy(['file.updated_at' => SORT_DESC]);
     // Get Files from comments
     return $query->all();
 }
 /**
  * Edits Entry Id
  */
 public function actionEditEntry()
 {
     $messageEntryId = (int) Yii::$app->request->get('messageEntryId');
     $entry = MessageEntry::findOne(['id' => $messageEntryId]);
     // Check if message entry exists and it´s by this user
     if ($entry == null || $entry->user_id != Yii::$app->user->id) {
         throw new HttpException(404, 'Could not find message entry!');
     }
     if ($entry->load(Yii::$app->request->post()) && $entry->validate()) {
         // ?
         //$entry->content = $_POST['MessageEntry']['content'];
         $entry->save();
         File::attachPrecreated($entry, Yii::$app->request->get('fileUploaderHiddenGuidField'));
         return $this->htmlRedirect(['index', 'id' => $entry->message->id]);
     }
     return $this->renderAjax('editEntry', array('entry' => $entry));
 }