コード例 #1
0
ファイル: Parser.php プロジェクト: tubepress/tubepress
 private function _wrappedParse($content)
 {
     $keyword = $this->_context->get(tubepress_api_options_Names::SHORTCODE_KEYWORD);
     if (!$this->somethingToParse($content, $keyword)) {
         return;
     }
     preg_match("/\\[{$keyword}\\b(.*)\\]/", $content, $matches);
     if ($this->_shouldLog) {
         $this->_logger->debug(sprintf('Found a shortcode: %s', $this->_stringUtils->redactSecrets($matches[0])));
     }
     $this->_lastShortcodeUsed = $matches[0];
     /* Anything matched? */
     if (isset($matches[1]) && $matches[1] != '') {
         $text = preg_replace('/[\\x{00a0}\\x{200b}]+/u', ' ', $matches[1]);
         $text = self::_convertQuotes($text);
         $pattern = '/(\\w+)\\s*=\\s*"([^"]*)"(?:\\s*,)?(?:\\s|$)|(\\w+)\\s*=\\s*\'([^\']*)\'(?:\\s*,)?(?:\\s|$)|(\\w+)\\s*=\\s*([^\\s\'"]+)(?:\\s*,)?(?:\\s|$)/';
         if (preg_match_all($pattern, $text, $match, PREG_SET_ORDER)) {
             if ($this->_shouldLog) {
                 $this->_logger->debug(sprintf('Candidate options detected in shortcode: %s', $this->_stringUtils->redactSecrets($matches[0])));
             }
             $toReturn = $this->_buildNameValuePairArray($match);
             $this->_context->setEphemeralOptions($toReturn);
         }
     } else {
         if ($this->_shouldLog) {
             $this->_logger->debug(sprintf('No custom options detected in shortcode: %s', $this->_stringUtils->redactSecrets($matches[0])));
         }
     }
 }
コード例 #2
0
ファイル: PucListener.php プロジェクト: tubepress/tubepress
 public function onFilter_PucRequestInfoResultTubePress(tubepress_api_event_EventInterface $event)
 {
     $pluginInfo = $event->getSubject();
     if ($pluginInfo && $this->_environment->isPro()) {
         $apiKey = $this->_context->get(tubepress_api_options_Names::TUBEPRESS_API_KEY);
         if (!$apiKey) {
             /*
              * We don't want to downgrade Pro users that haven't entered an API key.
              */
             $pluginInfo->download_url = null;
         }
         if (property_exists($pluginInfo, 'download_url') && strpos($pluginInfo->download_url, 'free') !== false) {
             /*
              * Extra assurance that we don't downgrade Pro users
              */
             $pluginInfo->download_url = null;
         }
         if (property_exists($pluginInfo, 'download_url') && $pluginInfo->download_url && $apiKey) {
             $url = $this->_urlFactory->fromString($pluginInfo->download_url);
             $url->getQuery()->set('key', $apiKey)->set('pid', 2);
             $pluginInfo->download_url = $url->toString();
         }
         $event->setSubject($pluginInfo);
     }
 }
コード例 #3
0
 public function onAjax(tubepress_api_event_EventInterface $ajaxEvent)
 {
     $isDebugEnabled = $this->_logger->isEnabled();
     if ($isDebugEnabled) {
         $this->_logger->debug('Handling incoming request. First parsing shortcode.');
     }
     $nvpMap = $this->_requestParams->getParamValue('tubepress_options');
     $itemId = $this->_requestParams->getParamValue('tubepress_item');
     if ($isDebugEnabled) {
         $this->_logger->debug('Requested item ID is ' . $itemId);
     }
     $this->_context->setEphemeralOptions($nvpMap);
     if ($this->_context->get(tubepress_api_options_Names::EMBEDDED_LAZYPLAY)) {
         $this->_context->setEphemeralOption(tubepress_api_options_Names::EMBEDDED_AUTOPLAY, true);
     }
     if ($isDebugEnabled) {
         $this->_logger->debug('Now asking collector for item with ID ' . $itemId);
     }
     /* grab the item! */
     $mediaItem = $this->_collector->collectSingle($itemId);
     if ($mediaItem === null) {
         $this->_responseCode->setResponseCode(404);
         $ajaxEvent->setArgument('handled', true);
         return;
     }
     if ($isDebugEnabled) {
         $this->_logger->debug('Collector found item with ID ' . $itemId . '. Sending it to browser');
     }
     $playerHtml = $this->_templating->renderTemplate('gallery/player/ajax', array(tubepress_api_template_VariableNames::MEDIA_ITEM => $mediaItem));
     $toReturn = array('mediaItem' => $mediaItem->toHtmlSafeArray(), 'html' => $playerHtml);
     $this->_responseCode->setResponseCode(200);
     echo json_encode($toReturn);
     $ajaxEvent->setArgument('handled', true);
 }
