Skip to content

Commit

Permalink
Merge pull request #227 from humhub/enh/php-cs-fixer
Browse files Browse the repository at this point in the history
Use PHP CS Fixer
  • Loading branch information
luke- authored Jun 27, 2024
2 parents 5a9d822 + dfabea5 commit 181dbfa
Show file tree
Hide file tree
Showing 87 changed files with 481 additions and 503 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: PHP CS Fixer

on: push

jobs:
tests:
uses: humhub/actions/.github/workflows/module-php-cs-fixer.yml@main
6 changes: 2 additions & 4 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
use Yii;
use yii\base\Event;


/**
* cfiles Events
*
* @author luke
*/
class Events
{

public static function onSpaceMenuInit($event)
{

Expand All @@ -32,7 +30,7 @@ public static function onSpaceMenuInit($event)
'group' => 'modules',
'url' => $event->sender->space->createUrl('/cfiles/browse'),
'icon' => '<i class="fa fa-files-o"></i>',
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'cfiles')
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'cfiles'),
]);
}
}
Expand Down Expand Up @@ -79,7 +77,7 @@ public static function onProfileMenuInit($event)
'label' => Yii::t('CfilesModule.base', 'Files'),
'url' => $event->sender->user->createUrl('/cfiles/browse'),
'icon' => '<i class="fa fa-files-o"></i>',
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'cfiles')
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'cfiles'),
]);
}
}
Expand Down
15 changes: 7 additions & 8 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

class Module extends ContentContainerModule
{

public $resourcesPath = 'resources';

/**
Expand All @@ -38,12 +37,12 @@ class Module extends ContentContainerModule
*/
public $defaultFolderOrder = 'title ASC';

const ORDER_NAME = 'name';
const ORDER_UPDATED_AT = 'updated_at';
const ORDER_SIZE = 'size';
public const ORDER_NAME = 'name';
public const ORDER_UPDATED_AT = 'updated_at';
public const ORDER_SIZE = 'size';

const UPLOAD_BEHAVIOUR_INDEX = 0;
const UPLOAD_BEHAVIOUR_REPLACE = 1;
public const UPLOAD_BEHAVIOUR_INDEX = 0;
public const UPLOAD_BEHAVIOUR_REPLACE = 1;

/**
* @inheritdoc
Expand All @@ -65,7 +64,7 @@ public function getContentContainerTypes()
{
return [
Space::className(),
User::className()
User::className(),
];
}

Expand Down Expand Up @@ -156,7 +155,7 @@ public function getConfigUrl()
/**
* Determines ZIP Support is enabled or not
*
* @return boolean is ZIP support enabled
* @return bool is ZIP support enabled
*/
public function isZipSupportEnabled(): bool
{
Expand Down
2 changes: 1 addition & 1 deletion actions/UploadAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ protected function getValidationErrorResponse(FileSystemItem $file)
'size' => $file->baseFile->size ?? '',
];
}
}
}
3 changes: 1 addition & 2 deletions actions/UploadZipAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

namespace humhub\modules\cfiles\actions;


use humhub\modules\cfiles\libs\ZipExtractor;
use humhub\modules\cfiles\models\FileSystemItem;
use Yii;
Expand Down Expand Up @@ -50,4 +49,4 @@ protected function getValidationErrorResponse(FileSystemItem $file)
'size' => $file->baseFile->size ?? '',
];
}
}
}
14 changes: 7 additions & 7 deletions assets/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ class Assets extends AssetBundle
public $defer = true;

public $publishOptions = [
'forceCopy' => false
'forceCopy' => false,
];

public $css = [
'css/cfiles.css',
'css/directorylist.css'
'css/directorylist.css',
];

public $jsOptions = [
'position' => \yii\web\View::POS_BEGIN
'position' => \yii\web\View::POS_BEGIN,
];

public $js = [
'js/humhub.cfiles.js'
'js/humhub.cfiles.js',
];

public function init()
Expand Down
146 changes: 73 additions & 73 deletions components/UrlRule.php
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
<?php

/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

namespace humhub\modules\cfiles\components;

use humhub\components\ContentContainerUrlRuleInterface;
use humhub\modules\content\components\ContentContainerActiveRecord;
use yii\base\Component;
use yii\web\UrlManager;
use yii\web\UrlRuleInterface;

