function omb_oauth_consumer() { static $con = null; if (!$con) { $con = new OAuthConsumer(common_root_url(), ''); } return $con; }
function favorites($args, $apidata) { parent::handle($args); $this->auth_user = $apidata['user']; $user = $this->get_user($apidata['api_arg'], $apidata); if (!$user) { $this->clientError('Not Found', 404, $apidata['content-type']); return; } $profile = $user->getProfile(); if (!$profile) { $this->serverError(_('User has no profile.')); return; } $page = $this->arg('page'); if (!$page) { $page = 1; } if (!$count) { $count = 20; } $notice = $user->favoriteNotices(($page - 1) * 20, $count); if (!$notice) { $this->serverError(_('Could not retrieve favorite notices.')); return; } $sitename = common_config('site', 'name'); $title = sprintf(_('%s / Favorites from %s'), $sitename, $user->nickname); $taguribase = common_config('integration', 'taguri'); $id = "tag:{$taguribase}:Favorites:" . $user->id; $link = common_local_url('favorites', array('nickname' => $user->nickname)); $subtitle = sprintf(_('%s updates favorited by %s / %s.'), $sitename, $profile->getBestName(), $user->nickname); switch ($apidata['content-type']) { case 'xml': $this->show_xml_timeline($notice); break; case 'rss': $this->show_rss_timeline($notice, $title, $link, $subtitle); break; case 'atom': if (isset($apidata['api_arg'])) { $selfuri = $selfuri = common_root_url() . 'api/favorites/' . $apidata['api_arg'] . '.atom'; } else { $selfuri = $selfuri = common_root_url() . 'api/favorites.atom'; } $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, null, $selfuri); break; case 'json': $this->show_json_timeline($notice); break; default: $this->clientError(_('API method not found!'), $code = 404); } }
function showContent() { if (empty($this->user)) { $this->element('p', array('class' => 'notespdf-generate-error'), _m('Login first!')); } else { $this->element('h2', null, 'Grupos Disponibles'); // Obtenemos los grupos a los que pertenece el usuario. $groupsUser = $this->user->getGroups()->fetchAll(); // Si no pertenece a ninguno, le animamos a que se una a alguno de los existentes. if (empty($groupsUser)) { $this->elementStart('p', array('class' => 'notes-empty-groups')); $this->raw("Todavía no perteneces a ningún grupo."); $this->element('br'); $this->raw("Prueba uniéndote a alguno de los "); $this->element('a', array('href' => common_root_url() . 'groups/'), "Grupos Disponibles"); $this->elementEnd('p'); } else { // Obtenemos los grupos que contienen tweets puntuados. $groupsGraded = Grades::getIDsGroupsWithGrades(); $this->elementStart('ul'); foreach ($groupsUser as $group) { $this->elementStart('li', array('class' => 'notespdf-group-item')); $avatar = $group->getAvatar(); $this->element('img', array('src' => $avatar, 'width' => '48', 'height' => '48')); $this->elementStart('p'); $name = $group->getBestName(); $this->raw($name); $this->elementEnd('p'); // Si el grupo no tiene puntuaciones no se pueden generar apuntes if (!in_array($group->id, $groupsGraded)) { $butGenerate = new Notesgroupsform($this, $group->id, 'true'); $butGenerate->show(); $this->elementStart('div'); $this->elementStart('p', array('class' => 'notes-error-group-text')); $this->raw("No es posible generar apuntes. Grupo sin puntuaciones."); $this->elementEnd('p'); $path = common_path('local/plugins/NotesPDF/css/x.gif'); $this->element('img', array('class' => 'notes-error-group', 'src' => $path)); $this->elementEnd('div'); } else { $butGenerate = new Notesgroupsform($this, $group->id); $butGenerate->show(); } $this->elementEnd('li'); } $this->elementEnd('ul'); } } }
function timeline($args, $apidata) { parent::handle($args); common_debug("in tags api action"); $this->auth_user = $apidata['user']; $tag = $apidata['api_arg']; if (empty($tag)) { $this->clientError('Not Found', 404, $apidata['content-type']); return; } $sitename = common_config('site', 'name'); $title = sprintf(_("Notices tagged with %s"), $tag); $taguribase = common_config('integration', 'taguri'); $id = "tag:{$taguribase}:TagTimeline:" . $tag; $link = common_local_url('tag', array('tag' => $tag)); $subtitle = sprintf(_('Updates tagged with %1$s on %2$s!'), $tag, $sitename); $page = (int) $this->arg('page', 1); $count = (int) $this->arg('count', 20); $max_id = (int) $this->arg('max_id', 0); $since_id = (int) $this->arg('since_id', 0); $since = $this->arg('since'); # XXX: support max_id, since_id, and since arguments $notice = Notice_tag::getStream($tag, ($page - 1) * $count, $count + 1); switch ($apidata['content-type']) { case 'xml': $this->show_xml_timeline($notice); break; case 'rss': $this->show_rss_timeline($notice, $title, $link, $subtitle, $suplink); break; case 'atom': if (isset($apidata['api_arg'])) { $selfuri = common_root_url() . 'api/laconica/tags/timeline/' . $apidata['api_arg'] . '.atom'; } else { $selfuri = common_root_url() . 'api/laconica/tags/timeline.atom'; } $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, $suplink, $selfuri); break; case 'json': $this->show_json_timeline($notice); break; default: $this->clientError(_('API method not found!'), $code = 404); } }
function timeline($args, $apidata) { parent::handle($args); common_debug("in groups api action"); $this->auth_user = $apidata['user']; $group = $this->get_group($apidata['api_arg'], $apidata); if (empty($group)) { $this->clientError('Not Found', 404, $apidata['content-type']); return; } $sitename = common_config('site', 'name'); $title = sprintf(_("%s timeline"), $group->nickname); $taguribase = common_config('integration', 'taguri'); $id = "tag:{$taguribase}:GroupTimeline:" . $group->id; $link = common_local_url('showgroup', array('nickname' => $group->nickname)); $subtitle = sprintf(_('Updates from %1$s on %2$s!'), $group->nickname, $sitename); $page = (int) $this->arg('page', 1); $count = (int) $this->arg('count', 20); $max_id = (int) $this->arg('max_id', 0); $since_id = (int) $this->arg('since_id', 0); $since = $this->arg('since'); $notice = $group->getNotices(($page - 1) * $count, $count, $since_id, $max_id, $since); switch ($apidata['content-type']) { case 'xml': $this->show_xml_timeline($notice); break; case 'rss': $this->show_rss_timeline($notice, $title, $link, $subtitle, $suplink); break; case 'atom': if (isset($apidata['api_arg'])) { $selfuri = common_root_url() . 'api/laconica/groups/timeline/' . $apidata['api_arg'] . '.atom'; } else { $selfuri = common_root_url() . 'api/laconica/groups/timeline.atom'; } $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, $suplink, $selfuri); break; case 'json': $this->show_json_timeline($notice); break; default: $this->clientError(_('API method not found!'), $code = 404); } }
/** * Take a snapshot of the server * * Builds an array of statistical and configuration data based * on the local database and config files. We avoid grabbing any * information that could be personal or private. * * @return void */ function take() { $this->stats = array(); // Some basic identification stuff $this->stats['version'] = NEWTYPE_VERSION; $this->stats['phpversion'] = phpversion(); $this->stats['name'] = common_config('site', 'name'); $this->stats['root'] = common_root_url(); // non-identifying stats on various tables. Primary // interest is size and rate of activity of service. $tables = array('user', 'notice', 'subscription', 'remote_profile', 'user_group'); foreach ($tables as $table) { $this->tableStats($table); } // stats on some important config options $this->stats['theme'] = common_config('site', 'theme'); $this->stats['dbtype'] = common_config('db', 'type'); $this->stats['xmpp'] = common_config('xmpp', 'enabled'); $this->stats['inboxes'] = common_config('inboxes', 'enabled'); $this->stats['queue'] = common_config('queue', 'enabled'); $this->stats['license'] = common_config('license', 'url'); $this->stats['fancy'] = common_config('site', 'fancy'); $this->stats['private'] = common_config('site', 'private'); $this->stats['closed'] = common_config('site', 'closed'); $this->stats['memcached'] = common_config('memcached', 'enabled'); $this->stats['language'] = common_config('site', 'language'); $this->stats['timezone'] = common_config('site', 'timezone'); }
function handle($args) { parent::handle($args); header('Content-Type: application/rdf+xml'); $this->startXML(); $this->elementStart('rdf:RDF', array('xmlns:rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'xmlns:rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'xmlns:geo' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', 'xmlns:bio' => 'http://purl.org/vocab/bio/0.1/', 'xmlns:sioc' => 'http://rdfs.org/sioc/ns#', 'xmlns' => 'http://xmlns.com/foaf/0.1/')); // This is the document about the user $this->showPpd('', $this->user->uri); // Would be nice to tell if they were a Person or not (e.g. a #person usertag?) $this->elementStart('Agent', array('rdf:about' => $this->user->uri)); if ($this->user->email) { $this->element('mbox_sha1sum', null, sha1('mailto:' . $this->user->email)); } if ($this->profile->fullname) { $this->element('name', null, $this->profile->fullname); } if ($this->profile->homepage) { $this->element('homepage', array('rdf:resource' => $this->profile->homepage)); } if ($this->profile->profileurl) { $this->element('weblog', array('rdf:resource' => $this->profile->profileurl)); } if ($this->profile->bio) { $this->element('bio:olb', null, $this->profile->bio); } $location = $this->profile->getLocation(); if ($location) { $attr = array(); if ($location->getRdfURL()) { $attr['rdf:about'] = $location->getRdfURL(); } $location_name = $location->getName(); $this->elementStart('based_near'); $this->elementStart('geo:SpatialThing', $attr); if ($location_name) { $this->element('name', null, $location_name); } if ($location->lat) { $this->element('geo:lat', null, $location->lat); } if ($location->lon) { $this->element('geo:long', null, $location->lon); } if ($location->getURL()) { $this->element('page', array('rdf:resource' => $location->getURL())); } $this->elementEnd('geo:SpatialThing'); $this->elementEnd('based_near'); } $avatar = $this->profile->getOriginalAvatar(); if ($avatar) { $this->elementStart('img'); $this->elementStart('Image', array('rdf:about' => $avatar->url)); foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) { $scaled = $this->profile->getAvatar($size); if (!$scaled->original) { // sometimes the original has one of our scaled sizes $this->elementStart('thumbnail'); $this->element('Image', array('rdf:about' => $scaled->url)); $this->elementEnd('thumbnail'); } } $this->elementEnd('Image'); $this->elementEnd('img'); } $person = $this->showMicrobloggingAccount($this->profile, common_root_url(), $this->user->uri, true, false); // Get people who subscribe to user $sub = new Subscription(); $sub->subscribed = $this->profile->id; $sub->whereAdd('subscriber != subscribed'); if ($sub->find()) { while ($sub->fetch()) { $profile = Profile::staticGet('id', $sub->subscriber); if (empty($profile)) { common_debug('Got a bad subscription: ' . print_r($sub, true)); continue; } $user = $profile->getUser(); $other_uri = $profile->getUri(); if (array_key_exists($other_uri, $person)) { $person[$other_uri][0] = BOTH; } else { $person[$other_uri] = array(LISTENER, $profile->id, $profile->nickname, $user ? 'local' : 'remote'); } unset($profile); } } unset($sub); foreach ($person as $uri => $p) { list($type, $id, $nickname, $local) = $p; if ($type == BOTH) { $this->element('knows', array('rdf:resource' => $uri)); } } $this->elementEnd('Agent'); foreach ($person as $uri => $p) { $foaf_url = null; list($type, $id, $nickname, $local) = $p; if ($local == 'local') { $foaf_url = common_local_url('foaf', array('nickname' => $nickname)); } $profile = Profile::staticGet($id); $this->elementStart('Agent', array('rdf:about' => $uri)); if ($type == BOTH) { $this->element('knows', array('rdf:resource' => $this->user->uri)); } $this->showMicrobloggingAccount($profile, $local == 'local' ? common_root_url() : null, $uri, false, $type == LISTENER || $type == BOTH); if ($foaf_url) { $this->element('rdfs:seeAlso', array('rdf:resource' => $foaf_url)); } $this->elementEnd('Agent'); if ($foaf_url) { $this->showPpd($foaf_url, $uri); } $profile->free(); $profile = null; unset($profile); } $this->elementEnd('rdf:RDF'); $this->endXML(); }
/** * 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: Used as title in check for group membership. %s is a user name. $title = sprintf(_("%s's groups"), $this->user->nickname); $taguribase = TagURI::base(); $id = "tag:{$taguribase}:Groups"; $link = common_local_url('usergroups', array('nickname' => $this->user->nickname)); $subtitle = sprintf(_('%1$s groups %2$s is a member of.'), $sitename, $this->user->nickname); 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/' . $this->user->id . '.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; } }
function oid_authenticate($openid_url, $returnto, $immediate = false) { $consumer = oid_consumer(); if (!$consumer) { // TRANS: OpenID plugin server error. common_server_error(_m('Cannot instantiate OpenID consumer object.')); return false; } common_ensure_session(); $auth_request = $consumer->begin($openid_url); // Handle failure status return values. if (!$auth_request) { common_log(LOG_ERR, __METHOD__ . ": mystery fail contacting {$openid_url}"); // TRANS: OpenID plugin message. Given when an OpenID is not valid. return _m('Not a valid OpenID.'); } else { if (Auth_OpenID::isFailure($auth_request)) { common_log(LOG_ERR, __METHOD__ . ": OpenID fail to {$openid_url}: {$auth_request->message}"); // TRANS: OpenID plugin server error. Given when the OpenID authentication request fails. // TRANS: %s is the failure message. return sprintf(_m('OpenID failure: %s'), $auth_request->message); } } $sreg_request = Auth_OpenID_SRegRequest::build(array(), array('nickname', 'email', 'fullname', 'language', 'timezone', 'postcode', 'country')); if ($sreg_request) { $auth_request->addExtension($sreg_request); } $requiredTeam = common_config('openid', 'required_team'); if ($requiredTeam) { // LaunchPad OpenID extension $team_request = new Auth_OpenID_TeamsRequest(array($requiredTeam)); if ($team_request) { $auth_request->addExtension($team_request); } } $trust_root = common_root_url(true); $process_url = common_local_url($returnto); // Net::OpenID::Server as used on LiveJournal appears to incorrectly // reject POST requests for data submissions that OpenID 1.1 specs // as GET, although 2.0 allows them: // https://rt.cpan.org/Public/Bug/Display.html?id=42202 // // Our OpenID libraries would have switched in the redirect automatically // if it were detecting 1.1 compatibility mode, however the server is // advertising itself as 2.0-compatible, so we got switched to the POST. // // Since the GET should always work anyway, we'll just take out the // autosubmitter for now. // //if ($auth_request->shouldSendRedirect()) { $redirect_url = $auth_request->redirectURL($trust_root, $process_url, $immediate); if (!$redirect_url) { } else { if (Auth_OpenID::isFailure($redirect_url)) { // TRANS: OpenID plugin server error. Given when the OpenID authentication request cannot be redirected. // TRANS: %s is the failure message. return sprintf(_m('Could not redirect to server: %s'), $redirect_url->message); } else { common_redirect($redirect_url, 303); } } /* } else { // Generate form markup and render it. $form_id = 'openid_message'; $form_html = $auth_request->formMarkup($trust_root, $process_url, $immediate, array('id' => $form_id)); # XXX: This is cheap, but things choke if we don't escape ampersands # in the HTML attributes $form_html = preg_replace('/&/', '&', $form_html); // Display an error if the form markup couldn't be generated; // otherwise, render the HTML. if (Auth_OpenID::isFailure($form_html)) { // TRANS: OpenID plugin server error if the form markup could not be generated. // TRANS: %s is the failure message. common_server_error(sprintf(_m('Could not create OpenID form: %s'), $form_html->message)); } else { $action = new AutosubmitAction(); // see below $action->form_html = $form_html; $action->form_id = $form_id; $action->prepare(array('action' => 'autosubmit')); $action->handle(array('action' => 'autosubmit')); } } */ }
function registrationActivity() { $profile = $this->getProfile(); $service = new ActivityObject(); $service->type = ActivityObject::SERVICE; $service->title = common_config('site', 'name'); $service->link = common_root_url(); $service->id = $service->link; $act = new Activity(); $act->actor = ActivityObject::fromProfile($profile); $act->verb = ActivityVerb::JOIN; $act->objects[] = $service; $act->id = TagURI::mint('user:register:%d', $this->id); $act->time = strtotime($this->created); $act->title = _("Register"); $act->content = sprintf(_('%1$s joined %2$s.'), $profile->getBestName(), $service->title); return $act; }
function handle($args) { parent::handle($args); header('Content-Type: application/rdf+xml'); $this->startXML(); $this->elementStart('rdf:RDF', array('xmlns:rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'xmlns:rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'xmlns:geo' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', 'xmlns' => 'http://xmlns.com/foaf/0.1/')); // This is the document about the user $this->showPpd('', $this->user->uri); // XXX: might not be a person $this->elementStart('Person', array('rdf:about' => $this->user->uri)); $this->element('mbox_sha1sum', null, sha1('mailto:' . $this->user->email)); if ($this->profile->fullname) { $this->element('name', null, $this->profile->fullname); } if ($this->profile->homepage) { $this->element('homepage', array('rdf:resource' => $this->profile->homepage)); } if ($this->profile->bio) { $this->element('rdfs:comment', null, $this->profile->bio); } // XXX: more structured location data if ($this->profile->location) { $this->elementStart('based_near'); $this->elementStart('geo:SpatialThing'); $this->element('name', null, $this->profile->location); $this->elementEnd('geo:SpatialThing'); $this->elementEnd('based_near'); } $this->showMicrobloggingAccount($this->profile, common_root_url()); $avatar = $this->profile->getOriginalAvatar(); if ($avatar) { $this->elementStart('img'); $this->elementStart('Image', array('rdf:about' => $avatar->url)); foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) { $scaled = $this->profile->getAvatar($size); if (!$scaled->original) { // sometimes the original has one of our scaled sizes $this->elementStart('thumbnail'); $this->element('Image', array('rdf:about' => $scaled->url)); $this->elementEnd('thumbnail'); } } $this->elementEnd('Image'); $this->elementEnd('img'); } // Get people user is subscribed to $person = array(); $sub = new Subscription(); $sub->subscriber = $this->profile->id; $sub->whereAdd('subscriber != subscribed'); if ($sub->find()) { while ($sub->fetch()) { if ($sub->token) { $other = Remote_profile::staticGet('id', $sub->subscribed); } else { $other = User::staticGet('id', $sub->subscribed); } if (!$other) { common_debug('Got a bad subscription: ' . print_r($sub, true)); continue; } $this->element('knows', array('rdf:resource' => $other->uri)); $person[$other->uri] = array(LISTENEE, $other); } } // Get people who subscribe to user $sub = new Subscription(); $sub->subscribed = $this->profile->id; $sub->whereAdd('subscriber != subscribed'); if ($sub->find()) { while ($sub->fetch()) { if ($sub->token) { $other = Remote_profile::staticGet('id', $sub->subscriber); } else { $other = User::staticGet('id', $sub->subscriber); } if (!$other) { common_debug('Got a bad subscription: ' . print_r($sub, true)); continue; } if (array_key_exists($other->uri, $person)) { $person[$other->uri][0] = BOTH; } else { $person[$other->uri] = array(LISTENER, $other); } } } $this->elementEnd('Person'); foreach ($person as $uri => $p) { $foaf_url = null; if ($p[1] instanceof User) { $foaf_url = common_local_url('foaf', array('nickname' => $p[1]->nickname)); } $this->profile = Profile::staticGet($p[1]->id); $this->elementStart('Person', array('rdf:about' => $uri)); if ($p[0] == LISTENER || $p[0] == BOTH) { $this->element('knows', array('rdf:resource' => $this->user->uri)); } $this->showMicrobloggingAccount($this->profile, $p[1] instanceof User ? common_root_url() : null); if ($foaf_url) { $this->element('rdfs:seeAlso', array('rdf:resource' => $foaf_url)); } $this->elementEnd('Person'); if ($foaf_url) { $this->showPpd($foaf_url, $uri); } } $this->elementEnd('rdf:RDF'); $this->endXML(); }
function initRss() { $channel = $this->getChannel(); header('Content-Type: application/rdf+xml'); $this->startXml(); $this->elementStart('rdf:RDF', array('xmlns:rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'xmlns:dc' => 'http://purl.org/dc/elements/1.1/', 'xmlns:cc' => 'http://creativecommons.org/ns#', 'xmlns:content' => 'http://purl.org/rss/1.0/modules/content/', 'xmlns:ctag' => 'http://commontag.org/ns#', 'xmlns:foaf' => 'http://xmlns.com/foaf/0.1/', 'xmlns:enc' => 'http://purl.oclc.org/net/rss_2.0/enc#', 'xmlns:sioc' => 'http://rdfs.org/sioc/ns#', 'xmlns:sioct' => 'http://rdfs.org/sioc/types#', 'xmlns:rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'xmlns:geo' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', 'xmlns:statusnet' => 'http://status.net/ont/', 'xmlns' => 'http://purl.org/rss/1.0/')); $this->elementStart('sioc:Site', array('rdf:about' => common_root_url())); $this->element('sioc:name', null, common_config('site', 'name')); $this->elementStart('sioc:space_of'); $this->element('sioc:Container', array('rdf:about' => $channel['url'])); $this->elementEnd('sioc:space_of'); $this->elementEnd('sioc:Site'); }
/** * 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; } }
function testArgs($notice) { $args = array(); $args['comment'] = $notice->content; $args['ip'] = $this->getClientIP(); if (isset($_SERVER) && array_key_exists('HTTP_USER_AGENT', $_SERVER)) { $args['agent'] = $_SERVER['HTTP_USER_AGENT']; } $profile = $notice->getProfile(); if ($profile && $profile->homepage) { $args['link'] = $profile->homepage; } if ($profile && $profile->fullname) { $args['name'] = $profile->fullname; } else { $args['name'] = $profile->nickname; } $args['site'] = common_root_url(); $args['version'] = $this->userAgent(); $args['options'] = "max-size=" . common_config('site', 'textlimit') . ",min-size=0,min-words=0,exclude=bayasian"; return $args; }
function remoteSubscription() { if (!$this->nickname) { $this->showForm(_('No such user.')); return; } $user = User::staticGet('nickname', $this->nickname); $this->profile_url = $this->trimmed('profile_url'); if (!$this->profile_url) { $this->showForm(_('No such user.')); return; } if (!common_valid_http_url($this->profile_url)) { $this->showForm(_('Invalid profile URL (bad format)')); return; } try { $service = new OMB_Service_Consumer($this->profile_url, common_root_url(), omb_oauth_datastore()); } catch (OMB_InvalidYadisException $e) { $this->showForm(_('Not a valid profile URL (no YADIS document or ' . 'invalid XRDS defined).')); return; } if ($service->getServiceURI(OAUTH_ENDPOINT_REQUEST) == common_local_url('requesttoken') || User::staticGet('uri', $service->getRemoteUserURI())) { $this->showForm(_('That’s a local profile! Login to subscribe.')); return; } try { $service->requestToken(); } catch (OMB_RemoteServiceException $e) { $this->showForm(_('Couldn’t get a request token.')); return; } /* Create an OMB_Profile from $user. */ $profile = $user->getProfile(); if (!$profile) { common_log_db_error($user, 'SELECT', __FILE__); $this->serverError(_('User without matching profile.')); return; } $target_url = $service->requestAuthorization(profile_to_omb_profile($user->uri, $profile), common_local_url('finishremotesubscribe')); common_ensure_session(); $_SESSION['oauth_authorization_request'] = serialize($service); /* Redirect to the remote service for authorization. */ common_redirect($target_url, 303); }
/** * Returns an array based on this activity suitable * for encoding as a JSON object * * @return array $activity */ function asArray() { $activity = array(); // actor $activity['actor'] = $this->actor->asArray(); // body $activity['body'] = $this->content; // generator <-- We could use this when we know a notice is created // locally. Or if we know the upstream Generator. // icon <-- I've decided to use the posting user's stream avatar here // for now (also included in the avatarLinks extension) // object if ($this->verb == ActivityVerb::POST && count($this->objects) == 1) { $activity['object'] = $this->objects[0]->asArray(); // Context stuff. For now I'm just sticking most of it // in a property called "context" if (!empty($this->context)) { if (!empty($this->context->location)) { $loc = $this->context->location; // GeoJSON $activity['geopoint'] = array('type' => 'Point', 'coordinates' => array($loc->lat, $loc->lon)); } $activity['to'] = $this->context->getToArray(); $activity['context'] = $this->context->asArray(); } // Instead of adding enclosures as an extension to JSON // Activities, it seems like we should be using the // attachedObjects property of ActivityObject $attachedObjects = array(); // XXX: OK, this is kinda cheating. We should probably figure out // what kind of objects these are based on mime-type and then // create specific object types. Right now this rely on // duck-typing. Also, we should include an embed code for // video attachments. foreach ($this->enclosures as $enclosure) { if (is_string($enclosure)) { $attachedObjects[]['id'] = $enclosure; } else { $attachedObjects[]['id'] = $enclosure->url; $mediaLink = new ActivityStreamsMediaLink($enclosure->url, null, null, $enclosure->mimetype); $attachedObjects[]['mediaLink'] = $mediaLink->asArray(); // extension if ($enclosure->title) { $attachedObjects[]['displayName'] = $enclosure->title; } } } if (!empty($attachedObjects)) { $activity['object']['attachedObjects'] = $attachedObjects; } } else { $activity['object'] = array(); foreach ($this->objects as $object) { $activity['object'][] = $object->asArray(); } } $activity['postedTime'] = self::iso8601Date($this->time); // Change to exactly be RFC3339? // provider $provider = array('objectType' => 'service', 'displayName' => common_config('site', 'name'), 'url' => common_root_url()); $activity['provider'] = $provider; // target if (!empty($this->target)) { $activity['target'] = $this->target->asArray(); } // title $activity['title'] = $this->title; // updatedTime <-- Should we use this to indicate the time we received // a remote notice? Probably not. // verb // // We can probably use the whole schema URL here but probably the // relative simple name is easier to parse $activity['verb'] = substr($this->verb, strrpos($this->verb, '/') + 1); /* Purely extensions hereafter */ $tags = array(); // Use an Activity Object for term? Which object? Note? foreach ($this->categories as $cat) { $tags[] = $cat->term; } $activity['tags'] = $tags; // XXX: a bit of a hack... Since JSON isn't namespaced we probably // shouldn't be using 'statusnet:notice_info', but this will work // for the moment. foreach ($this->extra as $e) { list($objectName, $props, $txt) = $e; if (!empty($objectName)) { $activity[$objectName] = $props; } } return array_filter($activity); }
/** * Handle the request * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); $noticeurl = common_path('notice/', StatusNet::isHTTPS()); $instanceurl = common_path('', StatusNet::isHTTPS()); // remove protocol for the comparison below $noticeurl_wo_protocol = preg_replace('(^https?://)', '', $noticeurl); $instanceurl_wo_protocol = preg_replace('(^https?://)', '', $instanceurl); $url_wo_protocol = preg_replace('(^https?://)', '', $this->url); // find local notice if (strpos($url_wo_protocol, $noticeurl_wo_protocol) === 0) { $possible_notice_id = str_replace($noticeurl_wo_protocol, '', $url_wo_protocol); if (ctype_digit($possible_notice_id)) { $notice = Notice::getKV('id', $possible_notice_id); } else { $this->clientError("Notice not found.", 404); } } if (!$notice instanceof Notice) { // TRANS: Client error displayed in oEmbed action when notice not found. // TRANS: %s is a notice. $this->clientError(sprintf(_("Notice %s not found."), $this->id), 404); } $profile = $notice->getProfile(); if (!$profile instanceof Profile) { // TRANS: Server error displayed in oEmbed action when notice has not profile. $this->serverError(_('Notice has no profile.'), 500); } $authorname = $profile->getFancyName(); $oembed = array(); $oembed['version'] = '1.0'; $oembed['provider_name'] = common_config('site', 'name'); $oembed['provider_url'] = common_root_url(); $oembed['type'] = 'link'; // TRANS: oEmbed title. %1$s is the author name, %2$s is the creation date. $oembed['title'] = ApiAction::dateTwitter($notice->created) . ' (Qvitter)'; $oembed['author_name'] = $authorname; $oembed['author_url'] = $profile->profileurl; $oembed['url'] = $notice->getUrl(); $oembed['html'] = $notice->getRendered(); // maybe add thumbnail $attachments = $notice->attachments(); if (!empty($attachments)) { foreach ($attachments as $attachment) { if (is_object($attachment)) { try { $thumb = $attachment->getThumbnail(); } catch (ServerException $e) { // } if (!empty($thumb) && method_exists('File_thumbnail', 'url')) { try { $thumb_url = File_thumbnail::url($thumb->filename); $oembed['thumbnail_url'] = $thumb_url; break; // only first one } catch (ClientException $e) { // } } } } } if ($this->format == 'json') { $this->initDocument('json'); print json_encode($oembed); $this->endDocument('json'); } elseif ($this->format == 'xml') { $this->initDocument('xml'); $this->elementStart('oembed'); foreach (array('version', 'type', 'provider_name', 'provider_url', 'title', 'author_name', 'author_url', 'url', 'html') as $key) { if (isset($oembed[$key]) && $oembed[$key] != '') { $this->element($key, null, $oembed[$key]); } } $this->elementEnd('oembed'); $this->endDocument('xml'); } else { $this->serverError(sprintf(_('Format %s not supported.'), $this->format), 501); } }
/** * Returns an array based on this activity suitable * for encoding as a JSON object * * @return array $activity */ function asArray() { $activity = array(); // actor $activity['actor'] = $this->actor->asArray(); // content $activity['content'] = $this->content; // generator <-- We could use this when we know a notice is created // locally. Or if we know the upstream Generator. // icon <-- possibly a mini object representing verb? // id $activity['id'] = $this->id; // object if ($this->verb == ActivityVerb::POST && count($this->objects) == 1) { $activity['object'] = $this->objects[0]->asArray(); // Context stuff. For now I'm just sticking most of it // in a property called "context" if (!empty($this->context)) { if (!empty($this->context->location)) { $loc = $this->context->location; // GeoJSON $activity['geopoint'] = array('type' => 'Point', 'coordinates' => array($loc->lat, $loc->lon), 'deprecated' => true); $activity['location'] = array('objectType' => 'place', 'position' => sprintf("%+02.5F%+03.5F/", $loc->lat, $loc->lon), 'lat' => $loc->lat, 'lon' => $loc->lon); $name = $loc->getName(); if ($name) { $activity['location']['displayName'] = $name; } $url = $loc->getURL(); if ($url) { $activity['location']['url'] = $url; } } $activity['to'] = $this->context->getToArray(); $activity['context'] = $this->context->asArray(); } // Instead of adding enclosures as an extension to JSON // Activities, it seems like we should be using the // attachements property of ActivityObject $attachments = array(); // XXX: OK, this is kinda cheating. We should probably figure out // what kind of objects these are based on mime-type and then // create specific object types. Right now this rely on // duck-typing. Also, we should include an embed code for // video attachments. foreach ($this->enclosures as $enclosure) { if (is_string($enclosure)) { $attachments[]['id'] = $enclosure; } else { $attachments[]['id'] = $enclosure->url; $mediaLink = new ActivityStreamsMediaLink($enclosure->url, null, null, $enclosure->mimetype); $attachments[]['mediaLink'] = $mediaLink->asArray(); // extension if ($enclosure->title) { $attachments[]['displayName'] = $enclosure->title; } } } if (!empty($attachments)) { $activity['object']['attachments'] = $attachments; } } else { $activity['object'] = array(); foreach ($this->objects as $object) { $oa = $object->asArray(); if ($object instanceof Activity) { // throw in a type // XXX: hackety-hack $oa['objectType'] = 'activity'; } $activity['object'][] = $oa; } } // published $activity['published'] = self::iso8601Date($this->time); // provider $provider = array('objectType' => 'service', 'displayName' => common_config('site', 'name'), 'url' => common_root_url()); $activity['provider'] = $provider; // target if (!empty($this->target)) { $activity['target'] = $this->target->asArray(); } // title $activity['title'] = $this->title; // updated <-- Optional. Should we use this to indicate the time we r // eceived a remote notice? Probably not. // verb // // We can probably use the whole schema URL here but probably the // relative simple name is easier to parse $activity['verb'] = substr($this->verb, strrpos($this->verb, '/') + 1); // url $activity['url'] = $this->id; /* Purely extensions hereafter */ if ($activity['verb'] == 'post') { $tags = array(); foreach ($this->categories as $cat) { if (mb_strlen($cat->term) > 0) { // Couldn't figure out which object type to use, so... $tags[] = array('objectType' => 'http://activityschema.org/object/hashtag', 'displayName' => $cat->term); } } if (count($tags) > 0) { $activity['object']['tags'] = $tags; } } // XXX: a bit of a hack... Since JSON isn't namespaced we probably // shouldn't be using 'statusnet:notice_info', but this will work // for the moment. foreach ($this->extra as $e) { list($objectName, $props, $txt) = $e; if (!empty($objectName)) { $activity[$objectName] = $props; } } return array_filter($activity); }
function replies($args, $apidata) { parent::handle($args); $since = $this->arg('since'); $count = $this->arg('count'); $page = $this->arg('page'); $since_id = $this->arg('since_id'); $before_id = $this->arg('before_id'); $user = $this->get_user($apidata['api_arg'], $apidata); $this->auth_user = $apidata['user']; $profile = $user->getProfile(); $sitename = common_config('site', 'name'); $title = sprintf(_('%1$s / Updates replying to %2$s'), $sitename, $user->nickname); $taguribase = common_config('integration', 'taguri'); $id = "tag:{$taguribase}:Replies:" . $user->id; $link = common_local_url('replies', array('nickname' => $user->nickname)); $subtitle = sprintf(_('%1$s updates that reply to updates from %2$s / %3$s.'), $sitename, $user->nickname, $profile->getBestName()); if (!$page) { $page = 1; } if (!$count) { $count = 20; } if (!$since_id) { $since_id = 0; } // NOTE: before_id is an extension to Twitter API -- TB if (!$before_id) { $before_id = 0; } $since = strtotime($this->arg('since')); $notice = $user->getReplies(($page - 1) * 20, $count, $since_id, $before_id, $since); $notices = array(); while ($notice->fetch()) { $notices[] = clone $notice; } switch ($apidata['content-type']) { case 'xml': $this->show_xml_timeline($notices); break; case 'rss': $this->show_rss_timeline($notices, $title, $link, $subtitle); break; case 'atom': if (isset($apidata['api_arg'])) { $selfuri = $selfuri = common_root_url() . 'api/statuses/replies/' . $apidata['api_arg'] . '.atom'; } else { $selfuri = $selfuri = common_root_url() . 'api/statuses/replies.atom'; } $this->show_atom_timeline($notices, $title, $id, $link, $subtitle, null, $selfuri); break; case 'json': $this->show_json_timeline($notices); break; default: $this->clientError(_('API method not found!'), $code = 404); } }
function show_messages($args, $apidata, $type) { $user = $apidata['user']; $count = $this->arg('count'); $since = $this->arg('since'); $since_id = $this->arg('since_id'); $before_id = $this->arg('before_id'); $page = $this->arg('page'); if (!$page) { $page = 1; } if (!$count) { $count = 20; } $message = new Message(); $title = null; $subtitle = null; $link = null; $server = common_root_url(); if ($type == 'received') { $message->to_profile = $user->id; $title = sprintf(_("Direct messages to %s"), $user->nickname); $subtitle = sprintf(_("All the direct messages sent to %s"), $user->nickname); $link = $server . $user->nickname . '/inbox'; } else { $message->from_profile = $user->id; $title = _('Direct Messages You\'ve Sent'); $subtitle = sprintf(_("All the direct messages sent from %s"), $user->nickname); $link = $server . $user->nickname . '/outbox'; } if ($before_id) { $message->whereAdd("id < {$before_id}"); } if ($since_id) { $message->whereAdd("id > {$since_id}"); } $since = strtotime($this->arg('since')); if ($since) { $d = date('Y-m-d H:i:s', $since); $message->whereAdd("created > '{$d}'"); } $message->orderBy('created DESC, id DESC'); $message->limit(($page - 1) * 20, $count); $message->find(); switch ($apidata['content-type']) { case 'xml': $this->show_xml_dmsgs($message); break; case 'rss': $this->show_rss_dmsgs($message, $title, $link, $subtitle); break; case 'atom': $selfuri = common_root_url() . 'api/direct_messages'; $selfuri .= $type == 'received' ? '.atom' : '/sent.atom'; $taguribase = common_config('integration', 'taguri'); if ($type == 'sent') { $id = "tag:{$taguribase}:SentDirectMessages:" . $user->id; } else { $id = "tag:{$taguribase}:DirectMessages:" . $user->id; } $this->show_atom_dmsgs($message, $title, $link, $subtitle, $selfuri, $id); break; case 'json': $this->show_json_dmsgs($message); break; default: $this->clientError(_('API method not found!'), $code = 404); } }
function handle($args) { common_debug("in oembed api action"); $url = $args['url']; if (substr(strtolower($url), 0, strlen(common_root_url())) == strtolower(common_root_url())) { $path = substr($url, strlen(common_root_url())); $r = Router::get(); $proxy_args = $r->map($path); if (!$proxy_args) { // TRANS: Server error displayed in oEmbed action when path not found. // TRANS: %s is a path. $this->serverError(sprintf(_('"%s" not found.'), $path), 404); } $oembed = array(); $oembed['version'] = '1.0'; $oembed['provider_name'] = common_config('site', 'name'); $oembed['provider_url'] = common_root_url(); switch ($proxy_args['action']) { case 'shownotice': $oembed['type'] = 'link'; $id = $proxy_args['notice']; $notice = Notice::staticGet($id); if (empty($notice)) { // TRANS: Server error displayed in oEmbed action when notice not found. // TRANS: %s is a notice. $this->serverError(sprintf(_("Notice %s not found."), $id), 404); } $profile = $notice->getProfile(); if (empty($profile)) { // TRANS: Server error displayed in oEmbed action when notice has not profile. $this->serverError(_('Notice has no profile.'), 500); } $authorname = $profile->getFancyName(); // TRANS: oEmbed title. %1$s is the author name, %2$s is the creation date. $oembed['title'] = sprintf(_('%1$s\'s status on %2$s'), $authorname, common_exact_date($notice->created)); $oembed['author_name'] = $authorname; $oembed['author_url'] = $profile->profileurl; $oembed['url'] = $notice->url ? $notice->url : $notice->uri; $oembed['html'] = $notice->rendered; break; case 'attachment': $id = $proxy_args['attachment']; $attachment = File::staticGet($id); if (empty($attachment)) { // TRANS: Server error displayed in oEmbed action when attachment not found. // TRANS: %d is an attachment ID. $this->serverError(sprintf(_('Attachment %s not found.'), $id), 404); } if (empty($attachment->filename) && ($file_oembed = File_oembed::staticGet('file_id', $attachment->id))) { // Proxy the existing oembed information $oembed['type'] = $file_oembed->type; $oembed['provider'] = $file_oembed->provider; $oembed['provider_url'] = $file_oembed->provider_url; $oembed['width'] = $file_oembed->width; $oembed['height'] = $file_oembed->height; $oembed['html'] = $file_oembed->html; $oembed['title'] = $file_oembed->title; $oembed['author_name'] = $file_oembed->author_name; $oembed['author_url'] = $file_oembed->author_url; $oembed['url'] = $file_oembed->url; } else { if (substr($attachment->mimetype, 0, strlen('image/')) == 'image/') { $oembed['type'] = 'photo'; if ($attachment->filename) { $filepath = File::path($attachment->filename); $gis = @getimagesize($filepath); if ($gis) { $oembed['width'] = $gis[0]; $oembed['height'] = $gis[1]; } else { // TODO Either throw an error or find a fallback? } } $oembed['url'] = $attachment->url; $thumb = $attachment->getThumbnail(); if ($thumb) { $oembed['thumbnail_url'] = $thumb->url; $oembed['thumbnail_width'] = $thumb->width; $oembed['thumbnail_height'] = $thumb->height; } } else { $oembed['type'] = 'link'; $oembed['url'] = common_local_url('attachment', array('attachment' => $attachment->id)); } } if ($attachment->title) { $oembed['title'] = $attachment->title; } break; default: // TRANS: Server error displayed in oEmbed request when a path is not supported. // TRANS: %s is a path. $this->serverError(sprintf(_('"%s" not supported for oembed requests.'), $path), 501); } switch ($args['format']) { case 'xml': $this->init_document('xml'); $this->elementStart('oembed'); $this->element('version', null, $oembed['version']); $this->element('type', null, $oembed['type']); if ($oembed['provider_name']) { $this->element('provider_name', null, $oembed['provider_name']); } if ($oembed['provider_url']) { $this->element('provider_url', null, $oembed['provider_url']); } if ($oembed['title']) { $this->element('title', null, $oembed['title']); } if ($oembed['author_name']) { $this->element('author_name', null, $oembed['author_name']); } if ($oembed['author_url']) { $this->element('author_url', null, $oembed['author_url']); } if ($oembed['url']) { $this->element('url', null, $oembed['url']); } if ($oembed['html']) { $this->element('html', null, $oembed['html']); } if ($oembed['width']) { $this->element('width', null, $oembed['width']); } if ($oembed['height']) { $this->element('height', null, $oembed['height']); } if ($oembed['cache_age']) { $this->element('cache_age', null, $oembed['cache_age']); } if ($oembed['thumbnail_url']) { $this->element('thumbnail_url', null, $oembed['thumbnail_url']); } if ($oembed['thumbnail_width']) { $this->element('thumbnail_width', null, $oembed['thumbnail_width']); } if ($oembed['thumbnail_height']) { $this->element('thumbnail_height', null, $oembed['thumbnail_height']); } $this->elementEnd('oembed'); $this->end_document('xml'); break; case 'json': case '': $this->init_document('json'); print json_encode($oembed); $this->end_document('json'); break; default: // TRANS: Error message displaying attachments. %s is a raw MIME type (eg 'image/png') $this->serverError(sprintf(_('Content type %s not supported.'), $apidata['content-type']), 501); } } else { // TRANS: Error message displaying attachments. %s is the site's base URL. $this->serverError(sprintf(_('Only %s URLs over plain HTTP please.'), common_root_url()), 404); } }
function initRss() { $channel = $this->getChannel(); header('Content-Type: application/rdf+xml'); $this->startXml(); $this->elementStart('rdf:RDF', array('xmlns:rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'xmlns:dc' => 'http://purl.org/dc/elements/1.1/', 'xmlns:cc' => 'http://web.resource.org/cc/', 'xmlns:content' => 'http://purl.org/rss/1.0/modules/content/', 'xmlns:foaf' => 'http://xmlns.com/foaf/0.1/', 'xmlns:sioc' => 'http://rdfs.org/sioc/ns#', 'xmlns:sioct' => 'http://rdfs.org/sioc/types#', 'xmlns:laconica' => 'http://laconi.ca/ont/', 'xmlns' => 'http://purl.org/rss/1.0/')); $this->elementStart('sioc:Site', array('rdf:about' => common_root_url())); $this->element('sioc:name', null, common_config('site', 'name')); $this->elementStart('sioc:container_of'); $this->element('sioc:Container', array('rdf:about' => $channel['url'])); $this->elementEnd('sioc:container_of'); $this->elementEnd('sioc:Site'); }
/** * Shows a list of direct messages as Atom entries * * @return void */ function showAtomDirectMessages() { $this->initDocument('atom'); $this->element('title', null, $this->title); $this->element('id', null, $this->id); $selfuri = common_root_url() . 'api/direct_messages.atom'; $this->element('link', array('href' => $this->link, 'rel' => 'alternate', 'type' => 'text/html'), null); $this->element('link', array('href' => $this->selfuri_base . '.atom', 'rel' => 'self', 'type' => 'application/atom+xml'), null); $this->element('updated', null, common_date_iso8601('now')); $this->element('subtitle', null, $this->subtitle); foreach ($this->messages as $m) { $entry = $this->rssDirectMessageArray($m); $this->showTwitterAtomEntry($entry); } $this->endDocument('atom'); }
function sendInvitation($email, $user, $personal) { $profile = $user->getProfile(); $bestname = $profile->getBestName(); $sitename = common_config('site', 'name'); $invite = new Invitation(); $invite->address = $email; $invite->address_type = 'email'; $invite->code = common_confirmation_code(128); $invite->user_id = $user->id; $invite->created = common_sql_now(); if (!$invite->insert()) { common_log_db_error($invite, 'INSERT', __FILE__); return false; } $recipients = array($email); $headers['From'] = mail_notify_from(); $headers['To'] = trim($email); $headers['Subject'] = sprintf(_('%1$s has invited you to join them on %2$s'), $bestname, $sitename); $body = sprintf(_("%1\$s has invited you to join them on %2\$s (%3\$s).\n\n" . "%2\$s is a micro-blogging service that lets you keep up-to-date with people you know and people who interest you.\n\n" . "You can also share news about yourself, your thoughts, or your life online with people who know about you. " . "It's also great for meeting new people who share your interests.\n\n" . "%1\$s said:\n\n%4\$s\n\n" . "You can see %1\$s's profile page on %2\$s here:\n\n" . "%5\$s\n\n" . "If you'd like to try the service, click on the link below to accept the invitation.\n\n" . "%6\$s\n\n" . "If not, you can ignore this message. Thanks for your patience and your time.\n\n" . "Sincerely, %2\$s\n"), $bestname, $sitename, common_root_url(), $personal, common_local_url('showstream', array('nickname' => $user->nickname)), common_local_url('register', array('code' => $invite->code))); mail_send($recipients, $headers, $body); }
/** * Returns an array based on this activity suitable * for encoding as a JSON object * * @return array $activity */ function asArray() { $activity = array(); // actor $activity['actor'] = $this->actor->asArray(); // content $activity['content'] = $this->content; // generator if (!empty($this->generator)) { $activity['generator'] = $this->generator->asArray(); } // icon <-- possibly a mini object representing verb? // id $activity['id'] = $this->id; // object if (count($this->objects) == 0) { common_log(LOG_ERR, "Can't save " . $this->id); } else { if (count($this->objects) > 1) { common_log(LOG_WARNING, "Ignoring " . (count($this->objects) - 1) . " extra objects in JSON output for activity " . $this->id); } $object = $this->objects[0]; if ($object instanceof Activity) { // Sharing a post activity is more like sharing the original object if (ActivityVerb::canonical($this->verb) == ActivityVerb::canonical(ActivityVerb::SHARE) && ActivityVerb::canonical($object->verb) == ActivityVerb::canonical(ActivityVerb::POST)) { // XXX: Here's one for the obfuscation record books $object = $object->objects[0]; } } $activity['object'] = $object->asArray(); if ($object instanceof Activity) { $activity['object']['objectType'] = 'activity'; } foreach ($this->attachments as $attachment) { if (empty($activity['object']['attachments'])) { $activity['object']['attachments'] = array(); } $activity['object']['attachments'][] = $attachment->asArray(); } } // Context stuff. if (!empty($this->context)) { if (!empty($this->context->location)) { $loc = $this->context->location; $activity['location'] = array('objectType' => 'place', 'position' => sprintf("%+02.5F%+03.5F/", $loc->lat, $loc->lon), 'lat' => $loc->lat, 'lon' => $loc->lon); $name = $loc->getName(); if ($name) { $activity['location']['displayName'] = $name; } $url = $loc->getURL(); if ($url) { $activity['location']['url'] = $url; } } $activity['to'] = $this->context->getToArray(); $ctxarr = $this->context->asArray(); if (array_key_exists('inReplyTo', $ctxarr)) { $activity['object']['inReplyTo'] = $ctxarr['inReplyTo']; unset($ctxarr['inReplyTo']); } if (!array_key_exists('status_net', $activity)) { $activity['status_net'] = array(); } foreach ($ctxarr as $key => $value) { $activity['status_net'][$key] = $value; } } // published $activity['published'] = self::iso8601Date($this->time); // provider $provider = array('objectType' => 'service', 'displayName' => common_config('site', 'name'), 'url' => common_root_url()); $activity['provider'] = $provider; // target if (!empty($this->target)) { $activity['target'] = $this->target->asArray(); } // title $activity['title'] = $this->title; // updated <-- Optional. Should we use this to indicate the time we r // eceived a remote notice? Probably not. // verb $activity['verb'] = ActivityVerb::canonical($this->verb); // url if ($this->link) { $activity['url'] = $this->link; } /* Purely extensions hereafter */ if ($activity['verb'] == 'post') { $tags = array(); foreach ($this->categories as $cat) { if (mb_strlen($cat->term) > 0) { // Couldn't figure out which object type to use, so... $tags[] = array('objectType' => 'http://activityschema.org/object/hashtag', 'displayName' => $cat->term); } } if (count($tags) > 0) { $activity['object']['tags'] = $tags; } } // XXX: a bit of a hack... Since JSON isn't namespaced we probably // shouldn't be using 'statusnet:notice_info', but this will work // for the moment. foreach ($this->extra as $e) { list($objectName, $props, $txt) = $e; if (!empty($objectName)) { $parts = explode(":", $objectName); if (count($parts) == 2 && $parts[0] == "statusnet") { if (!array_key_exists('status_net', $activity)) { $activity['status_net'] = array(); } $activity['status_net'][$parts[1]] = $props; } else { $activity[$objectName] = $props; } } } return array_filter($activity); }
function oid_authenticate($openid_url, $returnto, $immediate = false) { $consumer = oid_consumer(); if (!$consumer) { common_server_error(_m('Cannot instantiate OpenID consumer object.')); return false; } common_ensure_session(); $auth_request = $consumer->begin($openid_url); // Handle failure status return values. if (!$auth_request) { return _m('Not a valid OpenID.'); } else { if (Auth_OpenID::isFailure($auth_request)) { return sprintf(_m('OpenID failure: %s'), $auth_request->message); } } $sreg_request = Auth_OpenID_SRegRequest::build(array(), array('nickname', 'email', 'fullname', 'language', 'timezone', 'postcode', 'country')); if ($sreg_request) { $auth_request->addExtension($sreg_request); } $trust_root = common_root_url(true); $process_url = common_local_url($returnto); if ($auth_request->shouldSendRedirect()) { $redirect_url = $auth_request->redirectURL($trust_root, $process_url, $immediate); if (!$redirect_url) { } else { if (Auth_OpenID::isFailure($redirect_url)) { return sprintf(_m('Could not redirect to server: %s'), $redirect_url->message); } else { common_redirect($redirect_url, 303); } } } else { // Generate form markup and render it. $form_id = 'openid_message'; $form_html = $auth_request->formMarkup($trust_root, $process_url, $immediate, array('id' => $form_id)); # XXX: This is cheap, but things choke if we don't escape ampersands # in the HTML attributes $form_html = preg_replace('/&/', '&', $form_html); // Display an error if the form markup couldn't be generated; // otherwise, render the HTML. if (Auth_OpenID::isFailure($form_html)) { common_server_error(sprintf(_m('Could not create OpenID form: %s'), $form_html->message)); } else { $action = new AutosubmitAction(); // see below $action->form_html = $form_html; $action->form_id = $form_id; $action->prepare(array('action' => 'autosubmit')); $action->handle(array('action' => 'autosubmit')); } } }
function omb_oauth_consumer() { // Don't try to make this static. Leads to issues in // multi-site setups - Z return new OAuthConsumer(common_root_url(), ''); }
function showReportGrader() { $groupsUser = $this->user->getGroups()->fetchAll(); if (empty($groupsUser)) { $this->element('p', null, 'Todavía no perteneces a ningún grupo.'); } foreach ($groupsUser as $group) { $gradespergroup = Grades::getGradedNoticesAndUsersWithinGroup($group->id); $nicksMembers = Grades::getMembersNicksExcludeGradersAndAdmin($group->id); foreach ($nicksMembers as $nick) { if (!array_key_exists($nick, $gradespergroup)) { $gradespergroup[$nick] = '0'; } } $this->elementStart('div', array('id' => 'grade-report-group-' . $group->id, 'class' => 'div-group-report')); $this->elementStart('h3', array('class' => 'grade-report-group', 'title' => $group->getBestName())); $this->element('a', array('class' => 'grade-report-group-link', 'href' => common_root_url() . 'group/' . $group->nickname), $group->getBestName()); $this->elementEnd('h3'); $this->element('a', array('class' => 'grade-show-report', 'href' => 'javascript:mostrarReport(' . $group->id . ');'), 'Expandir'); $this->element('a', array('class' => 'grade-export-report', 'href' => common_local_url('gradeoptionscsv') . '?group=' . $group->id), 'Exportar CSV'); $this->element('p', array('class' => 'grade-reports-group-underline'), ''); $this->elementStart('div', array('class' => 'report-group-hidden')); if (empty($gradespergroup)) { $this->element('p', null, 'Todavía no hay puntuaciones.'); } else { $this->elementStart('ol', array('class' => 'grade-report-groupmembers')); foreach ($gradespergroup as $alumno => $puntuacion) { $this->elementStart('li', array('class' => 'grade-report-groupmembers-item')); $profile = Profile::staticGet('nickname', $alumno); $avatar = $profile->getAvatar(AVATAR_MINI_SIZE); if ($avatar) { $avatar = $avatar->displayUrl(); } else { $avatar = Avatar::defaultImage(AVATAR_MINI_SIZE); } $this->element('img', array('src' => $avatar)); $this->elementStart('a', array('class' => 'user-link-report', 'href' => common_local_url('gradeshowuser', array('nickgroup' => $group->nickname, 'nickname' => $profile->nickname)))); $this->raw($profile->getBestName() . ', ' . number_format($puntuacion, 2)); $this->elementEnd('a'); $this->elementEnd('li'); } $this->elementEnd('ol'); } $this->elementEnd('div'); $this->elementEnd('div'); } }