コード例 #4
0
 public function onAction_in_plugin_update_message(tubepress_api_event_EventInterface $event)
 {
     if (!$this->_context->get(tubepress_api_options_Names::TUBEPRESS_API_KEY)) {
         $html = $this->_templating->renderTemplate('wordpress/in-update-message');
         echo $html;
     }
 }
コード例 #5
0
 public function onSearchInputTemplatePreRender(tubepress_api_event_EventInterface $event)
 {
     /*
      * @var array
      */
     $existingTemplateVars = $event->getSubject();
     $resultsUrl = $this->_context->get(tubepress_api_options_Names::SEARCH_RESULTS_URL);
     $url = '';
     try {
         $url = $this->_urlFactory->fromString($resultsUrl);
     } catch (Exception $e) {
         //this is not a real problem, as the user might simply not supply a custom URL
     }
     /* if the user didn't request a certain page, just send the search results right back here */
     if ($url == '') {
         $url = $this->_urlFactory->fromCurrent();
     }
     /* clean up the search terms a bit */
     $searchTerms = $this->_requestParams->getParamValue('tubepress_search');
     $searchTerms = urldecode($searchTerms);
     /*
      * read http://stackoverflow.com/questions/1116019/submitting-a-get-form-with-query-string-params-and-hidden-params-disappear
      * if you're curious as to what's going on here
      */
     $params = $url->getQuery();
     $params->remove('tubepress_page');
     $params->remove('tubepress_search');
     /* apply the template variables */
     $newVars = array(tubepress_api_template_VariableNames::SEARCH_HANDLER_URL => $url->toString(), tubepress_api_template_VariableNames::SEARCH_HIDDEN_INPUTS => $params->toArray(), tubepress_api_template_VariableNames::SEARCH_TERMS => $searchTerms);
     $existingTemplateVars = array_merge($existingTemplateVars, $newVars);
     $event->setSubject($existingTemplateVars);
 }
コード例 #6
0
ファイル: HtmlLogger.php プロジェクト: tubepress/tubepress
 public function __construct(tubepress_api_options_ContextInterface $context, tubepress_api_http_RequestParametersInterface $requestParams)
 {
     $loggingRequested = $requestParams->hasParam('tubepress_debug') && $requestParams->getParamValue('tubepress_debug') === true;
     $loggingEnabled = $context->get(tubepress_api_options_Names::DEBUG_ON);
     $this->_enabled = $loggingRequested && $loggingEnabled;
     $this->_bootMessageBuffer = array();
     $this->_shouldBuffer = true;
     $this->_timezone = new DateTimeZone(@date_default_timezone_get() ? @date_default_timezone_get() : 'UTC');
 }
コード例 #7
0
 private function _buildShortcodeEvent(array $normalizedOptions, $innerContent)
 {
     if (!$innerContent) {
         $innerContent = null;
     }
     $name = $this->_context->get(tubepress_api_options_Names::SHORTCODE_KEYWORD);
     $shortcode = new tubepress_shortcode_impl_Shortcode($name, $normalizedOptions, $innerContent);
     return $this->_eventDispatcher->newEventInstance($shortcode);
 }
コード例 #8
0
 private function _getToShowMap()
 {
     $toReturn = array();
     $map = $this->_getMetaOptionNamesToAttributeDisplayNames();
     foreach ($map as $metaOptionName => $attributeName) {
         if ($this->_context->get($metaOptionName)) {
             $toReturn[] = $attributeName;
         }
     }
     return $toReturn;
 }
