Ejemplo n.º 1
0
 /**
  * Show the menu
  *
  * @return void
  */
 function show()
 {
     $this->actionName = $this->action->trimmed('action');
     $this->action->elementStart('ul', array('class' => 'nav'));
     if (Event::handle('StartPublicGroupNav', array($this))) {
         if (!common_config('singleuser', 'enabled')) {
             // TRANS: Menu item in search group navigation panel.
             $this->out->menuItem(common_local_url('public'), _m('MENU', 'Public'), _('Public timeline'), $this->actionName == 'public', 'nav_timeline_public');
         }
         // TRANS: Menu item in search group navigation panel.
         $this->out->menuItem(common_local_url('groups'), _m('MENU', 'Groups'), _('User groups'), $this->actionName == 'groups', 'nav_groups');
         if (!common_config('performance', 'high')) {
             // TRANS: Menu item in search group navigation panel.
             $this->out->menuItem(common_local_url('publictagcloud'), _m('MENU', 'Recent tags'), _('Recent tags'), $this->actionName == 'publictagcloud', 'nav_recent-tags');
         }
         if (count(common_config('nickname', 'featured')) > 0) {
             // TRANS: Menu item in search group navigation panel.
             $this->out->menuItem(common_local_url('featured'), _m('MENU', 'Featured'), _('Featured users'), $this->actionName == 'featured', 'nav_featured');
         }
         if (!common_config('singleuser', 'enabled')) {
             // TRANS: Menu item in search group navigation panel.
             $this->out->menuItem(common_local_url('favorited'), _m('MENU', 'Popular'), _('Popular notices'), $this->actionName == 'favorited', 'nav_timeline_favorited');
         }
         Event::handle('EndPublicGroupNav', array($this));
     }
     $this->action->elementEnd('ul');
 }
