コード例 #1
0
 /**
  * @brief Retrieve the media server to use
  *
  * @param filename Name of the file to serve (acually, part of the path)
  *
  * @todo Check performences
  *
  * @return URL of the server to use.
  */
 public static function getMediaServer($filename, &$protocol = NULL)
 {
     if (!self::_isActive()) {
         return parent::getMediaServer($filename);
     }
     // Init the server list if needed
     if (!self::$_servers) {
         self::_initServers();
     }
     if (!self::$_activatedModule) {
         return parent::getMediaServer($filename);
     }
     // If there is a least one ALL server, then use one of them
     if (self::$_serversCount[CLOUDCACHE_FILE_TYPE_ALL]) {
         $server = self::$_servers[CLOUDCACHE_FILE_TYPE_ALL][abs(crc32($filename)) % self::$_serversCount[CLOUDCACHE_FILE_TYPE_ALL]];
         if ($protocol) {
             $protocol = $server['protocol'];
         }
         return $server['url'];
     }
     // If there is servers, then use them
     if (self::$_totalServerCount) {
         // Loop on the file types to find the current one
         foreach (self::$_fileTypes as $type) {
             // If we find the type in the filename, then it is our
             if (strstr($filename, $type) && self::$_serversCount[$type]) {
                 // Return one of those server
                 $server = self::$_servers[$type][abs(crc32($filename)) % self::$_serversCount[$type]];
                 if ($protocol) {
                     $protocol = $server['protocol'];
                 }
                 return $server['url'];
             }
         }
         // If no file type found, then it is 'other'
         // If there is server setted for the 'other' type, use it
         if (self::$_serversCount[CLOUDCACHE_FILE_TYPE_OTHER]) {
             // Return one of the server setted up
             $server = self::$_servers[$type][abs(crc32($filename)) % self::$_serversCount[$type]];
             if ($protocol) {
                 $protocol = $server['protocol'];
             }
             return $server['url'];
         }
     }
     // If there is no server setted up, then use the parent method
     return parent::getMediaServer($filename);
 }