Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev-4-php8' into dev-4
Browse files Browse the repository at this point in the history
  • Loading branch information
gondoh committed Sep 29, 2022
2 parents 7c4aeb5 + 0368dba commit a5d3564
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 46 deletions.
11 changes: 9 additions & 2 deletions app/webroot/theme/admin-third/Elements/admin/sites/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@
foreach($languages as $key => $lang) {
$langs[$key] = $lang['name'];
}
$useSiteDeviceSetting = @$this->get('siteConfig')['use_site_device_setting'];
$useSiteLangSetting = @$this->get('siteConfig')['use_site_lang_setting'];
$useSiteDeviceSetting = 0;
$useSiteLangSetting = 0;
$thisSiteConfig = $this->get('siteConfig');
if (isset($thisSiteConfig['use_site_lang_setting'])) {
$useSiteDeviceSetting = $thisSiteConfig['use_site_lang_setting'];
}
if (isset($thisSiteConfig['use_site_device_setting'])) {
$useSiteLangSetting = $thisSiteConfig['use_site_device_setting'];
}
?>


Expand Down
2 changes: 1 addition & 1 deletion lib/Baser/Controller/SiteConfigsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function admin_form()
}
}

$adminSsl = @$this->request->data['SiteConfig']['admin_ssl'];
$adminSsl = $this->request->data['SiteConfig']['admin_ssl'];
if ($this->request->data['SiteConfig']['use_site_device_setting'] === "0" && $this->SiteConfig->isChange('use_site_device_setting', "0")) {
$this->Site->resetDevice();
}
Expand Down
20 changes: 16 additions & 4 deletions lib/Baser/Controller/ThemeFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,11 @@ public function admin_del()
$result = $folder->delete($fullpath);
$target = __d('baser', 'フォルダ');
} else {
$result = @unlink($fullpath);
if (file_exists($fullpath)) {
$result = unlink($fullpath);
} else {
$result = false;
}
$target = __d('baser', 'ファイル');
}