Ejemplo n.º 2
0
 /**
  * Handle the request
  *
  * Show the user's groups
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $sitename = common_config('site', 'name');
     // TRANS: Message is used as a title. %s is a site name.
     $title = sprintf(_("%s groups"), $sitename);
     $taguribase = TagURI::base();
     $id = "tag:{$taguribase}:Groups";
     $link = common_local_url('groups');
     $subtitle = sprintf(_("groups on %s"), $sitename);
     switch ($this->format) {
         case 'xml':
             $this->showXmlGroups($this->groups);
             break;
         case 'rss':
             $this->showRssGroups($this->groups, $title, $link, $subtitle);
             break;
         case 'atom':
             $selfuri = common_root_url() . 'api/statusnet/groups/list_all.atom';
             $this->showAtomGroups($this->groups, $title, $id, $link, $subtitle, $selfuri);
             break;
         case 'json':
             $this->showJsonGroups($this->groups);
             break;
         default:
             $this->clientError(_('API method not found.'), 404, $this->format);
             break;
     }
 }
Ejemplo n.º 3
0
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->arg('page') && $this->arg('page') != 1) {
             $args['page'] = $this->arg['page'];
         }
         common_redirect(common_local_url($this->trimmed('action'), $args), 301);
         return false;
     }
     $this->user = User::staticGet('nickname', $nickname);
     if (!$this->user) {
         $this->clientError(_m('No such user.'), 404);
         return false;
     }
     $this->profile = $this->user->getProfile();
     if (!$this->profile) {
         $this->serverError(_m('User has no profile.'));
         return false;
     }
     $page = $this->trimmed('page');
     if (!empty($page) && Validate::number($page)) {
         $this->page = $page + 0;
     } else {
         $this->page = 1;
     }
     $this->notices = empty($this->tag) ? $this->user->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1) : $this->user->getTaggedNotices($this->tag, ($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null);
     return true;
 }
Ejemplo n.º 4
0
function updateGroupUrls()
{
    printfnq("Updating group URLs...\n");
    $group = new User_group();
    if ($group->find()) {
        while ($group->fetch()) {
            try {
                printfv("Updating group {$group->nickname}...");
                $orig = User_group::getKV('id', $group->id);
                if (!empty($group->original_logo)) {
                    $group->original_logo = Avatar::url(basename($group->original_logo));
                    $group->homepage_logo = Avatar::url(basename($group->homepage_logo));
                    $group->stream_logo = Avatar::url(basename($group->stream_logo));
                    $group->mini_logo = Avatar::url(basename($group->mini_logo));
                }
                // XXX: this is a hack to see if a group is local or not
                $localUri = common_local_url('groupbyid', array('id' => $group->id));
                if ($group->getUri() != $localUri) {
                    $group->mainpage = common_local_url('showgroup', array('nickname' => $group->nickname));
                }
                $group->update($orig);
                printfv("DONE.");
            } catch (Exception $e) {
                echo "Can't update avatars for group " . $group->nickname . ": " . $e->getMessage();
            }
        }
    }
}
Ejemplo n.º 5
0
 function prepare($args)
 {
     parent::prepare($args);
     if (common_config('singleuser', 'enabled')) {
         $nickname_arg = User::singleUserNickname();
     } else {
         $nickname_arg = $this->arg('nickname');
     }
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->arg('page') && $this->arg('page') != 1) {
             $args['page'] = $this->arg['page'];
         }
         common_redirect(common_local_url('peopletagsforuser', $args), 301);
     }
     $this->user = User::getKV('nickname', $nickname);
     if (!$this->user) {
         // TRANS: Client error displayed trying to perform an action related to a non-existing user.
         $this->clientError(_('No such user.'), 404);
     }
     $this->tagged = $this->user->getProfile();
     if (!$this->tagged) {
         // TRANS: Error message displayed when referring to a user without a profile.
         $this->serverError(_('User has no profile.'));
     }
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Handle input and output a page
  *
  * @param array $args $_REQUEST arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (!common_logged_in()) {
         $this->clientError(_('Not logged in.'));
         return;
     } else {
         if (!common_is_real_login()) {
             // Cookie theft means that automatic logins can't
             // change important settings or see private info, and
             // _all_ our settings are important
             common_set_returnto($this->selfUrl());
             $user = common_current_user();
             if (Event::handle('RedirectToLogin', array($this, $user))) {
                 common_redirect(common_local_url('login'), 303);
             }
         } else {
             if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                 $this->handlePost();
             } else {
                 $this->showForm();
             }
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Content area of the page
  *
  * Shows a form for uploading an avatar.
  *
  * @return void
  */
 function showContent()
 {
     $user = common_current_user();
     $this->elementStart('form', array('method' => 'post', 'id' => 'form_settings_other', 'class' => 'form_settings', 'action' => common_local_url('othersettings')));
     $this->elementStart('fieldset');
     $this->hidden('token', common_session_token());
     $this->elementStart('ul', 'form_data');
     $shorteners = array();
     Event::handle('GetUrlShorteners', array(&$shorteners));
     $services = array();
     foreach ($shorteners as $name => $value) {
         $services[$name] = $name;
         if ($value['freeService']) {
             $services[$name] .= _(' (free service)');
         }
     }
     if ($services) {
         asort($services);
         $this->elementStart('li');
         $this->dropdown('urlshorteningservice', _('Shorten URLs with'), $services, _('Automatic shortening service to use.'), false, $user->urlshorteningservice);
         $this->elementEnd('li');
     }
     $this->elementStart('li');
     $this->checkbox('viewdesigns', _('View profile designs'), $user->viewdesigns, _('Show or hide profile designs.'));
     $this->elementEnd('li');
     $this->elementEnd('ul');
     $this->submit('save', _('Save'));
     $this->elementEnd('fieldset');
     $this->elementEnd('form');
 }
Ejemplo n.º 8
0
 /**
  * Show the widget
  *
  * @return void
  */
 function show()
 {
     $this->out->elementStart('li', array('class' => 'h-entry notice', 'id' => 'message-' . $this->message->id));
     $profile = $this->getMessageProfile();
     $this->out->elementStart('a', array('href' => $profile->profileurl, 'class' => 'p-author'));
     $avatarUrl = $profile->avatarUrl(AVATAR_STREAM_SIZE);
     $this->out->element('img', array('src' => $avatarUrl, 'class' => 'avatar u-photo', 'width' => AVATAR_STREAM_SIZE, 'height' => AVATAR_STREAM_SIZE, 'alt' => $profile->getBestName()));
     $this->out->element('span', array('class' => 'nickname fn'), $profile->getNickname());
     $this->out->elementEnd('a');
     // FIXME: URL, image, video, audio
     $this->out->elementStart('div', array('class' => 'e-content'));
     $this->out->raw($this->message->rendered);
     $this->out->elementEnd('div');
     $messageurl = common_local_url('showmessage', array('message' => $this->message->id));
     // XXX: we need to figure this out better. Is this right?
     if (strcmp($this->message->uri, $messageurl) != 0 && preg_match('/^http/', $this->message->uri)) {
         $messageurl = $this->message->uri;
     }
     $this->out->elementStart('div', 'entry-metadata');
     $this->out->elementStart('a', array('rel' => 'bookmark', 'class' => 'timestamp', 'href' => $messageurl));
     $dt = common_date_iso8601($this->message->created);
     $this->out->element('time', array('class' => 'dt-published', 'datetime' => common_date_iso8601($this->message->created), 'title' => common_exact_date($this->message->created)), common_date_string($this->message->created));
     $this->out->elementEnd('a');
     if ($this->message->source) {
         $this->out->elementStart('span', 'source');
         // FIXME: bad i18n. Device should be a parameter (from %s).
         // TRANS: Followed by notice source (usually the client used to send the notice).
         $this->out->text(_('from'));
         $this->showSource($this->message->source);
         $this->out->elementEnd('span');
     }
     $this->out->elementEnd('div');
     $this->out->elementEnd('li');
 }
