function doRead()
 {
     // strip HTML tags from the read line
     $line = fgetss($this->fp, 4096);
     // convert HTML entities to valid UTF-8 characters
     $line = String::html2utf($line);
     // slightly (~10%) faster than above, but not quite as accurate, and requires html_entity_decode()
     //		$line = html_entity_decode($line, ENT_COMPAT, strtoupper(Config::getVar('i18n', 'client_charset')));
     return $line;
 }
示例#2
0
 /**
  * Transcode a string
  * @param $string string String to transcode
  * @return string Result of transcoding
  */
 function trans($string)
 {
     // detect existence of encoding conversion libraries
     $mbstring = function_exists('mb_convert_encoding');
     $iconv = function_exists('iconv');
     // don't do work unless we have to
     if (strtolower($this->fromEncoding) == strtolower($this->toEncoding)) {
         return $string;
     }
     // 'HTML-ENTITIES' is not a valid encoding for iconv, so transcode manually
     if ($this->toEncoding == 'HTML-ENTITIES' && !$mbstring) {
         // NB: old PHP versions may have issues with htmlentities()
         if (checkPhpVersion('5.2.3')) {
             // don't double encode added in PHP 5.2.3
             return htmlentities($string, ENT_COMPAT, $this->fromEncoding, false);
         } else {
             return htmlentities($string, ENT_COMPAT, $this->fromEncoding);
         }
     } elseif ($this->fromEncoding == 'HTML-ENTITIES' && !$mbstring) {
         // NB: old PHP versions may have issues with html_entity_decode()
         if (checkPhpVersion('4.3.0')) {
             // multibyte character handling added in PHP 5.0.0
             return html_entity_decode($string, ENT_COMPAT, $this->toEncoding);
         } else {
             // use built-in transcoding to UTF8
             $string = String::html2utf($string);
             // make another pass to target encoding
             $this->fromEncoding = 'UTF-8';
             return $this->trans($string);
         }
         // Special cases for transliteration ("down-sampling")
     } elseif ($this->translit && $iconv) {
         // use the iconv library to transliterate
         return iconv($this->fromEncoding, $this->toEncoding . '//TRANSLIT', $string);
     } elseif ($this->translit && $this->fromEncoding == "UTF-8" && $this->toEncoding == "ASCII") {
         // use the utf2ascii library
         require_once './lib/pkp/lib/phputf8/utf8_to_ascii.php';
         return utf8_to_ascii($string);
     } elseif ($mbstring) {
         // use the mbstring library to transcode
         return mb_convert_encoding($string, $this->toEncoding, $this->fromEncoding);
     } elseif ($iconv) {
         // use the iconv library to transcode
         return iconv($this->fromEncoding, $this->toEncoding . '//IGNORE', $string);
     } else {
         // fail gracefully by returning the original string unchanged
         return $string;
     }
 }
示例#3
0
 function trans($string)
 {
     // detect existence of encoding conversion libraries
     $mbstring = function_exists('mb_convert_encoding');
     $iconv = function_exists('iconv');
     // ===	special cases for HTML entities to handle various PHP platforms
     // 'HTML-ENTITIES' is not a valid encoding for iconv, so transcode manually
     if ($this->toEncoding == 'HTML-ENTITIES' && !$mbstring) {
         if (strtoupper($this->fromEncoding) == 'UTF-8') {
             return String::utf2html($string);
             // NB: this will return all numeric entities
         } else {
             // NB: old PHP versions may have issues with htmlentities()
             if ($string == html_entity_decode($string, ENT_COMPAT, $this->fromEncoding)) {
                 return htmlentities($string, ENT_COMPAT, $this->fromEncoding);
             } else {
                 return $string;
             }
         }
     } elseif ($this->fromEncoding == 'HTML-ENTITIES' && !$mbstring) {
         if (strtoupper($this->toEncoding) == 'UTF-8') {
             // use built-in transcoding to UTF8
             return String::html2utf($string);
         } else {
             // NB: old PHP versions may have issues with html_entity_decode()
             return html_entity_decode($string, ENT_COMPAT, $this->toEncoding);
         }
         // === end special cases for HTML entities
     } elseif ($this->translit == true && $iconv) {
         // use the iconv library to transliterate
         return iconv($this->fromEncoding, $this->toEncoding . '//TRANSLIT', $string);
     } elseif ($this->translit == true && $this->fromEncoding == "UTF-8" && $this->toEncoding == "ASCII") {
         // transliterate using built-in mapping
         return String::html2utf(String::html2ascii(String::utf2html($string)));
         // === end special cases for transliteration
     } elseif ($mbstring) {
         // use the multibyte library to transcode (no transliteration)
         // this call semantic uses backwards-compatible by-reference for better reliability
         return call_user_func_array('mb_convert_encoding', array(&$string, $this->toEncoding, $this->fromEncoding));
     } elseif ($iconv) {
         // use the iconv library to transcode
         return iconv($this->fromEncoding, $this->toEncoding . '//IGNORE', $string);
     } else {
         // fail gracefully by returning the original string unchanged
         return $string;
     }
 }
