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);
 }
示例#2
0
 public function onAcceptableValues(tubepress_api_event_EventInterface $event)
 {
     $tokens = $this->_persistence->fetch(tubepress_api_options_Names::OAUTH2_TOKENS);
     $decoded = json_decode($tokens, true);
     $toSet = is_array($decoded) ? array_keys($decoded) : array();
     $event->setSubject($toSet);
 }
示例#3
0
 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);
     }
 }
示例#4
0
 public function onScriptsStylesTemplatePreRender(tubepress_api_event_EventInterface $event)
 {
     $templateVars = $event->getSubject();
     if (is_array($templateVars)) {
         $templateVars['urls'] = array();
         $event->setSubject($templateVars);
     }
 }
 public function onAcceptableValues(tubepress_api_event_EventInterface $event)
 {
     $current = $event->getSubject();
     if (!is_array($current)) {
         $current = array();
     }
     $event->setSubject(array_merge($current, $this->_acceptableValues));
 }
 public function onGalleryTemplatePreRender(tubepress_api_event_EventInterface $event)
 {
     $currentTemplateVars = $event->getSubject();
     $mediaPage = $currentTemplateVars['mediaPage'];
     $pagination = $this->_getHtml($mediaPage->getTotalResultCount());
     $newTemplateVars = array_merge($currentTemplateVars, array(tubepress_api_template_VariableNames::GALLERY_PAGINATION_HTML => $pagination, tubepress_api_template_VariableNames::GALLERY_PAGINATION_SHOW_TOP => (bool) $this->_context->get(tubepress_api_options_Names::GALLERY_PAGINATE_ABOVE), tubepress_api_template_VariableNames::GALLERY_PAGINATION_SHOW_BOTTOM => (bool) $this->_context->get(tubepress_api_options_Names::GALLERY_PAGINATE_BELOW)));
     $event->setSubject($newTemplateVars);
 }
 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 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);
 }
 private function _handle(tubepress_api_event_EventInterface $event, $methodName)
 {
     $current = $event->getSubject();
     if (!is_array($current)) {
         $current = array();
     }
     foreach ($this->_mediaProviders as $provider) {
         $current = array_merge($current, $provider->{$methodName}());
     }
     $event->setSubject($current);
 }
 /**
  * The following options are required by JS, so we explicity set them:
  *
  *  ajaxPagination
  *  autoNext
  *  embeddedHeight
  *  embeddedWidth
  *  fluidThumbs
  *  httpMethod
  *  playerLocation
  *
  * The following options are JS-specific
  *
  *  playerJsUrl
  *  playerLocationProducesHtml
  *
  * Otherwise, we simply set any "custom" options so they can be passed back in via Ajax operations.
  */
 public function onGalleryInitJs(tubepress_api_event_EventInterface $event)
 {
     $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $args = $event->getSubject();
     $requiredNvpMap = $this->_buildRequiredNvpMap($context);
     $jsMap = $this->_buildJsMap($context);
     $customNvpMap = $context->getCustomOptions();
     $nvpMap = array_merge($requiredNvpMap, $customNvpMap);
     $newArgs = array(self::$_PROPERTY_NVPMAP => tubepress_impl_context_MemoryExecutionContext::convertBooleans($nvpMap), self::$_PROPERTY_JSMAP => tubepress_impl_context_MemoryExecutionContext::convertBooleans($jsMap));
     $event->setSubject(array_merge($args, $newArgs));
 }
示例#11
0
 /**
  * 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);
 }
示例#12
0
    public function onPreScriptsHtml(tubepress_api_event_EventInterface $event)
    {
        $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher();
        $jsEvent = new tubepress_spi_event_EventBase(array());
        $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::CSS_JS_GLOBAL_JS_CONFIG, $jsEvent);
        $args = $jsEvent->getSubject();
        $asJson = json_encode($args);
        $html = $event->getSubject();
        $toPrepend = <<<EOT
<script type="text/javascript">var TubePressJsConfig = {$asJson};</script>
EOT;
        $event->setSubject($toPrepend . $html);
    }
示例#13
0
 public function onPreTemplate(tubepress_api_event_EventInterface $event)
 {
     /*
      * @var array
      */
     $templateVars = $event->getSubject();
     if (!is_array($templateVars)) {
         $templateVars = array();
     }
     $vars = array(tubepress_api_template_VariableNames::MEDIA_ITEM_ATTRIBUTE_LABELS => $this->_getLabelMap(), tubepress_api_template_VariableNames::MEDIA_ITEM_ATTRIBUTES_TO_SHOW => $this->_getToShowMap());
     $templateVars = array_merge($templateVars, $vars);
     $event->setSubject($templateVars);
 }
 public function onJsConfig(tubepress_api_event_EventInterface $event)
 {
     /**
      * @var $config array
      */
     $config = $event->getSubject();
     $environmentDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector();
     if (!isset($config['urls'])) {
         $config['urls'] = array();
     }
     $config['urls']['base'] = $environmentDetector->getBaseUrl();
     $config['urls']['usr'] = $environmentDetector->getUserContentUrl();
     $event->setSubject($config);
 }
 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();
     }
 }
示例#16
0
 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);
         }
     }
 }
