From 3b1e5e5204d7cade3afc320cc45b1eb4efa6743c Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 19 Jun 2013 21:50:14 -0700 Subject: source code re-org, move taxonomy to separate include --- include/taxonomy.php | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 include/taxonomy.php (limited to 'include/taxonomy.php') diff --git a/include/taxonomy.php b/include/taxonomy.php new file mode 100644 index 000000000..5130ff9b7 --- /dev/null +++ b/include/taxonomy.php @@ -0,0 +1,91 @@ +','[',']'),array('%3c','%3e','%5b','%5d'),$s); +} + +function file_tag_decode($s) { + return str_replace(array('%3c','%3e','%5b','%5d'),array('<','>','[',']'),$s); +} + +function file_tag_file_query($table,$s,$type = 'file') { + + if($type == 'file') + $termtype = TERM_FILE; + else + $termtype = TERM_CATEGORY; + + return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.type = %d and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ", + intval($termtype), + protect_sprintf(dbesc($s)) + ); +} + +function term_query($table,$s,$type = TERM_UNKNOWN) { + + return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.type = %d and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ", + intval($type), + protect_sprintf(dbesc($s)) + ); +} + + +function store_item_tag($uid,$iid,$otype,$type,$term,$url = '') { + if(! $term) + return false; + $r = q("select * from term + where uid = %d and oid = %d and otype = %d and type = %d + and term = '%s' and url = '%s' ", + intval($uid), + intval($iid), + intval($otype), + intval($type), + dbesc($term), + dbesc($url) + ); + if($r) + return false; + $r = q("insert into term (uid, oid, otype, type, term, url) + values( %d, %d, %d, %d, '%s', '%s') ", + intval($uid), + intval($iid), + intval($otype), + intval($type), + dbesc($term), + dbesc($url) + ); + return $r; +} + +function get_terms_oftype($arr,$type) { + $ret = array(); + if(! (is_array($arr) && count($arr))) + return $ret; + + if(! is_array($type)) + $type = array($type); + + foreach($type as $t) + foreach($arr as $x) + if($x['type'] == $t) + $ret[] = $x; + return $ret; +} + +function format_term_for_display($term) { + $s = ''; + if($term['type'] == TERM_HASHTAG) + $s .= '#'; + elseif($term['type'] == TERM_MENTION) + $s .= '@'; + + if($term['url']) $s .= '' . htmlspecialchars($term['term']) . ''; + else $s .= htmlspecialchars($term['term']); + return $s; +} + -- cgit v1.2.3 From 58ac92f4e162abdad2d2f259bbf6c58029f65b86 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 20 Jun 2013 20:34:00 -0700 Subject: bring back the body tag list - though it really belongs in the templates. It's difficult to debug community tags when you can't see any tags (except those the author typed in). --- include/taxonomy.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'include/taxonomy.php') diff --git a/include/taxonomy.php b/include/taxonomy.php index 5130ff9b7..aadcd938f 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -83,9 +83,13 @@ function format_term_for_display($term) { $s .= '#'; elseif($term['type'] == TERM_MENTION) $s .= '@'; + else + return $s; - if($term['url']) $s .= '' . htmlspecialchars($term['term']) . ''; - else $s .= htmlspecialchars($term['term']); + if($term['url']) + $s .= '' . htmlspecialchars($term['term']) . ''; + else + $s .= htmlspecialchars($term['term']); return $s; } -- cgit v1.2.3 From e16d678aab5fc43027ff80beedf1609ae09d78b0 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 21 Jun 2013 15:15:07 -0700 Subject: relocate tagadelic to include/taxonomy --- include/taxonomy.php | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'include/taxonomy.php') diff --git a/include/taxonomy.php b/include/taxonomy.php index aadcd938f..7e9a4c856 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -93,3 +93,67 @@ function format_term_for_display($term) { return $s; } +// Tag cloud functions - need to be adpated to this database format + + +function tagadelic($uid, $count = 0, $type = TERM_HASHTAG) { + + // Fetch tags + $r = q("select term, count(term) as total from term + where uid = %d and type = %d + and otype = %d + group by term order by total desc %s", + intval($uid), + intval($type), + intval(TERM_OBJ_POST), + ((intval($count)) ? "limit $count" : '') + ); + + if(! $r) + return array(); + + // Find minimum and maximum log-count. + $tags = array(); + $min = 1e9; + $max = -1e9; + + $x = 0; + foreach($r as $rr) { + $tags[$x][0] = $rr['term']; + $tags[$x][1] = log($rr['total']); + $tags[$x][2] = 0; + $min = min($min,$tags[$x][1]); + $max = max($max,$tags[$x][1]); + $x ++; + } + + usort($tags,'tags_sort'); + + $range = max(.01, $max - $min) * 1.0001; + + for($x = 0; $x < count($tags); $x ++) { + $tags[$x][2] = 1 + floor(5 * ($tags[$x][1] - $min) / $range); + } + + return $tags; +} + +function tags_sort($a,$b) { + if($a[0] == $b[0]) + return 0; + return((strtolower($a[0]) < strtolower($b[0])) ? -1 : 1); +} + + +function tagblock($link,$uid,$count = 0,$type = TERM_HASHTAG) { + $tab = 0; + $r = tagadelic($uid,$count,$type); + + if($r) { + echo '
'; + foreach($r as $rr) { + echo ''.$rr[0].' '; + } + echo '
'; + } +} -- cgit v1.2.3