function __construct(Profile $target, Profile $scoped = null, array $rsvp = array())
 {
     $stream = new RawEventsNoticeStream();
     if ($target->sameAs($scoped)) {
         $key = 'happening:ids_for_user_own:' . $target->getID();
     } else {
         $key = 'happening:ids_for_user:' . $target->getID();
     }
     // Match RSVP against our possible values, given in the class variable
     // and if no RSVPs are given is empty, assume we want all events, even
     // without RSVPs from this profile.
     $this->rsvp = array_intersect($this->rsvp, $rsvp);
     $this->target = $target;
     parent::__construct(new CachingNoticeStream($stream, $key), $scoped);
 }
예제 #2
0
 public static function saveNew(Notice $notice, Profile $target, $reason = null)
 {
     try {
         $att = Attention::getByKeys(['notice_id' => $notice->getID(), 'profile_id' => $target->getID()]);
         throw new AlreadyFulfilledException('Attention already exists with reason: ' . var_export($att->reason, true));
     } catch (NoResultException $e) {
         $att = new Attention();
         $att->notice_id = $notice->getID();
         $att->profile_id = $target->getID();
         $att->reason = $reason;
         $att->created = common_sql_now();
         $result = $att->insert();
         if ($result === false) {
             throw new Exception('Failed Attention::saveNew for notice id==' . $notice->getID() . ' target id==' . $target->getID() . ', reason=="' . $reason . '"');
         }
     }
     return $att;
 }
예제 #3
0
 static function cloneProfile(Profile $prof)
 {
     $plugprof = new self();
     if ($plugprof->getFromDB($prof->input['_old_id'])) {
         $input = ToolBox::addslashes_deep($plugprof->fields);
         $input['id'] = $prof->getID();
         $plugprof->add($input);
     }
 }
예제 #4
0
 public function removeEntry(Profile $actor, Notice $target)
 {
     $fave = new Fave();
     $fave->user_id = $actor->getID();
     $fave->notice_id = $target->getID();
     if (!$fave->find(true)) {
         // TRANS: Client error displayed when trying to remove a 'favor' when there is none in the first place.
         throw new AlreadyFulfilledException(_('This is already not favorited.'));
     }
     $result = $fave->delete();
     if ($result === false) {
         common_log_db_error($fave, 'DELETE', __FILE__);
         // TRANS: Server error displayed when removing a favorite from the database fails.
         throw new ServerException(_('Could not delete favorite.'));
     }
     Fave::blowCacheForProfileId($actor->getID());
     Fave::blowCacheForNoticeId($target->getID());
 }
예제 #5
0
 /**
  * Build common remote-profile options structure.
  * Currently only adds output for remote profiles, nothing for local users.
  *
  * @param HTMLOutputter $out
  * @param Profile $profile
  */
 protected function showProfileOptions(HTMLOutputter $out, Profile $profile)
 {
     if (!$profile->isGroup() && !$profile->isLocal()) {
         $target = common_local_url('userbyid', array('id' => $profile->getID()));
         // TRANS: Label for access to remote profile options.
         $label = _m('Remote profile options...');
         $out->elementStart('div', 'remote-profile-options');
         $out->element('a', array('href' => $target), $label);
         $out->elementEnd('div');
     }
 }
예제 #6
0
 /**
  * if profile cloned
  *
  * @param $prof   Profile  object
  **/
 static function cloneProfile(Profile $prof)
 {
     global $DB;
     $plugprof = new self();
     $crit = array('profiles_id' => $prof->input['_old_id']);
     foreach ($DB->request($plugprof->getTable(), $crit) as $data) {
         $input = ToolBox::addslashes_deep($data);
         unset($input['id']);
         $input['profiles_id'] = $prof->getID();
         $plugprof->add($input);
     }
 }
 /**
  * if profile cloned
  *
  * @param $prof   Profile  object
  **/
 static function cloneProfile(Profile $prof)
 {
     global $DB;
     ///TODO check if needed, as core should already do this.
     $profile_right = new ProfileRight();
     $crit = array('profiles_id' => $prof->input['_old_id'], "`name` LIKE 'plugin_reports_%'");
     $rights = array();
     foreach ($DB->request($profile_right->getTable(), $crit) as $data) {
         $rights[$data['name']] = $data['rights'];
     }
     unset($input['id']);
     $profile_right->updateProfileRights($prof->getID(), $rights);
 }
