function getHTML($paras = null){ if (!$paras["key"]){ $paras["key"] = "title"; } $title = $this->get($paras["key"]); if ($paras["maxlength"]){ if (strlen($title) > $paras["maxlength"]){ require_once("knj/functions_knj_strings.php"); $title = trim(knj_strings::substr($title, 0, $paras["maxlength"] - 2)) . "..."; } } return htmlspecialchars($title); }
/** Returns the content of a file. */ function getFile($path, $args = array()){ if ($args["readmode"] == "shell"){ $startstring = md5("[THE START]" . time() . "-" . microtime(true)); $endstring = md5("[THE END]" . time() . "-" . microtime(true)); $commands = "echo " . $startstring . ";"; $commands .= "cat " . $path . ";"; $commands .= "echo " . $endstring . PHP_EOL; fwrite($this->shell, $commands); usleep(450000); while(true){ $new = fgets($this->shell, 4096); $string .= $new; if ($new == $endstring . "\r\n"){ break; } } if (!preg_match("/" . knj_strings::regexsafe($startstring) . "\s\s([\s\S]+)\s\s" . knj_strings::regexsafe($endstring) . "/", $string, $match)){ throw new exception("Could not read result from server."); } $result = $match[1]; if (strpos($result, "cat: command not found") !== false){ throw new exception("cat-command is not supported on that server using that user."); } $notfound_string = "cat: " . $path . ": No such file or directory"; if (strpos($result, $notfound_string) !== false){ throw new exception("File was not found: " . $path); } return $result; }else{ $stream = ssh2_exec($this->conn, "cat " . $path); stream_set_blocking($stream, true); $string = stream_get_contents($stream); } return $string; }
static function utf8force($string){ if (is_array($string)){ foreach($string as $key => $value){ $string[$key] = knj_strings::utf8force($value); } return $string; }else{ $values = array(); $special = array("ø", "æ", "å", "Ø", "Æ", "Å"); foreach($special AS $value){ $values[utf8_decode($value)] = $value; } $string = str_replace("æ", "æ", $string); return strtr($string, $values); } }
function knj_error_reporter_email($msg, $args = array()){ global $knj_error_reporter; $mail_headers = ""; if ($knj_error_reporter["email_from"]){ $mail_headers .= "From: " . $knj_error_reporter["email_from"] . "\r\n"; } $mail_headers .= "Content-Type: text/plain; charset=UTF-8; format=flowed"; if (count($knj_error_reporter["emails"]) > 0){ if ($knj_error_reporter["email_title"]){ $title = $knj_error_reporter["email_title"]; }else{ $title = "Error reported by knj's error reporter"; } require_once "knj/strings.php"; $err_msg = knj_strings::shorten($args["error_msg"], 38); $title = sprintf($title, $err_msg); foreach($knj_error_reporter["emails"] AS $email){ mail($email, $title, $msg, $mail_headers); } } }