public function canDelete() { if (get_viewer()->admin()) { return true; } return false; }
/** * Subscribe Action. * * @param LibBaseTemplateObject $command The action object */ protected function _commandSubscribe($command) { $entity = $this->getController()->getItem(); $action = $entity->subscribed(get_viewer()) ? 'unsubscribe' : 'subscribe'; $label = JText::_('LIB-AN-ACTION-' . strtoupper($action)); $command->append(array('label' => $label))->href($entity->getURL())->class('action-' . $action)->setAttribute('data-action', $action); }
/** * Read * * @param KCommandContext $contxt * * @return void */ protected function _actionInvite($context) { $data = $context->data; $siteConfig = JFactory::getConfig(); $filter = $this->getService('koowa:filter.email'); $emails = array_filter((array) $data['email'], function ($email) use($filter) { return $filter->validate($email); }); $payloads = array(); $sent_one = false; foreach ($emails as $email) { $token = $this->getService('repos://site/invites.token')->getEntity(array('data' => array('inviter' => get_viewer(), 'serviceName' => 'email'))); $person = $this->getService('repos://site/people')->find(array('email' => $email)); $payload = array('email' => $email, 'sent' => false); if (!$person && $token->save()) { $payload['sent'] = true; $sent_one = true; $this->mail(array('subject' => JText::sprintf('COM-INVITES-MESSAGE-SUBJECT', $siteConfig->getValue('sitename')), 'to' => $email, 'layout' => false, 'template' => 'invite', 'data' => array('invite_url' => $token->getURL(), 'site_name' => $siteConfig->getValue('sitename'), 'sender' => $this->viewer))); } else { $payload['person'] = $person; } $payloads[] = $payload; } $content = $this->getView()->set(array('data' => $payloads))->display(); $context->response->setContent($content); if ($sent_one) { $this->setMessage('COM-INVITES-EMAIL-INVITES-SENT', 'info', false); } }
protected function _beforeRepositoryFetch(KCommandContext $context) { $viewer = get_viewer(); if (!$viewer->admin()) { $context->query->where('IF(@col(enabled)=FALSE,0,1)'); } }
/** * Adds a new post * * @param KCommandContext $context Context parameter * * @return void */ protected function _actionAdd($context) { $data = $context->data; $entity = parent::_actionAdd($context); //if a person posting a message on his profile //or if a target is not actor then it can't be a private message if (get_viewer()->eql($this->actor) || !is_person($this->actor)) { unset($data->private); } //if a private message then //set the privacy to subject/target if ($data->private) { $entity->setAccess(array($this->actor->id, get_viewer()->id)); } //create a notification for the subscribers and //the post owner as well if ($entity->owner->isSubscribable()) { //create a notification and pass the owner $notification = $this->createNotification(array('name' => 'note_add', 'object' => $entity, 'subscribers' => array($entity->owner->subscriberIds->toArray(), $entity->owner)))->setType('post', array('new_post' => true)); } if (!empty($data['channels'])) { $this->shareObject(array('object' => $entity, 'sharers' => $data['channels'])); } return $entity; }
/** * Build the route * * @param array An array of URL arguments * @return array The URL arguments to use to assemble the subsequent URL. */ public function build(&$query) { if (isset($query['alias']) && isset($query['id'])) { if (!isset($query['get'])) { $query['id'] = $query['id'] . '-' . $query['alias']; } unset($query['alias']); } $has_id = isset($query['id']); $segments = parent::build($query); if ($has_id) { if (isset($query['get'])) { $segments[] = $query['get']; if ($query['get'] == 'graph') { if (!isset($query['type'])) { $query['type'] = 'followers'; } $segments[] = $query['type']; unset($query['type']); } unset($query['get']); } } elseif (isset($query['oid'])) { if ($query['oid'] == 'viewer') { $query['oid'] = get_viewer()->uniqueAlias; } $segments[] = '@' . $query['oid']; unset($query['oid']); } return $segments; }
public function _actionAdd($context) { $context->data->access = $context->data->parent->access; $context->data->author = get_viewer(); $this->parent->resetRead(); $post = parent::_actionAdd($context); }
public function addToolbarCommands() { $viewer = get_viewer(); $entity = $this->getController()->getItem(); if (!$entity && $viewer->admin()) { $this->addCommand('addCategory'); $this->addCommand('addForum'); $this->addCommand('recount'); } if ($entity && $entity->parent !== NULL && !$viewer->guest() && !$entity->locked) { $this->addCommand('new'); } if ($entity && $entity->locked) { $this->addCommand('locked'); } if ($entity && $entity->parent !== NULL && ($entity->authorize('subscribe') || $entity->subscribed($viewer))) { $this->addCommand('subscribe'); } if ($entity && $entity->authorize('delete')) { $this->addCommand('lock'); $this->addCommand('enable'); $action = $entity->enabled ? 'disable' : 'enable'; $this->getCommand('enable')->dataAction($action); } if ($entity && $entity->authorize('edit')) { $this->addCommand('edit'); } if ($entity && $entity->authorize('delete')) { $this->addCommand('delete'); $this->getCommand('delete')->dataRedirect(JRoute::_($entity->parent->getURL())); } }
public function addToolbarCommands() { $entity = $this->getController()->getItem(); if ($entity && $entity->authorize('add') && !$entity->locked && !$entity->parent->locked) { $this->addCommand('new'); } if ($entity && ($entity->locked || $entity->parent->locked)) { $this->addCommand('locked'); } if ($entity && ($entity->authorize('subscribe') || $entity->subscribed(get_viewer()))) { $this->addCommand('subscribe'); } if ($entity && $entity->authorize('pin')) { $this->addCommand('pin'); } if ($entity && $entity->authorize('lock')) { $this->addCommand('lock'); } if ($entity && $entity->authorize('delete')) { $this->addCommand('enable'); $label = $entity->enabled ? 'COM-FORUMS-POST-DELETE' : 'COM-FORUMS-POST-RESTORE'; $action = $entity->enabled ? 'disable' : 'enable'; $this->getCommand('enable')->label(JText::_($label))->dataAction($action); } if ($entity && $entity->authorize('delete') && !$entity->enabled) { $this->addCommand('delete'); $this->getCommand('delete')->dataRedirect(JRoute::_($entity->parent->getURL())); } if ($entity && $entity->authorize('moderate')) { $this->addCommand('moderate'); } }
/** * Parses the URI. * * @param JURI $uri */ public function parse(&$url) { $this->_fixUrlForParsing($url); if (empty($url->path) && !isset($url->query['option'])) { $url->path = get_viewer()->guest() ? 'pages' : 'dashboard'; } $this->_parse($url); }
/** * Creates a notification. * * @param array $data Notification data * * @return ComNotificationDomainEntityNotification */ public function createNotification($data = array()) { $data = new KConfig($data); $data->append(array('component' => 'com_' . $this->_mixer->getIdentifier()->package, 'subject' => get_viewer())); $notification = $this->getService('repos:notifications.notification')->getEntity(array('data' => $data)); $notification->removeSubscribers(get_viewer()); return $notification; }
public function canModerate() { $viewer = get_viewer(); if ($viewer->admin()) { return true; } return false; }
/** * Creates a story. * * @param array|KCommandContext $config Config. Can be a story data or KCommandContext if the method * is used as a callback * * @return ComStoriesDomainEntityStory */ public function createStory($config = array()) { $config = new KConfig($config); $config->append(array('subject' => get_viewer(), 'owner' => get_viewer(), 'component' => 'com_' . $this->_mixer->getIdentifier()->package)); $story = $this->getService('repos://site/stories')->create($config->toArray()); //$story = $this->getService('com://site/stories.controller.story')->add($config->toArray()); $story->save(); return $story; }
public function markRead() { $viewer = get_viewer(); if (!$this->newNotificationIds->offsetExists($viewer->id)) { $ids = clone $this->newNotificationIds; $ids[] = $viewer->id; $this->set('newNotificationIds', $ids)->save(); } }
/** * Before _actionGet controller event * * @param KEvent $event Event object * * @return string */ public function onBeforeControllerGet(KEvent $event) { parent::onBeforeControllerGet($event); if ($this->getController()->isOwnable() && $this->getController()->actor) { $actor = pick($this->getController()->actor, get_viewer()); $this->setTitle(sprintf(JText::_('COM-STORIES-HEADER-STORIES'), $actor->name)); $this->setActor($actor); } }
/** * (non-PHPdoc) * @see LibBaseControllerPermissionAbstract::canExecute() */ public function _canExecute($action) { $viewer = get_viewer(); if ($viewer->hasSubscription()) { $ret = $this->getItem()->authorize('upgradepackage'); } else { $ret = $this->getItem()->authorize('subscribepackage'); } return $ret; }
/** * Initializes the default configuration for the object * * Called from {@link __construct()} as a first step of object instantiation. * * @param KConfig $config An optional KConfig object with configuration options. * * @return void */ protected function _initialize(KConfig $config) { $config->append(array('behaviors' => array('validatable', 'com://site/mailer.controller.behavior.mailer'))); parent::_initialize($config); AnHelperArray::unsetValues($config->behaviors, 'ownable'); //if it's a person view , set the default id to person if ($config->request->view == 'person') { $config->append(array('request' => array('id' => get_viewer()->id))); } }
/** * Authorize if viewer can read. * * @return bool */ public function canRead() { $viewer = get_viewer(); if ($viewer->admin()) { return true; } if ($this->getItem()->actorId == $viewer->id) { return true; } return false; }
/** * Before controller action. * * @param KEvent $event Event object * * @return string */ public function onBeforeControllerGet(KEvent $event) { parent::onBeforeControllerGet($event); $viewer = get_viewer(); $actor = pick($this->getController()->actor, $viewer); $layout = pick($this->getController()->layout, 'default'); $name = $this->getController()->getIdentifier()->name; $this->setTitle(JText::sprintf('COM-PAGES-ACTOR-HEADER-' . strtoupper($name) . 'S', $actor->name)); //create navigations $this->addNavigation('pages', JText::_('COM-PAGES-LINK-PAGES'), array('option' => 'com_pages', 'view' => 'pages', 'oid' => $actor->id), $name == 'page'); }
protected function _beforeRepositoryFetch($context) { if (KService::has('com:people.viewer') && is_person(get_viewer()) && get_viewer()->admin()) { return; } $query = $context->query; $config = pick($query->privacy, new KConfig()); $config->append(array('viewer' => get_viewer())); $where = $this->buildCondition(get_viewer(), $config); $query->where($where); }
public function onBeforeControllerGet(KEvent $event) { $actor = get_viewer(); $controller = $this->getController(); parent::onBeforeControllerGet($event); $this->addNavigation('index', translate('COM-FORUMS-INDEX'), 'option=com_forums', $controller->view == 'forums' || $controller->view == 'category' || $controller->view == 'forum'); $this->addNavigation('recent-posts', translate('COM-FORUMS-RECENT-POSTS'), 'option=forums&view=posts', $controller->view == 'posts'); if (!$actor->guest()) { $this->addNavigation('your-threads', translate('COM-FORUMS-YOUR-THREADS'), array('option' => 'com_forums', 'view' => 'threads', 'oid' => $actor->uniqueAlias), $controller->view == 'threads' && $controller->oid == $actor->uniqueAlias); } }
/** * onAfterRender handler. */ public function onAfterRoute() { global $mainframe; if ($mainframe->isAdmin()) { return; } if (KRequest::get('session.invite_token', 'string', null) && KRequest::get('get.option', 'string', null) == 'com_people' && get_viewer()->guest()) { $personConfig =& JComponentHelper::getParams('com_people'); $personConfig->set('allowUserRegistration', true); } }
/** * {@inheritdoc} */ protected function _beforeRepositoryFetch(KCommandContext $context) { if (KService::has('com:people.viewer') && is_person(get_viewer()) && get_viewer()->admin()) { return; } $query = $context->query; $repository = $query->getRepository(); $config = pick($query->privacy, new KConfig()); $config->append(array('visible_to_leaders' => true, 'viewer' => get_viewer(), 'graph_check' => true)); $where = $this->buildCondition('@col(id)', $config, '@col(access)'); $query->where($where); }
/** * Adds a comment. * * @param string|ComBaseDomainEntityComment $comment The comment to add * * @return ComBaseDomainEntityComment */ public function addComment($comment) { if (is_string($comment)) { $comment = KHelperString::trim($comment); $comment = array('author' => get_viewer(), 'body' => $comment, 'component' => $this->component); } $comment = $this->_mixer->comments->addNew($comment); if ($this->_mixer->isSubscribable() && !$this->_mixer->subscribed($comment->author)) { $this->_mixer->addSubscriber($comment->author); } return $comment; }
/** * {@inheritdoc} * * Only brings the media that are enabled or disabled but the viewer or one * of the actor they are administrating are the owner * * @param KCommandContext $context Context Parameter */ protected function _beforeRepositoryFetch(KCommandContext $context) { $query = $context->query; $repos = $query->getRepository(); if ($repos->hasBehavior('ownable')) { if (!get_viewer()->admin()) { $ids = get_viewer()->administratingIds->toArray(); $ids[] = get_viewer()->id; $ids = implode(',', $ids); $query->where("IF(@col(enabled) = FALSE, @col(owner.id) IN ({$ids}) ,1)"); } } }
protected function _actionVote($context) { // $data = new KConfig(); // $context->append(array( // 'data' => array( // 'target' => $this->getItem()->author // ) // )); // parent::_actionVote($context); $context->response->status = KHttpResponse::CREATED; $this->getItem()->voteup(get_viewer()); $notification = $this->_mixer->createNotification(array('name' => 'voteup', 'object' => $this->getItem(), 'target' => $this->getItem()->author, 'component' => $this->getItem()->component)); $context->response->content = $this->_mixer->execute('getvoters', $context); }
/** * Called before default layout * * @return void */ protected function _layoutDefault() { $story = $this->_state->getItem(); $helper = $this->getTemplate()->getHelper('parser'); $data = $helper->parse($story, $this->actor); $data['subject'] = $story->subject; $data['timestamp'] = $story->creationTime; $data['story'] = $story; $data['entity'] = $story; $viewer = get_viewer(); $commands = $this->getTemplate()->renderHelper('toolbar.commands', 'list'); $commands->offsetUnset('comment'); $this->set($data); }
/** * {@inheritdoc} * * Only brings the actor that are enabled * * @param KCommandContext $context Context Parameter */ protected function _beforeRepositoryFetch(KCommandContext $context) { if (get_viewer()->admin()) { return; } $query = $context->query; $repos = $query->getRepository(); if (get_viewer()->admin()) { $ids = get_viewer()->administratingIds->toArray(); } $ids[] = 0; $ids = implode(',', $ids); $query->where("IF(@col(enabled) = FALSE, @col(id) IN ({$ids}) ,1)"); }
/** * Displays selector for person usertypes. * * @param array of options * * @return html select */ public function usertypes($options = array()) { $viewer = get_viewer(); $options = new KConfig($options); $options->append(array('id' => 'person-userType', 'selected' => 'registered', 'name' => 'userType', 'class' => 'input-block-level')); $selected = $options->selected; unset($options->selected); $usertypes = array(ComPeopleDomainEntityPerson::USERTYPE_REGISTERED => JText::_('COM-PEOPLE-USERTYPE-REGISTERED'), ComPeopleDomainEntityPerson::USERTYPE_ADMINISTRATOR => JText::_('COM-PEOPLE-USERTYPE-ADMINISTRATOR')); if ($viewer->superadmin()) { $usertypes[ComPeopleDomainEntityPerson::USERTYPE_SUPER_ADMINISTRATOR] = JText::_('COM-PEOPLE-USERTYPE-SUPER-ADMINISTRATOR'); } $html = $this->getService('com:base.template.helper.html'); return $html->select($options->name, array('options' => $usertypes, 'selected' => $selected), KConfig::unbox($options)); }
/** * Authorize if viewer can add * * @return boolean */ public function canAdd() { $actor = $this->actor; $viewer = get_viewer(); if ($actor) { if ($viewer->blocking($actor)) { return false; } $action = 'com_' . $this->_mixer->getIdentifier()->package . ':' . $this->_mixer->getIdentifier()->name . ':add'; $ret = $actor->authorize('action', $action); return $ret !== false; } return false; }