/**
  * @return array An associative array of template variables for this field.
  */
 protected function getTemplateVariables()
 {
     $storage = tubepress_impl_patterns_sl_ServiceLocator::getOptionStorageManager();
     $id = $this->getId();
     $value = $this->convertStorageFormatToStringValueForHTML($storage->fetch($id));
     return array_merge(array('id' => $id, 'value' => $value), $this->getAdditionalTemplateVariables());
 }
 /**
  * @param string $videoId The video ID to play.
  *
  * @return ehough_curly_Url The URL of the data for this video.
  */
 public final function getDataUrlForVideo($videoId)
 {
     $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $link = new ehough_curly_Url('https://www.youtube.com/embed/' . $videoId);
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getQueryStringService();
     $url = new ehough_curly_Url($qss->getFullUrl($_SERVER));
     $origin = $url->getScheme() . '://' . $url->getHost();
     $autoPlay = $context->get(tubepress_api_const_options_names_Embedded::AUTOPLAY);
     $loop = $context->get(tubepress_api_const_options_names_Embedded::LOOP);
     $showInfo = $context->get(tubepress_api_const_options_names_Embedded::SHOW_INFO);
     $autoHide = $context->get(tubepress_addons_youtube_api_const_options_names_Embedded::AUTOHIDE);
     $enableJsApi = $context->get(tubepress_api_const_options_names_Embedded::ENABLE_JS_API);
     $fullscreen = $context->get(tubepress_addons_youtube_api_const_options_names_Embedded::FULLSCREEN);
     $modestBranding = $context->get(tubepress_addons_youtube_api_const_options_names_Embedded::MODEST_BRANDING);
     $showRelated = $context->get(tubepress_addons_youtube_api_const_options_names_Embedded::SHOW_RELATED);
     $link->setQueryVariable('wmode', 'opaque');
     $link->setQueryVariable('autohide', $this->_getAutoHideValue($autoHide));
     $link->setQueryVariable('autoplay', tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($autoPlay));
     $link->setQueryVariable('enablejsapi', tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($enableJsApi));
     $link->setQueryVariable('fs', tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($fullscreen));
     $link->setQueryVariable('loop', tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($loop));
     $link->setQueryVariable('modestbranding', tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($modestBranding));
     $link->setQueryVariable('rel', tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($showRelated));
     $link->setQueryVariable('showinfo', tubepress_impl_embedded_EmbeddedPlayerUtils::booleanToOneOrZero($showInfo));
     $link->setQueryVariable('origin', $origin);
     return $link;
 }
 private function _getFromCache($url, tubepress_spi_context_ExecutionContext $context, $isDebugEnabled)
 {
     /**
      * @var $cache ehough_stash_interfaces_PoolInterface
      */
     $cache = tubepress_impl_patterns_sl_ServiceLocator::getCacheService();
     if ($isDebugEnabled) {
         $this->_logger->debug(sprintf('First asking cache for <a href="%s">URL</a>', $url));
     }
     $cacheKey = $this->_urlToCacheKey($url);
     $result = $cache->getItem($cacheKey);
     if ($result && !$result->isMiss()) {
         if ($isDebugEnabled) {
             $this->_logger->debug(sprintf('Cache has <a href="%s">URL</a>. Sweet.', $url));
         }
     } else {
         if ($isDebugEnabled) {
             $this->_logger->debug(sprintf('Cache does not have <a href="%s">URL</a>. We\'ll have to get it from the network.', $url));
         }
         $data = $this->_getFromNetwork($url);
         $storedSuccessfully = $result->set($data, $context->get(tubepress_api_const_options_names_Cache::CACHE_LIFETIME_SECONDS));
         if (!$storedSuccessfully) {
             if ($isDebugEnabled) {
                 $this->_logger->debug('Unable to store data to cache');
             }
             return $data;
         }
     }
     return $result->get();
 }
 protected function getAdditionalTemplateVariables()
 {
     $ms = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     $cancelText = $ms->_('cancel');
     $chooseText = $ms->_('Choose');
     return array('preferredFormat' => $this->_preferredFormat, 'showAlpha' => $this->_showAlpha, 'showInput' => $this->_showInput, 'showPalette' => $this->_showSelectionPalette, 'cancelText' => $cancelText, 'chooseText' => $chooseText);
 }
 protected function getStatusCodeToHtmlMap()
 {
     $executionContext = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $player = tubepress_impl_patterns_sl_ServiceLocator::getPlayerHtmlGenerator();
     $provider = tubepress_impl_patterns_sl_ServiceLocator::getVideoCollector();
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $isDebugEnabled = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     if ($isDebugEnabled) {
         $this->_logger->debug('Handling incoming request. First parsing shortcode.');
     }
     $nvpMap = $qss->getAllParams();
     $videoId = $qss->getParamValue(tubepress_spi_const_http_ParamName::VIDEO);
     if ($isDebugEnabled) {
         $this->_logger->debug('Requested video is ' . $videoId);
     }
     $executionContext->setCustomOptions($nvpMap);
     if ($executionContext->get(tubepress_api_const_options_names_Embedded::LAZYPLAY)) {
         $executionContext->set(tubepress_api_const_options_names_Embedded::AUTOPLAY, true);
     }
     if ($isDebugEnabled) {
         $this->_logger->debug('Now asking video collector for video ' . $videoId);
     }
     /* grab the video! */
     $video = $provider->collectSingleVideo($videoId);
     if ($video === null) {
         return array(404 => "Video {$videoId} not found");
     }
     if ($isDebugEnabled) {
         $this->_logger->debug('Video collector found video ' . $videoId . '. Sending it to browser');
     }
     $toReturn = array('title' => $video->getAttribute(tubepress_api_video_Video::ATTRIBUTE_TITLE), 'html' => $player->getHtml($video));
     return array(200 => json_encode($toReturn));
 }
 private function _dispatchErrorAndGetMessage(Exception $e)
 {
     $event = new tubepress_spi_event_EventBase($e, array('message' => $e->getMessage()));
     $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher();
     $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::ERROR_EXCEPTION_CAUGHT, $event);
     return $event->getArgument('message');
 }
 private function _getSingleVideoHtml($videoId)
 {
     $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher();
     $provider = tubepress_impl_patterns_sl_ServiceLocator::getVideoCollector();
     $themeHandler = tubepress_impl_patterns_sl_ServiceLocator::getThemeHandler();
     $template = $themeHandler->getTemplateInstance('single_video.tpl.php', TUBEPRESS_ROOT . '/src/main/resources/default-themes/default');
     /* grab the video from the provider */
     if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) {
         $this->_logger->debug(sprintf('Asking provider for video with ID %s', $videoId));
     }
     $video = $provider->collectSingleVideo($videoId);
     if ($video === null) {
         return sprintf('Video %s not found', $videoId);
         //>(translatable)<
     }
     if ($eventDispatcher->hasListeners(tubepress_api_const_event_EventNames::TEMPLATE_SINGLE_VIDEO)) {
         $event = new tubepress_spi_event_EventBase($template, array('video' => $video));
         $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::TEMPLATE_SINGLE_VIDEO, $event);
         $template = $event->getSubject();
     }
     $html = $template->toString();
     if ($eventDispatcher->hasListeners(tubepress_api_const_event_EventNames::HTML_SINGLE_VIDEO)) {
         $event = new tubepress_spi_event_EventBase($html);
         $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::HTML_SINGLE_VIDEO, $event);
         $html = $event->getSubject();
     }
     return $html;
 }
