From 84b3004231d97bcbeadf3b2544e3f9472d295783 Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 10 Jun 2016 13:57:39 -0700 Subject: [PATCH] Tagwords replacement plugin added. Tagcloud. --- e107_plugins/tagcloud/e_header.php | 8 + e107_plugins/tagcloud/e_menu.php | 49 ++ e107_plugins/tagcloud/images/icon_16.png | Bin 0 -> 736 bytes e107_plugins/tagcloud/images/icon_32.png | Bin 0 -> 1497 bytes .../languages/English/English_admin.php | 10 + .../languages/English/English_global.php | 13 + e107_plugins/tagcloud/plugin.xml | 7 + e107_plugins/tagcloud/tagcloud.css | 46 ++ e107_plugins/tagcloud/tagcloud_class.php | 589 ++++++++++++++++++ e107_plugins/tagcloud/tagcloud_menu.php | 112 ++++ 10 files changed, 834 insertions(+) create mode 100644 e107_plugins/tagcloud/e_header.php create mode 100644 e107_plugins/tagcloud/e_menu.php create mode 100644 e107_plugins/tagcloud/images/icon_16.png create mode 100644 e107_plugins/tagcloud/images/icon_32.png create mode 100644 e107_plugins/tagcloud/languages/English/English_admin.php create mode 100644 e107_plugins/tagcloud/languages/English/English_global.php create mode 100644 e107_plugins/tagcloud/plugin.xml create mode 100644 e107_plugins/tagcloud/tagcloud.css create mode 100644 e107_plugins/tagcloud/tagcloud_class.php create mode 100644 e107_plugins/tagcloud/tagcloud_menu.php diff --git a/e107_plugins/tagcloud/e_header.php b/e107_plugins/tagcloud/e_header.php new file mode 100644 index 000000000..029e85353 --- /dev/null +++ b/e107_plugins/tagcloud/e_header.php @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/e107_plugins/tagcloud/e_menu.php b/e107_plugins/tagcloud/e_menu.php new file mode 100644 index 000000000..5985da543 --- /dev/null +++ b/e107_plugins/tagcloud/e_menu.php @@ -0,0 +1,49 @@ + LAN_CAPTION, 'type'=>'text', 'multilan'=>true, 'writeParms'=>array('size'=>'xxlarge')); + + return $fields; + + } + + +} + +// optional +class tagcloud_menu_form extends e_form +{ + + +} + + +?> \ No newline at end of file diff --git a/e107_plugins/tagcloud/images/icon_16.png b/e107_plugins/tagcloud/images/icon_16.png new file mode 100644 index 0000000000000000000000000000000000000000..3f6f3ac41111de6509f38b5726238ab8b113f872 GIT binary patch literal 736 zcmV<60w4W}P)s7y@T#GkT;+f{09gi6a#>MW4M3+KEutMH^BzM zYzEPwumEX9cOgIkF(I1@5?H!)DZ`8zGr$U9Hh~O=1tvQ?JBk4S0mK3fAg~0;*>~>T zVYq$!Hp9!8FByP=#9(Y}3|4sQ(j|s{`}Q$>|Nfo9#>R%h+1VNHEr0-Gf-yh}ckkZK zps1+Gz{$zUuyW-}xU)~6KF#ps#}BZ<)22;h0LBE|#Q*^W4};gQUo%|0b`8uH5D);{ z2yzX`Fi}xahTp$`GrWEK799F8%^&~}KujQ8Kqk(dIg{brw{Hw(Wn~O`d3g*EA3kK5 zFku42({T~kOu`e$W{;lS$g5Z1%}AT$U^`D!~!x2B>Cmb7q9`al=uGqdpH{;haCTWe0*R% zATfXdVgZ`Q2#P|GjmR;AoQRNVkVY;pE^y!iEo1@+AeM9I&V9GAu;2hW7nUYqF@tO% zj1R&fwV-qY469!N0mKNjIZ;YVDh-sDK$#CcE2HNFkQflN0HggY(3_J00t^6|-_OiWCSzkdBb3=9kyczJoXfWk^Z{01O^;12lx`}bcM``^ERL|cTe9-mrZ z)Pn2*(V%$Y0LcLa5EFWwp@#svWw=>b_DAb?nK`I;Et;fpS8YOy&QAb^RKVddLC<5EHf#fYBf^5DhFu7?v+z&QMud33do5J7Mz`F+N9k3_t*3gaA65 zjg5`r(W6HUw{PEOc=hTP!|Btf!D6^_3M{pQFs{%+4gr7wV#1dOU~zxq#0iF*H*bP{ zzG>4Yh95tEU{%Y)!otAG$qCj20w6ZXvAA*#2mk~S3$FYR3;OThzcU;;a)jaS+qVod zGBOO8FJET3bLS2Nu-*X6!PJ5r2MVEW+qN+P%X@}DfBrDY$;mN9M@KU#DJj9#qB{T} zfZ!njDy7hU1#|j`;Mg{-@gtHuA zXJ==4{`@(^jT<+>a#N;EVYqki9@sKa6aZ^AhOn?Ou!W%DRa8`DC@d^wc=6%|SiZNn z7pxx^x}fO9R=@!S5EHI601C20hYo>LKd1r$1v|)K4h{~6FJHbetXsDZ9M8xe03}Y4 zx}2OGhNn-T!V4}Cjje(M0e}F)ng~IbgM0-_Q2P4%40Gnp0s9nKje_GC6vPJ)9%Q(C z_b#X!2kQfcNPBxb*dma6Jv}`J7Z(?>qmXj~dI$gnV6)my0184_YR9s1Qb%zB!QKs= z;a!Alj#o;W{2=~r0aZo>stRVdaS$gd-fTBZ=k5@ZB}{i_2Ir%KsvG8&j$UvQ~qtyk9A+ON=i|5;)==P>6a z=S+-|loDeM?!Cwmtu@4fDIig5t>{sqZ4pAidrv6^fs2g4eYy(PS_oA3-Z73prRcH00Iae0>C=_3=kUv3m%ku9$#?diaJ~g8?H`qszA(5!yY-v=TCt6G0^Tm009O7vpK7ZhA6fL00000NkvXXu0mjfglcUu literal 0 HcmV?d00001 diff --git a/e107_plugins/tagcloud/languages/English/English_admin.php b/e107_plugins/tagcloud/languages/English/English_admin.php new file mode 100644 index 000000000..6be096686 --- /dev/null +++ b/e107_plugins/tagcloud/languages/English/English_admin.php @@ -0,0 +1,10 @@ + + + + Add a Tag Cloud to your site. + misc + Copyright e107 Inc e107.org, Licensed under GPL (http://www.gnu.org/licenses/gpl.txt) + \ No newline at end of file diff --git a/e107_plugins/tagcloud/tagcloud.css b/e107_plugins/tagcloud/tagcloud.css new file mode 100644 index 000000000..d234aab28 --- /dev/null +++ b/e107_plugins/tagcloud/tagcloud.css @@ -0,0 +1,46 @@ + + .size9 { + font-size: 130%; + opacity: 1; + } + + .size8 { + font-size: 125%; + opacity: 0.9 + } + .size7 { + font-size: 120%; + opacity: 0.8 + } + .size6 { + font-size: 110%; + } + .size5 { + font-size: 100%; + } + .size4 { + font-size: 90%; + } + .size3 { + font-size: 80%; + } + .size2 { + font-size: 70%; + } + .size1 { + font-size: 60%; + } + +.tagcloud-menu a { } + +.tagcloud-menu > a.tag { + margin-bottom:1px; + display:inline-block; + padding-right:5px; +} + +div.tagcloud-menu { + text-align:justify; + font-size:90%; + opacity:0.7; +} \ No newline at end of file diff --git a/e107_plugins/tagcloud/tagcloud_class.php b/e107_plugins/tagcloud/tagcloud_class.php new file mode 100644 index 000000000..39630d0fd --- /dev/null +++ b/e107_plugins/tagcloud/tagcloud_class.php @@ -0,0 +1,589 @@ + 'lower', + 'trim' => true + ); + + /** + * Custom function to create the tag-output + */ + protected $_htmlizeTagFunction = null; + + /** + * @var array Conversion map + */ + protected $_transliterationTable = array( + 'á' => 'a', 'Á' => 'A', 'à' => 'a', 'À' => 'A', 'ă' => 'a','Ă' => 'A', 'â' => 'a', 'Â' => 'A', + 'å' => 'a', 'Å' => 'A', 'ã' => 'a', 'Ã' => 'A', 'ą' => 'a', 'Ą' => 'A', 'ā' => 'a', 'Ā' => 'A', + 'ä' => 'ae', 'Ä' => 'AE', 'æ' => 'ae', 'Æ' => 'AE', 'ḃ' => 'b', 'Ḃ' => 'B', 'ć' => 'c', 'Ć' => 'C', + 'ĉ' => 'c', 'Ĉ' => 'C', 'č' => 'c', 'Č' => 'C', 'ċ' => 'c', 'Ċ' => 'C', 'ç' => 'c', 'Ç' => 'C', + 'ď' => 'd', 'Ď' => 'D', 'ḋ' => 'd', 'Ḋ' => 'D', 'đ' => 'd', 'Đ' => 'D', 'ð' => 'dh', 'Ð' => 'Dh', + 'é' => 'e', 'É' => 'E', 'è' => 'e', 'È' => 'E', 'ĕ' => 'e', 'Ĕ' => 'E', 'ê' => 'e', 'Ê' => 'E', + 'ě' => 'e', 'Ě' => 'E', 'ë' => 'e', 'Ë' => 'E', 'ė' => 'e', 'Ė' => 'E', 'ę' => 'e', 'Ę' => 'E', + 'ē' => 'e', 'Ē' => 'E', 'ḟ' => 'f', 'Ḟ' => 'F', 'ƒ' => 'f', 'Ƒ' => 'F', 'ğ' => 'g', 'Ğ' => 'G', + 'ĝ' => 'g', 'Ĝ' => 'G', 'ġ' => 'g', 'Ġ' => 'G', 'ģ' => 'g', 'Ģ' => 'G', 'ĥ' => 'h', 'Ĥ' => 'H', + 'ħ' => 'h', 'Ħ' => 'H', 'í' => 'i', 'Í' => 'I', 'ì' => 'i', 'Ì' => 'I', 'î' => 'i', 'Î' => 'I', + 'ï' => 'i', 'Ï' => 'I', 'ĩ' => 'i', 'Ĩ' => 'I', 'į' => 'i', 'Į' => 'I', 'ī' => 'i', 'Ī' => 'I', + 'ĵ' => 'j', 'Ĵ' => 'J', 'ķ' => 'k', 'Ķ' => 'K', 'ĺ' => 'l', 'Ĺ' => 'L', 'ľ' => 'l', 'Ľ' => 'L', + 'ļ' => 'l', 'Ļ' => 'L', 'ł' => 'l', 'Ł' => 'L', 'ṁ' => 'm', 'Ṁ' => 'M', 'ń' => 'n', 'Ń' => 'N', + 'ň' => 'n', 'Ň' => 'N', 'ñ' => 'n', 'Ñ' => 'N', 'ņ' => 'n', 'Ņ' => 'N', 'ó' => 'o', 'Ó' => 'O', + 'ò' => 'o', 'Ò' => 'O', 'ô' => 'o', 'Ô' => 'O', 'ő' => 'o', 'Ő' => 'O', 'õ' => 'o', 'Õ' => 'O', + 'ø' => 'oe', 'Ø' => 'OE', 'ō' => 'o', 'Ō' => 'O', 'ơ' => 'o', 'Ơ' => 'O', 'ö' => 'oe', 'Ö' => 'OE', + 'ṗ' => 'p', 'Ṗ' => 'P', 'ŕ' => 'r', 'Ŕ' => 'R', 'ř' => 'r', 'Ř' => 'R', 'ŗ' => 'r', 'Ŗ' => 'R', + 'ś' => 's', 'Ś' => 'S', 'ŝ' => 's', 'Ŝ' => 'S', 'š' => 's', 'Š' => 'S', 'ṡ' => 's', 'Ṡ' => 'S', + 'ş' => 's', 'Ş' => 'S', 'ș' => 's', 'Ș' => 'S', 'ß' => 'SS', 'ť' => 't', 'Ť' => 'T', 'ṫ' => 't', + 'Ṫ' => 'T', 'ţ' => 't', 'Ţ' => 'T', 'ț' => 't', 'Ț' => 'T', 'ŧ' => 't', 'Ŧ' => 'T', 'ú' => 'u', + 'Ú' => 'U', 'ù' => 'u', 'Ù' => 'U', 'ŭ' => 'u', 'Ŭ' => 'U', 'û' => 'u', 'Û' => 'U', 'ů' => 'u', + 'Ů' => 'U', 'ű' => 'u', 'Ű' => 'U', 'ũ' => 'u', 'Ũ' => 'U', 'ų' => 'u', 'Ų' => 'U', 'ū' => 'u', + 'Ū' => 'U', 'ư' => 'u', 'Ư' => 'U', 'ü' => 'ue', 'Ü' => 'UE', 'ẃ' => 'w', 'Ẃ' => 'W', 'ẁ' => 'w', + 'Ẁ' => 'W', 'ŵ' => 'w', 'Ŵ' => 'W', 'ẅ' => 'w', 'Ẅ' => 'W', 'ý' => 'y', 'Ý' => 'Y', 'ỳ' => 'y', + 'Ỳ' => 'Y', 'ŷ' => 'y', 'Ŷ' => 'Y', 'ÿ' => 'y', 'Ÿ' => 'Y', 'ź' => 'z', 'Ź' => 'Z', 'ž' => 'z', + 'Ž' => 'Z', 'ż' => 'z', 'Ż' => 'Z', 'þ' => 'th', 'Þ' => 'Th', 'µ' => 'u', 'а' => 'a', 'А' => 'a', + 'б' => 'b', 'Б' => 'b', 'в' => 'v', 'В' => 'v', 'г' => 'g', 'Г' => 'g', 'д' => 'd', 'Д' => 'd', + 'е' => 'e', 'Е' => 'e', 'ё' => 'e', 'Ё' => 'e', 'ж' => 'zh', 'Ж' => 'zh', 'з' => 'z', 'З' => 'z', + 'и' => 'i', 'И' => 'i', 'й' => 'j', 'Й' => 'j', 'к' => 'k', 'К' => 'k', 'л' => 'l', 'Л' => 'l', + 'м' => 'm', 'М' => 'm', 'н' => 'n', 'Н' => 'n', 'о' => 'o', 'О' => 'o', 'п' => 'p', 'П' => 'p', + 'р' => 'r', 'Р' => 'r', 'с' => 's', 'С' => 's', 'т' => 't', 'Т' => 't', 'у' => 'u', 'У' => 'u', + 'ф' => 'f', 'Ф' => 'f', 'х' => 'h', 'Х' => 'h', 'ц' => 'c', 'Ц' => 'c', 'ч' => 'ch', 'Ч' => 'ch', + 'ш' => 'sh', 'Ш' => 'sh', 'щ' => 'sch', 'Щ' => 'sch', 'ъ' => '', 'Ъ' => '', 'ы' => 'y', 'Ы' => 'y', + 'ь' => '', 'Ь' => '', 'э' => 'e', 'Э' => 'e', 'ю' => 'ju', 'Ю' => 'ju', 'я' => 'ja', 'Я' => 'ja' + ); + + /* + * Constructor + * + * @param array $tags + * + * @return void + */ + public function __construct($tags = false) + { + if ($tags !== false) { + if (is_string($tags)) { + $this->addString($tags); + } elseif (count($tags)) { + foreach ($tags as $key => $value) { + $this->addTag($value); + } + } + } + } + + /* + * Convert a string into a array + * + * @param string $string The string to use + * @param string $seperator The seperator to extract the tags + * + * @return void + */ + public function addString($string, $seperator = ' ') + { + $inputArray = explode($seperator, $string); + $tagArray = array(); + foreach ($inputArray as $inputTag) { + $tagArray[]=$this->formatTag($inputTag); + } + $this->addTags($tagArray); + } + + /* + * Parse tag into safe format + * + * @param string $string + * + * @return string + */ + public function formatTag($string) + { + $string = $this->_convertCharacters($string); + if ($this->_formatting['transformation']) { + switch ($this->_formatting['transformation']) { + case 'upper': + $string = strtoupper($string); + break; + default: + $string = strtolower($string); + } + } + if ($this->_formatting['trim']) { + $string = trim($string); + } + return preg_replace('/[^\w ]/u', '', strip_tags($string)); + } + + /* + * Assign tag to array + * + * @param array $tagAttributes Tags or tag attributes array + * + * @return array $this->tagsArray + */ + public function addTag($tagAttributes = array()) + { + if (is_string($tagAttributes)) { + $tagAttributes = array('tag' => $tagAttributes); + } + $tagAttributes['tag'] = $this->formatTag($tagAttributes['tag']); + if (!array_key_exists('size', $tagAttributes)) { + $tagAttributes = array_merge($tagAttributes, array('size' => 1)); + } + if (!array_key_exists('tag', $tagAttributes)) { + return false; + } + $tag = $tagAttributes['tag']; + if (empty($this->_tagsArray[$tag])) { + $this->_tagsArray[$tag] = array(); + } + if (!empty($this->_tagsArray[$tag]['size']) && !empty($tagAttributes['size'])) { + $tagAttributes['size'] = ($this->_tagsArray[$tag]['size'] + $tagAttributes['size']); + } elseif (!empty($this->_tagsArray[$tag]['size'])) { + $tagAttributes['size'] = $this->_tagsArray[$tag]['size']; + } + $this->_tagsArray[$tag] = $tagAttributes; + $this->addAttributes($tagAttributes); + return $this->_tagsArray[$tag]; + } + + /* + * Add all attributes to cached array + * + * @return void + */ + public function addAttributes($attributes) + { + $this->_attributes = array_unique( + array_merge( + $this->_attributes, + array_keys($attributes) + ) + ); + } + + /* + * Get attributes from cache + * + * @return array $this->_attibutes + */ + public function getAttributes() + { + return $this->_attributes; + } + + /* + * Assign multiple tags to array + * + * @param array $tags + * + * @return void + */ + public function addTags($tags = array()) + { + if (!is_array($tags)) { + $tags = func_get_args(); + } + foreach ($tags as $tagAttributes) { + $this->addTag($tagAttributes); + } + } + + /* + * Sets a minimum string length for the + * tags to display + * + * @param int $minLength + * + * @returns obj $this + */ + public function setMinLength($minLength) + { + $this->_minLength = $minLength; + return $this; + } + + + /* + * Gets the minimum length value + * + * @returns void + */ + public function getMinLength() + { + return $this->_minLength; + } + + + /* + * Sets a limit for the amount of clouds + * + * @param int $limit + * + * @returns obj $this + */ + public function setLimit($limit) + { + $this->_limit = $limit; + return $this; + } + + /* + * Get the limit for the amount tags + * to display + * + * @param int $limit + * + * @returns int $this->_limit + */ + public function getLimit() + { + return $this->_limit; + } + + /* + * Remove a tag from the array + * + * @param string $tag + * + * @returns obj $this + */ + public function setRemoveTag($tag) + { + $this->_removeTags[] = $this->formatTag($tag); + return $this; + } + + /* + * Remove multiple tags from the array + * + * @param array $tags + * + * @returns obj $this + */ + public function setRemoveTags($tags) + { + foreach ($tags as $tag) { + $this->setRemoveTag($tag); + } + return $this; + } + + /* + * Get the list of remove tags + * + * @returns array $this->_removeTags + */ + public function getRemoveTags() + { + return $this->_removeTags; + } + + /* + * Assign the order field and order direction of the array + * + * Order by tag or size / defaults to random + * + * @param array $field + * @param string $direction + * + * @returns $this->orderBy + */ + public function setOrder($field, $direction = 'ASC') + { + return $this->orderBy = array( + 'field' => $field, + 'direction' => $direction + ); + } + + /* + * Inject a custom function for generatinng the rendered HTML + * + * @param function $htmlizer + * + * @return $this->_htmlizeTagFunction + */ + public function setHtmlizeTagFunction($htmlizer) + { + return $this->_htmlizeTagFunction = $htmlizer; + } + + /* + * Generate the output for each tag. + * + * @returns string/array $return + */ + public function render($returnType = 'html') + { + $this->_remove(); + $this->_minLength(); + if (empty($this->orderBy)) { + $this->_shuffle(); + } else { + $orderDirection = strtolower($this->orderBy['direction']) == 'desc' ? 'SORT_DESC' : 'SORT_ASC'; + $this->_tagsArray = $this->_order( + $this->_tagsArray, + $this->orderBy['field'], + $orderDirection + ); + } + + $this->_limit(); + $max = $this->_getMax(); + if (count($this->_tagsArray)) { + $return = ($returnType == 'html' ? '' : ($returnType == 'array' ? array() : '')); + foreach ($this->_tagsArray as $tag => $arrayInfo) { + $sizeRange = $this->_getClassFromPercent(($arrayInfo['size'] / $max) * 100); + $arrayInfo['range'] = $sizeRange; + if ($returnType == 'array') { + $return [$tag] = $arrayInfo; + } elseif ($returnType == 'html') { + $return .= $this->htmlizeTag( $arrayInfo, $sizeRange ); + } + } + return $return; + } + return null; + } + + /** + * Convert a tag into an html-snippet + * + * This function is mainly an anchor to decide if a user-supplied + * custom function should be used or the normal output method. + * + * This will most likely only work in PHP >= 5.3 + * + * @param array $arrayInfo + * @param string $sizeRange + * + * @return string + */ + public function htmlizeTag($arrayInfo, $sizeRange) + { + $htmlizeTagFunction = $this->_htmlizeTagFunction; + if (isset($htmlizeTagFunction) && + is_callable($htmlizeTagFunction) + ) { + // this cannot be written in one line or the PHP interpreter will puke + // apparently, it's okay to have a function in a variable, + // but it's not okay to have it in an instance-variable. + return $htmlizeTagFunction($arrayInfo, $sizeRange); + } else { + return "   {$arrayInfo['tag']}   "; + } + } + + /* + * Removes tags from the whole array + * + * @returns array $this->_tagsArray + */ + protected function _remove() + { + $_tagsArray = array(); + foreach ($this->_tagsArray as $key => $value) { + if (!in_array($value['tag'], $this->getRemoveTags())) { + $_tagsArray[$value['tag']] = $value; + } + } + $this->_tagsArray = array(); + $this->_tagsArray = $_tagsArray; + return $this->_tagsArray; + } + + /* + * Orders the cloud by a specific field + * + * @param array $unsortedArray + * @param string $sortField + * @param string $sortWay + * + * @returns array $unsortedArray + */ + protected function _order($unsortedArray, $sortField, $sortWay = 'SORT_ASC') + { + $sortedArray = array(); + foreach ($unsortedArray as $uniqid => $row) { + foreach ($this->getAttributes() as $attr) { + if (isset($row[$attr])) { + $sortedArray[$attr][$uniqid] = $unsortedArray[$uniqid][$attr]; + } else { + $sortedArray[$attr][$uniqid] = null; + } + } + } + if ($sortWay) { + array_multisort($sortedArray[$sortField], constant($sortWay), $unsortedArray); + } + return $unsortedArray; + } + + /* + * Parses the array and retuns + * limited amount of items + * + * @returns array $this->_tagsArray + */ + protected function _limit() + { + $limit = $this->getLimit(); + if ($limit !== null) { + $i = 0; + $_tagsArray = array(); + foreach ($this->_tagsArray as $key => $value) { + if ($i < $limit) { + $_tagsArray[$value['tag']] = $value; + } + $i++; + } + $this->_tagsArray = array(); + $this->_tagsArray = $_tagsArray; + } + return $this->_tagsArray; + } + + /* + * Reduces the array by removing strings + * with a length shorter than the minLength + * + * @returns array $this->_tagsArray + */ + protected function _minLength() + { + $limit = $this->getMinLength(); + if ($limit !== null) { + $i = 0; + $_tagsArray = array(); + foreach ($this->_tagsArray as $key => $value) { + if (strlen($value['tag']) >= $limit) { + $_tagsArray[$value['tag']] = $value; + } + $i++; + } + $this->_tagsArray = array(); + $this->_tagsArray = $_tagsArray; + } + return $this->_tagsArray; + } + + /* + * Finds the maximum 'size' value of an array + * + * @returns string $max + */ + protected function _getMax() + { + $max = 0; + if (!empty($this->_tagsArray)) { + $p_size = 0; + foreach ($this->_tagsArray as $cKey => $cVal) { + $c_size = $cVal['size']; + if ($c_size > $p_size) { + $max = $c_size; + $p_size = $c_size; + } + } + } + return $max; + } + + /* + * Shuffle associated names in array + * + * @return array $this->_tagsArray The shuffled array + */ + protected function _shuffle() + { + $keys = array_keys($this->_tagsArray); + shuffle($keys); + if (count($keys) && is_array($keys)) { + $tmpArray = $this->_tagsArray; + $this->_tagsArray = array(); + foreach ($keys as $key => $value) + $this->_tagsArray[$value] = $tmpArray[$value]; + } + return $this->_tagsArray; + } + + /* + * Get the class range using a percentage + * + * @returns int $class The respective class + * name based on the percentage value + */ + protected function _getClassFromPercent($percent) + { + $class = floor(($percent / 10)); + + if ($percent >= 5) { + $class++; + } + + if ($percent >= 80 && $percent < 100) { + $class = 8; + } elseif ($percent == 100) { + $class = 9; + } + + return $class; + } + + /** + * Calculate the class given to a tag from the + * weight percentage of the given tag. + */ + public function calculateClassFromPercent($percent) + { + return $this->_getClassFromPercent($percent); + } + + /** + * Convert accented chars into basic latin chars + * + * Taken from http://stackoverflow.com/questions/6837148/change-foreign-characters-to-normal-equivalent + */ + function _convertCharacters($string) { + return str_replace(array_keys($this->_transliterationTable), array_values($this->_transliterationTable), $string); + } +} diff --git a/e107_plugins/tagcloud/tagcloud_menu.php b/e107_plugins/tagcloud/tagcloud_menu.php new file mode 100644 index 000000000..d1cdf828f --- /dev/null +++ b/e107_plugins/tagcloud/tagcloud_menu.php @@ -0,0 +1,112 @@ +setMD5(e_LANGUAGE); + + if($text = e107::getCache()->retrieve('tagcloud',5,false)) + { + return $text; + } + + + if($result = $sql->retrieve('news','news_id,news_meta_keywords', "news_meta_keywords !='' ", true)) + { + foreach($result as $row) + { + + $tmp = explode(",", $row['news_meta_keywords']); + foreach($tmp as $word) + { + //$newsUrlparms = array('id'=> $row['news_id'], 'name'=>'a name'); + $url = e107::getUrl()->create('news/list/tag',array('tag'=>$word)); // SITEURL."news.php?tag=".$word; + $cloud->addTag(array('tag' => $word, 'url' => $url)); + + } + } + + } + else + { + $text = "No tags Found"; + } + + $cloud->setHtmlizeTagFunction( function($tag, $size) + { + return "".$tag['tag']." "; + }); + + $cloud->setOrder('tag','ASC'); + $cloud->setLimit(50); + + $text = $cloud->render(); + + e107::getCache()->set('tagcloud', $text, true); + + $text .= "
"; + + return $text; + + } + + + +} + + +$tag = new tagcloud_menu; +$text = $tag->render(); + + +if(!empty($parm)) +{ + + if(isset($parm['tagcloud_caption'][e_LANGUAGE])) + { + $caption = $parm['tagcloud_caption'][e_LANGUAGE]; + } +} +else +{ + $caption = LAN_PLUGIN_TAGCLOUD_NAME; +} + + + +e107::getRender()->tablerender($caption, "
".$text."
", 'tagcloud_menu'); + + + + +?> \ No newline at end of file