Ejemplo n.º 1
0
 public function onOptionSet(tubepress_api_event_EventInterface $event)
 {
     if (!$this->_logger->isEnabled()) {
         return;
     }
     $errors = $event->getSubject();
     $optionName = $event->getArgument('optionName');
     $optionValue = $event->getArgument('optionValue');
     if (count($errors) === 0) {
         $this->_logger->debug(sprintf('(Option Logger) Accepted valid value: <code>%s</code> = <code>%s</code>', $optionName, $this->_stringUtils->redactSecrets($optionValue)));
     } else {
         $this->_logger->error(sprintf('(Option Logger) Rejecting invalid value: <code>%s</code> = <code>%s</code> (%s)', $optionName, $this->_stringUtils->redactSecrets($optionValue), $errors[0]));
     }
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function rfc3339toUnixTime($rfcTime)
 {
     $tmp = str_replace('T', ' ', $rfcTime);
     $tmp = preg_replace('/(\\.[0-9]{1,})?/', '', $tmp);
     $datetime = substr($tmp, 0, 19);
     if ($this->_stringUtils->endsWith($tmp, 'Z')) {
         $reset = date_default_timezone_get();
         date_default_timezone_set('UTC');
         $toReturn = strtotime($datetime);
         date_default_timezone_set($reset);
         return $toReturn;
     }
     $timezone = str_replace(':', '', substr($tmp, 19, 6));
     return strtotime($datetime . ' ' . $timezone);
 }
Ejemplo n.º 3
0
 /**
  * Handles the detection of a custom options.
  *
  * @param array $match The array shortcode matches
  *
  * @return array The name value pair array.
  */
 private function _buildNameValuePairArray($match)
 {
     $toReturn = array();
     $value = null;
     foreach ($match as $m) {
         if (!empty($m[1])) {
             $name = $m[1];
             $value = $m[2];
         } elseif (!empty($m[3])) {
             $name = $m[3];
             $value = $m[4];
         } elseif (!empty($m[5])) {
             $name = $m[5];
             $value = $m[6];
         }
         if (!isset($name) || !isset($value)) {
             continue;
         }
         if ($this->_shouldLog) {
             $this->_logger->debug(sprintf('Name-value pair detected: %s = "%s" (unfiltered)', $name, $this->_stringUtils->redactSecrets($value)));
         }
         $event = $this->_eventDispatcher->newEventInstance($value, array('optionName' => $name));
         $this->_eventDispatcher->dispatch(tubepress_api_event_Events::NVP_FROM_EXTERNAL_INPUT, $event);
         $filtered = $event->getSubject();
         $event = $this->_eventDispatcher->newEventInstance($filtered, array('optionName' => $name));
         $this->_eventDispatcher->dispatch(tubepress_api_event_Events::NVP_FROM_EXTERNAL_INPUT . ".{$name}", $event);
         $filtered = $event->getSubject();
         if ($this->_shouldLog) {
             $this->_logger->debug(sprintf('Name-value pair detected: %s = "%s" (filtered)', $name, $this->_stringUtils->redactSecrets($filtered)));
         }
         $toReturn[$name] = $filtered;
     }
     return $toReturn;
 }
 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);
 }
Ejemplo n.º 5
0
 public function onFilter_jetpack_photon_skip_for_url(tubepress_api_event_EventInterface $event)
 {
     $args = $event->getArgument('args');
     $imageUrl = $args[0];
     try {
         $imageUrl = $this->_urlFactory->fromString($imageUrl);
     } catch (\InvalidArgumentException $e) {
         return;
     }
     $imageHost = $imageUrl->getHost();
     foreach ($this->_domainsToSearch as $domain) {
         if ($imageHost === "{$domain}" || $this->_stringUtils->endsWith($imageHost, ".{$domain}")) {
             $event->setSubject(true);
             return;
         }
     }
 }