Esempio n. 8
0
 /**
  * Override point.
  *
  * Allows subclasses to further modify the description for this field.
  *
  * @param $originalDescription string The original description as calculated by AbstractField.php.
  *
  * @return string The (possibly) modified description for this field.
  */
 protected final function getModifiedDescription($originalDescription)
 {
     $environmentDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector();
     $defaultThemesPath = TUBEPRESS_ROOT . '/src/main/resources/default-themes';
     $userThemesPath = $environmentDetector->getUserContentDirectory() . '/themes';
     return sprintf($originalDescription, $userThemesPath, $defaultThemesPath);
 }
 /**
  * @return string The HTML for this shortcode handler.
  */
 public final function getHtml()
 {
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $execContext = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $rawSearchTerms = $qss->getParamValue(tubepress_spi_const_http_ParamName::SEARCH_TERMS);
     $hasSearchTerms = $rawSearchTerms != '';
     $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     /* if the user isn't searching, don't display anything */
     if (!$hasSearchTerms) {
         if ($shouldLog) {
             $this->_logger->debug('User doesn\'t appear to be searching. Will not display anything.');
         }
         return '';
     }
     if ($shouldLog) {
         $this->_logger->debug('User is searching. We\'ll handle this.');
     }
     /* who are we searching? */
     switch ($execContext->get(tubepress_api_const_options_names_InteractiveSearch::SEARCH_PROVIDER)) {
         case 'vimeo':
             $execContext->set(tubepress_api_const_options_names_Output::GALLERY_SOURCE, tubepress_addons_vimeo_api_const_options_values_GallerySourceValue::VIMEO_SEARCH);
             $execContext->set(tubepress_addons_vimeo_api_const_options_names_GallerySource::VIMEO_SEARCH_VALUE, $rawSearchTerms);
             break;
         default:
             $execContext->set(tubepress_api_const_options_names_Output::GALLERY_SOURCE, tubepress_addons_youtube_api_const_options_values_GallerySourceValue::YOUTUBE_SEARCH);
             $execContext->set(tubepress_addons_youtube_api_const_options_names_GallerySource::YOUTUBE_TAG_VALUE, $rawSearchTerms);
             break;
     }
     /* display the results as a thumb gallery */
     return $this->_thumbGalleryShortcodeHandler->getHtml();
 }
 private function _getFilePath($currentTheme, $pathToTemplate, $fallBackDirectory, $debugEnabled)
 {
     $environmentDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector();
     $userContentDirectory = $environmentDetector->getUserContentDirectory();
     /**
      * First try to load the template from system themes.
      */
     $filePath = TUBEPRESS_ROOT . "/src/main/resources/default-themes/{$currentTheme}/{$pathToTemplate}";
     if (is_readable($filePath)) {
         if ($debugEnabled) {
             $this->_logger->debug("Found {$pathToTemplate} first try at {$filePath}");
         }
         return $filePath;
     }
     if ($debugEnabled) {
         $this->_logger->debug("Didn't find {$pathToTemplate} at {$filePath}. Trying user theme directory next.");
     }
     /**
      * Next try to load the template from the user's theme directory.
      */
     $filePath = "{$userContentDirectory}/themes/{$currentTheme}/{$pathToTemplate}";
     if (is_readable($filePath)) {
         if ($debugEnabled) {
             $this->_logger->debug("Found {$pathToTemplate} in user's theme directory at {$filePath}");
         }
         return $filePath;
     }
     if ($debugEnabled) {
         $this->_logger->debug("Didn't find {$pathToTemplate} in system or user's theme directories. Falling back to {$fallBackDirectory}");
     }
     /**
      * Finally, load the template from the fallback directory.
      */
     return "{$fallBackDirectory}/{$pathToTemplate}";
 }
 private function _fireEventAndReturnSubject($eventName, $raw)
 {
     $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher();
     $event = new tubepress_spi_event_EventBase($raw);
     $eventDispatcher->dispatch($eventName, $event);
     return $event->getSubject();
 }
 /**
  * @param array  $links An array of meta links for this plugin.
  * @param string $file  The file.
  *
  * @return array The modified links
  */
 public final function modifyMetaRowLinks($links, $file)
 {
     $wordPressFunctionWrapper = tubepress_impl_patterns_sl_ServiceLocator::getService(tubepress_addons_wordpress_spi_WordPressFunctionWrapper::_);
     $plugin = $wordPressFunctionWrapper->plugin_basename(basename(TUBEPRESS_ROOT) . '/tubepress.php');
     if ($file != $plugin) {
         return $links;
     }
     return array_merge($links, array(sprintf('<a href="options-general.php?page=tubepress.php">%s</a>', $wordPressFunctionWrapper->__('Settings', 'tubepress')), sprintf('<a href="http://tubepress.com/documentation/">Documentation</a>'), sprintf('<a href="http://tubepress.com/forum/">Support</a>')));
 }
 private static function _tryToMirror($source, $dest)
 {
     $fs = tubepress_impl_patterns_sl_ServiceLocator::getFileSystem();
     try {
         $fs->mirror($source, $dest);
     } catch (Exception $e) {
         //ignore
     }
 }
 /**
  * Invoked when the element is submitted by the user.
  *
  * @return string|null A string error message to be displayed to the user, or null if no problem.
  */
 public function onSubmit()
 {
     $hrps = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $fieldName = tubepress_api_const_options_names_Output::GALLERY_SOURCE;
     if (!$hrps->hasParam($fieldName)) {
         return null;
     }
     return $this->sendToStorage($fieldName, $hrps->getParamValue($fieldName));
 }
 private function _addMetaTags($html)
 {
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $page = $qss->getParamValueAsInt(tubepress_spi_const_http_ParamName::PAGE, 1);
     if ($page > 1) {
         $html .= "\n" . '<meta name="robots" content="noindex, nofollow" />';
     }
     return $html;
 }
 /**
  * @return string The HTML for this shortcode handler.
  */
 public final function getHtml()
 {
     $execContext = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $galleryId = $execContext->get(tubepress_api_const_options_names_Advanced::GALLERY_ID);
     $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     if ($galleryId == '') {
         $galleryId = mt_rand();
         $result = $execContext->set(tubepress_api_const_options_names_Advanced::GALLERY_ID, $galleryId);
         if ($result !== true) {
             return false;
         }
     }
     if ($shouldLog) {
         $this->_logger->debug(sprintf('Starting to build thumbnail gallery %s', $galleryId));
     }
     $provider = tubepress_impl_patterns_sl_ServiceLocator::getVideoCollector();
     $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher();
     $themeHandler = tubepress_impl_patterns_sl_ServiceLocator::getThemeHandler();
     $ms = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $template = $themeHandler->getTemplateInstance('gallery.tpl.php', TUBEPRESS_ROOT . '/src/main/resources/default-themes/default');
     $page = $qss->getParamValueAsInt(tubepress_spi_const_http_ParamName::PAGE, 1);
     /* first grab the videos */
     if ($shouldLog) {
         $this->_logger->debug('Asking provider for videos');
     }
     $feedResult = $provider->collectVideoGalleryPage();
     $numVideos = sizeof($feedResult->getVideos());
     if ($shouldLog) {
         $this->_logger->debug(sprintf('Provider has delivered %d videos', $numVideos));
     }
     if ($numVideos == 0) {
         return $ms->_('No matching videos');
         //>(translatable)<
     }
     /* send the template through the listeners */
     if ($eventDispatcher->hasListeners(tubepress_api_const_event_EventNames::TEMPLATE_THUMBNAIL_GALLERY)) {
         $event = new tubepress_spi_event_EventBase($template, array('page' => $page, 'videoGalleryPage' => $feedResult));
         $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::TEMPLATE_THUMBNAIL_GALLERY, $event);
         $template = $event->getSubject();
     }
     $html = $template->toString();
     /* send gallery HTML through the listeners */
     if ($eventDispatcher->hasListeners(tubepress_api_const_event_EventNames::HTML_THUMBNAIL_GALLERY)) {
         $event = new tubepress_spi_event_EventBase($html, array('page' => $page, 'videoGalleryPage' => $feedResult));
         $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::HTML_THUMBNAIL_GALLERY, $event);
         $html = $event->getSubject();
     }
     /* we're done. tie up */
     if ($shouldLog) {
         $this->_logger->debug(sprintf('Done assembling gallery %d', $galleryId));
     }
     return $html;
 }
 /**
  * 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));
 }
 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 buildCache()
 {
     $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $dir = $context->get(tubepress_api_const_options_names_Cache::CACHE_DIR);
     if (!$dir || !is_writable($dir)) {
         @mkdir($dir, 0755, true);
     }
     if (!$dir || !is_writable($dir)) {
         $fs = tubepress_impl_patterns_sl_ServiceLocator::getFileSystem();
         $dir = $fs->getSystemTempDirectory() . DIRECTORY_SEPARATOR . 'tubepress-api-cache';
     }
     return new ehough_stash_Pool(new ehough_stash_driver_FileSystem(array('path' => $dir)));
 }
 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);
 }
Esempio n. 21
0
 protected function getAdditionalTemplateVariables()
 {
     $values = array();
     $map = $this->getOptionDescriptor()->getAcceptableValues();
     if (!tubepress_impl_util_LangUtils::isAssociativeArray($map)) {
         throw new InvalidArgumentException(sprintf('"%s" has a non-associative array set for its value map', $this->getOptionDescriptor()->getName()));
     }
     $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     foreach ($map as $key => $value) {
         $values[$key] = $messageService->_($value);
     }
     return array('choices' => $values);
 }
 /**
  * Get the HTML for pagination.
  *
  * @param int $vidCount The total number of results in this gallery
  *
  * @return string The HTML for the pagination.
  */
 private function _getHtml($vidCount)
 {
     $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext();
     $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     $qss = tubepress_impl_patterns_sl_ServiceLocator::getQueryStringService();
     $hrps = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService();
     $currentPage = $hrps->getParamValueAsInt(tubepress_spi_const_http_ParamName::PAGE, 1);
     $vidsPerPage = $context->get(tubepress_api_const_options_names_Thumbs::RESULTS_PER_PAGE);
     $newurl = new ehough_curly_Url($qss->getFullUrl($_SERVER));
     $newurl->unsetQueryVariable('tubepress_page');
     $result = $this->_diggStyle($vidCount, $messageService, $currentPage, $vidsPerPage, 1, $newurl->toString(), 'tubepress_page');
     return $result;
 }
 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));
     }
 }
