// ******************************************************* // TomTak // Date: 2011-06-23 // ******************************************************* session_start(); ini_set('mbstring.internal_encoding', 'UTF-8'); define(LF , chr(10)); define(SQLITE_URI , 'sqlite:./data/data.sqlite'); define(HTML_TEMPLATE , './template.html'); define(HTML_TEMPLATE_TOP , './template_top.html'); define(HTML_PREVIEW , './preview_template.html'); define(XML_PATH , './data/site_express_base_setting.xml'); define(UPLOAD_PATH , './system/site_express/img/upload/'); define(PATH_STARTER, './system/starter/index.php'); print main(); // =================================================== // main // =================================================== function main() { $oXml = simplexml_load_file(XML_PATH); if ($oXml->type == 'starter') { require(PATH_STARTER); $sRes = buildStarter(); } else { $sRes = buildSiteExpress(); } return $sRes; } // =================================================== // buildSiteExpress // =================================================== function buildSiteExpress() { // --- necessary for CPI server --- header('Content-Type:text/html;charset=utf-8;'); // --- get data --- $iPageId = $_GET['pageid']; // --- search top page --- if(!$iPageId) { // --- build sql --- $sql = ''; $sql .= 'select id from site_express_page where top="○"'; // --- db access --- $oPdo = new PDO(SQLITE_URI); $oPdoStmt = $oPdo->query($sql); $aData = array(); if($oPdoStmt) { $aData = $oPdoStmt->fetchAll(PDO::FETCH_NUM); } $iPageId .= $aData[0][0]; } // --- build sql --- $sql = ''; $sql .= 'select * from site_express_page where id=' . $iPageId; // --- db access --- $oPdo = new PDO(SQLITE_URI); $oPdoStmt = $oPdo->query($sql); $aData = array(); if($oPdoStmt) { $aData = $oPdoStmt->fetchAll(PDO::FETCH_NUM); } // --- define column number --- define(TOP, 3); define(TITLE_NUM , 5); define(CONTENT_NUM , 6); // --- check top template --- $iFileSize = 0; if (file_exists(HTML_TEMPLATE_TOP)) { $iFileSize = (int)filesize(HTML_TEMPLATE_TOP); } // --- set template --- $sTemplate = $aData[0][TOP]; $pathTemplate = ''; if($sTemplate && $iFileSize) { $pathTemplate .= HTML_TEMPLATE_TOP; } else { $pathTemplate .= HTML_TEMPLATE; } // --- html setting --- $sTemplatePath = $pathTemplate; $sAction = $_GET['action']; if($sAction == 'preview') { $sTemplatePath = HTML_PREVIEW; } // --- read template html --- $htmBody = ''; if (!file_exists($sTemplatePath)) { buildDefaultTemplate(); } $oFp = fopen($sTemplatePath, 'r'); while (!feof($oFp)) { $htmBody .= fgets($oFp); } fclose($oFp); // --- send mail if needed (2012-02-09) --- $sContent = $aData[0][CONTENT_NUM]; if ($sAction == 'sendmail') { require('./system/lib/procMail.php'); $sContent = procMail(); } // --- replace content --- $htmBody = str_replace('[[content]]' , $sContent , $htmBody); // --- replace tag setting (page title) --- $aReplaceData = array(); $aReplaceData['[[page_title]]'] = $aData[0][TITLE_NUM]; // --- replace tag setting (menu) --- $iMenu = strpos($htmBody , '[[menu]]'); if($iMenu) { $htmUlMenu = buildMenu(); $aReplaceData['[[menu]]'] = $htmUlMenu; } // --- replace tag setting (submenu) --- $iSubmenu = strpos($htmBody , '[[submenu]]'); if($iSubmenu) { $htmSubmenu = buildSubmenu(); $aReplaceData['[[submenu]]'] = $htmSubmenu; } // --- replace tag setting (news) --- $iNews = strpos($htmBody , '[[news]]'); if($iNews) { $sNews = buildNews(); $aReplaceData['[[news]]'] = $sNews; } // --- replace tag setting (mail form) --- $iMail = strpos($htmBody , '[[mail]]'); if($iMail) { $aQueryString = parse_str($_SERVER['QUERY_STRING']); $urlSelf = basename($_SERVER['PHP_SELF']) . '?' . uniqid() . '&pageid=mail&action=sendmail'; $pathMailFormHtml = './system/mail/mailform.html'; $sMailForm .= '
'; $aReplaceData['[[mail]]'] = $sMailForm; } // --- get xml data --- $bXmlExist = file_exists(XML_PATH); if($bXmlExist) { $oXml = simplexml_load_file(XML_PATH); $sLogo = UPLOAD_PATH . $oXml->logo[0]; $sTitle = $oXml->title[0]; $sCatchCopy = $oXml->catch_copy[0]; $aKeyword = array(); foreach($oXml->keyword_list[0]->keyword as $key=>$val){ $aKeyword[] = (string)$val[0]; } $sKeyword = ''; if(count($aKeyword)) { $sKeyword = implode(',' , $aKeyword); } $sDescription = $oXml->description[0]; // --- replace tag setting (base setting) --- $aReplaceData['[[logo]]'] = $sLogo; $aReplaceData['[[base_title]]'] = $sTitle; $aReplaceData['[[catch_copy]]'] = $sCatchCopy; $aReplaceData['[[keyword]]'] = $sKeyword; $aReplaceData['[[description]]'] = $sDescription; } // --- replace tag setting (css / js) --- $aReplaceData['[[css_main]]'] = './css/main.css'; $aReplaceData['[[jquery]]'] = './js/jquery.js'; $aReplaceData['[[hover.js]]'] = './js/hoverIntent.js'; $aReplaceData['[[superfish.js]]'] = './js/superfish.js'; $aReplaceData['[[mail.js]]'] = './js/mail.js'; $aReplaceData['[[js]]'] = './js/main.js'; // --- replace --- foreach($aReplaceData as $key=>$val) { $htmBody = str_replace($key , $val , $htmBody); } return $htmBody; } // =================================================== // build news // =================================================== function buildNews() { // --- lang select --- if ($_GET['lang'] ) { $_SESSION['lang'] = '_' . $_GET['lang']; } else { if (!$_SESSION['lang']) { $_SESSION['lang'] = '_jp'; } } // --- set table name --- define(TBL_PREFIX , 'news'); $sTblName = TBL_PREFIX . $_SESSION['lang']; // --- build sql condition --- $sToday = date('Y-m-d'); $sqlWhere = ''; $sqlWhere .= 'where '; $sqlWhere .= ' update_date <= "' . $sToday . '"'; $sqlWhere .= ' and '; $sqlWhere .= ' content <> "" '; // --- get news line max & new limit day $oXml = simplexml_load_file(XML_PATH); $iLineMax = (int)$oXml->line_max[0]; $iNewLimitDay = (int)$oXml->new_limit_day[0]; // --- check and set value (line-max / limit-day) --- if(!$iLineMax) { define('DEFAULT_LINEMAX', 5); $iLineMax = DEFAULT_LINEMAX; } if(!$iNewLimitDay) { define('DEFAULT_LIMIT_DAY', 7); $iNewLimitDay = DEFAULT_LIMIT_DAY; } // --- build sql --- $sql = ''; $sql .= 'select update_date, content, url, window '; $sql .= 'from ' . $sTblName . ' '; $sql .= $sqlWhere; $sql .= 'order by update_date desc, id desc '; $sql .= 'limit ' . $iLineMax; // --- db access --- $oPdo = new PDO(SQLITE_URI); $oPdoStmt = $oPdo->query($sql); $aData = array(); if($oPdoStmt) { $aData = $oPdoStmt->fetchAll(PDO::FETCH_NUM); } // --- check count of news --- $iNewsCount = count($aData); if(!$iNewsCount) { return '[[news]]'; } // --- define column number --- define(DATE, 0); define(NEWS, 1); define(URL, 2); define(WINDOW, 3); // --- time setting --- $iNewLimitDay = 60 * 60 * 24 * $iNewLimitDay; $iToday = mktime('0' , '0' , '0' , date('m') , date('d') , date('Y')); // --- build img --- $sNewImg = ''; $sNewImg .= LF; $sNewImg .= 'new_img[0].'"'; $sNewImg .= ' class="new_img"'; $sNewImg .= ' alt="new"'; $sNewImg .= ' title="new">'; // --- build news record --- $sNewsRecord = ''; $sNewsRecord .= LF . '