smiley-parser
Index.php:
------------------------
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?
// Vergeet geen database connectie te maken!!
function smilie($text)
{
$db_result = mysql_query("SELECT code, img FROM smilies");
$rows = mysql_num_rows($db_result);
for ($i = 0; $list = mysql_fetch_array($db_result); $i++)
{
$sm_text[$i] = $list['code'];
$image[$i] = "<img src='".$list[img]."' border='0'>";
}
if ($rows > 0)
{
$text = str_replace($sm_text, $image, $text);
}
return $text;
}
$text = "hallo, hoe gaat het! Met mij goed :)";
echo smilie($text);
?>
// Vergeet geen database connectie te maken!!
function smilie($text)
{
$db_result = mysql_query("SELECT code, img FROM smilies");
$rows = mysql_num_rows($db_result);
for ($i = 0; $list = mysql_fetch_array($db_result); $i++)
{
$sm_text[$i] = $list['code'];
$image[$i] = "<img src='".$list[img]."' border='0'>";
}
if ($rows > 0)
{
$text = str_replace($sm_text, $image, $text);
}
return $text;
}
$text = "hallo, hoe gaat het! Met mij goed :)";
echo smilie($text);
?>
admin.php:
-----------------------------
<script type="text/javascript">
<!-- Submit knop Disabelen -->
var doneit;
function disableForm(theform)
{
if (document.all || document.getElementById)
{
if(doneit != 1)
{
for (i = 0; i < theform.length; i++)
{
var tempobj = theform.elements;
if (tempobj.type.toLowerCase() == 'submit' || tempobj.type.toLowerCase() == 'reset')
{
tempobj.style.color = 'gray';
}
}
doneit = 1;
// submit form
return true;
}
else
{
alert('1x klikken is al goed hoor! :D');
return false;
}
}
}
</script>
Hier kunt u smileys toevoegen!<br />
Deze smiley's zijn reeds toegevoegd:<br />
<table>
<form method="post" onsubmit="return disableForm(this)">
<tr>
<td>Smiley:</td>
<td>Code:</td>
<td>Bewerk:</td>
<td>Verwijder:</td>
</tr>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
<?
$query = mysql_query("SELECT * FROM smilies");
while($obj = mysql_fetch_object($query))
{
echo '<tr>';
echo '<td><img src="'.$obj->img.'" alt="Smiley '.$obj->code.'"></td>';
echo '<td>'.$obj->code.'</td>';
echo '<td><a href="admin.php?actie=bewerk&id='.$obj->id.'">Ja</a></td>';
echo '<td><input type="checkbox" name="checkbox[]" value="'.$obj->id.'" /></td>';
echo '</tr>';
}
?>
$query = mysql_query("SELECT * FROM smilies");
while($obj = mysql_fetch_object($query))
{
echo '<tr>';
echo '<td><img src="'.$obj->img.'" alt="Smiley '.$obj->code.'"></td>';
echo '<td>'.$obj->code.'</td>';
echo '<td><a href="admin.php?actie=bewerk&id='.$obj->id.'">Ja</a></td>';
echo '<td><input type="checkbox" name="checkbox[]" value="'.$obj->id.'" /></td>';
echo '</tr>';
}
?>
<tr>
<td></td>
<td></td>
<td></td>
<td align="center"><input type="submit" name="submit" value="verwijder" />
</form>
</table>
<br /><br />
<form method="get" onsubmit="return disableForm(this)">
Smiley's toevoegen:<br />
Voeg <input type="text" value="aantal" name="aantal" /> smileys toe.<br />
<input type="submit" name="actie" value="toevoegen" />
</form>
Code (php)
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
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
<?
}
else
{
$id = $_POST['checkbox'];
$id = count($id);
for($i = 1; $i <= $id; $i++)
{
$nr = $i - 1;
$pid = $_POST['checkbox'][$nr];
mysql_query("DELETE FROM smilies WHERE id = '$pid'");
}
header("Location: admin.php");
}
}
elseif($_GET['actie'] == 'toevoegen')
{
if(!isset($_POST['submit']))
{
if(!isset($_GET['aantal']))
{
$aantal = 1;
}
elseif(empty($_GET['aantal']))
{
$aantal = 1;
}
elseif(!is_numeric($_GET['aantal']))
{
$aantal = 1;
}
elseif($_GET['aantal'] > 15 || $_GET['aantal'] < 1)
{
$aantal = 1;
}
else
{
$aantal = $_GET['aantal'];
}
echo '<table>';
echo '<form method="post" action="admin.php?actie=toevoegen" onsubmit="return disableForm(this)">';
echo '<tr><td>Link:</td><td>Code:</td></tr>';
echo '<input type="hidden" name="aantal" value="'.$aantal.'" />';
for($i = 1; $i <= $aantal; $i++)
{
echo '<tr><td><input type="text" value="smileys/" name="smilie[]" /></td>';
echo '<td><input type="text" name="code[]" /></td></tr>';
}
echo '<tr><td colspan="2" align="center"><input type="submit" value="Voeg Toe" name="submit" /></td></tr>';
echo '</form>';
echo '</table>';
}
else
{
$aantal = $_POST['aantal'];
$error = 0;
for($i = 1; $i <= $aantal; $i++)
{
$nr = $i - 1;
if(!isset($_POST['code'][$nr]) OR empty($_POST['code'][$nr]))
{
$error = 1;
}
elseif(!isset($_POST['smilie'][$nr]) OR empty($_POST['smilie'][$nr]) OR $_POST['smilie'][$nr] == "smileys/")
{
$error = 1;
}
if($error !== 0)
{
break;
}
}
if($error !== 0)
{
echo 'U heeft iets niet ingevuld!<br />Ga terug en verbeter het.';
}
else
{
for($i = 1; $i <= $aantal; $i++)
{
$nr = $i - 1;
$code = $_POST['code'][$nr];
$smilie = $_POST['smilie'][$nr];
mysql_query("INSERT INTO smilies (code,img) VALUES ('$code','$smilie')");
header("Location: admin.php");
}
}
}
}
elseif($_GET['actie'] == 'bewerk')
{
if(!isset($_GET['id']) OR empty($_GET['id']) OR !is_numeric($_GET['id']))
{
echo 'Er ging iets fout met het smiley id, probeer het nog eens.';
}
else
{
if(!isset($_POST['bewerk']))
{
$query = mysql_query("SELECT * FROM smilies WHERE id = '".$_GET['id']."'");
$obj = mysql_fetch_object($query);
$smile = $obj->img;
$code = $obj->code;
echo '<table><tr><td>Smiley:</td><td>Code:</td></tr>';
echo '<form method="post" onsubmit="return disableForm(this)">';
echo '<tr><td><input type="text" name="smile" value="'.$smile.'" /></td>';
echo '<td><input type="text" name="code" value="'.$code.'" /></td></tr>';
echo '<tr><td colspan="2" align="center"><input type="submit" value="bewerk" name="bewerk" /></td>';
echo '</tr></form></table>';
}
else
{
if(empty($_POST['code']) OR empty($_POST['smile']))
{
echo 'Iets is niet goed ingevuld!';
}
else
{
mysql_query("UPDATE smilies SET code = '".$_POST['code']."', img = '".$_POST['smile']."' WHERE id = '".$_GET['id']."'");
header("Location: admin.php");
}
}
}
}
?>
}
else
{
$id = $_POST['checkbox'];
$id = count($id);
for($i = 1; $i <= $id; $i++)
{
$nr = $i - 1;
$pid = $_POST['checkbox'][$nr];
mysql_query("DELETE FROM smilies WHERE id = '$pid'");
}
header("Location: admin.php");
}
}
elseif($_GET['actie'] == 'toevoegen')
{
if(!isset($_POST['submit']))
{
if(!isset($_GET['aantal']))
{
$aantal = 1;
}
elseif(empty($_GET['aantal']))
{
$aantal = 1;
}
elseif(!is_numeric($_GET['aantal']))
{
$aantal = 1;
}
elseif($_GET['aantal'] > 15 || $_GET['aantal'] < 1)
{
$aantal = 1;
}
else
{
$aantal = $_GET['aantal'];
}
echo '<table>';
echo '<form method="post" action="admin.php?actie=toevoegen" onsubmit="return disableForm(this)">';
echo '<tr><td>Link:</td><td>Code:</td></tr>';
echo '<input type="hidden" name="aantal" value="'.$aantal.'" />';
for($i = 1; $i <= $aantal; $i++)
{
echo '<tr><td><input type="text" value="smileys/" name="smilie[]" /></td>';
echo '<td><input type="text" name="code[]" /></td></tr>';
}
echo '<tr><td colspan="2" align="center"><input type="submit" value="Voeg Toe" name="submit" /></td></tr>';
echo '</form>';
echo '</table>';
}
else
{
$aantal = $_POST['aantal'];
$error = 0;
for($i = 1; $i <= $aantal; $i++)
{
$nr = $i - 1;
if(!isset($_POST['code'][$nr]) OR empty($_POST['code'][$nr]))
{
$error = 1;
}
elseif(!isset($_POST['smilie'][$nr]) OR empty($_POST['smilie'][$nr]) OR $_POST['smilie'][$nr] == "smileys/")
{
$error = 1;
}
if($error !== 0)
{
break;
}
}
if($error !== 0)
{
echo 'U heeft iets niet ingevuld!<br />Ga terug en verbeter het.';
}
else
{
for($i = 1; $i <= $aantal; $i++)
{
$nr = $i - 1;
$code = $_POST['code'][$nr];
$smilie = $_POST['smilie'][$nr];
mysql_query("INSERT INTO smilies (code,img) VALUES ('$code','$smilie')");
header("Location: admin.php");
}
}
}
}
elseif($_GET['actie'] == 'bewerk')
{
if(!isset($_GET['id']) OR empty($_GET['id']) OR !is_numeric($_GET['id']))
{
echo 'Er ging iets fout met het smiley id, probeer het nog eens.';
}
else
{
if(!isset($_POST['bewerk']))
{
$query = mysql_query("SELECT * FROM smilies WHERE id = '".$_GET['id']."'");
$obj = mysql_fetch_object($query);
$smile = $obj->img;
$code = $obj->code;
echo '<table><tr><td>Smiley:</td><td>Code:</td></tr>';
echo '<form method="post" onsubmit="return disableForm(this)">';
echo '<tr><td><input type="text" name="smile" value="'.$smile.'" /></td>';
echo '<td><input type="text" name="code" value="'.$code.'" /></td></tr>';
echo '<tr><td colspan="2" align="center"><input type="submit" value="bewerk" name="bewerk" /></td>';
echo '</tr></form></table>';
}
else
{
if(empty($_POST['code']) OR empty($_POST['smile']))
{
echo 'Iets is niet goed ingevuld!';
}
else
{
mysql_query("UPDATE smilies SET code = '".$_POST['code']."', img = '".$_POST['smile']."' WHERE id = '".$_GET['id']."'");
header("Location: admin.php");
}
}
}
}
?>