Ejemplo n.º 9
0
 function showTagsDropdown()
 {
     $tag = $this->trimmed('tag');
     $tags = $this->getAllTags();
     $content = array();
     foreach ($tags as $t) {
         $content[$t] = $t;
     }
     if ($tags) {
         $this->elementStart('dl', array('id' => 'filter_tags'));
         $this->element('dt', null, _('Tags'));
         $this->elementStart('dd');
         $this->elementStart('ul');
         $this->elementStart('li', array('id' => 'filter_tags_all', 'class' => 'child_1'));
         $this->element('a', array('href' => common_local_url($this->trimmed('action'), array('nickname' => $this->target->getNickname()))), _m('TAGS', 'All'));
         $this->elementEnd('li');
         $this->elementStart('li', array('id' => 'filter_tags_item'));
         $this->elementStart('form', array('name' => 'bytag', 'id' => 'form_filter_bytag', 'action' => common_path('?action=' . $this->getActionName()), 'method' => 'post'));
         $this->elementStart('fieldset');
         // TRANS: Fieldset legend on gallery action page.
         $this->element('legend', null, _('Select tag to filter'));
         // TRANS: Dropdown field label on gallery action page for a list containing tags.
         $this->dropdown('tag', _('Tag'), $content, _('Choose a tag to narrow list.'), false, $tag);
         $this->hidden('nickname', $this->target->getNickname());
         // TRANS: Submit button text on gallery action page.
         $this->submit('submit', _m('BUTTON', 'Go'));
         $this->elementEnd('fieldset');
         $this->elementEnd('form');
         $this->elementEnd('li');
         $this->elementEnd('ul');
         $this->elementEnd('dd');
         $this->elementEnd('dl');
     }
 }
Ejemplo n.º 10
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $cur = common_current_user();
     if (empty($cur)) {
         throw new ClientException(_('Only for logged-in users'), 403);
     }
     $nicknameArg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nicknameArg);
     if ($nickname != $nicknameArg) {
         $url = common_local_url('groupinbox', array('nickname' => $nickname));
         common_redirect($url);
         return false;
     }
     $localGroup = Local_group::staticGet('nickname', $nickname);
     if (empty($localGroup)) {
         throw new ClientException(_('No such group'), 404);
     }
     $this->group = User_group::staticGet('id', $localGroup->group_id);
     if (empty($this->group)) {
         throw new ClientException(_('No such group'), 404);
     }
     if (!$cur->isMember($this->group)) {
         throw new ClientException(_('Only for members'), 403);
     }
     $this->page = $this->trimmed('page');
     if (!$this->page) {
         $this->page = 1;
     }
     $this->gm = Group_message::forGroup($this->group, ($this->page - 1) * MESSAGES_PER_PAGE, MESSAGES_PER_PAGE + 1);
     return true;
 }
Ejemplo n.º 11
0
 /**
  * Class handler.
  *
  * @param array $args query arguments
  *
  * @return boolean false if user doesn't exist
  */
 function handle($args)
 {
     parent::handle($args);
     $type = $this->trimmed('type');
     $short_name = '';
     if ($type == 'people') {
         $type = 'peoplesearch';
         // TRANS: ShortName in the OpenSearch interface when trying to find users.
         $short_name = _('People Search');
     } else {
         $type = 'noticesearch';
         // TRANS: ShortName in the OpenSearch interface when trying to find notices.
         $short_name = _('Notice Search');
     }
     header('Content-Type: application/opensearchdescription+xml');
     $this->startXML();
     $this->elementStart('OpenSearchDescription', array('xmlns' => 'http://a9.com/-/spec/opensearch/1.1/'));
     $short_name = common_config('site', 'name') . ' ' . $short_name;
     $this->element('ShortName', null, $short_name);
     $this->element('Contact', null, common_config('site', 'email'));
     $this->element('Url', array('type' => 'text/html', 'method' => 'get', 'template' => str_replace('---', '{searchTerms}', common_local_url($type, array('q' => '---')))));
     $this->element('Image', array('height' => 16, 'width' => 16, 'type' => 'image/vnd.microsoft.icon'), common_path('favicon.ico'));
     $this->element('Image', array('height' => 50, 'width' => 50, 'type' => 'image/png'), Theme::path('logo.png'));
     $this->element('AdultContent', null, 'false');
     $this->element('Language', null, common_language());
     $this->element('OutputEncoding', null, 'UTF-8');
     $this->element('InputEncoding', null, 'UTF-8');
     $this->elementEnd('OpenSearchDescription');
     $this->endXML();
 }
