Пример #1
0
 static function getGraders($groupid)
 {
     $qry = 'SELECT profile.* ' . 'FROM profile JOIN grades_group ' . 'ON profile.id = grades_group.userid ' . 'WHERE grades_group.groupid = ' . $groupid;
     $graders = new Profile();
     $graders->query($qry);
     return $graders;
 }
Пример #2
0
function updateUserUrls()
{
    printfnq("Updating user URLs...\n");
    // XXX: only update user URLs where out-of-date
    $qry = "SELECT * FROM profile order by id asc";
    $pflQry = new Profile();
    $pflQry->query($qry);
    $members = array();
    while ($pflQry->fetch()) {
        $members[] = clone $pflQry;
    }
    $pflQry->free();
    foreach ($members as $member) {
        $user = $member->getUser();
        printfv("Updating user {$user->nickname}...");
        try {
            $profile = $user->getProfile();
            updateProfileUrl($profile);
            updateAvatarUrls($profile);
            // Broadcast for remote users
            common_broadcast_profile($profile);
        } catch (Exception $e) {
            printv("Error updating URLs: " . $e->getMessage());
        }
        printfv("DONE.");
    }
}
Пример #3
0
 static function getTagged($tagger, $tag)
 {
     $profile = new Profile();
     $profile->query('SELECT profile.* ' . 'FROM profile JOIN profile_tag ' . 'ON profile.id = profile_tag.tagged ' . 'WHERE profile_tag.tagger = ' . $tagger . ' ' . 'AND profile_tag.tag = "' . $tag . '" ');
     $tagged = array();
     while ($profile->fetch()) {
         $tagged[] = clone $profile;
     }
     return $tagged;
 }
Пример #4
0
 function getMembers($offset = 0, $limit = null)
 {
     $qry = 'SELECT profile.* ' . 'FROM profile JOIN group_member ' . 'ON profile.id = group_member.profile_id ' . 'WHERE group_member.group_id = %d ' . 'ORDER BY group_member.created DESC ';
     if ($limit != null) {
         if (common_config('db', 'type') == 'pgsql') {
             $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
         } else {
             $qry .= ' LIMIT ' . $offset . ', ' . $limit;
         }
     }
     $members = new Profile();
     $members->query(sprintf($qry, $this->id));
     return $members;
 }
Пример #5
0
/**
 * Check for profiles in the given id range that are missing, presumed deleted.
 *
 * @param int $start beginning profile.id, inclusive
 * @param int $end final profile.id, inclusive
 * @return array of integer profile.ids
 * @access private
 */
function get_missing_profiles($start, $end)
{
    $query = sprintf("SELECT id FROM profile WHERE id BETWEEN %d AND %d", $start, $end);
    $profile = new Profile();
    $profile->query($query);
    $all = range($start, $end);
    $known = array();
    while ($row = $profile->fetch()) {
        $known[] = intval($profile->id);
    }
    unset($profile);
    $missing = array_diff($all, $known);
    return $missing;
}
Пример #6
0
 /**
  * Search for users matching the query and spit the results out
  * as a quick-n-dirty JSON document
  *
  * @return void
  */
 function showResults()
 {
     $people = array();
     $profile = new Profile();
     $search_engine = $profile->getSearchEngine('profile');
     $search_engine->set_sort_mode('nickname_desc');
     $search_engine->limit(0, 10);
     $search_engine->query(strtolower($this->query . '*'));
     $cnt = $profile->find();
     if ($cnt > 0) {
         $sql = 'SELECT profile.* FROM profile, user WHERE profile.id = user.id ' . ' AND LEFT(LOWER(profile.nickname), ' . strlen($this->query) . ') = \'%s\' ' . ' LIMIT 0, 10';
         $profile->query(sprintf($sql, $this->query));
     }
     while ($profile->fetch()) {
         $people[] = $profile->nickname;
     }
     header('Content-Type: application/json; charset=utf-8');
     print json_encode($people);
 }
Пример #7
0
 function getTaggedSubscriptions($tag, $offset = 0, $limit = null)
 {
     $qry = 'SELECT profile.* ' . 'FROM profile JOIN subscription ' . 'ON profile.id = subscription.subscribed ' . 'JOIN profile_tag on (profile_tag.tagged = subscription.subscribed ' . 'AND profile_tag.tagger = subscription.subscriber) ' . 'WHERE subscription.subscriber = %d ' . "AND profile_tag.tag = '%s' " . 'AND subscription.subscribed != subscription.subscriber ' . 'ORDER BY subscription.created DESC ';
     $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     $profile = new Profile();
     $profile->query(sprintf($qry, $this->id, $tag));
     return $profile;
 }
