/** * Translates a given string into the selected language, if exists * * @param string $msgid string to translate * @param mixed $substitution Prevent the returned string from being replaced with html entities * @return string Translated or original string */ function tr($msgid, $substitution = false) { $encoding = 'UTF-8'; $msgstr = gettext($msgid); if ($msgid == 'encoding' && $msgstr == 'encoding') { $msgstr = 'UTF-8'; } // Detect comments and strip them if $msgid == $msgstr // e.g. tr('_: This is just a comment\nReal message to translate here') if (substr($msgid, 0, 3) == '_: ' && $msgid == $msgstr && count($l = explode("\n", $msgid)) > 1) { unset($l[0]); $msgstr = implode("\n", $l); } // Replace values if (func_num_args() > 1) { $argv = func_get_args(); unset($argv[0]); //msgid if (is_bool($argv[1])) { unset($argv[1]); } $msgstr = vsprintf($msgstr, $argv); } if (!$substitution) { $msgstr = replace_html(htmlentities($msgstr, ENT_COMPAT, $encoding)); } return $msgstr; }
/** * Full name creator. * @param string $fname First Name, eg: John * @param string $lname Last Name, eg: Doe * @param string $mname Middle Name, eg: Dela Cruz * @return string Format: John D.C. Doe */ function create_name($fname, $lname, $mname = null, $order = 'standard') { $mi = ''; if ($mname !== null) { $temp = explode(' ', $mname); foreach ($temp as &$i) { if (!empty($i)) { $i = strtoupper(substr($i, 0, 1)) . '.'; } } unset($i); $mi = implode(' ', $temp); } // first letter only according to http://www.census.gov.ph/civilregistration/problems-and-solutions/compound-middle-names-dela-cruz-quintos-deles-villa-roman // $mi = substr(strtoupper($mname), 0, 1).'.'; if ($order === 'standard') { return trim(replace_html("{$fname} {$mi} {$lname}")); } else { return trim(replace_html("{$lname}, {$fname} {$mi}")); } }
/** * log function */ function write_log($msg, $level = E_USER_WARNING) { $cfg = EasySCP_Registry::get('Config'); if (isset($_SERVER['REMOTE_ADDR'])) { $client_ip = $_SERVER['REMOTE_ADDR']; } else { $client_ip = "unknown"; } $msg = htmlentities($msg, ENT_NOQUOTES, tr('encoding'), false); $msg = replace_html($msg, ENT_COMPAT, tr('encoding')) . '<br /><small>User IP: ' . $client_ip . '</small>'; $sql_param = array(':log_message' => $msg); $sql_query = "\n\t\tINSERT INTO\n\t\t\tlog (log_time, log_message)\n\t\tVALUES\n\t\t\t(NOW(), :log_message);\n\t\t"; DB::prepare($sql_query); DB::execute($sql_param)->closeCursor(); $msg = strip_tags(str_replace('<br />', "\n", $msg)); // now send email if DEFAULT_ADMIN_ADDRESS != '' if (EasyConfig::$cfg->{'DEFAULT_ADMIN_ADDRESS'} != '' && $level <= $cfg->LOG_LEVEL) { global $default_hostname, $default_base_server_ip, $Version, $BuildDate, $admin_login; $admin_email = EasyConfig::$cfg->{'DEFAULT_ADMIN_ADDRESS'}; $default_hostname = EasyConfig::$cfg->{'SERVER_HOSTNAME'}; $default_base_server_ip = EasyConfig::$cfg->{'BASE_SERVER_IP'}; $Version = EasyConfig::$cfg->{'Version'}; $BuildDate = EasyConfig::$cfg->{'BuildDate'}; $subject = "EasySCP {$Version} on {$default_hostname} ({$default_base_server_ip})"; $to = EasyConfig::$cfg->{'DEFAULT_ADMIN_ADDRESS'}; $message = <<<AUTO_LOG_MSG EasySCP Log Server: {$default_hostname} ({$default_base_server_ip}) Version: EasySCP {$Version} ({$BuildDate}) Message: ----------------[BEGIN]-------------------------- {$msg} Message: ----------------[END]---------------------------- AUTO_LOG_MSG; $headers = "From: \"EasySCP Logging Daemon\" <" . $admin_email . ">\n"; $headers .= "MIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 7bit\n"; $headers .= "X-Mailer: EasySCP {$Version} Logging Mailer"; $mail_result = mail($to, $subject, $message, $headers); // Reduce admin log entries by only logging email notification if not // successful if (!$mail_result) { $mail_status = $mail_result ? 'OK' : 'NOT OK'; $sql_param = array(':log_message' => "{$admin_login}: Logging Daemon Mail To: |{$to}|, " . "From: |{$admin_email}|, Status: |{$mail_status}|!"); $sql_query = "\n\t\t\t\tINSERT INTO\n\t\t\t\t\tlog (log_time, log_message)\n\t\t\t\tVALUES\n\t\t\t\t\t(NOW(), :log_message);\n\t\t\t"; DB::prepare($sql_query); DB::execute($sql_param)->closeCursor(); } } }
</td></tr> </table> <?php //header("location:".$row["url"].""); $file_name = "www/" . str_replace("http://", "", $url . ".html"); if (file_exists($file_name)) { $htmlcode = file_get_contents($file_name); //echo $file_name; } if (empty($htmlcode)) { $spider = new spider(); $spider->url($url); $htmlcode = $spider->htmlcode; } $htmlcode = replace_html($htmlcode); /* foreach(explode(" ",$wd) as $value) { $htmlcode=str_replace($value,"<font background=#FFFF00>".$value."</font>",$htmlcode); }*/ echo $htmlcode; /* $fp=@fopen("www/".str_replace("http://","",$url.".html"),"w") or die("写方式打开文件失败,请检查程序目录是否为可写");//配置conn.php文件 @fputs($fp,$htmlcode) or die("文件写入失败,请检查程序目录是否为可写"); @fclose($fp); */ function replace_html($string) { $pattern = array("'<script[^>]*?>.*?</script>'si", "'<!--[/!]*?[^<>]*?>'si", "'<iframe[^>]*?>.*?</iframe>'si"); $replace = array("", "", ""); return preg_replace($pattern, $replace, $string);
/** * Writes a log message in the database and notify administrator if needed * * @param string $msg Message * @param int $logLevel Log level * @return void */ function write_log($msg, $logLevel = E_USER_WARNING) { if (defined('IMSCP_SETUP')) { return; } $cfg = iMSCP_Registry::get('config'); $clientIp = getIpAddr() ? getIpAddr() : 'unknown'; $msg = replace_html($msg . '<br><small>User IP: ' . $clientIp . '</small>'); exec_query('INSERT INTO `log` (`log_time`,`log_message`) VALUES(NOW(), ?)', $msg); if (!isset($cfg['DEFAULT_ADMIN_ADDRESS']) || $cfg['DEFAULT_ADMIN_ADDRESS'] == '' || $logLevel > $cfg['LOG_LEVEL']) { return; } $msg = strip_tags(preg_replace('/<br\\s*\\/?>/', "\n", $msg)); $hostname = isset($cfg['SERVER_HOSTNAME']) ? $cfg['SERVER_HOSTNAME'] : 'unknown'; $baseServerIp = isset($cfg['BASE_SERVER_PUBLIC_IP']) ? $cfg['BASE_SERVER_PUBLIC_IP'] : 'unknown'; $version = isset($cfg['Version']) ? $cfg['Version'] : 'unknown'; $buildDate = !empty($cfg['BuildDate']) ? $cfg['BuildDate'] : 'unavailable'; $subject = "i-MSCP {$version} on {$hostname} ({$baseServerIp})"; if ($logLevel == E_USER_NOTICE) { $severity = 'Notice (You can ignore this message)'; } elseif ($logLevel == E_USER_WARNING) { $severity = 'Warning'; } elseif ($logLevel == E_USER_ERROR) { $severity = 'Error'; } else { $severity = 'Unknown'; } $message = <<<AUTO_LOG_MSG i-MSCP Log Server : {$hostname} ({$baseServerIp}) Version: {$version} Build : {$buildDate} Message severity: {$severity} Message: ----------------[BEGIN]-------------------------- {$msg} Message: ----------------[END]---------------------------- _________________________ i-MSCP Log Mailer Note: If you want no longer receive messages for this log level, you can change it via the settings page. AUTO_LOG_MSG; $headers = "From: \"i-MSCP Logging Mailer\" <" . $cfg['DEFAULT_ADMIN_ADDRESS'] . ">\n"; $headers .= "MIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\n"; $headers .= "Content-Transfer-Encoding: 7bit\n"; $headers .= "X-Mailer: i-MSCP Mailer"; mail($cfg['DEFAULT_ADMIN_ADDRESS'], $subject, $message, $headers); }