Ejemplo n.º 12
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->checkSessionToken();
     if (!common_logged_in()) {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $this->clientError(_('Not logged in.'));
         } else {
             // Redirect to login.
             common_set_returnto($this->selfUrl());
             $user = common_current_user();
             if (Event::handle('RedirectToLogin', array($this, $user))) {
                 common_redirect(common_local_url('login'), 303);
             }
         }
         return false;
     }
     $id = $this->trimmed('profileid');
     if (!$id) {
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (!$this->profile) {
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     return true;
 }
Ejemplo n.º 13
0
 /**
  * Prepare for the action
  *
  * We check to see that the user is logged in, has
  * authenticated in this session, and has the right
  * to configure the site.
  *
  * @param array $args Array of arguments from Web driver
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     // User must be logged in.
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
     }
     $user = common_current_user();
     // ...because they're logged in
     assert(!empty($user));
     // It must be a "real" login, not saved cookie login
     if (!common_is_real_login()) {
         // Cookie theft is too easy; we require automatic
         // logins to re-authenticate before admining the site
         common_set_returnto($this->selfUrl());
         if (Event::handle('RedirectToLogin', array($this, $user))) {
             common_redirect(common_local_url('login'), 303);
         }
     }
     // User must have the right to change admin settings
     if (!$user->hasRight(Right::CONFIGURESITE)) {
         // TRANS: Client error message thrown when a user tries to change admin settings but has no access rights.
         $this->clientError(_('You cannot make changes to this site.'));
     }
     // This panel must be enabled
     $name = $this->trimmed('action');
     $name = mb_substr($name, 0, -10);
     if (!self::canAdmin($name)) {
         // TRANS: Client error message throw when a certain panel's settings cannot be changed.
         $this->clientError(_('Changes to that panel are not allowed.'), 403);
     }
     return true;
 }
Ejemplo n.º 14
0
 /**
  * We've gotten a post event on the Salmon backchannel, probably a reply.
  */
 function handlePost()
 {
     // @fixme process all objects?
     switch ($this->activity->objects[0]->type) {
         case ActivityObject::ARTICLE:
         case ActivityObject::BLOGENTRY:
         case ActivityObject::NOTE:
         case ActivityObject::STATUS:
         case ActivityObject::COMMENT:
             break;
         default:
             // TRANS: Client exception.
             throw new ClientException('Cannot handle that kind of post.');
     }
     // Notice must be to the attention of this group
     if (empty($this->activity->context->attention)) {
         // TRANS: Client exception.
         throw new ClientException("Not to the attention of anyone.");
     } else {
         $uri = common_local_url('groupbyid', array('id' => $this->group->id));
         if (!array_key_exists($uri, $this->activity->context->attention)) {
             // TRANS: Client exception.
             throw new ClientException("Not to the attention of this group.");
         }
     }
     try {
         $this->saveNotice();
     } catch (AlreadyFulfilledException $e) {
         return;
     }
 }
Ejemplo n.º 15
0
 protected function doPost()
 {
     try {
         $request = Subscription_queue::pkeyGet(array('subscriber' => $this->scoped->id, 'subscribed' => $this->target->id));
         if ($request instanceof Subscription_queue) {
             $request->abort();
         }
     } catch (AlreadyFulfilledException $e) {
         common_debug('Tried to cancel a non-existing pending subscription');
     }
     if (GNUsocial::isAjax()) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Title after unsubscribing from a group.
         $this->element('title', null, _m('TITLE', 'Unsubscribed'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $subscribe = new SubscribeForm($this, $this->target);
         $subscribe->show();
         $this->elementEnd('body');
         $this->endHTML();
         exit;
     }
     common_redirect(common_local_url('subscriptions', array('nickname' => $this->scoped->getNickname())), 303);
 }
Ejemplo n.º 16
0
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         common_redirect(common_local_url('hcard', $args), 301);
         return false;
     }
     $this->user = User::staticGet('nickname', $nickname);
     if (!$this->user) {
         // TRANS: Client error displayed when trying to get a user hCard for a non-existing user.
         $this->clientError(_('No such user.'), 404);
         return false;
     }
     $this->profile = $this->user->getProfile();
     if (!$this->profile) {
         // TRANS: Server error displayed when trying to get a user hCard for a user without a profile.
         $this->serverError(_('User has no profile.'));
         return false;
     }
     return true;
 }
