Ejemplo n.º 1
0
 private function _handleBlacklist(array &$manifestData, array &$errors)
 {
     $name = $manifestData[self::$FIRST_LEVEL_KEY_NAME];
     if (in_array($name, $this->_bootSettings->getAddonBlacklistArray())) {
         $errors[] = "{$name} is blacklisted";
     }
 }
Ejemplo n.º 2
0
 /**
  * @param string $serializedString
  *
  * @return tubepress_api_contrib_ContributableInterface[]
  *
  * @throws InvalidArgumentException
  */
 public function unserialize($serializedString)
 {
     $decoded = $serializedString;
     $encoding = $this->_bootSettings->getSerializationEncoding();
     switch ($encoding) {
         /** @noinspection PhpMissingBreakStatementInspection */
         case 'gzip-then-base64':
         case 'base64':
             $decoded = @base64_decode($serializedString);
             if ($decoded === false) {
                 throw new InvalidArgumentException('Failed to base64_decode() serialized data');
             }
             if ($encoding === 'gzip-then-base64') {
                 $decoded = gzuncompress($decoded);
                 if ($decoded === false) {
                     throw new InvalidArgumentException('Failed to gzuncompress() serialized data');
                 }
             }
             break;
         case 'urlencode':
             $decoded = urldecode($serializedString);
             break;
         default:
             break;
     }
     $unserialized = @unserialize($decoded);
     if ($unserialized === false) {
         throw new InvalidArgumentException('Failed to unserialize incoming data');
     }
     return $unserialized;
 }
Ejemplo n.º 3
0
 private function _findUserManifestPaths($userPath)
 {
     $userContentDir = $this->_bootSettings->getUserContentDirectory();
     $userContributablesDir = $userContentDir . $userPath;
     $userContributables = $this->__findManifestPathsInDirectory($userContributablesDir);
     return $userContributables;
 }
Ejemplo n.º 4
0
 private function _getCache()
 {
     $enabled = $this->_context->get(tubepress_api_options_Names::TEMPLATE_CACHE_ENABLED);
     if (!$enabled) {
         return false;
     }
     $dir = $this->_context->get(tubepress_api_options_Names::TEMPLATE_CACHE_DIR);
     if ($this->_writableDirectory($dir)) {
         return $dir;
     }
     $dir = $this->_bootSettingsInterface->getPathToSystemCacheDirectory() . DIRECTORY_SEPARATOR . '/twig';
     if ($this->_writableDirectory($dir)) {
         return $dir;
     }
     @mkdir($dir);
     if ($this->_writableDirectory($dir)) {
         return $dir;
     }
     return false;
 }
