View file wapirate/wml/notepad.php

File size: 6.46Kb
<?php

// Notepad for WAP  Virtual Cheetah  2003, 2004 - javнtott  (freeware)

header("Content-type: text/vnd.wap.wml");

header("Cache-control: no-cache, must-revalidate");

error_reporting(0);



// Beбllнtбsok:

$max = 100;             // max hбny hozzбszуlбst tбroljon

$block = 3;             // hбny hozzбszуlбst jelenнtsen meg egy oldalon

$prg = "notepad.php";   // a php-fбjl neve (ha esetleg tцbb notepad-ot szeretnйnk egy kцnyvtбrban)

$file = "notepad.tmp";  // az a fбjl, amibe a hozzбszуlбsokat menti

$title = "Vendйgkцny";  // az oldal cнme (title)

$namlng = 20;           // nйv maximбlis hossza (max 255)

$txtlng = 500;          // szцveg maximбlis hossza (max 9999)

$sid = $_GET["sid"];

$usr = $_POST["usr"];

$txt = $_POST["txt"];

$pos = $_GET["pos"];



$brcmd = "<br/>";

function inputstr($txt) {

  $file = "inputchr.dat";

  $handle = fopen($file, "r");

  $n = fread($handle, 3);

  for ($i = 0; $i < $n; $i++) {

    $nn = fread($handle, 1);

    $s = "";

    for ($ii = 0; $ii < $nn; $ii++)

      $s .= chr(fread($handle, 3));

    $c = fread($handle, 1);

    $txt = str_replace($s, $c, $txt);

  }

  fclose($handle);



  $txt = str_replace('\\\\', '\\', $txt);

  $txt = str_replace('\\\'', '\'', $txt);

  $txt = str_replace('\\"', '"', $txt);

  $txt = str_replace(chr(13) . chr(10), chr(1), $txt);

  $txt = str_replace(chr(10), chr(1), $txt);

  $txt = str_replace(chr(13), chr(1), $txt);

  $txt = str_replace("**", chr(1), $txt);

  $txt = str_replace("*A", 'Б', $txt);

  $txt = str_replace("*a", 'б', $txt);

  $txt = str_replace("*E", 'Й', $txt);

  $txt = str_replace("*e", 'й', $txt);

  $txt = str_replace("*I", 'Н', $txt);

  $txt = str_replace("*i", 'н', $txt);

  $txt = str_replace("*O:", 'Ц', $txt);

  $txt = str_replace("*o:", 'ц', $txt);

  $txt = str_replace("*O=", 'Х', $txt);

  $txt = str_replace("*o=", 'х', $txt);

  $txt = str_replace("*O", 'У', $txt);

  $txt = str_replace("*o", 'у', $txt);

  $txt = str_replace("*U:", 'Ь', $txt);

  $txt = str_replace("*u:", 'ь', $txt);

  $txt = str_replace("*U=", 'Ы', $txt);

  $txt = str_replace("*u=", 'ы', $txt);

  $txt = str_replace("*U", 'Ъ', $txt);

  $txt = str_replace("*u", 'ъ', $txt);

  return $txt;

}

function outputusr($s) {

  $s = str_replace("&", '&amp;', $s);

  $s = str_replace("<", '&lt;', $s);

  $s = str_replace(">", '&gt;', $s);

  return $s;

}

function outputstr($s) {

  $s = str_replace("&", '&amp;', $s);

  $s = str_replace("<", '&lt;', $s);

  $s = str_replace(">", '&gt;', $s);

  $s = str_replace(chr(1), $GLOBALS["brcmd"], $s);

  $s = " " . $s;

  $ss = "";

  while ($s != "") {

    if ((strlen($s) >= 8) && (substr($s, 0, 8) == " http://")) {

      $s = substr($s, 1, strlen($s) - 1);

      $lnk = "";

      while (($s != "") && ($s[0] != " ")) {

        $lnk = $lnk . $s[0];

        $s = substr($s, 1, strlen($s) - 1);

      }

      $ss = $ss . " <a href=\"$lnk\">$lnk</a>";

    } else {

      $ss = $ss . $s[0];

      $s = substr($s, 1, strlen($s) - 1);

    }

  }

  $s = substr($ss, 1, strlen($ss) - 1);

  return $s;

}



$tim = time();

echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>

<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">

<wml>

";

