2010-12-18 16:27:14 +09:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2010, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* A plugin to enable social-bookmarking functionality
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @category SocialBookmark
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2010 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('STATUSNET')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bookmark plugin main class
|
|
|
|
*
|
|
|
|
* @category Bookmark
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Brion Vibber <brionv@status.net>
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2010 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
|
|
|
|
class BookmarkPlugin extends Plugin
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Database schema setup
|
|
|
|
*
|
|
|
|
* @see Schema
|
|
|
|
* @see ColumnDef
|
|
|
|
*
|
|
|
|
* @return boolean hook value; true means continue processing, false means stop.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function onCheckSchema()
|
|
|
|
{
|
|
|
|
$schema = Schema::get();
|
|
|
|
|
|
|
|
// For storing user-submitted flags on profiles
|
|
|
|
|
|
|
|
$schema->ensureTable('notice_bookmark',
|
|
|
|
array(new ColumnDef('notice_id',
|
|
|
|
'integer',
|
|
|
|
null,
|
2010-12-20 00:18:33 +09:00
|
|
|
false,
|
2010-12-18 16:36:13 +09:00
|
|
|
'PRI'),
|
|
|
|
new ColumnDef('title',
|
|
|
|
'varchar',
|
|
|
|
255),
|
|
|
|
new ColumnDef('description',
|
|
|
|
'text')));
|
2010-12-18 16:27:14 +09:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-18 16:39:44 +09:00
|
|
|
function onNoticeDeleteRelated($notice)
|
|
|
|
{
|
|
|
|
$nb = Notice_bookmark::staticGet('notice_id', $notice->id);
|
|
|
|
|
|
|
|
if (!empty($nb)) {
|
|
|
|
$nb->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-19 07:21:40 +09:00
|
|
|
function onEndShowStyles($action)
|
|
|
|
{
|
|
|
|
$action->style('.bookmark_tags li { display: inline; }');
|
2010-12-20 00:18:33 +09:00
|
|
|
$action->style('.bookmark_mentions li { display: inline; }');
|
2010-12-19 07:21:40 +09:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-18 16:27:14 +09:00
|
|
|
/**
|
|
|
|
* Load related modules when needed
|
|
|
|
*
|
|
|
|
* @param string $cls Name of the class to be loaded
|
|
|
|
*
|
|
|
|
* @return boolean hook value; true means continue processing, false means stop.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function onAutoload($cls)
|
|
|
|
{
|
|
|
|
$dir = dirname(__FILE__);
|
|
|
|
|
|
|
|
switch ($cls)
|
|
|
|
{
|
|
|
|
case 'NewbookmarkAction':
|
|
|
|
include_once $dir.'/newbookmark.php';
|
|
|
|
return false;
|
|
|
|
case 'Notice_bookmark':
|
|
|
|
include_once $dir.'/'.$cls.'.php';
|
|
|
|
return false;
|
|
|
|
case 'BookmarkForm':
|
2010-12-21 02:04:02 +09:00
|
|
|
case 'DeliciousBackupImporter':
|
2010-12-18 16:27:14 +09:00
|
|
|
include_once $dir.'/'.strtolower($cls).'.php';
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Map URLs to actions
|
|
|
|
*
|
|
|
|
* @param Net_URL_Mapper $m path-to-action mapper
|
|
|
|
*
|
|
|
|
* @return boolean hook value; true means continue processing, false means stop.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function onRouterInitialized($m)
|
|
|
|
{
|
|
|
|
$m->connect('main/bookmark/new',
|
|
|
|
array('action' => 'newbookmark'),
|
|
|
|
array('id' => '[0-9]+'));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-19 07:21:40 +09:00
|
|
|
function onStartShowNoticeItem($nli)
|
|
|
|
{
|
|
|
|
$nb = Notice_bookmark::staticGet('notice_id',
|
|
|
|
$nli->notice->id);
|
|
|
|
|
|
|
|
if (!empty($nb)) {
|
|
|
|
$att = $nli->notice->attachments();
|
|
|
|
$nli->out->elementStart('h3');
|
|
|
|
$nli->out->element('a',
|
|
|
|
array('href' => $att[0]->url),
|
|
|
|
$nb->title);
|
|
|
|
$nli->out->elementEnd('h3');
|
|
|
|
$nli->out->element('p',
|
|
|
|
array('class' => 'bookmark_description'),
|
|
|
|
$nb->description);
|
|
|
|
$nli->out->elementStart('p');
|
|
|
|
$nli->out->element('a', array('href' => $nli->profile->profileurl,
|
|
|
|
'class' => 'bookmark_author',
|
|
|
|
'title' => $nli->profile->getBestName()),
|
|
|
|
$nli->profile->getBestName());
|
|
|
|
$nli->out->elementEnd('p');
|
|
|
|
$tags = $nli->notice->getTags();
|
|
|
|
$nli->out->elementStart('ul', array('class' => 'bookmark_tags'));
|
|
|
|
foreach ($tags as $tag) {
|
|
|
|
$nli->out->elementStart('li');
|
2010-12-20 00:18:33 +09:00
|
|
|
$nli->out->element('a',
|
|
|
|
array('rel' => 'tag',
|
|
|
|
'href' => Notice_tag::url($tag)),
|
2010-12-19 07:21:40 +09:00
|
|
|
$tag);
|
|
|
|
$nli->out->elementEnd('li');
|
|
|
|
$nli->out->text(' ');
|
|
|
|
}
|
|
|
|
$nli->out->elementEnd('ul');
|
2010-12-20 00:18:33 +09:00
|
|
|
$replies = $nli->notice->getReplies();
|
|
|
|
if (!empty($replies)) {
|
|
|
|
$nli->out->elementStart('ul', array('class' => 'bookmark_mentions'));
|
|
|
|
foreach ($replies as $reply) {
|
|
|
|
$other = Profile::staticGet('id', $reply);
|
|
|
|
$nli->out->elementStart('li');
|
|
|
|
$nli->out->element('a', array('rel' => 'tag',
|
|
|
|
'href' => $other->profileurl,
|
|
|
|
'title' => $other->getBestName()),
|
|
|
|
sprintf('for:%s', $other->nickname));
|
|
|
|
$nli->out->elementEnd('li');
|
|
|
|
$nli->out->text(' ');
|
|
|
|
}
|
|
|
|
$nli->out->elementEnd('ul');
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onStartActivityObjectFromNotice($notice, &$object)
|
|
|
|
{
|
|
|
|
$nb = Notice_bookmark::staticGet('notice_id',
|
|
|
|
$notice->id);
|
|
|
|
|
|
|
|
if (!empty($nb)) {
|
|
|
|
|
|
|
|
$object->id = $notice->uri;
|
|
|
|
$object->type = ActivityObject::BOOKMARK;
|
|
|
|
$object->title = $nb->title;
|
|
|
|
$object->summary = $nb->summary;
|
|
|
|
|
|
|
|
// Attributes of the URL
|
|
|
|
|
|
|
|
$attachments = $notice->attachments();
|
|
|
|
|
|
|
|
if (count($attachments) != 1) {
|
|
|
|
throw new ServerException(_('Bookmark notice with the wrong number of attachments.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$target = $attachments[0];
|
|
|
|
|
|
|
|
$attrs = array('rel' => 'related',
|
|
|
|
'href' => $target->url);
|
|
|
|
|
|
|
|
if (!empty($target->title)) {
|
|
|
|
$attrs['title'] = $target->title;
|
|
|
|
}
|
|
|
|
|
|
|
|
$object->extra[] = array('link', $attrs);
|
|
|
|
|
|
|
|
// Attributes of the thumbnail, if any
|
|
|
|
|
|
|
|
$thumbnail = $target->getThumbnail();
|
|
|
|
|
|
|
|
if (!empty($thumbnail)) {
|
|
|
|
$tattrs = array('rel' => 'preview',
|
|
|
|
'href' => $thumbnail->url);
|
|
|
|
|
|
|
|
if (!empty($thumbnail->width)) {
|
|
|
|
$tattrs['media:width'] = $thumbnail->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($thumbnail->height)) {
|
|
|
|
$tattrs['media:height'] = $thumbnail->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
$object->extra[] = array('link', $attrs);
|
|
|
|
}
|
|
|
|
|
2010-12-19 07:21:40 +09:00
|
|
|
return false;
|
|
|
|
}
|
2010-12-20 00:18:33 +09:00
|
|
|
|
2010-12-19 07:21:40 +09:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-18 16:27:14 +09:00
|
|
|
function onPluginVersion(&$versions)
|
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'Sample',
|
|
|
|
'version' => STATUSNET_VERSION,
|
|
|
|
'author' => 'Evan Prodromou',
|
|
|
|
'homepage' => 'http://status.net/wiki/Plugin:Bookmark',
|
|
|
|
'rawdescription' =>
|
|
|
|
_m('Simple extension for supporting bookmarks.'));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|