Ejemplo n.º 5
0
 public function buildFilesystemDriver()
 {
     $dir = $this->_context->get(tubepress_api_options_Names::CACHE_DIRECTORY);
     if ($this->_shouldLog) {
         $this->_logDebug(sprintf('Starting to build API cache driver. User candidate is "<code>%s</code>"', $dir));
     }
     /*
      * If a path was given, but it's not a directory, let's try to create it.
      */
     if ($dir && !is_dir($dir)) {
         if ($this->_shouldLog) {
             $this->_logDebug(sprintf('"<code>%s</code>" is not a directory. Let\'s try to create it...', $dir));
         }
         @mkdir($dir, 0755, true);
     }
     /*
      * If the directory exists, but isn't writable, let's try to change that.
      */
     if ($dir && is_dir($dir) && !is_writable($dir)) {
         if ($this->_shouldLog) {
             $this->_logDebug(sprintf('"<code>%s</code>" is a directory but we can\'t write to it. Let\'s try to change that...', $dir));
         }
         @chmod($dir, 0755);
     }
     /*
      * If we don't have a writable directory, use the system temp directory.
      */
     if (!is_dir($dir) || !is_writable($dir)) {
         if ($this->_shouldLog) {
             $this->_logDebug(sprintf('We don\'t have a directory that we can use for the API cache. Giving up and falling back to system directory.', $dir));
         }
         $dir = $this->_bootSettings->getPathToSystemCacheDirectory() . '/api-calls';
         if ($this->_shouldLog) {
             $this->_logDebug(sprintf('Final API cache directory is "<code>%s</code>"', $dir));
         }
     }
     $driver = new \Stash\Driver\FileSystem();
     $driver->setOptions(array('path' => $dir));
     return $driver;
 }
 /**
  * @param tubepress_internal_ioc_ContainerBuilder $containerBuilder
  *
  * @return \Symfony\Component\DependencyInjection\ContainerInterface
  */
 private function _convertToSymfonyContainer(tubepress_internal_ioc_ContainerBuilder $containerBuilder)
 {
     if ($this->_shouldLog) {
         $this->_logDebug('Preparing to store boot to cache.');
     }
     $dumpedContainerText = $this->_getDumpedSymfonyContainerAsString($containerBuilder->getDelegateContainerBuilder());
     if ($this->_bootSettings->isSystemCacheEnabled()) {
         $cachePath = $this->_bootSettings->getPathToSystemCacheDirectory();
         $storagePath = sprintf('%s%sTubePressServiceContainer.php', $cachePath, DIRECTORY_SEPARATOR);
     } else {
         $storagePath = tempnam(sys_get_temp_dir(), 'TubePressServiceContainer');
     }
     if (!is_dir(dirname($storagePath))) {
         if ($this->_shouldLog) {
             $this->_logDebug(sprintf('Attempting to create all the parent directories of <code>%s</code>', $storagePath));
         }
         $success = @mkdir(dirname($storagePath), 0755, true);
         if ($this->_shouldLog) {
             if ($success === true) {
                 $this->_logDebug(sprintf('Created all the parent directories of <code>%s</code>', $storagePath));
             } else {
                 $this->_logger->error(sprintf('Failed to create all the parent directories of <code>%s</code>', $storagePath));
             }
         }
         if ($success !== true) {
             return $containerBuilder->getDelegateContainerBuilder();
         }
     }
     if ($this->_shouldLog) {
         $this->_logDebug(sprintf('Now writing dumped container to <code>%s</code>', $storagePath));
     }
     $success = @file_put_contents($storagePath, $dumpedContainerText) !== false;
     if ($success) {
         if ($this->_shouldLog) {
             $this->_logDebug(sprintf('Saved service container to <code>%s</code>. Now including it.', $storagePath));
         }
         if (!class_exists('TubePressServiceContainer', false)) {
             /** @noinspection PhpIncludeInspection */
             require $storagePath;
         }
     } else {
         if ($this->_shouldLog) {
             $this->_logger->error(sprintf('Could not write service container to <code>%s</code>.', $storagePath));
         }
         return $containerBuilder->getDelegateContainerBuilder();
     }
     /** @noinspection PhpUndefinedClassInspection */
     return new TubePressServiceContainer();
 }