コード例 #9
0
 private function _getDataUrl(tubepress_api_media_MediaItem $mediaItem, $playerId)
 {
     $autoPlay = $this->_context->get(tubepress_api_options_Names::EMBEDDED_AUTOPLAY);
     $showInfo = $this->_context->get(tubepress_api_options_Names::EMBEDDED_SHOW_INFO);
     $actualId = str_replace('dailymotion_', '', $mediaItem->getId());
     /* build the data URL based on these options */
     $link = $this->_urlFactory->fromString("https://www.dailymotion.com/embed/video/{$actualId}");
     $query = $link->getQuery();
     $query->set(self::$_URL_PARAM_AUTOPLAY, $this->_langUtils->booleanToStringOneOrZero($autoPlay));
     $query->set(self::$_URL_PARAM_UI_START_SCREEN, $this->_langUtils->booleanToStringOneOrZero($showInfo));
     $query->set(self::$_URL_PARAM_ID, $playerId);
     return $link;
 }
コード例 #10
0
 private function _getHtml($vidCount)
 {
     $currentPage = $this->_requestParams->getParamValueAsInt('tubepress_page', 1);
     $vidsPerPage = $this->_context->get(tubepress_api_options_Names::FEED_ADJUSTED_RESULTS_PER_PAGE);
     if (!$vidsPerPage) {
         $vidsPerPage = $this->_context->get(tubepress_api_options_Names::FEED_RESULTS_PER_PAGE);
     }
     $newurl = $this->_urlFactory->fromCurrent();
     if (!$this->_isLegacyTheme()) {
         return $this->_paginationFromTemplate($vidCount, $currentPage, $vidsPerPage, $newurl);
     }
     return $this->_legacyPagination($vidCount, $currentPage, $vidsPerPage, 1, $newurl, 'tubepress_page');
 }
コード例 #11
0
 private function _getDataUrl(tubepress_api_media_MediaItem $mediaItem)
 {
     $link = $this->_urlFactory->fromString('https://www.youtube.com/embed/' . $mediaItem->getId());
     $embedQuery = $link->getQuery();
     $url = $this->_urlFactory->fromCurrent();
     $origin = $url->getScheme() . '://' . $url->getHost();
     $autoPlay = $this->_context->get(tubepress_api_options_Names::EMBEDDED_AUTOPLAY);
     $loop = $this->_context->get(tubepress_api_options_Names::EMBEDDED_LOOP);
     $showInfo = $this->_context->get(tubepress_api_options_Names::EMBEDDED_SHOW_INFO);
     $autoHide = $this->_context->get(tubepress_youtube3_api_Constants::OPTION_AUTOHIDE);
     $fullscreen = $this->_context->get(tubepress_youtube3_api_Constants::OPTION_FULLSCREEN);
     $modestBranding = $this->_context->get(tubepress_youtube3_api_Constants::OPTION_MODEST_BRANDING);
     $showRelated = $this->_context->get(tubepress_youtube3_api_Constants::OPTION_SHOW_RELATED);
     $embedQuery->set('autohide', $this->_getAutoHideValue($autoHide));
     $embedQuery->set('autoplay', $this->_langUtils->booleanToStringOneOrZero($autoPlay));
     $embedQuery->set('enablejsapi', '1');
     $embedQuery->set('fs', $this->_langUtils->booleanToStringOneOrZero($fullscreen));
     $embedQuery->set('modestbranding', $this->_langUtils->booleanToStringOneOrZero($modestBranding));
     $embedQuery->set('origin', $origin);
     $embedQuery->set('rel', $this->_langUtils->booleanToStringOneOrZero($showRelated));
     $embedQuery->set('showinfo', $this->_langUtils->booleanToStringOneOrZero($showInfo));
     $embedQuery->set('wmode', 'opaque');
     if ($loop) {
         $embedQuery->set('loop', $this->_langUtils->booleanToStringOneOrZero($loop));
         $embedQuery->set('playlist', $mediaItem->getId());
     }
     return $link;
 }
コード例 #12
0
 private function _handle(tubepress_api_event_EventInterface $event)
 {
     $itemId = $this->_requestParams->getParamValue('tubepress_item');
     $shouldLog = $this->_logger->isEnabled();
     if ($shouldLog) {
         $this->_logger->debug(sprintf('Building single video with ID %s', $itemId));
     }
     $result = $this->_context->setEphemeralOption(tubepress_api_options_Names::SINGLE_MEDIA_ITEM_ID, $itemId);
     if ($result !== null) {
         if ($shouldLog) {
             $this->_logger->debug('Could not verify video ID.');
         }
     }
 }
