diff --git a/app/webroot/theme/admin-third/Elements/admin/sites/form.php b/app/webroot/theme/admin-third/Elements/admin/sites/form.php index dce7a2ab1c..70cfd3f06a 100644 --- a/app/webroot/theme/admin-third/Elements/admin/sites/form.php +++ b/app/webroot/theme/admin-third/Elements/admin/sites/form.php @@ -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']; +} ?> diff --git a/lib/Baser/Controller/SiteConfigsController.php b/lib/Baser/Controller/SiteConfigsController.php index 3c7a6d0969..dcc2944f72 100644 --- a/lib/Baser/Controller/SiteConfigsController.php +++ b/lib/Baser/Controller/SiteConfigsController.php @@ -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(); } diff --git a/lib/Baser/Controller/ThemeFilesController.php b/lib/Baser/Controller/ThemeFilesController.php index f99f378d8e..d3fd1d5ec7 100644 --- a/lib/Baser/Controller/ThemeFilesController.php +++ b/lib/Baser/Controller/ThemeFilesController.php @@ -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', 'ファイル'); } @@ -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) { @@ -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) { @@ -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); } diff --git a/lib/Baser/Lib/BcFileUploader.php b/lib/Baser/Lib/BcFileUploader.php index d7cb3a9a34..b622ee1ce6 100644 --- a/lib/Baser/Lib/BcFileUploader.php +++ b/lib/Baser/Lib/BcFileUploader.php @@ -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; } @@ -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; } @@ -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; } diff --git a/lib/Baser/Lib/BcUtil.php b/lib/Baser/Lib/BcUtil.php index 4d591326f9..a9c141d9a6 100644 --- a/lib/Baser/Lib/BcUtil.php +++ b/lib/Baser/Lib/BcUtil.php @@ -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 ''; } diff --git a/lib/Baser/Model/BcAppModel.php b/lib/Baser/Model/BcAppModel.php index db80dc1190..ef6eefa95e 100755 --- a/lib/Baser/Model/BcAppModel.php +++ b/lib/Baser/Model/BcAppModel.php @@ -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); } diff --git a/lib/Baser/Model/Behavior/BcUploadBehavior.php b/lib/Baser/Model/Behavior/BcUploadBehavior.php index d7edb010cf..a89602e04d 100755 --- a/lib/Baser/Model/Behavior/BcUploadBehavior.php +++ b/lib/Baser/Model/Behavior/BcUploadBehavior.php @@ -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; } } @@ -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); @@ -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()) { diff --git a/lib/Baser/Model/Page.php b/lib/Baser/Model/Page.php index 08e3899047..615fec5fa4 100755 --- a/lib/Baser/Model/Page.php +++ b/lib/Baser/Model/Page.php @@ -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; diff --git a/lib/Baser/Model/SearchIndex.php b/lib/Baser/Model/SearchIndex.php index e4df196b9b..4e2b60fc8a 100755 --- a/lib/Baser/Model/SearchIndex.php +++ b/lib/Baser/Model/SearchIndex.php @@ -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'); @@ -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; } diff --git a/lib/Baser/Plugin/Blog/Event/BlogControllerEventListener.php b/lib/Baser/Plugin/Blog/Event/BlogControllerEventListener.php index afae081349..286bea93e3 100644 --- a/lib/Baser/Plugin/Blog/Event/BlogControllerEventListener.php +++ b/lib/Baser/Plugin/Blog/Event/BlogControllerEventListener.php @@ -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'], diff --git a/lib/Baser/Plugin/Feed/Model/Feed.php b/lib/Baser/Plugin/Feed/Model/Feed.php index c3e4d3381c..278e7ba6f0 100644 --- a/lib/Baser/Plugin/Feed/Model/Feed.php +++ b/lib/Baser/Plugin/Feed/Model/Feed.php @@ -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; diff --git a/lib/Baser/Plugin/Mail/Model/MailMessage.php b/lib/Baser/Plugin/Mail/Model/MailMessage.php index 3a415c8877..f80e24d6a5 100755 --- a/lib/Baser/Plugin/Mail/Model/MailMessage.php +++ b/lib/Baser/Plugin/Mail/Model/MailMessage.php @@ -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; } diff --git a/lib/Baser/Test/Case/Lib/BcFileUploaderTest.php b/lib/Baser/Test/Case/Lib/BcFileUploaderTest.php index b6aec55cca..cbe57bc0e4 100644 --- a/lib/Baser/Test/Case/Lib/BcFileUploaderTest.php +++ b/lib/Baser/Test/Case/Lib/BcFileUploaderTest.php @@ -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'; //————————————————————————— @@ -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]); @@ -433,7 +433,7 @@ public function testMoveFileSessionToTmp() 'error' => 0, 'name' => $targetName, 'tmp_name' => $targetPath, - 'size' => 5, + 'size' => 219, 'type' => 'basercms', 'uploadable' => true, 'ext' => false diff --git a/lib/Baser/Test/Case/Lib/BcUtilTest.php b/lib/Baser/Test/Case/Lib/BcUtilTest.php index 61e0e1a755..ba2ec71f5f 100644 --- a/lib/Baser/Test/Case/Lib/BcUtilTest.php +++ b/lib/Baser/Test/Case/Lib/BcUtilTest.php @@ -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); @@ -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"); + } /** @@ -318,7 +325,7 @@ public function testSerialize() */ public function testUnserialize() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $this->markTestIncomplete('testSerializeにて実装'); } /** diff --git a/lib/Baser/View/Elements/admin/sites/form.php b/lib/Baser/View/Elements/admin/sites/form.php index 469aa2a256..b25894031b 100644 --- a/lib/Baser/View/Elements/admin/sites/form.php +++ b/lib/Baser/View/Elements/admin/sites/form.php @@ -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']; +} ?> diff --git a/lib/Baser/View/Helper/BcXmlHelper.php b/lib/Baser/View/Helper/BcXmlHelper.php index dd744edff8..b18a9d8a27 100644 --- a/lib/Baser/View/Helper/BcXmlHelper.php +++ b/lib/Baser/View/Helper/BcXmlHelper.php @@ -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');