. * * @category GNUSocial * @package StatusNet * @author Shashi Gowda * @copyright 2009, 2010, StatusNet, Inc. * @copyright 2010, Free Software Foundation, Inc. * @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; # path to the plugin directory private $plugin_path = null; function initialize() { # set $this->plugin_path here. } function onAutoload($cls) { $actions = array(); foreach(array('Public', 'User', 'Group') as $a) { $actions[] = $a.$this->slug_plural.'Action'; } $actions[] = 'New'.$this->slug.'Action'; $actions[] = $this->dbclass; if(in_array($cls, $actions)) { require_once $this->plugin_path."/$cls.php"; return false; } return true; } # setup DB tables etc. function onCheckSchema() { $schema = Schema::get(); $schema->ensureTable(call_user_func( array($this->dbname, 'schemaDef'))); 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}')); # create new $m->connect($this->slug.'/new', array('action' => 'new'.$this->slug_plural)); # more to come in future: popular & lists. return true; } # use this to blow our caches. # the alternative is to decide # which keys 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('li'); } # 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(); } }