Esempio n. 1
0
 /**
  * Return a story formatted for display.
  * 
  * The input story is ESCAPED before html tags are inserted for the formatting.
  * It is assumed strip_tags() was used previously. The returned string should not be escaped
  * again in the view template.
  * 
  * @param  String   $story
  * @param  String   $keyword
  * @param  Boolean  $bSubstituteLinks    True to show frame number references as links otherwise plain text.
  * @return String
  */
 public static function getFormattedStory($story, $keyword, $bSubstituteLinks = true)
 {
     // Links helper is used by getFormattedKanjiLink() call
     coreToolkit::loadHelpers(array('Tag', 'Url'));
     // minimal punctuation : upper case first beginning of text
     $s = phpToolkit::mb_ucfirst($story);
     //echo error_reporting();exit;
     // minimal punctuation : end sentence with dot.
     if (preg_match('/[^.!?]$/', $s)) {
         $s = $s . '.';
     }
     // remove extra spaces
     $s = preg_replace('/\\s\\s+/u', ' ', $s);
     // format mnemonic keyword if keyword is found within text
     $keywords = explode(rtkBook::EDITION_SEPARATOR, $keyword);
     if (count($keywords) > 1) {
         // use 4th edition keyword if multiple edition keyword
         $keyword = $keywords[1];
     }
     // remove trailing '?' or '...'
     $keyword = preg_replace('/\\s*\\.\\.\\.$|\\s*\\?$/', '', $keyword);
     // fixes highlighting keywords like "lead (metal)" or "abyss [old]"
     if (strstr($keyword, '(')) {
         $keyword = preg_replace('/\\s+\\([^\\)]+\\)/', '', $keyword);
     }
     if (strstr($keyword, '[')) {
         $keyword = preg_replace('/\\s+\\[[^\\]]+\\]/', '', $keyword);
     }
     if (strlen($keyword) == 1) {
         $keyword = $keyword . '($|\\s+)';
     }
     // escape text before adding html tags, replace the single quotes with another
     // special character because the escaping uses htmlspecialchars() inserts '
     // and then the '#' character is matched by another regexp as the #keyword# marker
     $s = str_replace('\'', '`', $s);
     $s = escape_once($s);
     $s = preg_replace('/(^|\\s+)(' . $keyword . ')/i', '<strong>$1$2</strong>', $s);
     // format mnemonic #keyword#
     $s = preg_replace('/#([^#]+)#/ui', '<strong>$1</strong>', $s);
     // format mnemonic *primitives*
     $s = preg_replace('/\\*([^\\*]+)\\*/ui', '<em>$1</em>', $s);
     //    $s = preg_replace("/{([0-9]+)}/", "<a href=\"?framenum=$1\">frame $1</a>", $s);
     if ($bSubstituteLinks) {
         $s = preg_replace_callback('/{([0-9]+)}/', array('StoriesPeer', 'getFormattedKanjiLink'), $s);
     } else {
         $s = preg_replace_callback('/{([0-9]+)}/', create_function('$matches', 'return sprintf("<em>%s</em> (FRAME %d)", KanjisPeer::getKeyword($matches[1]), $matches[1]);'), $s);
     }
     // Now restore the single quotes (as escaped single quotes)
     $s = str_replace('`', '&#039;', $s);
     return $s;
 }
Esempio n. 2
0
 /**
  * 
  *
  */
 public function executeIndex($request)
 {
     list($year, $month) = phpToolkit::array_splice_values($request->getParameterHolder()->getAll(), array('year', 'month'));
     if (!$year) {
         $this->newsPosts = SitenewsPeer::getMostRecentPosts();
         $this->title = 'News Archive <span>&raquo; Latest News</span>';
     } else {
         if ($month >= 1 && $month <= 12) {
             $this->newsPosts = SitenewsPeer::getPostsByDate($year, $month);
             coreToolkit::loadHelpers('Date');
             $this->selection = format_date(mktime(0, 0, 0, $month, 1, $year), "F Y");
             $this->title = 'News for ' . $this->selection;
         } else {
             $this->forward404();
         }
     }
 }