Пример #8
0
 /**
  * Whips up a query to get a list of profiles based on the provided
  * people tag and page, initalizes a ProfileList widget, and displays
  * it to the user.
  *
  * @return nothing
  */
 function showContent()
 {
     $profile = new Profile();
     $offset = ($this->page - 1) * PROFILES_PER_PAGE;
     $limit = PROFILES_PER_PAGE + 1;
     if (common_config('db', 'type') == 'pgsql') {
         $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $lim = ' LIMIT ' . $offset . ', ' . $limit;
     }
     // XXX: memcached this
     $qry = 'SELECT profile.* ' . 'FROM profile JOIN profile_tag ' . 'ON profile.id = profile_tag.tagger ' . 'WHERE profile_tag.tagger = profile_tag.tagged ' . "AND tag = '%s' " . 'ORDER BY profile_tag.modified DESC%s';
     $profile->query(sprintf($qry, $this->tag, $lim));
     $ptl = new PeopleTagList($profile, $this);
     // pass the ammunition
     $cnt = $ptl->show();
     $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE, $this->page, 'peopletag', array('tag' => $this->tag));
 }
Пример #9
0
 function getBlocked($offset = 0, $limit = null)
 {
     $qry = 'SELECT profile.* ' . 'FROM profile JOIN group_block ' . 'ON profile.id = group_block.blocked ' . 'WHERE group_block.group_id = %d ' . 'ORDER BY group_block.modified DESC ';
     if ($limit != null) {
         if (common_config('db', 'type') == 'pgsql') {
             $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
         } else {
             $qry .= ' LIMIT ' . $offset . ', ' . $limit;
         }
     }
     $blocked = new Profile();
     $blocked->query(sprintf($qry, $this->id));
     return $blocked;
 }
Пример #10
0
 */
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
$shortoptions = 'y';
$longoptions = array('yes');
$helptext = <<<END_OF_HELP
clean_profiles.php [options]
Deletes all profile table entries where the profile does not occur in the
notice table, is not a group and is not a local user. Very MySQL specific I think.

WARNING: This has not been tested thoroughly. Maybe we've missed a table to compare somewhere.

  -y --yes      do not wait for confirmation

