00001 <?php 00020 $__Z__isRouter = true; 00021 include_once('config.php'); 00022 $__Z__ContentPath = ''; 00023 if(!$GLOBALS['prjName'] = url_segment(0)){ 00024 exit('No Project Name Given'); 00025 } 00026 if(!$contentType = url_segment(1)){ 00027 exit('No Content Type Given'); 00028 } 00029 if(!$filePath = url_segment(2)){ 00030 exit('No File Path Given'); 00031 } 00032 $filePath = ''; 00033 $urlParts = url_segment(); 00034 for($i=2;$i<count($urlParts);$i++){ 00035 $filePath .= "/".$urlParts[$i]; 00036 } 00043 class mediaRouter extends zCore{ 00052 function getMimeType($extension){ 00053 $mime = parse_ini_file(ZIGSETTINGS.DRS.'mime.types.ini.php'); 00054 if(!isset($mime[$extension])){ 00055 return mime_content_type($mime[$extension]); 00056 }else{ 00057 return $mime[$extension]; 00058 } 00059 } 00065 function defineSharedPaths(){ 00066 $dummyBin = parse_ini_file(ZIGSETTINGS.DRS.'mime.types.ini.php', true); 00067 foreach($dummyBin['flag'] as $defKey => $defVal){ 00068 if(!defined($defKey))define($defKey, $defVal); 00069 } 00070 } 00077 function determineSharedPath(){ 00078 switch($GLOBALS['contentType']){ 00079 case ZIG_ROUTE_FLAG_UPLOAD: 00080 return Z_DIR_TRANS_UP; 00081 break; 00082 case ZIG_ROUTE_FLAG_DOWNLOAD: 00083 return Z_DIR_TRANS_DN; 00084 break; 00085 case ZIG_ROUTE_FLAG_PIX: 00086 return Z_DIR_IMG; 00087 break; 00088 case ZIG_ROUTE_FLAG_JS: 00089 return Z_DIR_JS; 00090 break; 00091 case ZIG_ROUTE_FLAG_VBS: 00092 return Z_DIR_VBS; 00093 break; 00094 case ZIG_ROUTE_FLAG_CSS: 00095 return Z_DIR_CSS; 00096 break; 00097 case ZIG_ROUTE_FLAG_AJX_JS: 00098 return Z_DIR_AJX_C; 00099 break; 00100 default: 00101 perror('<code>zigmoyd.SharedContent.route</code>Invalid Type '.$GLOBALS['contentType']); 00102 } 00103 } 00110 function locateSharedPath(){ 00111 $path = ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.fstab_getProjectDirByName($GLOBALS['prjName']).DRS.mediaRouter::determineSharedPath().$GLOBALS['filePath']; 00112 return $path; 00113 } 00119 function sendContentType(){ 00120 if(!headers_sent()){ 00121 header('Content-Type: '.mediaRouter::getMimeType(pathinfo($GLOBALS['filePath'], PATHINFO_EXTENSION))); 00122 }else{ 00123 perror("<code>zigmoyd.shared.Router</code><br />Failed to sent Content Type as HEADER ALREADY SENT"); 00124 zLogger::error("failed To Send Mime Type as Header already sent", 'shared.Router'); 00125 } 00126 } 00132 function send404(){ 00133 header('HTTP/1.0 404 Not Found'); 00134 } 00141 function readFile(){ 00142 global $__Z__ContentPath; 00143 $sharedPath = mediaRouter::locateSharedPath(); 00144 if(!file_exists($sharedPath)){ 00145 mediaRouter::send404(); 00146 zLogger::error('File '.$sharedPath.' doesn\'t exists', 'shared.router'); 00147 perror('File '.$sharedPath.' doesn\'t exists'); 00148 }else{ 00149 if(!is_readable($sharedPath)){ 00150 mediaRouter::send404(); 00151 zLogger::error('File '.$sharedPath.' is not readable Plese Check the permission', 'shared.router'); 00152 perror('File '.$GLOBALS['filePath'].' is not readable Plese Check the permission'); 00153 }else{ 00154 mediaRouter::sendContentType(); 00155 $__Z__ContentPath = $sharedPath; 00156 if(strstr(mediaRouter::getMimeType(pathinfo($GLOBALS['filePath'], PATHINFO_EXTENSION)), "text")){ 00157 return include($__Z__ContentPath); 00158 }else{ 00159 return readfile($__Z__ContentPath); 00160 } 00161 } 00162 } 00163 return false; 00164 } 00170 function doRoute(){ 00171 mediaRouter::defineSharedPaths(); 00172 return mediaRouter::readFile(); 00173 } 00174 } 00175 mediaRouter::doRoute(); 00176 zLogger::debug("Serverd Content $__Z__ContentPath Successfully", 'zigmoyd.logger.end'); 00177 ?>