]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Status_network_tag.php
Removed plugin Google-Analytics as this is free/libre and decentralized
[quix0rs-gnu-social.git] / classes / Status_network_tag.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, 2010 StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('STATUSNET')) { exit(1); }
21
22 class Status_network_tag extends Safe_DataObject
23 {
24     ###START_AUTOCODE
25     /* the code below is auto generated do not remove the above tag */
26
27     public $__table = 'status_network_tag';                      // table name
28     public $site_id;                  // int(4)  primary_key not_null
29     public $tag;                      // varchar(64)  primary_key not_null
30     public $created;                 // datetime()   not_null
31
32
33     function __construct()
34     {
35         global $config;
36         global $_DB_DATAOBJECT;
37
38         $sn = new Status_network();
39         $sn->_connect();
40
41         $config['db']['table_'. $this->tableName()] = $sn->_database;
42
43         $this->_connect();
44     }
45
46     /* the code above is auto generated do not remove the tag below */
47     ###END_AUTOCODE
48
49     /* Static get */
50     static function getKV($k,$v=null)
51     {
52         // TODO: This probably has to be converted to a non-static call
53         $i = DB_DataObject::staticGet('Status_network_tag',$k,$v);
54
55         // Don't use local process cache; if we're fetching multiple
56         // times it's because we're reloading it in a long-running
57         // process; we need a fresh copy!
58         global $_DB_DATAOBJECT;
59         unset($_DB_DATAOBJECT['CACHE']['status_network_tag']);
60         return $i;
61     }
62
63     static function pkeyGet($kv)
64     {
65         return Memcached_DataObject::pkeyGetClass('Status_network_tag', $kv);
66     }
67
68     /**
69      * Fetch the (possibly cached) tag entries for the given site id.
70      * Uses status_network's cache settings.
71      *
72      * @param string $site_id
73      * @return array of strings
74      */
75     static function getTags($site_id)
76     {
77         $key = 'status_network_tags:' . $site_id;
78         if (Status_network::$cache) {
79             $packed = Status_network::$cache->get($key);
80             if (is_string($packed)) {
81                 if ($packed == '') {
82                     return array();
83                 } else {
84                     return explode('|', $packed);
85                 }
86             }
87         }
88
89         $result = array();
90
91         $tags = new Status_network_tag();
92         $tags->site_id = $site_id;
93         if ($tags->find()) {
94             while ($tags->fetch()) {
95                 $result[] = $tags->tag;
96             }
97         }
98
99         if (Status_network::$cache) {
100             $packed = implode('|', $result);
101             Status_network::$cache->set($key, $packed, 0, 3600);
102         }
103
104         return $result;
105     }
106
107     /**
108      * Drop the cached tag entries for this site.
109      * Needed after inserting/deleting a tag entry.
110      */
111     function decache()
112     {
113         $key = 'status_network_tags:' . $this->site_id;
114         if (Status_network::$cache || Status_network::$cacheInitialized) {
115             // FIXME: this was causing errors, so I'm hiding them.
116             // I'm a big chicken and lazy.
117             @Status_network::$cache->delete($key);
118         }
119     }
120
121     function insert()
122     {
123         $ret = parent::insert();
124         $this->decache();
125         return $ret;
126     }
127
128     function delete($useWhere=false)
129     {
130         $this->decache();
131         return parent::delete($useWhere);
132     }
133
134     static function withTag($tag)
135     {
136         $snt = new Status_network_tag();
137
138         $snt->tag = $tag;
139
140         $snt->find();
141
142         return $snt;
143     }
144 }