END_OF_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
if (!have_option('y', 'yes')) {
    print "About to delete profiles that we think are useless to save. Are you sure? [y/N] ";
    $response = fgets(STDIN);
    if (strtolower(trim($response)) != 'y') {
        print "Aborting.\n";
        exit(0);
    }
}
print "Deleting";
$profile = new Profile();
$profile->query('SELECT * FROM profile WHERE ' . 'NOT (SELECT COUNT(*) FROM notice WHERE profile_id=profile.id) ' . 'AND NOT (SELECT COUNT(*) FROM user WHERE user.id=profile.id) ' . 'AND NOT (SELECT COUNT(*) FROM user_group WHERE user_group.profile_id=profile.id) ' . 'AND NOT (SELECT COUNT(*) FROM subscription WHERE subscriber=profile.id OR subscribed=profile.id) ');
while ($profile->fetch()) {
    echo ' ' . $profile->getID() . ':' . $profile->getNickname();
    $profile->delete();
}
print "\nDONE.\n";
Пример #11
0
 /**
  * Register a new user account and profile and set up default subscriptions.
  * If a new-user welcome message is configured, this will be sent.
  *
  * @param array $fields associative array of optional properties
  *              string 'bio'
  *              string 'email'
  *              bool 'email_confirmed' pass true to mark email as pre-confirmed
  *              string 'fullname'
  *              string 'homepage'
  *              string 'location' informal string description of geolocation
  *              float 'lat' decimal latitude for geolocation
  *              float 'lon' decimal longitude for geolocation
  *              int 'location_id' geoname identifier
  *              int 'location_ns' geoname namespace to interpret location_id
  *              string 'nickname' REQUIRED
  *              string 'password' (may be missing for eg OpenID registrations)
  *              string 'code' invite code
  *              ?string 'uri' permalink to notice; defaults to local notice URL
  * @return  User object
  * @throws  Exception on failure
  */
 static function register(array $fields)
 {
     // MAGICALLY put fields into current scope
     extract($fields);
     $profile = new Profile();
     if (!empty($email)) {
         $email = common_canonical_email($email);
     }
     // Normalize _and_ check whether it is in use. Throw NicknameException on failure.
     $profile->nickname = Nickname::normalize($nickname, true);
     $profile->profileurl = common_profile_url($profile->nickname);
     if (!empty($fullname)) {
         $profile->fullname = $fullname;
     }
     if (!empty($homepage)) {
         $profile->homepage = $homepage;
     }
     if (!empty($bio)) {
         $profile->bio = $bio;
     }
     if (!empty($location)) {
         $profile->location = $location;
         $loc = Location::fromName($location);
         if (!empty($loc)) {
             $profile->lat = $loc->lat;
             $profile->lon = $loc->lon;
             $profile->location_id = $loc->location_id;
             $profile->location_ns = $loc->location_ns;
         }
     }
     $profile->created = common_sql_now();
     $user = new User();
     $user->nickname = $profile->nickname;
     $invite = null;
     // Users who respond to invite email have proven their ownership of that address
     if (!empty($code)) {
         $invite = Invitation::getKV($code);
         if ($invite instanceof Invitation && $invite->address && $invite->address_type == 'email' && $invite->address == $email) {
             $user->email = $invite->address;
         }
     }
     if (isset($email_confirmed) && $email_confirmed) {
         $user->email = $email;
     }
     // Set default-on options here, otherwise they'll be disabled
     // initially for sites using caching, since the initial encache
     // doesn't know about the defaults in the database.
     $user->emailnotifysub = 1;
     $user->emailnotifynudge = 1;
     $user->emailnotifymsg = 1;
     $user->emailnotifyattn = 1;
     $user->emailmicroid = 1;
     $user->emailpost = 1;
     $user->jabbermicroid = 1;
     $user->created = common_sql_now();
     if (Event::handle('StartUserRegister', array($profile))) {
         $profile->query('BEGIN');
         $id = $profile->insert();
         if ($id === false) {
             common_log_db_error($profile, 'INSERT', __FILE__);
             $profile->query('ROLLBACK');
             // TRANS: Profile data could not be inserted for some reason.
             throw new ServerException(_m('Could not insert profile data for new user.'));
         }
         $user->id = $id;
         if (!empty($uri)) {
             $user->uri = $uri;
         } else {
             $user->uri = common_user_uri($user);
         }
         if (!empty($password)) {
             // may not have a password for OpenID users
             $user->password = common_munge_password($password, $id);
         }
         $result = $user->insert();
         if ($result === false) {
             common_log_db_error($user, 'INSERT', __FILE__);
             $profile->query('ROLLBACK');
             // TRANS: User data could not be inserted for some reason.
             throw new ServerException(_m('Could not insert user data for new user.'));
         }
         // Everyone is subscribed to themself
         $subscription = new Subscription();
         $subscription->subscriber = $user->id;
         $subscription->subscribed = $user->id;
         $subscription->created = $user->created;
         $result = $subscription->insert();
         if (!$result) {
             common_log_db_error($subscription, 'INSERT', __FILE__);
             $profile->query('ROLLBACK');
             // TRANS: Subscription data could not be inserted for some reason.
             throw new ServerException(_m('Could not insert subscription data for new user.'));
         }
         // Mark that this invite was converted
         if (!empty($invite)) {
             $invite->convert($user);
         }
         if (!empty($email) && !$user->email) {
             $confirm = new Confirm_address();
             $confirm->code = common_confirmation_code(128);
             $confirm->user_id = $user->id;
             $confirm->address = $email;
             $confirm->address_type = 'email';
             $result = $confirm->insert();
             if (!$result) {
                 common_log_db_error($confirm, 'INSERT', __FILE__);
                 $profile->query('ROLLBACK');
                 // TRANS: Email confirmation data could not be inserted for some reason.
                 throw new ServerException(_m('Could not insert email confirmation data for new user.'));
             }
         }
         if (!empty($code) && $user->email) {
             $user->emailChanged();
         }
         // Default system subscription
         $defnick = common_config('newuser', 'default');
         if (!empty($defnick)) {
             $defuser = User::getKV('nickname', $defnick);
             if (empty($defuser)) {
                 common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick), __FILE__);
             } else {
                 Subscription::ensureStart($profile, $defuser->getProfile());
             }
         }
         $profile->query('COMMIT');
         if (!empty($email) && !$user->email) {
             mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
         }
         // Welcome message
         $welcome = common_config('newuser', 'welcome');
         if (!empty($welcome)) {
             $welcomeuser = User::getKV('nickname', $welcome);
             if (empty($welcomeuser)) {
                 common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick), __FILE__);
             } else {
                 $notice = Notice::saveNew($welcomeuser->id, sprintf(_('Welcome to %1$s, @%2$s!'), common_config('site', 'name'), $user->nickname), 'system');
             }
         }
         Event::handle('EndUserRegister', array($profile));
     }
     if (!$user instanceof User) {
         throw new ServerException('User could not be registered. Probably an event hook that failed.');
     }
     return $user;
 }
