singpolyma / tagging

Code from tagging.ning.com

This URL has Read+Write access

tagging / tagFunctions.php
100755 63 lines (57 sloc) 2.237 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
 
    function getTagCount($limit=null,$sort=false) {
        $tags = XN_Query::create('tag_valuecount')
                                ->filter('content->owner');
        $tags = $tags->execute();
        if(is_array($tags)) {
            // sort, if true
            if($sort) {
                arsort($tags, SORT_NUMERIC);
            }
            // apply limit, if any
            if((int)$limit) {
                $tags = array_slice($tags,0,$limit);
            }
        }
        return $tags;
    }
 
    function fetchTags($content) {
        try{
              $results = XN_Query::create( 'Tag' )
                         ->filter( 'content', '=', $content )
                         ->order( 'count(value)', 'desc' )
                         ->order( 'value', 'asc' );
              $results = $results->execute();
              // Put all the tags into an array
              $tagArray = array();
              foreach($results as $tag) {
                  $tagArray[] = $tag->value;
              }
          }
          catch (XN_Exception $e) {
              echo 'Whoops! Something\'s Gone Wrong';
              echo 'There was an error in this page and I can\'t fetch the list of tags. The error is: '.$e->getMessage();
          }
          
        return $tagArray;
    }
 
    function fetchTagsWithCount($content) {
        try{
              $results = XN_Query::create( 'Tag' )
                         ->filter( 'content', '=', $content )
                         ->order( 'count(value)', 'desc' )
                         ->order( 'value', 'asc' );
              $results = $results->execute();
              // Put all the tags into an array
              $tagcounts = getTagCount();
              $tagArray = array();
              foreach($results as $tag) {
                  $tagArray[$tag->value] = $tagcounts[$tag->value];
              }
          }
          catch (XN_Exception $e) {
              echo 'Whoops! Something\'s Gone Wrong';
              echo 'There was an error in this page and I can\'t fetch the list of tags. The error is: '.$e->getMessage();
          }
          
        return $tagArray;
    }
 
?>