Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Merge branch 'dev-baserproject#2773' into dev-baserproject#2773-BcPlugin
Browse files Browse the repository at this point in the history
# Conflicts:
#	plugins/bc-blog/src/Controller/BlogController.php
  • Loading branch information
nghiem-mb committed Oct 10, 2023
2 parents 491e739 + 1ed9f35 commit fd80d04
Show file tree
Hide file tree
Showing 58 changed files with 389 additions and 256 deletions.
20 changes: 8 additions & 12 deletions __assets/plugins/baser-core/src/basics.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
// App::uses('CakeText', 'Utility');
use Cake\Cache\Cache;
use Cake\Utility\Text;
use Cake\Filesystem\File;
use Cake\Filesystem\Folder;
use BaserCore\Utility\BcFolder;
use Cake\Utility\Inflector;
use BaserCore\Utility\BcUtil;

Expand Down Expand Up @@ -183,9 +182,9 @@ function clearViewCache($url = null, $ext = '.php')
clearCache(strtolower(Text::slug($url)), 'views', $ext);
}
} else {
$folder = new Folder(CACHE . 'views' . DS);
$files = $folder->read(true, true);
foreach($files[1] as $file) {
$folder = new BcFolder(CACHE . 'views' . DS);
$files = $folder->getFiles();
foreach ($files as $file) {
if ($file != 'empty') {
@unlink(CACHE . 'views' . DS . $file);
}
Expand All @@ -200,16 +199,13 @@ function clearDataCache()
{

App::import('Core', 'Folder');
$folder = new Folder(CACHE . 'datas' . DS);
$folder = new BcFolder(CACHE . 'datas' . DS);

$files = $folder->read(true, true, true);
foreach($files[1] as $file) {
$files = $folder->getFiles();
foreach ($files as $file) {
@unlink($file);
}
$Folder = new Folder();
foreach($files[0] as $folder) {
$Folder->delete($folder);
}
$folder->delete();
}

/**
Expand Down
40 changes: 18 additions & 22 deletions __assets/plugins/baser-core/tests/TestCase/BcBasicsTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
// TODO : コード確認要
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcFile;
use BaserCore\Utility\BcUtil;

return;
Expand Down Expand Up @@ -164,17 +166,17 @@ public function testClearViewCache($url, $ext)
{
$viewCachePath = CACHE . 'views' . DS;
if ($url == '/' || $url == '/index' || $url == '/index.html' || $url == '/m/' || $url == '/m/index' || $url == '/m/index.html') {
$cache = new File($viewCachePath . DS . strtolower(Inflector::slug($url)) . $ext, true);
$cache = new BcFile($viewCachePath . DS . strtolower(Inflector::slug($url)) . $ext);
// 削除実行
clearViewCache($url, $ext);

} elseif ($url) {
// ダミーのキャッシュファイルを生成
$cache = new File($viewCachePath . DS . strtolower(Inflector::slug($url)) . $ext, true);
$cacheHoge = new File($viewCachePath . DS . strtolower(Inflector::slug($url)) . '.hoge', true);
$cache = new BcFile($viewCachePath . DS . strtolower(Inflector::slug($url)) . $ext);
$cacheHoge = new BcFile($viewCachePath . DS . strtolower(Inflector::slug($url)) . '.hoge');
if (preg_match('/\/index$/', $url)) {
$replacedUrl = preg_replace('/\/index$/', '', $url);
$replacedCache = new File($viewCachePath . DS . strtolower(Inflector::slug($replacedUrl)) . $ext, true);
$replacedCache = new BcFile($viewCachePath . DS . strtolower(Inflector::slug($replacedUrl)) . $ext);
}
// 削除実行
clearViewCache($url, $ext);
Expand All @@ -191,8 +193,8 @@ public function testClearViewCache($url, $ext)

} else {
// ダミーのキャッシュファイルを生成
$cache = new File($viewCachePath . DS . 'cache', true);
$empty = new File($viewCachePath . DS . 'empty', true);
$cache = new BcFile($viewCachePath . DS . 'cache');
$empty = new BcFile($viewCachePath . DS . 'empty');

// 削除実行
clearViewCache($url, $ext);
Expand Down Expand Up @@ -240,26 +242,20 @@ public function testClearAllCache()
$envConf = Cache::config('_bc_env_');
$envConf = $envConf['settings'];

$coreCache = new File($coreConf['path'] . $coreConf['prefix'] . 'cache', true);
$modelCache = new File($modelConf['path'] . $modelConf['prefix'] . 'cache', true);
$envCache = new File($envConf['path'] . $envConf['prefix'] . 'cache', true);
$viewCache = new File(CACHE . 'views' . DS . 'cache', true);
$dataCache = new File(CACHE . 'datas' . DS . 'cache', true);
$coreCache = new BcFile($coreConf['path'] . $coreConf['prefix'] . 'cache');
$modelCache = new BcFile($modelConf['path'] . $modelConf['prefix'] . 'cache');
$envCache = new BcFile($envConf['path'] . $envConf['prefix'] . 'cache');
$viewCache = new BcFile(CACHE . 'views' . DS . 'cache');
$dataCache = new BcFile(CACHE . 'datas' . DS . 'cache');

// キャッシュ削除
BcUtil::clearAllCache();

$this->assertFalse($coreCache->exists());
$this->assertFalse($modelCache->exists());
$this->assertFalse($envCache->exists());
$this->assertFalse($viewCache->exists());
$this->assertFalse($dataCache->exists());

$coreCache->close();
$modelCache->close();
$envCache->close();
$viewCache->close();
$dataCache->close();
$this->assertFalse(is_file($coreCache->getPath()));
$this->assertFalse(is_file($modelCache->getPath()));
$this->assertFalse(is_file($envCache->getPath()));
$this->assertFalse(is_file($viewCache->getPath()));
$this->assertFalse(is_file($dataCache->getPath()));
}

/**
Expand Down
6 changes: 6 additions & 0 deletions plugins/baser-core/config/paths.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,9 @@
define('BASER_THEMES', BASER_PLUGINS);
}

/**
* テスト用の一時フォルダ
*/
if(!defined('TMP_TESTS')) {
define('TMP_TESTS', TMP . 'tests' . DS);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function initialize(): void
$this->loadComponent('Authentication.Authentication', [
'logoutRedirect' => Router::url(Configure::read('BcPrefixAuth.Admin.loginAction'), true),
]);
if (Configure::read('BcApp.adminSsl') && !BcUtil::isConsole()) $this->Security->requireSecure();
}

/**
Expand Down Expand Up @@ -97,7 +96,6 @@ public function beforeFilter(EventInterface $event)
public function beforeRender(EventInterface $event): void
{
parent::beforeRender($event);
if (isset($this->RequestHandler) && $this->RequestHandler->prefers('json')) return;
if ($this->getRequest()->getQuery('preview')) return;
$this->viewBuilder()->setClassName('BaserCore.BcAdminApp');
$this->setAdminTheme();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function beforeFilter(EventInterface $event)
{
$response = parent::beforeFilter($event);
if($response) return $response;
$this->Security->setConfig('unlockedActions', ['delete', 'batch', 'trash_return']);
$this->FormProtection->setConfig('unlockedActions', ['delete', 'batch', 'trash_return']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function beforeFilter(EventInterface $event)
['BcTime',
// 'BcFreeze'
]);
$this->Security->setConfig('unlockedActions', [
$this->FormProtection->setConfig('unlockedActions', [
'update_sort',
'batch',
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function beforeFilter(EventInterface $event)
{
$response = parent::beforeFilter($event);
if($response) return $response;
$this->Security->setConfig('unlockedActions', ['reset_db', 'update_sort', 'batch']);
$this->FormProtection->setConfig('unlockedActions', ['reset_db', 'update_sort', 'batch']);
if(Configure::read('BcRequest.isUpdater')) $this->Authentication->allowUnauthenticated(['update']);
}

Expand Down
18 changes: 3 additions & 15 deletions plugins/baser-core/src/Controller/Admin/PreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PreviewController extends BcAdminAppController
public function initialize(): void
{
parent::initialize();
$this->Security->setConfig('unlockedActions', ['view']);
$this->FormProtection->setConfig('unlockedActions', ['view']);
}

/**
Expand Down Expand Up @@ -110,24 +110,12 @@ private function _createPreviewRequest($request)
// メールフォームのフォームを生成する際、$this->>formProtector が存在しないとエラーとなる。
// formProtector をセットするには、FormHelper::create() 内にて、生成する必要があるが、
// 生成条件として $request の attribute に formTokenData がセットされていないといけない。
//
// $request の attribute に formTokenData をセットするためには、
// FormProtectionComponent を有効にするか、SecurityComponent で生成する必要がある。
//
// FormProtectionComponent では、_Tokenを送っても「_Token was not found in request data.」
// となり、理由がわからず断念。SecurityComponent を利用する。
//
// SecurityComponent は、SecurityComponent::_validatePost() で引っかかってしまうため、
// initialize でアンロックしている。
// $this->Security->setConfig('unlockedActions', ['view']);
//
// そのため、自動で formTokenData が生成されないため、明示的にここで生成する。
//========================================================================
$request = $this->Security->generateToken($request);
$request = $request->withAttribute('formTokenData', $this->getRequest()->getAttribute('formTokenData'));

//========================================================================
// 2022/12/02 by ryuring
// 上記に続き、メールフォームの FormHelper::create() 内にて、formProtector を生成するには、
// メールフォームの FormHelper::create() 内にて、formProtector を生成するには、
// セッションが「正常に」スタートしている事が前提となる。
//
// リクエストの早い段階にてセッションはスタートしているが、$request を模倣する前提のため
Expand Down
15 changes: 6 additions & 9 deletions plugins/baser-core/src/Controller/AnalyseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@

namespace BaserCore\Controller;

use Cake\Core\Plugin;
use Cake\Filesystem\File;
use Cake\Filesystem\Folder;
use BaserCore\Utility\BcFile;
use BaserCore\Utility\BcFolder;
use Doctrine\Common\Annotations\AnnotationReader;
use Exception;
use ReflectionClass;
Expand Down Expand Up @@ -85,17 +84,16 @@ public function index($pluginName = null)
*/
private function getList($path)
{
$folder = new Folder($path);
$files = $folder->read(true, true, true);
$folder = new BcFolder($path);
$metas = [];

foreach($files[0] as $file) {
foreach($folder->getFolders(['full' => true]) as $file) {
if (preg_match('/(\/node_modules\/|\/vendors\/|Migrations|Seeds)/', $file)) {
continue;
}
$metas = array_merge($metas, $this->getList($file . DS));
}
foreach($files[1] as $path) {
foreach($folder->getFiles(['full' => true]) as $path) {
$fileName = basename($path);
if (preg_match('/(' . str_replace(',', '|', preg_quote(implode(',', self::EXCLUDE_EXT))) . ')$/', $fileName)) {
continue;
Expand All @@ -114,8 +112,7 @@ private function getList($path)
'note' => ''
];
if (preg_match('/^[a-z]/', $fileName) || !preg_match('/\.php$/', $fileName)) {
$file = new File($path);
$code = $file->read();
$code = (new BcFile($path))->read();
if (preg_match('/@checked/', $code)) {
$meta['checked'] = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function initialize(): void
{
parent::initialize();
$this->loadComponent('Authentication.Authentication');
$this->Security->setConfig('validatePost', false);
$this->FormProtection->setConfig('validate', false);
}

/**
Expand Down
35 changes: 6 additions & 29 deletions plugins/baser-core/src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
use BaserCore\Utility\BcContainerTrait;
use BaserCore\Utility\BcSiteConfig;
use BaserCore\Utility\BcUtil;
use Cake\Controller\Component\PaginatorComponent;
use Cake\Controller\Component\SecurityComponent;
use Cake\Controller\ComponentRegistry;
use Cake\Core\Configure;
use Cake\Event\EventInterface;
Expand All @@ -41,8 +39,6 @@
/**
* Class AppController
* @property BcMessageComponent $BcMessage
* @property SecurityComponent $Security
* @property PaginatorComponent $Paginator
* @property AuthenticationComponent $Authentication
*/
class AppController extends BaseController
Expand Down Expand Up @@ -118,11 +114,12 @@ public function initialize(): void
{
parent::initialize();
$this->loadComponent('BaserCore.BcMessage');
$this->loadComponent('Security', [
'blackHoleCallback' => '_blackHoleCallback',
'validatePost' => true,
'requireSecure' => false,
'unlockedFields' => ['x', 'y', 'MAX_FILE_SIZE']
$this->loadComponent('FormProtection', [
'unlockedFields' => ['x', 'y', 'MAX_FILE_SIZE'],
'validationFailureCallback' => function (BadRequestException $exception) {
$message = __d('baser_core', '不正なリクエストと判断されました。<br>もしくは、システムが受信できるデータ上限より大きなデータが送信された可能性があります。') . "<br>" . $exception->getMessage();
throw new BadRequestException($message);
}
]);
}

Expand Down Expand Up @@ -237,26 +234,6 @@ public function setupFrontView(): void
$this->viewBuilder()->setTheme(BcUtil::getCurrentTheme());
}

/**
* Securityコンポーネントのブラックホールからのコールバック
*
* フォーム改ざん対策・CSRF対策・SSL制限・HTTPメソッド制限などへの違反が原因で
* Securityコンポーネントに"ブラックホールされた"場合の動作を指定する
*
* @param string $err エラーの種類
* @return void
* @throws BadRequestException
* @uses _blackHoleCallback
* @checked
* @noTodo
* @unitTest
*/
public function _blackHoleCallback($err, $exception)
{
$message = __d('baser_core', '不正なリクエストと判断されました。もしくは、システムが受信できるデータ上限より大きなデータが送信された可能性があります') . "\n" . $exception->getMessage();
throw new BadRequestException($message);
}

/**
* http経由で送信されたデータを変換する
* とりあえず、UTF-8で固定
Expand Down
4 changes: 1 addition & 3 deletions plugins/baser-core/src/Controller/BcFrontAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ public function beforeRender(EventInterface $event): void
// ショートコード
$this->getEventManager()->on(new BcShortCodeEventListener());
}
if (!isset($this->RequestHandler) || !$this->RequestHandler->prefers('json')) {
$this->setupFrontView();
}
$this->setupFrontView();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function getDetectorConfigs()
$configs['update'] = [$this, 'isUpdate'];
$configs['page'] = [$this, 'isPage'];
$configs['requestview'] = [$this, 'isRequestView'];
$configs['rss'] = ['param' => '_ext', 'value' => 'rss'];

$agents = BcAgent::findAll();
foreach($agents as $agent) {
Expand Down
20 changes: 10 additions & 10 deletions plugins/baser-core/src/Model/Entity/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace BaserCore\Model\Entity;

use Cake\I18n\FrozenDate;
use Cake\I18n\FrozenTime;
use Cake\ORM\Entity;

/**
Expand All @@ -37,20 +37,20 @@
* @property integer $author_id
* @property string $layout_template
* @property bool $status
* @property FrozenDate $publish_begin
* @property FrozenDate $publish_end
* @property FrozenTime $publish_begin
* @property FrozenTime $publish_end
* @property bool $self_status
* @property FrozenDate $self_publish_begin
* @property FrozenDate $self_publish_end
* @property FrozenTime $self_publish_begin
* @property FrozenTime $self_publish_end
* @property bool $exclude_search
* @property FrozenDate $created_date
* @property FrozenDate $modified_date
* @property FrozenTime $created_date
* @property FrozenTime $modified_date
* @property bool $site_root
* @property FrozenDate $deleted_date
* @property FrozenTime $deleted_date
* @property bool $exclude_menu
* @property bool $blank_link
* @property FrozenDate $created
* @property FrozenDate $modified
* @property FrozenTime $created
* @property FrozenTime $modified
* @property Site $site
*/
class Content extends Entity
Expand Down

0 comments on commit fd80d04

Please sign in to comment.