Пример #12
0
 function getSubscribers($offset = 0, $limit = null)
 {
     $qry = 'SELECT profile.* ' . 'FROM profile JOIN subscription ' . 'ON profile.id = subscription.subscriber ' . 'WHERE subscription.subscribed = %d ' . 'AND subscription.subscribed != subscription.subscriber ' . 'ORDER BY subscription.created DESC ';
     if ($offset > 0 && !is_null($limit)) {
         if ($offset) {
             if (common_config('db', 'type') == 'pgsql') {
                 $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
             } else {
                 $qry .= ' LIMIT ' . $offset . ', ' . $limit;
             }
         }
     }
     $profile = new Profile();
     $cnt = $profile->query(sprintf($qry, $this->id));
     return $profile;
 }
Пример #13
0
function initGroupProfileId()
{
    printfnq("Ensuring all User_group entries have a Profile and profile_id...");
    $group = new User_group();
    $group->whereAdd('NOT EXISTS (SELECT id FROM profile WHERE id = user_group.profile_id)');
    $group->find();
    while ($group->fetch()) {
        try {
            // We must create a new, incrementally assigned profile_id
            $profile = new Profile();
            $profile->nickname = $group->nickname;
            $profile->fullname = $group->fullname;
            $profile->profileurl = $group->mainpage;
            $profile->homepage = $group->homepage;
            $profile->bio = $group->description;
            $profile->location = $group->location;
            $profile->created = $group->created;
            $profile->modified = $group->modified;
            $profile->query('BEGIN');
            $id = $profile->insert();
            if (empty($id)) {
                $profile->query('ROLLBACK');
                throw new Exception('Profile insertion failed, profileurl: ' . $profile->profileurl);
            }
            $group->query("UPDATE user_group SET profile_id={$id} WHERE id={$group->id}");
            $profile->query('COMMIT');
            $profile->free();
        } catch (Exception $e) {
            printfv("Error initializing Profile for group {$group->nickname}:" . $e->getMessage());
        }
    }
    printfnq("DONE.\n");
}
Пример #14
0
 static function register($fields)
 {
     if (!empty($fields['userid'])) {
         $profile = Profile::getKV('id', $fields['userid']);
         if ($profile && !$profile->hasRight(Right::CREATEGROUP)) {
             common_log(LOG_WARNING, "Attempted group creation from banned user: " . $profile->nickname);
             // TRANS: Client exception thrown when a user tries to create a group while banned.
             throw new ClientException(_('You are not allowed to create groups on this site.'), 403);
         }
     }
     $fields['nickname'] = Nickname::normalize($fields['nickname']);
     // MAGICALLY put fields into current scope
     // @fixme kill extract(); it makes debugging absurdly hard
     $defaults = array('nickname' => null, 'fullname' => null, 'homepage' => null, 'description' => null, 'location' => null, 'uri' => null, 'mainpage' => null, 'aliases' => array(), 'userid' => null);
     $fields = array_merge($defaults, $fields);
     extract($fields);
     $group = new User_group();
     if (empty($uri)) {
         // fill in later...
         $uri = null;
     }
     if (empty($mainpage)) {
         $mainpage = common_local_url('showgroup', array('nickname' => $nickname));
     }
     // We must create a new, incrementally assigned profile_id
     $profile = new Profile();
     $profile->nickname = $nickname;
     $profile->fullname = $fullname;
     $profile->profileurl = $mainpage;
     $profile->homepage = $homepage;
     $profile->bio = $description;
     $profile->location = $location;
     $profile->created = common_sql_now();
     $group->nickname = $profile->nickname;
     $group->fullname = $profile->fullname;
     $group->homepage = $profile->homepage;
     $group->description = $profile->bio;
     $group->location = $profile->location;
     $group->mainpage = $profile->profileurl;
     $group->created = $profile->created;
     $profile->query('BEGIN');
     $id = $profile->insert();
     if ($id === false) {
         $profile->query('ROLLBACK');
         throw new ServerException(_('Profile insertion failed'));
     }
     $group->profile_id = $id;
     $group->uri = $uri;
     if (isset($fields['join_policy'])) {
         $group->join_policy = intval($fields['join_policy']);
     } else {
         $group->join_policy = 0;
     }
     if (isset($fields['force_scope'])) {
         $group->force_scope = intval($fields['force_scope']);
     } else {
         $group->force_scope = 0;
     }
     if (Event::handle('StartGroupSave', array(&$group))) {
         $result = $group->insert();
         if ($result === false) {
             common_log_db_error($group, 'INSERT', __FILE__);
             // TRANS: Server exception thrown when creating a group failed.
             throw new ServerException(_('Could not create group.'));
         }
         if (!isset($uri) || empty($uri)) {
             $orig = clone $group;
             $group->uri = common_local_url('groupbyid', array('id' => $group->id));
             $result = $group->update($orig);
             if (!$result) {
                 common_log_db_error($group, 'UPDATE', __FILE__);
                 // TRANS: Server exception thrown when updating a group URI failed.
                 throw new ServerException(_('Could not set group URI.'));
             }
         }
         $result = $group->setAliases($aliases);
         if (!$result) {
             // TRANS: Server exception thrown when creating group aliases failed.
             throw new ServerException(_('Could not create aliases.'));
         }
         $member = new Group_member();
         $member->group_id = $group->id;
         $member->profile_id = $userid;
         $member->is_admin = 1;
         $member->created = $group->created;
         $result = $member->insert();
         if (!$result) {
             common_log_db_error($member, 'INSERT', __FILE__);
             // TRANS: Server exception thrown when setting group membership failed.
             throw new ServerException(_('Could not set group membership.'));
         }
         self::blow('profile:groups:%d', $userid);
         if ($local) {
             $local_group = new Local_group();
             $local_group->group_id = $group->id;
             $local_group->nickname = $nickname;
             $local_group->created = common_sql_now();
             $result = $local_group->insert();
             if (!$result) {
                 common_log_db_error($local_group, 'INSERT', __FILE__);
                 // TRANS: Server exception thrown when saving local group information failed.
                 throw new ServerException(_('Could not save local group info.'));
             }
         }
         Event::handle('EndGroupSave', array($group));
     }
     $profile->query('COMMIT');
     return $group;
 }
