tagCloud
[ class tree: tagCloud ] [ index: tagCloud ] [ all elements ]

Source for file tagCloud.inc.php

Documentation is available at tagCloud.inc.php

  1. <?php
  2.     /**
  3.      * @author            Matthias Reuter ($LastChangedBy: matthias $)
  4.      * @version            $LastChangedDate: 2008-11-02 16:54:59 +0000 (So, 02 Nov 2008) $
  5.      * @package            tagCloud
  6.      * @copyright        2007-2010 IPBWI development team
  7.      * @link            http://ipbwi.com/examples/stats.php
  8.      * @since            2.0
  9.      * @license            http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
  10.      */
  11.     class ipbwi_tagCloud extends ipbwi {
  12.         private $ipbwi            null;
  13.         /**
  14.          * @desc            Loads and checks different vars when class is initiating
  15.          * @author            Matthias Reuter
  16.          * @since            2.0
  17.          * @ignore
  18.          */
  19.         public function __construct($ipbwi){
  20.             // loads common classes
  21.             $this->ipbwi $ipbwi;
  22.  
  23.             // create table if not exists
  24.             $sql_create '
  25.             CREATE TABLE IF NOT EXISTS '.ipbwi_DB_prefix.'tagcloud (
  26.                 id int(10) NOT NULL auto_increment,
  27.                 tag text character set utf8 collate utf8_unicode_ci NOT NULL,
  28.                 destination text character set utf8 collate utf8_unicode_ci NOT NULL,
  29.                 tid int(10) default NULL,
  30.                 title text character set utf8 collate utf8_unicode_ci,
  31.                 category text character set utf8 collate utf8_unicode_ci NOT NULL,
  32.                 PRIMARY KEY (id)
  33.             ) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;';
  34.  
  35.             $this->ipbwi->ips_wrapper->DB->query($sql_create);
  36.         }
  37.         /**
  38.          * @desc            Creates a tag cloud
  39.          * @param    string    $category Set a Category Name, if you want to get a tagcloud from one category only.
  40.          * @param    string    $link define a custom link to the tags and insert %key% as var which will be replaced, default: ?tag=%key%
  41.          * @return    string    Tag Cloud HTML
  42.          * @author            Matthias Reuter
  43.          * @sample
  44.          *  <code>
  45.          *  $ipbwi->tagCloud->view();
  46.          *  $ipbwi->tagCloud->view('Category Name');
  47.          *  $ipbwi->tagCloud->view('Category Name','/ipbwi_tagcloud_%key');
  48.          *  </code>
  49.          * @since            2.0
  50.          */
  51.         public function view($category=false,$link='?tag=%key%'){
  52.             if(isset($category&& $category != ''){
  53.                 $category ' WHERE category = "'.$category.'"';
  54.             }
  55.             $query $this->ipbwi->ips_wrapper->DB->query('SELECT * from '.ipbwi_DB_prefix.'tagcloud'.$category);
  56.             if($this->ipbwi->ips_wrapper->DB->getTotalRows($query== 0){
  57.                 return false;
  58.             }
  59.             while($row $this->ipbwi->ips_wrapper->DB->fetch($query)){
  60.                 if(empty($cloud[$row['tag']])){
  61.                     $cloud[$row['tag']] 1;
  62.                 }
  63.                 $cloud[$row['tag']]++;
  64.             }
  65.             ksort($cloud);
  66.  
  67.             $size[0'font-size:xx-small;';
  68.             $size[1'font-size:x-small;';
  69.             $size[2'font-size:small;';
  70.             $size[3'font-size:medium;';
  71.             $size[4'font-size:large;';
  72.             $size[5'font-size:x-large;';
  73.             $size[6'font-size:xx-large;';
  74.  
  75.             $output '';
  76.             foreach($cloud as $key => $value){
  77.                 $fmax 6//maximale Fontgröße
  78.                 $ti $value//Anzahl
  79.                 $tmin min($cloud)//minimale Anzahl
  80.                 $tmax max($cloud)//maximale Anzahl
  81.  
  82.                 //Anzuzeigende Fontgröße
  83.                 if($tmax-$tmin 0){
  84.                     $si ($fmax ($ti-$tmin)) ($tmax-$tmin);
  85.                 }else{
  86.                     $si $fmax;
  87.                 }
  88.                 $output .= '<a href="'.str_replace('%key%',$key,$link).'"><span style="'.$size[$si].'">'.$key.'</span></a>'."\n";
  89.             }
  90.             return $output;
  91.         }
  92.         /**
  93.          * @desc            gets all data from a tag
  94.          * @param    string    $tag Name of the tag
  95.          * @return    string    Tag Cloud HTML
  96.          * @author            Matthias Reuter
  97.          * @sample
  98.          *  <code>
  99.          *  $ipbwi->tagCloud->getTagData('Tools');
  100.          *  </code>
  101.          * @since            2.0
  102.          */
  103.         public function getTagData($tag){
  104.             $query $this->ipbwi->ips_wrapper->DB->query('SELECT * from '.ipbwi_DB_prefix.'tagcloud WHERE tag="'.$tag.'"');
  105.             if($this->ipbwi->ips_wrapper->DB->getTotalRows($query== 0){
  106.                 return false;
  107.             }
  108.             $data '';
  109.             while($row $this->ipbwi->ips_wrapper->DB->fetch($query)){
  110.                 $data[$row;
  111.             }
  112.             return $data;
  113.         }
  114.         /**
  115.          * @desc            gets array with all tags of a topic.
  116.          * @param    int        $topicID Get Tags of a specific topic
  117.          * @return    array    array with all tags
  118.          * @author            Matthias Reuter
  119.          * @sample
  120.          *  <code>
  121.          *  $ipbwi->tagCloud->getTagList();
  122.          *  $ipbwi->tagCloud->getTagList(55);
  123.          *  </code>
  124.          * @since            2.0
  125.          */
  126.         public function getTagList($topicID){
  127.             $query $this->ipbwi->ips_wrapper->DB->query('SELECT * FROM '.ipbwi_DB_prefix.'tagcloud WHERE tid="'.intval($topicID).'"');
  128.             if($this->ipbwi->ips_wrapper->DB->getTotalRows($query== 0){
  129.                 return false;
  130.             }
  131.             $data array();
  132.             while($row $this->ipbwi->ips_wrapper->DB->fetch($query)){
  133.                 $data[$row;
  134.             }
  135.             return $data;
  136.         }
  137.         /**
  138.          * @desc            gets array with all categories
  139.          * @return    array    array with all categories
  140.          * @author            Matthias Reuter
  141.          * @sample
  142.          *  <code>
  143.          *  $ipbwi->tagCloud->getCategoryList();
  144.          *  </code>
  145.          * @since            2.01
  146.          */
  147.         public function getCategoryList(){
  148.             $query $this->ipbwi->ips_wrapper->DB->query('SELECT DISTINCT category FROM '.ipbwi_DB_prefix.'tagcloud');
  149.             if($this->ipbwi->ips_wrapper->DB->getTotalRows($query== 0){
  150.                 return false;
  151.             }
  152.             $data array();
  153.             while($row $this->ipbwi->ips_wrapper->DB->fetch($query)){
  154.                 $data[$row['category'];
  155.             }
  156.             return $data;
  157.         }
  158.         /**
  159.          * @desc            adds a tag for a topic to tagcloud
  160.          * @param    string    $tag Name of the Tag
  161.          * @param    string    $destination Define a destination. This could be a full qualified URL, a relative path or filename or just again the topic id.
  162.          * @param    int        $topicID ID of the specific topic
  163.          * @param    string    $title Define a title. This could be an alternative of retrieving title informations through the topic id
  164.          * @param    string    $category Define a category to make handling with tags more efficient
  165.          * @return    bool    true on success, otherwise false
  166.          * @author            Matthias Reuter
  167.          * @sample
  168.          *  <code>
  169.          *  $ipbwi->tagCloud->addTag(55,'New tag','http://ipbwi.com/');
  170.          *  $ipbwi->tagCloud->addTag(66,'Another new tag','example.php','examples');
  171.          *  </code>
  172.          * @since            2.0
  173.          */
  174.         public function addTag($tag,$destination,$topicID=false,$title=false,$category='default'){
  175.             if($tag == '' || !is_string($tag)){
  176.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('badTag'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  177.                 return false;
  178.             }
  179.             if($destination == '' || !is_string($destination)){
  180.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('badDestination'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  181.                 return false;
  182.             }
  183.             if(intval($topicID0){
  184.                 $topicID '"'.intval($topicID).'"';
  185.             }else{
  186.                 $topicID 'NULL';
  187.             }
  188.             if(strlen($title0){
  189.                 $title '"'.$title.'"';
  190.             }else{
  191.                 $title 'NULL';
  192.             }
  193.             $this->ipbwi->ips_wrapper->DB->query('INSERT INTO '.ipbwi_DB_prefix.'tagcloud (tag,destination,tid,title,category) VALUES("'.$tag.'","'.$destination.'",'.$topicID.','.$title.',"'.$category.'")');
  194.             return true;
  195.         }
  196.         /**
  197.          * @desc            deletes a tag from tagcloud
  198.          * @param    int        $tagID ID of the tag which should be deleted
  199.          * @return    bool    true on success, otherwise false
  200.          * @author            Matthias Reuter
  201.          * @sample
  202.          *  <code>
  203.          *  $ipbwi->tagCloud->deleteTag(55);
  204.          *  </code>
  205.          * @since            2.0
  206.          */
  207.         public function deleteTag($tagID){
  208.             if($tagID == '' || intval($tagID== || !is_int(intval($tagID))){
  209.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('badTagID'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  210.                 return false;
  211.             }
  212.             $this->ipbwi->ips_wrapper->DB->query('DELETE FROM '.ipbwi_DB_prefix.'tagcloud WHERE id="'.$tagID.'"');
  213.             return true;
  214.         }
  215.     }
  216. ?>

Documentation generated on Sat, 23 Oct 2010 23:36:13 +0200 by phpDocumentor 1.4.3