Ejemplo n.º 17
0
 function prepare($args)
 {
     parent::prepare($args);
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->page != 1) {
             $args['page'] = $this->page;
         }
         common_redirect(common_local_url('groupmembers', $args), 301);
         return false;
     }
     if (!$nickname) {
         // TRANS: Client error displayed when trying to view group members without providing a group nickname.
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $local = Local_group::staticGet('nickname', $nickname);
     if (!$local) {
         // TRANS: Client error displayed when trying to view group members for a non-existing group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         // TRANS: Client error displayed when trying to view group members for an object that is not a group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     return true;
 }
Ejemplo n.º 18
0
 function prepare($args)
 {
     Action::prepare($args);
     // skip the ProfileAction code and replace it...
     $id = $this->arg('id');
     $this->user = false;
     $this->profile = Profile::staticGet('id', $id);
     if (!$this->profile) {
         // TRANS: Error message displayed when referring to a user without a profile.
         $this->serverError(_m('User has no profile.'));
         return false;
     }
     $user = User::staticGet('id', $this->profile->id);
     if ($user) {
         // This is a local user -- send to their regular profile.
         $url = common_local_url('showstream', array('nickname' => $user->nickname));
         common_redirect($url);
         return false;
     }
     $this->tag = $this->trimmed('tag');
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     common_set_returnto($this->selfUrl());
     $p = Profile::current();
     if (empty($this->tag)) {
         $stream = new ProfileNoticeStream($this->profile, $p);
     } else {
         $stream = new TaggedProfileNoticeStream($this->profile, $this->tag, $p);
     }
     $this->notice = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
     return true;
 }
Ejemplo n.º 19
0
 /**
  * Content area of the page
  *
  * Shows a form for changing the password
  *
  * @return void
  */
 function showContent()
 {
     $user = common_current_user();
     $this->elementStart('form', array('method' => 'POST', 'id' => 'form_password', 'class' => 'form_settings', 'action' => common_local_url('passwordsettings')));
     $this->elementStart('fieldset');
     // TRANS: Fieldset legend on page where to change password.
     $this->element('legend', null, _('Password change'));
     $this->hidden('token', common_session_token());
     $this->elementStart('ul', 'form_data');
     // Users who logged in with OpenID won't have a pwd
     if ($user->password) {
         $this->elementStart('li');
         // TRANS: Field label on page where to change password.
         $this->password('oldpassword', _('Old password'));
         $this->elementEnd('li');
     }
     $this->elementStart('li');
     // TRANS: Field label on page where to change password.
     $this->password('newpassword', _('New password'), _('6 or more characters.'));
     $this->elementEnd('li');
     $this->elementStart('li');
     // TRANS: Field label on page where to change password. In this field the new password should be typed a second time.
     $this->password('confirm', _m('LABEL', 'Confirm'), _('Same as password above.'));
     $this->elementEnd('li');
     $this->elementEnd('ul');
     // TRANS: Button text on page where to change password.
     $this->submit('changepass', _m('BUTTON', 'Change'));
     $this->elementEnd('fieldset');
     $this->elementEnd('form');
 }
Ejemplo n.º 20
0
 static function saveNew($from, $to, $content, $source)
 {
     $sender = Profile::staticGet('id', $from);
     if (!$sender->hasRight(Right::NEWMESSAGE)) {
         // TRANS: Client exception thrown when a user tries to send a direct message while being banned from sending them.
         throw new ClientException(_('You are banned from sending direct messages.'));
     }
     $msg = new Message();
     $msg->from_profile = $from;
     $msg->to_profile = $to;
     $msg->content = common_shorten_links($content);
     $msg->rendered = common_render_text($content);
     $msg->created = common_sql_now();
     $msg->source = $source;
     $result = $msg->insert();
     if (!$result) {
         common_log_db_error($msg, 'INSERT', __FILE__);
         // TRANS: Message given when a message could not be stored on the server.
         return _('Could not insert message.');
     }
     $orig = clone $msg;
     $msg->uri = common_local_url('showmessage', array('message' => $msg->id));
     $result = $msg->update($orig);
     if (!$result) {
         common_log_db_error($msg, 'UPDATE', __FILE__);
         // TRANS: Message given when a message could not be updated on the server.
         return _('Could not update message with new URI.');
     }
     return $msg;
 }
Ejemplo n.º 21
0
 /**
  * Constructor
  *
  * @param User    $user    the user for the feed
  * @param User    $cur     the current authenticated user, if any
  * @param boolean $indent  flag to turn indenting on or off
  *
  * @return void
  */
 function __construct($user, $cur = null, $indent = true)
 {
     parent::__construct($cur, $indent);
     $this->user = $user;
     if (!empty($user)) {
         $profile = $user->getProfile();
         $this->addAuthor($profile->nickname, $user->uri);
         $this->setActivitySubject($profile->asActivityNoun('subject'));
     }
     // TRANS: Title in atom user notice feed. %s is a user name.
     $title = sprintf(_("%s timeline"), $user->nickname);
     $this->setTitle($title);
     $sitename = common_config('site', 'name');
     $subtitle = sprintf(_('Updates from %1$s on %2$s!'), $user->nickname, $sitename);
     $this->setSubtitle($subtitle);
     $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
     $logo = $avatar ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE);
     $this->setLogo($logo);
     $this->setUpdated('now');
     $this->addLink(common_local_url('showstream', array('nickname' => $user->nickname)));
     $self = common_local_url('ApiTimelineUser', array('id' => $user->id, 'format' => 'atom'));
     $this->setId($self);
     $this->setSelfLink($self);
     $this->addLink(common_local_url('sup', null, null, $user->id), array('rel' => 'http://api.friendfeed.com/2008/03#sup', 'type' => 'application/json'));
 }
