* @copyright Copyright(c) 2010 C-UNIT SQUARE Co.,Ltd. All Rights Reserved. * @license C-UNIT SQUARE Co.,Ltd. ------------------------------------------------------------------------*/ /** * CMSオブジェクト基本クラスを呼び出す */ require_once('CmsObjectCls.php'); /** * ファイル圧縮クラスを呼び出す */ require_once('Archive.php'); /** * DB操作用クラスを呼び出す */ require_once('DbCls.php'); /** * class connect ftp */ require_once('FtpCls.php'); /** * 拡大画像・同名の画像があった場合に負荷される文字列 */ define('BIG_IMAGE_PREFIX', 'Othersize_of_'); define('SAME_IMAGE_SUFFIX', '_same'); define('SAME_IMAGE_PREFIX', 'same_'); /** * 上書きなどのモードを定義 */ define('MEDIA_MODE_NONE', -1); define('MEDIA_MODE_OVERWRITE_NO', 1); define('MEDIA_MODE_OVERWRITE_OK', 2); define('MEDIA_MODE_SET_FOLDER', 3); class MediaCls extends CmsObjectCls { /** * @var string 扱うデータの型 */ protected $_type = 'file'; /** * @var object 同値チェックするキーと検索条件の連想配列 */ protected $_objAlreadyKey = array( ); /** * @var number 上書き指示のフラグ */ protected $_int_mode_flag = MEDIA_MODE_NONE; /** * @var number 仮アップロードの結果 */ protected $_result_upload_tmp; /** * @var boolean Ignore the check_already */ protected $_ignore_check_already = false; /** * @var array 圧縮ファイルのリスト */ protected $arrListFile_zip = array(); /** * @var string フォルダ名 */ protected $strFolderExtract = ''; /** * @var string 圧縮ファイル名 */ protected $strTempZipName = ''; /** * @var array 一括アップロード時のテキストデータを格納 */ protected $arrTextData = array(); /** * @var string エラーメッセージ */ protected $name_error; /** * @var string size upload */ protected $sizeUpload; /** * @var object Ftp */ protected $_objFtpMgr; /** * @var is connect Ftp */ protected $_isConnect; /**---------------------------------------------------------------------- * エラーメッセージをセットする * @param string エラーメッセージをセットする ------------------------------------------------------------------------*/ public function setNameError(&$val) { $this->name_error = $val; } /**---------------------------------------------------------------------- * エラーメッセージを取得する * @return string エラーメッセージ ------------------------------------------------------------------------*/ public function getNameError() { return $this->name_error; } /**---------------------------------------------------------------------- * function set size file upload * @param string エラーメッセージをセットする ------------------------------------------------------------------------*/ public function setSize(&$val) { $this->sizeUpload = $val; } /**---------------------------------------------------------------------- * エラーメッセージを取得する * @return string エラーメッセージ ------------------------------------------------------------------------*/ public function getSize() { return $this->sizeUpload; } /**---------------------------------------------------------------------- * 扱うデータの型を設定する * @param string $type 扱うデータの型 ------------------------------------------------------------------------*/ public function setType($type) { $this->_type = $type; } /**---------------------------------------------------------------------- * 処理モードフラグ設定 * @param number $flag 処理モードフラグ ------------------------------------------------------------------------*/ public function set_mode_flag($flag) { $this->_int_mode_flag = (int)$flag; } /**---------------------------------------------------------------------- * 取得条件に合致したメディアの一覧を取得 * @param object $params URLパラメータ * @return array 取得条件に合致したメディアを格納した配列 ------------------------------------------------------------------------*/ public function getAll_cond($params) { $where = ''; // フォルダとタイプを指定 $where .= ' where `type` = "' . $params['ext'] . '"'; if($params['folder'] != 'All') { $where .= ' and `id_folder`="' . $params['folder'] . '"'; } if($params['keyword'] != '' && $params['keyword'] != 'undefined') { $where .= ' and (`name` LIKE "%' . $params['keyword'] . '%" OR `url` LIKE "%' . $params['keyword'] . '%" ) ' ; } // 作成日で並び替え、そこから指定ページ、指定件数を取得 $index = $params['page'] * $params['count']; $where .= ' order by `date_create` desc'; $where .= ' limit ' . $index . ',' . $params['count']; $list = $this->query_fetch_all('select * from `' . $this->_table . '`' . $where); // データ展開 foreach ($list as $i => $objData) { /* * C-Unit 2011-11-1 start * #5598 * Change date format */ $objData['date_create'] = date($this->_objDateFormat . ' H:i:s',strtotime($objData['date_create'])); /* * C-Unit 2011-11-1 and */ $list[$i] = $this->_get_process($objData); } return $list; } /**---------------------------------------------------------------------- * 取得条件に合致したメディアの総数を取得 * @param object $params URLパラメータ * @return array 取得条件に合致したメディアの総数 ------------------------------------------------------------------------*/ public function get_count_cond($params) { // フォルダとタイプを指定 $where = ''; $where .= ' where `type` = "' . $params['ext'] . '"'; if($params['folder'] != 'All') { $where .= ' and `id_folder`="' . $params['folder'] . '"'; } if($params['keyword'] != '' && $params['keyword'] != 'undefined') { $where .= ' and (`name` LIKE "%' . $params['keyword'] . '%" OR `url` LIKE "%' . $params['keyword'] . '%" ) '; } // 件数 $result = $this->query_fetch('select count(`id`) from `' . $this->_table . '`' . $where); return $result['count(`id`)']; } /**---------------------------------------------------------------------- * データベースの指定テーブルから全レコードを取得する(メイン) * @return array 全レコードのリスト ------------------------------------------------------------------------*/ protected function _getAll_main() { // SQL $sql = 'select * from `' . $this->_table . '` where `type` = "' . $this->_type . '%" and `name`!="" order by `date_create` DESC'; // 検索 $list = $this->query_fetch_all($sql); return $list; } /**---------------------------------------------------------------------- * 取得したデータを加工する * @param object $data 加工するデータを格納した連想配列 * @return object 加工したデータを格納した連想配列 ------------------------------------------------------------------------*/ protected function _get_process($data) { $data = parent::_get_process($data); if (isset($data['id_folder'])) { // パス $objPath = new PathMgr($this->_config); $data['url_system'] = $objPath->get('file', 'system') . '/' . $data['url']; $data['url_public'] = $objPath->get('file', 'public') . '/' . $data['url']; $strDataName = $data['name']; $strExtension = $this->getExtensionFile($data['url']); //Cut duoi file (jpg).Update by Sinh $data['name'] = $strDataName; // タイプ switch (true) { // 画像、アイコン case (0 === strpos($data['url'], 'image')): $data['type'] = 'image'; break; case (0 === strpos($data['url'], 'icon')): $data['type'] = 'icon'; break; case (0 === strpos($data['url'], 'movie')): $data['type'] = 'movie'; break; case (0 === strpos($data['url'], 'file')): $data['type'] = 'file'; break; } // ファイルサイズ格納 { switch ($data['type']) { // 画像、アイコン case 'image': case 'icon': if (is_file($data['url_system'])) { $image_size = GetImageSize($data['url_system']); } else { $image_size = array(0, 0); } /* * C-Unit 2011-11-02 * fix size show in Media using FTP */ if($this->_config['system']['ftp_transfer'] == '1'){ @$image_size = GetImageSize($data['url_public']); } $data['size'] = $image_size[0] . '×' . $image_size[1]; $data['width'] = $image_size[0]; // Adding image height $data['height'] = $image_size[1]; if ($image_size[0] > 300) { $data['class'] = '_reduction'; } else { $data['class'] = ''; } $data['style'] = 'style="display:inline"'; break; // その他 default: if (is_file($data['url_system'])) { $data['size'] = filesize($data['url_system']); } else { $data['size'] = 0; } /* * C-Unit 2011-11-02 * fix size show in Media using FTP */ if($this->_config['system']['ftp_transfer'] == '1'){ @$data['size'] = filesize($data['url_public']); } $data['size'] .= $this->_objTranslation->_('MediaCls_msg0'); $data['width'] = 0; $data['class'] = ''; $data['style'] = 'style="display:none"'; break; } } } return $data; } /**---------------------------------------------------------------------- * レコードを1件登録する * @param object $model 登録するレコードを格納した連想配列 * @return integer 処理結果コード ------------------------------------------------------------------------*/ public function set($model) { /* * C-Unit 2011-11-14 Start * #6022 * check connect FTP */ if($this->_config['system']['ftp_transfer'] == '1'){ if (isset($this->_isConnect) == false) { $this->_objFtpMgr = new FtpCls(); $this->_isConnect = $this->_objFtpMgr->ftpConnection(); } if($this->_isConnect == false) { return FILE_NO_FTP_NG; } } $this->_log->start('set'); if('zip' == $model['type']) { if (RETURN_NORMAL != $this->_result_upload_zipfile) { $this->_log->end(); return $this->_result_upload_zipfile; } } else if('txt' == $model['type']) { if (RETURN_NORMAL != $this->_result_upload_textfile) { $this->_log->end(); return $this->_result_upload_textfile; } } else { if (RETURN_NORMAL != $this->_result_upload_tmp) { $this->_log->end(); return $this->_result_upload_tmp; } } // Register list of files and folder in the uploaded zip file Start if('zip' == $model['type']) { $objPath = new PathMgr($this->_config); $strPath = $objPath->get('file', 'system') . '/'; foreach ($this->arrListFile_zip as $key => $value) { //Register Folder $objFolder = array(); if ( $key != $this->strFolderExtract && isset($value['top']) === false) { $objDb = new DbCls(); $objFolder['name'] = $key ; $strSql = 'select * from ' . $this->_config['db_cms']['prefix'] . 'folder where `name` = "' . $objFolder['name'] . '" order by name asc'; $arrFolderAlready = $this->query_fetch_all($strSql); if (!(isset($arrFolderAlready) && count($arrFolderAlready) > 0)) { $objFolder['id'] = uniqid32(); $objFolder['status'] = CMS_STATUS_EDITED; $objFolder['date_create'] = date('Y-m-d H:i:s'); $objFolder['date_update'] = date('Y-m-d H:i:s'); // 保存者のIDを記録 $objFolder['id_account'] = $this->_auth->get_login_user('id'); $objDb->insert($this->_config['db_cms']['prefix'] . 'folder', $objFolder); } else { $objFolder['id'] = $arrFolderAlready[0]['id']; } } //Register Media foreach($value['file'] as $objFile) { $objMedia = array(); $objMedia = $this->createMedia($objFile); if(isset($objFolder['id'])) { $objMedia['id_folder'] = $objFolder['id']; } else { $objMedia['id_folder'] = ''; } /* * C-Unit 2011-10-25 Start * #5560 * move unzip file */ if($this->_config['system']['ftp_transfer'] == '1'){ if($this->_objFtpMgr->moveUploadedFile($this->_config['path']['user_file_site'], $objFile, $value['path'] . '/' . $objFile) == false){ return FILE_UPLOAD_ERROR_NG; } } else{ //copy file copy($value['path'] . '/' . $objFile, $strPath . $objFile); } //copy file //copy($value['path'] . '/' . $objFile, $strPath . $objFile); /* * C-Unit 2011-10-15 End */ //insert db $result = parent::set($objMedia); } } //delete file uploaded temp unlink($strPath . $this->strTempZipName); if(is_dir($strPath . $this->strFolderExtract)) deleteDir($strPath . $this->strFolderExtract); return $result; } // Register list of files and folder in the uploaded zip file End if('txt' == $model['type']) { foreach($this->arrTextData as $textdata) { $objMedia = array(); if(count($textdata) > 1) { $this->_db->update($this->_table, array('name' => $textdata[1]), '`url`="' . $textdata[0] . '"'); } } return RETURN_NORMAL; } // フォルダ登録 if ('folder' == $model['type']) { $result = parent::set($model); } else if (MEDIA_MODE_SET_FOLDER == $this->_int_mode_flag) { // フォルダ移動 // 移動するデータ $objData = $this->get($model['id']); // 同名が無くなるまで移動名を付加 { $model_name = explode('(', $objData['name']); $ext_name = array_splice($model_name, count($model_name) - 1, 1); $model_name = implode('(', $model_name); $ext_name = '(' . $ext_name[0]; } // fix (.ext) { $model_name = explode('(', $objData['name']); $model_name = $model_name[0]; $objData['name'] = $model_name; } $objAlready = $this->search('`id_folder`="' . $model['id_folder'] . '" and `name`="' . $objData['name'] . '"'); $move_name = ''; while (0 != count($objAlready)) { $move_name .= '_move'; //$objData['name'] = $model_name . $move_name . $ext_name; // fix (.ext) $objData['name'] = $model_name . $move_name; $objAlready = $this->search('`id_folder`="' . $model['id_folder'] . '" and `name`="' . $objData['name'] . '"'); } // フォルダ移動 $objData = array( 'name' => $objData['name'], 'id' => $model['id'], 'id_folder' => $model['id_folder'], ); $result = parent::set($objData); } else { // 登録 $session = new Zend_Session_Namespace('media_replace_model'); if (isset($session->model['extension'])) { unset($session->model['extension']); } if (isset($session->model_big['extension'])) { unset($session->model_big['extension']); } if (isset($session->model['filename'])) { unset($session->model['filename']); } if (isset($session->model_big['filename'])) { unset($session->model_big['filename']); } switch ($this->_int_mode_flag) { // 同名上書き指示なし case MEDIA_MODE_NONE: // 登録先フォルダ $objPath = new PathMgr($this->_config); $strPath = $objPath->get('file', 'system') . '/'; /* * C-Unit 2011-10-25 Start * #5560 * rename file */ if($this->_config['system']['ftp_transfer'] == '1'){ $this->_objFtpMgr->renameFile($this->_config['path']['user_file_site'], $session->model['url_tmp'], $session->model['url']); } else{ rename($strPath . $session->model['url_tmp'], $strPath . $session->model['url']); } //rename($strPath . $session->model_big['url_tmp'], $strPath . $session->model_big['url']); unset($session->model['url_tmp']); $result = parent::set($session->model); if (null != $session->model_big) { if($this->_config['system']['ftp_transfer'] == '1'){ $this->_objFtpMgr->renameFile($this->_config['path']['user_file_site'], $session->model_big['url_tmp'], $session->model_big['url']); } else{ rename($strPath . $session->model_big['url_tmp'], $strPath . $session->model_big['url']); } //rename($strPath . $session->model_big['url_tmp'], $strPath . $session->model_big['url']); unset($session->model_big['url_tmp']); $result = parent::set($session->model_big); } /* * C-Unit 2011-10-25 End */ break; // 同名上書き許可あり case MEDIA_MODE_OVERWRITE_OK: $result = CMS_FILE_SET_OK; // 登録先フォルダ $objPath = new PathMgr($this->_config); $strPath = $objPath->get('file', 'system') . '/'; // ファイルのみ差し替える { $objUpdateData = array( 'status' => CMS_STATUS_EDITED, 'date_update' => date('Y-m-d H:i:s'), ); $strUrl = $session->model['url']; $strBigUrl = BIG_IMAGE_PREFIX.$session->model['url']; // Select image have name $strfilename in database $objData = $this->query_fetch_all('select *, length(url) AS length from `' . $this->_table . '` where `url` = "' . $strUrl . '" and `url` NOT LIKE "%' . $strBigUrl . '" order by length desc '); // init file name number $strFileNumber = ''; $strNewFileName = ''; // While exist in database, then check other name while ((isset($objData) == true) && (sizeof($objData) > 0)) { // Explode file name to get the number of the file have the same name $arrFileName = explode('_', $objData[0]['url']); if (count($arrFileName) > 0){ // Explode file name to get the number of the file have the same name $arrFileNumber = explode('.', $arrFileName[count($arrFileName) - 1]); // If file have the number at the end of file name. Ex: picture_1.jpg if(is_numeric($arrFileNumber[0]) == true){ $strFileNumber = $arrFileNumber[0] + 1; } } // If exist file but don't have any file have the number at the end of file name if ('' == $strFileNumber) { $strFileNumber = 1; } // Explode to create new file name have the number at the end of file. // Explode to create new file name have the number at the end of file. $arrExpFileName = explode('.', $session->model['url']); $strNewFileName = ''; for ($i = 0; $i <= count($arrExpFileName) - 2; $i++) { $strNewFileName .= $arrExpFileName[$i] . '.'; } $strOrgName = substr($strNewFileName, 0, strlen($strNewFileName) - 1); $strNewFileName = $strOrgName . '_' . $strFileNumber . '.' . $arrExpFileName[count($arrExpFileName) - 1]; $strUrl = $strNewFileName; // Select new file name indatabase $objData = $this->query_fetch_all('select *, length(url) AS length from `' . $this->_table . '` where `url` = "' . $strNewFileName . '" and `url` NOT LIKE "%' . $strBigUrl . '" order by length desc '); } $session->model['url'] = $strUrl; /* * C-Unit 2011-10-25 Start * #5560 * rename file */ if($this->_config['system']['ftp_transfer'] == '1'){ $this->_objFtpMgr->renameFile($this->_config['path']['user_file_site'], $session->model['url_tmp'], $session->model['url']); } else{ rename($strPath . $session->model['url_tmp'], $strPath . $session->model['url']); } /* * C-Unit 2011-10-25 End */ unset($session->model['url_tmp']); $result = parent::set($session->model); if (null != $session->model_big) { $strUrl = $session->model_big['url']; $objData = $this->query_fetch_all('select *,length(url) AS length from `' . $this->_table . '` where `url` LIKE "%' . $strUrl . '" order by length desc '); // init file name number $strFileNumber = ''; // While exist in database, then check other name while ((isset($objData) == true) && (sizeof($objData) > 0)) { // Explode file name to get the number of the file have the same name $arrFileName = explode('_', $objData[0]['url']); if (count($arrFileName) > 0) { // Explode file name to get the number of the file have the same name $arrFileNumber = explode('.', $arrFileName[count($arrFileName) - 1]); // If file have the number at the end of file name. Ex: picture_1.jpg if(is_numeric($arrFileNumber[0]) == true){ $strFileNumber = $arrFileNumber[0] + 1; } } // If exist file but don't have any file have the number at the end of file name if ('' == $strFileNumber) { $strFileNumber = 1; } // Explode to create new file name have the number at the end of file. $arrExpFileName = explode('.', $session->model_big['url']); $strUrl = ''; for ($i = 0; $i <= count($arrExpFileName) - 2; $i++) { $strUrl .= $arrExpFileName[$i] . '.'; } $strOrgName = substr($strUrl, 0, strlen($strUrl) - 1); $strUrl = $strOrgName . '_' . $strFileNumber . '.' . $arrExpFileName[count($arrExpFileName) - 1]; // Select new file name indatabase $objData = $this->query_fetch_all('select *,length(url) AS length from `' . $this->_table . '` where `url` LIKE "%' . $strUrl . '" order by length desc '); } $session->model_big['url'] = $strUrl; /* * C-Unit 2011-10-25 Start * #5560 * rename file */ if($this->_config['system']['ftp_transfer'] == '1'){ $this->_objFtpMgr->renameFile($this->_config['path']['user_file_site'], $session->model_big['url_tmp'], $session->model_big['url']); } else{ rename($strPath . $session->model_big['url_tmp'], $strPath . $session->model_big['url']); } //rename($strPath . $session->model_big['url_tmp'], $strPath . $session->model_big['url']); /* * C-Unit 2011-10-25 End */ unset($session->model_big['url_tmp']); $result = parent::set($session->model_big); } } break; // 同名上書き未許可(仮アップロードしたファイルを削除) case MEDIA_MODE_OVERWRITE_NO: $result = CMS_FILE_ALREADY_SKIP; // 登録先フォルダ $objPath = new PathMgr($this->_config); $strPath = $objPath->get('file', 'system'); $strPath .= '/'; if (is_file($strPath . $session->model['url_tmp'])) { unlink($strPath . $session->model['url_tmp']); } // 拡大画像データあり if (null != $session->model_big) { // 拡大画像削除 if (is_file($strPath . $session->model_big['url_tmp'])) { unlink($strPath . $session->model_big['url_tmp']); } } break; } } $this->_log->end(); return $result; } /**---------------------------------------------------------------------- * 同値チェック ------------------------------------------------------------------------*/ public function check_already($model, $arrError) { if ($this->_ignore_check_already === true) { $this->_ignore_check_already = false; return; } $arrError = parent::check_already($model, $arrError); // 上書き指示なし if (MEDIA_MODE_NONE == $this->_int_mode_flag) { if (isset($_FILES['file']) || isset($_FILES['file_movie']) || isset($_FILES['file_big'])) { // 名前が使用されていないかチェック $objAlready = $this->search('`url` = "' . $model['url'] . '" '); if (0 < count($objAlready)) { if (!isset($arrError['name'])) { $arrError['name'] = array(); } if (!isset($arrError['name']['already'])) { $arrError['name']['already'] = array(); } $arrError['name']['already'][] = $this->_objTranslation->_('MediaCls_msg1') . $model['name'] . $this->_objTranslation->_('MediaCls_msg2'); } } } return $arrError; } /**---------------------------------------------------------------------- * 仮アップロード ------------------------------------------------------------------------*/ public function upload_tmp($model, $bBig = false) { /** * Set execution time for approval function. */ @ini_set("max_execution_time", $this->_config['system']['execution_time']); /* * C-Unit 2011-10-25 Start * #5560 * move unzip file */ if($this->_config['system']['ftp_transfer'] == '1'){ $this->_objFtpMgr = new FtpCls(); $this->_isConnect = $this->_objFtpMgr->ftpConnection(); if($this->_isConnect == false){ $result = FILE_NO_FTP_NG; return; } } if (MEDIA_MODE_NONE != $this->_int_mode_flag) { return; } $result = RETURN_NORMAL; // アップロードファイル $oFile = null; if ('movie' != $model['type'] && null == $oFile && isset($_FILES['file']) && '' != $_FILES['file']['name']) { $oFile = $_FILES['file']; } if ('movie' == $model['type'] && null == $oFile && isset($_FILES['file_movie']) && '' != $_FILES['file_movie']['name']) { $oFile = $_FILES['file_movie']; } if (null == $oFile && isset($_FILES['file_big']) && '' != $_FILES['file_big']['name']) { $oFile = $_FILES['file_big']; } if (null == $oFile) { $result = FILE_UPLOAD_NOFILE_NG; } /* * C-Unit 2011-12-01 Start * #5822 * check size file */ // ファイル容量 if (RETURN_NORMAL == $result) { if (UPLOAD_ERR_INI_SIZE == $oFile['error']) { $result = FILE_ERROR_NG; } } if (version_compare(PHP_VERSION, '5.2.12', '>=')) { $intMBMaxSize = min($this->_config['cms']['media_max_size'], ( integer )ini_get('post_max_size'), ( integer )ini_get('max_file_uploads') ); } else { $intMBMaxSize = min($this->_config['cms']['media_max_size'], ( integer )ini_get('post_max_size'), ( integer )ini_get('upload_max_filesize')); } $intByteMaxSize = $intMBMaxSize * 1024 * 1024; if (RETURN_NORMAL == $result) { if ($intByteMaxSize < $oFile['size']) { $result = FILE_UPLOAD_SIZEOVER_NG; $this->setSize($intMBMaxSize); } } /* * C-Unit 2011-12-01 Start */ // 拡張子 if (RETURN_NORMAL == $result) { if (!isset($model['extension']) || '' == $model['extension']) { $model['extension'] = pathinfo($oFile['name'], PATHINFO_EXTENSION); } if ('file' != $model['type'] && false === strpos($this->_config['cms']['ext_' . $model['type']], strtolower($model['extension']))) { $result = FILE_UPLOAD_EXT_NG; } else if ('file' == $model['type'] && strpos($this->_config['cms']['ext_' . $model['type']], strtolower($model['extension'])) > -1) { $result = FILE_UPLOAD_EXT_NG; } } // Check the valid of input character if (RETURN_NORMAL == $result) { /** * C-Unit 2011-11-01 * Move check_nochar function to Util_SiteCls */ $objSiteMgr = new Util_SiteCls($this->_config); $arrError = $objSiteMgr->check_nochar($model, array(), array('name' => 'name')); if (isset($arrError) && sizeof($arrError) > 0) { $result = FILE_UPLOAD_FILENAME_NOCHAR_NG; } } if (RETURN_NORMAL == $result) { if($this->isJapanese($model['url'])) { $result = FILE_UPLOAD_FILENAME_NG; } } if (RETURN_NORMAL == $result) { // ファイル名 { // 表示画像名 if (!isset($model['name']) || '' == $model['name']) { $model['name'] = str_replace('.' . $model['extension'], '', $oFile['name']); } // 拡大画像名 if (true == $bBig) { $model['name'] = BIG_IMAGE_PREFIX . $model['name']; } // ファイル名 $strTempFilename = $model['type'] . '_' . uniqid32() . '.' . $model['extension']; $strFilename = $model['url']; if (true == $bBig) { $strFilename = BIG_IMAGE_PREFIX . $model['url']; } } // ファイル保存 { $objPath = new PathMgr($this->_config); $strPath = $objPath->get('file', 'system'); $objPath->create($strPath); $strPath .= '/' . $strTempFilename; /* * C-Unit 2011-10-25 Start * #5560 * move Uploaded file */ // If upload unsuccessful, then return message if($this->_config['system']['ftp_transfer'] == '1'){ if($this->_objFtpMgr->moveUploadedFile($this->_config['path']['user_file_site'], $strTempFilename, $oFile['tmp_name']) == false){ $result = FILE_UPLOAD_ERROR_NG; } } else{ if(!@move_uploaded_file($oFile['tmp_name'], $strPath)) { die($this->_objTranslation->_('MediaCls_msg3')); } } /* * C-Unit 2011-10-25 End */ $model['url_tmp'] = $strTempFilename; $model['url'] = $strFilename; } // 上書き指示なし if (MEDIA_MODE_NONE == $this->_int_mode_flag) { // データをセッションに保存 $session = new Zend_Session_Namespace('media_replace_model'); if (true == $bBig) { $session->model_big = $model; } else { $session->model = $model; $session->model_big = null; } } // 拡大画像が存在し、まだ処理していない if (isset($_FILES['file_big']) && $oFile != $_FILES['file_big'] && is_file($_FILES['file_big']['tmp_name'])) { // 表示画像は処理したので消す unset($_FILES['file']); // 拡大画像の仮アップロード $this->upload_tmp($model, true); } } else { // Put marker for ignoring check already $this->_ignore_check_already = true; } $this->_result_upload_tmp = $result; } /**---------------------------------------------------------------------- * レコードを1件削除する * @param string $id 対象レコードの主キー * @return integer 処理結果コード ------------------------------------------------------------------------*/ public function del($id) { $objFileData = $this->get($id); if (0 != count($objFileData)) { if($this->_config['system']['ftp_transfer'] == '1') { /* * C-Unit 2011-10-27 Start * #5561 * check server user private */ $objPath = new PathMgr($this->_config); $strSystemPath = $objPath->get('user_site', 'system'); $destinationFTP = $objFileData['url_system']; if (strlen($strSystemPath) < strlen($destinationFTP)) { $destinationFTP = substr($destinationFTP, strlen($strSystemPath)); } $objFtpMgr = new FtpCls(); $objFtpMgr->deleteFile($destinationFTP, true); /* * C-Unit 2011-10-27 end */ } else { // ファイル削除 if (isset($objFileData['url_system']) && is_file($objFileData['url_system'])) { unlink($objFileData['url_system']); } } // レコード削除 $result = parent::del($id); } else { $result = DB_DELETE_NG; } return $result; } /**---------------------------------------------------------------------- * フォルダ指定を削除する * @param string $id 対象フォルダの主キー ------------------------------------------------------------------------*/ public function del_folder($id) { $this->_db->update($this->_table, array('id_folder' => ''), '`id_folder`="' . $id . '"'); } /**---------------------------------------------------------------------- * This function checks whether a word contains at least one Japanese letter * @param string $word 変換前の文字列 * @return string 変換後の文字列 ------------------------------------------------------------------------*/ function isJapanese($word) { return preg_match('/[\x{4E00}-\x{9FBF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}]/u', $word); } /**---------------------------------------------------------------------- * 仮アップロード * @param array $model アップロードするファイルの情報 ------------------------------------------------------------------------*/ public function upload_tmp_zipfile($model) { /** * Set execution time for approval function. */ @ini_set("max_execution_time", $this->_config['system']['execution_time']); $result = RETURN_NORMAL; // アップロードファイル $oFile = null; if (null == $oFile && isset($_FILES['file_zip']) && '' != $_FILES['file_zip']['name']) { $oFile = $_FILES['file_zip']; } if (null == $oFile) { $result = FILE_UPLOAD_NOFILE_NG; } //config.iniファイルをチェックしimageとmovieに同じ拡張子が入っていないかチェックする $strExtImage = $this->_config['cms']['ext_image']; $arrExtImage = explode(",", $strExtImage); foreach($arrExtImage as $extImage) { if (false !== strpos($this->_config['cms']['ext_movie'], strtolower($extImage))) { $result = FILE_UPLOAD_IMAGE_MOVIE_EXT_NG; } } // 拡張子 if (RETURN_NORMAL == $result) { if (!isset($model['extension']) || '' == $model['extension']) { $model['extension'] = pathinfo($oFile['name'], PATHINFO_EXTENSION); } if (false === strpos($this->_config['cms']['ext_zipfile'], strtolower($model['extension']))) { $result = FILE_UPLOAD_EXT_NG; } } //Check filename is English word. if (RETURN_NORMAL == $result) { if($this->isJapanese($model['url'])) { $result = FILE_UPLOAD_FILENAME_NG; } } //Check over size if (RETURN_NORMAL == $result) { /** * C-Unit 2011-12-07 stard * #6296 * Get min */ // Get min MB if (version_compare(PHP_VERSION, '5.2.12', '>=')) { $intMBMaxSize = min($this->_config['cms']['media_max_size'], ( integer )ini_get('post_max_size'), ( integer )ini_get('max_file_uploads') ); } else { $intMBMaxSize = min($this->_config['cms']['media_max_size'], ( integer )ini_get('post_max_size'), ( integer )ini_get('upload_max_filesize')); } // change to byte $intByteMaxSize = $intMBMaxSize * 1024 * 1024; if ((isset($oFile['error']) && $oFile['error'] !== 0) || ($intByteMaxSize < $oFile['size'])) { $result = FILE_UPLOAD_ZIP_SIZEOVER_NG; $this->setSize($intMBMaxSize); } } /** * C-Unit 2011-12-07 and */ if (RETURN_NORMAL == $result) { // ファイル名 { // 表示画像名 if (!isset($model['name']) || '' == $model['name']) { $model['name'] = str_replace('.' . $model['extension'], '', $oFile['name']); } $this->strTempZipName = $model['type'] . '_' . uniqid32() . '.' . $model['extension']; } // ファイル保存 { $objPath = new PathMgr($this->_config); $strPath = $objPath->get('file', 'system'); $objPath->create($strPath); $this->strFolderExtract = 'extract_'.uniqid32() ; $strExtract = $strPath . '/'.$this->strFolderExtract; $strPath .= '/' . $this->strTempZipName; // If upload unsuccessful, then return message if(!@move_uploaded_file($oFile['tmp_name'], $strPath)) { die($this->_objTranslation->_('MediaCls_msg3')); } $model['url_tmp'] = $this->strTempZipName; } //Unzip file $objArchive = new Archive(); $objArchive->unzip($strPath, $strExtract); //get infor in directory $this->arrListFile_zip = $this->getListFiles($strExtract); if (isset($this->arrListFile_zip['error']) ) { unlink($strPath); if (is_dir($strExtract)) { deleteDir($strExtract); } if($this->arrListFile_zip['error'] == FILE_UPLOAD_ZIP_DULICATE_NG ) { $this->setNameError($this->arrListFile_zip['name']); } $result = $this->arrListFile_zip['error']; } } $this->_result_upload_zipfile = $result; } /**---------------------------------------------------------------------- * Check File Name * @param string $fileName チェックするファイル名 * @return string 処理結果メッセージ ------------------------------------------------------------------------*/ private function checkFileName($fileName) { //Check extension of file name $strExtension = $this->getExtensionFile($fileName); if(false !== strpos($this->_config['cms']['ext_file'], $strExtension)) { return FILE_UPLOAD_ZIP_EXT_NG; } //Check file name contains at least one Japanese letter if($this->isJapanese($fileName)) { return FILE_UPLOAD_FILENAME_NG; } //Check duplicate url $objAlready = $this->search('`url` = "' . $fileName . '" '); if(isset($objAlready) && count($objAlready) > 0) { return FILE_UPLOAD_ZIP_DULICATE_NG; } return RETURN_NORMAL; } /**---------------------------------------------------------------------- * Get extension of file * @param string $fileName 拡張子を取得するするファイル名 * @return string 取得した拡張子 ------------------------------------------------------------------------*/ private function getExtensionFile($strFileName) { $list = explode('.', $strFileName); if(isset($list) && count($list) > 1) return $list[1]; } /**---------------------------------------------------------------------- * Make media object * @param string $fileName ファイル名 * @return array ファイル名とURLを格納した配列 ------------------------------------------------------------------------*/ function createMedia($strFileName) { $data = array(); $strExtension = $this->getExtensionFile($strFileName); $data['type'] = 'file'; if (false !== strpos($this->_config['cms']['ext_image'], strtolower($strExtension))) { $data['type'] ='image'; } else if (false !== strpos($this->_config['cms']['ext_movie'], strtolower($strExtension))) { $data['type'] ='movie'; } $data['name'] = $strFileName; $data['url'] = $strFileName; return $data; } /**---------------------------------------------------------------------- * Get all file corresponding path * @param string $strFolderPath フォルダのパス * @return array ファイルのリスト ------------------------------------------------------------------------*/ function getListFiles($strFolderPath) { $arrStack = array(); array_push($arrStack, array('level' => 0, 'folder' => $strFolderPath)); $arrFile = array(); $strTopFolder = ''; $bolFirst = false; $strZipName = basename($strFolderPath); while (count($arrStack) > 0) { $arrData = array_pop($arrStack); $strPath = $arrData['folder']; $handle = opendir($strPath); $arrSubFile = array(); $arrListFiles = array(); while ($filename = readdir($handle)) { if (strcmp($filename, ".") != 0 && strcmp($filename, "..") != 0) { if (is_dir($strPath . '/' . $filename)) { if(empty($strTopFolder) === true) { $strTopFolder = $filename; $bolFirst = true; } if (!empty($filename)) { $level = $arrData['level'] + 1; //check if ($level >= 3) { unset($arrFile); $arrFile = array(); $arrFile['error'] = FILE_UPLOAD_ZIPLEVEL_NG; return $arrFile; } array_push($arrStack, array('level' => $level, 'folder' => $strPath . '/' . $filename)); } } else { $filename = mb_convert_encoding($filename, 'UTF-8', 'SJIS'); if(isset($arrListFiles[$filename]) == true) { unset($arrFile); $arrFile = array(); $arrFile['error'] = FILE_UPLOAD_ZIP_DULICATE_NG; $arrFile['name'] = $filename; return $arrFile; } $errorCode = $this->checkFileName($filename); if($errorCode != RETURN_NORMAL) { unset($arrFile); $arrFile = array(); $arrFile['error'] = $errorCode; $arrFile['name'] = $filename; return $arrFile; } $arrListFiles[$filename] = $filename; $arrSubFile[] = $filename; } } } if(count($arrSubFile) > 0 || ( count($arrSubFile) <= 0 && $arrData['level'] != 1) ) { $strTmp = end( explode( "/", $strPath ) ); $srtEncoding = mb_detect_encoding($strTmp); $strTmp = mb_convert_encoding($strTmp, 'UTF-8', $srtEncoding); if ($arrData['level'] == 1 ) { $strTmp = ''; $arrFile[$strTmp]['top'] = true; } $arrFile[$strTmp]['path'] = $strPath; $arrFile[$strTmp]['file'] = $arrSubFile; if (isset($arrFile[$strZipName]) === false && $bolFirst === true) { $arrFile[$strTmp]['top'] = true; $bolFirst = false; } } } return $arrFile; } /**---------------------------------------------------------------------- * Upload file text * @param array $model 一括アップロード時のtextファイルの値 ------------------------------------------------------------------------*/ function upload_tmp_textfile($model) { $result = RETURN_NORMAL; // アップロードファイル $oFile = null; if (null == $oFile && isset($_FILES['file_text']) && '' != $_FILES['file_text']['name']) { $oFile = $_FILES['file_text']; } if (null == $oFile) { $result = FILE_UPLOAD_NOFILE_NG; } // 拡張子 if (RETURN_NORMAL == $result) { if (!isset($model['extension']) || '' == $model['extension']) { $model['extension'] = pathinfo($oFile['name'], PATHINFO_EXTENSION); } if (false === strpos($this->_config['cms']['ext_textfile'], strtolower($model['extension']))) { $result = FILE_UPLOAD_EXT_NG; } } if (RETURN_NORMAL == $result) { // ファイル名 { // 表示画像名 if (!isset($model['name']) || '' == $model['name']) { $model['name'] = str_replace('.' . $model['extension'], '', $oFile['name']); } $strTempTextName = $model['type'] . '_' . uniqid32() . '.' . $model['extension']; } // ファイル保存 { $objPath = new PathMgr($this->_config); $strPath = $objPath->get('file', 'system'); $objPath->create($strPath); $strPath .= '/' .$strTempTextName; /* * C-Unit 2011-10-25 Start * #5560 * move Uploaded File */ // If upload unsuccessful, then return message //if(!@move_uploaded_file($oFile['tmp_name'], $strPath)) { // die('データの登録に失敗しました。'); //} if($this->_config['system']['ftp_transfer'] == '1'){ if($this->_objFtpMgr->moveUploadedFile($this->_config['path']['user_file_site'], $strTempFilename, $oFile['tmp_name']) == false){ return FILE_UPLOAD_ERROR_NG; //die($this->_objTranslation->_('MediaCls_msg3')); } } else{ if(!@move_uploaded_file($oFile['tmp_name'], $strPath)) { die($this->_objTranslation->_('MediaCls_msg3')); } } /* * C-Unit 2011-10-25 End */ $model['url_tmp'] = $strTempTextName; } //read file $this->arrTextData = $this->rdTextFile($strPath); //delete file unlink($strPath); } $this->_result_upload_textfile = $result; } /**---------------------------------------------------------------------- * Read contents of text file * @param string $strPath textファイルのパス * @return array 読み込んだテキストファイルの内容 ------------------------------------------------------------------------*/ function rdTextFile($strPath) { $data = array(); $f = fopen($strPath, "r"); while ( $line = fgets($f, 1000) ) { $tab = "\t"; $line = str_replace("\n", "", $line); $line = str_replace("\r", "", $line); $line = mb_convert_encoding($line, 'UTF-8', 'SJIS'); $arrLine = explode($tab, $line); $data [] = $arrLine; } fclose($f); return $data; } /**---------------------------------------------------------------------- * Get Id File Name * @param string $fileName ファイル名 * @return object ファイルのID ------------------------------------------------------------------------*/ public function getIdFileName($fileName) { $objAlready = $this->search('`url` = "' . $fileName . '" '); if(isset($objAlready) && count($objAlready) > 0) { return $objAlready; } return null; } }