} // Only users with a lock on the article can change it. if ($articleObj->isLocked() && ($g_user->getUserId() != $articleObj->getLockedByUser())) { $diffSeconds = time() - strtotime($articleObj->getLockTime()); $hours = floor($diffSeconds/3600); $diffSeconds -= $hours * 3600; $minutes = floor($diffSeconds/60); $lockUser = new User($articleObj->getLockedByUser()); camp_html_add_msg(getGS('Could not save the article. It has been locked by $1 $2 hours and $3 minutes ago.', $lockUser->getRealName(), $hours, $minutes)); camp_html_goto_page($BackLink); exit; } // Update the first comment if the article title has changed if ($f_article_title != $articleObj->getTitle()) { $firstPostId = ArticleComment::GetCommentThreadId($articleObj->getArticleNumber(), $articleObj->getLanguageId()); if ($firstPostId) { $firstPost = new Phorum_message($firstPostId); $firstPost->setSubject($f_article_title); } } // Update the article author if (!empty($f_article_author)) { ArticleAuthor::OnArticleLanguageDelete($articleObj->getArticleNumber(), $articleObj->getLanguageId()); $i = 0; foreach ($f_article_author as $author) { $authorObj = new Author($author); if (!$authorObj->exists() && strlen(trim($author)) > 0) { $authorData = Author::ReadName($author); $authorObj->create($authorData);
/** * Create the first message for an article, which is a blank message * with the title of the article as the subject. * * @param Article $p_article * @param int $p_forumId * @return mixed * The comment created (or the one that already exists) on success, * or false on error. */ private function CreateFirstComment($p_article, $p_forumId) { // Check if the first post already exists. $articleNumber = $p_article->getArticleNumber(); $languageId = $p_article->getLanguageId(); $firstPost = ArticleComment::GetCommentThreadId($articleNumber, $languageId); if ($firstPost) { return new Phorum_message($firstPost); } // Get article creator $user = new User($p_article->getCreatorId()); if ($user->exists()) { $userId = $user->getUserId(); $userEmail = $user->getEmail(); $userPasswd = $user->getPassword(); $userName = $user->getUserName(); $userRealName = $user->getRealName(); // Create phorum user if necessary $phorumUser = Phorum_user::GetByUserName($userName); if (!is_object($phorumUser)) { $phorumUser = new Phorum_user(); } if (!$phorumUser->CampUserExists($userId) && !$phorumUser->create($userName, $userPasswd, $userEmail, $userId)) { return null; } } else { $userId = null; $userEmail = ''; $userRealName = ''; } // Create the comment. $title = $p_article->getTitle(); $commentObj = new Phorum_message(); if ($commentObj->create($p_forumId, $title, '', 0, 0, $userRealName, $userEmail, is_null($userId) ? 0 : $userId)) { // Link the message to the current article. ArticleComment::Link($articleNumber, $languageId, $commentObj->getMessageId(), true); return $commentObj; } else { return null; } } // method CreateFirstComment
/** * Returns an article comments list based on the given parameters. * * @param array $p_parameters * An array of ComparisonOperation objects * @param string $p_order * An array of columns and directions to order by * @param integer $p_start * The record number to start the list * @param integer $p_limit * The offset. How many records from $p_start will be retrieved. * @param integer $p_count * The total count of the elements; this count is computed without * applying the start ($p_start) and limit parameters ($p_limit) * * @return array $articleCommentsList * An array of Comment objects */ public static function GetList(array $p_parameters, $p_order = null, $p_start = 0, $p_limit = 0, &$p_count, $p_skipCache = false) { global $g_ado_db, $PHORUM; if (!$p_skipCache && CampCache::IsEnabled()) { $paramsArray['parameters'] = serialize($p_parameters); $paramsArray['order'] = (is_null($p_order)) ? 'null' : $p_order; $paramsArray['start'] = $p_start; $paramsArray['limit'] = $p_limit; $cacheListObj = new CampCacheList($paramsArray, __METHOD__, self::DEFAULT_TTL); $articleCommentsList = $cacheListObj->fetchFromCache(); if ($articleCommentsList !== false && is_array($articleCommentsList)) { return $articleCommentsList; } } $selectClauseObj = new SQLSelectClause(); $countClauseObj = new SQLSelectClause(); $messageTable = $PHORUM['message_table']; $selectClauseObj->setTable($messageTable); $countClauseObj->setTable($messageTable); $articleNumber = null; $languageId = null; // sets the where conditions foreach ($p_parameters as $param) { $comparisonOperation = self::ProcessListParameters($param); if (strtolower($comparisonOperation->getLeftOperand()) == 'fk_article_number') { $articleNumber = $comparisonOperation->getRightOperand(); } if (strtolower($comparisonOperation->getLeftOperand()) == 'fk_language_id') { $languageId = $comparisonOperation->getRightOperand(); } $parameters[] = $comparisonOperation; } if (!is_null($articleNumber) && !is_null($languageId)) { // gets the thread id for the article $threadId = ArticleComment::GetCommentThreadId($articleNumber, $languageId); $selectClauseObj->addWhere('thread = '.$threadId); $countClauseObj->addWhere('thread = '.$threadId); } $selectClauseObj->addWhere('message_id != thread'); $selectClauseObj->addWhere('status = '.PHORUM_STATUS_APPROVED); $countClauseObj->addWhere('message_id != thread'); $countClauseObj->addWhere('status = '.PHORUM_STATUS_APPROVED); if (!is_array($p_order) || count($p_order) == 0) { $p_order = array('default'=>'asc'); } // sets the order condition if any if (is_array($p_order)) { $order = ArticleComment::ProcessListOrder($p_order); // sets the order condition if any foreach ($order as $orderDesc) { $orderField = $orderDesc['field']; $orderDirection = $orderDesc['dir']; $selectClauseObj->addOrderBy($orderField . ' ' . $orderDirection); } } // sets the limit $selectClauseObj->setLimit($p_start, $p_limit); // builds the query and executes it $selectQuery = $selectClauseObj->buildQuery(); $comments = $g_ado_db->GetAll($selectQuery); if (is_array($comments)) { $countClauseObj->addColumn('COUNT(*)'); $countQuery = $countClauseObj->buildQuery(); $p_count = $g_ado_db->GetOne($countQuery); // builds the array of comment objects $articleCommentsList = array(); foreach ($comments as $comment) { $pmObj = new Phorum_message($comment['message_id']); if ($pmObj->exists()) { $articleCommentsList[] = $pmObj; } } } else { $articleCommentsList = array(); $p_count = 0; } if (!$p_skipCache && CampCache::IsEnabled()) { $cacheListObj->storeInCache($articleCommentsList); } return $articleCommentsList; } // fn GetList