/**
  * @param array   $errors        An associative array, which may be empty, of field IDs to error messages.
  * @param boolean $justSubmitted True if the form was just submitted, false otherwise.
  *
  * @return string The HTML for the options page.
  */
 public function getHTML(array $errors = array(), $justSubmitted = false)
 {
     $templateBldr = tubepress_impl_patterns_sl_ServiceLocator::getTemplateBuilder();
     $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher();
     $environmentDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector();
     $template = $templateBldr->getNewTemplateInstance($this->_templatePath);
     $fields = $this->_buildFieldsArray();
     $categories = $this->_buildCategoriesArray();
     $categoryIdToParticipantIdToFieldsMap = $this->_buildCategoryIdToParticipantIdToFieldsMap($categories);
     $participants = $this->_buildParticipantsArray();
     if (isset($fields[tubepress_addons_core_impl_options_ui_fields_ParticipantFilterField::FIELD_ID])) {
         /**
          * @var $filterField tubepress_addons_core_impl_options_ui_fields_ParticipantFilterField
          */
         $filterField = $fields[tubepress_addons_core_impl_options_ui_fields_ParticipantFilterField::FIELD_ID];
         $filterField->setOptionsPageParticipants($this->_optionsPageParticipants);
     }
     $templateVariables = array('categories' => $categories, 'categoryIdToParticipantIdToFieldsMap' => $categoryIdToParticipantIdToFieldsMap, 'errors' => $errors, 'fields' => $fields, 'isPro' => $environmentDetector->isPro(), 'justSubmitted' => $justSubmitted, 'participants' => $participants, "successMessage" => 'Settings updated.', 'tubePressBaseUrl' => $environmentDetector->getBaseUrl(), "saveText" => 'Save');
     foreach ($templateVariables as $key => $val) {
         $template->setVariable($key, $val);
     }
     $templateEvent = new tubepress_spi_event_EventBase($template);
     $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::OPTIONS_PAGE_TEMPLATE, $templateEvent);
     return $template->toString();
 }
