<?php
/*
// YOU CAN CUSTOMIZE BALLOON TIP with an image editor 

PHP_TIP CLASS
###########################################
Author:    Ersin Guvenc                   #
Email:     eguvenc@gmail.com              #
Web:       http://ersin.fikirmakinasi.net #
Location:  Turkey - istanbul              #
Version:   1.3                            #  
Product. Date:  02.27.2008 12:13 AM       #
Php_tip class under the LGPL license.     #
###########################################

About version 1.1: Added word show limit.
Version 1.2: Word boundary problem fixed.
             (Thanks Ajay Chadha for report this bugs.)  02.03.2008
Version 1.3  Deleted .js files :P
             Added Css tooltip. 08.03.2008
             
LICENSE: LGPL

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License (LGPL) as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

For more details on the GNU Lesser General Public License,
see http://www.gnu.org/copyleft/lesser.html

*/
//XML versiyon Coming soon...

class php_tip {

var 
$subject "";
var 
$what_is_the "What is the";
var 
$target "_self";
var 
$show_limit true;
var 
$word_limit "1";  //One keyword one times show.You can set it two or three.. times.
                        //if show_limit = false; this option not important and all words will show.
                      
      
function tip($subject$what_is_the$target$show_limit$word_limit) {
         
$this->subject "<div id=\"container\">".$subject."</div>";
         
$this->what_is_the $what_is_the;
         
$this->target $target;
         
$this->show_limit $show_limit;
         
$this->word_limit $word_limit;
         
$this->get_data();
      }
           
      function 
a_link($a_color="blue"$a_decoration$hover_color="red",$hover_decoration,
      
$hover_background="lightyellow") {
         echo 
"a.tt{position:relative; z-index:24; color:$a_color; text-decoration:$a_decoration;}";
         echo 
"a.tt span{display: none;}";
         echo 
"a.tt:hover{z-index:25;color:$hover_color;text-decoration:$hover_decoration;
         background:$hover_background;}"
;
      }
                                            
      function 
tip_top($opacity="90"$top_fontface="Arial,sans-serif"$top_fontsize="12px",
      
$top_fontcolor="black"$top_fontweight="bold"$top_padding="30px 8px 0"$top_image="bubble.gif"){
         
         echo 
"<style type=\"text/css\">";
         
         
///// Cut body part and insert it your css file.
         
echo "body{font-family:Arial; font-size:14px; background: #FFFFFF; color: #333333;}";
         
///// Cut body part and insert it your css file.
         
         
echo "div#container{margin:0 auto}";
         echo 
"h1{ color: #F60; margin: 1em 0 0; letter-spacing: -2px; }";
         echo 
"p{margin: 0 0 1.7em; }";

         echo 
"a.tt:hover span.tooltip{display:block;position:absolute;top:0px;
         left:0;padding:15px 0 0 0;width:200px;"
;
         echo 
"color: #993300;text-align:left;filter: alpha(opacity:$opacity);KHTMLOpacity: 0.$opacity;
         MozOpacity: 0.$opacity;"
;
         echo 
"opacity: 0.$opacity;}";
        
         echo 
"a.tt:hover span.top{display:block;padding:$top_padding;background: url($top_image) no-repeat top;";
         echo 
"font-size:$top_fontsize;font-family:$top_fontface;font-weight:$top_fontweight;color:$top_fontcolor;}";
      }
      
      function 
tip_middle($mid_fontface="Arial,sans-serif"$mid_fonsize="12px"$mid_fontcolor="black",
      
$mid_fontweight="bold"$mid_padding="0 8px"$mid_image="bubble_filler.gif"){
         
         echo 
"a.tt:hover span.middle{display: block;padding: $mid_padding;font-size:$mid_fonsize;
         font-family:$mid_fontface;font-weight:$mid_fontweight;color:$mid_fontcolor;"
;
         echo 
"background: url($mid_image) repeat bottom;}";
      }
      
      function 