Пример #15
0
 function ensureProfile($user)
 {
     // check to see if there's already a profile for this user
     $profileurl = 'http://twitter.com/' . $user->screen_name;
     $profile = Profile::staticGet('profileurl', $profileurl);
     if ($profile) {
         if (defined('SCRIPT_DEBUG')) {
             common_debug("Profile for {$profile->nickname} found.");
         }
         // Check to see if the user's Avatar has changed
         $this->checkAvatar($user, $profile);
         return $profile->id;
     } else {
         if (defined('SCRIPT_DEBUG')) {
             common_debug('Adding profile and remote profile ' . "for Twitter user: {$profileurl}");
         }
         $profile = new Profile();
         $profile->query("BEGIN");
         $profile->nickname = $user->screen_name;
         $profile->fullname = $user->name;
         $profile->homepage = $user->url;
         $profile->bio = $user->description;
         $profile->location = $user->location;
         $profile->profileurl = $profileurl;
         $profile->created = common_sql_now();
         $id = $profile->insert();
         if (empty($id)) {
             common_log_db_error($profile, 'INSERT', __FILE__);
             $profile->query("ROLLBACK");
             return false;
         }
         // check for remote profile
         $remote_pro = Remote_profile::staticGet('uri', $profileurl);
         if (!$remote_pro) {
             $remote_pro = new Remote_profile();
             $remote_pro->id = $id;
             $remote_pro->uri = $profileurl;
             $remote_pro->created = common_sql_now();
             $rid = $remote_pro->insert();
             if (empty($rid)) {
                 common_log_db_error($profile, 'INSERT', __FILE__);
                 $profile->query("ROLLBACK");
                 return false;
             }
         }
         $profile->query("COMMIT");
         $this->saveAvatars($user, $id);
         return $id;
     }
 }