示例#4
0
 /**
  * Sanitize a variable.
  * Removes leading and trailing whitespace, normalizes all characters to UTF-8.
  * @param $var string
  * @return string
  */
 function cleanVar($var)
 {
     // only normalize strings that are not UTF-8 already, and when the system is using UTF-8
     if (Config::getVar('i18n', 'charset_normalization') == 'On' && strtolower(Config::getVar('i18n', 'client_charset')) == 'utf-8' && !String::utf8_is_valid($var)) {
         $var = String::utf8_normalize($var);
         // convert HTML entities into valid UTF-8 characters (do not transcode)
         if (checkPhpVersion('5.0.0')) {
             $var = html_entity_decode($var, ENT_COMPAT, 'UTF-8');
         } else {
             $var = String::html2utf($var);
         }
         // strip any invalid UTF-8 sequences
         $var = String::utf8_bad_strip($var);
         // re-encode special HTML characters
         if (checkPhpVersion('5.2.3')) {
             $var = htmlspecialchars($var, ENT_NOQUOTES, 'UTF-8', false);
         } else {
             $var = htmlspecialchars($var, ENT_NOQUOTES, 'UTF-8');
         }
     }
     // strip any invalid ASCII control characters
     $var = String::utf8_strip_ascii_ctrl($var);
     return trim($var);
 }
 /**
  * Replace HTML "newline" tags (p, li, br) with line feeds. Strip all other tags.
  * @param $html String Input HTML string
  * @return String Text with replaced and stripped HTML tags
  */
 function _html2text($html)
 {
     $html = String::regexp_replace('/<[\\/]?p>/', chr(13) . chr(10), $html);
     $html = String::regexp_replace('/<li>/', '&bull; ', $html);
     $html = String::regexp_replace('/<\\/li>/', chr(13) . chr(10), $html);
     $html = String::regexp_replace('/<br[ ]?[\\/]?>/', chr(13) . chr(10), $html);
     $html = String::html2utf(strip_tags($html));
     return $html;
 }
示例#6
0
 /**
  * Blind CC the reviews to reviewers.
  * @param $paper object
  * @param $send boolean
  * @param $inhibitExistingEmail boolean
  * @return boolean true iff ready for redirect
  */
 function blindCcReviewsToReviewers($paper, $send = false, $inhibitExistingEmail = false)
 {
     $commentDao =& DAORegistry::getDAO('PaperCommentDAO');
     $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
     $userDao =& DAORegistry::getDAO('UserDAO');
     $conference =& Request::getConference();
     $comments =& $commentDao->getPaperComments($paper->getId(), COMMENT_TYPE_DIRECTOR_DECISION);
     $reviewAssignments =& $reviewAssignmentDao->getReviewAssignmentsByPaperId($paper->getId(), $paper->getCurrentStage());
     $commentsText = "";
     foreach ($comments as $comment) {
         $commentsText .= String::html2utf(strip_tags($comment->getComments())) . "\n\n";
     }
     $user =& Request::getUser();
     import('mail.PaperMailTemplate');
     $email = new PaperMailTemplate($paper, 'SUBMISSION_DECISION_REVIEWERS');
     if ($send && !$email->hasErrors() && !$inhibitExistingEmail) {
         HookRegistry::call('TrackDirectorAction::blindCcReviewsToReviewers', array(&$paper, &$reviewAssignments, &$email));
         $email->send();
         return true;
     } else {
         if ($inhibitExistingEmail || !Request::getUserVar('continued')) {
             $email->clearRecipients();
             foreach ($reviewAssignments as $reviewAssignment) {
                 if ($reviewAssignment->getDateCompleted() != null && !$reviewAssignment->getCancelled()) {
                     $reviewer =& $userDao->getUser($reviewAssignment->getReviewerId());
                     if (isset($reviewer)) {
                         $email->addBcc($reviewer->getEmail(), $reviewer->getFullName());
                     }
                 }
             }
             $paramArray = array('comments' => $commentsText, 'editorialContactSignature' => $user->getContactSignature());
             $email->assignParams($paramArray);
         }
         $email->displayEditForm(Request::url(null, null, null, 'blindCcReviewsToReviewers'), array('paperId' => $paper->getId()));
         return false;
     }
 }