예제 #8
0
 public static function saveNew(Notice $notice, Profile $profile, $reason = null)
 {
     $att = new Attention();
     $att->notice_id = $notice->getID();
     $att->profile_id = $profile->getID();
     $att->reason = $reason;
     $att->created = common_sql_now();
     $result = $att->insert();
     if ($result === false) {
         throw new Exception('Could not saveNew in Attention');
     }
     return $att;
 }
예제 #9
0
 static function getTagsArray($tagger, $tagged, Profile $scoped = null)
 {
     $ptag = new Profile_tag();
     $qry = sprintf('select profile_tag.tag ' . 'from profile_tag join profile_list ' . ' on (profile_tag.tagger = profile_list.tagger ' . '     and profile_tag.tag = profile_list.tag) ' . 'where profile_tag.tagger = %d ' . 'and   profile_tag.tagged = %d ', $tagger, $tagged);
     if (!$scoped instanceof Profile || $scoped->getID() !== $tagger) {
         $qry .= 'and profile_list.private = 0';
     }
     $tags = array();
     $ptag->query($qry);
     while ($ptag->fetch()) {
         $tags[] = $ptag->tag;
     }
     return $tags;
 }
예제 #10
0
 /**
  * Set common template tags for all profile aspects
  * @param int $user the user id
  * @return void
  */
 private function commonTemplateTags($user)
 {
     // get a random sample of 6 friends.
     require_once FRAMEWORK_PATH . 'models/relationships.php';
     $relationships = new Relationships($this->registry);
     $cache = $relationships->getByUser($user, true, 6);
     $this->registry->getObject('template')->getPage()->addTag('profile_friends_sample', array('SQL', $cache));
     // get the name and photo of the user
     require_once FRAMEWORK_PATH . 'models/profile.php';
     $profile = new Profile($this->registry, $user);
     $name = $profile->getName();
     $photo = $profile->getPhoto();
     $uid = $profile->getID();
     $this->registry->getObject('template')->getPage()->addTag('profile_name', $name);
     $this->registry->getObject('template')->getPage()->addTag('profile_photo', $photo);
     $this->registry->getObject('template')->getPage()->addTag('profile_user_id', $uid);
     // clear the profile
     $profile = "";
 }
예제 #11
0
 static function install(Migration $migration)
 {
     global $DB;
     $profileRight = new ProfileRight();
     $profile = new Profile();
     //Update needed
     if (TableExists('glpi_plugin_genericobject_profiles')) {
         foreach (getAllDatasFromTable('glpi_plugin_genericobject_profiles') as $right) {
             if (preg_match("/PluginGenericobject(.*)/", $right['itemtype'], $results)) {
                 $newrightname = 'plugin_genericobject_' . strtolower($results[1]) . 's';
                 if (!countElementsInTable('glpi_profilerights', "`profiles_id`='" . $right['profiles_id'] . "' \n                                           AND `name`='{$newrightname}'")) {
                     switch ($right['right']) {
                         case NULL:
                         case '':
                             $rightvalue = 0;
                             break;
                         case 'r':
                             $rightvalue = READ;
                             break;
                         case 'w':
                             $rightvalue = ALLSTANDARDRIGHT;
                             break;
                     }
                     $profileRight->add(array('profiles_id' => $right['profiles_id'], 'name' => $newrightname, 'rights' => $rightvalue));
                     if (!countElementsInTable('glpi_profilerights', "`profiles_id`='" . $right['profiles_id'] . "' \n                                              AND `name`='plugin_genericobject_types'")) {
                         $profileRight->add(array('profiles_id' => $right['profiles_id'], 'name' => 'plugin_genericobject_types', 'rights' => 23));
                     }
                 }
                 if ($right['open_ticket']) {
                     $profile->getFromDB($right['profiles_id']);
                     $helpdesk_item_types = json_decode($profile->fields['helpdesk_item_type'], true);
                     if (is_array($helpdesk_item_types)) {
                         if (!in_array($right['itemtype'], $helpdesk_item_types)) {
                             $helpdesk_item_types[] = $right['itemtype'];
                         }
                     } else {
                         $helpdesk_item_types = array($right['itemtype']);
                     }
                     $tmp['id'] = $profile->getID();
                     $tmp['helpdesk_item_type'] = json_encode($helpdesk_item_types);
                     $profile->update($tmp);
                 }
             }
         }
         //$migration->dropTable('glpi_plugin_genericobject_profiles');
     }
     if (!countElementsInTable('glpi_profilerights', "`name` LIKE '%genericobject%'")) {
         self::createFirstAccess();
     }
 }