Пример #16
0
 function getUsers()
 {
     $profile = new Profile();
     $offset = ($this->page - 1) * PROFILES_PER_PAGE;
     $limit = PROFILES_PER_PAGE + 1;
     if (isset($this->q)) {
         // User is searching via query
         $search_engine = $profile->getSearchEngine('profile');
         $mode = 'reverse_chron';
         if ($this->sort == 'nickname') {
             if ($this->reverse) {
                 $mode = 'nickname_desc';
             } else {
                 $mode = 'nickname_asc';
             }
         } else {
             if ($this->reverse) {
                 $mode = 'chron';
             }
         }
         $search_engine->set_sort_mode($mode);
         $search_engine->limit($offset, $limit);
         $search_engine->query($this->q);
         $profile->find();
     } else {
         // User is browsing via AlphaNav
         $sort = $this->getSortKey();
         $sql = 'SELECT profile.* FROM profile, user WHERE profile.id = user.id';
         switch ($this->filter) {
             case 'all':
                 // NOOP
                 break;
             case '0-9':
                 $sql .= '  AND LEFT(profile.nickname, 1) BETWEEN \'0\' AND \'9\'';
                 break;
             default:
                 $sql .= sprintf(' AND LEFT(LOWER(profile.nickname), 1) = \'%s\'', $this->filter);
         }
         $sql .= sprintf(' ORDER BY profile.%s %s, profile.nickname ASC LIMIT %d, %d', $sort, $this->reverse ? 'DESC' : 'ASC', $offset, $limit);
         $profile->query($sql);
     }
     return $profile;
 }
Пример #17
0
 function ensureProfile($user)
 {
     // check to see if there's already a profile for this user
     $profileurl = 'http://twitter.com/' . $user->screen_name;
     $profile = $this->getProfileByUrl($user->screen_name, $profileurl);
     if (!empty($profile)) {
         common_debug($this->name() . " - Profile for {$profile->nickname} found.");
         // Check to see if the user's Avatar has changed
         $this->checkAvatar($user, $profile);
         return $profile;
     } else {
         common_debug($this->name() . ' - Adding profile and remote profile ' . "for Twitter user: {$profileurl}.");
         $profile = new Profile();
         $profile->query("BEGIN");
         $profile->nickname = $user->screen_name;
         $profile->fullname = $user->name;
         $profile->homepage = $user->url;
         $profile->bio = $user->description;
         $profile->location = $user->location;
         $profile->profileurl = $profileurl;
         $profile->created = common_sql_now();
         try {
             $id = $profile->insert();
         } catch (Exception $e) {
             common_log(LOG_WARNING, $this->name() . ' Couldn\'t insert profile - ' . $e->getMessage());
         }
         if (empty($id)) {
             common_log_db_error($profile, 'INSERT', __FILE__);
             $profile->query("ROLLBACK");
             return false;
         }
         // check for remote profile
         $remote_pro = Remote_profile::staticGet('uri', $profileurl);
         if (empty($remote_pro)) {
             $remote_pro = new Remote_profile();
             $remote_pro->id = $id;
             $remote_pro->uri = $profileurl;
             $remote_pro->created = common_sql_now();
             try {
                 $rid = $remote_pro->insert();
             } catch (Exception $e) {
                 common_log(LOG_WARNING, $this->name() . ' Couldn\'t save remote profile - ' . $e->getMessage());
             }
             if (empty($rid)) {
                 common_log_db_error($profile, 'INSERT', __FILE__);
                 $profile->query("ROLLBACK");
                 return false;
             }
         }
         $profile->query("COMMIT");
         $this->saveAvatars($user, $id);
         return $profile;
     }
 }
Пример #18
0
 protected function ensureProfile($twuser)
 {
     // check to see if there's already a profile for this user
     $profileurl = 'https://twitter.com/' . $twuser->screen_name;
     try {
         $profile = $this->getProfileByUrl($twuser->screen_name, $profileurl);
         $this->updateAvatar($twuser, $profile);
         return $profile;
     } catch (NoResultException $e) {
         common_debug(__METHOD__ . ' - Adding profile and remote profile ' . "for Twitter user: {$profileurl}.");
     }
     $profile = new Profile();
     $profile->query("BEGIN");
     $profile->nickname = $twuser->screen_name;
     $profile->fullname = $twuser->name;
     $profile->homepage = $twuser->url;
     $profile->bio = $twuser->description;
     $profile->location = $twuser->location;
     $profile->profileurl = $profileurl;
     $profile->created = common_sql_now();
     try {
         $id = $profile->insert();
         // insert _should_ throw exception on failure
         if (empty($id)) {
             throw new Exception('Failed insert');
         }
     } catch (Exception $e) {
         common_log(LOG_WARNING, __METHOD__ . " Couldn't insert profile: " . $e->getMessage());
         common_log_db_error($profile, 'INSERT', __FILE__);
         $profile->query("ROLLBACK");
         return false;
     }
     $profile->query("COMMIT");
     $this->updateAvatar($twuser, $profile);
     return $profile;
 }
