xml = $xmlObject; $this->pageNumber = $pageNumber + 1; $this->validatePageNumber = $pageNumber; $this->pages = array(); $this->startSession(); }function setPageNumber($pageNumber){ $this->pageNumber = $pageNumber; }function execute($mode){ if (!isset($this->xml->is_mobile) || $this->xml->is_mobile != '1') { if (!$this->getSession() || !isset($_SERVER['HTTP_REFERER']) || !$_SERVER['HTTP_REFERER'] || !strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])) { $mode = 'input'; $this->pageNumber = 1; $this->validatePageNumber = 0; }}$hiddens = array(); $errors = array(); $errorPageFilename = false; $isMultipart = false; if (!$this->checkXMLValidate()) { exit; }$this->setSession(); if (isset($this->xml->charset) && is_array($_POST)) { foreach ($_POST as $k => $v) { if (is_array($v)) { foreach ($v as $kk => $vv) { $_POST[$k][$kk] = mb_convert_encoding($vv, 'utf8', $this->xml->charset); }} else { $_POST[$k] = mb_convert_encoding($v, 'utf8', $this->xml->charset); }}}$plugins = $this->getPluginArray(); $pluginObjects = $this->getPluginObjects($plugins); if ($mode == 'return') { if ($this->pageNumber > 1) { $this->pageNumber--; }}foreach ($pluginObjects as $pageNumber => $pluginObject) { if ($mode != 'return' && $pageNumber == $this->validatePageNumber && $this->validatePageNumber > 0 && is_array($pluginObject)){ foreach ($pluginObject as $object) { if ($error = $object->validate()) { $errors[$object->name] = $error; }}}foreach ($pluginObject as $object) { $ov = $object->getValue(); $name = $object->getName('confirm'); if (strlen(trim($object->getValue())) > 0) { $name = $object->getName('confirm'); if (is_array($name)) { foreach ($name as $n) { $hiddens[$n] = $this->getHiddenTag($n, $object->getValue('hidden')); }} else { if ($object->isMultipart()) { $name .= '_hidden'; }$hiddens[$name] = $this->getHiddenTag($name, $object->getValue('hidden')); }}if ($object->tag->type == 'checkgroup') { $checkHiddenVal = ''; if (!empty($ov) && !empty($name)) { $ov = @unserialize(urldecode($ov)); $type = gettype($ov); if ($type == "string") { $checkHiddenVal = $ov; } elseif ($type == "array") { $ovCount = count($ov); $currentCount = '1'; foreach ($ov as $k => $o) { if ($ovCount == $currentCount) { $checkHiddenVal .= $o; } else { $checkHiddenVal .= $o . ', '; }$hiddens[$k] = ''; $currentCount++; }}$hiddens[$name] = ''; }}}}if (count($errors)) { $this->pageNumber--; $errorPageFilename = $this->getErrorPage($this->validatePageNumber); }if ($errorPageFilename) { $mode = 'error'; } else if ($mode == 'send' || count($pluginObjects) < $this->pageNumber) { if ($mode != 'send' && isset($this->xml->templates->confirm)) { $mode = 'confirm'; } else { $mode = 'send'; }} else { $mode = 'input'; }if ($mode == 'send' && $this->xml->session_use != '0') { if (!$_POST['csrfid'] || $_SESSION['csrfid'] != $_POST['csrfid']) { $this->raiseError('csrf'); } else { unset($_SESSION['csrfid']); }}$filename = $errorPageFilename ? $errorPageFilename : $this->getPageTemplateFileName($mode, $this->pageNumber); if (is_array($filename)) { $this->sendForm($pluginObjects); $filename = $filename[0]; $this->resetSession(); }if (file_exists((string)$this->xml->templates['directory'] . $filename)) { $this->templateStrings = file_get_contents((string)$this->xml->templates['directory'] . $filename); } else { $this->raiseError('template'); }if (!isset($this->pages[$this->pageNumber])) { $this->pages[$this->pageNumber] = array(); }if ($mode == 'input') { foreach ($pluginObjects[$this->pageNumber] as $object) { $name = $object->getName('confirm'); if (is_array($name)) { foreach ($name as $n) { unset($hiddens[$n]); }} else { unset($hiddens[$name]); }$this->makeupTemplate('input', $object); if (!$isMultipart) { $isMultipart = $object->isMultipart(); }}}if (count($hiddens)) { foreach ($hiddens as $hidden) { $this->setHiddenTag($hidden); }}$this->replaceTemplate('{form}', $this->getFormTag($mode, $isMultipart)); $this->replaceTemplate('{/form}', ''); if ($mode != 'confirm') { $this->makeupSendButton($this->pages[$this->pageNumber], $errorPageFilename ? true : false); $this->makeupReturnButton($this->pages[$this->pageNumber]); }$this->makeupResetButton($this->pages[$this->pageNumber]); if (isset($this->xml->templates->confirm)) { $this->makeupConfirmTemplate($pluginObjects, $mode); }if (isset($pluginObjects[$this->pageNumber])) { $this->makeupJavaScript($pluginObjects[$this->pageNumber]); }$errorHTML = ''; foreach ($errors as $e) { $errorHTML .= '
  • ' . $e . '
  • ' . PHP_EOL; }$this->replaceTemplate('{errors}', sprintf('', $errorHTML)); $this->viewFinalCharset($this->templateStrings); } function makeupJavaScript($pluginObjects){ $scripts = array(); $submitScripts = array(); foreach ($pluginObjects as $object) { if ($script = $object->getJavaScript()) { $scripts[] = $script; }if ($script = $object->getSubmitJavaScript()) { $submitScripts[] = $script; }}if (!isset($this->xml->is_mobile) || $this->xml->is_mobile != '1') { $script = sprintf( '', implode(PHP_EOL, $scripts), ($this->xml->submit_check == 1 ? ('var WebossReturnFlag=false;' . PHP_EOL . 'function WebossFormConfirm() { ' . PHP_EOL . 'if (WebossReturnFlag) return true;' . PHP_EOL . implode(PHP_EOL, $submitScripts) . PHP_EOL . '}') : '') ); $this->replaceTemplate('', $script . PHP_EOL . ''); }} function makeupConfirmTemplate($pluginObjects, $mode = null){ $formatType = (strtolower($this->xml->templates->confirm_format) == 'dl') ? 'dl' : 'table'; preg_match('/{forms\s*excepts="(.*)"/', $this->templateStrings, $exceptMatches); if (isset($exceptMatches[1])) { $excepts = explode(',', str_replace(' ', '', $exceptMatches[1])); } else { $excepts = array(); }$values = array(); foreach ($pluginObjects as $pluginObject) { foreach ($pluginObject as $object) { $this->replaceTemplate($object->getLabelTag(), $object->getLabel('confirm')); $this->replaceTemplate($object->getFormTag(), $object->getValue('confirm')); if (array_search($object->getName(), $excepts) !== false) { continue; }if ($formatType == 'dl') { $tag = "
    %s
    \n
    %s
    "; } else { $tag = " \n %s\n %s\n "; }$values[] = $object->getLabel('confirm') ? sprintf($tag, $object->getLabel('confirm'), (strlen(trim($object->getValue('confirm'))) > 0 ? htmlspecialchars($object->getValue('confirm')) : '-')) : ''; }}if (strtolower($this->xml->templates->confirm_format) == 'dl') { $html = sprintf("
    \n%s\n
    \n", implode("\n", $values)); } else { $html = sprintf("\n%s\n
    \n", implode("\n", $values)); }$this->replaceTemplate('{forms[^}]*}', $html); if ($mode == 'confirm') { if (isset($this->xml->templates->confirm_send_image)) { $buttonValue = $this->xml->templates->confirm_send_image; } else if (isset($this->xml->templates->confirm_send)) { $buttonValue = $this->xml->templates->confirm_send; } else { $buttonValue = '送信'; }$title = isset($this->xml->templates->confirm_send_title) ? sprintf(' title="%s"', $this->xml->templates->confirm_send_title) : ''; $tabindex = isset($this->xml->templates->confirm_send_tabindex) ? sprintf(' tabindex="%s"', $this->xml->templates->confirm_send_tabindex) : ''; $accesskey = isset($this->xml->templates->confirm_send_accesskey) ? sprintf(' accesskey="%s"', $this->xml->templates->confirm_send_accesskey) : ''; $append = isset($this->xml->templates->confirm_send_append) ? sprintf(' %s', $this->xml->templates->confirm_send_append) : ''; if (isset($this->xml->templates->confirm_send_image)) { $button = sprintf('', $buttonValue, $this->xml->templates->confirm_send, $title, $tabindex, $accesskey, $append); } else { $button = sprintf('', $buttonValue, $title, $tabindex, $accesskey, $append); }if (strpos($this->templateStrings, '{submit}')) { $this->replaceTemplate('{submit}', $button . ''); } else { $this->replaceTemplate('', $button . ''); } if (isset($this->xml->templates->confirm_return_image)) { $buttonValue = $this->xml->templates->confirm_return_image; } else if (isset($this->xml->templates->confirm_return)) { $buttonValue = $this->xml->templates->confirm_return; } else { $buttonValue = '戻る'; }$title = isset($this->xml->templates->confirm_return_title) ? sprintf(' title="%s"', $this->xml->templates->confirm_return_title) : ''; $tabindex = isset($this->xml->templates->confirm_return_tabindex) ? sprintf(' tabindex="%s"', $this->xml->templates->confirm_return_tabindex) : ''; $accesskey = isset($this->xml->templates->confirm_return_accesskey) ? sprintf(' accesskey="%s"', $this->xml->templates->confirm_return_accesskey) : ''; $append = isset($this->xml->templates->confirm_return_append) ? sprintf(' %s', $this->xml->templates->confirm_return_append) : ''; if (isset($this->xml->templates->confirm_return_image)) { $button = sprintf('', $buttonValue, $this->xml->templates->confirm_return, $title, $tabindex, $accesskey, $append); } else { $button = sprintf('', $buttonValue, $title, $tabindex, $accesskey, $append); }if (strpos($this->templateStrings, '{return}')) { $tag = '{return}'; } else { $tag = ''; }$this->replaceTemplate($tag, $button . PHP_EOL); }}function sendForm($pluginObjects){ if (isset($this->xml->csv_filename)) { $this->putCsvFile($pluginObjects); }$this->sendMailToCompany($pluginObjects); $this->sendMailToCustomer($pluginObjects); $this->sendMailToChecked($pluginObjects); } function sendMailToChecked($pluginObjects){ $tags = $this->xml->pages->page->tags->tag; if (!empty($tags)) { if (isset($this->xml->mail_from_tag) && isset($_POST[(string)$this->xml->mail_from_tag]) && strlen($_POST[(string)$this->xml->mail_from_tag])) { $mailFrom = $_POST[(string)$this->xml->mail_from_tag]; } else { $mailFrom = isset($this->xml->mail_from) ? (string)$this->xml->mail_from : ''; } $mailCc = isset($this->xml->mail_cc) ? (string)$this->xml->mail_cc : ''; $mailBcc = isset($this->xml->mail_bcc) ? (string)$this->xml->mail_bcc : ''; $subject = isset($this->xml->mail_templates->send_subject) ? (string)$this->xml->mail_templates->send_subject : 'フォーム投稿がありました'; $returnPath = isset($this->xml->mail_returnpath) ? ('-f' . (string)$this->xml->mail_returnpath) : null; $ua = (isset($this->xml->mail_templates->ua) && $this->xml->mail_templates->ua == 1) ? $_SERVER['HTTP_USER_AGENT'] : ''; $remoteHost = (isset($this->xml->mail_templates->ua) && $this->xml->mail_templates->ua == 1) ? gethostbyaddr($_SERVER['REMOTE_ADDR']) : ''; if ($filename = (string)$this->xml->mail_templates->checksend) { if (file_exists((string)$this->xml->mail_templates['directory'] . $filename)) { $body = file_get_contents((string)$this->xml->mail_templates['directory'] . $filename); $body = str_replace('{ua}', $ua, $body); $body = str_replace('{remotehost}', $remoteHost, $body); } } $files = $this->getAttachedFiles($pluginObjects); foreach ($tags as $tag) { $name = (string)$tag->attributes()->name; if ($tag->type == 'checkbox' && !empty($tag->mail) && !empty($_POST[$name])) { $mailName = $_POST[$name]; $mailBody = $this->makeupCheckboxMailTemplate($body, $pluginObjects, $mailName); $mailTo = (string)$tag->mail; $this->sendMail($mailTo, $mailFrom, $subject, $mailBody, $mailCc, $mailBcc, $files, $returnPath); } } } } function sendMailToCompany($pluginObjects){ if (isset($this->xml->mail_to)) { $mailTo = (string)$this->xml->mail_to; } else { return false; }if (isset($this->xml->mail_to_select)) { $mailToSelects = explode('#', $_POST[(string)$this->xml->mail_to_select]); $mailToSelect = array_shift($mailToSelects); } else { $mailToSelect = null; }if (isset($this->xml->mail_from_tag) && isset($_POST[(string)$this->xml->mail_from_tag]) && strlen($_POST[(string)$this->xml->mail_from_tag])) { $mailFrom = $_POST[(string)$this->xml->mail_from_tag]; } else { $mailFrom = isset($this->xml->mail_from) ? (string)$this->xml->mail_from : ''; }$mailCc = isset($this->xml->mail_cc) ? (string)$this->xml->mail_cc : ''; $mailBcc = isset($this->xml->mail_bcc) ? (string)$this->xml->mail_bcc : ''; $subject = isset($this->xml->mail_templates->send_subject) ? (string)$this->xml->mail_templates->send_subject : 'フォーム投稿がありました'; $returnPath = isset($this->xml->mail_returnpath) ? ('-f' . (string)$this->xml->mail_returnpath) : null; $ua = (isset($this->xml->mail_templates->ua) && $this->xml->mail_templates->ua == 1) ? $_SERVER['HTTP_USER_AGENT'] : ''; $remoteHost = (isset($this->xml->mail_templates->ua) && $this->xml->mail_templates->ua == 1) ? gethostbyaddr($_SERVER['REMOTE_ADDR']) : ''; if ($filename = (string)$this->xml->mail_templates->send) { if (file_exists((string)$this->xml->mail_templates['directory'] . $filename)) { $body = file_get_contents((string)$this->xml->mail_templates['directory'] . $filename); $body = str_replace('{ua}', $ua, $body); $body = str_replace('{remotehost}', $remoteHost, $body); }$body = $this->makeupMailTemplate($body, $pluginObjects); }$files = $this->getAttachedFiles($pluginObjects); $this->sendMail($mailTo, $mailFrom, $subject, $body, $mailCc, $mailBcc, $files, $returnPath); if ($mailToSelect) { $this->sendMail($mailToSelect, $mailFrom, $subject, $body, null, null, $files, $returnPath); }} function makeupCheckboxMailTemplate($templateStrings, $pluginObjects, $mailName = '') { $templateStrings = preg_replace('/{checkvalue}/', $mailName, $templateStrings); preg_match('/{forms\s*excepts="(.*)"/', $templateStrings, $exceptMatches); if (isset($exceptMatches[1])) { $excepts = explode(',', str_replace(' ', '', $exceptMatches[1])); } else { $excepts = array(); } $forms = array(); foreach ($pluginObjects as $pluginObject) { foreach ($pluginObject as $object) { $templateStrings = preg_replace('/' . $object->getLabelTag() . '/', $object->getLabel('mail'), $templateStrings); $templateStrings = preg_replace('/' . $object->getFormTag() . '/', $object->getValue('mail'), $templateStrings); if (array_search($object->getName(), $excepts) !== false) { continue; } $name = $object->getLabel('mail'); $value = $object->getValue('mail'); $value = str_replace('m²', '平米', $value); $value = str_replace("\r\n","\r", $value); $value = str_replace("\r","\n", $value); if ($name) { $forms[] = '■ ' . $name . PHP_EOL . $value . PHP_EOL; } } } $templateStrings = preg_replace('/{forms[^}]*}/', implode(PHP_EOL, $forms), $templateStrings); $templateStrings = preg_replace('/{remote_host}/', gethostbyaddr($_SERVER['REMOTE_ADDR']) . '(' . $_SERVER['REMOTE_ADDR'] . ')', $templateStrings); return $templateStrings; } function getAttachedFiles($pluginObjects){ $files = array(); foreach ($pluginObjects as $pluginObject) { foreach ($pluginObject as $object) { if ($object->isMultipart()) { $files[] = (string)$object->tag->directory . DIRECTORY_SEPARATOR . $object->getValue(); }}}return $files; }function sendMailToCustomer($pluginObjects){ if (isset($this->xml->mail_form) && isset($_POST[(string)$this->xml->mail_form])) { $mailTo = trim($_POST[(string)$this->xml->mail_form]); } else { return false; }$mailFrom = isset($this->xml->mail_from) ? (string)$this->xml->mail_from : ''; $mailCc = isset($this->xml->mail_cc) ? (string)$this->xml->mail_cc : ''; $mailBcc = isset($this->xml->mail_bcc) ? (string)$this->xml->mail_bcc : ''; $subject = isset($this->xml->mail_templates->thanks_subject) ? (string)$this->xml->mail_templates->thanks_subject : 'フォームへの投稿ありがとうございました'; $returnPath = isset($this->xml->mail_returnpath) ? ('-f ' . (string)$this->xml->mail_returnpath) : null; if ($filename = (string)$this->xml->mail_templates->thanks) { if (file_exists((string)$this->xml->mail_templates['directory'] . $filename)) { $body = file_get_contents((string)$this->xml->mail_templates['directory'] . $filename); }$body = $this->makeupMailTemplate($body, $pluginObjects); }$this->sendMail($mailTo, $mailFrom, $subject, $body, null, $mailBcc, null, $returnPath); }function makeupMailTemplate($templateStrings, $pluginObjects){ preg_match('/{forms\s*excepts="(.*)"/', $templateStrings, $exceptMatches); if (isset($exceptMatches[1])) { $excepts = explode(',', str_replace(' ', '', $exceptMatches[1])); } else { $excepts = array(); }$forms = array(); foreach ($pluginObjects as $pluginObject) { foreach ($pluginObject as $object) { $templateStrings = preg_replace('/' . $object->getLabelTag() . '/', $object->getLabel('mail'), $templateStrings); $templateStrings = preg_replace('/' . $object->getFormTag() . '/', $object->getValue('mail'), $templateStrings); if (array_search($object->getName(), $excepts) !== false) { continue; }$name = $object->getLabel('mail'); $value = $object->getValue('mail'); $value = str_replace('m²', '平米', $value); $value = str_replace("\r\n","\r", $value); $value = str_replace("\r","\n", $value); if ($name) { $forms[] = '■ ' . $name . PHP_EOL . $value . PHP_EOL; }}}$templateStrings = preg_replace('/{forms[^}]*}/', implode(PHP_EOL, $forms), $templateStrings); $templateStrings = preg_replace('/{remote_host}/', gethostbyaddr($_SERVER['REMOTE_ADDR']) . '(' . $_SERVER['REMOTE_ADDR'] . ')', $templateStrings); return $templateStrings; }function sendMail($to, $from, $subject, $body, $cc = null, $bcc = null, $files = array(), $returnPath = null){ if (is_array($files) && count($files)) { $boundary = md5(uniqid(rand())); $header = sprintf("From: %s\n%s%sContent-Type: multipart/mixed;\n\tboundary=\"%s\"\nX-Mailer: WEBOSSFORM", $from, ($cc ? sprintf("Cc: %s\n", $cc) : ''), ($bcc ? sprintf("Bcc: %s\n", $bcc) : ''), $boundary ); $subject = sprintf('=?utf-8?B?%s?=', base64_encode($subject)); $mailBody = sprintf("This is a multi-part message in MIME format.\n\n--%s\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit\n", $boundary); $mailBody .= $body; $mailBody .= "\n"; foreach ($files as $file) { if (basename($file) && file_exists($file)) { if ($contents = @file_get_contents($file)) { $encodedContents = chunk_split(base64_encode($contents)); $encodedContents = str_replace("\r\n","\r", $encodedContents); $encodedContents = str_replace("\r","\n", $encodedContents); $filename = basename($file); $mailBody .= sprintf( "\n\n--%s\nContent-Type: application/octet-stream;\n\tname=\"%s\"\n" . "Content-Transfer-Encoding: base64\nContent-Disposition: attachment;\n" . "\tfilename=\"%s\"\n\n%s\n", $boundary, $filename, $filename, $encodedContents ); }}}$mailBody .= sprintf("--%s--", $boundary); } else { $header = sprintf("From: %s\n%s%sContent-Type: text/plain;charset=utf-8\nContent-Transfer-Encoding: 8bit\nX-Mailer: WEBOSSFORM", $from, ($cc ? sprintf("Cc: %s\n", $cc) : ''), ($bcc ? sprintf("Bcc: %s\n", $bcc) : '') ); $subject = sprintf('=?utf-8?B?%s?=', base64_encode($subject)); $mailBody = $body; }if ($returnPath) { mail($to, $subject, $mailBody, $header, $returnPath); } else { mail($to, $subject, $mailBody, $header); }}function putCsvFile($pluginObjects){ $filename = (string)$this->xml->csv_filename; if (!file_exists($filename) || !file_get_contents($filename)) { $headerData = array(); foreach ($pluginObjects as $page => $pageObjects) { foreach ($pageObjects as $object) { if ($data = $object->getLabel('csv')) { $headerData[] = $data; }}}$headerData[] = '送信ホスト'; $headerData[] = '送信日時'; $csvdata = '"' . implode('","', $headerData) . '"' . PHP_EOL; file_put_contents($filename, mb_convert_encoding($csvdata, 'sjis-win', 'utf8')); } else { $csvdata = mb_convert_encoding(file_get_contents($filename), 'utf-8', 'sjis-win'); }$lineData = array(); foreach ($pluginObjects as $page => $pageObjects) { foreach ($pageObjects as $object) { if ($object->getLabel('csv')) { $lineData[] = str_replace('"', '""', $object->getValue('csv')); }}}$lineData[] = gethostbyaddr($_SERVER['REMOTE_ADDR']) . '(' . $_SERVER['REMOTE_ADDR'] . ')'; $lineData[] = date('Y-m-d H:i:s'); $csvdata .= '"' . implode('","', $lineData) . '"' . PHP_EOL; file_put_contents($filename, mb_convert_encoding($csvdata, 'sjis-win', 'utf8')); }function makeupReturnButton($pageObject){ if (isset($pageObject->return_title)) { $title = sprintf(' title="%s"', $pageObject->return_title); } else { $title = ''; }if (isset($pageObject->return_tabindex)) { $tabindex = sprintf(' tabindex="%s"', $pageObject->return_tabindex); } else { $tabindex = ''; }if (isset($pageObject->return_accesskey)) { $accesskey = sprintf(' accesskey="%s"', $pageObject->return_accesskey); } else { $accesskey = ''; }if (isset($pageObject->return_image)) { $button = sprintf('', $pageObject->return_image, $pageObject->return, $title, $tabindex, $accesskey); } else if (isset($pageObject->return)){ $button = sprintf('', $pageObject->return, $title, $tabindex, $accesskey); } else { return false; }if (strpos($this->templateStrings, '{return}')) { $tag = '{return}'; } else { $tag = ''; }$this->replaceTemplate($tag, $button . PHP_EOL); }function makeupResetButton($pageObject){ $append = isset($pageObject->reset_append) ? sprintf(' %s', $pageObject->reset_append) : ''; if (isset($pageObject->reset_title)) { $title = sprintf(' title="%s"', $pageObject->reset_title); } else { $title = ''; }if (isset($pageObject->reset_tabindex)) { $tabindex = sprintf(' tabindex="%s"', $pageObject->reset_tabindex); } else { $tabindex = ''; }if (isset($pageObject->reset_accesskey)) { $accesskey = sprintf(' accesskey="%s"', $pageObject->reset_accesskey); } else { $accesskey = ''; }if (isset($pageObject->reset)){ $value = (string)$pageObject->reset; } else { $value = 'リセット'; }if (isset($pageObject->reset_image)) { $button = sprintf('', $pageObject->reset_image, $value, $title, $tabindex, $accesskey, FORM_ID, $append); } else { $button = sprintf('', $value, $title, $tabindex, $accesskey, $append); }$this->replaceTemplate('{reset}', $button . "\n"); }function getErrorPage($pageNumber){ if ($errorPage = (string)$this->pages[$pageNumber]->error) { return $errorPage; } else { return false; }}function setHiddenTag($hidden){ $this->templateStrings = str_replace('{/form}', $hidden . PHP_EOL . '{/form}', $this->templateStrings); }function getHiddenTag($name, $value){ return sprintf('', $name, htmlspecialchars($value)); }function makeupSendButton($pageObject, $isError = false){ $isImage = false; if ($isError) { $append = isset($pageObject->error_send_append) ? sprintf(' %s', $pageObject->error_send_append) : ''; if (isset($pageObject->error_send_image)) { $buttonValue = $pageObject->error_send_image; $pageObject->send = $pageObject->error_send; $isImage = true; } else if (isset($pageObject->error_send)){ $buttonValue = $pageObject->error_send; } else { $buttonValue = '戻る'; }if (isset($pageObject->error_send_title)) { $title = sprintf(' title="%s"', $pageObject->error_send_title); } else { $title = ''; }if (isset($pageObject->error_send_tabindex)) { $tabindex = sprintf(' tabindex="%s"', $pageObject->error_send_tabindex); } else { $tabindex = ''; }if (isset($pageObject->error_send_accesskey)) { $accesskey = sprintf(' accesskey="%s"', $pageObject->error_send_accesskey); } else { $accesskey = ''; }} else { $append = isset($pageObject->send_append) ? sprintf(' %s', $pageObject->send_append) : ''; if (isset($pageObject->send_image)) { $buttonValue = $pageObject->send_image; $isImage = true; } else if (isset($pageObject->send)) { $buttonValue = $pageObject->send; } else { $buttonValue = '送信'; }if (isset($pageObject->send_title)) { $title = sprintf(' title="%s"', $pageObject->send_title); } else { $title = ''; }if (isset($pageObject->send_tabindex)) { $tabindex = sprintf(' tabindex="%s"', $pageObject->send_tabindex); } else { $tabindex = ''; }if (isset($pageObject->send_accesskey)) { $accesskey = sprintf(' accesskey="%s"', $pageObject->send_accesskey); } else { $accesskey = ''; }}if ($isImage) { $button = sprintf('', $buttonValue, $pageObject->send, $title, $tabindex, $accesskey, $append); } else { $button = sprintf('', $buttonValue, $title, $tabindex, $accesskey, $append); }if (strpos($this->templateStrings, '{submit}')) { $this->replaceTemplate('{submit}', $button . ''); } else { $this->replaceTemplate('', $button . ''); }}function getFormTag($mode = 'input', $isMultipart = false){ if ($this->xml->submit_check == 1 && $mode == 'input') { $onsubmit = 'onsubmit="return WebossFormConfirm();"'; } else { $onsubmit = ''; }if (isset($this->xml->jquery_mobile)) { if ($this->xml->jquery_mobile == 1) { $html = '
    ' . PHP_EOL; } else { $html = '' . PHP_EOL; }} else { $html = '' . PHP_EOL; }$html = sprintf($html, FORM_ID, FORM_ID, FORM_ACTION, ($isMultipart ? 'enctype="multipart/form-data"' : ''), $onsubmit); if ($mode == 'input') { $html .= '' . PHP_EOL . sprintf('', $this->pageNumber) . PHP_EOL; } else if ($mode == 'confirm') { $html .= '' . PHP_EOL; if ($this->xml->session_use != '0') { $csrfid = $this->getCsrfId(); $html .= sprintf('', $csrfid) . PHP_EOL; $_SESSION['csrfid'] = $csrfid; }} else if ($mode == 'error') { $html .= '' . PHP_EOL . sprintf('', $this->pageNumber) . PHP_EOL; }return $html; }function getPageTemplateFileName($mode, $pageNumber){ if ($mode == 'input') { $filename = $this->pages[$pageNumber]->template; } else if ($mode == 'confirm') { $filename = (string)$this->xml->templates->confirm; } else if ($mode == 'send') { if ($this->xml->templates->thanks) { $filename = array((string)$this->xml->templates->thanks); } else { $this->raiseError('template format'); }} else { $this->raiseError('template format'); }return $filename; }function makeupTemplate($mode = 'input', $object = null){ $this->replaceTemplate($object->getLabelTag(), $object->getLabel()); $html = $object->getForm(); $this->replaceTemplate($object->getFormTag(), $html); }function replaceTemplate($templateTag, $convertedTag){ $templateTag = sprintf('|%s|', str_replace(array('{', '}'), array('\\{', '\\}'), $templateTag)); $this->templateStrings = preg_replace($templateTag, $convertedTag, $this->templateStrings); }function viewFinalCharset($html){ if ($this->xml->charset != 'utf8') { $html = mb_convert_encoding($html, $this->xml->charset, 'utf8,euc,sjis'); header("Content-type: text/html; charset=", ($this->xml->charset == 'sjis' ? 'Shift-JIS' : $this->xml->charset)); } else { header("Content-type: text/html; charset=utf8"); }print $html; }function checkXMLValidate(){ $forms['charset'] = $this->_initval($this->xml->charset, 'utf-8'); if (!strlen(trim($this->xml->mail_to))) { $this->raiseError('xml format', 'Mail address'); }return true; }function getPluginObjects($pluginsArray, $pageNumber = null){ $pluginObjects = array(); if (is_array($pluginsArray)) { foreach ($pluginsArray as $pluginPageNumber => $plugin) { if (is_null($pageNumber) || $pageNumber == $pluginPageNumber) { foreach ($plugin as $id => $tag) { $className = 'Plugin' . ucfirst($tag->type); if (class_exists($className)) { $pluginObjects[$pluginPageNumber][] = new $className($tag); } else { $this->raiseError('class'); }}}}}return $pluginObjects; }function getPluginArray(){ $pluginNames = array(); if ($this->xml->pages) { $pageCount = 1; foreach ($this->xml->pages as $pageObjects) { foreach ($pageObjects->page as $page) { $this->pages[$pageCount] = $page; if ($page->tags) { foreach ($page->tags as $tagObjects) { foreach ($tagObjects->tag as $tag) { if (strlen(trim((string)$tag->type))) { $filename = './plugins/plugin_' . (string)$tag->type . '.class.php'; if (file_exists($filename)) { require_once($filename); }$pluginNames[$pageCount][(string)$tag['name']] = $tag; }} }}$pageCount++; }}}return $pluginNames; }function raiseError($errorMode, $parameter = null){ $errorMessages = array( 'xml' => 'XML file not found.', 'xml format' => 'XML file format error : not defined %s.', 'template' => 'template file not found.', 'template format' => 'template xml data not found.', 'class' => 'class file is not found.', 'csrf' => 'invalid post.', ); echo (($msg = $errorMessages[$errorMode]) ? sprintf($msg, $parameter) : 'undefined error.') . "\n"; exit; }function _initval($value, $default = null){ if (is_null($value)) { $value = $default; }return $value; }function setSession(){ if ($this->xml->session_use != '0') { $_SESSION[FORM_ID] = md5(time() . mt_rand(10000, 99999)); }}function getSession(){ if ($this->xml->session_use != '0') { return isset($_SESSION[FORM_ID]) ? $_SESSION[FORM_ID] : ''; } else { return true; }}function resetSession(){ if ($this->xml->session_use != '0') { unset($_SESSION[FORM_ID]); }}function startSession(){ if ($this->xml->session_use != '0') { session_set_cookie_params(0); session_id(FORM_ID); session_start(); }}function getCsrfId(){ return Weboss_FormCreater::getRandom(); }static function getRandom($length = 64){ static $srand = false; if ($srand == false) { list($usec, $sec) = explode(' ', microtime()); mt_srand((float) $sec + ((float) $usec * 100000) + getmypid()); $srand = true; }$value = ""; for ($i = 0; $i < 2; $i++) { if (file_exists('/proc/net/dev')) { $rx = $tx = 0; $fp = fopen('/proc/net/dev', 'r'); if ($fp != null) { $header = true; while (feof($fp) === false) { $s = fgets($fp, 4096); if ($header) { $header = false; continue; }$v = preg_split('/[:\s]+/', $s); if (is_array($v) && count($v) > 10) { $rx += $v[2]; $tx += $v[10]; }}}$platform_value = $rx . $tx . mt_rand() . getmypid(); } else { $platform_value = mt_rand() . getmypid(); }$now = strftime('%Y%m%d %H:%M:%S'); $time = gettimeofday(); $v = $now . $time['usec'] . $platform_value . mt_rand(0, time()); $value .= md5($v); }if ($length < 64) { $value = substr($value, 0, $length); }return $value; }} class Weboss_FormObject{ var $parse; var $tag; var $name; function Weboss_FormObject($tag){ $this->name = (string)$tag['name']; $this->tag = $tag; }function getFormTag(){ $tag = '{tag name="%s"}'; return sprintf($tag, $this->name); }function isMultipart(){ return false; }function getName(){ return $this->name; }function getValue($mode = null){ if (isset($_POST[$this->getName()])) { return $this->filter($_POST[$this->getName()], $mode); } else { return ''; }}function filter($param, $mode){ return $param; }function getLabelTag(){ $tag = '{label name="%s"}'; return sprintf($tag, $this->name); }function getLabel($mode = null){ if (isset($this->tag->label)) { return $this->tag->label; } else { return $this->name; }}function getJavaScript() {}function getSubmitJavaScript() {}function validate() {}function stripTags($text){ $text = preg_replace('/