* @copyright Copyright(c) 2010 C-UNIT SQUARE Co.,Ltd. All Rights Reserved. * @license C-UNIT SQUARE Co.,Ltd. ------------------------------------------------------------------------*/ /** * モデル抽象クラスを呼び出す */ require_once('AbstructModel.php'); /** * class connect ftp */ require_once('FtpCls.php'); /** * Zend_Http_Clientを利用するためのクラス */ require_once('Zend/Http/Client.php'); /** * Zend_Controller_Request_Simpleを利用するためのクラス */ require_once('Zend/Controller/Request/Simple.php'); /** * Zend_Controller_Response_Httpを利用するためのクラス */ require_once('Zend/Controller/Response/Http.php'); class Util_SiteCls { /** * @var object システム設定情報を保持するオブジェクト */ protected $_config; /** * @var object ログ管理オブジェクト */ protected $_log; /** * @var string The closed url path */ protected $_closed_url = ''; /* * folder ftp page. */ protected $_strFolderFTPPage; /* * object translation . */ public $_objTranslation; /** * @var is ftp connection */ protected $_isFTPConnect; /** * @var object Ftp */ protected $_objFtpMgr; /** * @var array error */ public $_arrErrorFTP = array(); /**---------------------------------------------------------------------- * コンストラクタ * @param object $config 利用するconfigファイル ------------------------------------------------------------------------*/ public function __construct($config, $objFtpMgr = null) { $this->_config = $config; $this->_log = new LogTrace($this->_config, get_class($this)); $this->_objModel = new AbstructModel(); if(isset($objFtpMgr) == false){ $this->_objFtpMgr = new FtpCls; } else { $this->_objFtpMgr = $objFtpMgr; } //define object translation $objTranslate = new TranslateCls; $this->_objTranslation = $objTranslate->_objTranslation; } /**---------------------------------------------------------------------- * 公開ベースSmartyテンプレートに展開 * @param string $id_template テンプレートID * @param string $id_site サイトID * @param object $objContentsData コンテンツのデータ * @param string $strBody コンテンツのデータ * @param string $strBlockSearch 検索後のデータ * @param boolean $search_flag 検索後のページかどうか ------------------------------------------------------------------------*/ public function base($id_template, $id_site, $objContentsData, $strBody, $strBlockSearch = '', $search_flag = '') { $this->_log->error($objContentsData); // テンプレート展開 $objTemplate = $this->_objModel->createObject('template'); $strBody = $objTemplate->display($id_template, $strBody, $id_site); $view = new ViewMgr($this->_config); $objPath = new PathMgr($this->_config); $userSession = new Zend_Session_Namespace('userinfo'); if ($userSession->user_id != '') { $userId = $userSession->user_id; } else { $userId = ''; } /* * C-Unit 2011-12-07 Start * #6115 * get user_id in file config */ if($objPath->get('user_id') != ''){ $userId = $objPath->get('user_id'); } /* * C-Unit 2011-12-07 Start */ $objContentsMgr = $this->_objModel->createObject('contents'); $strPublicPath = $objPath->get('user_site', 'public'); // 動的ページの場合は、$id_siteには、動的ページ自体のidが格納される。 // cssファイルなどは、サイトのルートに作られるため、サイトのルートを取得し、パスを設定する $strSiteId = $id_site; if (empty($strSiteId) == false && empty($keyword) == false) { // サイトIDが入力されていた場合、サイトのトップページのIDを取得 $arrSiteData = $objContentsMgr->get($id_site); $strSiteId = $arrSiteData['id_site']; $key_list = array( 'id' => $arrSiteData['id'], 'name' => $arrSiteData['name'], 'description' => $arrSiteData['description'], 'keyword' => $arrSiteData['keyword'], 'id_dynamic' => $arrSiteData['id_dynamic'], 'ssl' => '', ); } else { // デフォルト値設定 $key_list = array( 'id' => '', 'name' => $this->_objTranslation->_('Util_SiteCls_msg0'), 'description' => '', 'keyword' => '', 'id_dynamic' => '', 'ssl' => '', ); } $path_public = $strPublicPath . $objContentsMgr->createRoot($strSiteId); foreach ($key_list as $key => $strDefault) { if (!isset($objContentsData[$key])) { $objContentsData[$key] = $strDefault; } } // システム設定 $objAdmin = $this->_objModel->createObject('admin'); $objAdminData = $objAdmin->getConfig(); if (false == CmsObjectCls::is_front()) { $objAdminData['traking_code'] = ''; } // Smartyテンプレート用のデータ作成 $model = array( 'root_path' => $path_public, 'rss_name' => $this->_config['cms']['rss_name'], 'admin' => $objAdminData, 'system' => array( /* * C-Unit 2011-10-31 Start * #5571 * path using FTP */ 'domain_user' => $this->_config['path']['root_public'], 'path_public_user_root' => $objPath->get('tpl', 'public_user_root') . '/', 'path_system_user_root' => $objPath->get('tpl', 'system_user_root') . '/', 'ftp_transfer' => $this->_config['system']['ftp_transfer'], /* * C-Unit 2011-10-31 End */ 'path_public' => $objPath->get('tpl', 'public') . '/', 'path_system' => $objPath->get('tpl', 'system') . '/', 'path_public_user' => $objPath->get('tpl', 'public_user') . '/', 'path_system_user' => $objPath->get('tpl', 'system_user') . '/', 'user_id' => $userId, ), 'model' => array( 'id' => $objContentsData['id'], 'id_site' => $id_site, 'id_dynamic' => $objContentsData['id_dynamic'], 'title' => $objContentsData['name'], /* * C-Unit 2011-10-19 Start * #5417 * ssl => https */ 'ssl' => $objContentsData['ssl'], /* * C-Unit 2011-10-18 End */ 'description' => $objContentsData['description'], 'keyword' => $objContentsData['keyword'], 'body' => $strBody, 'search' => $strBlockSearch, 'search_flag' => $search_flag, ), ); $this->_log->error($objContentsData); /** * C-Unit 2011-12-06 Start * #6294 * Replace ssl link */ if($objContentsData['ssl'] == 1){ $model['system']['domain_user'] = str_replace("http://", "https://", $model['system']['domain_user']); $model['root_path'] = str_replace("http://", "https://", $model['root_path']); if($this->_config['system']['ftp_transfer'] == 1){ $model['system']['path_public_user_root'] = str_replace("http://", "https://", $model['system']['path_public_user_root']); $model['system']['path_system_user_root'] = str_replace("http://", "https://", $model['system']['path_system_user_root']); }else{ $model['system']['path_system_user'] = str_replace("http://", "https://", $model['system']['path_system_user']); $model['system']['path_public_user'] = str_replace("http://", "https://", $model['system']['path_public_user']); } } /** * C-Unit 2011-12-06 End */ // ベースに展開 if ($userId != '') { $strRootDir = $this->_config['saas']['root_dir']; $strTplPath = $this->_config['saas']['tpl_path']; $strBlock = $view->view($strRootDir . $strTplPath . '/block/base.tpl', $model); } else { $strBlock = $view->view('block/base.tpl', $model); } return $strBlock; } /**---------------------------------------------------------------------- * サイト作成 * @param string $id コンテンツID ------------------------------------------------------------------------*/ public function create($id = null) { $this->_log->start('create'); CmsObjectCls::set_front_flag(true); $view = new ViewMgr($this->_config); $bolReturn = true; $objPath = new PathMgr($this->_config); $strSystemPath = $objPath->get('user_site', 'system'); $strPublicPath = $objPath->get('user_site', 'public'); // 静的ページ作成 { $objContentsMgr = $this->_objModel->createObject('contents'); if (null === $id) { $arrContentsData = $objContentsMgr->search('`id_site`="' . $id . '"'); } else if (is_array($id)) { $where = '`id`="' . implode('" or `id`="', $id) . '"'; $arrContentsData = $objContentsMgr->search($where); } else { $objContentsData = $objContentsMgr->get($id); $arrContentsData = array($objContentsData); } // 登録ページのトップリスト $arrTopContentsData = array(); foreach ($arrContentsData as $i => $objContentsData) { $arrTopContentsData[$objContentsData['id_site']] = $objContentsMgr->get($objContentsData['id_site']); } $arrTopContentsData = array_unique($arrTopContentsData); foreach ($arrTopContentsData as $site_id => $objContentsData) { $arrTopContentsData[$site_id] = $objContentsMgr->get($site_id); $site_path = $objContentsMgr->createRoot($site_id); $arrTopContentsData[$site_id]['path_public'] = $strPublicPath . $site_path; $arrTopContentsData[$site_id]['path_system'] = $strSystemPath . $site_path; } foreach ($arrContentsData as $i => $objContentsData) { // 静的ページ作成 { $top_url = $strPublicPath . 'contents_public_before.html'; $strAfterHtml = $strPublicPath . 'contents_public_after.html'; // コンテンツ取得 $strBlock = $objContentsMgr->create($objContentsData['id']); // ブロック展開 $strBlock = $objContentsMgr->parse($strBlock, $objContentsData); $objContentsData['contents'] = $strBlock; // Smartyテンプレート用のデータ作成 $model = array( 'system' => array( 'path_public' => $objPath->get('tpl', 'public') . '/', 'path_system' => $objPath->get('tpl', 'system') . '/', ), 'top_url' => $top_url, 'top_after_url' => $strAfterHtml, 'model' => $objContentsData, ); // 静的ページブロック作成 $userSession = new Zend_Session_Namespace('userinfo'); if ($userSession->user_id != '') { $strRootDir = $this->_config['saas']['root_dir']; $strTplPath = $this->_config['saas']['tpl_path']; $strBlock = $view->view($strRootDir . $strTplPath . '/block/contents.tpl', $model); } else { $strBlock = $view->view('block/contents.tpl', $model); } // ベース展開 $strBlock = $this->base($objContentsData['id_template'], $objContentsData['id_site'], $objContentsData, $strBlock); $strUrl = $objContentsMgr->createURL($model['model']['id']); $strFullUrl = $strPublicPath . $strUrl; $strBlock = str_replace('@url', $strFullUrl, $strBlock); // 公開期間チェックPHP if ($objContentsMgr->isPHP($objContentsData)) { $userSession = new Zend_Session_Namespace('userinfo'); if ($userSession->user_id != '') { $strRootDir = $this->_config['saas']['root_dir']; $strTplPath = $this->_config['saas']['tpl_path']; $strBlock = $view->view($strRootDir . $strTplPath . '/block/contents_range.tpl', $model) . $strBlock; } else { $strBlock = $view->view('block/contents_range.tpl', $model) . $strBlock; } } } // URL $url = $objContentsMgr->createURL($objContentsData['id']); // 保存先フォルダ { // 保存先のフォルダを作成 $strCurrentPath = $strSystemPath . str_replace(basename($url), '', $url); // 保存先のフォルダはあるか? /* * C-Unit 2011-11-14 start * #6022 * create folder using FTP */ if ($this->_config['system']['ftp_transfer'] == '1') { $this->_strFolderFTPPage = str_replace(basename($url), '', $url); if($this->_objFtpMgr->createFolder($this->_strFolderFTPPage) == false){ $bolReturn = false; } } if (!is_dir($strCurrentPath)) { // 無いので作成 $objPath->create($strCurrentPath, 'site'); } /* * C-Unit 2011-11-14 end */ } // ファイル作成 $strClosedUrl = $this->_config['path']['root_public'] . $this->_config['system']['closed_url']; // ファイル作成 $strHtml = ''; /* * C-Unit 2011-11-14 start * #6022 * create file content using FTP */ if ( $model['model']['public'] == 'private' ){ if($this->_config['system']['ftp_transfer'] == '1') { if($this->_objFtpMgr->createFile('', $url, $strHtml) == false){ $bolReturn = false; } }else { $fp = fopen($strSystemPath . $url, 'w'); if ($fp) { fwrite($fp, $strHtml); fclose($fp); } } }else{ if($this->_config['system']['ftp_transfer'] == '1') { if($this->_objFtpMgr->createFile('', $url, $strBlock) == false){ $bolReturn = false; } }else { $fp = fopen($strSystemPath . $url, 'w'); if ($fp) { fwrite($fp, $strBlock); fclose($fp); } } } /* * C-Unit 2011-11-14 end */ } } // CSS作成(全部共通なのでここで作っておく) $objCssMgr = $this->_objModel->createObject('css'); $objCssMgr->create_css_file(false,$this->_objFtpMgr); $arrDestination = array(); // サイト単位で作成 foreach ($arrTopContentsData as $objContentsData) { if(in_array($objContentsData['path_system'],$arrDestination ,true) == false){ $arrDestination[] = $objContentsData['path_system']; $strDestinationFTP = str_replace($this->_config['saas']['root_dir'].$this->_config['saas']['site_path'],'',$objContentsData['path_system']); /* * C-Unit 2011-11-29 start * #6022,6259 * coppy site_template using FTP */ /* if($this->_config['system']['ftp_transfer'] == '1') { $this->_objFtpMgr->copyDir($objPath->get('site_template', 'system'), $strDestinationFTP); } else { // サイトテンプレートフォルダコピー copyDir($objPath->get('site_template', 'system'), $objContentsData['path_system']); } */ /* * C-Unit 2011-11-29 end */ // メニューテンプレート複製 if (!is_file($objContentsData['path_system'] . 'menu.tpl')) { $tplPath = $objPath->get('mvc', 'view'); $userSession = new Zend_Session_Namespace('userinfo'); if ($userSession->user_id != '') { // Process in case of using USER $strRootDir = $this->_config['saas']['root_dir']; $strTplPath = $this->_config['saas']['tpl_path']; copy($strRootDir . $strTplPath . '/block/menu.tpl', $objContentsData['path_system'] . 'menu.tpl'); } else { copy($tplPath . '/block/menu.tpl', $objContentsData['path_system'] . 'menu.tpl'); } } // RSS $this->create_rss($objContentsData['id'], $objContentsData['path_system']); } } // Create .htaccess for static contents $this->create_htaccess($objContentsData, $objContentsData['path_system'], $url); // create sitemap file //$this->create_sitemap(); /* * C-Unit 2011-11-29 start * #5967 * get array error upload FTP */ if($this->_config['system']['ftp_transfer'] == '1') { $this->_arrErrorFTP = $this->_objFtpMgr->_arrErrorFTP; } /* * C-Unit 2011-11-29 end */ CmsObjectCls::set_front_flag(false); $this->_log->end(); return $bolReturn; } /**---------------------------------------------------------------------- * 更新情報 RSS 作成 * @param string $id TOPページのコンテンツID * @param string $site_path RSS作成場所のパス ------------------------------------------------------------------------*/ function create_rss($id, $site_path) { $this->_log->start('create_rss'); $now_time = date('Y/m/d'); $objContentsMgr = $this->_objModel->createObject('contents'); $top = $objContentsMgr->get($id); $objPath = new PathMgr($this->_config); $strPublicPath = $objPath->get('user_site', 'public'); // RSS データ作成 $objRssData = array( 'site_title' => $top['name'], 'site_description' => $top['description'], 'site_url' => $strPublicPath . $objContentsMgr->createURL($top), 'item_list' => array(), ); { // 承認、公開中のコンテンツ、最新15件を取得 $where = ''; $where .= '`id_site`="' . $top['id_site'] . '"'; $where .= ' and '; $where .= '`status`=' . CMS_STATUS_PUBLIC; $where .= ' and '; $where .= '`public`="public"'; $where .= ' and '; $where .= '(`range_use`=0 or (`range_use`=1 and `range_start`<="' . $now_time . '" and `range_end`>="' . $now_time . '"))'; $site_list = $objContentsMgr->search($where); foreach ($site_list as $item) { $objRssData['item_list'][] = array( 'title' => $item['name'], 'description' => $item['description'], 'url' => $strPublicPath . $objContentsMgr->createURL($item), ); } } // RSS ファイル作成 /* * C-Unit 2011-11-14 start * #6022 * create file rss using FTP */ $view = new ViewMgr($this->_config); if($this->_config['system']['ftp_transfer'] == '1') { $userSession = new Zend_Session_Namespace('userinfo'); if ($userSession->user_id != '') { $strRootDir = $this->_config['saas']['root_dir']; $strTplPath = $this->_config['saas']['tpl_path']; $block = $view->view($strRootDir . $strTplPath . '/block/rss.tpl', $objRssData); } else { $block = $view->view('block/rss.tpl', $objRssData); } $this->_objFtpMgr->createFile($this->_strFolderFTPPage,'rss.xml',$block); }else{ $fp = fopen($site_path . $this->_config['cms']['rss_name'], 'w'); if ($fp) { $userSession = new Zend_Session_Namespace('userinfo'); if ($userSession->user_id != '') { $strRootDir = $this->_config['saas']['root_dir']; $strTplPath = $this->_config['saas']['tpl_path']; $block = $view->view($strRootDir . $strTplPath . '/block/rss.tpl', $objRssData); } else { $block = $view->view('block/rss.tpl', $objRssData); } fwrite($fp, $block); fclose($fp); } } $this->_log->end(); } /**---------------------------------------------------------------------- * Create file .htaccess for static page contents * @param object $objTopContentsData TOPページのコンテンツデータ * @param string $system_path htaccessファイル作成場所 * @param string $strTopURL TOPページのURL ------------------------------------------------------------------------*/ function create_htaccess($objMainContentsData, $system_path, $strTopURL) { $this->_log->start('create_htaccess'); $objPath = new PathMgr($this->_config); $strSystemPath = $objPath->get('user_site', 'system'); $strPublicPath = $objPath->get('user_site', 'public'); $strTopURL = $strPublicPath . $strTopURL; $strCurrentDate = date('Y/m/d'); $objContentsMgr = $this->_objModel->createObject('contents'); /**------------------------------------------------------------------------------- * get .htaccess content */ if($this->_config['system']['ftp_transfer'] == '1') { $strHtaccessContent = $this->_objFtpMgr->ftpFileGetContents('.htaccess'); }else { $strHtaccessContent = @file_get_contents($system_path . '/.htaccess'); } if(is_file($system_path . '/.htaccess') == false || $strHtaccessContent == false || $strHtaccessContent == ''){ $strHtaccessContent = 'Options FollowSymLinks' . "\n"; $strHtaccessContent .= 'RewriteEngine On ' . "\n"; $strHtaccessContent .= 'ErrorDocument 404 ' . $strPublicPath . 'contents_none.html' . "\n"; } /**------------------------------------------------------------------------------- * get records to create .htaccess content */ $arrCreateAccessData = array(); // Get full path $objMainContentsData['path'] = $objContentsMgr->createURL($objMainContentsData['id'], true); $arrCreateAccessData[$objMainContentsData['id']] = $objMainContentsData; $strContentsIds = $objMainContentsData['id']; // Get all sub pages. do{ if($strContentsIds == ""){ break; } // Get all sub pages in database $arrSubContentsData = $objContentsMgr->search('`id_contents_parent` IN ("' . $strContentsIds . '")'); $strContentsIds = ''; if(count($arrSubContentsData) > 0){ foreach ($arrSubContentsData as $objContentsData){ $arrCreateAccessData[$objContentsData['id']] = $objContentsData; // If main page is private then set sub page to private. if($objContentsData['id_contents_parent'] != '' && $arrCreateAccessData[$objContentsData['id_contents_parent']]['public'] == 'private'){ $arrCreateAccessData[$objContentsData['id']]['public'] = 'private'; } // If main page is mobile site then set sub page to mobile site if ('' != $objContentsData['id_contents_au'] || '' != $objContentsData['id_contents_docomo'] || '' != $objContentsData['id_contents_softbank']){ $arrCreateAccessData[$objContentsData['id']]['id_contents_au'] = $objContentsData['id_contents_au']; $arrCreateAccessData[$objContentsData['id']]['id_contents_docomo'] = $objContentsData['id_contents_docomo']; $arrCreateAccessData[$objContentsData['id']]['id_contents_softbank'] = $objContentsData['id_contents_softbank']; } // Set path for sub page if($arrCreateAccessData[$objContentsData['id_contents_parent']]['path'] != ''){ if($arrCreateAccessData[$objContentsData['id']]['path'] != ''){ $arrCreateAccessData[$objContentsData['id']]['path'] = $arrCreateAccessData[$objContentsData['id_contents_parent']]['path'] . '/' .$arrCreateAccessData[$objContentsData['id']]['path']; }else{ $arrCreateAccessData[$objContentsData['id']]['path'] = $arrCreateAccessData[$objContentsData['id_contents_parent']]['path']; } } // Generate ids to get sub pages. $strContentsIds .= $objContentsData['id'] . '","'; } // Remove 3 last string [","] if($strContentsIds != ''){ $strContentsIds = substr($strContentsIds, 0, -3); } } }while(count($arrSubContentsData) > 0); /**------------------------------------------------------------------------------- * Generate .htaccess content. */ foreach ($arrCreateAccessData as $objHtaccessData) { $strHtaccessText = ''; $strSlate = ''; if($objHtaccessData['path'] != ''){ $strSlate = '/'; } $strStartPage = '#' . $objHtaccessData['path'] . $strSlate . $objHtaccessData['url'] . 'html'; $strEndPage = '#/' . $objHtaccessData['path'] . $strSlate . $objHtaccessData['url'] . 'html'; // Create .htaccess text for public sites if ('public' == $objHtaccessData['public']) { // If status is not published then do not create .htaccess text. if ('1' != $objHtaccessData['status']){ continue; } // Check is mobile page. $bolUseMobile = false; if ('' != $objHtaccessData['id_contents_au'] || '' != $objHtaccessData['id_contents_docomo'] || '' != $objHtaccessData['id_contents_softbank']){ $bolUseMobile = true; } /** * Generate .htaccess for mobile sites. */ if(true == $bolUseMobile){ // モバイル対応 $arrCareers = array('DoCoMo' => $objTopContentsData['id_contents_docomo'], // DoCoMo 'SoftBank' => $objTopContentsData['id_contents_softbank'], // SoftBank 'Vodafone' => $objTopContentsData['id_contents_softbank'], // SoftBank 'UP\.Browser' => $objTopContentsData['id_contents_softbank'], // SoftBank 'KDDI' => $objTopContentsData['id_contents_au'] // AU ); foreach ($arrCareers as $strCareer => $strContentsId) { if ('' == $strContentsId) { continue; } $objContentsData = $objContentsMgr->get($strContentsId); $strUrl = $objContentsMgr->createURL($strContentsId); // キャリア判別 $strHtaccessText .= 'RewriteCond %{HTTP_USER_AGENT} ' . $strCareer . "\n"; // ページアクセスのみ対象 $strHtaccessText .= 'RewriteCond %{REQUEST_FILENAME} ^(.*)\.(php|html|htm)$ [NC]' . "\n"; // ページ無しHTML判別 $strHtaccessText .= 'RewriteCond %{REQUEST_URI} !'. $strPublicPath . 'contents_none.html' . "\n"; // リダイレクトループ排除 $strHtaccessText .= 'RewriteCond %{REQUEST_URI} !' . $strUrl . "\n"; if ('' === $objContentsData['range_start']) { $objContentsData['range_start'] = 0; } if ('' === $objContentsData['range_end']) { $objContentsData['range_end'] = $strCurrentDate; } // 非公開 if (('public' != $objContentsData['public']) || ((1 == $objContentsData['range_use']) && (($strCurrentDate < $objContentsData['range_start']) || ($objContentsData['range_end'] < $strCurrentDate)))) { $strHtaccessText .= 'RewriteRule .* ' . $strPublicPath . 'contents_none.html [R,L]' . "\n"; } else { // 公開 $strHtaccessText .= 'RewriteRule .* ' . $strPublicPath . $strUrl . ' [R,L]' . "\n"; } } }else{ if ((1 == $objHtaccessData['range_use']) && ((!empty($objHtaccessData['range_start']) && $strCurrentDate < $objHtaccessData['range_start']) || (!empty($objHtaccessData['range_end']) && $objHtaccessData['range_end'] < $strCurrentDate))) { $strBaseURL = $objContentsMgr->createURL($objHtaccessData['id']); // 拡張子除去、対象拡張子指定 if ('.php' == substr($strBaseURL, strlen($strBaseURL) - 4, 4)) { $strBaseURL = substr($strBaseURL, 0, strlen($strBaseURL) - 4); $ext_type = 'html'; } else { $strBaseURL = substr($strBaseURL, 0, strlen($strBaseURL) - 5); $ext_type = 'php'; } // 正規表現で使う記号をエスケープ $strBaseURL = str_replace('.', '\.', $strBaseURL); $strBaseURL = str_replace('?', '\?', $strBaseURL); /* * 公開期間の判定は、phpファイルで行うため、公開期間外であっても公開期間内であっても、「.htaccess」ファイルの * 内容が変わることはありません。 */ if(!empty($objHtaccessData['range_end']) && $objHtaccessData['range_end'] < $strCurrentDate){ $strHtaccessText .= "\n"; $strHtaccessText .= 'RewriteCond %{REQUEST_URI} ' . $strBaseURL . '.html' . "\n"; $strHtaccessText .= 'RewriteRule .* ' . $strPublicPath . 'contents_public_after.html [R,L]' . "\n"; }else{ $strHtaccessText .= "\n"; $strHtaccessText .= 'RewriteCond %{REQUEST_URI} ' . $strBaseURL . '.html' . "\n"; $strHtaccessText .= 'RewriteRule .* ' . $strPublicPath . $strBaseURL . '.php [R,L]' . "\n"; } } else { $strHtaccessText .= "\n" . 'RewriteCond %{REQUEST_URI} ' . $objHtaccessData['path'] . $strSlate . $objHtaccessData['url'] . '.php' . "\n"; $strHtaccessText .= 'RewriteRule .* ' . $strPublicPath . $objHtaccessData['path'] . $strSlate . $objHtaccessData['url'] . '.html [R,L]' . "\n"; } } }else{ // Create .htaccess text for private sites $strHtaccessText .= "\n" . 'RewriteCond %{REQUEST_URI} ' . $objHtaccessData['path'] . $strSlate . $objHtaccessData['url'] . '.html' . "\n"; $strHtaccessText .= 'RewriteRule .* ' . $strPublicPath . 'contents_none.html [R,L]' . "\n"; } if($strHtaccessText != ''){ // Text to replace. $strHtaccessText = $strStartPage . $strHtaccessText . $strEndPage; // Get possition to replace $arrSplitHtaccessFile = explode($strStartPage, $strHtaccessContent); $strHtaccessContent = $arrSplitHtaccessFile[0]; if(isset($arrSplitHtaccessFile[1]) && $arrSplitHtaccessFile[1] != ''){ // Replace old htaccess content with new text. $arrSplitHtaccessFile = explode($strEndPage, $arrSplitHtaccessFile[1]); $strHtaccessContent .= $strHtaccessText . $arrSplitHtaccessFile[1]; }else{ // Add new text to the end of .htaccess file $strHtaccessContent .= "\n" . $strHtaccessText . "\n"; } } } if($this->_config['system']['ftp_transfer'] == '1') { $this->_objFtpMgr->createFile($this->_strFolderFTPPage ,'.htaccess', $strHtaccessContent); }else { $fp = fopen($system_path . '/.htaccess', 'w'); if ($fp) { fwrite($fp, $strHtaccessContent); fclose($fp); } } $this->_log->end(); } /**---------------------------------------------------------------------- * Generate valid htaccess url based on input url * * @param string $strOrgUrl The original url * @return string The valid url ------------------------------------------------------------------------*/ private function generateHtaccessUrl($strOrgUrl) { $strValidUrl = $strOrgUrl; // Replace all special character []()+ into normal character by adding prefix '\' $strReplacePattern = '*+?^$[]()'; $intLength = strlen($strReplacePattern); for($i = 0; $i < $intLength; $i++) { $strSpecialChar = $strReplacePattern{$i}; $strValidUrl = str_replace($strSpecialChar, '\\' . $strSpecialChar, $strValidUrl); } return $strValidUrl; } /**---------------------------------------------------------------------- * Generate htaccess text for content data and its children and grandchildren... * * @param ContentsCls $objContentsMgr Instant of 静的ページモデルクラス * @param array $parentContentsData Data of parent static page * @param string $strPublicPath URL to site * @param string $urlParent URL which will apply for child/grandchild. If empty, the child/grandchild use their own one. ------------------------------------------------------------------------*/ private function _generate_htaccess($objContentsMgr, $parentContentsData, $strPublicPath, $urlParent) { $now_time = date('Y/m/d'); $htaccess_text = ''; $ext_type = ''; $strBaseURL = $objContentsMgr->createURL($parentContentsData['id']); // 拡張子除去、対象拡張子指定 if ('.php' == substr($strBaseURL, strlen($strBaseURL) - 4, 4)) { $strBaseURL = substr($strBaseURL, 0, strlen($strBaseURL) - 4); $ext_type = 'php'; } else { $strBaseURL = substr($strBaseURL, 0, strlen($strBaseURL) - 5); $ext_type = 'html'; } // 正規表現で使う記号をエスケープ $strBaseURL = str_replace('.', '\.', $strBaseURL); $strBaseURL = str_replace('?', '\?', $strBaseURL); if (!empty($urlParent)) { $htaccess_text .= "\n"; $htaccess_text .= 'RewriteCond %{REQUEST_URI} ' . $strBaseURL . '.php' . "\n"; $htaccess_text .= 'RewriteRule .* ' . $urlParent . ' [R,L]' . "\n"; $htaccess_text .= "\n"; $htaccess_text .= 'RewriteCond %{REQUEST_URI} ' . $strBaseURL . '.html' . "\n"; $htaccess_text .= 'RewriteRule .* ' . $urlParent . ' [R,L]' . "\n"; /** * C-Unit 2011-12-02 Delete * #5866 */ /* $arrContentsDataChild = $objContentsMgr->search('`id_contents_parent`="' . $parentContentsData['id'] . '"'); foreach ($arrContentsDataChild as $objContentsDataChild) { $htaccess_text .= $this->_generate_htaccess($objContentsMgr, $objContentsDataChild, $strPublicPath, $urlParent); } */ return $htaccess_text; } else { // トップが非公開の場合 if ('public' != $parentContentsData['public']) { $close_url = ''; $objOrgContentsData = array(); if (!empty($parentContentsData['id_org'])) { $objOrgContentsData = $objContentsMgr->get($parentContentsData['id_org']); } if (empty($objOrgContentsData)) { if ($parentContentsData['status'] == 1 || $parentContentsData['status'] == 5) { $strSitePublicPath = $objContentsMgr->createURL($parentContentsData['id_site']); $intPos = strripos($strBaseURL, '/'); if ($intPos === FALSE) { $strSitePublicPath = $strPublicPath; } else { $strSitePublicPath = $strPublicPath . substr($strBaseURL, 0, $intPos + 1); } $close_url = $strSitePublicPath . $this->_config['system']['closed_url']; $htaccess_text .= "\n"; $htaccess_text .= 'RewriteCond %{REQUEST_URI} ' . $strBaseURL . '.php' . "\n"; $htaccess_text .= 'RewriteRule .* ' . $close_url . ' [R,L]' . "\n"; $htaccess_text .= "\n"; $htaccess_text .= 'RewriteCond %{REQUEST_URI} ' . $strBaseURL . '.html' . "\n"; $htaccess_text .= 'RewriteRule .* ' . $close_url . ' [R,L]' . "\n"; } /** * C-Unit 2011-12-02 Delete * #5866 */ /* $arrContentsDataChild = $objContentsMgr->search('`id_contents_parent`="' . $parentContentsData['id'] . '"'); foreach ($arrContentsDataChild as $objContentsDataChild) { $htaccess_text .= $this->_generate_htaccess($objContentsMgr, $objContentsDataChild, $strPublicPath, $close_url); } */ } else { $objOrgContentsData['id'] = $parentContentsData['id']; $htaccess_text .= $this->_generate_htaccess($objContentsMgr, $objOrgContentsData, $strPublicPath, ''); } return $htaccess_text; } else { //C-UNIT 2011/10/10 add start if((1 == $parentContentsData['range_use'])&&(''==$parentContentsData['range_start'])&&($parentContentsData['range_end'] =='')) { $htaccess_text .= "\n"; $htaccess_text .= 'RewriteCond %{REQUEST_URI} ' . $strBaseURL . '.php' . "\n"; $htaccess_text .= 'RewriteRule .* ' . $strPublicPath . $strBaseURL . '.html' . ' [R,L]' . "\n"; return $htaccess_text; } else { //C-UNIT 2011/10/10 add end if ((1 == $parentContentsData['range_use']) && (($now_time < $parentContentsData['range_start']) || ($parentContentsData['range_end'] < $now_time))) { $url = ''; $objOrgContentsData = array(); if (!empty($parentContentsData['id_org'])) { $objOrgContentsData = $objContentsMgr->get($parentContentsData['id_org']); } if (empty($objOrgContentsData)) { if ($parentContentsData['status'] == 1 || $parentContentsData['status'] == 5) { $url = $strPublicPath . $strBaseURL . '.php'; $htaccess_text .= "\n"; $htaccess_text .= 'RewriteCond %{REQUEST_URI} ' . $strBaseURL . '.html' . "\n"; $htaccess_text .= 'RewriteRule .* ' . $url . ' [R,L]' . "\n"; } /** * C-Unit 2011-12-02 Delete * #5866 */ /* $arrContentsDataChild = $objContentsMgr->search('`id_contents_parent`="' . $parentContentsData['id'] . '" or path = "' . $parentContentsData['path'] . '"'); foreach ($arrContentsDataChild as $objContentsDataChild) { $htaccess_text .= $this->_generate_htaccess($objContentsMgr, $objContentsDataChild, $strPublicPath, $url); } */ } else { $objOrgContentsData['id'] = $parentContentsData['id']; $htaccess_text .= $this->_generate_htaccess($objContentsMgr, $objOrgContentsData, $strPublicPath, ''); } return $htaccess_text; } else if (1 == $parentContentsData['range_use'] && (!empty($parentContentsData['range_start']) || !empty($parentContentsData['range_end']))) { /* * 静的ページ管理Bug-No.7 * 公開期間[設定なし]の場合、拡張子htmlでもアクセス可能であり、 * 拡張子phpでアクセスしても、拡張子htmlのページにリダイレクトされる。 * 公開期間が設定されている場合、拡張子phpでもアクセス可能であり、 * 拡張子htmlでアクセスしても拡張子phpのページにリダイレクトされる。 */ $objOrgContentsData = array(); if (!empty($parentContentsData['id_org'])) { $objOrgContentsData = $objContentsMgr->get($parentContentsData['id_org']); } if (empty($objOrgContentsData)) { if ($parentContentsData['status'] == 1 || $parentContentsData['status'] == 5) { $htaccess_text .= "\n"; $htaccess_text .= 'RewriteCond %{REQUEST_URI} ' . $strBaseURL . '.html' . "\n"; $htaccess_text .= 'RewriteRule .* ' . $strPublicPath . $strBaseURL . '.php [R,L]' . "\n"; } /** * C-Unit 2011-12-02 Delete * #5866 */ /* $arrContentsDataChild = $objContentsMgr->search('`id_contents_parent`="' . $parentContentsData['id'] . '" or path = "' . $parentContentsData['path'] . '"'); foreach ($arrContentsDataChild as $objContentsDataChild) { $htaccess_text .= $this->_generate_htaccess($objContentsMgr, $objContentsDataChild, $strPublicPath, ''); } */ } else { $objOrgContentsData['id'] = $parentContentsData['id']; $htaccess_text .= $this->_generate_htaccess($objContentsMgr, $objOrgContentsData, $strPublicPath, ''); } return $htaccess_text; } else { /* * phpファイルにアクセスすると、htmlファイルにアクセスします。 * なぜ上記のような変更を行うかというと、公開期間を設定すると、「php」ファイルになりますが、公開期間を解除すると * 「html」ファイルになります。公開期間を設定した後に、公開期間を解除すると、「php」ファイルと「html」ファイルの両方が * できてしまうため、「php」ファイルにアクセスする場合は、「html」ファイルにアクセスするようにします。 */ $objOrgContentsData = array(); if (!empty($parentContentsData['id_org'])) { $objOrgContentsData = $objContentsMgr->get($parentContentsData['id_org']); } if (empty($objOrgContentsData)) { if ($parentContentsData['status'] == 1 || $parentContentsData['status'] == 5) { if ($ext_type === 'html') { $htaccess_text .= "\n"; $htaccess_text .= 'RewriteCond %{REQUEST_URI} ' . $strBaseURL . '.php' . "\n"; $htaccess_text .= 'RewriteRule .* ' . $strPublicPath . $strBaseURL . '.html [R,L]' . "\n"; } else { $htaccess_text .= "\n"; $htaccess_text .= 'RewriteCond %{REQUEST_URI} ' . $strBaseURL . '.html' . "\n"; $htaccess_text .= 'RewriteRule .* ' . $strPublicPath . $strBaseURL . '.php [R,L]' . "\n"; } } /** * C-Unit 2011-12-02 Delete * #5866 */ /* $arrContentsDataChild = $objContentsMgr->search('`id_contents_parent`="' . $parentContentsData['id'] . '" or path = "' . $parentContentsData['path'] . '"'); foreach ($arrContentsDataChild as $objContentsDataChild) { $htaccess_text .= $this->_generate_htaccess($objContentsMgr, $objContentsDataChild, $strPublicPath, ''); } */ } else { $objOrgContentsData['id'] = $parentContentsData['id']; $htaccess_text .= $this->_generate_htaccess($objContentsMgr, $objOrgContentsData, $strPublicPath, ''); } return $htaccess_text; } }//C-UNIT 2011/10/10 add } } return $htaccess_text; } /**---------------------------------------------------------------------- * サイトマップXMLデータ作成 * @param array $id_list 処理対象のトップリスト ------------------------------------------------------------------------*/ function create_sitemap() { $this->_log->start('create_sitemap'); $objContentsMgr = $this->_objModel->createObject('contents'); $view = new ViewMgr($this->_config); $objPath = new PathMgr($this->_config); $strSystemPath = $objPath->get('user_site', 'system'); $strPublicPath = $objPath->get('user_site', 'public'); $time = time(); //get from db $arrDataFromDb = $objContentsMgr->getAll(); if(isset($arrDataFromDb) && sizeof($arrDataFromDb) > 0){ foreach ($arrDataFromDb as $i => $data_from_db) { // 公開期間外のものはスキップ if ($data_from_db['range_use'] && ($time < $data_from_db['range_start'] || $data_from_db['range_end'] < $time)) { continue; } $file = $strSystemPath . $objContentsMgr->createURL($data_from_db['id']); if (is_file($file)) { $sitemap[] = array( 'loc' => $strPublicPath . $objContentsMgr->createURL($data_from_db['id']), 'lastmod' => $data_from_db['date_update'], 'changefreq' => $data_from_db['sitemap_changefreq'], 'priority' => $data_from_db['sitemap_priority'], ); } } } //get data in folder site/itemview $item_folder = $this->_config['path']['item_view']; $folder = $strSystemPath . $item_folder; $sitemap = array(); if($resource = @opendir($folder)) { while (false!==($file = readdir($resource))) { if ($file != '.' && $file != '..' && pathinfo($file, PATHINFO_EXTENSION) === 'html') { $filepath = $folder . '/' . $file; $lastmod = filemtime($filepath); $sitemap[] = array( 'loc' => $strPublicPath . $item_folder . '/' . $file, 'lastmod' => date('Y-m-d H:i:s', $lastmod), 'changefreq' => 'weekly', 'priority' => '0.5', ); } } closedir($resource); } // Sort the site map items $sitemap = vsort($sitemap, array('lastmod' => SORT_DESC)); // XML作成 $model = array( 'sitemap' => $sitemap, ); $userSession = new Zend_Session_Namespace('userinfo'); if ($userSession->user_id != '') { $strRootDir = $this->_config['saas']['root_dir']; $strTplPath = $this->_config['saas']['tpl_path']; $block = $view->view($strRootDir . $strTplPath . '/block/sitemap_xml.tpl', $model); } else { $block = $view->view('block/sitemap_xml.tpl', $model); } // サイトマップXMLファイル作成 /* * C-Unit 2011-11-14 * #6022 * create file .sitemap.xml using FTP */ if($this->_config['system']['ftp_transfer'] == '1') { $this->_objFtpMgr->createFile($this->_strFolderFTPPage ,'sitemap.xml', $block); }else { $fp = fopen($strSystemPath . '/sitemap.xml', 'w'); fwrite($fp, $block); fclose($fp); } $this->_log->end(); } /**---------------------------------------------------------------------- * Check the using of page template by another static page contents. * The input parameter can be id_dynamic or id_item, not both of them. * @param array $params The array of parameters, include * 'id_item' (option 1) * 'id_dynamic' (option 2) * @return boolean The result of checking (true/false <=> used/not used) ------------------------------------------------------------------------*/ public function checkUsingPageTemplate($params) { $strIdDynamic = @$params['id_dynamic']; if (!isset($strIdDynamic)) { // Get id_dynamic from id_item $objItemMgr = $this->_objModel->createObject('item'); $strIdDynamic = $objItemMgr->get($params['id_item']); $strIdDynamic = @$strIdDynamic['id_dynamic']; } // Can't get the id_dynamic, we will return false if (!isset($strIdDynamic)) { return false; } $objContentsMgr = $this->_objModel->createObject('contents'); $objTemplateMgr = $this->_objModel->createObject('template'); /** * C-Unit 2011-10-25 Start * #5589 * Change all tag to english * AND c.contents like "%{@自動生成一覧}%" => AND c.contents like "%{@DynamicList}%" */ $strSqlContents = ' SELECT c.id, c.name FROM ' . $objContentsMgr->get_table() . ' AS c INNER JOIN ' . $objTemplateMgr->get_table() . ' AS t ON c.id_template = t.id WHERE c.status = ' . CMS_STATUS_PUBLIC . ' AND c.public = "public" AND c.contents like "%{@DynamicList}%" AND c.id_template IS NOT NULL AND c.id_template <> "" AND c.id_dynamic = "' . $strIdDynamic . '" AND ( t.status = ' . CMS_STATUS_PUBLIC . ' OR (SELECT t1.id FROM ' . $objTemplateMgr->get_table() . ' AS t1 WHERE t1.id = t.id_org AND t1.status = ' . CMS_STATUS_PUBLIC . ' ) IS NOT NULL ) '; // Get all layout template of static pages that using current page tamplate $arrContents = $objContentsMgr->query_fetch_all($strSqlContents); if (isset($arrContents) && sizeof($arrContents) > 0) { return true; } return false; } /**---------------------------------------------------------------------- * Get dynamic HTML name from specified URL * @param array $params The array of parameters, include 'id_item', 'id_template' ------------------------------------------------------------------------*/ public function getDynamicHtmlName(&$params) { // Get the file name pattern from the buffer, if exist to improve performance $strFileName = @$params['file_name_pattern']; if (!isset($strFileName)) { $strFileName = $this->_config['path']['html_template_file'] . '#id_template#_#id_dynamic#_#id_item#.html'; $params['file_name_pattern'] = $strFileName; } $strIdItem = @$params['id_item']; $strIdTemplate = @$params['id_template']; // Get id_html of cms_template table if (isset($strIdTemplate) && $strIdTemplate != '') { $objTemplateMgr = $this->_objModel->createObject('template'); $objTemplate = $objTemplateMgr->get($strIdTemplate); if (isset($objTemplate) && sizeof($objTemplate) > 0) { $strIdTemplateHtml = @$objTemplate['id_html']; // Get original template (if exists) $arrOrgData = $objTemplateMgr->query_fetch_all( ' SELECT id, id_html FROM ' . $objTemplateMgr->get_table() . ' WHERE id_org = "' . $strIdTemplate . '" ' ); if (isset($arrOrgData) && sizeof($arrOrgData) > 0) { $strIdTemplateHtml = $arrOrgData[0]['id_html']; } $strFileName = str_replace('#id_template#', $strIdTemplateHtml, $strFileName); } else { // Can't find the matching template $strFileName = str_replace('#id_template#', '', $strFileName); } } else { // The page that do not use any template $strFileName = str_replace('#id_template#', '', $strFileName); } // Get id_html of cms_item table $objItemMgr = $this->_objModel->createObject('item'); $objItem = $objItemMgr->get($strIdItem); if (isset($objItem) && sizeof($objItem) > 0) { // Check if the current item is a store record (based on an id_org) $arrOrgData = $objItemMgr->query_fetch_all( ' SELECT id, id_html FROM ' . $objItemMgr->get_table() . ' WHERE id_org = "' . $strIdItem . '" AND public = "public" ' ); if (isset($arrOrgData) && sizeof($arrOrgData) > 0) { $strItemIdHtml = $arrOrgData[0]['id_html']; } else { $strItemIdHtml = $objItem['id_html']; } $strFileName = str_replace('#id_item#', $strItemIdHtml, $strFileName); } else { //return $this->getClosedUrl(); } // Get id_html of cms_dynamic table $objDynamicMgr = $this->_objModel->createObject('dynamic'); $objDynamic = $objItemMgr->get($objItem['id_dynamic']); if (isset($objDynamic) && sizeof($objDynamic) > 0) { $strFileName = str_replace('#id_dynamic#', $objDynamic['id_html'], $strFileName); } else { //return $this->getClosedUrl(); } // Create full path for this file $strItemFolder = @$params['itemview_folder']; // When the destination is not available, we will return the error page (Error 404) if (@$params['checking_file_available'] === true) { $strSystemItemFolder = $this->_config['path']['root_system_user'] . str_replace('//', '/', '/' . $this->_config['path']['user_site'] . '/' . $this->_config['path']['item_view']); /* * C-Unit 2011-10-27 Start * #5561 * check server user private */ /* if($this->_config['system']['ftp_transfer'] == '1') { $strFolderPath = '/' . $this->_config['path']['user_site'] . '/' . $this->_config['path']['item_view']; if ($this->_objFtpMgr-> isExistFile($this->_objFtpMgr->strSystemPathFTP . $strFolderPath . '/' . $strFileName) == false){ return $this->getClosedUrl(); } } else { if (false === is_file($strSystemItemFolder . '/' . $strFileName)) { return $this->getClosedUrl(); } }*/ } if (isset($strItemFolder) && $strItemFolder != '') { $strFileName = $strItemFolder . '/' . $strFileName; } return $strFileName; } public function createDynamicHtmlName(&$params,$objItem,$objDynamic){ // Get the file name pattern from the buffer, if exist to improve performance $strFileName = @$params['file_name_pattern']; if (!isset($strFileName)) { $strFileName = $this->_config['path']['html_template_file'] . '#id_template#_#id_dynamic#_#id_item#.html'; $params['file_name_pattern'] = $strFileName; } $strIdItem = @$params['id_item']; $strIdTemplate = @$params['id_template']; // Get id_html of cms_template table if (isset($strIdTemplate) && $strIdTemplate != '') { $objTemplateMgr = $this->_objModel->createObject('template'); $objTemplate = $objTemplateMgr->get($strIdTemplate,'id_html'); if (isset($objTemplate) && sizeof($objTemplate) > 0) { $strIdTemplateHtml = @$objTemplate['id_html']; // Get original template (if exists) $arrOrgData = $objTemplateMgr->query_fetch_all( ' SELECT id, id_html FROM ' . $objTemplateMgr->get_table() . ' WHERE id_org = "' . $strIdTemplate . '" ' ); if (isset($arrOrgData) && sizeof($arrOrgData) > 0) { $strIdTemplateHtml = $arrOrgData[0]['id_html']; } $strFileName = str_replace('#id_template#', $strIdTemplateHtml, $strFileName); } else { // Can't find the matching template $strFileName = str_replace('#id_template#', '', $strFileName); } } else { // The page that do not use any template $strFileName = str_replace('#id_template#', '', $strFileName); } // Get id_html of cms_item table $objItemMgr = $this->_objModel->createObject('item'); // $objItem = $objItemMgr->get($strIdItem); if (isset($objItem) && sizeof($objItem) > 0) { // Check if the current item is a store record (based on an id_org) $arrOrgData = $objItemMgr->query_fetch_all( ' SELECT id, id_html FROM ' . $objItemMgr->get_table() . ' WHERE id_org = "' . $strIdItem . '" AND public = "public" ' ); if (isset($arrOrgData) && sizeof($arrOrgData) > 0) { $strItemIdHtml = $arrOrgData[0]['id_html']; } else { $strItemIdHtml = $objItem['id_html']; } $strFileName = str_replace('#id_item#', $strItemIdHtml, $strFileName); } // Get id_html of cms_dynamic table //$objDynamicMgr = $this->_objModel->createObject('dynamic'); // $objDynamic = $objItemMgr->get($objItem['id_dynamic']); if (isset($objDynamic) && sizeof($objDynamic) > 0) { $strFileName = str_replace('#id_dynamic#', $objDynamic['id_html'], $strFileName); } // Create full path for this file $strItemFolder = @$params['itemview_folder']; if (isset($strItemFolder) && $strItemFolder != '') { $strFileName = $strItemFolder . '/' . $strFileName; } return $strFileName; } /**---------------------------------------------------------------------- * Get closed url (for dynamic HTML contents) * If the content of closed URL is not available, we will copy it * into the root of user site from site_template, using singleton design pattern * @return string The web path of closed url ------------------------------------------------------------------------*/ public function getClosedUrl() { // Init the closed url, using singleton design pattern if ($this->_closed_url == '') { // Copy resources into the root of user site folder $objPath = new PathMgr($this->_config); //$strPublicPath = $objPath->get('user_site', 'public'); $strPublicPath = substr($objPath->get('user_site', 'public'),0,-1); $this->_closed_url = $strPublicPath . $this->_config['system']['closed_url']; /* * C-Unit 2011-10-27 Start * #5561 * check server user private */ if($this->_config['system']['ftp_transfer'] == '1') { // file ftp $strSystemPath = $objPath->get('user_site', 'system'); $directory =$objPath->get('site_template', 'system'); if (strlen($strSystemPath) < strlen($directory)) { $directory = substr($directory, strlen($strSystemPath)); } $this->_objFtpMgr->copyDir($objPath->get('site_template', 'system'), $directory); $this->_closed_url = $this->_objFtpMgr-> strSystemPathFTP . $directory . $this->_config['system']['closed_url']; } else { @mkdir($objPath->get('site', 'system')); @copyDir($objPath->get('site_template', 'system'), $objPath->get('site', 'system')); } } return $this->_closed_url; } /**---------------------------------------------------------------------- * Get data from specified URL * * @param $url The destination system to send request * @param $params The array of parameters * @return string The result content ------------------------------------------------------------------------*/ public function getRequestData($url, $params = array()) { // Create Http client object $objClient = new Zend_Http_Client($url); // set parameter for this object $objClient->setParameterPost($params); // Sent request $objResponse = $objClient->request('POST'); // Get the response data $strData = $objResponse->getBody(); return $strData; } /**---------------------------------------------------------------------- * Get data from specified controller, action, parameters * same as Http Request, but directly on server * * @param $controller The controller name * @param $action The action * @param $params The array of parameters * @return string The result content ------------------------------------------------------------------------*/ public function getRequestDataDirect($controller, $action, $params = array()) { // Create request, response object $request = new Zend_Controller_Request_Simple($action, $controller); $request->setParams($params); $response = new Zend_Controller_Response_Http(); // Dispatch for getting result data $frontController = Zend_Controller_Front::getInstance(); $dispatcher = $frontController->getDispatcher(); $dispatcher->dispatch($request, $response); $strData = $response->getBody(); return $strData; } /**---------------------------------------------------------------------- * Create static HTML for dynamic pages (using in SEO) * @param array $arrApprovalTemplates * @return none ------------------------------------------------------------------------*/ public function createDynamicHtml($arrApprovalTemplates) { // check server user private $objItemMgr = $this->_objModel->createObject('item'); // Create static HTML for dynamic pages (in case of the item approval) $arrApprovalTemplates = array_unique($arrApprovalTemplates); if (sizeof($arrApprovalTemplates) > 0) { $objPath = new PathMgr($this->_config); $strPublicPath = $objPath->get('user_site', 'public'); $objDynamicMgr = $this->_objModel->createObject('dynamic'); $objContentsMgr = $this->_objModel->createObject('contents'); $objTemplateMgr = $this->_objModel->createObject('template'); $objNewsMgr = $this->_objModel->createObject('news'); /** * Convert all array approval items to string */ $strAllDynamicIds = ''; foreach ($arrApprovalTemplates["approval_data_item"] as $strIdDynamic) { $strAllDynamicIds .= $strIdDynamic . '","'; } /** * Remove 3 characters at the last of dynamic ids (",") */ if($strAllDynamicIds != ''){ $strAllDynamicIds = substr($strAllDynamicIds, 0, strlen($strAllDynamicIds) -3); } /** * C-Unit 2011-11-28 Start * Get Site Id from What's News * #5925 */ /* $strWhatNews = ' SELECT REPLACE(GROUP_CONCAT(n.id_site_list SEPARATOR " "), " ", ",") AS id_site FROM ' . $objNewsMgr->get_table() . ' AS n INNER JOIN ' . $objItemMgr->get_table() . ' AS t ON n.data = t.id WHERE n.link = "item" AND t.id_dynamic IN ("' . $strAllDynamicIds . '") GROUP BY n.link '; $arrWhatNewsData = $objItemMgr->query_fetch_all($strWhatNews); $strSiteIds = ''; foreach ($arrWhatNewsData as $objItem) { if($strSiteIds != ""){ $strSiteIds .= '","'; } $strSiteIds .= str_replace(",", '","', $objItem['id_site']); } */ /** * C-Unit 2011-11-28 End */ /** ------------------------------------------------------------------------------ * Generate SQL statement */ $strSql = ' SELECT c.id_template, c.id_site, t.id_html AS id_html_template, it.id AS id_item, d.id_html AS id_html_dynamic, it.id_html AS id_html_item, it.public FROM ' . $objContentsMgr->get_table() . ' AS c, ' . $objTemplateMgr->get_table() . ' AS t, ' . $objItemMgr->get_table() . ' AS it, ' . $objDynamicMgr->get_table() . ' AS d WHERE c.id_template = t.id AND d.id = it.id_dynamic AND c.status = 1 AND c.id_org != "-" AND t.id_org != "-" AND c.public = "public" AND c.contents LIKE "%{@DynamicList}%" AND it.id IN ("' . $strAllDynamicIds . '") '; // AND it.id_dynamic IN ("' . $strAllDynamicIds . '") '; // $strSql .= ' OR c.id IN ("' . $strSiteIds . '")'; /* $strSql .= ' OR c.id IN ( SELECT REPLACE( GROUP_CONCAT( n.id_site_list SEPARATOR " " ) , " ", "," ) AS id_site FROM ' . $objNewsMgr->get_table() . ' AS n WHERE n.data = it.id AND n.link = "item" AND it.id_org != "-" AND it.id_dynamic IN ("' . $strAllDynamicIds . '") '; $strSql .= ' GROUP BY n.link) '; */ $strSql .= ' AND it.status = 1 AND it.id_org != "-" '; $strSql .= ' GROUP BY id_html_template, id_html_dynamic , id_html_item'; /** * Get data from database */ $arrPageData = $objItemMgr->query_fetch_all($strSql); /** ------------------------------------------------------------------------------ * C-Unit 2011-11-28 Start * #6085 * Create destination folder for static pages */ if($this->_config['system']['ftp_transfer'] == '1') { $this->_objFtpMgr->createFolder($this->_config['path']['item_view']); }else { $strItemFolder = $this->_config['path']['root_system'] . str_replace('//', '/', '/' . $this->_config['path']['user_site_create'] . '/' . $this->_config['path']['item_view']); $this->createFolder($strItemFolder); } /* * C-Unit 2011-11-28 End */ /** * Loop to create dynamic file */ foreach ($arrPageData as $objItem) { /**------------------------------------------------------------------------------ * Create file name */ $strFileNamePattern = $this->_config['path']['html_template_file'] . '#id_template#_#id_dynamic#_#id_item#.html'; $strFileName = str_replace('#id_dynamic#', $objItem['id_html_dynamic'], $strFileNamePattern); $strFileName = str_replace('#id_item#', $objItem['id_html_item'], $strFileName); $strFileName = str_replace('#id_template#', $objItem['id_html_template'], $strFileName); /** * C-Unit 2011-01-31 start * #7070 * @Desc: replace the @url by url */ $strFullUrl = $strPublicPath . 'itemview/'. $strFileName; /** * C-Unit 2011-01-31 end */ $strFilePath = $strItemFolder . '/' . $strFileName; // Create static HTML page in case of public value if ($objItem['public'] == 'public') { /** * Get contents of data (by making http request directly on server */ $arrParams = array( 'mode' => 'detail', 'id_item' => $objItem['id_item'], 'site' => $objItem['id_site'], 'template' => $objItem['id_template'], 'html_template' => $objItem['id_html_template'], 'html_dynamic' => $objItem['id_html_dynamic'], 'html_item' => $objItem['id_html_item'], 'dynamic_html_page' => 'true' ); $strFileContent = $this->getRequestDataDirect('site', 'itemview', $arrParams); /** * C-Unit 2011-01-31 start * #7070 * @Desc: replace the @url by url */ $strFileContent = str_replace('@url', $strFullUrl, $strFileContent); /** * C-Unit 2011-01-31 end */ /** ------------------------------------------------------------------------------ * Create Create HTML files */ /** * Create dynamic files on FTP server */ if($this->_config['system']['ftp_transfer'] == '1') { $this->_objFtpMgr->createFile($this->_config['path']['item_view'], $strFileName, $strFileContent); }else { /** * Create dynamic files on local server */ $objFile = fopen($strFilePath, 'w'); if ($objFile) { fwrite($objFile, $strFileContent); fclose($objFile); } } }else{ /** ------------------------------------------------------------------------------ * Delete static HTML page in case of private value */ /** * Delete dynamic files on FTP server */ if($this->_config['system']['ftp_transfer'] == '1') { if ($this->_objFtpMgr-> isExistFile($this->_objFtpMgr->strSystemPathFTP . $this->_config['path']['item_view'] . '/' . $strFileName) == true){ $this->_objFtpMgr->deleteFile($this->_config['path']['item_view'] . '/' . $strFileName, true); } }else{ /** * Delete dynamic files on local server */ if (is_file($strFilePath)) { unlink($strFilePath); } } } } } } // $objItemMgr = $this->_objModel->createObject('item'); // /** // * C-Unit 2011-11-11 // * Get items with id_org != NULL // */ // $strSqlItem = ' // SELECT t.id, t.id_html, t.public, t1.id_html AS id_html_org // FROM ' . $objItemMgr->get_table() . ' AS t // LEFT JOIN ' . $objItemMgr->get_table() . ' AS t1 ON t.id = t1.id_org // WHERE t.status = ' . CMS_STATUS_PUBLIC . ' // AND t.id_org != "-" // '; // // $objContentsMgr = $this->_objModel->createObject('contents'); // $objTemplateMgr = $this->_objModel->createObject('template'); // /** // * C-Unit 2011-10-25 // * #5589 // * Change all tag to english // * AND c.contents like "%{@自動生成一覧}%" => AND c.contents like "%{@DynamicList}%" // */ // $strSqlContents = ' // SELECT c.id, // c.id_template, // c.id_site, // t.id_html, // t1.id AS id_template_org // FROM ' . $objContentsMgr->get_table() . ' AS c // LEFT JOIN ' . $objTemplateMgr->get_table() . ' AS t ON c.id_template = t.id // LEFT JOIN ' . $objTemplateMgr->get_table() . ' AS t1 ON t.id_org = t1.id // AND t1.status = ' . CMS_STATUS_PUBLIC . ' AND t.id_org != "-" // WHERE (c.status = ' . CMS_STATUS_PUBLIC . ' // AND c.public = "public" // AND c.contents like "%{@DynamicList}%" // AND c.id_dynamic = "#id_dynamic#") // AND c.id_org != "-" // '; //// // // $objNewsMgr = $this->_objModel->createObject('news'); // /** // * C-Unit 2011-11-11 // * Get items with id_org != NULL // */ // $strWhatNews = ' // SELECT REPLACE(GROUP_CONCAT(n.id_site_list SEPARATOR " "), " ", ",") AS id_site // FROM ' . $objNewsMgr->get_table() . ' AS n // INNER JOIN ' . $objItemMgr->get_table() . ' AS t ON n.data = t.id // WHERE n.link = "item" // AND t.id_dynamic = "#id_dynamic#" // GROUP BY n.link // '; //// AND n.id_org != "-" // // $objDynamicMgr = $this->_objModel->createObject('dynamic'); // $strFileNamePattern = $this->_config['path']['html_template_file'] . '#id_template#_#id_dynamic#_#id_item#.html'; // // // Create destination folder for static pages // $strItemFolder = $this->_config['path']['root_system'] . str_replace('//', '/', // '/' . $this->_config['path']['user_site_create'] . '/' // . $this->_config['path']['item_view']); // $this->createFolder($strItemFolder); // // /** // * C-Unit 2011-11-11 // * Arrays to check file is created. // */ // $arrFilesCreated = array(); // /** // * C-Unit 2011-11-11 // * Arrays to check file get content. // */ // $arrFilesContent = array(); // // foreach ($arrApprovalTemplates as $strIdDynamic) { // // Get the page template for current page // $strIdHtmlDynamic = $objDynamicMgr->get($strIdDynamic); // $strIdHtmlDynamic = $strIdHtmlDynamic['id_html']; // // // Get all pages based on the page template // $arrPageData = $objItemMgr->query_fetch_all($strSqlItem . ' AND t.id_dynamic = "' . $strIdDynamic . '"'); // // // Get all layout template of static pages that using current page tamplate // $strSqlCurrentContent = str_replace('#id_dynamic#', $strIdDynamic, $strSqlContents); // // // Find all the static pages that use What's New in dyanmic pages // $strWhatNews = str_replace('#id_dynamic#', $strIdDynamic, $strWhatNews); // $arrWhatNewsData = $objContentsMgr->query_fetch_all($strWhatNews); // // if (isset($arrWhatNewsData) && sizeof($arrWhatNewsData) > 0) { // $strIdSiteList = @$arrWhatNewsData[0]['id_site']; // if (isset($strIdSiteList)) { // $strIdSiteList = str_replace (',', '","', $strIdSiteList); // // // Adding What's News condition // $strSqlCurrentContent .= ' // OR c.id IN ("' . $strIdSiteList . '") // '; // } // } // // $arrContents = $objContentsMgr->query_fetch_all($strSqlCurrentContent); // // foreach ($arrPageData as $objItem) { // $strIdHtmlItem = $objItem['id_html']; // // if (isset($objItem['id_html_org']) && $objItem['id_html_org'] != '') { // $strIdHtmlItem = $objItem['id_html_org']; // } // // // Create/delete static HTML page based on public/private value of 'public' field // $strPublic = $objItem['public']; // // foreach ($arrContents as $objContent) { // $strFileName = $strFileNamePattern; // $strFileName = str_replace('#id_dynamic#', $strIdHtmlDynamic, $strFileName); // $strFileName = str_replace('#id_item#', $strIdHtmlItem, $strFileName); // // $strIdTemplate = @$objContent['id_template']; // // // Get the original layout in case of editting layout template // $strIdTemplateOrg = @$objContent['id_template_org']; // if (isset($strIdTemplateOrg) && $strIdTemplateOrg != '') { // $strIdTemplate = $strIdTemplateOrg; // } // // if (isset($strIdTemplate) && $strIdTemplate != '') { // $strFileName = str_replace('#id_template#', $objContent['id_html'], $strFileName); // } else { // $strFileName = str_replace('#id_template#', $objContent['id_html'], $strFileName); // } // // // /** // * C-Unit 2011-11-11 // * If file is created then continue other file // */ // /*if(in_array($strFileName, $arrFilesCreated)){ // continue; // }*/ // $arrFilesCreated[] = $strFileName; // // $strFilePath = $strItemFolder . '/' . $strFileName; // // // Create static HTML page in case of public value // if ($strPublic == 'public') { // // // Get contents of data (by making http request directly on server // $arrParams = array( // 'mode' => 'detail', // 'id_item' => $objItem['id'], // 'site' => @$objContent['id_site'], // 'template' => $strIdTemplate, // 'dynamic_html_page' => 'true' // ); // // $strIdContents = $objContent['id_html'] . '_' . $strIdHtmlDynamic . '_' . $strIdHtmlItem; // /** // * C-Unit 2011-11-11 // * If file got content then not get again. // */ // $strFileCnt = $this->getRequestDataDirect('site', 'itemview', $arrParams); // // if(isset($arrFilesContent[$strIdContents])){ // // $strLog .= "Other Path: ".$strItemFolder . '/' . $strIdContents . '.html'; // $fp = fopen( $strItemFolder . '/' . $strIdContents . '.html', 'w'); // if ($fp) { // fwrite($fp, $arrFilesContent[$strIdContents]); // fclose($fp); // } // }else{ // //$strFileCnt = $this->getRequestDataDirect('site', 'itemview', $arrParams); // $arrFilesContent[$strIdContents] = $strFileCnt; // } // // Write dynamic HTML data into file system // /* // * C-Unit 2011-11-14 // * #6022 // * dynamic HTML data into file system using FTP // */ // if($this->_config['system']['ftp_transfer'] == '1') { // $this->_objFtpMgr->createFolder($this->_config['path']['item_view']); // $this->_objFtpMgr->createFile($this->_config['path']['item_view'] ,$strFileName, $strFileCnt); // }else { // $fp = fopen($strFilePath, 'w'); // if ($fp) { // fwrite($fp, $strFileCnt); // fclose($fp); // } // } // } else { // // Delete static HTML page in case of private value // if (is_file($strFilePath)) { // unlink($strFilePath); // } // } // } // } // } // } // } /**---------------------------------------------------------------------- * Create folder based on $folderPath * @param string $folderPath The full path of folder * @return boolean The result of making folder ------------------------------------------------------------------------*/ public function createFolder($folderPath) { if (!is_dir($folderPath)) { mkdir($folderPath, 0777, true); return true; } return false; } /**---------------------------------------------------------------------- *get content of file * @param string $filename The full path of folder and filename * @return string The result ------------------------------------------------------------------------*/ public function getContentOffile($filename) { $strLine=''; if (file_exists($filename)) { $fh = fopen($filename, "r"); while (!feof($fh)) { $strLine .= fgets($fh); $strLine .= "\n " ; } fclose($fh); } return $strLine; } /**---------------------------------------------------------------------- * C-Unit 2011-10-27 * Convert date to insert to SQL format Y/m/d * @param string $strDate * @param string $strFormat * @return string The result ------------------------------------------------------------------------*/ public function convertToSqlDate($strDate, $strFormat) { if(empty($strFormat) == false && $strFormat != 'Y/m/d'){ $arrDate = explode('/', $strDate); switch($strFormat){ case'd/m/Y': $strDate = $arrDate[2] . '/' . $arrDate[1] . '/' . $arrDate[0]; break; case'm/d/Y': $strDate = $arrDate[2] . '/' . $arrDate[0] . '/' . $arrDate[1]; break; default: $strDate = $arrDate[0] . '/' . $arrDate[1] . '/' . $arrDate[2]; } } return $strDate; } /**---------------------------------------------------------------------- * 使用不可の記号をチェックする * @param object $model チェック対象の連想配列 * @param array $arrError 検証エラー結果オブジェクト * @param object $arrKey 使用不可チェックを行う要素名とその名前を格納した連想配列 * @return object 検証エラー結果オブジェクト ------------------------------------------------------------------------*/ public function check_nochar($model, $arrError, $objKey) { foreach ($objKey as $key => $name) { switch (true) { case (false !== strpos($model[$key], ' ')): case (false !== strpos($model[$key], '\\')): case (false !== strpos($model[$key], '/')): case (false !== strpos($model[$key], ';')): case (false !== strpos($model[$key], ',')): case (false !== strpos($model[$key], '!')): case (false !== strpos($model[$key], '*')): case (false !== strpos($model[$key], '|')): case (false !== strpos($model[$key], '"')): case (false !== strpos($model[$key], '\'')): case (false !== strpos($model[$key], '<')): case (false !== strpos($model[$key], '>')): case (false !== strpos($model[$key], '?')): if (!isset($arrError[$key])) { $arrError[$key] = array(); } if (!isset($arrError[$key]['no_using'])) { $arrError[$key]['no_using'] = array(); } $arrError[$key]['no_using'][] = $this->_objTranslation->_('Util_SiteCls_msg1') . $name . $this->_objTranslation->_('Util_SiteCls_msg2'); break; } } return $arrError; } /**---------------------------------------------------------------------- * 使用不可の記号をチェックする * @param object $model チェック対象の連想配列 * @param array $arrError 検証エラー結果オブジェクト * @param object $arrKey 使用不可チェックを行う要素名とその名前を格納した連想配列 * @return object 検証エラー結果オブジェクト ------------------------------------------------------------------------*/ public function check_path($model, $arrError, $objKey) { foreach ($objKey as $key => $name) { switch (true) { case (false !== strpos($model[$key], ' ')): case (false !== strpos($model[$key], ' ')): case (false !== strpos($model[$key], '\\')): case (false !== strpos($model[$key], '//')): case (false !== strpos($model[$key], ';')): case (false !== strpos($model[$key], ',')): case (false !== strpos($model[$key], '!')): case (false !== strpos($model[$key], '*')): case (false !== strpos($model[$key], '|')): case (false !== strpos($model[$key], '"')): case (false !== strpos($model[$key], '\'')): case (false !== strpos($model[$key], '<')): case (false !== strpos($model[$key], '>')): case (false !== strpos($model[$key], '?')): case (false !== strpos($model[$key], '.')): if (!isset($arrError[$key])) { $arrError[$key] = array(); } if (!isset($arrError[$key]['no_using'])) { $arrError[$key]['no_using'] = array(); } $arrError[$key]['no_using'][] = $this->_objTranslation->_('Util_SiteCls_msg1') . $name . $this->_objTranslation->_('Util_SiteCls_msg2'); break; } } return $arrError; } }