Ejemplo n.º 22
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $cur = common_current_user();
     if (empty($cur)) {
         // TRANS: Client exception thrown when trying to view group inbox while not logged in.
         throw new ClientException(_m('Only for logged-in users.'), 403);
     }
     $nicknameArg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nicknameArg);
     if ($nickname != $nicknameArg) {
         $url = common_local_url('groupinbox', array('nickname' => $nickname));
         common_redirect($url);
     }
     $localGroup = Local_group::getKV('nickname', $nickname);
     if (empty($localGroup)) {
         // TRANS: Client exception thrown when trying to view group inbox for non-existing group.
         throw new ClientException(_m('No such group.'), 404);
     }
     $this->group = User_group::getKV('id', $localGroup->group_id);
     if (empty($this->group)) {
         // TRANS: Client exception thrown when trying to view group inbox for non-existing group.
         throw new ClientException(_m('No such group.'), 404);
     }
     if (!$cur->isMember($this->group)) {
         // TRANS: Client exception thrown when trying to view group inbox while not a member.
         throw new ClientException(_m('Only for members.'), 403);
     }
     $this->page = $this->trimmed('page');
     if (!$this->page) {
         $this->page = 1;
     }
     $this->gm = Group_message::forGroup($this->group, ($this->page - 1) * MESSAGES_PER_PAGE, MESSAGES_PER_PAGE + 1);
     return true;
 }
Ejemplo n.º 23
0
 function onEndAvatarFormData($action)
 {
     $user = common_current_user();
     $hasGravatar = $this->hasGravatar($user->id);
     if (!empty($user->email) && !$hasGravatar) {
         //and not gravatar already set
         $action->elementStart('form', array('method' => 'post', 'id' => 'form_settings_gravatar_add', 'class' => 'form_settings', 'action' => common_local_url('avatarsettings')));
         $action->elementStart('fieldset', array('id' => 'settings_gravatar_add'));
         $action->element('legend', null, _m('Set Gravatar'));
         $action->hidden('token', common_session_token());
         $action->element('p', 'form_guide', _m('If you want to use your Gravatar image, click "Add".'));
         $action->element('input', array('type' => 'submit', 'id' => 'settings_gravatar_add_action-submit', 'name' => 'add', 'class' => 'submit', 'value' => _m('Add')));
         $action->elementEnd('fieldset');
         $action->elementEnd('form');
     } elseif ($hasGravatar) {
         $action->elementStart('form', array('method' => 'post', 'id' => 'form_settings_gravatar_remove', 'class' => 'form_settings', 'action' => common_local_url('avatarsettings')));
         $action->elementStart('fieldset', array('id' => 'settings_gravatar_remove'));
         $action->element('legend', null, _m('Remove Gravatar'));
         $action->hidden('token', common_session_token());
         $action->element('p', 'form_guide', _m('If you want to remove your Gravatar image, click "Remove".'));
         $action->element('input', array('type' => 'submit', 'id' => 'settings_gravatar_remove_action-submit', 'name' => 'remove', 'class' => 'submit', 'value' => _m('Remove')));
         $action->elementEnd('fieldset');
         $action->elementEnd('form');
     } else {
         $action->element('p', 'form_guide', _m('To use a Gravatar first enter in an email address.'));
     }
 }
 function pushGroup($group_id)
 {
     // For a local group, ping the PuSH hub to update its feed.
     // Updates may come from either a local or a remote user.
     $feed = common_local_url('ApiTimelineGroup', array('id' => $group_id, 'format' => 'atom'));
     $this->pushFeed($feed, array($this, 'groupFeedForNotice'), $group_id);
 }
