/** * {@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; }
public function onGalleryInitJs(tubepress_api_event_EventInterface $event) { $args = $event->getSubject(); $ephemeral = $this->_context->getEphemeralOptions(); $optionsToAdd = array(); $requiredOptionNames = array(tubepress_api_options_Names::GALLERY_AJAX_PAGINATION, tubepress_api_options_Names::GALLERY_FLUID_THUMBS, tubepress_api_options_Names::GALLERY_AUTONEXT, tubepress_api_options_Names::HTTP_METHOD); foreach ($requiredOptionNames as $optionName) { $optionsToAdd[$optionName] = $this->_context->get($optionName); } foreach (array('ephemeral', 'options') as $key) { if (!array_key_exists($key, $args) || !is_array($args[$key])) { $args[$key] = array(); } } $args['ephemeral'] = array_merge($args['ephemeral'], $ephemeral); $args['options'] = array_merge($args['options'], $optionsToAdd); $event->setSubject($args); }
/** * 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()); }