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])); } }
public function onOptionValidation(tubepress_api_event_EventInterface $event) { $errors = $event->getSubject(); $optionName = $event->getArgument('optionName'); $optionValue = $event->getArgument('optionValue'); if (!$this->isValid($optionName, $optionValue)) { $template = $this->getErrorMessageTemplate(); $error = $this->_translator->trans($template); $error = sprintf($error, $this->_getLabel($optionName)); $errors[] = $error; $event->setSubject($errors); $event->stopPropagation(); } }
public function onResponse(tubepress_api_event_EventInterface $event) { /* * @var tubepress_api_http_message_RequestInterface */ $httpRequest = $event->getArgument('request'); if (!$this->_shouldExecute($httpRequest)) { return; } /** * @var $httpResponse tubepress_api_http_message_ResponseInterface */ $httpResponse = $event->getSubject(); if ($httpResponse->hasHeader(self::HTTP_HEADER_CACHE_HIT)) { return; } $url = $httpRequest->getUrl(); $body = $httpResponse->getBody(); $result = $this->_getItem($url); $this->_possiblyClearCache(); $toStore = $body ? $body->toString() : ''; $storedSuccessfully = $result->set($toStore, intval($this->_context->get(tubepress_api_options_Names::CACHE_LIFETIME_SECONDS))); if (!$storedSuccessfully) { if ($this->_logger->isEnabled()) { $this->_logger->error('Unable to store data to cache'); } } }
public function onEmbeddedTemplate(tubepress_api_event_EventInterface $event) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $environment = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector(); $template = $event->getSubject(); $dataUrl = $event->getArgument('dataUrl'); $videoId = $event->getArgument('videoId'); $providerName = $event->getArgument('providerName'); $autoPlay = $context->get(tubepress_api_const_options_names_Embedded::AUTOPLAY); $embedWidth = $context->get(tubepress_api_const_options_names_Embedded::EMBEDDED_WIDTH); $embedHeight = $context->get(tubepress_api_const_options_names_Embedded::EMBEDDED_HEIGHT); $vars = array(tubepress_api_const_template_Variable::EMBEDDED_DATA_URL => $dataUrl->toString(true), tubepress_api_const_template_Variable::TUBEPRESS_BASE_URL => $environment->getBaseUrl(), tubepress_api_const_template_Variable::EMBEDDED_AUTOSTART => tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToString($autoPlay), tubepress_api_const_template_Variable::EMBEDDED_WIDTH => $embedWidth, tubepress_api_const_template_Variable::EMBEDDED_HEIGHT => $embedHeight, tubepress_api_const_template_Variable::VIDEO_ID => $videoId, tubepress_api_const_template_Variable::VIDEO_DOM_ID => $this->_getVideoDomId($providerName, $dataUrl), tubepress_api_const_template_Variable::EMBEDDED_IMPL_NAME => $event->getArgument('embeddedImplementationName'), tubepress_api_const_template_Variable::VIDEO_PROVIDER_NAME => $providerName); foreach ($vars as $key => $value) { $template->setVariable($key, $value); } return $template; }
/** * Build a map of attribute names => attribute values for the video construction event. * * @param tubepress_api_event_EventInterface $event The video construction event. * * @return array An associative array of attribute names => attribute values */ private function _buildAttributeMap(tubepress_api_event_EventInterface $event) { $toReturn = array(); $feed = $event->getArgument('feedAsArray'); $index = $event->getArgument('zeroBasedIndex'); // starts at 0 $this->_applyTitle($toReturn, $feed, $index); $this->_applyDuration($toReturn, $feed, $index); $this->_applyAuthor($toReturn, $feed, $index); $this->_applyKeywords($toReturn, $feed, $index); $this->_applyHomeUrl($toReturn, $feed, $index); $this->_applyCategory($toReturn, $feed, $index); $this->_applyViewCount($toReturn, $feed, $index); $this->_applyTimePublished($toReturn, $feed, $index); $this->_applyDescription($toReturn, $feed, $index); $this->_applyThumbnail($toReturn, $feed, $index); return $toReturn; }
public function onPreValidationOptionSet(tubepress_api_event_EventInterface $event) { $name = $event->getArgument('optionName'); if (!in_array($name, $this->_applicableOptionNames)) { return; } $value = $event->getSubject(); $value = $this->_stripLeadingHash($value); $event->setSubject($value); }
public function onMediaItemRequest(tubepress_api_event_EventInterface $event) { if (!$event->hasArgument('mediaItem')) { return; } $item = $event->getArgument('mediaItem'); $event = $this->_eventDispatcher->newEventInstance($item); $item = $this->_dispatchAndReturnSubject($event, tubepress_api_event_Events::MEDIA_ITEM_NEW); $event->setArgument('mediaItem', $item); }
public function onSingleTemplate(tubepress_api_event_EventInterface $event) { $existingTemplateVars = $event->getSubject(); if (!$event->hasArgument('item')) { $existingTemplateVars[tubepress_api_const_template_Variable::VIDEO] = new tubepress_api_media_MediaItem('id'); } else { $existingTemplateVars[tubepress_api_const_template_Variable::VIDEO] = $event->getArgument('item'); } $event->setSubject($existingTemplateVars); }
public function onEmbeddedTemplateSelect(tubepress_api_event_EventInterface $event) { if (!$event->hasArgument('embeddedProvider')) { return; } /* * @var tubepress_spi_embedded_EmbeddedProviderInterface */ $embeddedProvider = $event->getArgument('embeddedProvider'); $event->setSubject($embeddedProvider->getTemplateName()); }
public function onPreValidationOptionSet(tubepress_api_event_EventInterface $event) { $name = $event->getArgument('optionName'); /** We only care about playlistValue. */ if ($name !== tubepress_addons_youtube_api_const_options_names_GallerySource::YOUTUBE_PLAYLIST_VALUE) { return; } $filteredValue = $this->_maybeGetListValueFromUrl($event->getSubject()); $filteredValue = $this->_maybeRemoveLeadingPL($filteredValue); $event->setSubject($filteredValue); }
/** * Filter the content (which may be empty). */ public function onFilter_row_meta(tubepress_api_event_EventInterface $event) { $links = $event->getSubject(); $args = $event->getArgument('args'); $file = $args[0]; $plugin = $this->_wpFunctions->plugin_basename(basename(TUBEPRESS_ROOT) . '/tubepress.php'); if ($file != $plugin) { return; } $toReturn = array_merge($links, array(sprintf('<a href="options-general.php?page=tubepress.php">%s</a>', $this->_wpFunctions->__('Settings', 'tubepress')), sprintf('<a href="http://support.tubepress.com/">Support</a>'))); $event->setSubject($toReturn); }
public function onPlayerTemplate(tubepress_api_event_EventInterface $event) { $embedded = tubepress_impl_patterns_sl_ServiceLocator::getEmbeddedHtmlGenerator(); $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $galleryId = $context->get(tubepress_api_const_options_names_Advanced::GALLERY_ID); $template = $event->getSubject(); $video = $event->getArgument('video'); $template->setVariable(tubepress_api_const_template_Variable::EMBEDDED_SOURCE, $embedded->getHtml($video->getId())); $template->setVariable(tubepress_api_const_template_Variable::GALLERY_ID, $galleryId); $template->setVariable(tubepress_api_const_template_Variable::VIDEO, $video); $template->setVariable(tubepress_api_const_template_Variable::EMBEDDED_WIDTH, $context->get(tubepress_api_const_options_names_Embedded::EMBEDDED_WIDTH)); }
public function onGalleryTemplate(tubepress_api_event_EventInterface $event) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $htmlGenerator = tubepress_impl_patterns_sl_ServiceLocator::getPlayerHtmlGenerator(); $playerName = $context->get(tubepress_api_const_options_names_Embedded::PLAYER_LOCATION); $providerResult = $event->getArgument('videoGalleryPage'); $videos = $providerResult->getVideos(); $template = $event->getSubject(); $galleryId = $context->get(tubepress_api_const_options_names_Advanced::GALLERY_ID); $playerHtml = $playerHtml = $this->_showPlayerHtmlOnPageLoad($playerName) ? $htmlGenerator->getHtml($videos[0], $galleryId) : ''; $template->setVariable(tubepress_api_const_template_Variable::PLAYER_HTML, $playerHtml); $template->setVariable(tubepress_api_const_template_Variable::PLAYER_NAME, $playerName); }
/** * Build a map of attribute names => attribute values for the video construction event. * * @param tubepress_api_event_EventInterface $event The video construction event. * * @return array An associative array of attribute names => attribute values */ protected final function buildAttributeMap(tubepress_api_event_EventInterface $event) { $toReturn = array(); $index = $event->getArgument('zeroBasedFeedIndex'); $videoArray = $event->getArgument('videoArray'); /* Author */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_AUTHOR_DISPLAY_NAME] = $videoArray[$index]->owner->display_name; $toReturn[tubepress_api_video_Video::ATTRIBUTE_AUTHOR_USER_ID] = $videoArray[$index]->owner->username; /* Description */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_DESCRIPTION] = $this->trimDescription($videoArray[$index]->description); /* Duration */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_DURATION_SECONDS] = $videoArray[$index]->duration; $toReturn[tubepress_api_video_Video::ATTRIBUTE_DURATION_FORMATTED] = tubepress_impl_util_TimeUtils::secondsToHumanTime($toReturn[tubepress_api_video_Video::ATTRIBUTE_DURATION_SECONDS]); /* Home URL */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_HOME_URL] = 'http://vimeo.com/' . $videoArray[$index]->id; /* ID */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_ID] = $videoArray[$index]->id; /* Keywords */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_KEYWORD_ARRAY] = $this->_gatherArrayOfContent($videoArray[$index], 'tags', 'tag'); /* Likes. */ if (isset($videoArray[$index]->number_of_likes)) { $toReturn[tubepress_api_video_Video::ATTRIBUTE_LIKES_COUNT] = $videoArray[$index]->number_of_likes; } /* Thumbnail. */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_THUMBNAIL_URL] = $this->_getThumbnailUrl($videoArray, $index); /* Time published. Vimeo dates are in US Eastern Time.*/ $reset = date_default_timezone_get(); date_default_timezone_set('America/New_York'); $toReturn[tubepress_api_video_Video::ATTRIBUTE_TIME_PUBLISHED_UNIXTIME] = strtotime($videoArray[$index]->upload_date); $toReturn[tubepress_api_video_Video::ATTRIBUTE_TIME_PUBLISHED_FORMATTED] = $this->unixTimeToHumanReadable($toReturn[tubepress_api_video_Video::ATTRIBUTE_TIME_PUBLISHED_UNIXTIME]); date_default_timezone_set($reset); /* Title. */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_TITLE] = $videoArray[$index]->title; /* Views. */ if (isset($videoArray[$index]->number_of_plays)) { $toReturn[tubepress_api_video_Video::ATTRIBUTE_VIEW_COUNT] = number_format($videoArray[$index]->number_of_plays); } return $toReturn; }
public function onEmbeddedTemplate(tubepress_api_event_EventInterface $event) { $implName = $event->getArgument('embeddedImplementationName'); if ($implName !== 'longtail') { return; } $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $template = $event->getSubject(); $toSet = array(tubepress_addons_jwplayer_api_const_template_Variable::COLOR_FRONT => tubepress_addons_jwplayer_api_const_options_names_Embedded::COLOR_FRONT, tubepress_addons_jwplayer_api_const_template_Variable::COLOR_LIGHT => tubepress_addons_jwplayer_api_const_options_names_Embedded::COLOR_LIGHT, tubepress_addons_jwplayer_api_const_template_Variable::COLOR_SCREEN => tubepress_addons_jwplayer_api_const_options_names_Embedded::COLOR_SCREEN, tubepress_addons_jwplayer_api_const_template_Variable::COLOR_BACK => tubepress_addons_jwplayer_api_const_options_names_Embedded::COLOR_BACK); foreach ($toSet as $templateVariableName => $optionName) { $template->setVariable($templateVariableName, $context->get($optionName)); } }
public function onSingleVideoTemplate(tubepress_api_event_EventInterface $event) { $video = $event->getArgument('video'); $template = $event->getSubject(); $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $embedded = tubepress_impl_patterns_sl_ServiceLocator::getEmbeddedHtmlGenerator(); $embeddedString = $embedded->getHtml($video->getId()); $width = $context->get(tubepress_api_const_options_names_Embedded::EMBEDDED_WIDTH); /* apply it to the template */ $template->setVariable(tubepress_api_const_template_Variable::EMBEDDED_SOURCE, $embeddedString); $template->setVariable(tubepress_api_const_template_Variable::EMBEDDED_WIDTH, $width); $template->setVariable(tubepress_api_const_template_Variable::VIDEO, $video); }
/** * Build a map of attribute names => attribute values for the video construction event. * * @param tubepress_api_event_EventInterface $event The video construction event. * * @return array An associative array of attribute names => attribute values */ protected final function buildAttributeMap(tubepress_api_event_EventInterface $event) { $toReturn = array(); $xpath = $event->getArgument('xPath'); $index = $event->getArgument('zeroBasedFeedIndex'); /* Author */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_AUTHOR_DISPLAY_NAME] = $this->_relativeQuery($xpath, $index, 'atom:author/atom:name')->item(0)->nodeValue; $toReturn[tubepress_api_video_Video::ATTRIBUTE_AUTHOR_USER_ID] = $toReturn[tubepress_api_video_Video::ATTRIBUTE_AUTHOR_DISPLAY_NAME]; /* Category */ /** @noinspection PhpUndefinedMethodInspection */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_CATEGORY_DISPLAY_NAME] = trim($this->_relativeQuery($xpath, $index, 'media:group/media:category')->item(0)->getAttribute('label')); /* Description */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_DESCRIPTION] = $this->trimDescription($this->_relativeQuery($xpath, $index, 'media:group/media:description')->item(0)->nodeValue); /* Duration */ /** @noinspection PhpUndefinedMethodInspection */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_DURATION_SECONDS] = $this->_relativeQuery($xpath, $index, 'media:group/yt:duration')->item(0)->getAttribute('seconds'); $toReturn[tubepress_api_video_Video::ATTRIBUTE_DURATION_FORMATTED] = tubepress_impl_util_TimeUtils::secondsToHumanTime($toReturn[tubepress_api_video_Video::ATTRIBUTE_DURATION_SECONDS]); /* Home URL */ /** @noinspection PhpUndefinedMethodInspection */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_HOME_URL] = $this->_relativeQuery($xpath, $index, "atom:link[@rel='alternate']")->item(0)->getAttribute('href'); /* ID */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_ID] = $this->_relativeQuery($xpath, $index, 'media:group/yt:videoid')->item(0)->nodeValue; /* Keywords. */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_KEYWORD_ARRAY] = array(); /* Rating */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_RATING_AVERAGE] = $this->_getRatingAverage($xpath, $index); $toReturn[tubepress_api_video_Video::ATTRIBUTE_RATING_COUNT] = $this->_getRatingCount($xpath, $index); /* Thumbnail. */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_THUMBNAIL_URL] = $this->pickThumbnailUrl($this->_getThumbnailUrls($xpath, $index)); /* Time published. */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_TIME_PUBLISHED_UNIXTIME] = $this->_getTimePublishedUnixTime($xpath, $index); $toReturn[tubepress_api_video_Video::ATTRIBUTE_TIME_PUBLISHED_FORMATTED] = $this->unixTimeToHumanReadable($toReturn[tubepress_api_video_Video::ATTRIBUTE_TIME_PUBLISHED_UNIXTIME]); /* Title. */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_TITLE] = $this->_relativeQuery($xpath, $index, 'atom:title')->item(0)->nodeValue; /* Views. */ $toReturn[tubepress_api_video_Video::ATTRIBUTE_VIEW_COUNT] = $this->fancyNumber($this->_getRawViewCount($xpath, $index)); return $toReturn; }
/** * Build a map of attribute names => attribute values for the video construction event. * * @param tubepress_api_event_EventInterface $event The video construction event. * * @return array An associative array of attribute names => attribute values */ protected function buildAttributeMap(tubepress_api_event_EventInterface $event) { $toReturn = array(); $index = $event->getArgument('zeroBasedIndex'); $mediaItemArray = $event->getArgument('videoArray'); /* Author */ $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_AUTHOR_DISPLAY_NAME] = $mediaItemArray[$index]['user']['name']; $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_AUTHOR_USER_ID] = substr($mediaItemArray[$index]['user']['uri'], strlen('/users/')); $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_AUTHOR_URL] = $mediaItemArray[$index]['user']['link']; /* Description */ $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_DESCRIPTION] = $mediaItemArray[$index]['description']; /* Duration */ $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_DURATION_SECONDS] = $mediaItemArray[$index]['duration']; /* Home URL */ $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_HOME_URL] = 'https://vimeo.com/' . substr($mediaItemArray[$index]['uri'], strlen('/videos/')); /* Keywords */ $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_KEYWORD_ARRAY] = $this->_gatherArrayOfContent($mediaItemArray[$index], 'tags', 'tag'); /* Likes. */ if (isset($mediaItemArray[$index]['stats']['likes'])) { $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_LIKES_COUNT] = $mediaItemArray[$index]['stats']['likes']; } /* Thumbnail. */ $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_THUMBNAIL_URL] = $this->_getThumbnailUrl($mediaItemArray, $index); /* Time published. Vimeo dates are in US Eastern Time.*/ $reset = date_default_timezone_get(); date_default_timezone_set('America/New_York'); $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_TIME_PUBLISHED_UNIXTIME] = strtotime($mediaItemArray[$index]['created_time']); date_default_timezone_set($reset); /* Title. */ $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_TITLE] = $mediaItemArray[$index]['name']; /* Views. */ if (isset($mediaItemArray[$index]['stats']['plays'])) { $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_VIEW_COUNT] = $mediaItemArray[$index]['stats']['plays']; } /* ID */ $toReturn[tubepress_api_media_MediaItem::ATTRIBUTE_ID] = substr($mediaItemArray[$index]['uri'], strlen('/videos/')); return $toReturn; }
public function onOption(tubepress_api_event_EventInterface $event) { $incoming = (string) $event->getArgument('optionValue'); $final = $this->_transformer->transform($incoming); if (!$final && !$this->_allowEmpty) { $errors = $event->getSubject(); $errors[] = $this->_errorMessage; $event->setSubject($errors); } else { if ($incoming !== $final) { $event->setArgument('optionValue', $final); } } }
public function onOption(tubepress_api_event_EventInterface $event) { $errors = $event->getSubject(); $optionName = $event->getArgument('optionName'); $optionValue = $event->getArgument('optionValue'); if (!$this->_optionsReference->optionExists($optionName)) { $error = $this->_translator->trans('No option with name "%s".'); //>(translatable)< $error = sprintf($error, $optionName); $errors[] = $error; $event->setSubject($errors); return; } if ($this->_optionsReference->isBoolean($optionName) && !is_bool($optionValue)) { $error = $this->_translator->trans('"%s" can only be "true" or "false". You supplied "%s".'); //>(translatable)< $error = sprintf($error, $this->_getLabel($optionName), $optionValue); $errors[] = $error; $event->setSubject($errors); return; } $acceptableValues = $this->_acceptableValues->getAcceptableValues($optionName); if ($acceptableValues !== null) { if ($this->_langUtils->isAssociativeArray($acceptableValues)) { $values = array_keys($acceptableValues); } else { $values = array_values($acceptableValues); } if (!in_array($optionValue, $values)) { $error = $this->_translator->trans('"%s" must be one of "%s". You supplied "%s".'); //>(translatable)< $error = sprintf($error, $this->_getLabel($optionName), implode(', ', $values), $optionValue); $errors[] = $error; $event->setSubject($errors); } } }
public function onGalleryTemplate(tubepress_api_event_EventInterface $event) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $videoGalleryPage = $event->getArgument('videoGalleryPage'); $template = $event->getSubject(); $videoArray = $videoGalleryPage->getVideos(); $thumbWidth = $context->get(tubepress_api_const_options_names_Thumbs::THUMB_WIDTH); $thumbHeight = $context->get(tubepress_api_const_options_names_Thumbs::THUMB_HEIGHT); $galleryId = $context->get(tubepress_api_const_options_names_Advanced::GALLERY_ID); /* add some core template variables */ $template->setVariable(tubepress_api_const_template_Variable::VIDEO_ARRAY, $videoArray); $template->setVariable(tubepress_api_const_template_Variable::GALLERY_ID, $galleryId); $template->setVariable(tubepress_api_const_template_Variable::THUMBNAIL_WIDTH, $thumbWidth); $template->setVariable(tubepress_api_const_template_Variable::THUMBNAIL_HEIGHT, $thumbHeight); }
/** * Build a map of attribute names => attribute values for the video construction event. * * @param tubepress_api_event_EventInterface $event The video construction event. * * @return array An associative array of attribute names => attribute values */ private function _buildAttributeMap(tubepress_api_event_EventInterface $event) { $toReturn = array(); $metadata = $event->getArgument('metadataAsArray'); $index = $event->getArgument('zeroBasedIndex'); // starts at 0 $this->_applyTimePublished($toReturn, $metadata, $index); $this->_applyAuthor($toReturn, $metadata, $index); $this->_applyTitle($toReturn, $metadata, $index); $this->_applyDescription($toReturn, $metadata, $index); $this->_applyThumbnail($toReturn, $metadata, $index); $this->_applyKeywords($toReturn, $metadata, $index); $this->_applyDuration($toReturn, $metadata, $index); $this->_applyHomeUrl($event->getSubject(), $toReturn); $this->_applyViewCount($toReturn, $metadata, $index); $this->_applyLikes($toReturn, $metadata, $index); $this->_applyDislikes($toReturn, $metadata, $index); $this->_applyFavorites($toReturn, $metadata, $index); $this->_applyComments($toReturn, $metadata, $index); if ($this->_context->get(tubepress_api_options_Names::META_DISPLAY_CATEGORY)) { $this->_applyCategory($toReturn, $metadata, $index); } return $toReturn; }
public function onOption(tubepress_api_event_EventInterface $event) { $optionValue = $event->getArgument('optionValue'); if (!is_scalar($optionValue)) { return; } if ($this->_ltrim) { $optionValue = ltrim($optionValue, $this->_charlist); } else { if ($this->_rtrim) { $optionValue = rtrim($optionValue, $this->_charlist); } else { $optionValue = trim($optionValue, $this->_charlist); } } $event->setArgument('optionValue', $optionValue); }
public function onGalleryTemplate(tubepress_api_event_EventInterface $event) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $pm = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher(); $providerResult = $event->getArgument('videoGalleryPage'); $template = $event->getSubject(); $pagination = $this->_getHtml($providerResult->getTotalResultCount()); $event = new tubepress_spi_event_EventBase($pagination); $pm->dispatch(tubepress_api_const_event_EventNames::HTML_PAGINATION, $event); $pagination = $event->getSubject(); if ($context->get(tubepress_api_const_options_names_Thumbs::PAGINATE_ABOVE)) { $template->setVariable(tubepress_api_const_template_Variable::PAGINATION_TOP, $pagination); } if ($context->get(tubepress_api_const_options_names_Thumbs::PAGINATE_BELOW)) { $template->setVariable(tubepress_api_const_template_Variable::PAGINATION_BOTTOM, $pagination); } }
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; } } }
public function onMediaPageRequest(tubepress_api_event_EventInterface $event) { $source = $event->getSubject(); $provider = null; foreach ($this->_mediaProviders as $mediaProvider) { $sources = $mediaProvider->getGallerySourceNames(); if (in_array($source, $sources)) { $provider = $mediaProvider; break; } } if ($provider === null) { return; } $page = $provider->collectPage($event->getArgument('pageNumber')); foreach ($page->getItems() as $mediaItem) { $mediaItem->setAttribute(tubepress_api_media_MediaItem::ATTRIBUTE_PROVIDER, $provider); } $event->setArgument('mediaPage', $page); }
public function onPreValidationSet(tubepress_api_event_EventInterface $event) { $themeValue = $event->getArgument('optionValue'); $shouldLog = $this->_logger->isEnabled(); if (in_array($themeValue, self::$_LEGACY_THEME_VALUES)) { if ($shouldLog) { $this->_logger->debug(sprintf('Renaming theme value from %s to tubepress/legacy-%s', $themeValue, $themeValue)); } $event->setArgument('optionValue', "tubepress/legacy-{$themeValue}"); return; } $allThemes = $this->_themeRegistry->getAll(); foreach ($allThemes as $theme) { if ($theme->getName() !== "unknown/legacy-{$themeValue}") { continue; } if ($shouldLog) { $this->_logger->debug(sprintf('Renaming theme value from %s to unknown/legacy-%s', $themeValue, $themeValue)); } $event->setArgument('optionValue', "unknown/legacy-{$themeValue}"); } }
public function onSet(tubepress_api_event_EventInterface $event) { $value = $event->getArgument('optionValue'); $this->_magic($value); $event->setArgument('optionValue', $value); }
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); }
public function onGroupValue(tubepress_api_event_EventInterface $event) { $filteredValue = $this->_maybeConvertUrl($event->getArgument('optionValue'), 'groups'); $event->setArgument('optionValue', $filteredValue); }