class UrlRule extends Component implements UrlRuleInterface, ContentContainerUrlRuleInterface
{
const DOWNLOAD_ROUTE = 'cfiles/download';

/**
* @inheritdoc
*/
public function parseContentContainerRequest(ContentContainerActiveRecord $container, UrlManager $manager, string $containerUrlPath, array $urlParams)
{
if (substr($containerUrlPath, 0, 16) === self::DOWNLOAD_ROUTE . '/') {
$parts = explode('/', $containerUrlPath, 4);

if (isset($parts[2])) {
$urlParams['guid'] = $parts[2];

return [self::DOWNLOAD_ROUTE, $urlParams];
}
}

return false;
}

/**
* @inheritdoc
*/
public function createContentContainerUrl(UrlManager $manager, string $containerUrlPath, string $route, array $params)
{
if ($route === self::DOWNLOAD_ROUTE && isset($params['guid'])) {
$url = $containerUrlPath . '/' . self::DOWNLOAD_ROUTE . '/' . urlencode($params['guid']);
unset($params['guid']);

if (!empty($params) && ($query = http_build_query($params)) !== '') {
$url .= '?' . $query;
}

return $url;
}

return false;
}

/**
* @inheritdoc
*/
public function createUrl($manager, $route, $params)
{
return false;
}

/**
* @inheritdoc
*/
public function parseRequest($manager, $request)
{
return false;
}
}
<?php

/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

namespace humhub\modules\cfiles\components;

use humhub\components\ContentContainerUrlRuleInterface;
use humhub\modules\content\components\ContentContainerActiveRecord;
use yii\base\Component;
use yii\web\UrlManager;
use yii\web\UrlRuleInterface;

