postit-wall

Gesponsorde koppelingen

PHP script bestanden

  1. postit-wall

« Lees de omschrijving en reacties

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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/*
    PHP / AJAX / JAVASCRIPT / MYSQL Post-it script
    Lars Van Overmeire
    http://www.larsvanovermeire.be
    
    Gebruikers kunnen met dit script een Post-it bericht achterlen op jouw muur.
        Features:
            - AJAX om berichten toe te voegen.
            - Hacker proof
            - Duplicate content beveliging
    
*/


$database['host'] = ''; //MySQL host, meestal localhost
$database['user'] = ''; //username, voorbeeld: root
$database['password'] = ''; //paswoord
$database['name'] = ''; // databasenaam

$maxmessages = 500; // maximum aantal berichten dat geplaatst kan worden, 1000 berichten wil zeggen een pagina van rond de 150kb.
$password = 'clearall'; //Als iemand dit woord of zinnetje plaatst dan worden alle berichten verwijderd. Laat dit leeg om dit uit te schakelen.
/*
    Hieronder niks veranderen tenzij je weet wat je doet!
*/


mysql_connect($database['host'],$database['user'],$database['password']);
mysql_select_db($database['name']);


if(!empty($_POST['x']) && (!empty($_POST['y'])) && (!empty($_POST['text'])))
{

    if(is_numeric($_POST['x']) && is_numeric($_POST['y']) && $_POST['y'] <= 1000 && $_POST['x'] <= 2500)
    {

        if(strlen($_POST['text']) <= 100)
        {

            $f = mysql_query("SELECT * FROM texts WHERE text = '".addslashes($_POST['text'])."'");
            if(mysql_num_rows($f) == 0)
            {

            mysql_query("INSERT INTO texts (id,text,x,y,date) VALUES ('','".htmlspecialchars($_POST['text'])."','".$_POST['x']."','".$_POST['y']."','".time()."')");
                print '0';
            }

            else
            {
                print '1';
            }
        }

        if($_POST['text'] == $password)
        {

            mysql_query('TRUNCATE TABLE texts');
        }
    }

    die(); //executie stopt hier :-)
}
?>

<html>
    <title>Post-it wall</title>
    <head>
        <script type="text/javascript">
        var doNotMove = false; var xNow = 0; var yNow = 0; var submitted = false;
        function placeInputBox(x,y)
        {
            if((!doNotMove) && (!submitted))
            {
                var element = document.getElementById('formBox');
                element.style.left = x+'px';
                element.style.top = y+'px';
                element.style.display = 'inline';
                xNow = x; yNow = y;
            }
            if(submitted)
            {
                submitted = false;
            }
        }
        function limitText(limitField, limitCount, limitNum) //http://www.mediacollege.com/internet/javascript/form/limit-characters.html
        {
            if (limitField.value.length > limitNum)
            {
                limitField.value = limitField.value.substring(0, limitNum);
            } else
            {
                limitCount.value = limitNum - limitField.value.length;
            }
        }

        function createXMLHttpRequest()
        {
            if(window.ActiveXObject)
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if(window.XMLHttpRequest)
            {
                xmlHttp = new XMLHttpRequest();
            }
        }

        function postRequest(data,url)
        {
            createXMLHttpRequest();
            xmlHttp.open("POST", url, true);
            xmlHttp.onreadystatechange = function()
            {
                if(xmlHttp.responseText == "1")
                {
                    document.getElementById('container').innerHTML += "<div class='message' style='left: "+xNow+"px; top: "+yNow+"px;'><font color='red'><b>Je bericht werd niet toegevoegd. Reden:<br /><i>bestaat al</i></b></font></div>";
                }
                else
                {
                    txt = document.getElementById('textField').value.replace(/</g,"&lt;");
                    txt = txt.replace(/>/g,"&gt;");
                    document.getElementById('container').innerHTML += "<div class='message' style='left: "+xNow+"px; top: "+yNow+"px;'>"+txt+"</div>";
                }
                document.getElementById('textField').value = '';
            };
            xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");    
            xmlHttp.send(data);
        }
        
        function placeThing() //document.getElementById('textField').value
        {
            postRequest('x='+escape(xNow)+"&y="+escape(yNow)+"&text="+escape(document.getElementById('textField').value),'index.php');
            submitted = true; doNotMove = false;
            document.getElementById('formBox').style.display = 'none';
        }
        </script>
        
        <style type="text/css">
        #container
        {
                    background:#FFFFFF url(bg.jpg) repeat scroll 0 0;
                    height:100%;
                    margin:0;
                    padding:0;
                    width:100%;
        }
        body
        {
                    background:#FFFFFF url(bg.jpg) repeat scroll 0 0;
                    height:100%;
                    margin:0;
                    padding:0;
                    width:100%;
                    color:#3D4664;
                    font-family: verdana, arial, century gothic;
                    font-size: 10px;
        }
        #formBox
        {
                    background-color:#F6EF88;
                    border:1px dotted #303030;
                    display:none;
                    padding:10px 0;
                    position:absolute;
                    text-align:center;
                    width:200px;
                    height:152px;
        }
        #formBox textarea
        {
                    background-color:#F6EF88;
                    border:1px solid #303030;
        }
        .message
        {
                    background-color:#F6EF88;
                    border:1px dotted #303030;
                    padding:0 3px;
                    position:absolute;
        }
        
        #copyright
        {
            background-color:#F6EF88;
            border:1px dotted #303030;
            padding:2px 3px;
            position:absolute;
            bottom: 2px;
            left: 50%;
            margin-left: -100px;
            width: 200px;
        }
        
        a
        {
            color: #000;
        }
        </style>
    </head>
    <body>
        <div id="container" onClick="placeInputBox(event.clientX,event.clientY);">
        <?php
        $q
= mysql_query('SELECT * FROM texts ORDER BY id ASC LIMIT '.$maxmessages);
        while($res = mysql_fetch_assoc($q))
        {

            print '<div class="message" style="left: '.($res['x']).'px; top: '.($res['y']).'px;">'.wordwrap($res['text'],20,"<br />", true).'</div>'."\n";
        }

        ?>

            <div id="formBox" onMouseOver="doNotMove = true;" onMouseOut="doNotMove = false;">
            <form method="POST" onSubmit="placeThing(); return false;">
                <textarea rows="4" cols="22" id="textField" name="limitedtextarea"  onKeyDown="limitText(this.form.limitedtextarea,this.form.countdown,100);"
onKeyUp="limitText(this.form.limitedtextarea,this.form.countdown,100);" onFocus="if(this.value == 'Your text'){ this.value = '';}">Jouw tekst</textarea>
Je hebt <input readonly type="text" name="countdown" size="3" value="100"> characters over.</font>
                <input type="button" value="Submit" onClick="placeThing();" />
            </form>
            </div>
            <div id="copyright">Post-it &copy; <br><a href="http://www.larsvanovermeire.be">Lars Van Overmeire</a></div>
        </div>
    </body>
</html>

 
 

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.