tagCloud Class Reference

Tag Cloud. More...

List of all members.

Public Member Functions

  • __construct ($words=false)
    PHP 5 Constructor $words array.
  • addString ($string)
    Convert a string into a cloud $string.
  • notify ($string, $value)
    Display user friendly message, for debugging mainly string $string array $value.
  • addWord ($wordAttributes=array())
    Assign word to array string $word.
  • shuffleCloud ()
    Shuffle associated names in array.
  • getClassFromPercent ($percent)
    Get the class range using a percentage.
  • setLimit ($limit)
    Sets a limit for the amount of clouds string $limit.
  • limitCloud ()
    Gets the limited amount of clouds.
  • removeWord ($word)
    Finds the maximum value of an array string $word.
  • removeWords ()
    Removes tags from the whole array.
  • orderBy ($field, $direction= 'ASC')
    Assign the order field and order direction of the cloud array $field string $sortway.
  • orderCloud ($unsortedArray, $sortField, $sortWay= 'SORT_ASC')
    Orders the cloud by a specific field array $unsortedArray string $sortField string $sortWay.
  • getMax ()
    Finds the maximum value of an array.
  • showCloud ($returnType= 'html')
    Create the HTML code for each word and apply font size.

Public Attributes


Detailed Description

Tag Cloud.

Definition at line 15 of file tagcloud.php.


Constructor & Destructor Documentation

tagCloud::__construct ( words = false  ) 

PHP 5 Constructor $words array.

Returns:
void

Definition at line 25 of file tagcloud.php.

00025                                        {
00026     // If we are trying to parse some works, in any format / type
00027     if ($words !== false) {
00028       // If we have a string
00029       if (is_string($words)) {
00030         $this->addString($words);
00031       } elseif (count($words)) {
00032         foreach ($words as $key => $value) $this->addWord($value);
00033       }
00034     }
00035     return;
00036   }


Member Function Documentation

tagCloud::addString ( string  ) 

Convert a string into a cloud $string.

Returns:
void

Definition at line 43 of file tagcloud.php.

Referenced by __construct().

00043                              {
00044     // remove all other chars apart from a-z
00045     $string = preg_replace('[^a-z]', '', strip_tags(strtolower($string)));
00046     $words = array();
00047     $words = explode(' ', $string);
00048     if (count($words)) {
00049       foreach ($words as $key => $value) $this->addWord($value);
00050     }
00051   }

tagCloud::addWord ( wordAttributes = array()  ) 

Assign word to array string $word.

Returns:
string

Definition at line 72 of file tagcloud.php.

Referenced by __construct(), and addString().

00072                                               {
00073     if (is_string($wordAttributes))$wordAttributes = array('word' => $wordAttributes);
00074 
00075     if (!array_key_exists('size', $wordAttributes))$wordAttributes = array_merge($wordAttributes, array('size' => 1));
00076 
00077     if (!array_key_exists('word', $wordAttributes))return $this->notify('no word attribute', print_r($wordAttributes, true));
00078 
00079     $word = strtolower($wordAttributes['word']);
00080     if (empty($this->wordsArray[$word]))$this->wordsArray[$word] = array();
00081 
00082     if (!empty($this->wordsArray[$word]['size']) && !empty($wordAttributes['size']))$wordAttributes['size'] = ($this->wordsArray[$word]['size'] + $wordAttributes['size']);
00083     elseif (!empty($this->wordsArray[$word]['size'])) $wordAttributes['size'] = $this->wordsArray[$word]['size'];
00084 
00085     $this->wordsArray[$word] = $wordAttributes;
00086     return $this->wordsArray[$word];
00087   }

tagCloud::getClassFromPercent ( percent  ) 

Get the class range using a percentage.

Returns:
int $class

Definition at line 109 of file tagcloud.php.

Referenced by showCloud().

00109                                         {
00110     if ($percent >= 99)
00111             $class = 9;
00112     elseif ($percent >= 70)
00113             $class = 8;
00114     elseif ($percent >= 60)
00115             $class = 7;
00116     elseif ($percent >= 50)
00117             $class = 6;
00118     elseif ($percent >= 40)
00119             $class = 5;
00120     elseif ($percent >= 30)
00121             $class = 4;
00122     elseif ($percent >= 20)
00123             $class = 3;
00124     elseif ($percent >= 10)
00125             $class = 2;
00126     elseif ($percent >= 5)
00127             $class = 1;
00128     else
00129             $class = 0;
00130     return $class;
00131   }

tagCloud::getMax (  ) 

Finds the maximum value of an array.

Returns:
string $max

Definition at line 226 of file tagcloud.php.

Referenced by showCloud().

00226                     {
00227     $max = 0;
00228     if (!empty($this->wordsArray)) {
00229       $p_size = 0;
00230       foreach ($this->wordsArray as $cKey => $cVal) {
00231         $c_size = $cVal['size'];
00232         if ($c_size > $p_size)
00233                 $max = $c_size;
00234         $p_size = $c_size;
00235       }
00236     }
00237     return $max;
00238   }

tagCloud::limitCloud (  ) 

Gets the limited amount of clouds.

Returns:
string $wordCloud

Definition at line 151 of file tagcloud.php.

Referenced by showCloud().