コード例 #13
0
ファイル: Collector.php プロジェクト: tubepress/tubepress
 /**
  * {@inheritdoc}
  */
 public function collectPage($currentPage)
 {
     $modeValueFromContext = $this->_context->get(tubepress_api_options_Names::GALLERY_SOURCE);
     $originalEphemeralOptions = $this->_context->getEphemeralOptions();
     $isPro = $this->_environment->isPro();
     if ($isPro) {
         if ($this->_shouldLog) {
             $this->_logger->debug('Pro user, leaving collection up to collection listeners.');
         }
         return $this->_collectPage($modeValueFromContext, $currentPage);
     }
     /*
      * Did the user include mode in their ephemeral options?
      */
     if (isset($originalEphemeralOptions[tubepress_api_options_Names::GALLERY_SOURCE])) {
         if ($this->_shouldLog) {
             $this->_logger->debug(sprintf('Explicit mode requested in ephemeral options: <code>%s</code>.', $modeValueFromContext));
         }
         return $this->_collectPage($modeValueFromContext, $currentPage);
     }
     $jsonEncodedSources = $this->_context->get(tubepress_api_options_Names::SOURCES);
     if (!$jsonEncodedSources) {
         if ($this->_shouldLog) {
             $this->_logger->debug(sprintf('Encoded sources are falsy. Falling back to stored "mode" value of <code>%s</code>.', $modeValueFromContext));
         }
         return $this->_collectPage($modeValueFromContext, $currentPage);
     }
     $decodedSources = json_decode($jsonEncodedSources, true);
     if (!$decodedSources || !is_array($decodedSources) || count($decodedSources) < 1 || !is_array($decodedSources[0])) {
         if ($this->_shouldLog) {
             $this->_logger->debug(sprintf('Encoded sources are empty. Falling back to stored "mode" value of <code>%s</code>.', $modeValueFromContext));
         }
         return $this->_collectPage($modeValueFromContext, $currentPage);
     }
     if ($this->_shouldLog) {
         $this->_logger->debug('Popping first stored source and applying it as ephemeral options for collection.');
     }
     $newEphemeralOptions = array_merge($originalEphemeralOptions, $decodedSources[0]);
     if (!isset($newEphemeralOptions[tubepress_api_options_Names::GALLERY_SOURCE])) {
         $newEphemeralOptions[tubepress_api_options_Names::GALLERY_SOURCE] = $modeValueFromContext;
     }
     $this->_context->setEphemeralOptions($newEphemeralOptions);
     $page = $this->_collectPage($newEphemeralOptions[tubepress_api_options_Names::GALLERY_SOURCE], $currentPage);
     if ($this->_shouldLog) {
         $this->_logger->debug('Restoring saved ephemeral options after page collection.');
     }
     $this->_context->setEphemeralOptions($originalEphemeralOptions);
     return $page;
 }
コード例 #14
0
 /**
  * {@inheritdoc}
  */
 public function formatDateAttribute(tubepress_api_media_MediaItem $item, $sourceAttributeName, $destinationAttributeName)
 {
     if (!$item->hasAttribute($sourceAttributeName)) {
         return;
     }
     /*
      * Hacky way of warming up the translation service and thus setting locale etc.
      */
     $this->_translator->trans('');
     $dateFormat = $this->_context->get(tubepress_api_options_Names::META_DATEFORMAT);
     $relative = $this->_context->get(tubepress_api_options_Names::META_RELATIVE_DATES);
     $unixTime = $item->getAttribute($sourceAttributeName);
     $formatted = $this->_timeUtils->unixTimeToHumanReadable($unixTime, $dateFormat, $relative);
     $item->setAttribute($destinationAttributeName, $formatted);
 }
コード例 #15
0
 /**
  * @return tubepress_spi_player_PlayerLocationInterface
  *
  * @throws RuntimeException
  */
 private function _getActivePlayerLocation()
 {
     $playerName = $this->_context->get(tubepress_api_options_Names::PLAYER_LOCATION);
     if (!isset($this->_playerLocationNameToInstanceMap[$playerName])) {
         throw new RuntimeException('Unable to find active player location');
     }
     return $this->_playerLocationNameToInstanceMap[$playerName];
 }