示例#17
0
 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 magic(tubepress_api_event_EventInterface $event)
 {
     $value = $event->getSubject();
     /** If it's an array, send each element through the filter. */
     if (is_array($value)) {
         foreach ($value as $key => $subValue) {
             $subEvent = new tubepress_spi_event_EventBase($subValue);
             $subEvent->setArgument('optionName', $key);
             $this->magic($subEvent);
             $value[$key] = $subEvent->getSubject();
         }
         $event->setSubject($value);
         return;
     }
     /** We're only interested in strings. */
     if (!is_string($value)) {
         return;
     }
     $toReturn = trim($value);
     $toReturn = htmlspecialchars($toReturn, ENT_NOQUOTES);
     $toReturn = tubepress_impl_util_StringUtils::stripslashes_deep($toReturn);
     $toReturn = $this->_booleanMagic($toReturn);
     $event->setSubject($toReturn);
 }
 public function onAcceptableValues(tubepress_api_event_EventInterface $event)
 {
     $current = $event->getSubject();
     if (!is_array($current)) {
         $current = array();
     }
     $result = array();
     $allThemes = $this->_themeRegistry->getAll();
     foreach ($allThemes as $theme) {
         $result[$theme->getName()] = $theme->getTitle();
     }
     ksort($result);
     $toSet = array_merge($current, $result);
     $event->setSubject($toSet);
 }
示例#20
0
 public function onGalleryInitJs(tubepress_api_event_EventInterface $event)
 {
     $args = $event->getSubject();
     if (!isset($args[self::$_OPTIONS][tubepress_api_options_Names::EMBEDDED_PLAYER_IMPL])) {
         return;
     }
     $implementation = $args[self::$_OPTIONS][tubepress_api_options_Names::EMBEDDED_PLAYER_IMPL];
     if ($implementation !== 'embedplus') {
         return;
     }
     $existingHeight = $args[self::$_OPTIONS][tubepress_api_options_Names::EMBEDDED_HEIGHT];
     $newHeight = intval($existingHeight) + 30;
     $args[self::$_OPTIONS][tubepress_api_options_Names::EMBEDDED_HEIGHT] = $newHeight;
     $event->setSubject($args);
 }
 public function onAdminScripts(tubepress_api_event_EventInterface $event)
 {
     $urls = $event->getSubject();
     if (!$this->_isIE8OrLower() || !$this->_containsBootstrap($urls)) {
         return;
     }
     $baseUrl = $this->_environment->getBaseUrl()->getClone();
     $baseUrl->setPath('/web/admin-themes/admin-default/vendor/respond-1.4.2/respond.min.js');
     $baseUrl->freeze();
     array_unshift($urls, $baseUrl);
     $baseUrl = $baseUrl->getClone();
     $baseUrl->setPath('/web/admin-themes/admin-default/vendor/html5-shiv-3.7.0/html5shiv.js');
     $baseUrl->freeze();
     array_unshift($urls, $baseUrl);
     $event->setSubject($urls);
 }
示例#22
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;
         }
     }
 }
示例#23
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();
 }
    public function onGalleryHtml(tubepress_api_event_EventInterface $event)
    {
        $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
        $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher();
        $galleryId = $context->get(tubepress_api_const_options_names_Advanced::GALLERY_ID);
        $jsEvent = new tubepress_spi_event_EventBase(array());
        $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::CSS_JS_GALLERY_INIT, $jsEvent);
        $args = $jsEvent->getSubject();
        $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);
    }
示例#25
0
 public function onExternalInput(tubepress_api_event_EventInterface $event)
 {
     $value = $event->getSubject();
     $this->_magic($value);
     $event->setSubject($value);
 }
 /**
  * This listener has several very important tasks:
  *
  * 1. Add the template variables:
  *      categories
  *      categoryIdToProviderIdToFieldsMap
  *      fieldProviders
  *      tubePressBaseUrl
  *      isPro
  *
  * 2. Add the multisource template vars (super complicated).
  *
  * 3. Add the field provider properties as JSON
  *
  * 4. Sort the categories.
  *
  * 5. Sort the field providers
  *
  * @param tubepress_api_event_EventInterface $event
  */
 public function onOptionsGuiTemplate(tubepress_api_event_EventInterface $event)
 {
     $templateVariables = $event->getSubject();
     //1
     $this->_addTemplateVariableCategories($templateVariables);
     $this->_addTemplateVariableCategoryIdToProviderIdToFieldsMap($templateVariables);
     $this->_addTemplateVariableFieldProviders($templateVariables);
     $this->_addTemplateVariableTubePressBaseUrl($templateVariables);
     $this->_addTemplateVariableIsPro($templateVariables);
     //2
     $this->_addTemplateVariableGallerySources($templateVariables);
     //3
     $this->_addTemplateVariableMediaProviderProperties($templateVariables);
     //4
     $this->_sortCategories($templateVariables);
     //5
     $this->_sortFieldProviders($templateVariables);
     $event->setSubject($templateVariables);
 }
 public function onBeforeCssHtml(tubepress_api_event_EventInterface $event)
 {
     $html = $event->getSubject();
     $html = $this->_addMetaTags($html);
     $event->setSubject($html);
 }
示例#28
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);
    }
 public function onJs(tubepress_api_event_EventInterface $event)
 {
     $scripts = $event->getSubject();
     unset($scripts['tubepress']);
     $event->setSubject($scripts);
 }
示例#30
0
 public function onDefaultValue(tubepress_api_event_EventInterface $event)
 {
     $event->setSubject('tubepress/wordpress');
 }