protected function getAcl($baseUrl, array $urls)
 {
     require_once dirname(__FILE__) . '/../../../../../../infra/general/kString.class.php';
     // strip the filenames of all urls
     foreach ($urls as &$url) {
         $slashPos = strrpos($url, '/');
         if ($slashPos !== false) {
             $url = substr($url, 0, $slashPos + 1);
         }
     }
     $acl = kString::getCommonPrefix($urls);
     // the first comma in csmil denotes the beginning of the non-common URL part
     $commaPos = strpos($acl, ',');
     if ($commaPos !== false) {
         $acl = substr($acl, 0, $commaPos);
     }
     // if the base url has a port, remove it
     $parsedUrl = parse_url($baseUrl);
     if (isset($parsedUrl['port'])) {
         $baseUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host'];
         if (isset($parsedUrl['path'])) {
             $baseUrl .= $parsedUrl['path'];
         }
     }
     $acl = $baseUrl . $acl . '*';
     return $acl;
 }
 protected function getAcl($baseUrl, array $urls)
 {
     require_once dirname(__FILE__) . '/../../../../../../infra/general/kString.class.php';
     // strip the filenames of all urls
     foreach ($urls as &$url) {
         $slashPos = strrpos($url, '/');
         if ($slashPos !== false) {
             $url = substr($url, 0, $slashPos + 1);
         }
     }
     $acl = kString::getCommonPrefix($urls);
     // the first comma in csmil denotes the beginning of the non-common URL part
     $commaPos = strpos($acl, ',');
     if ($commaPos !== false) {
         $acl = substr($acl, 0, $commaPos);
     }
     $acl = $baseUrl . $acl . '*';
     return $acl;
 }
 protected static function generateMultiUrl(array $flavors)
 {
     $urls = array();
     foreach ($flavors as $flavor) {
         $urls[] = $flavor['url'];
     }
     $urls = array_unique($urls);
     if (count($urls) == 1) {
         $baseUrl = reset($urls);
         return '/' . ltrim($baseUrl, '/');
     }
     $prefix = kString::getCommonPrefix($urls);
     $prefixLen = strlen($prefix);
     $postfix = kString::getCommonPostfix($urls);
     $postfixLen = strlen($postfix);
     $middlePart = ',';
     foreach ($urls as $url) {
         $middlePart .= substr($url, $prefixLen, strlen($url) - $prefixLen - $postfixLen) . ',';
     }
     $baseUrl = $prefix . $middlePart . $postfix;
     return '/' . ltrim($baseUrl, '/') . '.urlset';
 }
 /**
  * @param string $baseUrl
  * @param array $flavors
  */
 public function tokenizeMultiUrls(&$baseUrl, &$flavors)
 {
     if ($this->usePrefix) {
         //in case of a cached-in tokenizer - need to require bootstrap
         require_once dirname(__FILE__) . '/../../../../../../' . 'infra/general/kString.class.php';
         $strings = array();
         foreach ($flavors as $flavor) {
             $url = $flavor["url"];
             if (substr($url, 0, 4) == "mp4:") {
                 $url = substr($url, 4);
             }
             $strings[] = $url;
         }
         $prefix = kString::getCommonPrefix($strings);
         $pos = strrpos($prefix, "/");
         if ($pos) {
             //include slash sign in prefix substr
             $pos++;
             $prefix = substr($prefix, 0, $pos);
         }
     } else {
         $prefix = "";
         foreach ($flavors as $flavor) {
             $url = $flavor["url"];
             if (substr($url, 0, 4) == "mp4:") {
                 $url = substr($url, 4);
             }
             $prefix = $prefix . $url . ";";
         }
     }
     $factory = new StreamTokenFactory();
     $token = $factory->getToken($this->type, $prefix, null, $this->profile, $this->key, null, $this->window, null, null, null);
     $auth = "?auth=" . $token->getToken() . "&aifp={$this->aifp}&slist={$prefix}";
     $baseUrl .= $auth;
     foreach ($flavors as &$flavor) {
         $url = $flavor["url"];
         $flavor["url"] = $url . $auth;
     }
 }
 protected static function generateMultiUrl(array $flavors, entry $entry)
 {
     $urls = array();
     foreach ($flavors as $flavor) {
         $urls[] = $flavor['url'];
     }
     $urls = array_unique($urls);
     if (count($urls) == 1) {
         $baseUrl = reset($urls);
         return '/' . ltrim($baseUrl, '/');
     }
     $prefix = kString::getCommonPrefix($urls);
     $postfix = kString::getCommonPostfix($urls);
     if ($entry->getType() == entryType::PLAYLIST) {
         // in case of a playlist, need to merge the flavor params of the urls
         // instead of using a urlset, since nginx-vod does not support urlsets of
         // non-trivial mapping responses.
         // so instead of building:
         //		/p/123/serveFlavor/entryId/0_abc/flavorParamIds/100,1,2,3,/forceproxy/true/name/a.mp4.urlset
         // we build:
         //		/p/123/serveFlavor/entryId/0_abc/flavorParamIds/1001,1002,1003/forceproxy/true/name/a.mp4.urlset
         $prefix = substr($prefix, 0, strrpos($prefix, '/') + 1);
         $postfix = substr($postfix, strpos($postfix, '/'));
     }
     $prefixLen = strlen($prefix);
     $postfixLen = strlen($postfix);
     $middlePart = ',';
     foreach ($urls as $url) {
         $middlePart .= substr($url, $prefixLen, strlen($url) - $prefixLen - $postfixLen) . ',';
     }
     if ($entry->getType() == entryType::PLAYLIST && strpos($middlePart, '/') === false) {
         $middlePart = rtrim(ltrim($middlePart, ','), ',');
         $result = $prefix . $middlePart . $postfix;
     } else {
         $result = $prefix . $middlePart . $postfix . '.urlset';
     }
     return '/' . ltrim($result, '/');
 }
 /**
  * @param array $urls
  * @return string
  */
 protected function getAcl(array $urls)
 {
     require_once dirname(__FILE__) . '/../../../../../../infra/general/kString.class.php';
     $acl = kString::getCommonPrefix($urls);
     // the first comma in csmil denotes the beginning of the non-common URL part
     $commaPos = strpos($acl, ',');
     if ($commaPos !== false) {
         $acl = substr($acl, 0, $commaPos);
     }
     // don't sign the manifest file name when playing HLS/HDS via AkamaiHD
     $postfixes = $this->customPostfixes ? explode(',', $this->customPostfixes) : array('/master.m3u8', '/manifest.f4m');
     foreach ($postfixes as $postfix) {
         if (substr($acl, -strlen($postfix)) == $postfix) {
             $acl = substr($acl, 0, -strlen($postfix));
         }
     }
     if (!$acl) {
         return false;
     }
     $acl .= $this->aclPostfix;
     return $acl;
 }