3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
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.
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.
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/>.
20 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
22 class Notice_tag extends Managed_DataObject
25 /* the code below is auto generated do not remove the above tag */
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
32 /* the code above is auto generated do not remove the tag below */
35 public static function schemaDef()
38 'description' => 'Hash tags',
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, 'description' => 'date this record was created'),
44 'primary key' => array('tag', 'notice_id'),
45 'foreign keys' => array(
46 'notice_tag_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
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')
56 static function getStream($tag, $offset=0, $limit=20, $sinceId=0, $maxId=0)
58 $stream = new TagNoticeStream($tag);
60 return $stream->getNotices($offset, $limit, $sinceId, $maxId);
63 function blowCache($blowLast=false)
65 self::blow('notice_tag:notice_ids:%s', Cache::keyize($this->tag));
67 self::blow('notice_tag:notice_ids:%s;last', Cache::keyize($this->tag));
71 static function url($tag)
73 if (common_config('singleuser', 'enabled')) {
74 // regular TagAction isn't set up in 1user mode
75 $nickname = User::singleUserNickname();
76 $url = common_local_url('showstream',
77 array('nickname' => $nickname,
80 $url = common_local_url('tag', array('tag' => $tag));
87 * Checks whether the current profile is allowed (in scope) to see this tag.
89 * @return $inScope Whether the current profile is allowed to see this tag
91 function isCurrentProfileInScope () {
92 // Check scope, default is allowed
95 // 1) Get notice object and set id
96 $notice = new Notice();
97 $notice->id = $this->notice_id;
99 //* NOISY-DEBUG: */ common_debug('[' . __METHOD__ . ':' . __LINE__ . '] this->tag=' . $this->tag . ',this->notice_id=' . $this->notice_id . ' - Calling find() ... fetch() ...');
102 if ((!$notice->find()) || (!$notice->fetch())) {
103 // No longer valid, so better don't allow to see it
107 //* NOISY-DEBUG: */ common_debug('[' . __METHOD__ . ':' . __LINE__ . '] this->tag=' . $this->tag . ',notice->id=' . $notice->id . ',notice->scope=' . $notice->scope);
109 // Is it private scope?
110 if ($notice->isPrivateScope()) {
111 // 2) Get current profile
112 $profile = Profile::current();
114 // Is the profile not set?
115 if (!$profile instanceof Profile) {
116 // Public viewer shall not see a tag from a private dent (privacy leak)
117 //* NOISY-DEBUG: */ common_debug('[' . __METHOD__ . ':' . __LINE__ . '] Not logged in (public view).');
119 } elseif (!$notice->inScope($profile)) {
120 // Current profile is not in scope (not allowed to see) of notice
121 //* NOISY-DEBUG: */ common_debug('[' . __METHOD__ . ':' . __LINE__ . '] profile->id=' . $profile->id . ' is not allowed to see this tag.');
127 //* NOISY-DEBUG: */ common_debug('[' . __METHOD__ . ':' . __LINE__ . '] this->tag=' . $this->tag . ',this->weight=' . $this->weight . ',inScope=' . intval($inScope) . ' - EXIT!');