$cdn_url, 'url' => $cdn_url . $base_path . $path, ); } } return $servers; } //---------------------------------------------------------------------------- // Private functions. /** * Parse the raw (textual) mapping into a lookup table, where the key is the * file extension and the value is a list of CDN URLs that serve the file. * * @param $mapping_raw * A raw (textual) mapping. * @return * The corresponding mapping lookup table. */ function _cdn_basic_parse_raw_mapping($mapping_raw) { $mapping = array(); if (!empty($mapping_raw)) { $lines = preg_split("/[\n\r]+/", $mapping_raw, -1, PREG_SPLIT_NO_EMPTY); foreach ($lines as $line) { // Parse this line. It may or may not limit the CDN URL to a list of // file extensions. if (strpos($line, '|') !== FALSE) { $parts = explode('|', $line); $cdn_url = rtrim(trim($parts[0]), '/'); // Remove whitespace and a trailing slash. $extensions = explode(' ', trim(str_replace('.', '', $parts[1]))); // Remove periods, whitespace and split on ' '. } else { $cdn_url = trim($line); $extensions = array('*'); // Use the asterisk as a wildcard. } // Create the mapping lookup table. foreach ($extensions as $extension) { $mapping[$extension][] = $cdn_url; } } } return $mapping; }