Posted by admin on May-5-2010 Add Comments

ExpBuilder Float Dialog v2.0 easy popup

Author: Ahmed Elkadery

$(Element).floatdialog(dialog id, options {backgroundcolor, speed, event, effect, move, closeClass} )

To View the Demo click here

Futures:

1- Can Load with page started

2- Can Run sound with starting dialog

3- Can Select the Sound Path

See more Here

The Demo Code:

<div id="loaddialog">

    <a href="javascript:void(0);">X</a>

    <h1>Load Event with sound effect - sample demo</h1>

    <h2>This is a sample demo of the ExpBuilder Float Dialog v2.0</h2>

    <div>

       This is the Load Event with sound effect, It appeare when page is start

       &nbsp;<b><a href="#sampledemoviewsource">Check "sample demo" view Source</a></b>

    </div>

</div>

<script>
$(document).floatdialog("loaddialog", {event: "load", sound: true});
</script>

To Download Click Here

Posted by admin on March-22-2010 Add Comments

Simple chatbox tutorial

Ok, this is going to be a tutorial that will show you how to build the frontend of a PHP/MYSQL based chatbox that has a WYSIWYG built in.

First we need to set up the mySQL database:
We’re going to call this table chatmessages for this tutorial. It needs 5 fields:

ID – Bigint, primary , auto increment
name – varchar 255
IP – varchar 255
postime – bigint
message – I’d say tinytext, but you can do medium text if you want your users to be able to post over 400 chars per post.

The second table is for a list of all ipbans:
IPID – Auto generated IP, primary Auto increment, bigint
IP – varchar 255 – this is where we wil store the actual IP

So you need 3 files for the main chatbox.

1 file we’ll call chatbox.php as the main file to hold the other two frames.

Another file called chatlog.php that will Display the messages and a third file called send.php we’ll use to send the messages.

The later 2 files will be iframes in the first file.
We also need a connect.php file for mySQL database connection:

<?php

$db = mysql_connect("localhost", "username", "password") or die("Could not connect."); //username and password

if(!$db) 

	die("no db");

if(!mysql_select_db("database_name",$db)) //database name

 	die("No database selected.");

if(!get_magic_quotes_gpc())

{

  $_GET = array_map('mysql_real_escape_string', $_GET); 

  $_POST = array_map('mysql_real_escape_string', $_POST); 

  $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);

}

else

{  

   $_GET = array_map('stripslashes', $_GET); 

   $_POST = array_map('stripslashes', $_POST); 

   $_COOKIE = array_map('stripslashes', $_COOKIE);

   $_GET = array_map('mysql_real_escape_string', $_GET); 

   $_POST = array_map('mysql_real_escape_string', $_POST); 

   $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);

}

?>

First we will work on submit.php
<?php

include "connect.php";

if(isset($_POST['submit'])) //if submit button push has been detected

{

   $message=$_POST['message'];

   $name=$_POST['name'];

   if(strlen($message)<1)

   {

      print "You did not input a message";

   }

   else if(strlen($name)<1)

   {

      print "You did not enter a name, please try again.";

   }

   else

   {

      $message=strip_tags($message);

      $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP

      $checkforbanned="SELECT IP from ipbans where IP='$IP'";

      $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS");

      if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list

      {

         print "You IP is banned from posting.";

      }

      else

      {

         $thedate = date("U"); //grab date and time of the post

         $insertmessage="INSERT into chatmessages (name,IP,postime,message) values('$name','$IP','$thedate','$message')";

         mysql_query($insertmessage) or die("Could not insert message");

      }

   }

}

print "<form action='submit.php' method='post' name='form'>";

print "Your name:<br>";

print "<input type='text' name='name' size='20'><br>";

print "Your message:<br>";

print "<textarea name='message' cols='40' rows='2'></textarea><br>";

print "<a onClick=\"addSmiley(':)')\"><img src='images/smile.gif'></a> "; //replace images/smile.gif with the relative path of your smiley

print "<a onClick=\"addSmiley(':(')\"><img src='images/sad.gif'></a> ";

print "<a onClick=\"addSmiley(';)')\"><img src='images/wink.gif'></a> ";

print "<input type='submit' name='submit' value='submit'></form>";

print "<script language=\"Java Script\" type=\"text/javascript\">\n";

print "function addSmiley(textToAdd)\n";

print "{\n";

print "document.form.message.value += textToAdd;";

print "document.form.message.focus();\n";

print "}\n";

print "</script>\n";

print "<br><br>";

?> 

This is the file that will submit a user's message into th database. At  the bottom you see the form that asks for your poster's name and
 the message he wants to post. The onclick and following javascript  function allows for clickable smilies. If you want more, simple add more  smilies in and copy and paste more:
print "<a onClick=\"addSmiley(':(')\"><img src='images/sad.gif'></a> ";