コード例 #16
0
 private function _getDataUrl(tubepress_api_media_MediaItem $mediaItem)
 {
     $autoPlay = $this->_context->get(tubepress_api_options_Names::EMBEDDED_AUTOPLAY);
     $showInfo = $this->_context->get(tubepress_api_options_Names::EMBEDDED_SHOW_INFO);
     $loop = $this->_context->get(tubepress_api_options_Names::EMBEDDED_LOOP);
     $color = $this->_context->get(tubepress_vimeo3_api_Constants::OPTION_PLAYER_COLOR);
     /* build the data URL based on these options */
     $link = $this->_urlFactory->fromString('https://player.vimeo.com/video/' . $mediaItem->getId());
     $query = $link->getQuery();
     $query->set(self::$_URL_PARAM_AUTOPLAY, $this->_langUtils->booleanToStringOneOrZero($autoPlay));
     $query->set(self::$_URL_PARAM_COLOR, $color);
     $query->set(self::$_URL_PARAM_LOOP, $this->_langUtils->booleanToStringOneOrZero($loop));
     $query->set(self::$_URL_PARAM_PORTRAIT, $this->_langUtils->booleanToStringOneOrZero($showInfo));
     $query->set(self::$_URL_PARAM_BYLINE, $this->_langUtils->booleanToStringOneOrZero($showInfo));
     $query->set(self::$_URL_PARAM_TITLE, $this->_langUtils->booleanToStringOneOrZero($showInfo));
     return $link;
 }
コード例 #17
0
 private function _setLegacyVariables(array &$templateVars)
 {
     $metaNames = $this->_getAllMetaOptionNames();
     $shouldShow = array();
     $labels = array();
     foreach ($metaNames as $metaName) {
         if (!$this->_optionReference->optionExists($metaName)) {
             $shouldShow[$metaName] = false;
             $labels[$metaName] = '';
             continue;
         }
         $shouldShow[$metaName] = $this->_context->get($metaName);
         $untranslatedLabel = $this->_optionReference->getUntranslatedLabel($metaName);
         $labels[$metaName] = $this->_translator->trans($untranslatedLabel);
     }
     $templateVars[tubepress_api_const_template_Variable::META_SHOULD_SHOW] = $shouldShow;
     $templateVars[tubepress_api_const_template_Variable::META_LABELS] = $labels;
 }
コード例 #18
0
ファイル: FeedHandler.php プロジェクト: tubepress/tubepress
 private function _addPagination($currentPage, tubepress_api_url_QueryInterface $query)
 {
     if (isset($this->_invokedAtLeastOnce)) {
         $perPage = $this->_context->get(tubepress_api_options_Names::FEED_RESULTS_PER_PAGE);
     } else {
         $perPage = min($this->_context->get(tubepress_api_options_Names::FEED_RESULTS_PER_PAGE), ceil(2.04));
     }
     $query->set('page', $currentPage)->set('limit', $perPage);
 }
コード例 #19
0
 /**
  * @return tubepress_api_theme_ThemeInterface
  */
 public function getCurrentTheme()
 {
     $currentTheme = $this->_context->get($this->_optionName);
     $this->_initCache();
     if ($currentTheme == '') {
         $currentTheme = $this->_defaultThemeName;
     }
     if (array_key_exists($currentTheme, $this->_themeMap)) {
         return $this->_themeMap[$currentTheme];
     }
     if (array_key_exists("tubepress/legacy-{$currentTheme}", $this->_themeMap)) {
         return $this->_themeMap["tubepress/legacy-{$currentTheme}"];
     }
     if (array_key_exists("unknown/legacy-{$currentTheme}", $this->_themeMap)) {
         return $this->_themeMap["unknown/legacy-{$currentTheme}"];
     }
     return $this->_themeMap[$this->_defaultThemeName];
 }
コード例 #20
0
 public function onHtmlGeneration(tubepress_api_event_EventInterface $event)
 {
     $mediaItemId = $this->_context->get(tubepress_api_options_Names::SINGLE_MEDIA_ITEM_ID);
     if ($mediaItemId == '') {
         return;
     }
     /* grab the media item from the provider */
     if ($this->_logger->isEnabled()) {
         $this->_logger->debug(sprintf('Asking provider for video with ID %s', $mediaItemId));
     }
     $mediaItem = $this->_collector->collectSingle($mediaItemId);
     $eventArgs = array('itemId' => $mediaItemId);
     if ($mediaItem !== null) {
         $eventArgs['mediaItem'] = $mediaItem;
     }
     $singleHtml = $this->_templating->renderTemplate('single/main', $eventArgs);
     $event->setSubject($singleHtml);
     $event->stopPropagation();
 }
