gastenboek-met-xml

Gesponsorde koppelingen

PHP script bestanden

  1. gastenboek-met-xml

« Lees de omschrijving en reacties

[gastenboek.php]

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php

require("functions.php");

?>

<html>
<head>
<script language="javascript" type="text/javascript">
function addText(let) {
   var story = document.gb.bericht.value
   story += let
   document.gb.bericht.value = story
   document.gb.bericht.focus()
}
</script>
</head>
<body>

<h1>Gastenboek</h1>

<?php

if ($_GET["msg"] == 1) {
   $msg = "Succesvol toegevoegd.";
}

elseif ($_GET["msg"] == 2) {
   $msg = "Niet alle velden zijn ingevoerd.";
   $oval = $_GET["ond"];
   $nval = $_GET["naam"];
   $eval = $_GET["email"];
   $bval = $_GET["bericht"];
}


if(isset($msg)) { echo("<font color=\"red\"><b>" . $msg . "</b></font>"); }

?>


<form name="gb" method="post" action="verzenden.php">
<table width="380" border="0">
   <tr>
      <td width="14%"><div align="left"><font face="Verdana" size="2"><b>naam: </b></div></td>
      <td width="86%"><input type="text" name="naam" size="35" value="<?php echo($nval); ?>"></td>
   </tr>
   <tr>
      <td><div align="left"><font face="Verdana" size="2"><B>email: </b></div></td>
      <td><input type="text" name="email" size="35" value="<?php echo($eval); ?>"></td>
   </tr>
   <tr>
      <td><div align="left"><font face="Verdana" size="2"><b>onderwerp: </b></div></td>
      <td><input type="text" name="onderwerp" size="35" value="<?php echo($oval); ?>"></td>
   </tr>
   <tr>
      <td><div align="left"><font face="Verdana" size="2"><b>bericht: </b><br /><br /></div></td>
      <td><textarea name="bericht" cols="26" rows="4"><?php echo($bval); ?></textarea></td>
   </tr>
   <tr>
      <td><div align="left"></div></td>
      <td><input type="submit" value="Teken het gastenboek"></td>
   </tr>
   <tr>
      <td colspan="2">
         <table>
<?php

$x
= 0;
$max = 12;
for ($i = 0; $i < count($GLOBALS["smileys"]); $i++) {
   if($x == 0) { echo("<tr>\n"); }
   echo("<td><a href=\"javascript:addText('" . $GLOBALS["smileys"][$i]["icon"] . "')\"><img src=\"" . $GLOBALS["smileys"][$i]["img"] . "\" border=\"0\"></a></td>\n");
   if($x == $max) { echo("</tr>\n"); }
   $x = $x + 1;
   if ($x > $max) { $x = 0; }
}

for ($i = 0; $x < $max + 1; $i++) {
   echo("<td>&nbsp;</td>\n");
   if($x == $max) { echo("</tr>\n"); }
   $x = $x + 1;
}


?>

         </table>
      </td>
   </tr>
</table>
</form>  

<?php echo(xml2String()); ?>

</body>
</html>

[/gastenboek.php]



[verzenden.php]
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php

require("functions.php");

$email = strip_tags($_POST["email"]);
$naam = strip_tags($_POST["naam"]);
$onderwerp = strip_tags($_POST["onderwerp"]);
$bericht = strip_tags($_POST["bericht"]);
$datum = date("r");
if(!$email || !$naam || !$onderwerp || !$bericht){
header("Location: gastenboek.php?msg=2&email=" . $email . "&ond=" . $onderwerp . "&naam=" . $naam . "&bericht=" . $bericht);
}

else {

$item  = "<item>\n";
$item .= "<subject>" . $onderwerp . "</subject>\n";
$item .= "<date>" . $datum . "</date>\n";
$item .= "<name>" . $naam . "</name>\n";
$item .= "<email>" . $email . "</email>\n";
$item .= "<post>" . $bericht . "</post>\n";
$item .= "</item>\n";

$file = fopen("gastenboek.xml","r");
$al = fread($file, filesize("gastenboek.xml"));
fclose($file);
$al = str_replace("<gastenboek>","",$al);
$al = str_replace("</gastenboek>","",$al);
$txt = "<gastenboek>" . $al . $item . "</gastenboek>";
$file = fopen("gastenboek.xml","w");  
fputs($file,$txt);
fclose($file);
header("Location: gastenboek.php?msg=1");
}