if ($sid == "sign") {

  echo "<card title=\"$title\">

<onevent type=\"onenterforward\">

<refresh>

<setvar name=\"txt\" value=\"\"/>

</refresh>

</onevent>

<p>

Nйv:<br/>

<input name=\"usr\" type=\"text\" maxlength=\"$namlng\"/><br/>

Szцveg:<br/>

<input name=\"txt\" type=\"text\" maxlength=\"$txtlng\"/><br/>

<anchor>Hozzбszуl

<go href=\"$prg?t=$tim\" method=\"post\">

<postfield name=\"usr\" value=\"$(usr)\"/>

<postfield name=\"txt\" value=\"$(txt)\"/>

</go>

</anchor>

<br/>

<anchor>Frissнt

<go href=\"$prg?t=$tim&amp;txt=\" method=\"post\">

<postfield name=\"usr\" value=\"$(usr)\"/>

</go>

</anchor>

</p>

</card>

</wml>

";

  exit;

}

if ($pos == NULL)

  $pos = 0;

if ($usr != NULL) {

  $usr = inputstr($usr);

  if (strlen($usr) > $namlng)

    $usr = substr($usr, 0, $namlng - 3) . "...";

}

if ($txt != NULL) {

  $txt = inputstr($txt);

  if (strlen($txt) > $txtlng)

    $txt = substr($txt, 0, $txtlng - 3) . "...";

}

$handle = fopen($file, "r");

$_usr[] = "";

$_tim[] = "";

$_tt[] = "";

$_num[] = "";

$_txt[] = "";

$n = fread($handle, 6) + 0;

for ($i = 0; $i < $n; $i++) {

  $_usr[] = fread($handle, ord(fread($handle, 1)));

  $_tim[] = fread($handle, ord(fread($handle, 1)));

  $_tt[] = fread($handle, ord(fread($handle, 1)));

  $_num[] = fread($handle, ord(fread($handle, 1)));

  $l = fread($handle, 4);

  $_txt[] = fread($handle, $l);

  if ($_usr[$i + 1] == $usr && $_tt[$i + 1] == $t && $_txt[$i + 1] == $txt)

    $txt = NULL;

}

$bg = 1;

fclose($handle);

if ($txt != NULL) {

  if ($n != 0)

    $num = $_num[1] + 1;

  else

    $num = 1;

  $_usr[0] = $usr;

  $_tim[0] = $tim;

  $_tt[0] = $t;

  $_num[0] = $num;

  $_txt[0] = $txt;

  $n++;

  $bg = 0;

  $nn = $n;

  if ($nn > $max)

    $nn = $max;

  $handle = fopen($file, "w");

  $l = $nn;

  while (strlen($l) < 6)

    $l = "0" . $l;

  fwrite($handle, $l);

  for ($i = 0; $i < $nn; $i++) {

    fwrite($handle, chr(strlen($_usr[$i])) . $_usr[$i]);

    fwrite($handle, chr(strlen($_tim[$i])) . $_tim[$i]);

    fwrite($handle, chr(strlen($_tt[$i])) . $_tt[$i]);

    fwrite($handle, chr(strlen($_num[$i])) . $_num[$i]);

    $l = strlen($_txt[$i]);

    while (strlen($l) < 4)

      $l = "0" . $l;

    fwrite($handle, $l . $_txt[$i]);

  }

  fclose($handle);

}

echo "<card title=\"$title\">

<p align=\"center\"><a href=\"$prg?sid=sign\">Hozzбszуlбs</a></p>

<p>

";

if ($n > $max)

  $n = $max;

$p = $bg + $pos;

if ($n == 0)

  echo "Nincs hozzбszуlбs!";

else {

  if ($pos > 0) {

    $i = $pos - $block;

    if ($i < 0)

      $i = 0;

    echo "<a href=\"$prg?usr=$usr&amp;txt=&amp;pos=$i\">&lt;&lt;lapoz</a><br/>\n";

  }

  $i = $block;

  while ($p < $n + $bg && $i > 0) {

    echo "[" . date("m-d H:i", $_tim[$p]) . " $_num[$p].]<br/>\n" . outputusr($_usr[$p]) . ": " . outputstr($_txt[$p]);

    $p++;

    $i--;

    if ($p < $n + $bg && $i > 0)

      echo "<br/>\n";

  }

  if ($p < $n + $bg) {

    $i = $pos + $block;

    echo "</p>

<p align=\"right\">

<a href=\"$prg?usr=$usr&amp;txt=&amp;pos=$i\">lapoz&gt;&gt;</a>

";

  }

}

echo "</p>

</card>

</wml>

";

?>