Example #1
0
 /**
  * For initializing members of the class.
  *
  * @param array $args misc. arguments
  *
  * @return boolean true
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!$this->isPost()) {
         throw new ClientException(_('POST only'), 405);
     }
     $this->checkSessionToken();
     $this->url = $this->trimmed('url');
     if (empty($this->url)) {
         throw new ClientException(_('URL is required.'), 400);
     }
     if (!Validate::uri($this->url, array('allowed_schemes' => array('http', 'https')))) {
         throw new ClientException(_('Invalid URL.'), 400);
     }
     $f = File::staticGet('url', $this->url);
     if (empty($url)) {
         $f = File::processNew($this->url);
     }
     // How about now?
     if (!empty($f)) {
         $this->oembed = File_oembed::staticGet('file_id', $f->id);
         if (!empty($this->oembed)) {
             $this->title = $this->oembed->title;
         }
         $this->thumbnail = File_thumbnail::staticGet('file_id', $f->id);
     }
     return true;
 }
 /**
  * Look up a notice from an argument, by poster's name to get last post
  * or notice_id prefixed with #.
  *
  * @return Notice
  * @throws CommandException
  */
 function getNotice($arg)
 {
     $notice = null;
     if (Event::handle('StartCommandGetNotice', array($this, $arg, &$notice))) {
         if (substr($this->other, 0, 1) == '#') {
             // A specific notice_id #123
             $notice = Notice::staticGet(substr($arg, 1));
             if (!$notice) {
                 throw new CommandException(_('Notice with that id does not exist'));
             }
         }
         if (Validate::uri($this->other)) {
             // A specific notice by URI lookup
             $notice = Notice::staticGet('uri', $arg);
         }
         if (!$notice) {
             // Local or remote profile name to get their last notice.
             // May throw an exception and report 'no such user'
             $recipient = $this->getProfile($arg);
             $notice = $recipient->getCurrentNotice();
             if (!$notice) {
                 throw new CommandException(_('User has no last notice'));
             }
         }
     }
     Event::handle('EndCommandGetNotice', array($this, $arg, &$notice));
     if (!$notice) {
         throw new CommandException(_('Notice with that id does not exist'));
     }
     return $notice;
 }
Example #3
0
 /**
  * Eventually we should use OAuth here, since this is mainly
  * for API authentication.
  *
  * For now let's just verify that they passed in a valid
  * OpenID. The API layer verifies a valid API key later anyway,
  * so we don't duplicate that effort here.
  *
  * @param string $name     the user name
  * @param string $password the password for the above user name
  *
  * @return mixed false if no auth
  *               array( contactID, ufID, unique string ) if success
  * @access public
  * @static
  */
 static function authenticate($name, $password)
 {
     // check that we got a valid URL
     $options = array('domain_check' => false, 'allowed_schemes' => array('http', 'https'));
     require_once 'Validate.php';
     $validUrl = Validate::uri($name, $options);
     if (!$validUrl) {
         return false;
     }
     // we got a valid URL, see if it's allowed to login
     require_once 'CRM/Core/BAO/OpenID.php';
     $allowLogin = CRM_Core_BAO_OpenID::isAllowedToLogin($name);
     if (!$allowLogin) {
         return false;
     }
     // see if the password matches the API key
     require_once 'CRM/Contact/BAO/Contact.php';
     $dao = CRM_Contact_BAO_Contact::matchContactOnOpenId($name);
     require_once 'CRM/Core/DAO.php';
     $api_key = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $dao->contact_id, 'api_key');
     if ($api_key != $password) {
         return false;
     }
     // everything looks good, setup the session and return
     require_once 'CRM/Standalone/User.php';
     $user = new CRM_Standalone_User($name);
     require_once 'CRM/Core/BAO/UFMatch.php';
     CRM_Core_BAO_UFMatch::synchronize($user, false, 'Standalone', 'Individual');
     require_once 'CRM/Core/Session.php';
     $session = CRM_Core_Session::singleton();
     $returnArray = array($session->get('userID'), $session->get('ufID'), mt_rand());
     return $returnArray;
 }
 /**
  * Constructor for OMB_Profile
  *
  * Initializes the OMB_Profile object with an identifier uri.
  *
  * @param string $identifier_uri The profile URI as defined by the OMB. A unique
  *                               and unchanging identifier for a profile.
  *
  * @access public
  */
 public function __construct($identifier_uri)
 {
     if (!Validate::uri($identifier_uri)) {
         throw new OMB_InvalidParameterException($identifier_uri, 'profile', 'omb_listenee or omb_listener');
     }
     $this->identifier_uri = $identifier_uri;
     $this->param_array = false;
 }
 /**
  * Test creating and then expanding a URL
  *
  * @param string $service The service to test
  *
  * @dataProvider allServices
  * @return void
  */
 public function testCreateThenExpand($service)
 {
     $api = Services_ShortURL::factory($service);
     // Create a short URL and do some sanity checking
     $small = $api->shorten($this->testURL);
     $this->assertType('string', $small);
     $this->assertTrue(Validate::uri($small), 'Invalid URL: ' . $small);
     // Expand the short URL and do some sanity checking
     $big = $api->expand($small);
     $this->assertEquals($this->testURL, $big);
 }
 /**
  * Constructor for OMB_Notice
  *
  * Initializes the OMB_Notice object with author, uri and content.
  * These parameters are mandatory for postNotice.
  *
  * @param object $author  An OMB_Profile object representing the author of the
  *                        notice.
  * @param string $uri     The notice URI as defined by the OMB. A unique and
  *                        unchanging identifier for a notice.
  * @param string $content The content of the notice. 140 chars recommended,
  *                        but there is no limit.
  *
  * @access public
  */
 public function __construct($author, $uri, $content)
 {
     $this->content = $content;
     if (is_null($author)) {
         throw new OMB_InvalidParameterException('', 'notice', 'omb_listenee');
     }
     $this->author = $author;
     if (!Validate::uri($uri)) {
         throw new OMB_InvalidParameterException($uri, 'notice', 'omb_notice');
     }
     $this->uri = $uri;
     $this->param_array = false;
 }
Example #7
0
 function save_notice(&$req, &$consumer, &$token)
 {
     $version = $req->get_parameter('omb_version');
     if ($version != OMB_VERSION_01) {
         $this->clientError(_('Unsupported OMB version'), 400);
         return false;
     }
     # First, check to see
     $listenee = $req->get_parameter('omb_listenee');
     $remote_profile = Remote_profile::staticGet('uri', $listenee);
     if (!$remote_profile) {
         $this->clientError(_('Profile unknown'), 403);
         return false;
     }
     $sub = Subscription::staticGet('token', $token->key);
     if (!$sub) {
         $this->clientError(_('No such subscription'), 403);
         return false;
     }
     $content = $req->get_parameter('omb_notice_content');
     $content_shortened = common_shorten_links($content);
     if (mb_strlen($content_shortened) > 140) {
         $this->clientError(_('Invalid notice content'), 400);
         return false;
     }
     $notice_uri = $req->get_parameter('omb_notice');
     if (!Validate::uri($notice_uri) && !common_valid_tag($notice_uri)) {
         $this->clientError(_('Invalid notice uri'), 400);
         return false;
     }
     $notice_url = $req->get_parameter('omb_notice_url');
     if ($notice_url && !common_valid_http_url($notice_url)) {
         $this->clientError(_('Invalid notice url'), 400);
         return false;
     }
     $notice = Notice::staticGet('uri', $notice_uri);
     if (!$notice) {
         $notice = Notice::saveNew($remote_profile->id, $content, 'omb', false, null, $notice_uri);
         if (is_string($notice)) {
             common_server_serror($notice, 500);
             return false;
         }
         common_broadcast_notice($notice, true);
     }
     return true;
 }
