コード例 #1
0
ファイル: Phorum_user.php プロジェクト: nistormihai/Newscoop
  	/**
  	 * Create the user.  The user cannot be created if the user is
  	 * banned or the user name or email already exists.  The optional
  	 * $p_userId parameter is there for the cases where Phorum is run
  	 * inside of another master application and you want to use the
  	 * master application user ID for the Phorum ID.
  	 *
  	 * @param string $p_username
	 * @param string $p_password
  	 * @param string $p_email
  	 * @param int $p_userId
  	 * @param bool $p_encryptedPassword
  	 * @return boolean
  	 */
  	public function create($p_username, $p_password, $p_email, $p_userId = null,
  	                       $p_encryptedPassword = false)
  	{
		$userdata = array();

	   	if (Phorum_user::UserNameExists($p_username)) {
	   		return false;
	   	}

	   	if (Phorum_user::EmailExists($p_email)) {
	   		return false;
	   	}

		if (Phorum_user::IsBanned($p_username, $p_email)) {
			return false;
		}

		if (!is_null($p_userId) && is_numeric($p_userId)) {
			$tmpUser = new Phorum_user($p_userId);
//			$userdata['user_id'] = $p_userId;
			$userdata['fk_campsite_user_id'] = $p_userId;
			if ($tmpUser->exists()) {
				unset($userdata['user_id']);
			}
		}

		$userdata['username'] = $p_username;
		$userdata['password'] = $p_encryptedPassword ? $p_password : sha1($p_password);
		$userdata['email'] = $p_email;
		$userdata['date_added'] = time();
		$userdata['date_last_active'] = time();
		$userdata['hide_email'] = true;
		$userdata['active'] = PHORUM_USER_ACTIVE;

		// Create the user
		$this->m_data['user_id'] = phorum_db_user_add( $userdata );

		// Refresh the object from the database.
		$this->fetch();

		return true;
	} // fn create
コード例 #2
0
    /**
     * Performs the action; returns true on success, false on error.
     *
     * @param $p_context - the current context object
     * @return bool
     */
    public function takeAction(CampContext &$p_context)
    {
        $p_context->default_url->reset_parameter('f_'.$this->m_name);
        $p_context->url->reset_parameter('f_'.$this->m_name);

        if (!is_null($this->m_error)) {
            return false;
        }

        // Check that the article exists.
        $articleMetaObj = $p_context->default_article;
        if (!$articleMetaObj->defined) {
            $this->m_error = new PEAR_Error('The article was not selected. You must view an article in order to post comments.',
            ACTION_SUBMIT_COMMENT_ERR_NO_ARTICLE);
            return false;
        }
        if (!$articleMetaObj->comments_enabled || $articleMetaObj->comments_locked)  {
            $this->m_error = new PEAR_Error('Comments are not enabled for this publication/article.',
            ACTION_SUBMIT_COMMENT_ERR_NOT_ENABLED);
            return false;
        }

        // Get the publication.
        $publicationObj = new Publication($articleMetaObj->publication->identifier);
        $forum = new Phorum_forum($publicationObj->getForumId());
        if (!$forum->exists()) {
            $forum->create();
            $forum->setName($publicationObj->getName());
            $publicationObj->setForumId($forum->getForumId());
        }
        $forumId = $forum->getForumId();

        $user = $p_context->user;
        if ($user->defined) {
            $phorumUser = Phorum_user::GetByUserName($user->uname);
            if (is_null($phorumUser)) {
                $phorumUser = new Phorum_user();
            }
            $userId = $user->identifier;
            $userEmail = $user->email;
            $userRealName = $user->name;
            $userPasswd = $user->password_encrypted;
            // Check if the phorum user existed or was created successfuly.
            // If not, set the error code to 'internal error' and exit.
            if (!Phorum_user::CampUserExists($userId)
            && !$phorumUser->create($user->uname, $userPasswd, $userEmail, $userId)) {
                $this->m_error = new PEAR_Error('There was an internal error when submitting the comment (code 1).',
                ACTION_SUBMIT_COMMENT_ERR_INTERNAL);
                return false;
            }
        } else {
            if ($forum->getPublicPermissions() & (PHORUM_USER_ALLOW_NEW_TOPIC | PHORUM_USER_ALLOW_REPLY)) {
                if (!isset($this->m_properties['reader_email'])) {
                    $this->m_error = new PEAR_Error('EMail field is empty. You must fill in your EMail address.',
                    ACTION_SUBMIT_COMMENT_ERR_NO_EMAIL);
                    return false;
                }
                $userId = null;
                $userEmail = $this->m_properties['reader_email'];
                $userRealName = $userEmail;
            } else {
                $this->m_error = new PEAR_Error('You must be a registered user in order to submit a comment. Please subscribe or log in if you already have a subscription.',
                ACTION_SUBMIT_COMMENT_ERR_NO_PUBLIC);
                return false;
            }
        }

        // Validate the CAPTCHA code if it was enabled for the current publication.
        if ($publicationObj->isCaptchaEnabled()) {
            if ($this->_processCaptcha() === FALSE) {
                return FALSE;
            }
        }

        // Check if the reader was banned from posting comments.
        if (Phorum_user::IsBanned($userRealName, $userEmail)) {
            $this->m_error = new PEAR_Error('You are banned from submitting comments.',
            ACTION_SUBMIT_COMMENT_ERR_BANNED);
            return false;
        }

        // Create the first post message (if needed)
        $articleObj = new Article($articleMetaObj->language->number, $articleMetaObj->number);
        $firstPost = $this->CreateFirstComment($articleObj, $forumId);
        if (is_null($firstPost)) {
            $this->m_error = new PEAR_Error('There was an internal error when submitting the comment (code 2).',
            ACTION_SUBMIT_COMMENT_ERR_INTERNAL);
            return false;
        }

        // Set the parent to the currently viewed comment if a certain existing
        // comment was selected. Otherwise, set the parent identifier to the root message.
        $parentMessage = new Phorum_message($p_context->comment->identifier);
        if (!$parentMessage->exists()) {
            $parentMessage = $firstPost;
        }

        // Create the comment. If there was an error creating the comment set the
        // error code to 'internal error' and exit.
        $commentObj = new Phorum_message();
        if (!$commentObj->create($forumId, $this->m_properties['subject'],
        $this->m_properties['content'], $firstPost->getThreadId(),
        $parentMessage->getMessageId(), $this->m_properties['nickname'], $userEmail,
        is_null($userId) ? 0 : $userId)) {
            $this->m_error = new PEAR_Error('There was an internal error when submitting the comment (code 3).',
            ACTION_SUBMIT_COMMENT_ERR_INTERNAL);
            return false;
        }

        // If the user was unknown (public comment) and public comments were moderated
        // or the user was known (subscriber comment) and subscriber comments were moderated
        // set the comment status to 'hold'. Otherwise, set the status to 'approved'.
        if ((!is_null($userId) && $publicationObj->commentsSubscribersModerated())
        || (is_null($userId) && $publicationObj->commentsPublicModerated())) {
            $commentObj->setStatus(PHORUM_STATUS_HOLD);
        } else {
            $commentObj->setStatus(PHORUM_STATUS_APPROVED);
        }

        // Link the message to the current article.
        $isFirstMessage = ($firstPost->getThreadId() == 0);
        ArticleComment::Link($articleMetaObj->number, $articleMetaObj->language->number,
        $commentObj->getMessageId(), $isFirstMessage);

        $p_context->comment = new MetaComment($commentObj->getMessageId());

        $p_context->default_url->reset_parameter('f_comment_reader_email');
        $p_context->default_url->reset_parameter('f_comment_subject');
        $p_context->default_url->reset_parameter('f_comment_content');
        $p_context->default_url->reset_parameter('f_submit_comment');
        $p_context->default_url->reset_parameter('f_captcha_code');
        $p_context->url->reset_parameter('f_comment_reader_email');
        $p_context->url->reset_parameter('f_comment_subject');
        $p_context->url->reset_parameter('f_comment_content');
        $p_context->url->reset_parameter('f_submit_comment');
        $p_context->url->reset_parameter('f_captcha_code');

        $this->m_properties['rejected'] = false;

        $this->m_error = ACTION_OK;
        return true;
    }
