Пример #1
0
 /**
  * Constructor
  *
  * @param Profile $profile
  */
 function __construct(Profile $profile)
 {
     $this->profile = $profile;
     $this->user = $profile->getUser();
     $this->fields = $this->loadFields();
     $this->sections = $this->getSections();
     //common_debug(var_export($this->sections, true));
     //common_debug(var_export($this->fields, true));
 }
Пример #2
0
 function onEndProfileGetAvatar(Profile $profile, $size, Avatar &$avatar = null)
 {
     if (empty($avatar)) {
         try {
             $user = $profile->getUser();
             if (!empty($user) && !empty($user->email)) {
                 // Fake one!
                 $avatar = new Avatar();
                 $avatar->width = $avatar->height = $size;
                 $avatar->url = $this->libravatar_url($user->email, $size);
                 return false;
             }
         } catch (Exception $e) {
             common_log(LOG_DEBUG, "Couldn't find User for Profile id: " . $profile->id . " (" . $profile->nickname . ")");
         }
     }
     return true;
 }
Пример #3
0
 /**
  * Sign and post the given Atom entry as a Salmon message.
  *
  * Side effects: may generate a keypair on-demand for the given user,
  * which can be very slow on some systems (like those without php5-gmp).
  *
  * @param string $endpoint_uri
  * @param string $xml string representation of payload
  * @param Profile $user profile whose keys we sign with (must be a local user)
  * @return boolean success
  */
 public static function post($endpoint_uri, $xml, Profile $actor, Profile $target = null)
 {
     if (empty($endpoint_uri)) {
         common_debug('No endpoint URI for Salmon post to ' . $actor->getUri());
         return false;
     }
     try {
         $magic_env = MagicEnvelope::signAsUser($xml, $actor->getUser());
     } catch (Exception $e) {
         common_log(LOG_ERR, "Salmon unable to sign: " . $e->getMessage());
         return false;
     }
     // $target is so far only used in Diaspora, so it can be null
     if (Event::handle('SalmonSlap', array($endpoint_uri, $magic_env, $target))) {
         return false;
         //throw new ServerException('Could not distribute salmon slap as no plugin completed the event.');
     }
     return true;
 }
Пример #4
0
 public static function figureOutScope(Profile $actor, array $groups, $scope = null)
 {
     $scope = is_null($scope) ? self::defaultScope() : intval($scope);
     // For private streams
     try {
         $user = $actor->getUser();
         // FIXME: We can't do bit comparison with == (Legacy StatusNet thing. Let's keep it for now.)
         if ($user->private_stream && ($scope === Notice::PUBLIC_SCOPE || $scope === Notice::SITE_SCOPE)) {
             $scope |= Notice::FOLLOWER_SCOPE;
         }
     } catch (NoSuchUserException $e) {
         // TODO: Not a local user, so we don't know about scope preferences... yet!
     }
     // Force the scope for private groups
     foreach ($groups as $group_id) {
         try {
             $group = User_group::getByID($group_id);
             if ($group->force_scope) {
                 $scope |= Notice::GROUP_SCOPE;
                 break;
             }
         } catch (Exception $e) {
             common_log(LOG_ERR, 'Notice figureOutScope threw exception: ' . $e->getMessage());
         }
     }
     return $scope;
 }
Пример #5
0
 function getUser()
 {
     if (is_null($this->UserID)) {
         return parent::getUser();
     }
     if (is_null(parent::getUser()) && $this->UserID) {
         parent::setUser(Outlet::getInstance()->load('User', $this->UserID));
     }
     return parent::getUser();
 }
Пример #6
0
 /**
  * Send a Salmon notification ping immediately, and confirm that we got
  * an acceptable response from the remote site.
  *
  * @param mixed $entry XML string, Notice, or Activity
  * @param Profile $actor
  * @return boolean success
  */
 public function notifyActivity($entry, Profile $actor)
 {
     if ($this->salmonuri) {
         return Salmon::post($this->salmonuri, $this->notifyPrepXml($entry), $actor->getUser());
     }
     common_debug(__CLASS__ . ' error: No salmonuri for Ostatus_profile uri: ' . $this->uri);
     return false;
 }
Пример #7
0
 protected function addWebFingerPersonLinks(XML_XRD $xrd, Profile $target)
 {
     $xrd->links[] = new XML_XRD_Element_Link(Discovery::UPDATESFROM, common_local_url('ApiTimelineUser', array('id' => $target->id, 'format' => 'atom')), 'application/atom+xml');
     // Get this profile's keypair
     $magicsig = Magicsig::getKV('user_id', $target->id);
     if (!$magicsig instanceof Magicsig && $target->isLocal()) {
         $magicsig = Magicsig::generate($target->getUser());
     }
     if (!$magicsig instanceof Magicsig) {
         return false;
         // value doesn't mean anything, just figured I'd indicate this function didn't do anything
     }
     if (Event::handle('StartAttachPubkeyToUserXRD', array($magicsig, $xrd, $target))) {
         $xrd->links[] = new XML_XRD_Element_Link(Magicsig::PUBLICKEYREL, 'data:application/magic-public-key,' . $magicsig->toString());
         // The following event handles plugins like Diaspora which add their own version of the Magicsig pubkey
         Event::handle('EndAttachPubkeyToUserXRD', array($magicsig, $xrd, $target));
     }
 }
Пример #8
0
# Prevent Null
// function baz(): bool {
//     return null;
// }
// baz();
# Doesnt work
// function boo(): void {
// valid
// }
// boo();
class User
{
    // Can't declare return type:
    // public function __construct(): bool {
    //     return true;
    // }
    public function get() : self
    {
        return self;
    }
}
class Profile extends User
{
    public function getUser(int $id) : parent
    {
        return new User();
    }
}
$p = new Profile();
$result = $p->getUser(1);
var_dump($result);
Пример #9
0
// Law of Demter (Tell, Don't Ask!)
//
//
// The method on an object is allowed to interact with the following:
//
//  1. Other methods on its object;
//  2. Methods on properties of the object;
//  3. Methods on arguments passed into the method;
//  4. Methods on instances of new objects, created inside of the method.
include "User.php";
include "Profile.php";
/**
 * If we want to get the user's name, through the Profile object,
 * it should TELL the name, not ASK for it a third party object,
 * in our case the User object.
 *
 * So, without the law of Demeter in mind, the code would look like this:
 */
$user = new User("Josh", 29);
$userProfile = new Profile($user, "/img/josh.jpg");
echo $userProfile->getUser()->getName();
/**
 * In the above example, we ASK the User object to give us it's name.
 *
 * Now, we'll make the Profile object TELL the user's name:
 */
echo $userProfile->getName();
/**
 * The above row is the law of Demeter in action.
 */