PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/tubepress/sys/classes/org/tubepress/impl/bootstrap/TubePressBootstrapper.class.php

https://gitlab.com/endomorphosis/jeffersonsmithmayor
PHP | 189 lines | 99 code | 38 blank | 52 comment | 6 complexity | 56e65b03df53d377069dbc0dd43fce7b MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright 2006 - 2012 Eric D. Hough (http://ehough.com)
  4. *
  5. * This file is part of TubePress (http://tubepress.org)
  6. *
  7. * TubePress is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * TubePress is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with TubePress. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. class_exists('org_tubepress_impl_classloader_ClassLoader') || require dirname(__FILE__) . '/../classloader/ClassLoader.class.php';
  22. org_tubepress_impl_classloader_ClassLoader::loadClasses(array(
  23. 'org_tubepress_api_bootstrap_Bootstrapper',
  24. 'org_tubepress_api_exec_ExecutionContext',
  25. 'org_tubepress_api_const_options_names_Advanced',
  26. 'org_tubepress_api_const_options_names_GallerySource',
  27. 'org_tubepress_api_const_plugin_EventName',
  28. 'org_tubepress_api_const_plugin_FilterPoint',
  29. 'org_tubepress_api_environment_Detector',
  30. 'org_tubepress_api_filesystem_Explorer',
  31. 'org_tubepress_api_ioc_IocService',
  32. 'org_tubepress_api_options_StorageManager',
  33. 'org_tubepress_api_plugin_PluginManager',
  34. 'org_tubepress_api_theme_ThemeHandler',
  35. 'org_tubepress_impl_ioc_IocContainer',
  36. 'org_tubepress_impl_log_Log',
  37. 'TubePress'
  38. ));
  39. /**
  40. * Performs TubePress-wide initialization.
  41. */
  42. class org_tubepress_impl_bootstrap_TubePressBootstrapper implements org_tubepress_api_bootstrap_Bootstrapper
  43. {
  44. const LOG_PREFIX = 'TubePress Bootstrapper';
  45. private static $_alreadyBooted = false;
  46. /**
  47. * Performs TubePress-wide initialization.
  48. *
  49. * @return null
  50. */
  51. public function boot()
  52. {
  53. /* don't boot twice! */
  54. if (self::$_alreadyBooted) {
  55. return;
  56. }
  57. try {
  58. $this->_doBoot();
  59. } catch (Exception $e) {
  60. org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Caught exception while booting: '. $e->getMessage());
  61. }
  62. }
  63. private function _doBoot()
  64. {
  65. $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
  66. $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_);
  67. $envDetector = $ioc->get(org_tubepress_api_environment_Detector::_);
  68. $pm = $ioc->get(org_tubepress_api_plugin_PluginManager::_);
  69. $sm = $ioc->get(org_tubepress_api_options_StorageManager::_);
  70. /** Init the storage manager. */
  71. $sm->init();
  72. /* WordPress likes to keep control of the output */
  73. if ($envDetector->isWordPress()) {
  74. ob_start();
  75. }
  76. /* Turn on logging if we need to */
  77. org_tubepress_impl_log_Log::setEnabled($context->get(org_tubepress_api_const_options_names_Advanced::DEBUG_ON), $_GET);
  78. org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Booting!');
  79. /* load plugins */
  80. $this->loadSystemPlugins($ioc);
  81. $this->_loadUserPlugins($ioc);
  82. /* tell everyone we're booting */
  83. $pm->notifyListeners(org_tubepress_api_const_plugin_EventName::BOOT);
  84. /* remember that we booted. */
  85. self::$_alreadyBooted = true;
  86. }
  87. private function _loadUserPlugins(org_tubepress_api_ioc_IocService $ioc)
  88. {
  89. $pm = $ioc->get(org_tubepress_api_plugin_PluginManager::_);
  90. $fe = $ioc->get(org_tubepress_api_filesystem_Explorer::_);
  91. $th = $ioc->get(org_tubepress_api_theme_ThemeHandler::_);
  92. $pluginPath = $th->getUserContentDirectory() . '/plugins';
  93. $pluginDirs = $fe->getDirectoriesInDirectory($pluginPath, self::LOG_PREFIX);
  94. foreach ($pluginDirs as $pluginDir) {
  95. org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Examining potential plugin directory at %s', $pluginDir);
  96. $files = $fe->getFilenamesInDirectory($pluginDir, self::LOG_PREFIX);
  97. foreach ($files as $file) {
  98. if ('.php' == substr($file, -4) && is_readable($file)) {
  99. org_tubepress_impl_log_Log::log(self::LOG_PREFIX, 'Loading PHP file at <tt>%s</tt>', $file);
  100. include_once $file;
  101. }
  102. }
  103. }
  104. }
  105. /**
  106. * Load system-defined plugins.
  107. *
  108. * @param org_tubepress_api_ioc_IocService $ioc The IOC container.
  109. *
  110. * @return void
  111. */
  112. protected function loadSystemPlugins(org_tubepress_api_ioc_IocService $ioc)
  113. {
  114. $pm = $ioc->get(org_tubepress_api_plugin_PluginManager::_);
  115. /* pre validation option setting */
  116. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::OPTION_SET_PRE_VALIDATION,
  117. $ioc->get('org_tubepress_impl_plugin_filters_prevalidationoptionset_StringMagic'));
  118. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::OPTION_SET_PRE_VALIDATION,
  119. $ioc->get('org_tubepress_impl_plugin_filters_prevalidationoptionset_YouTubePlaylistPlPrefixRemover'));
  120. /* embedded template filters */
  121. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_EMBEDDED, $ioc->get('org_tubepress_impl_plugin_filters_embeddedtemplate_CoreVariables'));
  122. /* embedded HTML filters */
  123. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::HTML_EMBEDDED, $ioc->get('org_tubepress_impl_plugin_filters_embeddedhtml_PlayerJavaScriptApi'));
  124. /* gallery HTML filters */
  125. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::HTML_GALLERY, $ioc->get('org_tubepress_impl_plugin_filters_galleryhtml_GalleryJs'));
  126. /* gallery init js */
  127. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::JAVASCRIPT_GALLERYINIT, $ioc->get('org_tubepress_impl_plugin_filters_galleryinitjs_GalleryInitJsBaseParams'));
  128. /* gallery template filters */
  129. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_GALLERY, $ioc->get('org_tubepress_impl_plugin_filters_gallerytemplate_CoreVariables'));
  130. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_GALLERY, $ioc->get('org_tubepress_impl_plugin_filters_gallerytemplate_EmbeddedPlayerName'));
  131. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_GALLERY, $ioc->get('org_tubepress_impl_plugin_filters_gallerytemplate_Pagination'));
  132. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_GALLERY, $ioc->get('org_tubepress_impl_plugin_filters_gallerytemplate_Player'));
  133. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_GALLERY, $ioc->get('org_tubepress_impl_plugin_filters_gallerytemplate_VideoMeta'));
  134. /* player template filters */
  135. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_PLAYER, $ioc->get('org_tubepress_impl_plugin_filters_playertemplate_CoreVariables'));
  136. /* provider result filters */
  137. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::PROVIDER_RESULT, $ioc->get('org_tubepress_impl_plugin_filters_providerresult_ResultCountCapper'));
  138. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::PROVIDER_RESULT, $ioc->get('org_tubepress_impl_plugin_filters_providerresult_VideoBlacklist'));
  139. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::PROVIDER_RESULT, $ioc->get('org_tubepress_impl_plugin_filters_providerresult_PerPageSorter'));
  140. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::PROVIDER_RESULT, $ioc->get('org_tubepress_impl_plugin_filters_providerresult_VideoPrepender'));
  141. /* search input template filter */
  142. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_SEARCHINPUT, $ioc->get('org_tubepress_impl_plugin_filters_searchinputtemplate_CoreVariables'));
  143. /* single video template filters */
  144. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_SINGLEVIDEO, $ioc->get('org_tubepress_impl_plugin_filters_singlevideotemplate_CoreVariables'));
  145. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::TEMPLATE_SINGLEVIDEO, $ioc->get('org_tubepress_impl_plugin_filters_singlevideotemplate_VideoMeta'));
  146. /* external input filters */
  147. $pm->registerFilter(org_tubepress_api_const_plugin_FilterPoint::VARIABLE_READ_FROM_EXTERNAL_INPUT, $ioc->get('org_tubepress_impl_plugin_filters_variablereadfromexternalinput_StringMagic'));
  148. $pm->registerListener(org_tubepress_api_const_plugin_EventName::BOOT, $ioc->get('org_tubepress_impl_plugin_listeners_WordPressBoot'));
  149. $pm->registerListener(org_tubepress_api_const_plugin_EventName::BOOT, $ioc->get('org_tubepress_impl_plugin_listeners_SkeletonExistsListener'));
  150. }
  151. }