/** * Retrieve currently active author object. * * @return CommentAuthor The active author object * * @since 2.0 */ public function activeAuthor() { if (!isset($this->_author)) { // get login (joomla users always win) $login = $this->app->request->getString(self::COOKIE_PREFIX . 'login', '', 'cookie'); // get active user $user = $this->app->user->get(); if ($user->id) { // create author object from user $this->_author = $this->app->commentauthor->create('joomla', array($user->name, $user->email, '', $user->id)); } else { if ($login == 'facebook' && ($connection = $this->app->facebook->client()) && ($content = $connection->getCurrentUserProfile()) && isset($content->id) && isset($content->name)) { // create author object from facebook user id $this->_author = $this->app->commentauthor->create('facebook', array($content->name, null, null, $content->id)); } else { if ($login == 'twitter' && ($connection = $this->app->twitter->client()) && ($content = $connection->get('account/verify_credentials')) && isset($content->screen_name) && isset($content->id)) { // create author object from twitter user id $this->_author = $this->app->commentauthor->create('twitter', array($content->screen_name, null, null, $content->id)); } else { $this->app->twitter->logout(); $this->app->facebook->logout(); // create author object from cookies $cookie = $this->readCookies(); $this->_author = $this->app->commentauthor->create('', array($cookie['author'], $cookie['email'], $cookie['url'])); } } } } setcookie(self::COOKIE_PREFIX . 'login', $this->_author->getUserType(), time() + self::COOKIE_LIFETIME, '/'); return $this->_author; }
/** * Set the author of the object * * @param CommentAuthor $author The author object * * @since 2.0 */ public function bindAuthor(CommentAuthor $author) { $this->author = $author->name; $this->email = $author->email; $this->url = $author->url; // set params if (!$author->isGuest()) { $this->user_id = $author->user_id; $this->user_type = $author->getUserType(); } }
public function getAvatar($size = 32) { if ($this->user_id) { $cache = new YCache(ZOO_CACHE_PATH . DS . 'author_cache.txt', true, 604800); $cache_check = $cache ? $cache->check() : false; $url = ''; // try to get avatar url from cache if ($cache_check) { $url = $cache->get($this->user_id); } // if url is empty, try to get avatar url from twitter if (empty($url)) { $info = CommentHelper::getTwitterFields($this->user_id, array('profile_image_url')); if (isset($info['profile_image_url'])) { $url = $info['profile_image_url']; } if ($cache_check) { $cache->set($this->user_id, $url); $cache->save(); } } if (!empty($url)) { return '<img alt="' . $this->name . '" title="' . $this->name . '" src="' . $url . '" height="' . $size . '" width="' . $size . '" />'; } } return parent::getAvatar($size); }
/** * Get the avatar from twitter * * @param integer $size The size of the avatar (squared). Default: 32 * * @return string The html img tag * * @since 2.0 */ public function getAvatar($size = 32) { if ($this->user_id) { $cache = $this->app->cache->create($this->app->path->path('cache:') . '/author_cache', true, 604800); $cache_check = $cache ? $cache->check() : false; $url = ''; // try to get avatar url from cache if ($cache_check) { $url = $cache->get($this->user_id); } // if url is empty, try to get avatar url from twitter if (empty($url)) { $info = $this->app->twitter->fields($this->user_id, array('profile_image_url'), $this->application); if (isset($info['profile_image_url'])) { $url = $info['profile_image_url']; } if ($cache_check) { $cache->set($this->user_id, $url)->save(); } } if (!empty($url)) { return '<img alt="' . $this->name . '" title="' . $this->name . '" src="' . $url . '" height="' . $size . '" width="' . $size . '" />'; } } return parent::getAvatar($size); }
public function getApprovedCommentCount(CommentAuthor $author) { // set query options if ($author && !$author->isGuest()) { $conditions = array("state = ? AND user_id = '?' AND user_type = '?'", Comment::STATE_APPROVED, $author->user_id, $author->getUserType()); } else { $conditions = array("state = ? AND user_id = '0' AND author = '?' AND email = '?'", Comment::STATE_APPROVED, $author->name, $author->email); } return $this->count(compact('conditions')); }