?>

[/verzenden.php]



[functions.php]
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php

global  $smileys;
$smileys = array();
$smileys[] = array("icon" => ":)", "img" => "images/smilies/smile.gif");
$smileys[] = array("icon" => "8|", "img" => "images/smilies/huh.gif");
$smileys[] = array("icon" => ":o", "img" => "images/smilies/ohmy.gif");
$smileys[] = array("icon" => ";)", "img" => "images/smilies/wink.gif");
$smileys[] = array("icon" => ":P", "img" => "images/smilies/tongue.gif");
$smileys[] = array("icon" => ":D", "img" => "images/smilies/biggrin.gif");
$smileys[] = array("icon" => "8)", "img" => "images/smilies/cool.gif");
$smileys[] = array("icon" => "*-)", "img" => "images/smilies/rolleyes.gif");
$smileys[] = array("icon" => ":?", "img" => "images/smilies/dry.gif");
$smileys[] = array("icon" => ":@", "img" => "images/smilies/mad.gif");
$smileys[] = array("icon" => ":(", "img" => "images/smilies/sad.gif");
$smileys[] = array("icon" => "8-)", "img" => "images/smilies/unsure.gif");
$smileys[] = array("icon" => ":|", "img" => "images/smilies/blink.gif");
$smileys[] = array("icon" => "|:-|", "img" => "images/smilies/ph34r.gif");
$smileys[] = array("icon" => ":\\", "img" => "images/smilies/happy.gif");
$smileys[] = array("icon" => "|-)", "img" => "images/smilies/sleep.gif");
$smileys[] = array("icon" => "(l)", "img" => "images/smilies/wub.gif");
$smileys[] = array("icon" => ":s", "img" => "images/smilies/wacko.gif");

function
ubb_code($string) {
 // HTML codes wegwerken
 $string = htmlspecialchars(strip_tags($string));
 // Enters maken
 $string = nl2br($string);
 // Cursief
 $string = preg_replace("#\[i\](.+?)\[/i\]#is","<i>\\1</i>",$string);
 // Onderstreept
 $string = preg_replace("#\[u\](.+?)\[/u\]#is","<u>\\1</u>",$string);
 // Vetgedrukt
 $string = preg_replace("#\[b\](.+?)\[/b\]#is","<b>\\1</b>",$string);
 // Doorstreept
 $string = preg_replace("#\[s\](.+?)\[/s\]#is","<s>\\1</s>",$string);
 // Links maken met behulp van tags
 $string = preg_replace("#\[url\](http|ftp)(.+?)\[/url\]#is","<a href=\"\\1\\2\" target=\"_blank\">\\1\\2</a>",$string);
 $string = preg_replace("#\[url\](mailto:)(.+?)\[/url]#is","<a href=\"\\1\\2\" target=\"_blank\">\\2</a>",$string);
 $string = preg_replace("#\[mail\](.+?)\[/mail]#is","<a href=\"mailto:\\1\" target=\"_blank\">\\1</a>",$string);
 $string = preg_replace("#\[url\](.+?)\[/url\]#is","<a href=\"http://\\1\" target=\"_blank\">\\1</a>",$string);
 $string = preg_replace("#\[url=(http|ftp|mailto)(.+?)\](.+?)\[/url\]#is","<a href=\"\\1\\2\" target=\"_blank\">\\3</a>",$string);
 $string = preg_replace("#\[url=(.+?)\](.+?)\[/url\]#is","<a href=\"http://\\1\" target=\"_blank\">\\2</a>",$string);
 // Automatisch links maken
 $string = eregi_replace("(^|[\n\r\t])((http(s?)://)(www\.)?([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)", "<a href=\"\\2\" target=\"_blank\">\\2</a>",$string);
 $string = eregi_replace("(^|[\n\r\t])((http(s?)://)(www\.)?([a-z0-9_-]+([a-z0-9_-]+)+)(/[^/ \n\r]*)*)", "<a href=\"\\2\" target=\"_blank\">\\2</a>",$string);
 $string = eregi_replace("(^|[\n\r\t])([a-z_-][a-z0-9\._-]*@[a-z0-9_-]+(\.[a-z0-9_-]+)+)","<a href=\"mailto:\\2\" target=\"_blank\">\\2</a>",$string);
 $string = eregi_replace("(^|[\n\r\t])(www\.([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\"http://\\2\" target=\"_blank\">\\2</a>",$string);
 $string = eregi_replace("(^|[\n\r\t])(www\.([a-z0-9_-]+([a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\"http://\\2\" target=\"_blank\">\\2</a>",$string);
 $string = eregi_replace("(^|[\n\r\t])(ftp://([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\"\\2\" target=\"_blank\">\\2</a>",$string);
 $string = eregi_replace("(^|[\n\r\t])(ftp://([a-z0-9_-]+([a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\"\\2\" target=\"_blank\">\\2</a>",$string);
 $string = eregi_replace("(^|[\n\r\t])(ftp\.([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\"\\2\" target=\"_blank\">\\2</a>",$string);
 // Smileys
 for ($i = 0; $i < count($GLOBALS["smileys"]); $i++) {
  $string = str_replace($GLOBALS["smileys"][$i]["icon"],"<img src=\"" . $GLOBALS["smileys"][$i]["img"] . "\" alt=\"Smilie\" />",$string);
 }

 
 // Return
 return $string;
}

