function int_esc(&$arg) { if (is_array($arg)) { foreach ($arg as $key => $val) { int_esc($arg[$key]); } } elseif (is_numeric($arg)) { $arg = round($arg); } else { $arg = 0; } return $arg; }
function addComment($entry, $name, $text) { if (!is_dir("data/{$entry}")) { return 0; } $name = preg_replace("/[\r\n]/", "", $name); $num = file_exists("data/{$entry}/ccounter") ? file_get_contents("data/{$entry}/ccounter") : 1; int_esc($num); if ($num <= 0) { $num = 1; } file_put_contents("data/{$entry}/ccounter", $num + 1); file_put_contents("data/{$entry}/comment{$num}", "{$name}\n{$text}"); }