Expand Down Expand Up @@ -442,7 +446,11 @@ protected function _del($args)
$result = $folder->delete($fullpath);
$target = __d('baser', 'フォルダ');
} else {
$result = @unlink($fullpath);
if (file_exists($fullpath)) {
$result = unlink($fullpath);
} else {
$result = false;
}
$target = __d('baser', 'ファイル');
}
if (!$result) {
Expand Down Expand Up @@ -480,7 +488,11 @@ protected function _batch_del($ids)
$result = $folder->delete($fullpath);
$target = __d('baser', 'フォルダ');
} else {
$result = @unlink($fullpath);
if (file_exists($fullpath)) {
$result = unlink($fullpath);
} else {
$result = false;
}
$target = __d('baser', 'ファイル');
}
if ($result) {
Expand Down Expand Up @@ -573,7 +585,7 @@ public function admin_ajax_copy()
}
$newPath .= '_copy';
}
$result = @copy(urldecode($fullpath), $newPath);
$result = copy(urldecode($fullpath), $newPath);
if ($result) {
chmod($newPath, 0666);
}
Expand Down
39 changes: 25 additions & 14 deletions lib/Baser/Lib/BcFileUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,18 @@ public function getSaveFileName($setting, $file)
*/
public function rotateImage($file)
{
// 有効な画像タイプはJPEGのみ
$enableType = [
IMAGETYPE_JPEG,
];
if (!extension_loaded("exif")) {
return false;
}
$exif = @exif_read_data($file);
if (!in_array(exif_imagetype($file), $enableType)) {
return false;
}

$exif = exif_read_data($file);
if (empty($exif) || empty($exif['Orientation'])) {
return true;
}
Expand All @@ -536,29 +544,29 @@ public function rotateImage($file)
$imageType = $imgInfo[2];
// 元となる画像のオブジェクトを生成
switch($imageType) {
case IMAGETYPE_GIF:
$srcImage = imagecreatefromgif($file);
break;
// case IMAGETYPE_GIF:
// $srcImage = imagecreatefromgif($file);
// break;
case IMAGETYPE_JPEG:
$srcImage = imagecreatefromjpeg($file);
break;
case IMAGETYPE_PNG:
$srcImage = imagecreatefrompng($file);
break;
// case IMAGETYPE_PNG:
// $srcImage = imagecreatefrompng($file);
// break;
default:
return false;
}
$rotate = imagerotate($srcImage, $angle, 0);
switch($imageType) {
case IMAGETYPE_GIF:
imagegif($rotate, $file);
break;
// case IMAGETYPE_GIF:
// imagegif($rotate, $file);
// break;
case IMAGETYPE_JPEG:
imagejpeg($rotate, $file, 100);
break;
case IMAGETYPE_PNG:
imagepng($rotate, $file);
break;
// case IMAGETYPE_PNG:
// imagepng($rotate, $file);
// break;
default:
return false;
}
Expand Down Expand Up @@ -682,7 +690,10 @@ public function renameToBasenameField($setting, $file, $entity, $copy = false)
if (empty($setting['namefield']) || empty($file) || !empty($file['delete'])) {
return false;
}
$oldName = @$file['name'];
if (!isset($file['name']) || empty($file['name'])) {
return false;
}
$oldName = $file['name'];
if (!$oldName || is_array($oldName)) {
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions lib/Baser/Lib/BcUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,11 @@ public static function serialize($value)
public static function unserialize($value)
{
$_value = $value;
$value = @unserialize(base64_decode($value));
// unserializeに失敗した場合noticをを発生させfalseが戻る
$value = unserialize(base64_decode($value));
// 下位互換の為、しばらくの間、失敗した場合の再変換を行う v.3.0.2
if ($value === false) {
$value = @unserialize($_value);
$value = unserialize($_value);
if($value === false) {
return '';
}
Expand Down
6 changes: 5 additions & 1 deletion lib/Baser/Model/BcAppModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ public function saveDbLog($message)
// ログを記録する
$Dblog = ClassRegistry::init('Dblog');
$logdata['Dblog']['name'] = $message;
$logdata['Dblog']['user_id'] = @$_SESSION['Auth'][Configure::read('BcAuthPrefix.admin.sessionKey')]['id'];
$userId = null;
if (!empty($_SESSION['Auth'][Configure::read('BcAuthPrefix.admin.sessionKey')]['id'])) {
$userId = $_SESSION['Auth'][Configure::read('BcAuthPrefix.admin.sessionKey')]['id'];
}
$logdata['Dblog']['user_id'] = $userId;
return $Dblog->save($logdata);
}

Expand Down
10 changes: 5 additions & 5 deletions lib/Baser/Model/Behavior/BcUploadBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ public function afterValidate(Model $Model, $options = [])
*/
public function beforeSave(Model $Model, $options = [])
{
if (isset($Model->data['CuApproverApplication'][['contentsMode']])
if (isset($Model->data['CuApproverApplication']['contentsMode'])
&& isset($Model->data['CuApproverApplication']['is_published'])) {
if($Model->alias === 'BlogPost' &&
@$Model->data['CuApproverApplication']['contentsMode'] === 'draft' &&
@$Model->data['CuApproverApplication']['is_published']) {
$Model->data['CuApproverApplication']['contentsMode'] === 'draft' &&
$Model->data['CuApproverApplication']['is_published']) {
return true;
}
}
Expand Down Expand Up @@ -196,7 +196,7 @@ public function afterSave(Model $Model, $created, $options = [])
// <<<

$data = isset($Model->data[$Model->alias])? $Model->data[$Model->alias] : $Model->data;
if ($Model->exists() && !empty($this->oldEntity[$Model->alias])) {
if ($Model->exists() && isset($this->oldEntity[$Model->alias])) {
$this->BcFileUploader[$Model->alias]->deleteExistingFiles($this->oldEntity[$Model->alias]);
}
$entity = $this->BcFileUploader[$Model->alias]->saveFiles($data);
Expand All @@ -207,7 +207,7 @@ public function afterSave(Model $Model, $created, $options = [])
$this->uploaded[$Model->alias] = $this->BcFileUploader[$Model->alias]->uploaded;
// <<<

if ($Model->exists() && !empty($this->oldEntity[$Model->alias])) {
if ($Model->exists() && isset($this->oldEntity[$Model->alias])) {
$entity = $this->BcFileUploader[$Model->alias]->deleteFiles($this->oldEntity[$Model->alias], $entity);
}
if ($this->BcFileUploader[$Model->alias]->isUploaded()) {
Expand Down
3 changes: 1 addition & 2 deletions lib/Baser/Model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,11 @@ public function createPageTemplate($data)
}

// ファイルに保存
$newFile = new File($newPath, true);
$newFile = new File($newPath, true, 0666);
if ($newFile->open('w')) {
$newFile->append($contents);
$newFile->close();
unset($newFile);
@chmod($newPath, 0666);
return true;
} else {
return false;
Expand Down
15 changes: 10 additions & 5 deletions lib/Baser/Model/SearchIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ public function reconstruct($parentContentId = null)
]);
$models = [];
$db = $this->getDataSource();
$this->begin();
$transactionBegun = false;
if ($db->nestedTransactionSupported()) {
$transactionBegun = $db->begin();
}

if (!$parentContentId) {
$db->truncate('search_indices');
Expand Down Expand Up @@ -96,10 +99,12 @@ public function reconstruct($parentContentId = null)
}
}
}
if ($result) {
$this->commit();
} else {
$this->roleback();
if ($transactionBegun) {
if ($result) {
$this->commit();
} else {
$this->roleback();
}
}
return $result;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/Baser/Plugin/Blog/Event/BlogControllerEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ public function contentsAfterChangeStatus(CakeEvent $event) {
$this->BlogContent->deleteSearchIndex($data['BlogContent']['id']);
}

if (empty($data['BlogContent']['id'])) {
$dataSource->commit();
return;
}

$posts = $this->BlogPost->find('all', [
'conditions' => [
'BlogPost.blog_content_id' => $data['BlogContent']['id'],
Expand Down
2 changes: 1 addition & 1 deletion lib/Baser/Plugin/Feed/Model/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getFeed($url, $limit = 10, $cacheExpires = null, $category = nul
$datas['Items'] = $this->_filteringCategory($datas['Items'], $category);

if (isset($datas['Items']) && $limit && count($datas['Items'] > $limit)) {
$datas['Items'] = @array_slice($datas['Items'], 0, $limit);
$datas['Items'] = array_slice($datas['Items'], 0, $limit);
}

return $datas;
Expand Down
7 changes: 6 additions & 1 deletion lib/Baser/Plugin/Mail/Model/MailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,12 @@ protected function _validExtends($data)
if (empty($data['MailMessage'][$field_name])) {
$this->invalidate($field_name, __('必須項目です。'));
}
$dists[$field_name][] = @$data['MailMessage'][$field_name];
if (!empty($data['MailMessage'][$field_name])) {
$dists[$field_name][] = $data['MailMessage'][$field_name];
} else {
$dists[$field_name][] = null;
}

// datetimeの空チェック
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Baser/Test/Case/Lib/BcFileUploaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ public function testMoveFileSessionToTmp()
$tmpId = 1;
$fieldName = 'image';
$tmp_name = 'basercms_tmp';
$basename = 'basename.png';
$ext = 'png';
$basename = 'basename.gif';
$ext = 'gif';
$namefield = 'hoge';

//—————————————————————————
Expand All @@ -402,7 +402,7 @@ public function testMoveFileSessionToTmp()

// ダミーファイルの作成
$file = new File($tmpPath);
$file->write('dummy');
$file->write(file_get_contents(BASER_WEBROOT . 'img/baser.power.gif'));
$file->close();

$this->initTestSaveFiles(1, $this->EditorTemplate->data['EditorTemplate'][$fieldName]);
Expand Down Expand Up @@ -433,7 +433,7 @@ public function testMoveFileSessionToTmp()
'error' => 0,
'name' => $targetName,
'tmp_name' => $targetPath,
'size' => 5,
'size' => 219,
'type' => 'basercms',
'uploadable' => true,
'ext' => false
Expand Down
9 changes: 8 additions & 1 deletion lib/Baser/Test/Case/Lib/BcUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ public function getDefaultDataPathDataProvider()
*/
public function testSerialize()
{
ini_set('display_errors', "Off");
$orig = PHPUnit_Framework_Error_Notice::$enabled;
PHPUnit_Framework_Error_Notice::$enabled = false;

// BcUtil::serialize()でシリアライズした場合
$serialized = BcUtil::serialize('hoge');
$result = BcUtil::unserialize($serialized);
Expand All @@ -310,6 +314,9 @@ public function testSerialize()
$result = BcUtil::unserialize($serialized);
$this->assertEquals('hoge', $result, 'serializeのみで正しくシリアライズ/アンシリアライズできません');

PHPUnit_Framework_Error_Notice::$enabled = $orig;
ini_set('display_errors', "On");

}

/**
Expand All @@ -318,7 +325,7 @@ public function testSerialize()
*/
public function testUnserialize()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->markTestIncomplete('testSerializeにて実装');
}

/**
Expand Down
11 changes: 9 additions & 2 deletions lib/Baser/View/Elements/admin/sites/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@
foreach($languages as $key => $lang) {
$langs[$key] = $lang['name'];
}
$useSiteDeviceSetting = @$this->get('siteConfig')['use_site_device_setting'];
$useSiteLangSetting = @$this->get('siteConfig')['use_site_lang_setting'];
$useSiteDeviceSetting = 0;
$useSiteLangSetting = 0;
$thisSiteConfig = $this->get('siteConfig');
if (isset($thisSiteConfig['use_site_lang_setting'])) {
$useSiteDeviceSetting = $thisSiteConfig['use_site_lang_setting'];
}
if (isset($thisSiteConfig['use_site_device_setting'])) {
$useSiteLangSetting = $thisSiteConfig['use_site_device_setting'];
}
?>


Expand Down
5 changes: 4 additions & 1 deletion lib/Baser/View/Helper/BcXmlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ class BcXmlHelper extends AppHelper
*/
public function header($attrib = [])
{
$ua = @$_SERVER['HTTP_USER_AGENT'];
$ua = "";
if (!empty($_SERVER['HTTP_USER_AGENT'])) {
$ua = $_SERVER['HTTP_USER_AGENT'];
}
if (!(preg_match("/Windows/", $ua) && preg_match("/MSIE/", $ua)) || !(preg_match("/MSIE 6/", $ua))) {
if (Configure::read('App.encoding') !== null) {
$this->encoding = Configure::read('App.encoding');
Expand Down

0 comments on commit a5d3564

Please sign in to comment.