예제 #1
0
 /**
  * convert text to different variants of a language. the automatic
  * conversion is done in autoConvert(). here we parse the text
  * marked with -{}-, which specifies special conversions of the
  * text that can not be accomplished in autoConvert()
  *
  * syntax of the markup:
  * -{code1:text1;code2:text2;...}-  or
  * -{flags|code1:text1;code2:text2;...}-  or
  * -{text}- in which case no conversion should take place for text
  *
  * @param string $text text to be converted
  * @param bool $isTitle whether this conversion is for the article title
  * @return string converted text
  * @public
  */
 function convert($text, $isTitle = false)
 {
     $mw =& MagicWord::get('notitleconvert');
     if ($mw->matchAndRemove($text)) {
         $this->mDoTitleConvert = false;
     }
     $mw =& MagicWord::get('nocontentconvert');
     if ($mw->matchAndRemove($text)) {
         $this->mDoContentConvert = false;
     }
     // no conversion if redirecting
     $mw =& MagicWord::get('redirect');
     if ($mw->matchStart($text)) {
         return $text;
     }
     $plang = $this->getPreferredVariant();
     // for title convertion
     if ($isTitle) {
         return $this->convertTitle($text, $plang);
     }
     $tarray = StringUtils::explode($this->mMarkup['end'], $text);
     $text = '';
     $marks = array();
     foreach ($tarray as $txt) {
         $marked = explode($this->mMarkup['begin'], $txt, 2);
         if (array_key_exists(1, $marked)) {
             $crule = new ConverterRule($marked[1], $this);
             $crule->parse($plang);
             $marked[1] = $crule->getDisplay();
             $this->prepareManualConv($crule);
         } else {
             $marked[0] .= $this->mMarkup['end'];
         }
         array_push($marks, $marked);
     }
     $this->applyManualConv();
     foreach ($marks as $marked) {
         if ($this->mDoContentConvert) {
             $text .= $this->autoConvert($marked[0], $plang);
         } else {
             $text .= $marked[0];
         }
         if (array_key_exists(1, $marked)) {
             $text .= $marked[1];
         }
     }
     // Remove the last delimiter (wasn't real)
     $text = substr($text, 0, -strlen($this->mMarkup['end']));
     return $text;
 }
예제 #2
0
 /**
  * convert text to different variants of a language. the automatic
  * conversion is done in autoConvert(). here we parse the text
  * marked with -{}-, which specifies special conversions of the
  * text that can not be accomplished in autoConvert()
  *
  * syntax of the markup:
  * -{code1:text1;code2:text2;...}-  or
  * -{flags|code1:text1;code2:text2;...}-  or
  * -{text}- in which case no conversion should take place for text
  *
  * @param string $text text to be converted
  * @param bool $isTitle whether this conversion is for the article title
  * @return string converted text
  * @public
  */
 function convert($text, $isTitle = false)
 {
     $mw =& MagicWord::get('notitleconvert');
     if ($mw->matchAndRemove($text)) {
         $this->mDoTitleConvert = false;
     }
     $mw =& MagicWord::get('nocontentconvert');
     if ($mw->matchAndRemove($text)) {
         $this->mDoContentConvert = false;
     }
     // no conversion if redirecting
     $mw =& MagicWord::get('redirect');
     if ($mw->matchStart($text)) {
         return $text;
     }
     // for title convertion
     if ($isTitle) {
         return $this->convertTitle($text);
     }
     $plang = $this->getPreferredVariant();
     $tarray = StringUtils::explode($this->mMarkup['end'], $text);
     $text = '';
     $lastDelim = false;
     foreach ($tarray as $txt) {
         $marked = explode($this->mMarkup['begin'], $txt, 2);
         if ($this->mDoContentConvert) {
             $text .= $this->autoConvert($marked[0], $plang);
         } else {
             $text .= $marked[0];
         }
         if (array_key_exists(1, $marked)) {
             // strip the flags from syntax like -{T| ... }-
             $crule = new ConverterRule($marked[1], $this);
             $crule->parse($plang);
             $text .= $crule->getDisplay();
             $this->applyManualConv($crule);
             $lastDelim = false;
         } else {
             // Reinsert the }- which wasn't part of anything
             $text .= $this->mMarkup['end'];
             $lastDelim = true;
         }
     }
     if ($lastDelim) {
         // Remove the last delimiter (wasn't real)
         $text = substr($text, 0, -strlen($this->mMarkup['end']));
     }
     return $text;
 }