get_type() public method

Get the Content-Type of the specified file
public get_type ( ) : string
return string Actual Content-Type
 /**
  * Get the Content-Type of the specified file
  *
  * @access public
  * @return string Filtered content type 
  */
 function get_type()
 {
     $contentType = null;
     $charset = null;
     if (isset($this->file->headers['content-type'])) {
         if (!is_array($this->file->headers['content-type'])) {
             $this->file->headers['content-type'] = array($this->file->headers['content-type']);
         }
         foreach ($this->file->headers['content-type'] as $type) {
             $parts = array_map('trim', explode(";", $type, 2));
             if (isset($parts[1])) {
                 $type = $parts[0];
                 $charset = $parts[1];
             }
             if (preg_match('!(application|text)/((atom|rss|rdf)\\+)?xml!', $type, $ref)) {
                 $contentType = $ref[0];
             }
         }
         $outHeader = array();
         if (!is_null($contentType)) {
             $outHeader[] = $contentType;
         } else {
             $outHeader[] = 'text/xml';
             // Generic
         }
         if (!is_null($charset)) {
             $outHeader[] = $charset;
         }
         $this->file->headers['content-type'] = implode("; ", $outHeader);
     } else {
         // The default SimplePie behavior seems to be to return
         // text/plain if it can't find a Content-Type header.
         // The default SimplePie behavior sucks. Particularly
         // since SimplePie gets so draconian about Content-Type.
         // And since the WP SimplePie seems to drop Content-Type
         // from cached copies for some unfortunate reason.
         $this->file->headers['content-type'] = 'text/xml';
         // Generic
     }
     return parent::get_type();
 }
Esempio n. 2
0
 public static function checkFavicon($favicon)
 {
     if ($favicon === null || $favicon == false) {
         return false;
     }
     $file = new \SimplePie_File($favicon);
     // size in bytes
     $filesize = strlen($file->body);
     if ($file->success && $filesize > 0 && $filesize < 50000) {
         //bigger files are not considered favicons
         $sniffer = new \SimplePie_Content_Type_Sniffer($file);
         if (substr($sniffer->get_type(), 0, 6) === 'image/') {
             $imgsize = getimagesize($favicon);
             if ($imgsize['0'] <= 32 && $imgsize['1'] <= 32) {
                 //bigger images are not considered favicons
                 return true;
             }
         }
     }
     return false;
 }