예제 #2
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);
 }
 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}";
 }
 /**
  * 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;
 }
예제 #5
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);
 }
 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;
 }
 public function onOptionsUiTemplate(tubepress_api_event_EventInterface $event)
 {
     /**
      * @var $template ehough_contemplate_api_Template
      */
     $template = $event->getSubject();
     $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService();
     $template->setVariable("pageTitle", $messageService->_('TubePress Options'));
     //>(translatable)<                                                                                                                                                                                                                                                                                                      //>(translatable)<
     $template->setVariable("introBlurb", $messageService->_('Here you can set the default options for TubePress. Each option here can be overridden on a per page/post basis with TubePress shortcodes. See the <a href="http://tubepress.com/documentation" target="_blank">documentation</a> for more information.'));
     //>(translatable)<
     $environmentDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector();
     $toEncode = array();
     if (!$environmentDetector->isPro()) {
         $toEncode[] = $this->_generateBox('You\'re Missing Out!', 'http://tubepress.com/snippets/wordpress/youre-missing-out.php');
     }
     $toEncode[] = $this->_generateBox('TubePress News', 'http://tubepress.com/snippets/wordpress/latest-news.php');
     $toEncode[] = $this->_generateBox('Need Help?', 'http://tubepress.com/snippets/wordpress/need-help.php');
     $template->setVariable(self::TEMPLATE_VAR_BOX_ARRAY, json_encode($toEncode));
 }
 public function onBoot(tubepress_api_event_EventInterface $event)
 {
     $environmentDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector();
     if (!$environmentDetector->isWordPress()) {
         //short circuit
         return;
     }
     $baseName = basename(TUBEPRESS_ROOT);
     /**
      * @var $wpFunctionWrapper tubepress_addons_wordpress_spi_WordPressFunctionWrapper
      */
     $wpFunctionWrapper = tubepress_impl_patterns_sl_ServiceLocator::getService(tubepress_addons_wordpress_spi_WordPressFunctionWrapper::_);
     $environmentDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector();
     /** http://code.google.com/p/tubepress/issues/detail?id=495#c2 */
     if (self::_isWordPressMuDomainMapped()) {
         $prefix = self::_getScheme($wpFunctionWrapper) . constant('COOKIE_DOMAIN') . '/wp-content';
     } else {
         $prefix = $wpFunctionWrapper->content_url();
     }
     $environmentDetector->setBaseUrl($prefix . "/plugins/{$baseName}");
     /* register the plugin's message bundles */
     $wpFunctionWrapper->load_plugin_textdomain('tubepress', false, "{$baseName}/src/main/resources/i18n");
     $contentFilter = tubepress_impl_patterns_sl_ServiceLocator::getService(tubepress_addons_wordpress_spi_ContentFilter::_);
     $jsAndCssInjector = tubepress_impl_patterns_sl_ServiceLocator::getService(tubepress_addons_wordpress_spi_FrontEndCssAndJsInjector::_);
     $wpAdminHandler = tubepress_impl_patterns_sl_ServiceLocator::getService(tubepress_addons_wordpress_spi_WpAdminHandler::_);
     $widgetHandler = tubepress_impl_patterns_sl_ServiceLocator::getService(tubepress_addons_wordpress_spi_WidgetHandler::_);
     $wpFunctionWrapper->add_filter('the_content', array($contentFilter, 'filterContent'), 10, 1);
     $wpFunctionWrapper->add_action('wp_head', array($jsAndCssInjector, 'printInHtmlHead'), 10, 1);
     $wpFunctionWrapper->add_action('init', array($jsAndCssInjector, 'registerStylesAndScripts'), 10, 1);
     $wpFunctionWrapper->add_action('admin_menu', array($wpAdminHandler, 'registerAdminMenuItem'), 10, 1);
     $wpFunctionWrapper->add_action('admin_enqueue_scripts', array($wpAdminHandler, 'registerStylesAndScripts'), 10, 1);
     $wpFunctionWrapper->add_action('admin_head', array($wpAdminHandler, 'printHeadMeta'), 10, 1);
     $wpFunctionWrapper->add_action('widgets_init', array($widgetHandler, 'registerWidget'), 10, 1);
     if (version_compare($wpFunctionWrapper->wp_version(), '2.8.alpha', '>')) {
         $filterPoint = 'plugin_row_meta';
     } else {
         $filterPoint = 'plugin_action_links';
     }
     $wpFunctionWrapper->add_filter($filterPoint, array($wpAdminHandler, 'modifyMetaRowLinks'), 10, 2);
     $wpFunctionWrapper->register_activation_hook($baseName . '/tubepress.php', array($this, '__callbackEnsureTubePressContentDirectoryExists'));
 }
 /**
  * Allows extensions to load services into the TubePress IOC container.
  *
  * @param tubepress_api_ioc_ContainerInterface $container A tubepress_api_ioc_ContainerInterface instance.
  *
  * @return void
  *
  * @api
  * @since 3.1.0
  */
 public function load(tubepress_api_ioc_ContainerInterface $container)
 {
     $environmentDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector();
     if (!$environmentDetector->isWordPress()) {
         //short circuit
         return;
     }
     /**
      * Core stuff.
      */
     $this->_registerMessageService($container);
     $this->_registerOptionsPage($container);
     $this->_registerOptionsStorageManager($container);
     /**
      * WordPress specific stuff.
      */
     $this->_registerContentFilter($container);
     $this->_registerCssAndJsInjector($container);
     $this->_registerWidgetHandler($container);
     $this->_registerWpAdminHandler($container);
     $this->_registerWpFunctionWrapper($container);
     $this->_registerPluggables($container);
     $this->_registerListeners($container);
 }
 /**
  * @return string Gets the relative path to this player location's JS init script.
  */
 public final function getPlayerJsUrl()
 {
     $environmentDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector();
     $sysUrl = $environmentDetector->getBaseUrl();
     return "{$sysUrl}/src/main/web/players/normal/normal.js";
 }
 private function _readConfig()
 {
     $envDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector();
     $userContentDirectory = $envDetector->getUserContentDirectory();
     $configFileLocation = $userContentDirectory . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'boot.json';
     if (!is_file($configFileLocation) || !is_readable($configFileLocation)) {
         if ($this->_shouldLog) {
             $this->_logger->debug(sprintf('No readable config file at %s', $configFileLocation));
         }
         return;
     }
     if ($this->_shouldLog) {
         $this->_logger->debug(sprintf('Attempting to read boot config from %s', $configFileLocation));
     }
     $contents = file_get_contents($configFileLocation);
     if ($contents === false) {
         if ($this->_shouldLog) {
             $this->_logger->warn(sprintf('Failed to read file contents of %s', $configFileLocation));
         }
         return;
     }
     $decoded = @json_decode($contents, true);
     if ($decoded === false || !is_array($decoded)) {
         if ($this->_shouldLog) {
             $this->_logger->warn(sprintf('Failed to parse %s', $configFileLocation));
         }
     }
     if ($this->_shouldLog) {
         $this->_logger->debug(sprintf('Successfully read boot config from %s', $configFileLocation));
     }
     $this->_bootConfig = $decoded;
 }
 public function _callbackGetValidThemeOptions()
 {
     $environmentDetectorService = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector();
     $fileSystemService = tubepress_impl_patterns_sl_ServiceLocator::getFileSystem();
     $fileSystemFinderFactoryService = tubepress_impl_patterns_sl_ServiceLocator::getFileSystemFinderFactory();
     $systemThemesDirectory = TUBEPRESS_ROOT . '/src/main/resources/default-themes';
     $userThemesDirectory = $environmentDetectorService->getUserContentDirectory() . '/themes';
     $directoriesToSearch = array();
     if ($fileSystemService->exists($systemThemesDirectory)) {
         $directoriesToSearch[] = $systemThemesDirectory;
     }
     if ($fileSystemService->exists($userThemesDirectory)) {
         $directoriesToSearch[] = $userThemesDirectory;
     }
     $finder = $fileSystemFinderFactoryService->createFinder();
     $finder->directories()->in($directoriesToSearch)->depth(0);
     $themeNames = array();
     /**
      * @var $themeDirectory SplFileInfo
      */
     foreach ($finder as $themeDirectory) {
         $themeNames[] = basename($themeDirectory->getBasename());
     }
     sort($themeNames);
     $toReturn = array();
     foreach ($themeNames as $themeName) {
         $toReturn[$themeName] = $themeName;
     }
     ksort($toReturn);
     return $toReturn;
 }
 private function _findUserAddons()
 {
     $environmentDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector();
     $userContentDir = $environmentDetector->getUserContentDirectory();
     $userAddonsDir = $userContentDir . '/add-ons';
     return $this->_findAddonsInDirectory($userAddonsDir);
 }
 private function _06_configureLoggingForWordPress()
 {
     $envDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector();
     /* WordPress likes to keep control of the output */
     if ($envDetector->isWordPress()) {
         ob_start();
     }
 }