コード例 #21
0
 private function _applyThumbnail(array &$toReturn, array $json, $index)
 {
     $preferredSize = $this->_context->get(tubepress_dailymotion_api_Constants::OPTION_THUMB_SIZE);
     $preferredSize = str_replace('px', '', $preferredSize);
     $url = $this->_relativeQueryAsString($json, $index, sprintf('thumbnail_%s_url', $preferredSize));
     if (!$url) {
         $url = $this->_relativeQueryAsString($json, $index, 'thumbnail_url');
     }
     $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_THUMBNAIL_URL] = $url;
 }
コード例 #22
0
 private function _findMediaProvider()
 {
     $name = $this->_context->get(tubepress_api_options_Names::SEARCH_PROVIDER);
     foreach ($this->_mediaProviders as $mediaProvider) {
         if ($mediaProvider->getName() === $name) {
             return $mediaProvider;
         }
     }
     return null;
 }
コード例 #23
0
 private function _getCache()
 {
     $enabled = $this->_context->get(tubepress_api_options_Names::TEMPLATE_CACHE_ENABLED);
     if (!$enabled) {
         return false;
     }
     $dir = $this->_context->get(tubepress_api_options_Names::TEMPLATE_CACHE_DIR);
     if ($this->_writableDirectory($dir)) {
         return $dir;
     }
     $dir = $this->_bootSettingsInterface->getPathToSystemCacheDirectory() . DIRECTORY_SEPARATOR . '/twig';
     if ($this->_writableDirectory($dir)) {
         return $dir;
     }
     @mkdir($dir);
     if ($this->_writableDirectory($dir)) {
         return $dir;
     }
     return false;
 }
コード例 #24
0
 public function buildFilesystemDriver()
 {
     $dir = $this->_context->get(tubepress_api_options_Names::CACHE_DIRECTORY);
     if ($this->_shouldLog) {
         $this->_logDebug(sprintf('Starting to build API cache driver. User candidate is "<code>%s</code>"', $dir));
     }
     /*
      * If a path was given, but it's not a directory, let's try to create it.
      */
     if ($dir && !is_dir($dir)) {
         if ($this->_shouldLog) {
             $this->_logDebug(sprintf('"<code>%s</code>" is not a directory. Let\'s try to create it...', $dir));
         }
         @mkdir($dir, 0755, true);
     }
     /*
      * If the directory exists, but isn't writable, let's try to change that.
      */
     if ($dir && is_dir($dir) && !is_writable($dir)) {
         if ($this->_shouldLog) {
             $this->_logDebug(sprintf('"<code>%s</code>" is a directory but we can\'t write to it. Let\'s try to change that...', $dir));
         }
         @chmod($dir, 0755);
     }
     /*
      * If we don't have a writable directory, use the system temp directory.
      */
     if (!is_dir($dir) || !is_writable($dir)) {
         if ($this->_shouldLog) {
             $this->_logDebug(sprintf('We don\'t have a directory that we can use for the API cache. Giving up and falling back to system directory.', $dir));
         }
         $dir = $this->_bootSettings->getPathToSystemCacheDirectory() . '/api-calls';
         if ($this->_shouldLog) {
             $this->_logDebug(sprintf('Final API cache directory is "<code>%s</code>"', $dir));
         }
     }
     $driver = new \Stash\Driver\FileSystem();
     $driver->setOptions(array('path' => $dir));
     return $driver;
 }
コード例 #25
0
 private function _applyThumbnail(array &$toReturn, array $json, $index)
 {
     $thumb = $this->_relativeQueryAsString($json, $index, array(tubepress_youtube3_impl_ApiUtility::RESOURCE_SNIPPET, tubepress_youtube3_impl_ApiUtility::RESOURCE_VIDEO_SNIPPET_THUMBS, 'default', tubepress_youtube3_impl_ApiUtility::RESOURCE_VIDEO_SNIPPET_THUMBS_URL));
     if ($this->_context->get(tubepress_api_options_Names::GALLERY_RANDOM_THUMBS)) {
         $choices = array('1', '2', '3');
         $new = $choices[array_rand($choices)];
         $final = str_replace('default', $new, $thumb);
     } else {
         $final = $thumb;
     }
     $final = str_replace('s://', '://', $final);
     $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_THUMBNAIL_URL] = $final;
 }