Esempio n. 24
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);
    }
 /**
  * Gets the parameter value from PHP's $_GET or $_POST array.
  *
  * @param string $name The name of the parameter.
  *
  * @return mixed The raw value of the parameter. Can be anything that would
  *               otherwise be found in PHP's $_GET or $_POST array. Returns null
  *               if the parameter is not set on this request.
  */
 public final function getParamValue($name)
 {
     /** Are we sure we have it? */
     if (!$this->hasParam($name)) {
         return null;
     }
     $request = $this->_getGETandPOSTarray();
     $rawValue = $request[$name];
     $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher();
     $event = new tubepress_spi_event_EventBase($rawValue, array('optionName' => $name));
     $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::OPTIONS_NVP_READFROMEXTERNAL, $event);
     return $event->getSubject();
 }
 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);
 }
 /**
  * @param array $optionNamesToValues An associative array of option names to values.
  *
  * @return null|string Null if the save succeeded and all queued options were saved, otherwise a string error message.
  */
 protected function saveAll(array $optionNamesToValues)
 {
     $wordPressFunctionWrapperService = tubepress_impl_patterns_sl_ServiceLocator::getService(tubepress_addons_wordpress_spi_WordPressFunctionWrapper::_);
     foreach ($optionNamesToValues as $optionName => $optionValue) {
         $wordPressFunctionWrapperService->update_option(self::$_optionPrefix . $optionName, $optionValue);
     }
     /**
      * WordPress API is silly.
      *
      * http://codex.wordpress.org/Function_Reference/update_option
      */
     return null;
 }
 /**
  * @return string The widget HTML for this form element.
  */
 public function getWidgetHTML()
 {
     $templateBuilder = tubepress_impl_patterns_sl_ServiceLocator::getTemplateBuilder();
     $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher();
     $template = $templateBuilder->getNewTemplateInstance($this->getAbsolutePathToTemplate());
     $templateEvent = new tubepress_spi_event_EventBase($template);
     $templateEvent->setArgument('field', $this);
     $templateVariables = $this->getTemplateVariables();
     foreach ($templateVariables as $name => $value) {
         $template->setVariable($name, $value);
     }
     $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::OPTIONS_PAGE_FIELDTEMPLATE, $templateEvent);
     return $template->toString();
 }
 /**
  * Fetch all the option descriptors from this provider.
  *
  * @return tubepress_spi_options_OptionDescriptor[]
  */
 public function getOptionDescriptors()
 {
     $environmentDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector();
     $toReturn = array();
     if ($environmentDetector->isWordPress()) {
         $option = new tubepress_spi_options_OptionDescriptor(tubepress_addons_wordpress_api_const_options_names_WordPress::WIDGET_TITLE);
         $option->setDefaultValue('TubePress');
         $toReturn[] = $option;
         $option = new tubepress_spi_options_OptionDescriptor(tubepress_addons_wordpress_api_const_options_names_WordPress::WIDGET_SHORTCODE);
         $option->setDefaultValue('[tubepress thumbHeight=\'105\' thumbWidth=\'135\']');
         $toReturn[] = $option;
     }
     return $toReturn;
 }
Esempio n. 30
0
 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);
 }