public function __callbackConvertToWpUrlString(tubepress_api_url_UrlInterface $url)
 {
     if ($url->isAbsolute()) {
         return $url->toString();
     }
     if (!isset($this->_urlCache)) {
         $this->_urlCache = new tubepress_internal_collection_Map();
         $this->_urlCache->put('url.base', rtrim($this->_environment->getBaseUrl()->toString(), '/'));
         $this->_urlCache->put('url.user', rtrim($this->_environment->getUserContentUrl()->toString(), '/'));
         $this->_urlCache->put('basename', basename(TUBEPRESS_ROOT));
     }
     $urlAsString = $url->toString();
     $tubePressBaseUrl = $this->_urlCache->get('url.base');
     $userContentUrl = $this->_urlCache->get('url.user');
     $baseName = $this->_urlCache->get('basename');
     $isSystem = false;
     if ($this->_stringUtils->startsWith($urlAsString, "{$tubePressBaseUrl}/web/")) {
         $isSystem = true;
     } else {
         if (!$this->_stringUtils->startsWith($urlAsString, "{$userContentUrl}/")) {
             //this should never happen
             return $urlAsString;
         }
     }
     if ($isSystem) {
         $path = str_replace($tubePressBaseUrl, '', $urlAsString);
         return $this->_wpFunctions->plugins_url($path, "{$baseName}/tubepress.php");
     }
     $path = str_replace($userContentUrl, '', $urlAsString);
     return $this->_wpFunctions->content_url('tubepress-content' . $path);
 }
 private function _maybeRemoveLeadingPL($originalValue)
 {
     if (!$this->_stringUtils->startsWith($originalValue, 'PL')) {
         return $originalValue;
     }
     return $this->_stringUtils->replaceFirst('PL', '', $originalValue);
 }
 /**
  * {@inheritdoc}
  */
 public function wantsToAuthorizeRequest(tubepress_api_http_message_RequestInterface $request)
 {
     $url = $request->getUrl();
     if ($url->getHost() !== 'api.vimeo.com') {
         return false;
     }
     $path = $url->getPath();
     $oauthPath = $this->_stringUtils->startsWith($path, '/oauth');
     return !$oauthPath;
 }
 public function transform($incoming)
 {
     if ($this->_looksLikeDailymotionVideoId($incoming)) {
         //looks like a valid video ID
         return $incoming;
     }
     // x2xv8yy_description
     if (preg_match_all('~^[a-z0-9]+_.+$~', $incoming, $matches) === 1) {
         $exploded = explode('_', $incoming);
         return $exploded[0];
     }
     $incoming = trim($incoming, '/');
     /*
      * Might be
      *
      * 1. http://www.dailymotion.com/video/videoid
      * 2. http://www.dailymotion.com/video/videoid_description
      */
     try {
         $url = $this->_urlFactory->fromString($incoming);
         $host = $url->getHost();
         $path = $url->getPath();
         if (!$this->_stringUtils->endsWith($host, 'dailymotion.com')) {
             return null;
         }
         if (!$this->_stringUtils->startsWith($path, '/video/') && !$this->_stringUtils->startsWith($path, '/hub/')) {
             return null;
         }
         $one = 1;
         $path = str_replace(array('/video/', '/hub/'), '', $path, $one);
         $exploded = explode('_', $path);
         $videoId = $exploded[0];
         $error = !$this->_looksLikeDailymotionVideoId($videoId);
         if ($error) {
             return null;
         }
         return $videoId;
     } catch (InvalidArgumentException $e) {
         //invalid URL
         return null;
     }
 }
 private function _maybeConvertUrl($originalValue, $pathSegment)
 {
     $url = null;
     try {
         $url = $this->_urlFactory->fromString($originalValue);
     } catch (Exception $e) {
         return $originalValue;
     }
     $host = $url->getHost();
     if (!$this->_stringUtils->endsWith($host, 'vimeo.com')) {
         return $originalValue;
     }
     $path = $url->getPath();
     $pathStartsWithSegment = $this->_stringUtils->startsWith($path, '/' . $pathSegment);
     if (!$pathStartsWithSegment) {
         return $originalValue;
     }
     $explodedPath = preg_split('~/~', $path);
     if (count($explodedPath) < 3) {
         return $originalValue;
     }
     return $explodedPath[2];
 }
 /**
  * @param tubepress_spi_options_ui_FieldProviderInterface[] $multiSourceFieldProviders
  *
  * @return array
  */
 private function _sortMultisourceFieldProviders(array $multiSourceFieldProviders)
 {
     $toReturn = array();
     $addedIds = array();
     foreach (self::$_providerSortMap as $providerId) {
         foreach ($multiSourceFieldProviders as $multiSourceFieldProvider) {
             $msFieldProviderId = $multiSourceFieldProvider->getId();
             if (!$this->_stringUtils->startsWith($msFieldProviderId, $providerId)) {
                 continue;
             }
             $toReturn[] = $multiSourceFieldProvider;
             $addedIds[] = $msFieldProviderId;
         }
     }
     foreach ($multiSourceFieldProviders as $multiSourceFieldProvider) {
         $msFieldProviderId = $multiSourceFieldProvider->getId();
         if (!in_array($msFieldProviderId, $addedIds)) {
             $toReturn[] = $multiSourceFieldProvider;
         }
     }
     return $toReturn;
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function ownsItem($mediaId)
 {
     return is_string($mediaId) && $this->_stringUtils->startsWith($mediaId, 'dailymotion_');
 }