Example #8
0
 protected function checkInput()
 {
     if (!$this->request->getParam('URL') && (!isset($_FILES['File']) || $_FILES['File']['tmp_name'] == '')) {
         throw new binarypool_exception(109, 400, "No file uploaded.");
     }
     $type = $this->request->getParam('Type');
     if (!$type) {
         throw new binarypool_exception(110, 400, "Type param not given.");
     }
     if (!in_array($type, self::$UPLOAD_TYPES)) {
         throw new binarypool_exception(111, 400, "Invalid upload type: " . $this->request->getParam('Type'));
     }
     $url = $this->request->getParam('URL');
     if ($url) {
         if (!Validate::uri($url, array('allowed_schemes' => array('http', 'https')))) {
             throw new binarypool_exception(120, 400, "Invalid URL for download: " . $url);
         }
     }
 }
Example #9
0
 function trySave()
 {
     $cur = common_current_user();
     if (!$cur->isAdmin($this->group)) {
         // TRANS: Client error displayed trying to edit a group while not being a group admin.
         $this->clientError(_('You must be an admin to edit the group.'), 403);
         return;
     }
     if (Event::handle('StartGroupSaveForm', array($this))) {
         $nickname = Nickname::normalize($this->trimmed('newnickname'));
         $fullname = $this->trimmed('fullname');
         $homepage = $this->trimmed('homepage');
         $description = $this->trimmed('description');
         $location = $this->trimmed('location');
         $aliasstring = $this->trimmed('aliases');
         $private = $this->boolean('private');
         if ($private) {
             $force_scope = 1;
             $join_policy = User_group::JOIN_POLICY_MODERATE;
         } else {
             $force_scope = 0;
             $join_policy = User_group::JOIN_POLICY_OPEN;
         }
         if ($this->nicknameExists($nickname)) {
             // TRANS: Group edit form validation error.
             $this->showForm(_('Nickname already in use. Try another one.'));
             return;
         } else {
             if (!User_group::allowedNickname($nickname)) {
                 // TRANS: Group edit form validation error.
                 $this->showForm(_('Not a valid nickname.'));
                 return;
             } else {
                 if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
                     // TRANS: Group edit form validation error.
                     $this->showForm(_('Homepage is not a valid URL.'));
                     return;
                 } else {
                     if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                         // TRANS: Group edit form validation error.
                         $this->showForm(_('Full name is too long (maximum 255 characters).'));
                         return;
                     } else {
                         if (User_group::descriptionTooLong($description)) {
                             $this->showForm(sprintf(_m('Description is too long (maximum %d character).', 'Description is too long (maximum %d characters).', User_group::maxDescription()), User_group::maxDescription()));
                             return;
                         } else {
                             if (!is_null($location) && mb_strlen($location) > 255) {
                                 // TRANS: Group edit form validation error.
                                 $this->showForm(_('Location is too long (maximum 255 characters).'));
                                 return;
                             }
                         }
                     }
                 }
             }
         }
         if (!empty($aliasstring)) {
             $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\\s,]+/', $aliasstring)));
         } else {
             $aliases = array();
         }
         if (count($aliases) > common_config('group', 'maxaliases')) {
             // TRANS: Group edit form validation error.
             // TRANS: %d is the maximum number of allowed aliases.
             $this->showForm(sprintf(_m('Too many aliases! Maximum %d allowed.', 'Too many aliases! Maximum %d allowed.', common_config('group', 'maxaliases')), common_config('group', 'maxaliases')));
             return;
         }
         foreach ($aliases as $alias) {
             if (!Nickname::isValid($alias)) {
                 // TRANS: Group edit form validation error.
                 $this->showForm(sprintf(_('Invalid alias: "%s"'), $alias));
                 return;
             }
             if ($this->nicknameExists($alias)) {
                 // TRANS: Group edit form validation error.
                 $this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'), $alias));
                 return;
             }
             // XXX assumes alphanum nicknames
             if (strcmp($alias, $nickname) == 0) {
                 // TRANS: Group edit form validation error.
                 $this->showForm(_('Alias can\'t be the same as nickname.'));
                 return;
             }
         }
         // Comprobamos si hay algo que actualizar, o si no ha cambiado nada el usuario.
         $part1 = false;
         if ($this->group->nickname == $nickname && $this->group->fullname == $fullname && $this->group->homepage == $homepage && $this->group->description == $description && $this->group->location == $location && $this->group->mainpage == common_local_url('showgroup', array('nickname' => $nickname)) && $this->group->join_policy == $join_policy && $this->group->force_scope == $force_scope) {
             $part1 = true;
         } else {
             $this->group->query('BEGIN');
             $orig = clone $this->group;
             $this->group->nickname = $nickname;
             $this->group->fullname = $fullname;
             $this->group->homepage = $homepage;
             $this->group->description = $description;
             $this->group->location = $location;
             $this->group->mainpage = common_local_url('showgroup', array('nickname' => $nickname));
             $this->group->join_policy = $join_policy;
             $this->group->force_scope = $force_scope;
             $result = $this->group->update($orig);
             if (!$result) {
                 common_log_db_error($this->group, 'UPDATE', __FILE__);
                 // TRANS: Server error displayed when editing a group fails.
                 $this->serverError(_('Could not update group.'));
             }
         }
         $newaliases = array_unique($aliases);
         $oldaliases = $this->group->getAliases();
         $diffAlias1 = array_diff($oldaliases, $newaliases);
         $diffAlias2 = array_diff($newaliases, $oldaliases);
         if ($part1 && (empty($diffAlias1) && empty($diffAlias2))) {
             $this->showForm(_('Nada que actualizar'));
             return;
         }
         if (!empty($diffAlias1) || !empty($diffAlias2)) {
             if ($part1) {
                 $this->group->query('BEGIN');
                 $orig = clone $this->group;
             }
             $result = $this->group->setAliases($aliases);
             if (!$result) {
                 // TRANS: Server error displayed when group aliases could not be added.
                 $this->serverError(_('Could not create aliases.'));
             }
         }
         if ($nickname != $orig->nickname) {
             common_log(LOG_INFO, "Saving local group info.");
             $local = Local_group::staticGet('group_id', $this->group->id);
             $local->setNickname($nickname);
         }
         $this->group->query('COMMIT');
         Event::handle('EndGroupSaveForm', array($this));
     }
     if ($this->group->nickname != $orig->nickname) {
         common_redirect(common_local_url('editgroup', array('nickname' => $nickname)), 303);
     } else {
         // TRANS: Group edit form success message.
         $this->showForm(_('Options saved.'));
     }
 }