예제 #12
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";
예제 #13
0
 static function newUri(Profile $actor, Managed_DataObject $object, $created = null)
 {
     if (is_null($created)) {
         $created = common_sql_now();
     }
     return TagURI::mint(strtolower(get_called_class()) . ':%d:%s:%d:%s', $actor->getID(), ActivityUtils::resolveUri($object->getObjectType(), true), $object->getID(), common_date_iso8601($created));
 }
예제 #14
0
 /**
  * Saves an attention for a profile (user or group) which means
  * it shows up in their home feed and such.
  */
 function saveAttention(Profile $target, $reason = null)
 {
     if ($target->isGroup()) {
         // FIXME: Make sure we check (for both local and remote) users are in the groups they send to!
         // legacy notification method, will still be in use for quite a while I think
         $this->addToGroupInbox($target->getGroup());
     } else {
         if ($target->hasBlocked($this->getProfile())) {
             common_log(LOG_INFO, "Not saving reply to profile {$target->id} ({$uri}) from sender {$sender->id} because of a block.");
             return false;
         }
     }
     if ($target->isLocal()) {
         // legacy notification method, will still be in use for quite a while I think
         $this->saveReply($target->getID());
     }
     $att = Attention::saveNew($this, $target, $reason);
     self::blow('reply:stream:%d', $target->getID());
     return true;
 }
예제 #15
0
 static function exists(Profile $subscriber, Profile $other)
 {
     $sub = Subscription_queue::pkeyGet(array('subscriber' => $subscriber->getID(), 'subscribed' => $other->getID()));
     return $sub instanceof Subscription_queue;
 }
예제 #16
0
 static function getTopic(Profile $profile, $namespace, $topic)
 {
     return Profile_prefs::getByPK(array('profile_id' => $profile->getID(), 'namespace' => $namespace, 'topic' => $topic));
 }
예제 #17
0
 /**
  * Low-level subscription save.
  * Outside callers should use Subscription::start()
  */
 protected static function saveNew(Profile $subscriber, Profile $other)
 {
     $sub = new Subscription();
     $sub->subscriber = $subscriber->getID();
     $sub->subscribed = $other->getID();
     $sub->jabber = 1;
     $sub->sms = 1;
     $sub->created = common_sql_now();
     $sub->uri = self::newUri($subscriber, $other, $sub->created);
     $result = $sub->insert();
     if ($result === false) {
         common_log_db_error($sub, 'INSERT', __FILE__);
         // TRANS: Exception thrown when a subscription could not be stored on the server.
         throw new Exception(_('Could not save subscription.'));
     }
     return $sub;
 }
 function onStartChangePassword(Profile $target, $oldpassword, $newpassword)
 {
     if ($this->password_changeable) {
         $user_username = new User_username();
         $user_username->user_id = $target->getID();
         $user_username->provider_name = $this->provider_name;
         if ($user_username->find(true)) {
             $authenticated = $this->checkPassword($user_username->username, $oldpassword);
             if ($authenticated) {
                 $result = $this->changePassword($user_username->username, $oldpassword, $newpassword);
                 if ($result) {
                     //stop handling of other handlers, because what was requested was done
                     return false;
                 } else {
                     // TRANS: Exception thrown when a password change fails.
                     throw new Exception(_('Password changing failed.'));
                 }
             } else {
                 if ($this->authoritative) {
                     //since we're authoritative, no other plugin could do this
                     // TRANS: Exception thrown when a password change fails.
                     throw new Exception(_('Password changing failed.'));
                 } else {
                     //let another handler try
                     return null;
                 }
             }
         }
     } else {
         if ($this->authoritative) {
             //since we're authoritative, no other plugin could do this
             // TRANS: Exception thrown when a password change attempt fails because it is not allowed.
             throw new Exception(_('Password changing is not allowed.'));
         }
     }
 }
 /**
  * Notify remote users when their notices get de-favorited.
  *
  * @param Profile $profile Profile person doing the de-faving
  * @param Notice  $notice  Notice being favored
  *
  * @return hook return value
  */
 function onEndDisfavorNotice(Profile $profile, Notice $notice)
 {
     try {
         $flink = Foreign_link::getByUserID($profile->getID(), TWITTER_SERVICE);
         // twitter service
     } catch (NoResultException $e) {
         return true;
     }
     if (!TwitterOAuthClient::isPackedToken($flink->credentials)) {
         $this->log(LOG_INFO, "Skipping fave processing for {$profile->id} since link is not OAuth.");
         return true;
     }
     $status_id = twitter_status_id($notice);
     if (empty($status_id)) {
         return true;
     }
     try {
         $token = TwitterOAuthClient::unpackToken($flink->credentials);
         $client = new TwitterOAuthClient($token->key, $token->secret);
         $client->favoritesDestroy($status_id);
     } catch (Exception $e) {
         common_log(LOG_ERR, "Error attempting to unfavorite bridged notice on Twitter: " . $e->getMessage());
     }
     return true;
 }