コード例 #26
0
 private function _shouldExecute(tubepress_api_http_message_RequestInterface $request)
 {
     $cacheEnabled = $this->_context->get(tubepress_api_options_Names::CACHE_ENABLED);
     $isDebugEnabled = $this->_logger->isEnabled();
     if ($isDebugEnabled && !$cacheEnabled) {
         $this->_logDebug('Skip API cache for debugging.');
         return false;
     }
     $config = $request->getConfig();
     if (!isset($config['tubepress-remote-api-call'])) {
         return false;
     }
     return true;
 }
コード例 #27
0
ファイル: Widget.php プロジェクト: tubepress/tubepress
 /**
  * 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());
 }
コード例 #28
0
 private function _adjustPagination(array &$templateVars)
 {
     if (!isset($templateVars[tubepress_api_template_VariableNames::GALLERY_PAGINATION_HTML])) {
         return;
     }
     $paginationHtml = $templateVars[tubepress_api_template_VariableNames::GALLERY_PAGINATION_HTML];
     $paginationTop = $this->_context->get(tubepress_api_options_Names::GALLERY_PAGINATE_ABOVE);
     $paginationBottom = $this->_context->get(tubepress_api_options_Names::GALLERY_PAGINATE_BELOW);
     if ($paginationTop) {
         $templateVars[tubepress_api_const_template_Variable::PAGINATION_TOP] = $paginationHtml;
     }
     if ($paginationBottom) {
         $templateVars[tubepress_api_const_template_Variable::PAGINATION_BOTTOM] = $paginationHtml;
     }
 }
コード例 #29
0
 public function saveToken(tubepress_spi_http_oauth2_Oauth2ProviderInterface $provider, $slug, tubepress_api_http_oauth_v2_TokenInterface $token)
 {
     $tokens = $this->_context->get(tubepress_api_options_Names::OAUTH2_TOKENS);
     $decoded = json_decode($tokens, true);
     $providerName = $provider->getName();
     if (!isset($decoded[$providerName])) {
         $decoded[$providerName] = array();
     }
     $providerTokens = $decoded[$providerName];
     $toSave = array(self::$_ACCESS_TOKEN => $token->getAccessToken(), self::$_EXPIRY_UNIX => $token->getEndOfLifeUnixTime(), self::$_EXTRA => $token->getExtraParams());
     if ($token->getRefreshToken()) {
         $toSave[self::$_REFRESH_TOKEN] = $token->getRefreshToken();
     }
     $providerTokens[$slug] = $toSave;
     $decoded[$providerName] = $providerTokens;
     $this->_persistence->queueForSave(tubepress_api_options_Names::OAUTH2_TOKENS, json_encode($decoded));
     $this->_persistence->flushSaveQueue();
 }
コード例 #30
0
    public function onPostGalleryTemplateRender(tubepress_api_event_EventInterface $event)
    {
        $galleryId = $this->_context->get(tubepress_api_options_Names::HTML_GALLERY_ID);
        $jsEvent = $this->_eventDispatcher->newEventInstance(array(), array('mediaPage' => $event->getArgument('mediaPage'), 'pageNumber' => $event->getArgument('pageNumber')));
        $this->_eventDispatcher->dispatch(tubepress_api_event_Events::GALLERY_INIT_JS, $jsEvent);
        $args = $jsEvent->getSubject();
        $this->_deepConvertBooleans($args);
        $asJson = json_encode($args);
        $html = $event->getSubject();
        $toReturn = $html . <<<EOT
<script type="text/javascript">
   var tubePressDomInjector = tubePressDomInjector || [], tubePressGalleryRegistrar = tubePressGalleryRegistrar || [];
       tubePressDomInjector.push(['loadGalleryJs']);
       tubePressGalleryRegistrar.push(['register', '{$galleryId}', {$asJson} ]);
</script>
EOT;
        $event->setSubject($toReturn);
    }