summaryrefslogtreecommitdiff
path: root/plugins/SocialObject/SocialObjectPlugin.php
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/SocialObject/SocialObjectPlugin.php')
-rw-r--r--plugins/SocialObject/SocialObjectPlugin.php164
1 files changed, 164 insertions, 0 deletions
diff --git a/plugins/SocialObject/SocialObjectPlugin.php b/plugins/SocialObject/SocialObjectPlugin.php
new file mode 100644
index 000000000..36cef0025
--- /dev/null
+++ b/plugins/SocialObject/SocialObjectPlugin.php
@@ -0,0 +1,164 @@
+<?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2009, StatusNet, Inc.
+ *
+ * Base class for all social object plugins
+ *
+ * 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 GNUSocial
+ * @package StatusNet
+ * @author Shashi Gowda <connect2shashi@gmail.com>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://daisycha.in
+ */
+
+if (!defined('STATUSNET')) {
+ exit(1);
+}
+
+class SocialObjectPlugin extends Plugin
+{
+ # name to use in the UI
+ public $name=null;
+ # plural name for menus
+ private $name_plural=null;
+ # short name for use in urls
+ private $slug=null;
+ # plural slug
+ private $slug_plural=null;
+ # Database class
+ private $dbclass=null;
+
+ # setup DB tables etc.
+ function onCheckSchema()
+ {
+ $schema = Schema::get();
+ $classname = $this->dbclass
+ $schema->ensureTable($classname::tableDef());
+ return true;
+ }
+
+ # Add some urls to be routed to respective actions
+ function onRouterInitialized(&$m)
+ {
+ # timeline of all public social-objects
+ $m->connect('public/'.$this->slug_plural,
+ array('action' => 'public'.$this->slug_plural));
+ # timeline of this social-object for each user
+ $m->connect(':user/'.$this->slug_plural,
+ array('action' => 'user'.$this->slug_plural,
+ 'user' => '[a-zA-Z0-9]{1,64}'));
+ # timeline of this social-object for groups
+ $m->connect('group/:group/'.$this->slug_plural,
+ array('action' => 'group'.$this->slug_plural,
+ 'group' => '[a-zA-Z0-9]{1,64}'));
+ return true;
+ }
+
+ # use this to blow our caches.
+ # the alternative is to decide
+ # which caches to blow, no thanks
+ # Notice class already does that
+ function onEndCacheDelete($key)
+ {
+ $keys = array('public:notice_ids' => 'public:%s:notice_ids',
+ 'profile:notice_ids:' => 'profile:%s:notice_ids:',
+ 'user_group:notice_ids:' => 'user_group:%s:notice_ids:');
+ foreach($keys as $s => $r) {
+ $len = strlen($s);
+ # if key starts with $s,
+ if(substr($key, 0, $len) === $s) {
+ Memcached_DataObject::blow(sprintf($r, $this->slug)));
+ }
+ }
+ }
+
+ # Menu on public page
+ function onEndPublicGroupNav($action)
+ {
+ $action->out->menuItem(common_local_url('public'.$this->slug_plural), $this->name_plural);
+ return true;
+ }
+
+ # Menu on personal pages (/user, /user/all, /user/replies etc)
+ function onEndPersonalGroupNav($action)
+ {
+ $action->out->menuItem(common_local_url('user'.$this->slug_plural,
+ array('user' => $action->trimmed('nickname'))), $this->name_plural);
+ return true;
+ }
+
+ # Menu on group pages
+ function onEndGroupGroupNav($action)
+ {
+ $action->out->menuItem(common_local_url('user'.$this->slug_plural,
+ array('group' => $action->trimmed('nickname'))), $this->name_plural);
+ return true;
+ }
+
+ # This is the menu for cranking up the notice form
+ function onShowSocialSwitcher($form)
+ {
+ $form->out->elementStart('li', "social-switch {$this->slug}-switch");
+ $form->out->element('a',
+ array('href' => common_local_url('shownoticeform').'#social-'.$this->slug,
+ 'title' => $this->name)
+ , $this->name);
+ $form->out->elementEnd('ul');
+ }
+
+ # if the notice being shown has metadata for
+ # a social-object then render it differently
+ function onStartShowNoticeItem($widget)
+ {
+ if($this->isThisObject($widget->notice)) {
+
+ $this->showItem($widget);
+ $widget->showNoticeInfo();
+ $widget->showNoticeOptions();
+ # don't want to break other plugins
+ Event::handle('EndShowNoticeItem', array($widget));
+ # return false, i.e stop rendering the notice
+ return false;
+ }
+ # continue with showing notice
+ return true;
+ }
+
+ # this hook needs to be patched to upstream
+ function onStartSingleNoticeItem($widget)
+ {
+ return $this->showItem($widget);
+ }
+
+ # does the notice have metadata related to this social object?
+ function isThisObject($notice)
+ {
+ $obj=call_user_func($this->dbclass, 'staticGet',
+ array(array('id' => $notice->id)));
+ return !empty($obj);
+ }
+
+ # show object in timeline
+ function showItem($widget)
+ {
+ $classname = $this->slug.'Widget';
+ $widget=new $classname();
+ $widget->show();
+ }
+}