/**
  * Parse the contents.
  *
  * @static
  * @param string $sContents
  * @param boolean $bIsDataUri Default: TRUE
  * @return string Contents
  */
 public static function init($sContents, $bIsDataUri = true)
 {
     $aEmoticons = static::gets();
     foreach ($aEmoticons as $sEmoticonKey => $aEmoticon) {
         if ($bIsDataUri) {
             $sContents = str_ireplace(static::getCode($aEmoticon), '<img src=\'' . Optimization::dataUri(static::getPath($sEmoticonKey)) . '\' alt=\'' . static::getName($aEmoticon) . '\' />', $sContents);
         } else {
             $sContents = str_ireplace(static::getCode($aEmoticon), '<img src=\'' . static::getUrl($sEmoticonKey) . '\' alt=\'' . static::getName($aEmoticon) . '\' />', $sContents);
         }
     }
     return $sContents;
 }
Example #2
0
 /**
  * Get the images in the CSS files.
  *
  * @return void
  */
 protected function getImgInCssFile()
 {
     preg_match_all('/url\\([\'"]*(.+?\\.)(gif|png|jpg|otf|ttf|woff)[\'"]*\\)/msi', $this->_sContents, $aHit, PREG_PATTERN_ORDER);
     for ($i = 0, $iCountHit = count($aHit[0]); $i < $iCountHit; $i++) {
         $imgPath = PH7_PATH_ROOT . $this->_sBaseUrl . $aHit[1][$i] . $aHit[2][$i];
         $imgUrl = PH7_URL_ROOT . $this->_sBaseUrl . $aHit[1][$i] . $aHit[2][$i];
         // If image-file exists and if file-size is lower than 24 KB
         $this->_sContents = $this->_bDataUri == true && is_file($imgPath) && $this->_oFile->size($imgPath) < 24000 ? str_replace($aHit[0][$i], 'url(' . Optimization::dataUri($imgPath) . ')', $this->_sContents) : str_replace($aHit[0][$i], 'url(' . $imgUrl . ')', $this->_sContents);
     }
 }