Example #10
0
 */
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
$longoptions = array('skip=', 'count=');
$helptext = <<<END_OF_HELP
testfeed.php [options] http://example.com/atom-feed-url
Pull an Atom feed and run items in it as though they were live PuSH updates.
Mainly intended for testing funky feed formats.

     --skip=N   Ignore the first N items in the feed.
     --count=N  Only process up to N items from the feed, after skipping.


END_OF_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
$validate = new Validate();
if (empty($args[0]) || !$validate->uri($args[0])) {
    print "{$helptext}";
    exit(1);
}
$feedurl = $args[0];
$skip = have_option('skip') ? intval(get_option_value('skip')) : 0;
$count = have_option('count') ? intval(get_option_value('count')) : 0;
$sub = FeedSub::getKV('uri', $feedurl);
if (!$sub) {
    print "Feed {$feedurl} is not subscribed.\n";
    exit(1);
}
// Fetch the URL
try {
    $xml = HTTPClient::quickGet($feedurl, 'text/html,application/xhtml+xml');
} catch (Exception $e) {
Example #11
0
 static function url($url, $checkDomain = false)
 {
     $options = array('domain_check' => $checkDomain, 'allowed_schemes' => array('http', 'https', 'mailto', 'ftp'));
     require_once 'Validate.php';
     return Validate::uri($url, $options);
 }
Example #12
0
 /**
  * Set API
  * 
  * @param mixed $api Api url to set
  *
  * @return void
  */
 public function setAPI($api)
 {
     if (!Validate::uri($api)) {
         throw new Services_Facebook('Invalid API: ' . $api);
     }
     $this->api = $api;
 }
Example #13
0
 /**
  * Handle a post
  *
  * Validate input and save changes. Reload the form with a success
  * or error message.
  *
  * @return void
  */
 function handlePost()
 {
     // CSRF protection
     $token = $this->trimmed('token');
     if (!$token || $token != common_session_token()) {
         // TRANS: Form validation error.
         $this->showForm(_('There was a problem with your session token. ' . 'Try again, please.'));
         return;
     }
     if (Event::handle('StartProfileSaveForm', array($this))) {
         try {
             $nickname = Nickname::normalize($this->trimmed('nickname'));
         } catch (NicknameException $e) {
             $this->showForm($e->getMessage());
             return;
         }
         $fullname = $this->trimmed('fullname');
         $homepage = $this->trimmed('homepage');
         $bio = $this->trimmed('bio');
         $location = $this->trimmed('location');
         $autosubscribe = $this->boolean('autosubscribe');
         $subscribe_policy = $this->trimmed('subscribe_policy');
         $private_stream = $this->boolean('private_stream');
         $language = $this->trimmed('language');
         $timezone = $this->trimmed('timezone');
         $tagstring = $this->trimmed('tags');
         // Some validation
         if (!User::allowed_nickname($nickname)) {
             // TRANS: Validation error in form for profile settings.
             $this->showForm(_('Not a valid nickname.'));
             return;
         } else {
             if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
                 // TRANS: Validation error in form for profile settings.
                 $this->showForm(_('Homepage is not a valid URL.'));
                 return;
             } else {
                 if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                     // TRANS: Validation error in form for profile settings.
                     $this->showForm(_('Full name is too long (maximum 255 characters).'));
                     return;
                 } else {
                     if (Profile::bioTooLong($bio)) {
                         // TRANS: Validation error in form for profile settings.
                         // TRANS: Plural form is used based on the maximum number of allowed
                         // TRANS: characters for the biography (%d).
                         $this->showForm(sprintf(_m('Bio is too long (maximum %d character).', 'Bio is too long (maximum %d characters).', Profile::maxBio()), Profile::maxBio()));
                         return;
                     } else {
                         if (!is_null($location) && mb_strlen($location) > 255) {
                             // TRANS: Validation error in form for profile settings.
                             $this->showForm(_('Location is too long (maximum 255 characters).'));
                             return;
                         } else {
                             if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
                                 // TRANS: Validation error in form for profile settings.
                                 $this->showForm(_('Timezone not selected.'));
                                 return;
                             } else {
                                 if ($this->nicknameExists($nickname)) {
                                     // TRANS: Validation error in form for profile settings.
                                     $this->showForm(_('Nickname already in use. Try another one.'));
                                     return;
                                 } else {
                                     if (!is_null($language) && strlen($language) > 50) {
                                         // TRANS: Validation error in form for profile settings.
                                         $this->showForm(_('Language is too long (maximum 50 characters).'));
                                         return;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $tags = array();
         $tag_priv = array();
         if (is_string($tagstring) && strlen($tagstring) > 0) {
             $tags = preg_split('/[\\s,]+/', $tagstring);
             foreach ($tags as &$tag) {
                 $private = @$tag[0] === '.';
                 $tag = common_canonical_tag($tag);
                 if (!common_valid_profile_tag($tag)) {
                     // TRANS: Validation error in form for profile settings.
                     // TRANS: %s is an invalid tag.
                     $this->showForm(sprintf(_('Invalid tag: "%s".'), $tag));
                     return;
                 }
                 $tag_priv[$tag] = $private;
             }
         }
         $user = common_current_user();
         $user->query('BEGIN');
         if ($user->nickname != $nickname || $user->language != $language || $user->timezone != $timezone) {
             common_debug('Updating user nickname from ' . $user->nickname . ' to ' . $nickname, __FILE__);
             common_debug('Updating user language from ' . $user->language . ' to ' . $language, __FILE__);
             common_debug('Updating user timezone from ' . $user->timezone . ' to ' . $timezone, __FILE__);
             $original = clone $user;
             $user->nickname = $nickname;
             $user->language = $language;
             $user->timezone = $timezone;
             $result = $user->updateKeys($original);
             if ($result === false) {
                 common_log_db_error($user, 'UPDATE', __FILE__);
                 // TRANS: Server error thrown when user profile settings could not be updated.
                 $this->serverError(_('Could not update user.'));
                 return;
             } else {
                 // Re-initialize language environment if it changed
                 common_init_language();
                 // Clear the site owner, in case nickname changed
                 if ($user->hasRole(Profile_role::OWNER)) {
                     User::blow('user:site_owner');
                 }
             }
         }
         // XXX: XOR
         if ($user->autosubscribe ^ $autosubscribe || $user->private_stream ^ $private_stream || $user->subscribe_policy != $subscribe_policy) {
             $original = clone $user;
             $user->autosubscribe = $autosubscribe;
             $user->private_stream = $private_stream;
             $user->subscribe_policy = $subscribe_policy;
             $result = $user->update($original);
             if ($result === false) {
                 common_log_db_error($user, 'UPDATE', __FILE__);
                 // TRANS: Server error thrown when user profile settings could not be updated to
                 // TRANS: automatically subscribe to any subscriber.
                 $this->serverError(_('Could not update user for autosubscribe or subscribe_policy.'));
                 return;
             }
         }
         $profile = $user->getProfile();
         $orig_profile = clone $profile;
         $profile->nickname = $user->nickname;
         $profile->fullname = $fullname;
         $profile->homepage = $homepage;
         $profile->bio = $bio;
         $profile->location = $location;
         $loc = Location::fromName($location);
         if (empty($loc)) {
             $profile->lat = null;
             $profile->lon = null;
             $profile->location_id = null;
             $profile->location_ns = null;
         } else {
             $profile->lat = $loc->lat;
             $profile->lon = $loc->lon;
             $profile->location_id = $loc->location_id;
             $profile->location_ns = $loc->location_ns;
         }
         $profile->profileurl = common_profile_url($nickname);
         if (common_config('location', 'share') == 'user') {
             $exists = false;
             $prefs = User_location_prefs::staticGet('user_id', $user->id);
             if (empty($prefs)) {
                 $prefs = new User_location_prefs();
                 $prefs->user_id = $user->id;
                 $prefs->created = common_sql_now();
             } else {
                 $exists = true;
                 $orig = clone $prefs;
             }
             $prefs->share_location = $this->boolean('sharelocation');
             if ($exists) {
                 $result = $prefs->update($orig);
             } else {
                 $result = $prefs->insert();
             }
             if ($result === false) {
                 common_log_db_error($prefs, $exists ? 'UPDATE' : 'INSERT', __FILE__);
                 // TRANS: Server error thrown when user profile location preference settings could not be updated.
                 $this->serverError(_('Could not save location prefs.'));
                 return;
             }
         }
         common_debug('Old profile: ' . common_log_objstring($orig_profile), __FILE__);
         common_debug('New profile: ' . common_log_objstring($profile), __FILE__);
         $result = $profile->update($orig_profile);
         if ($result === false) {
             common_log_db_error($profile, 'UPDATE', __FILE__);
             // TRANS: Server error thrown when user profile settings could not be saved.
             $this->serverError(_('Could not save profile.'));
             return;
         }
         // Set the user tags
         $result = $user->setSelfTags($tags, $tag_priv);
         if (!$result) {
             // TRANS: Server error thrown when user profile settings tags could not be saved.
             $this->serverError(_('Could not save tags.'));
             return;
         }
         $user->query('COMMIT');
         Event::handle('EndProfileSaveForm', array($this));
         common_broadcast_profile($profile);
         // TRANS: Confirmation shown when user profile settings are saved.
         $this->showForm(_('Settings saved.'), true);
     }
 }
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
$longoptions = array('skip=', 'count=');
$helptext = <<<END_OF_HELP
testfeed.php [options] http://example.com/atom-feed-url
Pull an Atom feed and run items in it as though they were live PuSH updates.
Mainly intended for testing funky feed formats.

     --skip=N   Ignore the first N items in the feed.
     --count=N  Only process up to N items from the feed, after skipping.


END_OF_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
if (empty($args[0]) || !Validate::uri($args[0])) {
    print "{$helptext}";
    exit(1);
}
$feedurl = $args[0];
$skip = have_option('skip') ? intval(get_option_value('skip')) : 0;
$count = have_option('count') ? intval(get_option_value('count')) : 0;
$sub = FeedSub::staticGet('topic', $feedurl);
if (!$sub) {
    print "Feed {$feedurl} is not subscribed.\n";
    exit(1);
}
$xml = file_get_contents($feedurl);
if ($xml === false) {
    print "Bad fetch.\n";
    exit(1);
function pullOstatusProfile($uri)
{
    $oprofile = null;
    if (Validate::email($uri)) {
        $oprofile = LooseOstatusProfile::updateWebfinger($uri);
    } else {
        if (Validate::uri($uri)) {
            $oprofile = LooseOstatusProfile::updateProfileURL($uri);
        } else {
            print "Sorry, we could not reach the address: {$uri}\n";
            return false;
        }
    }
    return $oprofile;
}
 function verifyCallback($callback)
 {
     if ($callback == "oob") {
         common_debug("OAuth request token requested for out of band client.");
         // XXX: Should we throw an error if a client is registered as a
         // web application but requests the pin based workflow? For now I'm
         // allowing the workflow to proceed and issuing a pin. --Zach
         return true;
     } else {
         return Validate::uri($callback);
     }
 }
Example #17
0
function common_valid_http_url($url)
{
    return Validate::uri($url, array('allowed_schemes' => array('http', 'https')));
}
 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 {
                         // TRANS: Exception in OStatus when invalid URI was entered.
                         throw new Exception(_m('Invalid URI.'));
                     }
                 }
                 return $this->filter(array($oprofile->localProfile()));
             } catch (Exception $e) {
                 // TRANS: Error message in OStatus plugin. Do not translate the domain names example.com
                 // TRANS: and example.net, as these are official standard domain names for use in examples.
                 $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;
 }
 function validate(&$values)
 {
     // Validate snapshot run value
     if (!in_array($values['snapshot']['run'], array('web', 'cron', 'never'))) {
         // TRANS: Client error displayed on admin panel for snapshots when providing an invalid run value.
         $this->clientError(_('Invalid snapshot run value.'));
     }
     // Validate snapshot frequency value
     if (!Validate::number($values['snapshot']['frequency'])) {
         // TRANS: Client error displayed on admin panel for snapshots when providing an invalid value for frequency.
         $this->clientError(_('Snapshot frequency must be a number.'));
     }
     // Validate report URL
     if (!is_null($values['snapshot']['reporturl']) && !Validate::uri($values['snapshot']['reporturl'], array('allowed_schemes' => array('http', 'https')))) {
         // TRANS: Client error displayed on admin panel for snapshots when providing an invalid report URL.
         $this->clientError(_('Invalid snapshot report URL.'));
     }
 }
Example #20
0
 /**
  * Is this a valid URI for remote profile/notice identification?
  * Does not have to be a resolvable URL.
  * @param string $uri
  * @return boolean
  */
 static function validateUri($uri)
 {
     // Check mailto: URIs first
     if (preg_match('/^mailto:(.*)$/', $uri, $match)) {
         return Validate::email($match[1], common_config('email', 'check_domain'));
     }
     if (Validate::uri($uri)) {
         return true;
     }
     // Possibly an upstream bug; tag: URIs aren't validated properly
     // unless you explicitly ask for them. All other schemes are accepted
     // for basic URI validation without asking.
     if (Validate::uri($uri, array('allowed_scheme' => array('tag')))) {
         return true;
     }
     return false;
 }
Example #21
0
 /**
  * Pull data for a remote profile and check if it's valid.
  * Fills out error UI string in $this->error
  * Fills out $this->oprofile on success.
  *
  * @return boolean
  */
 function pullRemoteProfile()
 {
     $this->profile_uri = $this->trimmed('profile');
     try {
         if (Validate::email($this->profile_uri)) {
             $this->oprofile = Ostatus_profile::ensureWebfinger($this->profile_uri);
         } else {
             if (Validate::uri($this->profile_uri)) {
                 $this->oprofile = Ostatus_profile::ensureProfileURL($this->profile_uri);
             } else {
                 // TRANS: Error message in OStatus plugin. Do not translate the domain names example.com
                 // TRANS: and example.net, as these are official standard domain names for use in examples.
                 $this->error = _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.");
                 common_debug('Invalid address format.', __FILE__);
                 return false;
             }
         }
         return true;
     } catch (FeedSubBadURLException $e) {
         // TRANS: Error message in OStatus plugin. Do not translate the domain names example.com
         // TRANS: and example.net, as these are official standard domain names for use in examples.
         $this->error = _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.');
         common_debug('Invalid URL or could not reach server.', __FILE__);
     } catch (FeedSubBadResponseException $e) {
         // TRANS: Error text.
         $this->error = _m('Sorry, we could not reach that feed. Please try that OStatus address again later.');
         common_debug('Cannot read feed; server returned error.', __FILE__);
     } catch (FeedSubEmptyException $e) {
         // TRANS: Error text.
         $this->error = _m('Sorry, we could not reach that feed. Please try that OStatus address again later.');
         common_debug('Cannot read feed; server returned an empty page.', __FILE__);
     } catch (FeedSubBadHTMLException $e) {
         // TRANS: Error text.
         $this->error = _m('Sorry, we could not reach that feed. Please try that OStatus address again later.');
         common_debug('Bad HTML, could not find feed link.', __FILE__);
     } catch (FeedSubNoFeedException $e) {
         // TRANS: Error text.
         $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
         common_debug('Could not find a feed linked from this URL.', __FILE__);
     } catch (FeedSubUnrecognizedTypeException $e) {
         // TRANS: Error text.
         $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
         common_debug('Not a recognized feed type.', __FILE__);
     } catch (Exception $e) {
         // Any new ones we forgot about
         // TRANS: Error message in OStatus plugin. Do not translate the domain names example.com
         // TRANS: and example.net, as these are official standard domain names for use in examples.
         $this->error = _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.");
         common_debug(sprintf('Bad feed URL: %s %s', get_class($e), $e->getMessage()), __FILE__);
     }
     return false;
 }
Example #22
0
 /**
  * Try to register a user
  *
  * Validates the input and tries to save a new user and profile
  * record. On success, shows an instructions page.
  *
  * @return void
  */
 function tryRegister()
 {
     if (Event::handle('StartRegistrationTry', array($this))) {
         $token = $this->trimmed('token');
         if (!$token || $token != common_session_token()) {
             $this->showForm(_('There was a problem with your session token. ' . 'Try again, please.'));
             return;
         }
         $nickname = $this->trimmed('nickname');
         $email = $this->trimmed('email');
         $fullname = $this->trimmed('fullname');
         $homepage = $this->trimmed('homepage');
         $bio = $this->trimmed('bio');
         $location = $this->trimmed('location');
         // We don't trim these... whitespace is OK in a password!
         $password = $this->arg('password');
         $confirm = $this->arg('confirm');
         // invitation code, if any
         $code = $this->trimmed('code');
         if ($code) {
             $invite = Invitation::staticGet($code);
         }
         if (common_config('site', 'inviteonly') && !($code && $invite)) {
             $this->clientError(_('Sorry, only invited people can register.'));
             return;
         }
         // Input scrubbing
         try {
             $nickname = Nickname::normalize($nickname);
         } catch (NicknameException $e) {
             $this->showForm($e->getMessage());
         }
         $email = common_canonical_email($email);
         if (!$this->boolean('license')) {
             $this->showForm(_('You cannot register if you don\'t ' . 'agree to the license.'));
         } else {
             if ($email && !Validate::email($email, common_config('email', 'check_domain'))) {
                 $this->showForm(_('Not a valid email address.'));
             } else {
                 if ($this->nicknameExists($nickname)) {
                     $this->showForm(_('Nickname already in use. Try another one.'));
                 } else {
                     if (!User::allowed_nickname($nickname)) {
                         $this->showForm(_('Not a valid nickname.'));
                     } else {
                         if ($this->emailExists($email)) {
                             $this->showForm(_('Email address already exists.'));
                         } else {
                             if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
                                 $this->showForm(_('Homepage is not a valid URL.'));
                                 return;
                             } else {
                                 if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                                     $this->showForm(_('Full name is too long (maximum 255 characters).'));
                                     return;
                                 } else {
                                     if (Profile::bioTooLong($bio)) {
                                         $this->showForm(sprintf(_m('Bio is too long (maximum %d character).', 'Bio is too long (maximum %d characters).', Profile::maxBio()), Profile::maxBio()));
                                         return;
                                     } else {
                                         if (!is_null($location) && mb_strlen($location) > 255) {
                                             $this->showForm(_('Location is too long (maximum 255 characters).'));
                                             return;
                                         } else {
                                             if (strlen($password) < 6) {
                                                 $this->showForm(_('Password must be 6 or more characters.'));
                                                 return;
                                             } else {
                                                 if ($password != $confirm) {
                                                     $this->showForm(_('Passwords don\'t match.'));
                                                 } else {
                                                     if ($user = User::register(array('nickname' => $nickname, 'password' => $password, 'email' => $email, 'fullname' => $fullname, 'homepage' => $homepage, 'bio' => $bio, 'location' => $location, 'code' => $code))) {
                                                         if (!$user) {
                                                             $this->showForm(_('Invalid username or password.'));
                                                             return;
                                                         }
                                                         // success!
                                                         if (!common_set_user($user)) {
                                                             $this->serverError(_('Error setting user.'));
                                                             return;
                                                         }
                                                         // this is a real login
                                                         common_real_login(true);
                                                         if ($this->boolean('rememberme')) {
                                                             common_debug('Adding rememberme cookie for ' . $nickname);
                                                             common_rememberme($user);
                                                         }
                                                         Event::handle('EndRegistrationTry', array($this));
                                                         // Re-init language env in case it changed (not yet, but soon)
                                                         common_init_language();
                                                         $this->showSuccess();
                                                     } else {
                                                         $this->showForm(_('Invalid username or password.'));
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Handle a post
  *
  * Validate input and save changes. Reload the form with a success
  * or error message.
  *
  * @return void
  */
 function handlePost()
 {
     // CSRF protection
     $token = $this->trimmed('token');
     if (!$token || $token != common_session_token()) {
         $this->showForm(_('There was a problem with your session token. ' . 'Try again, please.'));
         return;
     }
     if (Event::handle('StartProfileSaveForm', array($this))) {
         $nickname = $this->trimmed('nickname');
         $fullname = $this->trimmed('fullname');
         $homepage = $this->trimmed('homepage');
         $bio = $this->trimmed('bio');
         $location = $this->trimmed('location');
         $autosubscribe = $this->boolean('autosubscribe');
         $language = $this->trimmed('language');
         $timezone = $this->trimmed('timezone');
         $tagstring = $this->trimmed('tags');
         // Some validation
         if (!Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
             $this->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.'));
             return;
         } else {
             if (!User::allowed_nickname($nickname)) {
                 $this->showForm(_('Not a valid nickname.'));
                 return;
             } else {
                 if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
                     $this->showForm(_('Homepage is not a valid URL.'));
                     return;
                 } else {
                     if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                         $this->showForm(_('Full name is too long (max 255 chars).'));
                         return;
                     } else {
                         if (Profile::bioTooLong($bio)) {
                             $this->showForm(sprintf(_('Bio is too long (max %d chars).'), Profile::maxBio()));
                             return;
                         } else {
                             if (!is_null($location) && mb_strlen($location) > 255) {
                                 $this->showForm(_('Location is too long (max 255 chars).'));
                                 return;
                             } else {
                                 if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
                                     $this->showForm(_('Timezone not selected.'));
                                     return;
                                 } else {
                                     if ($this->nicknameExists($nickname)) {
                                         $this->showForm(_('Nickname already in use. Try another one.'));
                                         return;
                                     } else {
                                         if (!is_null($language) && strlen($language) > 50) {
                                             $this->showForm(_('Language is too long (max 50 chars).'));
                                             return;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($tagstring) {
             $tags = array_map('common_canonical_tag', preg_split('/[\\s,]+/', $tagstring));
         } else {
             $tags = array();
         }
         foreach ($tags as $tag) {
             if (!common_valid_profile_tag($tag)) {
                 $this->showForm(sprintf(_('Invalid tag: "%s"'), $tag));
                 return;
             }
         }
         $user = common_current_user();
         $user->query('BEGIN');
         if ($user->nickname != $nickname || $user->language != $language || $user->timezone != $timezone) {
             common_debug('Updating user nickname from ' . $user->nickname . ' to ' . $nickname, __FILE__);
             common_debug('Updating user language from ' . $user->language . ' to ' . $language, __FILE__);
             common_debug('Updating user timezone from ' . $user->timezone . ' to ' . $timezone, __FILE__);
             $original = clone $user;
             $user->nickname = $nickname;
             $user->language = $language;
             $user->timezone = $timezone;
             $result = $user->updateKeys($original);
             if ($result === false) {
                 common_log_db_error($user, 'UPDATE', __FILE__);
                 $this->serverError(_('Couldn\'t update user.'));
                 return;
             } else {
                 // Re-initialize language environment if it changed
                 common_init_language();
                 // Clear the site owner, in case nickname changed
                 if ($user->hasRole(Profile_role::OWNER)) {
                     User::blow('user:site_owner');
                 }
             }
         }
         // XXX: XOR
         if ($user->autosubscribe ^ $autosubscribe) {
             $original = clone $user;
             $user->autosubscribe = $autosubscribe;
             $result = $user->update($original);
             if ($result === false) {
                 common_log_db_error($user, 'UPDATE', __FILE__);
                 $this->serverError(_('Couldn\'t update user for autosubscribe.'));
                 return;
             }
         }
         $profile = $user->getProfile();
         $orig_profile = clone $profile;
         $profile->nickname = $user->nickname;
         $profile->fullname = $fullname;
         $profile->homepage = $homepage;
         $profile->bio = $bio;
         $profile->location = $location;
         $loc = Location::fromName($location);
         if (empty($loc)) {
             $profile->lat = null;
             $profile->lon = null;
             $profile->location_id = null;
             $profile->location_ns = null;
         } else {
             $profile->lat = $loc->lat;
             $profile->lon = $loc->lon;
             $profile->location_id = $loc->location_id;
             $profile->location_ns = $loc->location_ns;
         }
         $profile->profileurl = common_profile_url($nickname);
         if (common_config('location', 'share') == 'user') {
             $exists = false;
             $prefs = User_location_prefs::staticGet('user_id', $user->id);
             if (empty($prefs)) {
                 $prefs = new User_location_prefs();
                 $prefs->user_id = $user->id;
                 $prefs->created = common_sql_now();
             } else {
                 $exists = true;
                 $orig = clone $prefs;
             }
             $prefs->share_location = $this->boolean('sharelocation');
             if ($exists) {
                 $result = $prefs->update($orig);
             } else {
                 $result = $prefs->insert();
             }
             if ($result === false) {
                 common_log_db_error($prefs, $exists ? 'UPDATE' : 'INSERT', __FILE__);
                 $this->serverError(_('Couldn\'t save location prefs.'));
                 return;
             }
         }
         common_debug('Old profile: ' . common_log_objstring($orig_profile), __FILE__);
         common_debug('New profile: ' . common_log_objstring($profile), __FILE__);
         $result = $profile->update($orig_profile);
         if ($result === false) {
             common_log_db_error($profile, 'UPDATE', __FILE__);
             $this->serverError(_('Couldn\'t save profile.'));
             return;
         }
         // Set the user tags
         $result = $user->setSelfTags($tags);
         if (!$result) {
             $this->serverError(_('Couldn\'t save tags.'));
             return;
         }
         $user->query('COMMIT');
         Event::handle('EndProfileSaveForm', array($this));
         common_broadcast_profile($profile);
         $this->showForm(_('Settings saved.'), true);
     }
 }
 /**
  * Validate License admin form values
  *
  * @param array &$values from the form
  *
  * @return nothing
  */
 function validate(&$values)
 {
     // Validate license type (shouldn't have to do it, but just in case)
     $types = array('private', 'allrightsreserved', 'cc');
     if (!in_array($values['license']['type'], $types)) {
         $this->clientError(_("Invalid license selection."));
     }
     // Make sure the user has set an owner if the site has a private
     // license
     if ($values['license']['type'] == 'allrightsreserved' && empty($values['license']['owner'])) {
         $this->clientError(_("You must specify the owner of the content when using the All Rights Reserved license."));
     }
     // Make sure the license title is not too long
     if (mb_strlen($values['license']['type']) > 255) {
         $this->clientError(_('Invalid license title. Maximum length is 255 characters.'));
     }
     // make sure the license URL and license image URL are valid URLs
     $options = array('allowed_schemes' => array('http', 'https'));
     // URLs should be set for cc license
     if ($values['license']['type'] == 'cc') {
         if (!Validate::uri($values['license']['url'], $options)) {
             $this->clientError(_("Invalid license URL."));
         }
         if (!Validate::uri($values['license']['image'], $options)) {
             $this->clientError(_("Invalid license image URL."));
         }
     }
     // can be either blank or a valid URL for private & allrightsreserved
     if (!empty($values['license']['url'])) {
         if (!Validate::uri($values['license']['url'], $options)) {
             $this->clientError(_("License URL must be blank or a valid URL."));
         }
     }
     // can be either blank or a valid URL for private & allrightsreserved
     if (!empty($values['license']['image'])) {
         if (!Validate::uri($values['license']['image'], $options)) {
             $this->clientError(_("License image must be blank or valid URL."));
         }
     }
 }
Example #25
0
 /**
  * Grab and validate a URL from POST parameters.
  * @throws ClientException for malformed or non-http/https URLs
  */
 protected function argUrl($arg)
 {
     $url = $this->arg($arg);
     $params = array('domain_check' => false, 'allowed_schemes' => array('http', 'https'));
     $validate = new Validate();
     if ($validate->uri($url, $params)) {
         return $url;
     } else {
         // TRANS: Client exception.
         // TRANS: %1$s is this argument to the method this exception occurs in, %2$s is a URL.
         throw new ClientException(sprintf(_m('Invalid URL passed for %1$s: "%2$s"'), $arg, $url));
     }
 }
Example #26
0
 public static function updateProfile($profile, $object, $hints = array())
 {
     $orig = clone $profile;
     // Existing nickname is better than nothing.
     if (!array_key_exists('nickname', $hints)) {
         $hints['nickname'] = $profile->nickname;
     }
     $nickname = self::getActivityObjectNickname($object, $hints);
     if (!empty($nickname)) {
         $profile->nickname = $nickname;
     }
     if (!empty($object->title)) {
         $profile->fullname = $object->title;
     } else {
         if (array_key_exists('fullname', $hints)) {
             $profile->fullname = $hints['fullname'];
         }
     }
     if (!empty($object->link)) {
         $profile->profileurl = $object->link;
     } else {
         if (array_key_exists('profileurl', $hints)) {
             $profile->profileurl = $hints['profileurl'];
         } else {
             if (Validate::uri($object->id, array('allowed_schemes' => array('http', 'https')))) {
                 $profile->profileurl = $object->id;
             }
         }
     }
     $bio = self::getActivityObjectBio($object, $hints);
     if (!empty($bio)) {
         $profile->bio = $bio;
     }
     $location = self::getActivityObjectLocation($object, $hints);
     if (!empty($location)) {
         $profile->location = $location;
     }
     $homepage = self::getActivityObjectHomepage($object, $hints);
     if (!empty($homepage)) {
         $profile->homepage = $homepage;
     }
     if (!empty($object->geopoint)) {
         $location = ActivityContext::locationFromPoint($object->geopoint);
         if (!empty($location)) {
             $profile->lat = $location->lat;
             $profile->lon = $location->lon;
         }
     }
     // @todo FIXME: tags/categories
     // @todo tags from categories
     if ($profile->id) {
         common_log(LOG_DEBUG, "Updating OStatus profile {$profile->id} from remote info {$object->id}: " . var_export($object, true) . var_export($hints, true));
         $profile->update($orig);
     }
 }
Example #27
0
 function trySave()
 {
     $cur = common_current_user();
     if (!$cur->isAdmin($this->group)) {
         $this->clientError(_('You must be an admin to edit the group.'), 403);
         return;
     }
     $nickname = common_canonical_nickname($this->trimmed('nickname'));
     $fullname = $this->trimmed('fullname');
     $homepage = $this->trimmed('homepage');
     $description = $this->trimmed('description');
     $location = $this->trimmed('location');
     $aliasstring = $this->trimmed('aliases');
     if (!Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
         $this->showForm(_('Nickname must have only lowercase letters ' . 'and numbers and no spaces.'));
         return;
     } else {
         if ($this->nicknameExists($nickname)) {
             $this->showForm(_('Nickname already in use. Try another one.'));
             return;
         } else {
             if (!User_group::allowedNickname($nickname)) {
                 $this->showForm(_('Not a valid nickname.'));
                 return;
             } else {
                 if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
                     $this->showForm(_('Homepage is not a valid URL.'));
                     return;
                 } else {
                     if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                         $this->showForm(_('Full name is too long (max 255 chars).'));
                         return;
                     } else {
                         if (User_group::descriptionTooLong($description)) {
                             $this->showForm(sprintf(_('description is too long (max %d chars).'), User_group::maxDescription()));
                             return;
                         } else {
                             if (!is_null($location) && mb_strlen($location) > 255) {
                                 $this->showForm(_('Location is too long (max 255 chars).'));
                                 return;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!empty($aliasstring)) {
         $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\\s,]+/', $aliasstring)));
     } else {
         $aliases = array();
     }
     if (count($aliases) > common_config('group', 'maxaliases')) {
         $this->showForm(sprintf(_('Too many aliases! Maximum %d.'), common_config('group', 'maxaliases')));
         return;
     }
     foreach ($aliases as $alias) {
         if (!Validate::string($alias, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
             $this->showForm(sprintf(_('Invalid alias: "%s"'), $alias));
             return;
         }
         if ($this->nicknameExists($alias)) {
             $this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'), $alias));
             return;
         }
         // XXX assumes alphanum nicknames
         if (strcmp($alias, $nickname) == 0) {
             $this->showForm(_('Alias can\'t be the same as nickname.'));
             return;
         }
     }
     $this->group->query('BEGIN');
     $orig = clone $this->group;
     $this->group->nickname = $nickname;
     $this->group->fullname = $fullname;
     $this->group->homepage = $homepage;
     $this->group->description = $description;
     $this->group->location = $location;
     $this->group->mainpage = common_local_url('showgroup', array('nickname' => $nickname));
     $result = $this->group->update($orig);
     if (!$result) {
         common_log_db_error($this->group, 'UPDATE', __FILE__);
         $this->serverError(_('Could not update group.'));
     }
     $result = $this->group->setAliases($aliases);
     if (!$result) {
         $this->serverError(_('Could not create aliases.'));
     }
     if ($nickname != $orig->nickname) {
         common_log(LOG_INFO, "Saving local group info.");
         $local = Local_group::staticGet('group_id', $this->group->id);
         $local->setNickname($nickname);
     }
     $this->group->query('COMMIT');
     if ($this->group->nickname != $orig->nickname) {
         common_redirect(common_local_url('editgroup', array('nickname' => $nickname)), 303);
     } else {
         $this->showForm(_('Options saved.'));
     }
 }
Example #28
0
 /**
  * Validate params for the new group
  *
  * @return void
  */
 function validateParams()
 {
     $valid = Validate::string($this->nickname, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT));
     if (!$valid) {
         $this->clientError(_('Nickname must have only lowercase letters ' . 'and numbers and no spaces.'), 403, $this->format);
         return false;
     } elseif ($this->groupNicknameExists($this->nickname)) {
         $this->clientError(_('Nickname already in use. Try another one.'), 403, $this->format);
         return false;
     } else {
         if (!User_group::allowedNickname($this->nickname)) {
             $this->clientError(_('Not a valid nickname.'), 403, $this->format);
             return false;
         } elseif (!is_null($this->homepage) && strlen($this->homepage) > 0 && !Validate::uri($this->homepage, array('allowed_schemes' => array('http', 'https')))) {
             $this->clientError(_('Homepage is not a valid URL.'), 403, $this->format);
             return false;
         } elseif (!is_null($this->fullname) && mb_strlen($this->fullname) > 255) {
             $this->clientError(_('Full name is too long (maximum 255 characters).'), 403, $this->format);
             return false;
         } elseif (User_group::descriptionTooLong($this->description)) {
             $this->clientError(sprintf(_m('Description is too long (maximum %d character).', 'Description is too long (maximum %d characters).', User_group::maxDescription()), User_group::maxDescription()), 403, $this->format);
             return false;
         } elseif (!is_null($this->location) && mb_strlen($this->location) > 255) {
             $this->clientError(_('Location is too long (maximum 255 characters).'), 403, $this->format);
             return false;
         }
     }
     if (!empty($this->aliasstring)) {
         $this->aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\\s,]+/', $this->aliasstring)));
     } else {
         $this->aliases = array();
     }
     if (count($this->aliases) > common_config('group', 'maxaliases')) {
         $this->clientError(sprintf(_m('Too many aliases! Maximum %d allowed.', 'Too many aliases! Maximum %d allowed.', common_config('group', 'maxaliases')), common_config('group', 'maxaliases')), 403, $this->format);
         return false;
     }
     foreach ($this->aliases as $alias) {
         $valid = Validate::string($alias, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT));
         if (!$valid) {
             $this->clientError(sprintf(_('Invalid alias: "%s".'), $alias), 403, $this->format);
             return false;
         }
         if ($this->groupNicknameExists($alias)) {
             $this->clientError(sprintf(_('Alias "%s" already in use. Try another one.'), $alias), 403, $this->format);
             return false;
         }
         // XXX assumes alphanum nicknames
         if (strcmp($alias, $this->nickname) == 0) {
             $this->clientError(_('Alias can\'t be the same as nickname.'), 403, $this->format);
             return false;
         }
     }
     // Everything looks OK
     return true;
 }
Example #29
0
 function ostatusConnect()
 {
     $opts = array('allowed_schemes' => array('http', 'https', 'acct'));
     if (Validate::uri($this->profile, $opts)) {
         $bits = parse_url($this->profile);
         if ($bits['scheme'] == 'acct') {
             $this->connectWebfinger($bits['path']);
         } else {
             $this->connectProfile($this->profile);
         }
     } elseif (strpos($this->profile, '@') !== false) {
         $this->connectWebfinger($this->profile);
     } else {
         // TRANS: Client error.
         $this->clientError(_m('Must provide a remote profile.'));
     }
 }
Example #30
0
 function trySave()
 {
     $name = $this->trimmed('name');
     $description = $this->trimmed('description');
     $source_url = $this->trimmed('source_url');
     $organization = $this->trimmed('organization');
     $homepage = $this->trimmed('homepage');
     $callback_url = $this->trimmed('callback_url');
     $type = $this->arg('app_type');
     $access_type = $this->arg('default_access_type');
     if (empty($name)) {
         // TRANS: Validation error shown when not providing a name in the "Edit application" form.
         $this->showForm(_('Name is required.'));
         return;
     } elseif (mb_strlen($name) > 255) {
         // TRANS: Validation error shown when providing too long a name in the "Edit application" form.
         $this->showForm(_('Name is too long (maximum 255 characters).'));
         return;
     } else {
         if ($this->nameExists($name)) {
             // TRANS: Validation error shown when providing a name for an application that already exists in the "Edit application" form.
             $this->showForm(_('Name already in use. Try another one.'));
             return;
         } elseif (empty($description)) {
             // TRANS: Validation error shown when not providing a description in the "Edit application" form.
             $this->showForm(_('Description is required.'));
             return;
         } elseif (Oauth_application::descriptionTooLong($description)) {
             $this->showForm(sprintf(_m('Description is too long (maximum %d character).', 'Description is too long (maximum %d characters).', Oauth_application::maxDesc()), Oauth_application::maxDesc()));
             return;
         } elseif (mb_strlen($source_url) > 255) {
             // TRANS: Validation error shown when providing too long a source URL in the "Edit application" form.
             $this->showForm(_('Source URL is too long.'));
             return;
         } elseif (mb_strlen($source_url) > 0 && !Validate::uri($source_url, array('allowed_schemes' => array('http', 'https')))) {
             // TRANS: Validation error shown when providing an invalid source URL in the "Edit application" form.
             $this->showForm(_('Source URL is not valid.'));
             return;
         } elseif (empty($organization)) {
             // TRANS: Validation error shown when not providing an organisation in the "Edit application" form.
             $this->showForm(_('Organization is required.'));
             return;
         } elseif (mb_strlen($organization) > 255) {
             // TRANS: Validation error shown when providing too long an arganisation name in the "Edit application" form.
             $this->showForm(_('Organization is too long (maximum 255 characters).'));
             return;
         } elseif (empty($homepage)) {
             // TRANS: Form validation error show when an organisation name has not been provided in the edit application form.
             $this->showForm(_('Organization homepage is required.'));
             return;
         } elseif (mb_strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
             // TRANS: Validation error shown when providing an invalid homepage URL in the "Edit application" form.
             $this->showForm(_('Homepage is not a valid URL.'));
             return;
         } elseif (mb_strlen($callback_url) > 255) {
             // TRANS: Validation error shown when providing too long a callback URL in the "Edit application" form.
             $this->showForm(_('Callback is too long.'));
             return;
         } elseif (mb_strlen($callback_url) > 0 && !Validate::uri($source_url, array('allowed_schemes' => array('http', 'https')))) {
             // TRANS: Validation error shown when providing an invalid callback URL in the "Edit application" form.
             $this->showForm(_('Callback URL is not valid.'));
             return;
         }
     }
     $cur = common_current_user();
     // Checked in prepare() above
     assert(!is_null($cur));
     assert(!is_null($this->app));
     $orig = clone $this->app;
     $this->app->name = $name;
     $this->app->description = $description;
     $this->app->source_url = $source_url;
     $this->app->organization = $organization;
     $this->app->homepage = $homepage;
     $this->app->callback_url = $callback_url;
     $this->app->type = $type;
     common_debug("access_type = {$access_type}");
     if ($access_type == 'r') {
         $this->app->access_type = 1;
     } else {
         $this->app->access_type = 3;
     }
     $result = $this->app->update($orig);
     // Note: 0 means no rows changed, which can happen if the only
     // thing we changed was the icon, since it's not altered until
     // the next step.
     if ($result === false) {
         common_log_db_error($this->app, 'UPDATE', __FILE__);
         // TRANS: Server error occuring when an application could not be updated from the "Edit application" form.
         $this->serverError(_('Could not update application.'));
     }
     $this->app->uploadLogo();
     common_redirect(common_local_url('oauthappssettings'), 303);
 }