Ejemplo n.º 7
0
 private function _clearSystemCache()
 {
     if (!class_exists('\\Symfony\\Component\\Filesystem\\Filesystem', false)) {
         require TUBEPRESS_ROOT . '/vendor/symfony/filesystem/Filesystem.php';
         require TUBEPRESS_ROOT . '/vendor/symfony/filesystem/Exception/ExceptionInterface.php';
         require TUBEPRESS_ROOT . '/vendor/symfony/filesystem/Exception/IOExceptionInterface.php';
         require TUBEPRESS_ROOT . '/vendor/symfony/filesystem/Exception/IOException.php';
         require TUBEPRESS_ROOT . '/vendor/symfony/filesystem/Exception/FileNotFoundException.php';
     }
     $dir = $this->_bootSettings->getPathToSystemCacheDirectory();
     $filesystem = new \Symfony\Component\Filesystem\Filesystem();
     if ($this->_bootLogger->isEnabled()) {
         $this->_logDebug(sprintf('System cache clear requested. Attempting to recursively delete <code>%s</code>', $dir));
     }
     $filesystem->remove($dir);
     $filesystem->mkdir($dir, 0755);
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function getAjaxEndpointUrl()
 {
     if (!$this->_properties->containsKey(self::$_PROPERTY_URL_AJAX)) {
         /*
          * See if it was defined in boot settings.
          */
         $fromBootSettings = $this->_bootSettings->getUrlAjaxEndpoint();
         if ($fromBootSettings) {
             $this->_properties->put(self::$_PROPERTY_URL_AJAX, $fromBootSettings);
             return $fromBootSettings;
         }
         if ($this->_isWordPress()) {
             $url = $this->_wpFunctionsInterface->admin_url('admin-ajax.php');
         } else {
             $url = $this->getBaseUrl()->getClone()->setPath('/web/php/ajaxEndpoint.php');
         }
         $url = $this->_toUrl($url);
         $this->_properties->put(self::$_PROPERTY_URL_AJAX, $url);
     }
     return $this->_properties->get(self::$_PROPERTY_URL_AJAX);
 }
Ejemplo n.º 9
0
 private function _getPathToContainerCacheFile()
 {
     $cachePath = $this->_bootSettings->getPathToSystemCacheDirectory();
     return sprintf('%s%sTubePressServiceContainer.php', $cachePath, DIRECTORY_SEPARATOR);
 }
Ejemplo n.º 10
0
 private function _findUserLegacyThemes(tubepress_api_boot_BootSettingsInterface $bootSettings, tubepress_api_ioc_ContainerBuilderInterface $containerBuilder)
 {
     $userThemeDir = $bootSettings->getUserContentDirectory() . '/themes';
     if (!is_dir($userThemeDir)) {
         return array();
     }
     /**
      * @var tubepress_internal_finder_FinderFactory
      */
     $finderFactory = $containerBuilder->get('finder_factory');
     $finder = $finderFactory->createFinder()->directories()->in($userThemeDir)->depth('< 1');
     $toReturn = array();
     /**
      * @var SplFileInfo
      */
     foreach ($finder as $candidateLegacyThemeDir) {
         $themeRoot = "{$candidateLegacyThemeDir}";
         $baseName = basename($themeRoot);
         if ($baseName === 'starter') {
             /*
              * Ignore the starter theme.
              */
             continue;
         }
         if (is_file("{$themeRoot}/theme.json")) {
             continue;
         }
         /**
          * @var tubepress_internal_boot_helper_uncached_contrib_ThemeFactory
          */
         $themeFactory = $containerBuilder->get('tubepress_internal_boot_helper_uncached_contrib_ThemeFactory');
         $templateMap = $this->_getTemplateMapForLegacyDirectory($containerBuilder, $themeRoot);
         $manifestPath = $bootSettings->getPathToSystemCacheDirectory() . DIRECTORY_SEPARATOR . 'foobar';
         $manifestData = array('name' => "unknown/legacy-{$baseName}", 'version' => '1.0.0', 'title' => "{$baseName} (legacy)", 'authors' => array(array('name' => 'Unknown')), 'license' => array('type' => 'MPL-2.0', 'urls' => array('http://www.mozilla.org/MPL/2.0/')), 'description' => "TubePress 3.x.x theme auto-generated from {$themeRoot}");
         $theme = $themeFactory->fromManifestData($manifestPath, $manifestData);
         if (!$theme instanceof tubepress_internal_theme_FilesystemTheme) {
             continue;
         }
         $theme->setParentThemeName('tubepress/legacy-default');
         $theme->setTemplateNamesToAbsPathsMap($templateMap);
         $theme->setManifestPath($manifestPath);
         $toReturn[] = $theme;
     }
     return $toReturn;
 }