http://www.fsf.org/ or write * to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * */ /* The media serializer takes a media file and serialize it as a strim to the browser. It is useful for example if you want to make the media hidden. You havo not to specify the file type, we can automatically handle every mime type using apache format mime file. */ include ("plugins/mediaserializer/configure.php"); Class CmsDam_MediaSerializer { var $conf; var $useful_mime_list; function CmsDam_MediaSerializer() { // Constructor $this->conf = new CmsDam_MediaSerializer_Conf; return true; } function CmsDam_MediaSerializer_stream($relpath) { // Serialize the media stream if (($relpath == "") || (strlen($relpath) == 0)) { return false; } $conf = $this->conf; if (!is_file($relpath)) { return false; } $ext = substr(strrchr($relpath, "."), 1); $mime = $this->CmsDam_MediaSerializer_mime_parser($conf, $ext); $contribH = fopen ($relpath, 'rb'); header ("Content-Type: " . $mime); header ("Content-Length: " . filesize($relpath)); $media = fread ($contribH, filesize($relpath)); fclose ($contribH); return $media; } function CmsDam_MediaSerializer_mime_parser($conf, $ext="__.__") { // MIME PARSER if ($ext == "__.__") { // Set the default extension return $conf->default_mime; } if (is_file($conf->mime_filename)) { // A media was requested, and the file exist $contribH = fopen ($conf->mime_filename, 'r'); while ($data = fgets ($contribH, $conf->max_line_lenght)) { $data = ereg_replace ("\t", " ", $data); $line = split(' ', $data); $fields = count ($line); if (($data) && ($fields > 0) && (substr(trim($data[0]), 0, 1)) && (substr(trim($data[0]), 0, 1) != "#")) { // Field useful for ($c=1; $c < $fields; $c++) { if (trim($line[$c]) != "") { // Line is good if ($ext == trim($line[$c])) { // We found it!! fclose ($contribH); return trim($line[0]); } } } } } fclose ($contribH); } // No mime found, return the default mime! return $conf->default_mime; } } $this->included->mediaserializer->api = new CmsDam_MediaSerializer; ?>