class UrlRule extends Component implements UrlRuleInterface, ContentContainerUrlRuleInterface
{
public const DOWNLOAD_ROUTE = 'cfiles/download';

/**
* @inheritdoc
*/
public function parseContentContainerRequest(ContentContainerActiveRecord $container, UrlManager $manager, string $containerUrlPath, array $urlParams)
{
if (substr($containerUrlPath, 0, 16) === self::DOWNLOAD_ROUTE . '/') {
$parts = explode('/', $containerUrlPath, 4);

if (isset($parts[2])) {
$urlParams['guid'] = $parts[2];

return [self::DOWNLOAD_ROUTE, $urlParams];
}
}

return false;
}

/**
* @inheritdoc
*/
public function createContentContainerUrl(UrlManager $manager, string $containerUrlPath, string $route, array $params)
{
if ($route === self::DOWNLOAD_ROUTE && isset($params['guid'])) {
$url = $containerUrlPath . '/' . self::DOWNLOAD_ROUTE . '/' . urlencode($params['guid']);
unset($params['guid']);

if (!empty($params) && ($query = http_build_query($params)) !== '') {
$url .= '?' . $query;
}

return $url;
}

return false;
}

/**
* @inheritdoc
*/
public function createUrl($manager, $route, $params)
{
return false;
}

/**
* @inheritdoc
*/
public function parseRequest($manager, $request)
{
return false;
}
}
2 changes: 1 addition & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
[ContentContainerActiveRecord::class, ContentContainerActiveRecord::EVENT_AFTER_INSERT, ['humhub\modules\cfiles\Events', 'onContentContainerActiveRecordInsert']],
[ContentContainerModuleState::class, ContentContainerModuleState::EVENT_AFTER_INSERT, ['humhub\modules\cfiles\Events', 'onContentContainerModuleStateInsert']],
['humhub\modules\rest\Module', 'restApiAddRules', ['humhub\modules\cfiles\Events', 'onRestApiAddRules']],
]
],
];
32 changes: 16 additions & 16 deletions controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
*/
abstract class BaseController extends ContentContainerController
{

const ROOT_ID = 0;
const All_POSTED_FILES_ID = -1;
public const ROOT_ID = 0;
public const All_POSTED_FILES_ID = -1;

private $_currentFolder = null;
private $_rootFolder = null;
Expand All @@ -46,15 +45,15 @@ public function beforeAction($action)
if (!$this->getRootFolder()) {
$this->_rootFolder = Folder::initRoot($this->contentContainer);
$newRoot = true;
} else if($this->getRootFolder()->content->isPrivate()) {
} elseif($this->getRootFolder()->content->isPrivate()) {
// Make sure older root folders are public by default.
$this->getRootFolder()->content->visibility = Content::VISIBILITY_PUBLIC;
$this->getRootFolder()->content->save();
}

if ($this->getAllPostedFilesFolder() == null) {
$this->_allPostedFilesFolder = Folder::initPostedFilesFolder($this->contentContainer);
} else if($this->getAllPostedFilesFolder()->content->isPrivate()) {
} elseif($this->getAllPostedFilesFolder()->content->isPrivate()) {
$this->getAllPostedFilesFolder()->content->visibility = Content::VISIBILITY_PUBLIC;
$this->getAllPostedFilesFolder()->content->save();
}
Expand Down Expand Up @@ -137,11 +136,12 @@ protected function generateCrumb()
* @param int $parentId
* @return array [['folder' => --current folder--, 'subfolders' => [['folder' => --current folder--, 'subfolders' => []], ...], ['folder' => --current folder--, 'subfolders' => [['folder' => --current folder--, 'subfolders' => []], ...], ...]
*/
protected function getFolderList($parentId = self::ROOT_ID, $orderBy = NULL)
protected function getFolderList($parentId = self::ROOT_ID, $orderBy = null)
{
// set default value
if (!$orderBy)
if (!$orderBy) {
$orderBy = ['title' => SORT_ASC];
}

// map 0 to this containers root folder id
if ($parentId === self::ROOT_ID) {
Expand All @@ -158,8 +158,8 @@ protected function getFolderList($parentId = self::ROOT_ID, $orderBy = NULL)
['cfiles_folder.type' => null],
['and',
['<>', 'cfiles_folder.type', Folder::TYPE_FOLDER_POSTED],
['<>', 'cfiles_folder.type', Folder::TYPE_FOLDER_ROOT]
]
['<>', 'cfiles_folder.type', Folder::TYPE_FOLDER_ROOT],
],
]);

$foldersQuery->orderBy($orderBy);
Expand All @@ -179,7 +179,7 @@ protected function getFolderList($parentId = self::ROOT_ID, $orderBy = NULL)
* @param array $foldersOrder orderBy array appended to the folders query
* @return array
*/
protected function getItemsList($filesOrder = NULL, $foldersOrder = NULL)
protected function getItemsList($filesOrder = null, $foldersOrder = null)
{
// set default value
if (!$filesOrder) {
Expand All @@ -197,12 +197,12 @@ protected function getItemsList($filesOrder = NULL, $foldersOrder = NULL)
$specialFoldersQuery = Folder::find()->contentContainer($this->contentContainer)->readable();

$filesQuery->andWhere([
'cfiles_file.parent_folder_id' => $this->getCurrentFolder()->id
'cfiles_file.parent_folder_id' => $this->getCurrentFolder()->id,
]);

// user maintained folders
$foldersQuery->andWhere([
'cfiles_folder.parent_folder_id' => $this->getCurrentFolder()->id
'cfiles_folder.parent_folder_id' => $this->getCurrentFolder()->id,
]);

// do not return any folders here that are root or allpostedfiles
Expand All @@ -211,8 +211,8 @@ protected function getItemsList($filesOrder = NULL, $foldersOrder = NULL)
['cfiles_folder.type' => null],
['and',
['<>', 'cfiles_folder.type', Folder::TYPE_FOLDER_POSTED],
['<>', 'cfiles_folder.type', Folder::TYPE_FOLDER_ROOT]
]
['<>', 'cfiles_folder.type', Folder::TYPE_FOLDER_ROOT],
],
]);
// special default folders like the allposted files folder
$specialFoldersQuery->andWhere(['cfiles_folder.parent_folder_id' => $this->getCurrentFolder()->id]);
Expand All @@ -225,14 +225,14 @@ protected function getItemsList($filesOrder = NULL, $foldersOrder = NULL)
return [
'specialFolders' => $specialFoldersQuery->all(),
'folders' => $foldersQuery->all(),
'files' => $filesQuery->all()
'files' => $filesQuery->all(),
];
}

/**
* Checks if user can write
*
* @return boolean current user can write/upload/delete files
* @return bool current user can write/upload/delete files
*/
public function canWrite()
{
Expand Down
Loading

0 comments on commit 181dbfa

Please sign in to comment.