Ejemplo n.º 6
0
 public function transform($incoming)
 {
     if ($this->_looksLikeDailymotionUser($incoming)) {
         //looks like a valid user idn
         return $incoming;
     }
     $incoming = trim($incoming, '/');
     /*
      * Might be
      *
      * 1. http://www.dailymotion.com/user/foobar/1
      * 2. http://www.dailymotion.com/user/foobar
      * 3. http://www.dailymotion.com/foobar
      */
     try {
         $url = $this->_urlFactory->fromString($incoming);
         $host = $url->getHost();
         if (!$this->_stringUtils->endsWith($host, 'dailymotion.com')) {
             return null;
         }
         $pathSegments = $url->getPathSegments();
         $pathCount = count($pathSegments);
         if ($pathCount < 2) {
             return null;
         }
         if ($pathCount > 2 && $pathSegments[1] !== 'user') {
             return null;
         }
         if ($pathCount > 2) {
             $user = $pathSegments[2];
         } else {
             $user = $pathSegments[1];
         }
         $error = $user === 'user' || !$this->_looksLikeDailymotionUser($user);
         if ($error) {
             return null;
         }
         return $user;
     } catch (InvalidArgumentException $e) {
         //invalid URL
         return null;
     }
 }
Ejemplo n.º 7
0
 /**
  * {@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;
 }
Ejemplo n.º 8
0
 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;
     }
 }
Ejemplo n.º 9
0
 private function _toRealScreenshotUrl($candidate)
 {
     $realUrl = $this->toUrl($candidate);
     if (!$realUrl) {
         return $realUrl;
     }
     $path = $realUrl->getPath();
     if (!$this->_stringUtils->endsWith($path, '.png') && !$this->_stringUtils->endsWith($path, '.jpg')) {
         return null;
     }
     return $realUrl;
 }
Ejemplo n.º 10
0
 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];
 }
Ejemplo n.º 11
0
 /**
  * Registers all the styles and scripts for the front end.
  *
  * @param array $opts The options.
  *
  * @return void
  */
 public function printWidgetHtml(tubepress_api_event_EventInterface $event)
 {
     $opts = $event->getSubject();
     extract($opts);
     /* default widget options */
     $defaultWidgetOptions = array(tubepress_api_options_Names::FEED_RESULTS_PER_PAGE => 3, tubepress_api_options_Names::META_DISPLAY_VIEWS => false, tubepress_api_options_Names::META_DISPLAY_DESCRIPTION => true, tubepress_api_options_Names::META_DESC_LIMIT => 50, tubepress_api_options_Names::PLAYER_LOCATION => 'shadowbox', tubepress_api_options_Names::GALLERY_THUMB_HEIGHT => 105, tubepress_api_options_Names::GALLERY_THUMB_WIDTH => 135, tubepress_api_options_Names::GALLERY_PAGINATE_ABOVE => false, tubepress_api_options_Names::GALLERY_PAGINATE_BELOW => false, tubepress_api_options_Names::THEME => 'tubepress/default', tubepress_api_options_Names::GALLERY_FLUID_THUMBS => false);
     /* now apply the user's options */
     $rawTag = $this->_context->get(tubepress_wordpress_api_Constants::OPTION_WIDGET_SHORTCODE);
     $widgetTag = $this->_stringUtils->removeNewLines($rawTag);
     $this->_shortcodeParser->parse($widgetTag);
     /* calculate the final options */
     $finalOptions = array_merge($defaultWidgetOptions, $this->_context->getEphemeralOptions());
     $this->_context->setEphemeralOptions($finalOptions);
     if ($this->_context->get(tubepress_api_options_Names::THEME) === '') {
         $this->_context->setEphemeralOption(tubepress_api_options_Names::THEME, 'tubepress/default');
     }
     $out = $this->_htmlGenerator->getHtml();
     /* do the standard WordPress widget dance */
     /* @noinspection PhpUndefinedVariableInspection */
     echo $before_widget . $before_title . $this->_context->get(tubepress_wordpress_api_Constants::OPTION_WIDGET_TITLE) . $after_title . $out . $after_widget;
     /* reset the context for the next shortcode */
     $this->_context->setEphemeralOptions(array());
 }
Ejemplo n.º 12
0
 private function _maybeGetPlaylistValueFromUrl($originalValue)
 {
     $url = null;
     try {
         $url = $this->_urlFactory->fromString($originalValue);
     } catch (Exception $e) {
         return $originalValue;
     }
     $host = $url->getHost();
     if (!$this->_stringUtils->endsWith($host, 'youtube.com')) {
         return $originalValue;
     }
     $params = $url->getQuery();
     if (!$params->hasKey('list') && !$params->hasKey('p')) {
         return $originalValue;
     }
     if ($params->hasKey('list')) {
         return $params->get('list');
     }
     return $params->get('p');
 }
 /**
  * @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;
 }
Ejemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function ownsItem($mediaId)
 {
     return is_string($mediaId) && $this->_stringUtils->startsWith($mediaId, 'dailymotion_');
 }