diff --git a/models/File.php b/models/File.php index 613f97b..211dc28 100644 --- a/models/File.php +++ b/models/File.php @@ -9,6 +9,7 @@ use humhub\modules\file\libs\FileHelper; use humhub\modules\file\models\File as BaseFile; use humhub\modules\file\models\FileUpload; +use humhub\modules\friendship\Module as FriendshipModule; use humhub\modules\search\events\SearchAddEvent; use humhub\modules\topic\models\Topic; use Yii; @@ -98,7 +99,7 @@ public function rules() ['hidden', 'boolean'], ]; - if($this->parentFolder && $this->parentFolder->content->isPublic()) { + if ($this->parentFolder && $this->parentFolder->content->isPublic()) { $rules[] = ['visibility', 'integer', 'min' => 0, 'max' => 1]; } @@ -110,7 +111,7 @@ public function rules() */ public function attributeLabels() { - return array_merge(parent::attributeLabels(),[ + return array_merge(parent::attributeLabels(), [ 'id' => 'ID', 'parent_folder_id' => Yii::t('CfilesModule.models_File', 'Folder ID') ]); @@ -125,11 +126,11 @@ public function getSearchAttributes() 'description' => $this->description ]; - if($this->getCreator()) { + if ($this->getCreator()) { $attributes['creator'] = $this->getCreator()->getDisplayName(); } - if($this->getEditor()) { + if ($this->getEditor()) { $attributes['editor'] = $this->getEditor()->getDisplayName(); } @@ -207,7 +208,7 @@ public function updateVisibility($visibility) return; } - if(!$this->parentFolder->content->isPrivate() || $visibility == Content::VISIBILITY_PRIVATE) { + if (!$this->parentFolder->content->isPrivate() || $visibility == Content::VISIBILITY_PRIVATE) { // For user profile files we use Content::VISIBILITY_OWNER isntead of private $this->content->visibility = $visibility; } @@ -215,8 +216,9 @@ public function updateVisibility($visibility) public function getVisibilityTitle() { - if(Yii::$app->getModule('friendship')->getIsEnabled() && $this->content->container instanceof User) { - if($this->content->container->isCurrentuser()) { + $module = Yii::$app->getModule('friendship'); + if ($module instanceof FriendshipModule && $module->isFriendshipEnabled() && $this->content->container instanceof User) { + if ($this->content->container->isCurrentuser()) { $privateText = Yii::t('CfilesModule.base', 'This file is only visible for you and your friends.'); } else { $privateText = Yii::t('CfilesModule.base', 'This file is protected.'); @@ -324,7 +326,7 @@ public function getFullUrl() */ public function getDownloadUrl($forceDownload = false, $scheme = true) { - if(!$scheme) { + if (!$scheme) { return DownloadFileHandler::getUrl($this->baseFile, $forceDownload); } else { // Todo can be removed after v1.2.3 then call DownloadFileHandler::getUrl($this->baseFile, $forceDownload, $scheme) @@ -385,7 +387,7 @@ public static function getPathFromId($id, $parentFolderPath = false, $separator } $counter = 0; // break at maxdepth 20 to avoid hangs - while (!empty($tempFolder) && $counter ++ <= 20) { + while (!empty($tempFolder) && $counter++ <= 20) { $path = $separator . $tempFolder->title . $path; $tempFolder = $tempFolder->parentFolder; } @@ -415,7 +417,7 @@ public static function getPostedFiles($contentContainer, $filesOrder = ['file.up $query->andWhere(['content.contentcontainer_id' => $contentContainer->contentContainerRecord->id]); - if(!$contentContainer->canAccessPrivateContent()) { + if (!$contentContainer->canAccessPrivateContent()) { // Note this will cut comment images, but including the visibility of comments is pretty complex... $query->andWhere(['content.visibility' => Content::VISIBILITY_PUBLIC]); } @@ -424,10 +426,11 @@ public static function getPostedFiles($contentContainer, $filesOrder = ['file.up // only accept Posts as the base content, so stuff from sumbmodules like files itsself or gallery will be excluded $query->andWhere( - ['or', + ['or', ['=', 'comment.object_model', \humhub\modules\post\models\Post::className()], ['=', 'file.object_model', \humhub\modules\post\models\Post::className()] - ]); + ] + ); // Get Files from comments return $query->orderBy($filesOrder); diff --git a/models/Folder.php b/models/Folder.php index 82ff9c8..46bed14 100644 --- a/models/Folder.php +++ b/models/Folder.php @@ -7,6 +7,7 @@ use humhub\modules\file\libs\ImageHelper; use humhub\modules\file\models\FileContent; use humhub\modules\file\libs\FileHelper; +use humhub\modules\friendship\Module as FriendshipModule; use humhub\modules\user\models\User; use humhub\modules\search\events\SearchAddEvent; use humhub\modules\space\models\Space; @@ -34,7 +35,6 @@ */ class Folder extends FileSystemItem { - const TYPE_FOLDER_ROOT = 'root'; const TYPE_FOLDER_POSTED = 'posted'; const ROOT_TITLE = 'Root'; @@ -155,11 +155,11 @@ public function getSearchAttributes() 'description' => $this->description ]; - if($this->getCreator()) { + if ($this->getCreator()) { $attributes['creator'] = $this->getCreator()->getDisplayName(); } - if($this->getEditor()) { + if ($this->getEditor()) { $attributes['editor'] = $this->getEditor()->getDisplayName(); } } @@ -174,7 +174,7 @@ public function beforeSave($insert) { if ($insert && $this->visibility !== null) { $this->content->visibility = $this->visibility; - } else if ($this->visibility !== null && $this->visibility != $this->content->visibility) { + } elseif ($this->visibility !== null && $this->visibility != $this->content->visibility) { $this->updateVisibility($this->visibility); } return parent::beforeSave($insert); @@ -281,7 +281,8 @@ public function beforeDelete() public function getVisibilityTitle() { - if (Yii::$app->getModule('friendship')->getIsEnabled() && $this->content->container instanceof User) { + $module = Yii::$app->getModule('friendship'); + if ($module instanceof FriendshipModule && $module->isFriendshipEnabled() && $this->content->container instanceof User) { if ($this->content->container->isCurrentuser()) { $privateText = Yii::t('CfilesModule.base', 'This folder is only visible for you and your friends.'); } else { @@ -432,7 +433,7 @@ private static function getContainerOwnerId(ContentContainerActiveRecord $conten { if ($contentContainer instanceof User) { return $contentContainer->id; - } else if ($contentContainer instanceof Space) { + } elseif ($contentContainer instanceof Space) { return $contentContainer->created_by; } @@ -524,7 +525,7 @@ public function getTitle() { if ($this->isRoot()) { return Yii::t('CfilesModule.base', 'Root'); - } else if ($this->isAllPostedFiles()) { + } elseif ($this->isAllPostedFiles()) { return Yii::t('CfilesModule.base', 'Files from the stream'); } @@ -535,7 +536,7 @@ public function getDescription() { if ($this->isRoot()) { return Yii::t('CfilesModule.base', 'The root folder is the entry point that contains all available files.'); - } else if ($this->isAllPostedFiles()) { + } elseif ($this->isAllPostedFiles()) { return Yii::t('CfilesModule.base', 'You can find all files that have been posted to this stream here.'); } @@ -912,7 +913,7 @@ private function checkForDuplicate(FileSystemItem $item) if ($item instanceof File) { $item->setTitle($this->getAddedFileName($item->getTitle())); $result = $item; - } else if ($item instanceof Folder) { + } elseif ($item instanceof Folder) { $result = $item; $existingFolderWithTitle = $this->findFolderByName($item->title); diff --git a/module.json b/module.json index c5ac5a1..42ab240 100644 --- a/module.json +++ b/module.json @@ -11,7 +11,7 @@ ], "version": "0.16.3", "humhub": { - "minVersion": "1.14" + "minVersion": "1.16" }, "homepage": "https://github.com/humhub/cfiles", "authors": [