private function _getReviewTitles($reviewTag) { //Load a list of reviews based on the tag $comments = new Comments(); $comments->whereAdd("comment like \"%#" . mysql_escape_string($reviewTag) . '"'); $comments->find(); $recordIds = array(); $reviews = array(); $datesSaved = array(); while ($comments->fetch()) { $resourceId = $comments->resource_id; //Load the resource from the database $resource = new Resource(); $resource->id = $comments->resource_id; $resource->find(true); $recordIds[$resource->record_id] = $resource->record_id; $comment = preg_replace('/#.*/', '', $comments->comment); $reviews[$resource->record_id] = $comment; $datesSaved[$resource->record_id] = $comments->created; } $titles = $this->loadTitleInformationForIds($recordIds, $reviews, $datesSaved); return array('success' => true, 'listName' => $reviewTag, 'listDescription' => 'Tagged reviews', 'titles' => $titles, 'cacheLength' => 24); }
/** * @param string $source * @return array */ function getComments($source = 'VuFind') { require_once ROOT_DIR . '/services/MyResearch/lib/Comments.php'; $sql = "SELECT comments.*, CONCAT(LEFT(user.firstname,1), '. ', user.lastname) as fullname, user.displayName as displayName " . "FROM comments RIGHT OUTER JOIN user on comments.user_id = user.id " . "WHERE comments.resource_id = '{$this->id}' ORDER BY comments.created"; //Get a reference to the scope we are in so we can determine how to process the comments. global $library; global $user; //Load all bad words. require_once ROOT_DIR . '/Drivers/marmot_inc/BadWord.php'; $badWords = new BadWord(); $badWordsList = $badWords->getBadWordExpressions(); $commentList = array(); $commentList['user'] = array(); $commentList['staff'] = array(); $comment = new Comments(); $comment->query($sql); if ($comment->N) { while ($comment->fetch()) { $okToAdd = true; if (isset($user) && $user != false && $user->id == $comment->user_id) { //It's always ok to show the user what they wrote } else { //Determine if we should censor bad words or hide the comment completely. $censorWords = true; if (isset($library)) { $censorWords = $library->hideCommentsWithBadWords == 0 ? true : false; } if ($censorWords) { $commentText = $comment->comment; foreach ($badWordsList as $badWord) { $commentText = preg_replace($badWord, '***', $commentText); } $comment->comment = $commentText; } else { //Remove comments with bad words $commentText = trim($comment->comment); foreach ($badWordsList as $badWord) { if (preg_match($badWord, $commentText)) { $okToAdd = false; break; } } } } if ($okToAdd) { //Remove any hashtags that were added to the review. if (preg_match('/#.*/', $comment->comment)) { $comment->comment = preg_replace('/#.*/', '', $comment->comment); $commentList['staff'][] = clone $comment; } else { $commentList['user'][] = clone $comment; } } } } return $commentList; }
$configArray = readConfig(); // Setup time zone date_default_timezone_set($configArray['Site']['timezone']); // Setup Local Database Connection ConnectionManager::connectToDatabase(); // Setup index connection ConnectionManager::connectToIndex(); // Delete the expired searches -- this cleans up any junk left in the database // from old search histories that were not caught by the session garbage collector. $count = 0; $fixed = 0; $searchObject = SearchObjectFactory::initSearchObject(); $searchObject->disableLogging(); $comments = new Comments(); if ($comments->find()) { while ($comments->fetch()) { $commentsRecord = new Comments_record(); $commentsRecord->comment_id = $comments->id; if ($commentsRecord->find(true)) { $query = 'local_ids_str_mv:"' . addcslashes($commentsRecord->record_id, '"') . '"'; $searchObject->setQueryString($query); $result = $searchObject->processSearch(); $searchObject->close(); if (PEAR::isError($result)) { PEAR::raiseError($result->getMessage()); } if ($result['response']['numFound'] > 0) { $idArray = $result['response']['docs'][0]["local_ids_str_mv"]; if ($comments->verifyLinks($idArray)) { ++$fixed; }