コード例 #3
0
ファイル: MetaUser.php プロジェクト: nistormihai/Newscoop
 protected function isBlockedFromComments() {
     return (int)Phorum_user::IsBanned($this->m_dbObject->getRealName(), $this->m_dbObject->getEmail());
 }
コード例 #4
0
    /**
     * Performs the action; returns true on success, false on error.
     *
     * @param $p_context - the current context object
     * @return bool
     */
    public function takeAction(CampContext &$p_context)
    {
        $p_context->default_url->reset_parameter('f_'.$this->m_name);
        $p_context->url->reset_parameter('f_'.$this->m_name);

        if (!is_null($this->m_error)) {
            return false;
        }

        // Check that the article exists.
        $articleMetaObj = $p_context->default_article;
        if (!$articleMetaObj->defined) {
            $this->m_error = new PEAR_Error('The article was not selected. You must view an article in order to post comments.',
            ACTION_PREVIEW_COMMENT_ERR_NO_ARTICLE);
            return false;
        }
        if (!$articleMetaObj->comments_enabled || $articleMetaObj->comments_locked)  {
            $this->m_error = new PEAR_Error('Comments are not enabled for this publication/article.',
            ACTION_PREVIEW_COMMENT_ERR_NOT_ENABLED);
            return false;
        }

        // Get the publication.
        $publicationObj = new Publication($articleMetaObj->publication->identifier);
        $forum = new Phorum_forum($publicationObj->getForumId());
        if (!$forum->exists()) {
            $forum->create();
            $forum->setName($publicationObj->getName());
            $publicationObj->setForumId($forum->getForumId());
        }
        $forumId = $forum->getForumId();

        $user = $p_context->user;
        if ($user->defined) {
            $this->m_properties['reader_email'] = $user->email;
        } else {
            if ($forum->getPublicPermissions() & (PHORUM_USER_ALLOW_NEW_TOPIC | PHORUM_USER_ALLOW_REPLY)) {
                if (!isset($this->m_properties['reader_email'])) {
                    $this->m_error = new PEAR_Error('EMail field is empty. You must fill in your EMail address.',
                    ACTION_PREVIEW_COMMENT_ERR_NO_EMAIL);
                    return false;
                }
            } else {
                $this->m_error = new PEAR_Error('You must be a registered user in order to submit a comment. Please subscribe or log in if you already have a subscription.',
                ACTION_PREVIEW_COMMENT_ERR_NO_PUBLIC);
                return false;
            }
        }

        // Check if the reader was banned from posting comments.
        if (Phorum_user::IsBanned($userRealName, $userEmail)) {
            $this->m_error = new PEAR_Error('You are banned from submitting comments.',
            ACTION_PREVIEW_COMMENT_ERR_BANNED);
            return false;
        }

        $this->m_error = ACTION_OK;
        return true;
    }