Example #1
0
 /**
  * Takes the human-readable URL of an embeddable resource and converts it into an
  * Oembed_Result descriptor (which contains a full Oembed resource URL).
  *
  * @param $url Human-readable URL
  * @param $type ?
  * @param $options array Options to be used for constructing the resulting descriptor.
  * @returns Oembed_Result/bool An Oembed descriptor, or false
  */
 public static function get_oembed_from_url($url, $type = false, array $options = array())
 {
     if (!self::is_enabled()) {
         return false;
     }
     // Find or build the Oembed URL.
     $endpoint = self::find_endpoint($url);
     $oembedUrl = false;
     if (!$endpoint) {
         if (self::get_autodiscover()) {
             $oembedUrl = self::autodiscover_from_url($url);
         }
     } elseif ($endpoint === true) {
         $oembedUrl = self::autodiscover_from_url($url);
     } else {
         // Build the url manually - we gave all needed information.
         $oembedUrl = Controller::join_links($endpoint, '?format=json&url=' . rawurlencode($url));
     }
     // If autodescovery failed the resource might be a direct link to a file
     if (!$oembedUrl) {
         if (File::get_app_category(File::get_file_extension($url)) == "image") {
             return new Oembed_Result($url, $url, $type, $options);
         }
     }
     if ($oembedUrl) {
         // Inject the options into the Oembed URL.
         if ($options) {
             if (isset($options['width']) && !isset($options['maxwidth'])) {
                 $options['maxwidth'] = $options['width'];
             }
             if (isset($options['height']) && !isset($options['maxheight'])) {
                 $options['maxheight'] = $options['height'];
             }
             $oembedUrl = Controller::join_links($oembedUrl, '?' . http_build_query($options, '', '&'));
         }
         return new Oembed_Result($oembedUrl, $url, $type, $options);
     }
     // No matching Oembed resource found.
     return false;
 }
 /**
  * Category name
  *
  * @return string
  */
 public function appCategory()
 {
     if ($this->file) {
         return $this->file->appCategory();
     } else {
         return File::get_app_category($this->getExtension());
     }
 }
Example #3
0
 /**
  * Returns a category based on the file extension.
  *
  * This function is  meant to mimic the equivalent for File.
  *
  * @return String
  */
 public function appCategory()
 {
     return File::get_app_category($this->getExtension());
 }
 /**
  * @return mixed|null
  */
 public function Icon()
 {
     $ext = strtolower($this->Format);
     if (!Director::fileExists(FRAMEWORK_DIR . "/images/app_icons/{$ext}_32.gif")) {
         $ext = File::get_app_category($ext);
     }
     if (!Director::fileExists(FRAMEWORK_DIR . "/images/app_icons/{$ext}_32.gif")) {
         $ext = "generic";
     }
     return FRAMEWORK_DIR . "/images/app_icons/{$ext}_32.gif";
 }
 /**
  * Get maximum file size for all or specified file extension.
  *
  * @param string $ext
  * @return int Filesize in bytes
  */
 public function getAllowedMaxFileSize($ext = null)
 {
     // Check if there is any defined instance max file sizes
     if (empty($this->allowedMaxFileSize)) {
         // Set default max file sizes if there isn't
         $fileSize = Config::inst()->get('Upload_Validator', 'default_max_file_size');
         if (isset($fileSize)) {
             $this->setAllowedMaxFileSize($fileSize);
         } else {
             // When no default is present, use maximum set by PHP
             $maxUpload = File::ini2bytes(ini_get('upload_max_filesize'));
             $maxPost = File::ini2bytes(ini_get('post_max_size'));
             $this->setAllowedMaxFileSize(min($maxUpload, $maxPost));
         }
     }
     $ext = strtolower($ext);
     if ($ext) {
         if (isset($this->allowedMaxFileSize[$ext])) {
             return $this->allowedMaxFileSize[$ext];
         }
         $category = File::get_app_category($ext);
         if ($category && isset($this->allowedMaxFileSize['[' . $category . ']'])) {
             return $this->allowedMaxFileSize['[' . $category . ']'];
         }
         return false;
     } else {
         return isset($this->allowedMaxFileSize['*']) ? $this->allowedMaxFileSize['*'] : false;
     }
 }
Example #6
0
 /**
  * Return the relative URL of an icon for the file type,
  * based on the {@link appCategory()} value.
  * Images are searched for in "dms/images/app_icons/".
  *
  * @return String
  */
 function Icon($ext)
 {
     if (!Director::fileExists(DMS_DIR . "/images/app_icons/{$ext}_32.png")) {
         $ext = File::get_app_category($ext);
     }
     if (!Director::fileExists(DMS_DIR . "/images/app_icons/{$ext}_32.png")) {
         $ext = "generic";
     }
     return DMS_DIR . "/images/app_icons/{$ext}_32.png";
 }
 /**
  * @dataProvider allowedExtensions
  * @param string $extension
  */
 public function testAllFilesHaveCategory($extension)
 {
     $this->assertNotEmpty(File::get_app_category($extension), "Assert that extension {$extension} has a valid category");
 }