lines in, change the :(  into the character you want for your smiley and  the image path to the image path of your smiley.
 The code that comes in the:
if(isset($_POST['submit'])) //if submit button push has been detected

{

case is basically validation code for message, it checks to make sure  the poster's name and message is at least 1 character long  and if it  isn't, it doesn't post and gives an error message telling them that one  of the required fields is not valid. Next it gets the poster's posting  IP with the $_SERVER["REMOTE_ADDR"] function and checks that IP against  the table of banned IP with $checkforbanned. If the IP is found in the  list of banned IPS, it throws an error message saying that your IP is  banned and does not post the message. Finally, if all the conditions are  met, it grabs the current unix timestamp wth $date("U") and posts all  the information into the message database.

 Now lets look at chatlog.php, the file that displays the messages, the  newest messages will be posted at the bottom:
<?php

include "connect.php";

$getnummessages="SELECT COUNT(*) as messagecount from chatmessages";

$getnummessages2=mysql_query($getnummessages) or die("blah");

$getnummessages3= mysql_result($getnummessages2, 0);

if($getnummessages3>21)

{

   $startrow=$getmessages3-20;

}

else

{

  $startrow=1;

}

$getmsg="SELECT name, message from chatmessages order by postime ASC limit $startrow,$getnummessages3";

$getmsg2=mysql_query($getmsg) or die(mysql_error());

while($getmsg3=mysql_fetch_array($getmsg2))

{

  $message=Smiley($message); //Smiley faces

   print "<font color='red'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>";

}

function Smiley($texttoreplace)

{

    $smilies=array( 

    ':)' => "<img src='images/smile.gif'>",

    ':blush' =>"<img src='images/blush.gif'>",

    ':angry' =>"<img src='images/angry.gif'>",

    ':o'=>     "<img src='images/shocked.gif'>",  

    'fuck'=>"$#$%",

    'Fuck'=>"&$#@"

    );

    $texttoreplace=str_replace(array_keys($smilies), array_values($smilies), $texttoreplace);

    return $texttoreplace;

}

?>

<script>

  setTimeout("window.location.replace('chatlog.php')",2000);

</script>

Basically , this first counts the number of messages there are in the  database first, then subtracts 20 from that number and stored that value  in $startrow.
 Then we grab all the messages from $startrow to the last message in the  database and look through the array to display the 20 messages, with the  latest message at the bottom. The smilies function replaces the smiley  characters with the actual smiley images, not that this can also be used  as a bad words
 filter. The last line simply refreshes the page automatically every 2  seconds, so that new messags will automatically come up, just like a  real chatroom.

 Now we can look at chatframe.php which is a simple page with two iframes  to hold the submit page and the chatlog page.

 chatframe.php
<?

print "<iframe src='chatlog.php'  name='chatlogframe' width='350' height='400'></iframe>";

print "<br><br>";

print "<iframe src='submit.php' width='350' height='150' frameborder='0'></iframe><br><br>";

?>

There's really nothing to this file, just two iframes to hold the other  two files.

 The next post will be the admin files.
Posted by admin on March-22-2010 Add Comments

AJAX Multi-Level Comments

In this tutorial we will create multi level comments. You must have seen comments on youtube and that they have levels depending on who replied to who. That’s exactly what we will build.

Intro Top

I’ve seen that most of scripts online execute query to check if comment has child elements. Let’s say you have 10 comments and each of them has 1 child element. You would execute 1 query to get all those 10 comment (first level) and then for each of them to check if it has child. And then for each child to check if that comment has childs to. That would be 1 + 10 + 10 = 21. That’s 21 query for nothing. It’s easier to do it with just one query that will load all comments and then to structure them in an multidimensional array. For that purpose we will use walker class that you can download here and read tutorial how we made it here. So let’s start working on it.

Folder Structure Top

Folder structure is very simple. jQuery folder has jQuery v1.3.2. We have two image files used for loader and to style comments. In our lib folder we have walker class that I mentioned before and we have some php file that we’ll later talk about.

Muti Level Comments Folder StructureMuti Level Comments Folder Structure

MySQL Table Top

We’ll have very simple MySQL table. Table will have 7 fields.

  • id – unique ID
  • name – name of comment author
  • email – e-mail of comment author
  • url – url of comment author (optional)
  • parent – ID of parent comment (if no parent then equals to 0)
  • date – date that comment was posted
  • message – comment message
01.CREATE TABLE IF NOT EXISTS `comments_tutor` (
02. `id` int(11) NOT NULL AUTO_INCREMENT,
03. `name` varchar(128) COLLATE utf8_bin NOT NULL,
04. `email` varchar(255) COLLATE utf8_bin NOT NULL,
05. `url` varchar(255) COLLATE utf8_bin NOT NULL,
06. `parent` int(11) NOT NULL DEFAULT '0',
07. `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
08. `message` text COLLATE utf8_bin NOT NULL,
09. PRIMARY KEY (`id`)
10.) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;

Html And Css Top

Now we’ll do some html and css. I won’t explan what I’ve done here. There are many good css and html tutorial on net.

main.css Top

This is content of main.css file.

001.@CHARSET "UTF-8";
002.
003.body {
004. background-color: #f0f0f0;
005.}
006.
007.#wrapper {
008. margin: 100px auto;
009. width: 600px;
010.}
011.
012.#message {
013. margin-bottom: 15px;
014.}
015.
016.#waiting {
017. color: #767676;
018. text-align: center;
019.}
020.
021..success {
022. background: #a5e283;
023. border: #337f09 1px solid;
024. padding: 5px;
025.}
026.
027..error {
028. background: #ea7e7e;
029. border: #a71010 1px solid;
030. padding: 5px;
031.}
032.
033./* Form */
034.
035.#form fieldset {
036. border: none;
037.}
038.
039.#form legend {
040. font-weight: bold;
041.}
042.
043.#form label {
044. display: inline-block;
045. width: 70px;
046. vertical-align: top;
047. padding-top: 1px;
048.}
049.
050.#form .text, #form textarea {
051. width: 300px;
052.}
053.
054.#form textarea {
055. height: 100px;
056.}
057.
058.#form .required {
059. color: red;
060. font-weight: bold;
061.}
062.
063./* Comments */
064.
065.#comments ul {
066. margin: 0px;
067. padding: 0px;
068.}
069.
070.#comments li {
071. list-style: none;
072.}
073.
074.#comments .commentWrap p {
075. margin: 0px;
076. padding: 0px;
077.}
078.
079.#comments .userTime {
080. color: #777575;
081.}
082.
083.#comments li ul {
084. margin: 0px;
085. padding: 0px;
086.}
087.
088.#comments li ul {
089. border-left: 1px solid #ced0d0;
090.}
091.
092.#comments li li {
093. background: url('images/connect.gif') no-repeat transparent 0px 25px;
094. padding-left: 25px;
095.}
096.
097.#comments .commentWrap {
098. border: solid 1px #ccc;
099. padding: 10px;
100. margin: 7px 7px 7px 0px;
101. background-color: #f2f2f2;
102.}
103.
104.#comments li li .commentWrap {
105. background-color: #e6e4e4;
106.}
107.
108.#comments p.message {
109. margin-top: 13px;
110. margin-bottom: 15px;
111.}

index.php Top

This is source of index.php file.

01.< ?php
02./**
03. * @author Marijan Šuflaj <msufflaj32@gmail.com>
05. */
06.?>
07.< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
10. <head>
11. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
12. <title>Multilevel Comments</title>
13. <link href="css/main.css" type="text/css" media="screen, projection" rel="stylesheet" />
14. </head>
15.
16. <body>
17. <div id="wrapper">
18. <div id="message" style="display: none;">
19. </div>
20. <div id="waiting" style="display: none;">
21. Please wait<br />
22. <img src="images/ajax-loader.gif" title="Loader" alt="Loader" />
23. </div>
24. <div id="form">
25. <fieldset>
26. <legend>Write your comment</legend>
27. <p>
28. <label for="name"><span class="required">*</span> Name:</label>
29. <input type="text" name="name" class="text" id="name" />
30. </p>
31. <p>
32. <label for="email"><span class="required">*</span> E-mail:</label>
33. <input type="text" name="email" class="text" id="email" />
34. </p>
35. <p>
36. <label for="url">Url:</label>
37. <input type="text" name="url" class="text" id="url" />
38. </p>
39. <p>
40. <label for="msg"><span class="required">*</span> Message:</label>
41. <textarea rows="1" cols="1" id="msg" name="msg"></textarea>
42. </p>
43. <p>
44. <input type="hidden" name="parent" id="parent" value="0" />
45. <input type="button" name="submit" id="submit" value="Post" />
46. </p>
47. </fieldset>
48. </div>
49. <div id="comments">
50. </div>
51. </div>
52. <script type="text/javascript" src="js/jquery/jquery-1.3.2.js"></script>
53. <script type="text/javascript" src="js/ajaxSubmit.js"></script>
54. </body>
55.</html>

AJAX And Javascript Top

Now we will build JavaScript and add Ajax support. As you all know, when using jQuery you have to write your code when DOM is loaded like this. We’ll also add variable ajax that will disable making new AJAX call while there is still one active.

1.$(document).ready(function(){
2.
3. ajax = false;
4.
5. [...]
6.
7.});

When we have this, we’ll write our code for AJAX. After our variable we’ll call function loadComments() that will load comment from our database using AJAX (we’ll create this function next).

So, this will be our function that will load comment from server. For more details about AJAX and what we did you can find here. This is code for function (paste it outside of upper part of code).

01.function loadComments()
02.{
03.
04. $('#waiting').show(500);
05. $('#message').hide(0);
06.
07. ajax = true;
08.
09. $.ajax({
10. 'type' : 'POST',
11. 'url' : 'comments.php',
12. 'dataType' : 'html',
13. 'data' : {},
14. 'success' : function(data){
15. $('#waiting').hide(500);
16. $('#comments').html(data);
17. },
18. 'error' : function(XMLHttpRequest, textStatus, errorThrown) {
19. $('#waiting').hide(500);
20. $('#message').removeClass().addClass('error')
21. .text('There was an error.').show(500);
22. }
23. });
24.
25. ajax = false;
26.}

Now we’ll create event listeners for two actions:

  1. when user clicks on `Reply` link
  2. when user submits comment.

Event Listeners For `Reply` Link Top

This listeners calls function that check if comment exists. If comment does not exist, user can not make a reply to this comment. If comment exists, AJAX returns name of comment author that we use to construct string `Write reply to comment posted by %name%` where %name% is name returned from AJAX.

First we check if we are in AJAX, and if we are, we just return false. If we are not, then we do AJAX call. This is event listener.

01.$('.replayLink').live('click', function() {
02.
03. if (ajax)
04. return false;
05.
06. $('#waiting').show(500);
07. $('#demoForm').hide(0);
08. $('#message').hide(0);
09.
10. ajax = true;
11.
12. $.ajax({
13. 'type' : 'POST',
14. 'url' : $(this).attr('href'),
15. 'dataType' : 'json',
16. 'data' : {
17. 'type' : 'reply'
18. },
19. 'success' : function(data){
20. $('#waiting').hide(500);
21. if (data.error === true)
22. $('#message').removeClass().addClass('error')
23. .text(data.msg).show(500);
24. else {
25. $('#form legend').text('Write reply to comment posted by ' + data.name + '.');
26. $('#parent').val(data.id);
27. }
28. },
29. 'error' : function(XMLHttpRequest, textStatus, errorThrown) {
30. $('#waiting').hide(500);
31. $('#message').removeClass().addClass('error')
32. .text('There was an error.').show(500);
33. $('#demoForm').show(500);
34. }
35. });
36.
37. ajax = false;
38.
39. return false;
40.});

Event Listener For Comment Submitting Top

This listener submits form to PHP file on server if there is no AJAX running.

01.$('#submit').click(function() {
02.
03. if (ajax)
04. return false;
05.
06. $('#waiting').show(500);
07. $('#demoForm').hide(0);
08. $('#message').hide(0);
09.
10. ajax = true;
11.
12. $.ajax({
13. 'type' : 'POST',
14. 'url' : 'post.php',
15. 'dataType' : 'json',
16. 'data' : {
17. 'type' : 'post',
18. 'name' : $('#name').val(),
19. 'email' : $('#email').val(),
20. 'url' : $('#url').val(),
21. 'msg' : $('#msg').val(),
22. 'parent' : $('#parent').val()
23. },
24. 'success' : function(data){
25. $('#waiting').hide(500);
26. $('#message').removeClass().addClass((data.error === true) ? 'error' : 'success')
27. .text(data.msg).show(500);
28.
29. if (data.error === false) {
30. ajax = false;
31. loadComments();
32. }
33. },
34. 'error' : function(XMLHttpRequest, textStatus, errorThrown) {
35. $('#waiting').hide(500);
36. $('#message').removeClass().addClass('error')
37. .text('There was an error.').show(500);
38. $('#demoForm').show(500);
39. }
40. });
41.
42. ajax = false;
43.
44. return false;
45.});

PHP

Now we’ll do PHP part. This part generates comments and saves them. First we need to create db.php file. It’s just simple connection to database.

1.$con = mysql_connect('localhost', 'root', '');
2.mysql_select_db('tutoriali', $con);

Now we’ll do other parts as well.

Generating Comments Top

For this purpose we’ll use my walker class that you can get here.

First we have to include db.php and walker.php in our file.

1.require_once './db.php';
2.require_once './lib/walker.php';

Now we will create commentWalker class that will extend walker class. We will use this class to style our comments.

1.class commentWalker extends walker {
2.
3. [...]
4.
5.}

Now we’ll create function buildComments() that will be used to build comments. First we check if passed comments are null and if they are we use comments from parent class. If count of comments is less then one, then we echo message  There are no comments to display. to buffer and return it. If there are comments, then we start building them. We just go through each comment and if it has child elements, we just call this function again. We also increment $lv by 1 to make comments flat at certain level. At end we just return what we’ve build.

01.function buildComments($comments = null, $lv = 0)
02.{
03.
04. if (is_null($comments))
05. $comments = $this->_traced;
06.
07. if (count($comments) < 1) {
08.
09. ob_start();
10.?>
11.There are no comments to display.
12.< ?php
13. return ob_get_clean();
14. }
15.
16. $lv += 1;
17.
18. $commentHtml = '';
19.
20. if ($lv <= 3)
21. $commentHtml .= '<ul>';
22.
23. foreach ($comments as $comment) {
24.
25. ob_start();
26.?>
27.<div class="commentWrap">
28. <p class="userTime">User < ?php if (!empty($comment->self->url)) : ?>
29. <a href="<?php echo $comment->self->url; ?>">< ?php echo $comment->self->name; ?></a>
30. < ?php else : echo $comment->self->name; endif; ?> wrote on < ?php echo date('F, j Y', $comment->self->date); ?>
31. in < ?php echo date('g:i a', $comment->self->date); ?>
32.</p>
33.<p class="message">
34. < ?php echo $comment->self->message; ?>
35.</p>
36.<p>
37. <a href="http://tutoriali/multiLevelComments/post.php?id=<;?php echo $comment->self->id; ?>" class="replayLink">Reply</a>
38.</p>
39.</div>
40.< ?php
41. $html = ob_get_clean();
42.
43. if (!empty($comment->childs)) {
44. $commentHtml .= '<li>';
45. $commentHtml .= $html;
46. $commentHtml .= $this->buildComments($comment->childs, $lv);
47. $commentHtml .= '</li>';
48. }
49. else {
50. $commentHtml .= '<li>';
51. $commentHtml .= $html;
52. $commentHtml .= '</li>';
53. }
54. }
55. if ($lv < = 3)
56. $commentHtml .= '</ul>';
57.
58. return $commentHtml;
59.}

At the end we just have to create SQL query that will pull data from database and call this class and its functions.

1.$sql = 'SELECT `id`, `name`, `url`, `message`, `parent`, UNIX_TIMESTAMP(`date`) '
2.. 'AS `date` '
3.. 'FROM `comments_tutor` '
4.. 'ORDER BY `date`';
5.
6.$comments = new commentWalker($con);
7.echo $comments->loadResults($sql)->trace()->buildComments();

Saving Comments And AJAX Top

Here we have to require db.php. This will be fairly simple file. We’ll just check what kind of request are we doing and check data if they need to be checked. There is really noting complicated. We’ll use a variable $response to save response data and at the end echo it in JSON format.

001.require_once './db.php';
002.
003.$response = array(
004. 'error' => true,
005. 'msg' => ''
006.);
007.
008.while (true) {
009.
010. if (!isset($_POST['type'])) {
011. $response['msg'] = 'You did not provide type.';
012. break;
013. }
014.
015. switch ($_POST['type']) {
016. case 'reply' :
017.
018. if (!isset($_GET['id'])) {
019. $response['msg'] = 'You did not provide comment ID.';
020. break 2;
021. }
022.
023. $sql = 'SELECT `name`, `id` '
024. . 'FROM `comments_tutor` '
025. . 'WHERE `id` = %d '
026. . 'LIMIT 1';
027.
028. if (($result = mysql_query(sprintf($sql, $_GET['id']), $con)) === false) {
029. $response['msg'] = 'Could not retrieve comment author.';
030. break 2;
031. }
032.
033. if (mysql_num_rows($result) < 1) {
034. $response['msg'] = sprintf('There is not comment with ID `%s`.', $_GET['id']);
035. break 2;
036. }
037.
038. $name = mysql_fetch_object($result);
039.
040. $response['name'] = $name->name;
041. $response['id'] = $name->id;
042.
043. break;
044.
045. case 'post' :
046.
047. if (!isset($_POST['name'])) {
048. $response['msg'] = 'You did not provide name.';
049. break 2;
050. }
051.
052. if (!isset($_POST['email'])) {
053. $response['msg'] = 'You did not provide e-mail.';
054. break 2;
055. }
056.
057. if (!isset($_POST['url'])) {
058. $response['msg'] = 'You did not provide url.';
059. break 2;
060. }
061.
062. if (!isset($_POST['msg'])) {
063. $response['msg'] = 'You did not provide message.';
064. break 2;
065. }
066.
067. if (!isset($_POST['parent'])) {
068. $response['msg'] = 'You did not provide comment ID.';
069. break 2;
070. }
071.
072. if (!preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/', $_POST['email'])) {
073. $response['msg'] = 'E-mail not valid.';
074. break 2;
075. }
076.
077. if (!empty($_POST['url']) && !preg_match('#^((http|ftp|https)\:\/\/)(www\.)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?$#i', $_POST['url'])) {
078. $response['msg'] = 'Url not valid.';
079. break 2;
080. }
081.
082. if ($_POST['parent'] > 0) {
083. $sql = 'SELECT `id` '
084. . 'FROM `comments_tutor` '
085. . 'WHERE `id` = %d '
086. . 'LIMIT 1';
087.
088. if (($result = mysql_query(sprintf($sql, $_POST['parent']), $con)) === false) {
089. $response['msg'] = 'Could not check if comment exists.';
090. break 2;
091. }
092.
093. if (mysql_num_rows($result) < 1) {
094. $response['msg'] = sprintf('There is not comment with ID `%s`.', $_POST['parent']);
095. break 2;
096. }
097. }
098.
099. $sql = 'INSERT INTO `comments_tutor` ( '
100. . '`name`, `email`, `url`, `parent`, `message`'
101. . ') VALUES ( '
102. . "'%s', '%s', '%s', %d, '%s'"
103. . ')';
104.
105. if (mysql_query(sprintf(
106. $sql,
107. mysql_real_escape_string($_POST['name']),
108. mysql_real_escape_string($_POST['email']),
109. mysql_real_escape_string($_POST['url']),
110. $_POST['parent'],
111. mysql_real_escape_string($_POST['msg'])
112. )) === false) {
113. $response['msg'] = 'Could not insert comment.';
114. break 2;
115. }
116.
117. break;
118.
119. default :
120. $response['msg'] = 'Invalid type.';
121. break 2;
122. }
123.
124. $response['error'] = false;
125. $response['msg'] = 'Comment saved.';
126.
127. break;
128.}
129.
130.echo json_encode($response);
Posted by admin on January-11-2010 Add Comments

How To Detect Internet Explorer Version With PHP

Awhile ago I needed to detect the Internet Explorer version of the visitor from inside of my PHP script. Being lazy I just tried to Google for some existing code, but to my surprise there was none available! Well, I think it’s time to rectify that problem by publishing the code I ended up creating. The ieversion() function looks at the HTTP_USER_AGENT header sent by the browser to determine if the visitor is using Internet Explorer. If not, then the script will return -1. If yes, then the script will extract the version number and return that.

function ieversion() {
  ereg('MSIE ([0-9]\.[0-9])',$_SERVER['HTTP_USER_AGENT'],$reg);
  if(!isset($reg[1])) {
    return -1;
  } else {
    return floatval($reg[1]);
  }
}

What are the uses for this? You can do what I do and display a message notifying the visitor that he is using an outdated browser and he should upgrade to Firefox by clicking the Google Referal ad below. That solves two problems: Helps to pay the bills and I don’t have to make sure my site renders properly on the ancient Internet Explorer 6 (I let IE7 users get by, it does a pretty good job). I will publish the simple code I use for this later on.

Posted by admin on December-11-2009 Add Comments

Free Ads Manager Script in PHP

Free Ads Manager Script in PHP Powered by Expbuilder.com

Introduction

This can let your visitors add the ads without register, there are 2 types of ads:
1- free ads
2- premium ads

you have the full control from admin control panel, like allow, deny or delete.
Also you can make the ads active with client mail (activation mail)

Demo
To see the demo of script:
http://www.expbuilder.com/testpages/ads/index.php

install
1- unzip the ads.zip file and upload all files
2- run install.php file ex: www.yoursitename.com/install.php
3- set your database and server information
4- installing…
5- done

Download
the script is free, you can download it from here:
http://www.ziddu.com/download/7275637/ads.zip.html

thanks for choosing Expbuilder Ads Manager

Posted by admin on December-11-2009 Add Comments

JQuery Help Tooltip v1.0

JQuery Help Tooltip v1.0

HTML Code:
$(Element).helptooltip();

Demo: http://www.expbuilder.com/testpages/helptooltip/

Code:

HTML Code:
<span class="helps">
Click this help icon to test the help tooltip
</span>
<span><b>What is this ?</b> <br /> this is a test of JQuery Help Tooltip v1.0
<hr /> You can type any thing here !!</span>

</div>
<script type="text/javascript">
$(document).ready(function()
{
     $(".helps").helptooltip();
});
</script>

tested and working with all browsers

Download JQuery Help Tooltip v1.0

1- Download jQuery JavaScript Library – jquery-1.3.2.min.js
2- JQuery Help Tooltip v1.0 – jquery.helptooltip.zip

JQuery Help Tooltip v1.0 SetUp

A. Head Tag

Import files:

HTML Code:
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery.helptooltip.js"></script>
<link href="jquery.helptooltip.css" rel="stylesheet" type="text/css" />

B. Body Tag

HTML & JavaScript Code:

HTML Code:
<span class="helps">
Click this help icon to test the help tooltip
</span>
<span><b>What is this ?</b> <br /> this is a test of JQuery Help Tooltip v1.0
<hr /> You can type any thing here !!</span>

</div>
<script type="text/javascript">
$(document).ready(function()
{
     $(".helps").helptooltip();
});
</script>

Posted by admin on December-11-2009 Add Comments

JQuery Easy Tooltip v2.0

JQuery Easy Tooltip v2.0

HTML Code:
$(Element).easytooltip(Formid, options{backgroundcolor, border, color, event})

Demo: http://www.expbuilder.com/testpages/easytooltip2/

To see the last version (1.0) goto: http://www.expbuilder.com/vb/showthread.php?t=2

HTML Code:

HTML Code:
<style type="text/css">

.bg
        {
           background-image: url(bg.jpg);
           width: 275px;
           height: 135px;
           padding: 22px 55px 20px 55px;
           background-repeat: no-repeat;
           background-position: left top;
        }

</style>

<a class="demo" href="javascript:void(0);">
Move your mouse point here to see what JQuery Easy Tooltip can do !!
</a>

</div>
<div id="formdisplay" style="display: none;padding: 20px;width: 500px;">

   <div class="bg">
         <h2>This is a Demo of Easy Tooltip</h2>
        you can but any thing you want here
   </div>
</div>

javascript Code:

HTML Code:
<script>
$(document).ready(function()
{
    $(".demo").easytooltip("formdisplay", {backgroundcolor: "transparent", border: "0px"});
});
</script>

Demo – Default

HTML Code:
<a class="demo" href="javascript:void(0);">
Move your mouse point here to see what JQuery Easy Tooltip can do !!
</a>

</div>
<div id="formdisplay" style="display: none;padding: 20px;width: 500px;">

   <div class="bg">
         <h2>This is a Demo of Easy Tooltip</h2>
        you can but any thing you want here
   </div>
</div>

<script>
$(document).ready(function()
{
    $(".demo").easytooltip("formdisplay", {backgroundcolor: "transparent", border: "0px"});
});
</script>

Change background Color – backgroundcolor

HTML Code:
<div id="formdisplay2" style="display: none;padding: 20px;width: 500px;">
         <h2>This is a Demo of Easy Tooltip</h2>
        you can but any thing you want here
</div>
<a id="demo2" href="javascript:void(0);">check background color !! </a>

<script type="text/javascript">
$("#demo2").easytooltip("formdisplay2", {backgroundcolor: "#3399FF"});
</script>

Change border

HTML Code:
<div id="formdisplay3" style="display: none;padding: 20px;width: 500px;">
         <h2>This is a Demo of Easy Tooltip</h2>
        you can but any thing you want here
</div>
<a id="demo3" href="javascript:void(0);">check border !! </a>

<script type="text/javascript">
$("#demo3").easytooltip("formdisplay3", {border: "6px solid #3399FF"});
</script>

Change Font Color

HTML Code:
<div id="formdisplay4" style="display: none;padding: 20px;width: 500px;">
         <h2>This is a Demo of Easy Tooltip</h2>
        you can but any thing you want here
</div>

<a id="demo4" href="javascript:void(0);">check Font Color !! </a>

<script type="text/javascript">
$("#demo4").easytooltip("formdisplay4", {color: "red"});

</script>

Change Mouse event

HTML Code:
<div id="formdisplay5" style="display: none;padding: 20px;width: 500px;">
         <h2>This is a Demo of Easy Tooltip</h2>
        you can but any thing you want here
</div>

<a id="demo5" href="javascript:void(0);">click here to check Mouse event !! </a>

<script type="text/javascript">
$("#demo5").easytooltip("formdisplay5", {event: "click"});

</script>

Download JQuery Easy Tooltip v2.0

1- Download jQuery JavaScript Library – jquery-1.3.2.min.js
2- JQuery Easy Tooltip v2.0 – easytooltip2.0.zip

Download this demo

- easytooltip2.0.package.zip

JQuery Easy Tooltip v2.0 SetUp

A. Head Tag

Import files:

HTML Code:
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="easytooltip.js"></script>

B. Body Tag

HTML & JavaScript Code:

HTML Code:
<div id="formdisplay"
style="display: none;padding: 20px;background-color: #ffffff;border: 3px solid #000;width: 500px;">
    <h2>This is a Demo of Easy Tooltip</h2>
    you can but any thing you want here
</div>

<script>
$(document).ready(function()
{
    $(".demo").easytooltip("formdisplay");
});
</script>
Posted by admin on December-11-2009 Add Comments

JQuery Esay Tooltip v1.0

JQuery Esay Tooltip v1.0

Code:
$(Element).easytooltip(formid)

Demo: http://www.expbuilder.com/testpages/easytooltip/

To see the version 2.0 goto: http://www.expbuilder.com/vb/showthread.php?t=3

Code:

HTML Code:
<div id="formdisplay"

style="display: none;padding: 20px;background-color: #ffffff;border: 3px solid #000;width: 500px;">

    <h2>This is a Demo of Esay Tooltip</h2>

    you can but any thing you want here

</div>
HTML Code:
<script>

$(document).ready(function()

{

    $(".demo").easytooltip("formdisplay");

});

</script>

Download JQuery Esay Tooltip v1.0

1- Download jQuery JavaScript Library – jquery-1.3.2.min.js
2- JQuery Esay Tooltip v1.0 – easytooltip.zip
Download this demo

- easytooltip.package.zip

JQuery Esay Tooltip v1.0 SetUp

A. Head Tag

Import files:

HTML Code:
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>

<script type="text/javascript" src="easytooltip.js"></script>

B. Body Tag

HTML & JavaScript Code:

HTML Code:
<div id="formdisplay"

style="display: none;padding: 20px;background-color: #ffffff;border: 3px solid #000;width: 500px;">

    <h2>This is a Demo of Esay Tooltip</h2>

    you can but any thing you want here

</div>

<script>

$(document).ready(function()

{

    $(".demo").easytooltip("formdisplay");

});

</script>

Posted by admin on December-11-2009 Add Comments

JQuery Float Dialog v1.0

JQuery Float Dialog v1.0
Easy PopUp
Author: Ahmed Elkadery
Code:
$(Element).floatdialog(dialog id, options {backgroundcolor, speed, event, effect, move, closeClass} )

To Ses the Demo: http://www.expbuilder.com/testpages/floatdialog/

Explain:
Demo 1 – Default use

HTML Code:

Code:
<a id="demo1" href="javascript :void(0);">Clicking Here</a>

<div id="dialog1">

    <a href="javascript :void(0);">X</a>

    <h1>Demo1 - Default use</h1>

    <h2>This is a demo of the JQuery Float Dialog v1.0</h2>

    <div>

       this is the default use, you can do this demo by your self !

       &nbsp;<b><a href="#demo1viewsource">Check demo1 view Source</a></b>

    </div>

</div>

Javascipt Code:

Code:
<script>

    $("#demo1").floatdialog("dialog1");

</script>

Demo 2 – Options

1- move

[ default - down - up - left - right - slidedown ]
HTML Code:

Code:
<a id="demo2" href="javascript :void(0);">Slide down</a>

<div id="dialog2">

    <a href="javascript :void(0);">X</a>

    <h1>Demo2 - Options - slide Down</h1>

    <h2>This is a demo of the JQuery Float Dialog v1.0</h2>

    <div>

       you can make the box is slide down .. also can make it slide up, left and right

       &nbsp;<b><a href="#demo2viewsource">Check demo2 view Source</a></b>

    </div>

</div>

Javascipt Code

Code:
<script>

    $("#demo2").floatdialog("dialog2", {move: 'down'});

</script>

2- effect

[ true - false ]

Code:
<script>

    $("#demo3").floatdialog("dialog3", {effect: false});

</script>

3- speed

[ slow - fast - number ]

Code:
<script>

    $("#demo4").floatdialog("dialog4", {speed: 'fast'});

</script>

4- event

[ click - mouseover ...ect ]

Code:
<script>

    $("#demo4").floatdialog("dialog4", {speed: 'fast'});

</script>

5- backgroundcolor

[ color ]

Code:
<script>

    $("#demo6").floatdialog("dialog6", {backgroundcolor: 'red'});

</script>
Code:
<script>

    $("#demo6").floatdialog("dialog6", {backgroundcolor: '#CC0033'});

</script>

6- closeClass

[ Dialog Close button class ]

Default: closebutton

Code:
<a id="demo6" href="javascript :void(0);">You can change the close button class to what you want</a>

<div id="dialog6">

    <a href="javascript :void(0);">X</a>

    <h1>Demo2 - Options - Close button class</h1>

    <h2>This is a demo of the JQuery Float Dialog v1.0</h2>

    <div>

       You can change the close button class to what you want

    </div>

</div>

<script>

    $("#demo6").floatdialog("dialog6", {closeClass: '.myclosebutton'});

</script>

Download JQuery Float Dialog v1.0

1- Download jQuery JavaScript Library – jquery-1.3.2.min.js
2- JQuery Float Dialog v1.0 – jquery.floatdialog.zip
Download this demos

- jquery.floatdialog.package.zip JQuery Float Dialog v1.0 SetUp

A. Head Tag

1- css code:

Code:
<style>

.disable_masking

{

    z-index: 6001;

    position: absolute;

    display: none;

}

.closebutton

{

    float: right;

    text-decoration: none;

}

</style>

2- Import files:

Code:
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>

<script type="text/javascript" src="jquery.floatdialog.js"></script>

B. Body Tag

1- HTML & JavaScript Code:

Code:
<a id="linkid" href="javascript :void(0);">Clicking Here</a>

<div id="dialogid">

    <a href="javascript :void(0);">X</a>

    <h1>DIALOG DATA HERE !</h1>

</div>

<script>

    $("#linkid").floatdialog("dialogid");

</script>

===========================
Powered by: Ahmed Elkadrey – Expbuilder.com

Posted by admin on December-11-2009 Add Comments

In-place editing with contentEditable property and jQuery

In-place editing with contentEditable property and jQuery

Firefox 3 was released on June 17, 2008, and from that time, Firefox 2 browser share is quickly dropping. Very soon it will become inefficient to continue supporting it. And we will be able to use a lot of new Firefox 3 features, such as canvas support, CSS and DOM improvements and other. I am really glad that Firefox3 supports the “contentEditable” property. Setting this attribute to “true” allows you to make parts of a document editable. This attribute was already supported by IE6/7/8, Safari, Chrome and Opera. So now we can start using it in our applications.

To test “contentEditable” I made a plugin that allows you to convert parts of the page into editable areas, just click on them and when you finish editing click outside. If you convert an inline element (h1…h5, p ) with this script, the line breaks will be disabled.

Usage

First, add jQuery, plugin and style sheet to your page.

HTML Code:
<link href="editableText.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="../jquery.editableText.js" type="text/javascript"></script>

Next, pass the elements you want to make editable to the plugin. In this example I marked editable elements with “editableText” class.

HTML Code:
jQuery(function($){
     $('.editableText').editableText({
          // default value
          newlinesEnabled: false
     });

     // we will add more code here
});

Now you should create a function that will do something with the new
value of the editable element. Bind it to the element using change

HTML Code:
 //  bind an event listener that will be called when
   //  user saves changed content
   $('.editableText').change(function(){
         var newValue = $(this).html();

         // do something
         // For example, you could place an AJAX call here:
        $.ajax({
          type: "POST",
          url: "some.php",
          data: "newfieldvalue=" + newValue,
          success: function(msg){
            alert( "Data Saved: " + msg );
          }
       });
   });
event.

Download: http://www.ziddu.com/download/722162…87275.zip.html

Script Demo: http://valums.com/wp-content/uploads…/demo/demo.htm