function
ubb_back($string) {
 // Cursief
 $string = preg_replace("#<i>(.+?)</i>#is","[i]\\1[/i]",$string);
 // Onderstreept
 $string = preg_replace("#<u>(.+?)</u>#is","[u]\\1[/u]",$string);
 // Vetgedrukt
 $string = preg_replace("#<b>(.+?)</b>#is","[b]\\1[/b]",$string);
 // Doorstreept
 $string = preg_replace("#<s>(.+?)</s>#is","[s]\\1[/s]",$string);
 // Links
 $string = preg_replace("#<a href=\"(http|ftp)(.+?)\" target=\"_blank\">(.+?)</a>#is","[url=\\1\\2]\\3[/url]",$string);
 $string = preg_replace("#<a href=\"mailto:(.+?)\" target=\"_blank\">(.+?)</a>#is","[mail]\\1[/mail]",$string);
 // Smileys
 for ($i = 0; $i < count($GLOBALS["smileys"]); $i++) {
  $string = str_replace("<img src=\"" . $GLOBALS["smileys"][$i]["img"] . "\" alt=\"Smilie\" />",$GLOBALS["smileys"][$i]["icon"],$string);
 }

 
 // Return
 return $string;
}

function
genPost($item) {
   $entry  = "";
   $entry .="<b><font face='Verdana' size='2'>" . $item["subject"] . "</b><br />\n";
   $entry .="<font face='Verdana' size='1'><a href='mailto:" . $item["email"] . "'>" . $item["name"] . "</a> (" . date("d-m-Y H:i", strtotime($item["date"])) . ")<br />\n";
   $entry .="<font face='Verdana' size='2'>" . ubb_code($item["post"]) . "<br />\n";
   $entry .="<img src='images/lijnbericht.gif' border=0><br />\n\n";
   return $entry;
}

function
parseXmlFile($filename, $identifier) {
   $data = implode("",file($filename));
   $parser = xml_parser_create();
   xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
   xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
   xml_parse_into_struct($parser,$data,$values,$tags);
   xml_parser_free($parser);

   foreach ($tags as $key=>$val) {
      if ($key == $identifier) {
         $molranges = $val;
         for ($i=0; $i < count($molranges); $i+=2) {
            $offset = $molranges[$i] + 1;
            $len = $molranges[$i + 1] - $offset;
            $tdb[] = parseArray(array_slice($values, $offset, $len));
         }
      }

      else {
         continue;
      }
   }

   return $tdb;
}
    
function
parseArray($mvalues) {
   for ($i=0; $i < count($mvalues); $i++) {
      $mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];
   }

   return $mol;
}

function
xml2String() {
   $xmlcontent = parseXmlFile("gastenboek.xml", "item");
   $return_str = "";
   foreach ($xmlcontent as $item) {
      $return_str .= genPost($item);
   }

   return $return_str;
}


?>

[/functions.php]



[gastenboek.xml]
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
<gastenboek>
<item>
<subject>eerste post</subject>
<date>Sun, 30 Jan 2005 10:59:02 +0100</date>
<name>legolas</name>
<email>erm...</email>
<post>Dit is de eerste post... mag de admin veranderen naar wat hij daar hebben wil :P</post>
</item>
</gastenboek>

[/gastenboek.xml]

Let op: gastenboek.xml begint zijn leven met een eerste post, het is aan de admin wat er in komt ;).

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.