Пример #19
0
 /**
  * Create local ostatus_profile and profile/user_group entries for
  * the provided remote user or group.
  * This should never return null -- you will either get an object or
  * an exception will be thrown.
  *
  * @param ActivityObject $object
  * @param array $hints
  *
  * @return Ostatus_profile
  */
 protected static function createActivityObjectProfile(ActivityObject $object, array $hints = array())
 {
     $homeuri = $object->id;
     $discover = false;
     if (!$homeuri) {
         common_log(LOG_DEBUG, __METHOD__ . " empty actor profile URI: " . var_export($activity, true));
         // TRANS: Exception.
         throw new Exception(_m('No profile URI.'));
     }
     $user = User::getKV('uri', $homeuri);
     if ($user instanceof User) {
         // TRANS: Exception.
         throw new Exception(_m('Local user cannot be referenced as remote.'));
     }
     if (OStatusPlugin::localGroupFromUrl($homeuri)) {
         // TRANS: Exception.
         throw new Exception(_m('Local group cannot be referenced as remote.'));
     }
     $ptag = Profile_list::getKV('uri', $homeuri);
     if ($ptag instanceof Profile_list) {
         $local_user = User::getKV('id', $ptag->tagger);
         if ($local_user instanceof User) {
             // TRANS: Exception.
             throw new Exception(_m('Local list cannot be referenced as remote.'));
         }
     }
     if (array_key_exists('feedurl', $hints)) {
         $feeduri = $hints['feedurl'];
     } else {
         $discover = new FeedDiscovery();
         $feeduri = $discover->discoverFromURL($homeuri);
     }
     if (array_key_exists('salmon', $hints)) {
         $salmonuri = $hints['salmon'];
     } else {
         if (!$discover) {
             $discover = new FeedDiscovery();
             $discover->discoverFromFeedURL($hints['feedurl']);
         }
         // XXX: NS_REPLIES is deprecated anyway, so let's remove it in the future.
         $salmonuri = $discover->getAtomLink(Salmon::REL_SALMON) ?: $discover->getAtomLink(Salmon::NS_REPLIES);
     }
     if (array_key_exists('hub', $hints)) {
         $huburi = $hints['hub'];
     } else {
         if (!$discover) {
             $discover = new FeedDiscovery();
             $discover->discoverFromFeedURL($hints['feedurl']);
         }
         $huburi = $discover->getHubLink();
     }
     if (!$huburi && !common_config('feedsub', 'fallback_hub') && !common_config('feedsub', 'nohub')) {
         // We can only deal with folks with a PuSH hub
         throw new FeedSubNoHubException();
     }
     $oprofile = new Ostatus_profile();
     $oprofile->uri = $homeuri;
     $oprofile->feeduri = $feeduri;
     $oprofile->salmonuri = $salmonuri;
     $oprofile->created = common_sql_now();
     $oprofile->modified = common_sql_now();
     if ($object->type == ActivityObject::PERSON) {
         $profile = new Profile();
         $profile->created = common_sql_now();
         self::updateProfile($profile, $object, $hints);
         $oprofile->profile_id = $profile->insert();
         if ($oprofile->profile_id === false) {
             // TRANS: Server exception.
             throw new ServerException(_m('Cannot save local profile.'));
         }
     } else {
         if ($object->type == ActivityObject::GROUP) {
             $profile = new Profile();
             $profile->query('BEGIN');
             $group = new User_group();
             $group->uri = $homeuri;
             $group->created = common_sql_now();
             self::updateGroup($group, $object, $hints);
             // TODO: We should do this directly in User_group->insert()!
             // currently it's duplicated in User_group->update()
             // AND User_group->register()!!!
             $fields = array('nickname' => 'nickname', 'fullname' => 'fullname', 'mainpage' => 'profileurl', 'homepage' => 'homepage', 'description' => 'bio', 'location' => 'location', 'created' => 'created', 'modified' => 'modified');
             foreach ($fields as $gf => $pf) {
                 $profile->{$pf} = $group->{$gf};
             }
             $profile_id = $profile->insert();
             if ($profile_id === false) {
                 $profile->query('ROLLBACK');
                 throw new ServerException(_('Profile insertion failed.'));
             }
             $group->profile_id = $profile_id;
             $oprofile->group_id = $group->insert();
             if ($oprofile->group_id === false) {
                 $profile->query('ROLLBACK');
                 // TRANS: Server exception.
                 throw new ServerException(_m('Cannot save local profile.'));
             }
             $profile->query('COMMIT');
         } else {
             if ($object->type == ActivityObject::_LIST) {
                 $ptag = new Profile_list();
                 $ptag->uri = $homeuri;
                 $ptag->created = common_sql_now();
                 self::updatePeopletag($ptag, $object, $hints);
                 $oprofile->peopletag_id = $ptag->insert();
                 if ($oprofile->peopletag_id === false) {
                     // TRANS: Server exception.
                     throw new ServerException(_m('Cannot save local list.'));
                 }
             }
         }
     }
     $ok = $oprofile->insert();
     if ($ok === false) {
         // TRANS: Server exception.
         throw new ServerException(_m('Cannot save OStatus profile.'));
     }
     $avatar = self::getActivityObjectAvatar($object, $hints);
     if ($avatar) {
         try {
             $oprofile->updateAvatar($avatar);
         } catch (Exception $ex) {
             // Profile is saved, but Avatar is messed up. We're
             // just going to continue.
             common_log(LOG_WARNING, "Exception saving OStatus profile avatar: " . $ex->getMessage());
         }
     }
     return $oprofile;
 }