Ejemplo n.º 25
0
 /**
  * Content area of the page
  *
  * Shows a form for changing the password
  *
  * @return void
  */
 function showContent()
 {
     $user = common_current_user();
     $this->elementStart('form', array('method' => 'POST', 'id' => 'form_password', 'class' => 'form_settings', 'action' => common_local_url('passwordsettings')));
     $this->elementStart('fieldset');
     $this->element('legend', null, _('Password change'));
     $this->hidden('token', common_session_token());
     $this->elementStart('ul', 'form_data');
     // Users who logged in with OpenID won't have a pwd
     if ($user->password) {
         $this->elementStart('li');
         $this->password('oldpassword', _('Old password'));
         $this->elementEnd('li');
     }
     $this->elementStart('li');
     $this->password('newpassword', _('New password'), _('6 or more characters'));
     $this->elementEnd('li');
     $this->elementStart('li');
     $this->password('confirm', _('Confirm'), _('same as password above'));
     $this->elementEnd('li');
     $this->elementEnd('ul');
     $this->submit('changepass', _('Change'));
     $this->elementEnd('fieldset');
     $this->elementEnd('form');
 }
Ejemplo n.º 26
0
 /**
  * We've gotten a post event on the Salmon backchannel, probably a reply.
  */
 function handlePost()
 {
     // @fixme process all objects?
     switch ($this->activity->objects[0]->type) {
         case ActivityObject::ARTICLE:
         case ActivityObject::BLOGENTRY:
         case ActivityObject::NOTE:
         case ActivityObject::STATUS:
         case ActivityObject::COMMENT:
             break;
         default:
             // TRANS: Client exception.
             throw new ClientException("Can't handle that kind of post.");
     }
     // Notice must be to the attention of this group
     $context = $this->activity->context;
     if (empty($context->attention)) {
         // TRANS: Client exception.
         throw new ClientException("Not to the attention of anyone.");
     } else {
         $uri = common_local_url('groupbyid', array('id' => $this->group->id));
         if (!in_array($uri, $context->attention)) {
             // TRANS: Client exception.
             throw new ClientException("Not to the attention of this group.");
         }
     }
     $profile = $this->ensureProfile();
     $this->saveNotice();
 }
Ejemplo n.º 27
0
 /**
  * Show the menu
  *
  * @return void
  */
 function show()
 {
     $cur = common_current_user();
     $action = $this->action->trimmed('action');
     $this->out->elementStart('ul', array('class' => 'nav'));
     if (Event::handle('StartSubGroupNav', array($this))) {
         $this->out->menuItem(common_local_url('showstream', array('nickname' => $this->user->nickname)), _m('MENU', 'Profile'), empty($profile) ? $this->user->nickname : $profile->getBestName(), $action == 'showstream', 'nav_profile');
         $this->out->menuItem(common_local_url('subscriptions', array('nickname' => $this->user->nickname)), _m('MENU', 'Subscriptions'), sprintf(_('People %s subscribes to.'), $this->user->nickname), $action == 'subscriptions', 'nav_subscriptions');
         $this->out->menuItem(common_local_url('subscribers', array('nickname' => $this->user->nickname)), _m('MENU', 'Subscribers'), sprintf(_('People subscribed to %s.'), $this->user->nickname), $action == 'subscribers', 'nav_subscribers');
         if ($cur && $cur->id == $this->user->id) {
             // Possibly site admins should be able to get in here too
             $pending = $this->countPendingSubs();
             if ($pending || $cur->subscribe_policy == User::SUBSCRIBE_POLICY_MODERATE) {
                 $this->out->menuItem(common_local_url('subqueue', array('nickname' => $this->user->nickname)), sprintf(_m('MENU', 'Pending (%d)'), $pending), sprintf(_('Approve pending subscription requests.'), $this->user->nickname), $action == 'subqueueaction', 'nav_subscribers');
             }
         }
         $this->out->menuItem(common_local_url('usergroups', array('nickname' => $this->user->nickname)), _m('MENU', 'Groups'), sprintf(_('Groups %s is a member of.'), $this->user->nickname), $action == 'usergroups', 'nav_usergroups');
         $this->out->menuItem(common_local_url('peopletagsubscriptions', array('nickname' => $this->user->nickname)), _m('MENU', 'Lists'), sprintf(_('List subscriptions by %s.'), $this->user->nickname), in_array($action, array('peopletagsbyuser', 'peopletagsubscriptions', 'peopletagsforuser')), 'nav_timeline_peopletags');
         if (common_config('invite', 'enabled') && !is_null($cur) && $this->user->id === $cur->id) {
             $this->out->menuItem(common_local_url('invite'), _m('MENU', 'Invite'), sprintf(_('Invite friends and colleagues to join you on %s.'), common_config('site', 'name')), $action == 'invite', 'nav_invite');
         }
         Event::handle('EndSubGroupNav', array($this));
     }
     $this->out->elementEnd('ul');
 }
