+ function onStartShowTagProfileForm($action, $profile)
+ {
+ $action->elementStart('form', array('method' => 'post',
+ 'id' => 'form_tag_user',
+ 'class' => 'form_settings',
+ 'name' => 'tagprofile',
+ 'action' => common_local_url('tagprofile', array('id' => @$profile->id))));
+
+ $action->elementStart('fieldset');
+ $action->element('legend', null, _('Tag remote profile'));
+ $action->hidden('token', common_session_token());
+
+ $user = common_current_user();
+
+ $action->elementStart('ul', 'form_data');
+ $action->elementStart('li');
+
+ $action->input('uri', _('Remote profile'), $action->trimmed('uri'),
+ _('OStatus user\'s address, like nickname@example.com or http://example.net/nickname'));
+ $action->elementEnd('li');
+ $action->elementEnd('ul');
+ $action->submit('fetch', _('Fetch'));
+ $action->elementEnd('fieldset');
+ $action->elementEnd('form');
+ }
+
+ function onStartTagProfileAction($action, $profile)
+ {
+ $err = null;
+ $uri = $action->trimmed('uri');
+
+ if (!$profile && $uri) {
+ try {
+ if (Validate::email($uri)) {
+ $oprofile = Ostatus_profile::ensureWebfinger($uri);
+ } else if (Validate::uri($uri)) {
+ $oprofile = Ostatus_profile::ensureProfileURL($uri);
+ } else {
+ throw new Exception('Invalid URI');
+ }
+
+ // redirect to the new profile.
+ common_redirect(common_local_url('tagprofile', array('id' => $oprofile->profile_id)), 303);
+ return false;
+
+ } catch (Exception $e) {
+ $err = _m("Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname");
+ }
+
+ $action->showForm($err);
+ return false;
+ }
+ return true;
+ }
+
+ /*
+ * If the field being looked for is URI look for the profile
+ */
+ function onStartProfileCompletionSearch($action, $profile, $search_engine) {
+ if ($action->field == 'uri') {
+ $user = new User();
+ $profile->joinAdd($user);
+ $profile->whereAdd('uri LIKE "%' . $profile->escape($q) . '%"');
+ $profile->query();
+
+ if ($profile->N == 0) {
+ try {
+ if (Validate::email($q)) {
+ $oprofile = Ostatus_profile::ensureWebfinger($q);
+ } else if (Validate::uri($q)) {
+ $oprofile = Ostatus_profile::ensureProfileURL($q);
+ } else {
+ throw new Exception('Invalid URI');
+ }
+ return $this->filter(array($oprofile->localProfile()));
+
+ } catch (Exception $e) {
+ $this->msg = _m("Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname");
+ return array();
+ }
+ }
+ return false;
+ }
+ return true;
+ }
+