Пример #20
0
 /**
  * Get pending subscribers, who have not yet been approved.
  *
  * @param int $offset
  * @param int $limit
  * @return Profile
  */
 function getRequests($offset = 0, $limit = null)
 {
     $qry = 'SELECT profile.* ' . 'FROM profile JOIN subscription_queue ' . 'ON profile.id = subscription_queue.subscriber ' . 'WHERE subscription_queue.subscribed = %d ' . 'ORDER BY subscription_queue.created DESC ';
     if ($limit != null) {
         if (common_config('db', 'type') == 'pgsql') {
             $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
         } else {
             $qry .= ' LIMIT ' . $offset . ', ' . $limit;
         }
     }
     $members = new Profile();
     $members->query(sprintf($qry, $this->id));
     return $members;
 }
Пример #21
0
enviarEmail.php [options]
Send a welcome email with instructions.

  -i --id       ID of the user to send email
  -n --nickname nickname of the user to send email
  -g --group    Nickname or alias of group to send email
  -G --group-id ID of group to send email
  -a --all      Send email to all members

END_OF_USERROLE_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
// Si tiene la opción all
if (have_option('a', 'all')) {
    $qry = "SELECT * FROM profile order by id asc";
    $pflQry = new Profile();
    $pflQry->query($qry);
    $members = array();
    while ($pflQry->fetch()) {
        $members[] = clone $pflQry;
    }
    $pflQry->free();
} else {
    if (have_option('i', 'id') || have_option('n', 'nickname')) {
        if (have_option('i', 'id')) {
            $id = get_option_value('i', 'id');
            $profile = Profile::staticGet('id', $id);
            if (empty($profile)) {
                print "Can't find user with ID {$id}\n";
                exit(1);
            }
        } else {
Пример #22
0
 /**
  * Whips up a query to get a list of profiles based on the provided
  * people tag and page, initalizes a ProfileList widget, and displays
  * it to the user.
  *
  * @return nothing
  */
 function showContent()
 {
     $profile = new Profile();
     $offset = ($this->page - 1) * PROFILES_PER_PAGE;
     $limit = PROFILES_PER_PAGE + 1;
     if (common_config('db', 'type') == 'pgsql') {
         $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
     } else {
         $lim = ' LIMIT ' . $offset . ', ' . $limit;
     }
     // XXX: memcached this
     $qry = 'SELECT profile.* ' . 'FROM profile JOIN ( profile_tag, profile_list ) ' . 'ON profile.id = profile_tag.tagger ' . 'AND profile_tag.tagger = profile_list.tagger ' . 'AND profile_list.tag = profile_tag.tag ' . 'WHERE profile_tag.tagger = profile_tag.tagged ' . "AND profile_tag.tag = '%s' ";
     $user = common_current_user();
     if (empty($user)) {
         $qry .= 'AND profile_list.private = false ';
     } else {
         $qry .= 'AND (profile_list.tagger = ' . $user->id . ' OR profile_list.private = false) ';
     }
     $qry .= 'ORDER BY profile_tag.modified DESC%s';
     $profile->query(sprintf($qry, $this->tag, $lim));
     $ptl = new SelfTagProfileList($profile, $this);
     // pass the ammunition
     $cnt = $ptl->show();
     $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE, $this->page, 'selftag', array('tag' => $this->tag));
 }