/**
  * @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>')));
 }
 /**
  * @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;
 }
 /**
  * Registers all the styles and scripts for the front end.
  *
  * @return void
  */
 public final function registerStylesAndScripts()
 {
     $wordPressFunctionWrapper = tubepress_impl_patterns_sl_ServiceLocator::getService(tubepress_addons_wordpress_spi_WordPressFunctionWrapper::_);
     /* no need to queue any of this stuff up in the admin section or login page */
     if ($wordPressFunctionWrapper->is_admin() || __FILE__ === 'wp-login.php') {
         return;
     }
     $baseName = basename(TUBEPRESS_ROOT);
     $jsUrl = $wordPressFunctionWrapper->plugins_url("{$baseName}/src/main/web/js/tubepress.js", $baseName);
     $cssUrl = $wordPressFunctionWrapper->plugins_url("{$baseName}/src/main/web/css/tubepress.css", $baseName);
     $wordPressFunctionWrapper->wp_register_script('tubepress', $jsUrl);
     $wordPressFunctionWrapper->wp_register_style('tubepress', $cssUrl);
     $wordPressFunctionWrapper->wp_enqueue_script('jquery', false, array(), false, false);
     $wordPressFunctionWrapper->wp_enqueue_script('tubepress', false, array(), false, false);
     $wordPressFunctionWrapper->wp_enqueue_style('tubepress');
 }
 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'));
 }
 /**
  * Retrieves a message for TubePress
  *
  * @param string $message The message ID
  *
  * @return string The corresponding message, or "" if not found
  */
 public final function _($message)
 {
     $wordPressFunctionWrapperService = tubepress_impl_patterns_sl_ServiceLocator::getService(tubepress_addons_wordpress_spi_WordPressFunctionWrapper::_);
     return $message == '' ? '' : $wordPressFunctionWrapperService->__($message, 'tubepress');
 }
 /**
  * @return string The user content URL.
  */
 public function getUserContentUrl()
 {
     if (!isset($this->_userContentUrl)) {
         if (defined('TUBEPRESS_CONTENT_URL')) {
             $this->_userContentUrl = rtrim(TUBEPRESS_CONTENT_URL, DIRECTORY_SEPARATOR);
             return $this->_userContentUrl;
         }
         if ($this->isWordPress()) {
             /**
              * @var $wordPressFunctionWrapper tubepress_addons_wordpress_spi_WordPressFunctionWrapper
              */
             $wordPressFunctionWrapper = tubepress_impl_patterns_sl_ServiceLocator::getService(tubepress_addons_wordpress_spi_WordPressFunctionWrapper::_);
             $prefix = $wordPressFunctionWrapper->content_url();
         } else {
             $prefix = $this->getBaseUrl();
         }
         $this->_userContentUrl = $this->_urlToString($prefix . '/tubepress-content');
     }
     return $this->_userContentUrl;
 }
 private function _bootService($service, tubepress_spi_addon_Addon $addon)
 {
     if ($this->_shouldLog) {
         $this->_logger->debug(sprintf('Now loading service %s for add-on %s', $service, $addon->getName()));
     }
     try {
         $serviceInstance = tubepress_impl_patterns_sl_ServiceLocator::getService($service);
         if (!$serviceInstance) {
             $this->_logWarning(sprintf('%s is not a registered service', $service));
             return;
         }
         if (!$this->_hasValidBootMethod(new ReflectionClass(get_class($serviceInstance)))) {
             return;
         }
         if ($this->_shouldLog) {
             $this->_logger->debug(sprintf('Now calling boot() on %s for add-on %s', $service, $addon->getName()));
         }
         $serviceInstance->boot();
     } catch (Exception $e) {
         $this->_logWarning(sprintf('Caught exception when calling boot() on %s for add-on %s: %s', $service, $addon->getName(), $e->getMessage()));
     }
 }
 private static function _verifyNonce()
 {
     $wpFunctionWrapper = tubepress_impl_patterns_sl_ServiceLocator::getService(tubepress_addons_wordpress_spi_WordPressFunctionWrapper::_);
     $wpFunctionWrapper->check_admin_referer('tubepress-widget-nonce-save', 'tubepress-widget-nonce');
 }
예제 #9
0
 /**
  * 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()
 {
     $wpFunctions = tubepress_impl_patterns_sl_ServiceLocator::getService(tubepress_addons_wordpress_spi_WordPressFunctionWrapper::_);
     $wpFunctions->check_admin_referer('tubepress-save', 'tubepress-nonce');
     return null;
 }