/**
     * 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;
    }
Example #2
0
}

$articlesRemaining = Article::GetNumUniqueArticles($Pub);
if ($articlesRemaining > 0) {
	$errorMsgs[] = getGS('There are $1 article(s) left.', $articlesRemaining);
	$doDelete = false;
}

$subscriptionsRemaining = Subscription::GetNumSubscriptions($Pub);
if ($subscriptionsRemaining > 0) {
	$errorMsgs[] = getGS('There are $1 subscription(s) left.', $subscriptionsRemaining);
	$doDelete = false;
}

if ($doDelete) {
	$forum = new Phorum_forum($publicationObj->getForumId());
	$forum->delete();
	$publicationObj->delete();
	camp_html_goto_page("/$ADMIN/pub");
} else {
	$errorMsgs[] = getGS('The publication $1 could not be deleted.',
						 '<B>'.htmlspecialchars($publicationObj->getName()).'</B>');
}
echo camp_html_content_top(getGS("Deleting publication"), array("Pub" => $publicationObj));


?>
<P>
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="8" class="message_box">
<TR>
	<TD COLSPAN="2">
    /**
     * 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;
    }
Example #4
0
	/**
	 * Create a message.
	 *
	 * @param int $p_forumId
	 * 		The forum ID that this message belongs to.
	 *
	 * @param string $p_subject
	 * 		The subject of the message.
	 *
	 * @param string $p_body
	 * 		The body of the message
	 *
	 * @param int $p_threadId
	 * 		Set this to zero if it is the first message in the thread
	 *
	 * @param int $p_parentId
	 * 		The message you are replying to.
	 *
	 * @param string $p_author
	 * 		Human readable string for the name of the author.
	 *
	 * @param string $p_email
	 * 		Author's email.
	 *
	 * @param int $p_userId
	 * 		User ID that is stored in the phorum_users table.
	 *
	 * @return boolean
	 */
	public function create($p_forumId, $p_subject ='', $p_body = '',
					$p_threadId = 0, $p_parentId = 0,
				    $p_author = '', $p_email = '', $p_userId = 0)
	{
		global $PHORUM;
		global $g_ado_db;

		if (!is_numeric($p_forumId)) {
			return null;
		}

		// Fetch the settings and pretend they were returned to
		// us instead of setting a global variable.
		phorum_db_load_settings();
		$settings = $PHORUM['SETTINGS'];

		// Required Input
		$message['forum_id'] = $p_forumId;

		// Optional input
		$message['body'] = $p_body;
		$message['subject'] = $p_subject;
		$message['thread'] = $p_threadId;
		$message['parent_id'] = $p_parentId;
		$message['author'] = $p_author;
		$message['email'] = $p_email;
		$message['user_id'] = $p_userId;

		// Defaults
		$message['sort'] = PHORUM_SORT_DEFAULT;
		$message['closed'] = 0;

		// ??? Whats that suffix for?
//		$suffix = preg_replace("/[^a-z0-9]/i", "", $PHORUM["name"]);
//		$message['msgid'] = md5(uniqid(rand())) . ".$suffix";
		$message['msgid'] = md5(uniqid(rand()));
		$message['moderator_post'] = '0';
		$message['datestamp'] = time();

		// Fetch the forum object -
		// we need it for the config values.
		$forumObj = new Phorum_forum($p_forumId);
		if (!$forumObj->exists()) {
			return false;
		}

		// Set message workflow based on forum config.
		if ($forumObj->isModerated()) {
		    $message['status'] = PHORUM_STATUS_HOLD;
		} else {
		    $message['status'] = PHORUM_STATUS_APPROVED;
		}

		// Set user IP.
		$user_ip = $_SERVER["REMOTE_ADDR"];
		if ($settings["dns_lookup"]) {
		    $resolved = @gethostbyaddr($_SERVER["REMOTE_ADDR"]);
		    if (!empty($resolved)) {
		        $user_ip = $resolved;
		    }
		}
		$message["ip"] = $user_ip;

        $lockTables = array($PHORUM['message_table'],
                            $PHORUM['search_table'],
                            $PHORUM['subscribers_table']);
        $this->lockTables($lockTables);

		phorum_db_post_message($message);

		$this->mod_emailcomments($message);

		// Update the thread count.
		$sql = "SELECT COUNT(*) as thread_count FROM ".$PHORUM['message_table']
			   ." WHERE forum_id=".$p_forumId
			   ." AND thread=".$message['thread']
			   ." AND status > 0";
		$threadCount = $g_ado_db->GetOne($sql);

		$sql = "UPDATE ".$PHORUM['message_table']
				." SET thread_count=".$threadCount;
		$g_ado_db->Execute($sql);

	    // Retrieve the message again because the database sets
	    // some values.
	    $message = phorum_db_get_message($message["message_id"], "message_id", true);
		$this->m_data = $message;

		// Set the thread depth
		$this->__initThreadDepth();

		// Set the thread order.
		$this->__initThreadOrder();

		$this->__updateThreadInfo();

        if (isset($PHORUM['user']['user_id'])) {
		    // Mark own message read.
	        phorum_db_newflag_add_read(array(0=>array(
	            "id"    => $message["message_id"],
	            "forum" => $message["forum_id"],
	        )));

	        // Update the number of messages the user has posted.
        	phorum_db_user_addpost();
        }

        // Actions for messages which are approved.
	    if ($message["status"] > 0) {
	        // Update forum statistics,
	        // ??? Note: phorum_db_update_forum_stats requires global parameter-passing.
	        $PHORUM['forum_id'] = $p_forumId;
	        phorum_db_update_forum_stats(false, 1, $message["datestamp"]);

	        // Mail subscribed users.
	        //phorum_email_notice($message);
	    }

	    // Mail moderators.
	    if ($forumObj->emailModeratorsEnabled()) {
	        //phorum_email_moderators($message);
	    }
	    
	    $this->unlockTables();

	    return true;
	} // fn create
