/** * Create a new user instance. * * @param mixed $id * @return object */ protected function resolveUser($id) { if (!is_numeric($id)) { if (strstr($id, '@')) { $user = User::oneByEmail($id); } else { $user = User::oneByUsername($id); } } else { $user = User::oneOrNew($id); } return $user; }
/** * Get the owner of this entry * * Accepts an optional property name. If provided * it will return that property value. Otherwise, * it returns the entire object * * @param string $property What data to return * @param mixed $default Default value * @return mixed */ public function owner($property = null, $default = null) { if (!$this->_owner instanceof \Hubzero\User\User) { $this->_owner = \User::oneOrNew($this->get('assigned')); } if ($property) { if ($property == 'picture') { return $this->_owner->picture(); } return $this->_owner->get($property, $default); } return $this->_owner; }
/** * Handles the actual sending of emails (or queuing them to be sent) * * @param int $user the user id to send to * @param array $posts the posts to include in the email * @param string $interval the distribution interval * @return bool **/ private function sendEmail($user, $posts, $interval = 'day') { if (!is_dir(PATH_CORE . DS . 'plugins' . DS . 'members' . DS . 'activity')) { $this->setError('PLG_CRON_ACTIVITY_REQUIRED_PLUGIN_NOT_FOUND'); return false; } $user = User::oneOrNew($user); if (!$user->get('id')) { $this->setError('PLG_CRON_ACTIVITY_USER_NOT_FOUND', $user->get('id')); return false; } $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'plugins' . DS . 'members' . DS . 'activity', 'name' => 'emails', 'layout' => 'digest_plain')); $eview->member = $user; $eview->rows = $posts; $eview->interval = $interval; $plain = $eview->loadTemplate(); $plain = str_replace("\n", "\r\n", $plain); // HTML $eview->setLayout('digest_html'); $html = $eview->loadTemplate(); $html = str_replace("\n", "\r\n", $html); // Build message $message = App::get('mailer'); $message->setSubject(Lang::txt('PLG_MEMBERS_ACTIVITY_EMAIL_SUBJECT'))->addFrom(Config::get('mailfrom'), Config::get('sitename'))->addTo($user->get('email'), $user->get('name'))->addHeader('X-Component', 'com_members')->addHeader('X-Component-Object', 'members_activity_email_digest'); $message->addPart($plain, 'text/plain'); $message->addPart($html, 'text/html'); // Send mail if (!$message->send($this->params->get('email_transport_mechanism'))) { $this->setError(Lang::txt('PLG_CRON_ACTIVITY_EMAIL_FAILED', $user->get('email'))); return false; } return true; }