Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * 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();
     }
 }
Пример #3
0
 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'));
 }