示例#7
0
 /**
  * Email editor decision comment.
  * @param $sectionEditorSubmission object
  * @param $send boolean
  */
 function emailEditorDecisionComment($sectionEditorSubmission, $send)
 {
     $userDao =& DAORegistry::getDAO('UserDAO');
     $articleCommentDao =& DAORegistry::getDAO('ArticleCommentDAO');
     $sectionEditorSubmissionDao =& DAORegistry::getDAO('SectionEditorSubmissionDAO');
     $journal =& Request::getJournal();
     $user =& Request::getUser();
     import('mail.ArticleMailTemplate');
     $email =& new ArticleMailTemplate($sectionEditorSubmission);
     $copyeditor =& $sectionEditorSubmission->getCopyeditor();
     if ($send && !$email->hasErrors()) {
         HookRegistry::call('SectionEditorAction::emailEditorDecisionComment', array(&$sectionEditorSubmission, &$send));
         $email->send();
         $decisions = $sectionEditorSubmission->getDecisions();
         $decisions = array_pop($decisions);
         // Rounds
         $decision = array_pop($decisions);
         if ($decision && $decision['decision'] == SUBMISSION_EDITOR_DECISION_DECLINE) {
             // If the most recent decision was a decline,
             // sending this email archives the submission.
             $sectionEditorSubmission->setStatus(STATUS_ARCHIVED);
             $sectionEditorSubmission->stampStatusModified();
             $sectionEditorSubmissionDao->updateSectionEditorSubmission($sectionEditorSubmission);
         }
         $articleComment =& new ArticleComment();
         $articleComment->setCommentType(COMMENT_TYPE_EDITOR_DECISION);
         $articleComment->setRoleId(Validation::isEditor() ? ROLE_ID_EDITOR : ROLE_ID_SECTION_EDITOR);
         $articleComment->setArticleId($sectionEditorSubmission->getArticleId());
         $articleComment->setAuthorId($sectionEditorSubmission->getUserId());
         $articleComment->setCommentTitle($email->getSubject());
         $articleComment->setComments($email->getBody());
         $articleComment->setDatePosted(Core::getCurrentDate());
         $articleComment->setViewable(true);
         $articleComment->setAssocId($sectionEditorSubmission->getArticleId());
         $articleCommentDao->insertArticleComment($articleComment);
         return true;
     } else {
         if (!Request::getUserVar('continued')) {
             $authorUser =& $userDao->getUser($sectionEditorSubmission->getUserId());
             $authorEmail = $authorUser->getEmail();
             $email->addRecipient($authorEmail, $authorUser->getFullName());
             if ($journal->getSetting('notifyAllAuthorsOnDecision')) {
                 foreach ($sectionEditorSubmission->getAuthors() as $author) {
                     if ($author->getEmail() != $authorEmail) {
                         $email->addCc($author->getEmail(), $author->getFullName());
                     }
                 }
             }
         } else {
             if (Request::getUserVar('importPeerReviews')) {
                 $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
                 $reviewAssignments =& $reviewAssignmentDao->getReviewAssignmentsByArticleId($sectionEditorSubmission->getArticleId(), $sectionEditorSubmission->getCurrentRound());
                 $reviewIndexes =& $reviewAssignmentDao->getReviewIndexesForRound($sectionEditorSubmission->getArticleId(), $sectionEditorSubmission->getCurrentRound());
                 $body = '';
                 foreach ($reviewAssignments as $reviewAssignment) {
                     // If the reviewer has completed the assignment, then import the review.
                     if ($reviewAssignment->getDateCompleted() != null && !$reviewAssignment->getCancelled()) {
                         // Get the comments associated with this review assignment
                         $articleComments =& $articleCommentDao->getArticleComments($sectionEditorSubmission->getArticleId(), COMMENT_TYPE_PEER_REVIEW, $reviewAssignment->getReviewId());
                         $body .= "------------------------------------------------------\n";
                         $body .= Locale::translate('submission.comments.importPeerReviews.reviewerLetter', array('reviewerLetter' => chr(ord('A') + $reviewIndexes[$reviewAssignment->getReviewId()]))) . "\n";
                         if (is_array($articleComments)) {
                             foreach ($articleComments as $comment) {
                                 // If the comment is viewable by the author, then add the comment.
                                 if ($comment->getViewable()) {
                                     $body .= String::html2utf(strip_tags($comment->getComments())) . "\n\n";
                                 }
                             }
                         }
                         $body .= "------------------------------------------------------\n\n";
                     }
                 }
                 $oldBody = $email->getBody();
                 if (!empty($oldBody)) {
                     $oldBody .= "\n";
                 }
                 $email->setBody($oldBody . $body);
             }
         }
         $email->displayEditForm(Request::url(null, null, 'emailEditorDecisionComment', 'send'), array('articleId' => $sectionEditorSubmission->getArticleId()), 'submission/comment/editorDecisionEmail.tpl', array('isAnEditor' => true));
         return false;
     }
 }