Example #5
0
/**
 * Update the forum config.
 *
 * @param Phorum_forum $p_forum
 * @param string $p_publicationName
 * @param boolean $p_enabled
 * @param boolean $p_publicPostingEnabled
 */
function camp_forum_update($p_forum, $p_publicationName, $p_enabled, $p_publicPostingEnabled)
{
	$p_forum->setName($p_publicationName);
	if ($p_publicPostingEnabled) {
		$p_forum->setPublicPermissions($p_forum->getPublicPermissions()
									 | PHORUM_USER_ALLOW_NEW_TOPIC
									 | PHORUM_USER_ALLOW_REPLY);
	} else {
		$p_forum->setPublicPermissions($p_forum->getPublicPermissions()
									 & !PHORUM_USER_ALLOW_NEW_TOPIC
									 & !PHORUM_USER_ALLOW_REPLY);
	}
	$p_forum->setIsVisible($p_enabled);
} // fn camp_forum_update
Example #6
0
if (!$publicationObj->exists()) {
	camp_html_add_msg(getGS('Publication does not exist.'));
}

if ($f_default_alias != $publicationObj->getDefaultAliasId()) {
	camp_is_alias_conflicting($f_default_alias);
}
if ($f_name != $publicationObj->getName()) {
	camp_is_publication_conflicting($f_name);
}

if (camp_html_has_msgs()) {
      camp_html_goto_page($backLink);
}

$forum = new Phorum_forum($publicationObj->getForumId());
if (!$forum->exists()) {
	$forum = camp_forum_create($publicationObj);
}
$forum->setName($f_name);
$forum->setIsVisible($f_comments_enabled);
$publicationObj->setPublicComments($f_comments_public_enabled);

$setting = new Phorum_setting('mod_emailcomments', 'S');
if (!$setting->exists()) {
	$setting->create();
}
$setting->update(array('addresses' => array($forum->getForumId() => $f_comments_moderator_to)));
$setting->update(array('from_addresses' => array($forum->getForumId() => $f_comments_moderator_from)));

$columns = array('Name' => $f_name,