Ejemplo n.º 28
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->checkSessionToken();
     if (!common_logged_in()) {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
             $this->clientError(_('Not logged in.'));
         } else {
             // Redirect to login.
             common_set_returnto($this->selfUrl());
             $user = common_current_user();
             if (Event::handle('RedirectToLogin', array($this, $user))) {
                 common_redirect(common_local_url('login'), 303);
             }
         }
         return false;
     }
     $id = $this->trimmed('profileid');
     if (!$id) {
         // TRANS: Client error displayed when trying to change user options without specifying a user to work on.
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (!$this->profile) {
         // TRANS: Client error displayed when trying to change user options without specifying an existing user to work on.
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     return true;
 }
Ejemplo n.º 29
0
 /**
  * Constructor
  *
  * @param User    $user    the user for the feed
  * @param User    $cur     the current authenticated user, if any
  * @param boolean $indent  flag to turn indenting on or off
  *
  * @return void
  */
 function __construct($user, $cur = null, $indent = true)
 {
     parent::__construct($cur, $indent);
     $this->user = $user;
     if (!empty($user)) {
         $profile = $user->getProfile();
         $ao = ActivityObject::fromProfile($profile);
         array_push($ao->extra, $profile->profileInfo($cur));
         // XXX: For users, we generate an author _AND_ an <activity:subject>
         // This is for backward compatibility with clients (especially
         // StatusNet's clients) that assume the Atom will conform to an
         // older version of the Activity Streams API. Subject should be
         // removed in future versions of StatusNet.
         $this->addAuthorRaw($ao->asString('author'));
         $depMsg = 'Deprecation warning: activity:subject is present ' . 'only for backward compatibility. It will be ' . 'removed in the next version of StatusNet.';
         $this->addAuthorRaw("<!--{$depMsg}-->\n" . $ao->asString('activity:subject'));
     }
     // TRANS: Title in atom user notice feed. %s is a user name.
     $title = sprintf(_("%s timeline"), $user->nickname);
     $this->setTitle($title);
     $sitename = common_config('site', 'name');
     $subtitle = sprintf(_('Updates from %1$s on %2$s!'), $user->nickname, $sitename);
     $this->setSubtitle($subtitle);
     $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
     $logo = $avatar ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE);
     $this->setLogo($logo);
     $this->setUpdated('now');
     $this->addLink(common_local_url('showstream', array('nickname' => $user->nickname)));
     $self = common_local_url('ApiTimelineUser', array('id' => $user->id, 'format' => 'atom'));
     $this->setId($self);
     $this->setSelfLink($self);
     $this->addLink(common_local_url('sup', null, null, $user->id), array('rel' => 'http://api.friendfeed.com/2008/03#sup', 'type' => 'application/json'));
 }
Ejemplo n.º 30
0
 function onEndToolsLocalNav($action)
 {
     $actionName = $action->trimmed('action');
     $user = common_current_user();
     if (!empty($user)) {
         if ($actionName === 'taskcreate') {
             $action->elementStart('li', array('id' => 'nav_task', 'class' => 'current'));
         } else {
             $action->elementStart('li', array('id' => 'nav_task'));
         }
         $action->elementStart('a', array('href' => common_local_url('taskcreate'), 'title' => _m('Tareas de Clase')));
         $action->text('Tareas');
         // Si es alumno, mostramos las tareas pendientes.
         if (!$user->hasRole('grader')) {
             // Llamamos a la función que obtenga el numero de tareas
             $number = Task::getNumberPendingTasks($user->id);
             if ($number != 0) {
                 $action->element('span', 'pending-tasks-number', $number);
             }
         }
         $action->elementEnd('a');
         $action->elementEnd('li');
     }
     return true;
 }