00151                        {
00152     $i = 1;
00153     foreach ($this->wordsArray as $key => $value) {
00154             if ($this->limitAmount < $i) {
00155                     $wordsArray[$value['word']] = $value;
00156             }
00157             $i++;
00158     }
00159     $this->wordsArray = array();
00160     $this->wordsArray = $wordsArray;
00161     return $this->wordsArray;
00162   }

tagCloud::notify ( string,
value 
)

Display user friendly message, for debugging mainly string $string array $value.

Returns:
bool

Definition at line 59 of file tagcloud.php.

Referenced by addWord().

00059                                   {
00060           echo '<pre>';
00061           print_r($string);
00062           print_r($value);
00063           echo '</pre>';
00064           return false;
00065   }

tagCloud::orderBy ( field,
direction = 'ASC' 
)

Assign the order field and order direction of the cloud array $field string $sortway.

Returns:
void

Definition at line 196 of file tagcloud.php.

Referenced by showCloud().

00196                                                {
00197     return $this->orderBy = array('field' => $field, 'direction' => $direction);
00198   }

tagCloud::orderCloud ( unsortedArray,
sortField,
sortWay = 'SORT_ASC' 
)

Orders the cloud by a specific field array $unsortedArray string $sortField string $sortWay.

Returns:
array $unsortedArray

Definition at line 208 of file tagcloud.php.

Referenced by showCloud().

00208                                                                         {
00209     $sortedArray = array();
00210     foreach ($unsortedArray as $uniqid => $row) {
00211       foreach ($row as $key => $value) {
00212         $sortedArray[$key][$uniqid] = strtolower($value);
00213       }
00214     }
00215     if ($sortWay) {
00216       array_multisort($sortedArray[$sortField], constant($sortWay), $unsortedArray);
00217     }
00218     return $unsortedArray;
00219   }

tagCloud::removeWord ( word  ) 

Finds the maximum value of an array string $word.

Returns:
void

Definition at line 169 of file tagcloud.php.

00169                             {
00170     $this->removeWords[] = strtolower($word);
00171   }

tagCloud::removeWords (  ) 

Removes tags from the whole array.

Returns:
array $this->wordsArray

Definition at line 178 of file tagcloud.php.

Referenced by removeWord(), and showCloud().

00178                           {
00179     foreach ($this->wordsArray as $key => $value) {
00180             if (!in_array($value['word'], $this->removeWords)) {
00181                     $wordsArray[$value['word']] = $value;
00182             }
00183     }
00184     $this->wordsArray = array();
00185     $this->wordsArray = $wordsArray;
00186     return $this->wordsArray;
00187   }

tagCloud::setLimit ( limit  ) 

Sets a limit for the amount of clouds string $limit.

Returns:
string $this->limitAmount

Definition at line 139 of file tagcloud.php.

00139                             {
00140     if (!empty($limit)) {
00141             $this->limitAmount = $limit;
00142     }
00143     return $this->limitAmount;
00144   }

tagCloud::showCloud ( returnType = 'html'  ) 

Create the HTML code for each word and apply font size.

Returns:
string/array $return

Definition at line 245 of file tagcloud.php.

00245                                            {
00246     if (empty($this->orderBy)) {
00247       $this->shuffleCloud();
00248     } else {
00249       $orderDirection = strtolower($this->orderBy['direction']) == 'desc' ? 'SORT_DESC' : 'SORT_ASC';
00250       $this->wordsArray = $this->orderCloud($this->wordsArray, $this->orderBy['field'], $orderDirection);
00251     }
00252     if (!empty($this->limitAmount))$this->limitCloud();
00253 
00254     if (!empty($this->removeWords))  $this->removeWords();
00255 
00256     $this->max = $this->getMax();
00257     if (is_array($this->wordsArray)) {
00258       $return = ($returnType == 'html' ? '' : ($returnType == 'array' ? array() : ''));
00259       foreach ($this->wordsArray as $word => $arrayInfo) {
00260         $sizeRange = $this->getClassFromPercent(($arrayInfo['size'] / $this->max) * 100);
00261         $arrayInfo['range'] = $sizeRange;
00262         if ($returnType == 'array') {
00263           $return [$word] = $arrayInfo;
00264         } elseif ($returnType == 'html') {
00265           $return .= "<span class='word size{$sizeRange}'> &nbsp; {$arrayInfo['word']} &nbsp; </span>";
00266         }
00267       }
00268       return $return;
00269     }
00270   }

tagCloud::shuffleCloud (  ) 

Shuffle associated names in array.

Returns:
array $this->wordsArray

Definition at line 93 of file tagcloud.php.

Referenced by showCloud().

00093                          {
00094     $keys = array_keys($this->wordsArray);
00095     shuffle($keys);
00096     if (count($keys) && is_array($keys)) {
00097       $tmpArray = $this->wordsArray;
00098       $this->wordsArray = array();
00099       foreach ($keys as $key => $value)
00100         $this->wordsArray[$value] = $tmpArray[$value];
00101     }
00102     return $this->wordsArray;
00103   }


Member Data Documentation

tagCloud::$version = '1.0.1'

Definition at line 17 of file tagcloud.php.

tagCloud::$wordsArray = array()

Definition at line 18 of file tagcloud.php.

Referenced by limitCloud(), and removeWords().


The documentation for this class was generated from the following file: