/** * Get the placeholder data for database. * * @param string $data * * @return string */ function db_placeholder($data) { $holder = rand_string(); foreach ($data as $index => $query) { if (is_array($query) && count($query) === 2 && isset($query[1]) && is_array($query[1])) { list($query, $holders) = $query; $query = str_replace(':', $holder, $query); if (isset($holders[0])) { foreach ($holders as $key => $value) { if (regexp_match($holder . '\\?', $query)) { $query = regexp_replace($holder . '\\?', $value, $query, 1); } } } else { uksort($holders, create_function('$a,$b', 'return strlen($b) - strlen($a);')); foreach ($holders as $key => $value) { if (regexp_match($holder . $key, $query)) { $value = is_array($value) ? $value[0] : db_escape($value); $query = regexp_replace($holder . $key, $value, $query); } } } $query = str_replace($holder, ':', $query); $data[$index] = $query; } } return $data; }
/** * Get the unescaped data for database. * * @param string $data * * @return string */ function db_driver_unescape($data) { global $_db; $data = regexp_replace('(^\'|\'$)', '', $data); $data = str_replace('\'\'', '\'', $data); return $data; }
/** * Send encoded mail. * * @param string $to * @param string $subject * @param string $message * @param array $headers * @param string $parameters * @param array $files * * @return bool */ function mail_send($to, $subject, $message, $headers = array(), $parameters = null, $files = array()) { $subject = mb_convert_kana(unify($subject), 'KV', MAIN_INTERNAL_ENCODING); $message = mb_convert_kana(unify($message), 'KV', MAIN_INTERNAL_ENCODING); $subject = mb_convert_encoding($subject, 'JIS', MAIN_INTERNAL_ENCODING); $message = mb_convert_encoding($message, 'JIS', MAIN_INTERNAL_ENCODING); $subject = '=?iso-2022-jp?B?' . base64_encode($subject) . '?='; if (empty($files)) { $boundary = null; } else { $boundary = rand_string(); } if (empty($files)) { $body = $message; } else { $body = "--{$boundary}\n"; $body .= "Content-Type: text/plain; charset=\"iso-2022-jp\"\n"; $body .= "Content-Transfer-Encoding: 7bit\n"; $body .= "\n"; $body .= "{$message}\n"; foreach ($files as $file) { if (!is_file($file)) { continue; } $filename = basename($file); $body .= "\n"; $body .= "--{$boundary}\n"; $body .= "Content-Type: " . file_mimetype($file) . "; name=\"{$filename}\"\n"; $body .= "Content-Disposition: attachment; filename=\"{$filename}\"\n"; $body .= "Content-Transfer-Encoding: base64\n"; $body .= "\n"; $body .= chunk_split(base64_encode(file_get_contents($file))) . "\n"; } $body .= '--' . $boundary . '--'; } if (!isset($headers['X-Mailer'])) { $headers['X-Mailer'] = 'PHP'; } if (!isset($headers['From'])) { $headers['From'] = '"From" <*****@*****.**>'; } if (!isset($headers['MIME-Version'])) { $headers['MIME-Version'] = '1.0'; } if (!isset($headers['Content-Type'])) { if (empty($files)) { $headers['Content-Type'] = 'text/plain; charset="iso-2022-jp"'; } else { $headers['Content-Type'] = 'multipart/mixed; boundary="' . $boundary . '"'; } } if (!isset($headers['Content-Transfer-Encoding'])) { $headers['Content-Transfer-Encoding'] = '7bit'; } $header = null; foreach ($headers as $key => $value) { if ($header) { $header .= "\n"; } $key = regexp_replace('(\\r|\\n)', '', $key); $value = regexp_replace('(\\r|\\n)', '', $value); $header .= $key . ': ' . $value; } return mail($to, $subject, $body, $header, $parameters); }
/** * Log the message to a logs. * * @param string $type * @param string|null $message * * @return void */ function logging($type = 'message', $message = null) { $log = clientip() . ' ' . clientip(true) . ' [' . localdate('Y-m-d H:i:s') . '] ' . $_SERVER['REQUEST_URI']; if ($type === 'get') { if ($fp = fopen(LOGGING_PATH . 'get/' . localdate('Ymd') . '.log', 'a')) { fwrite($fp, $log . "\n"); fclose($fp); } } elseif ($type === 'post' || $type === 'files') { $directory = LOGGING_PATH . $type . '/' . localdate('Ymd') . '/'; if (!is_dir($directory)) { if (mkdir($directory, 0707)) { chmod($directory, 0707); } } if ($type === 'post') { $data = $_POST; } elseif ($type === 'files') { $data = $_FILES; } if ($fp = fopen($directory . localdate('His') . '.log', 'a')) { fwrite($fp, $log . "\n" . print_r($data, true) . "\n"); fclose($fp); } } else { $message = regexp_replace("\r", '\\r', $message); $message = regexp_replace("\n", '\\n', $message); if ($message === null) { $message = '-'; } if ($fp = fopen(LOGGING_PATH . 'message/' . localdate('Ymd') . '.log', 'a')) { fwrite($fp, $log . ' ' . $message . "\n"); fclose($fp); } } return; }
/** * Get the unescaped data for database. * * @param string $data * * @return string */ function db_driver_unescape($data) { global $_db; if ($_db['resource'][$_db['target']]['config']['type'] === 'pdo_mysql') { $data = regexp_replace('(^\'|\'$)', '', $data); $data = stripslashes($data); return $data; } elseif ($_db['resource'][$_db['target']]['config']['type'] === 'pdo_pgsql' or $_db['resource'][$_db['target']]['config']['type'] === 'pdo_sqlite' or $_db['resource'][$_db['target']]['config']['type'] === 'pdo_sqlite2') { $data = regexp_replace('(^\'|\'$)', '', $data); $data = str_replace('\'\'', '\'', $data); return $data; } }