예제 #20
0
 /**
  * Get the Salmon keypair from a URI, uses XRD Discovery etc. Reasonably
  * you'll only get the public key ;)
  *
  * The string will (hopefully) be formatted as described in Magicsig specification:
  * https://salmon-protocol.googlecode.com/svn/trunk/draft-panzer-magicsig-01.html#anchor13
  *
  * @return string formatted as Magicsig keypair
  */
 public function discoverKeyPair(Profile $profile)
 {
     $signer_uri = $profile->getUri();
     if (empty($signer_uri)) {
         throw new ServerException(sprintf('Profile missing URI (id==%d)', $profile->getID()));
     }
     $disco = new Discovery();
     // Throws exception on lookup problems
     try {
         $xrd = $disco->lookup($signer_uri);
     } catch (Exception $e) {
         // Diaspora seems to require us to request the acct: uri
         $xrd = $disco->lookup($profile->getAcctUri());
     }
     common_debug('Will try to find magic-public-key from XRD of profile id==' . $profile->getID());
     $pubkey = null;
     if (Event::handle('MagicsigPublicKeyFromXRD', array($xrd, &$pubkey))) {
         $link = $xrd->get(Magicsig::PUBLICKEYREL);
         if (is_null($link)) {
             // TRANS: Exception.
             throw new Exception(_m('Unable to locate signer public key.'));
         }
         $pubkey = $link->href;
     }
     if (empty($pubkey)) {
         throw new ServerException('Empty Magicsig public key. A bug?');
     }
     // We have a public key element, let's hope it has proper key data.
     $keypair = false;
     $parts = explode(',', $pubkey);
     if (count($parts) == 2) {
         $keypair = $parts[1];
     } else {
         // Backwards compatibility check for separator bug in 0.9.0
         $parts = explode(';', $pubkey);
         if (count($parts) == 2) {
             $keypair = $parts[1];
         }
     }
     if ($keypair === false) {
         // For debugging clarity. Keypair did not pass count()-check above.
         // TRANS: Exception when public key was not properly formatted.
         throw new Exception(_m('Incorrectly formatted public key element.'));
     }
     return $keypair;
 }
예제 #21
0
 /**
  * Get the bookmark that a user made for an URL
  *
  * @param Profile $profile Profile to check for
  * @param string  $url     URL to check for
  *
  * @return Bookmark bookmark found or null
  */
 static function getByURL(Profile $profile, $url)
 {
     $nb = new Bookmark();
     $nb->profile_id = $profile->getID();
     $nb->url = $url;
     if (!$nb->find(true)) {
         throw new NoResultException($nb);
     }
     return $nb;
 }
예제 #22
0
 /**
  * Typically just used to fill out Twitter-compatible API status data.
  *
  * FIXME: Make all the calls before this end up with a Notice instead of ArrayWrapper please...
  */
 public function onNoticeSimpleStatusArray($notice, array &$status, Profile $scoped = null, array $args = array())
 {
     $status['repeated'] = $scoped instanceof Profile ? $scoped->hasRepeated($notice) : false;
     if ($status['repeated'] === true) {
         // Qvitter API wants the "repeated_id" value set too.
         $repeated = Notice::pkeyGet(array('profile_id' => $scoped->getID(), 'repeat_of' => $notice->getID()));
         $status['repeated_id'] = $repeated->getID();
     }
 }