예제 #1
0
 /**
  * Initializes the application component.
  *
  * @return null
  */
 public function init()
 {
     parent::init();
     // Import this here to ensure that libs like SimplePie are using our version of the class and not any server's
     // random version.
     require_once Craft::getPathOfAlias('app.vendor.simplepie.simplepie.idn.') . DIRECTORY_SEPARATOR . 'idna_convert.class.php';
 }
 /**
  * Looks for a missing translation string in Yii's core translations.
  *
  * @param \CMissingTranslationEvent $event
  *
  * @return null
  */
 public static function findMissingTranslation(\CMissingTranslationEvent $event)
 {
     // Look for translation file from most to least specific.  So nl_nl.php gets checked before nl.php, for example.
     $translationFiles = array();
     $parts = explode('_', $event->language);
     $totalParts = count($parts);
     for ($i = 1; $i <= $totalParts; $i++) {
         $translationFiles[] = implode('_', array_slice($parts, 0, $i));
     }
     $translationFiles = array_reverse($translationFiles);
     // First see if we have any cached info.
     foreach ($translationFiles as $translationFile) {
         // We've loaded the translation file already, just check for the translation.
         if (isset(static::$_translations[$translationFile])) {
             if (isset(static::$_translations[$translationFile][$event->message])) {
                 $event->message = static::$_translations[$translationFile][$event->message];
             }
             // No translation... just give up.
             return;
         }
     }
     // No luck in cache, check the file system.
     $frameworkMessagePath = IOHelper::normalizePathSeparators(Craft::getPathOfAlias('app.framework.messages'));
     foreach ($translationFiles as $translationFile) {
         $path = $frameworkMessagePath . $translationFile . '/yii.php';
         if (IOHelper::fileExists($path)) {
             // Load it up.
             static::$_translations[$translationFile] = (include $path);
             if (isset(static::$_translations[$translationFile][$event->message])) {
                 $event->message = static::$_translations[$translationFile][$event->message];
                 return;
             }
         }
     }
 }
 public function __construct()
 {
     require_once Craft::getPathOfAlias('system.vendors.htmlpurifier') . '/HTMLPurifier.standalone.php';
     $whitelist = EmbeddedAssetsPlugin::getWhitelist();
     foreach ($whitelist as $i => $url) {
         $whitelist[$i] = preg_quote($url);
     }
     $regexp = '%^(https?:)?//([a-z0-9\\-]+\\.)?(' . implode('|', $whitelist) . ')([:/].*)?$%';
     $config = \HTMLPurifier_Config::createDefault();
     $config->set('HTML.SafeIframe', true);
     $config->set('URI.SafeIframeRegexp', $regexp);
     $config->set('Cache.SerializerPath', \Yii::app()->getRuntimePath());
     $this->_purifier = new \HTMLPurifier($config);
 }
예제 #4
0
 /**
  * Sets the Content-Type header based on a file extension.
  *
  * @param string $extension
  *
  * @return bool Whether setting the header was successful.
  */
 public static function setContentTypeByExtension($extension)
 {
     $extension = strtolower($extension);
     $mimeTypes = (require Craft::getPathOfAlias('app.framework.utils.mimeTypes') . '.php');
     if (!isset($mimeTypes[$extension])) {
         Craft::log('Tried to set the header mime type for the extension ' . $extension . ', but could not find in the mimeTypes list.', LogLevel::Warning);
         return false;
     }
     $mimeType = $mimeTypes[$extension];
     if (static::setHeader(array('Content-Type' => $mimeType . '; charset=utf-8'))) {
         // Save the MIME type for getMimeType()
         static::$_mimeType = $mimeType;
         return true;
     } else {
         return false;
     }
 }
예제 #5
0
 /**
  * Attempts to convert a string to UTF-8 and clean any non-valid UTF-8 characters.
  *
  * @param      $string
  *
  * @return bool|string
  */
 public static function convertToUTF8($string)
 {
     // Don't wrap in a class_exists in case the server already has it's own version of HTMLPurifier and they have
     // open_basedir restrictions
     require_once Craft::getPathOfAlias('system.vendors.htmlpurifier') . '/HTMLPurifier.standalone.php';
     // If it's already a UTF8 string, just clean and return it
     if (static::isUTF8($string)) {
         return \HTMLPurifier_Encoder::cleanUTF8($string);
     }
     // Otherwise set HTMLPurifier to the actual string encoding
     $config = \HTMLPurifier_Config::createDefault();
     $config->set('Core.Encoding', static::getEncoding($string));
     // Clean it
     $string = \HTMLPurifier_Encoder::cleanUTF8($string);
     // Convert it to UTF8 if possible
     if (static::checkForIconv()) {
         $string = \HTMLPurifier_Encoder::convertToUTF8($string, $config, null);
     } else {
         $encoding = static::getEncoding($string);
         $string = mb_convert_encoding($string, 'utf-8', $encoding);
     }
     return $string;
 }
예제 #6
0
 /**
  * @return string
  */
 public function getTemplate()
 {
     return file_get_contents(Craft::getPathOfAlias('app.etc.updates.migrationtemplate') . '.php');
 }