tip_bottom($bot_fontface="Arial,sans-serif"$bot_fonsize="9px"$bot_fontcolor="#548912",
      
$bot_fontweight="bold"$bot_padding="3px 8px 10px"$bot_image="bubble.gif") {
      
         echo 
"a.tt:hover span.bottom{display:block;padding:$bot_padding;font-family:$bot_fontface;
         font-size:$bot_fonsize;font-weight:$bot_fontweight;color:$bot_fontcolor;"
;
         echo 
"background: url($bot_image) no-repeat bottom;}";
         echo 
"</style>";
      }
                       
     function 
get_data(){
         
$key_sql mysql_query("SELECT keyword FROM dic_data") or die (mysql_error());
         
$i 0;
         
$array1_keywords = array();
         while (
$row mysql_fetch_array($key_sql)) {
         
extract($row);
         
$array1_keywords[$i++] = $keyword;
         }
     
$this->found_keywords($array1_keywords);
     }
     
     function 
found_keywords($found_keywords){
      
//found keyword
         
for ($i=0$i<count($array1_keywords); $i++) {
         
preg_match_all("/".$array1_keywords[$i]."/",$subject,$outPREG_PATTERN_ORDER);
         
$found_keywords[$i] = $out[0][0];
         }
         
//match keyword
         //not useful -> $found_keywords = array_uintersect($array1_keywords, $array2_body, "strcasecmp");
      
$this->find_real_keywords($found_keywords);
     }

     function 
find_real_keywords($found_keywords){
         
$patterns = array();
         
$replacements = array();
         for(
$i=0$i<=count($found_keywords) - 1$i++) {
         
$key_row mysql_query("SELECT * FROM dic_data WHERE keyword = '$found_keywords[$i]'");
         while (
$row mysql_fetch_assoc($key_row)) {
         
extract($row);
         
$capital_keyword ucwords($keyword);
         
//bu is kontrolden cikti.some turkish note.
         
         //don't change this section!!
         
$patterns[$i] = "/\b".$found_keywords[$i]."\b/i"//case sensitive, word boundary problem fixed.
         
$replacements[$i] = "<a href=\"$foot_note\" target=\"$this->target\" class=\"tt\">$found_keywords[$i]<span class=\"tooltip\"><span class=\"top\">$this->what_is_the $capital_keyword?</span><span class=\"middle\">$description</span><span class=\"bottom\">$foot_note</span></span></a>";
         
    }  
//end while.
    
}  //end for
    
    
$this->replace_all_words($patterns$replacements); 
    }  
//end real_key function.

        
    
function replace_all_words($patterns$replacements) {
    
//replace and echo subject.
         
if($this->show_limit == true) {
         echo 
preg_replace($patterns$replacements$this->subject$this->word_limit);
         } elseif (
$this->show_limit == false) {
         echo 
preg_replace($patterns$replacements$this->subject);
         }
    }
    

//end class
?>


//*** HOW TO USE   **************************************************************************

<?php

include "php_tip.class.php";
$tipi = new php_tip();

?>

HTML
<HEAD>
<?php
//Print css data between <HEAD></HEAD> tags.
 
$tipi->tip_top($opacity='99','Arial','12px','black','bold',$padding='33px 8px 0''bubble.gif');
$tipi->a_link('blue''underline'$hover_color='red',$hover_deco='none'$hover_bg='lightyellow');
$tipi->tip_middle('Arial','12px','black','none','0 8px','bubble_filler.gif');
$tipi->tip_bottom('Arial','10px','#548912','none','3px 8px 14px','bubble.gif');

?>
</HEAD>

<?PHP
 
$subject 
"<b>Weberian political sociology:</b>
In some social sciences, the understanding of the defining bla bla...."
;  



$tipi->tip($subject,'what is the''_blank'true,  '1');
            -----       ----         ----     ----   ----
             |           |            |        |      |
             
Subject   What is the   Url       Limit     Limit Number.
                                     
open      if true
                                               all words          
(While limit=true all words 
                                     in 
new    shows(loops)        shows as 1,2, or 3... times.)
                                     
window    as limit.
                                     or        
false
                                     
elseif    same words
                                     self
.     shows                                      
                                               many times
.                                             
                                                                                           
                                                                                           
                                                                                          
                                                                                             
                                                                                           
                                                  
                                            
                                              
?>