]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Notice_tag.php
62810eba987d24fdc0c260be4ad5adc5e85376e0
[quix0rs-gnu-social.git] / classes / Notice_tag.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, 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 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
21
22 class Notice_tag extends Managed_DataObject
23 {
24     ###START_AUTOCODE
25     /* the code below is auto generated do not remove the above tag */
26
27     public $__table = 'notice_tag';                      // table name
28     public $tag;                             // varchar(64)  primary_key not_null
29     public $notice_id;                       // int(4)  primary_key not_null
30     public $created;                         // datetime()   not_null default_0000-00-00%2000%3A00%3A00
31
32     /* the code above is auto generated do not remove the tag below */
33     ###END_AUTOCODE
34
35     public static function schemaDef()
36     {
37         return array(
38             'description' => 'Hash tags',
39             'fields' => array(
40                 'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'hash tag associated with this notice'),
41                 'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice tagged'),
42                 'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
43             ),
44             'primary key' => array('tag', 'notice_id'),
45             'foreign keys' => array(
46                 'notice_tag_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
47             ),
48             'indexes' => array(
49                 'notice_tag_created_idx' => array('created'),
50                 'notice_tag_notice_id_idx' => array('notice_id'),
51                 'notice_tag_tag_created_notice_id_idx' => array('tag', 'created', 'notice_id')
52             ),
53         );
54     }
55     
56     static function getStream($tag, $offset=0, $limit=20, $sinceId=0, $maxId=0)
57     {
58         // FIXME: Get the Profile::current value some other way
59         // to avoid confusino between queue processing and session.
60         $stream = new TagNoticeStream($tag, Profile::current());
61         return $stream;
62     }
63
64     function blowCache($blowLast=false)
65     {
66         self::blow('notice_tag:notice_ids:%s', Cache::keyize($this->tag));
67         if ($blowLast) {
68             self::blow('notice_tag:notice_ids:%s;last', Cache::keyize($this->tag));
69         }
70     }
71
72         static function url($tag)
73         {
74                 if (common_config('singleuser', 'enabled')) {
75                         // regular TagAction isn't set up in 1user mode
76                         $nickname = User::singleUserNickname();
77                         $url = common_local_url('showstream',
78                                                                         array('nickname' => $nickname,
79                                                                                   'tag' => $tag));
80                 } else {
81                         $url = common_local_url('tag', array('tag' => $tag));
82                 }
83
84                 return $url;
85         }
86
87     /**
88      * Checks whether the current profile is allowed (in scope) to see this tag.
89      *
90      * @return $inScope Whether the current profile is allowed to see this tag
91      */
92     public function isCurrentProfileInScope () {
93         // Check scope, default is allowed
94         $inScope = TRUE;
95
96         // 1) Get notice object and set id
97         $notice = new Notice();
98         $notice->id    = $this->notice_id;
99         $notice->scope = $this->scope;
100         /* NOISY-DEBUG: */ common_debug('[' . __METHOD__ . ':' . __LINE__ . '] this->tag=' . $this->tag . ',notice->id=' . $notice->id . ',notice->scope=' . $notice->scope);
101
102         // Is it private scope?
103         if ($notice->isPrivateScope()) {
104             // 2) Get current profile
105             $profile = Profile::current();
106
107             // Is the profile not set?
108             if (!$profile instanceof Profile) {
109                 // Public viewer shall not see a tag from a private dent (privacy leak)
110                 /* NOISY-DEBUG: */ common_debug('[' . __METHOD__ . ':' . __LINE__ . '] Not logged in, skipping ...');
111                 $inScope = FALSE;
112             } elseif (!$notice->inScope($profile)) {
113                 // Current profile is not in scope (not allowed to see) of notice
114                 /* NOISY-DEBUG: */ common_debug('[' . __METHOD__ . ':' . __LINE__ . '] profile->id=' . $profile->id . ' is not allowed to see this tag, skipping ...');
115                 $inScope = FALSE;
116             }
117         }
118
119         // Return result
120         /* NOISY-DEBUG: */ common_debug('[' . __METHOD__ . ':' . __LINE__ . '] this->tag=' . $this->tag . ',this->weight=' . $this->weight . ',inScope=' . intval($inScope) . ' - EXIT!');
121         return $inScope;
122     }
123 }