$item) { if (substr($key, -$len) == $envName) { return $item; } } return false; } protected static function getWebPExpressContentDirWithDocRoot() { // Get relative path to wp-content // -------------------------------- self::$checking = 'Relative path to wp-content dir'; // Passed in env variable? $wpContentDirRel = self::getEnvPassedInRewriteRule('WPCONTENT'); if ($wpContentDirRel === false) { // Passed in QS? if (isset($_GET['wp-content'])) { $wpContentDirRel = SanityCheck::pathWithoutDirectoryTraversal($_GET['wp-content']); } else { // In case above fails, fall back to standard location $wpContentDirRel = 'wp-content'; } } // Check WebP Express content dir // --------------------------------- self::$checking = 'WebP Express content dir'; $webExpressContentDirAbs = SanityCheck::absPathExistsAndIsDir(self::$docRoot . '/' . $wpContentDirRel . '/webp-express'); return $webExpressContentDirAbs; } protected static function getWebPExpressContentDirNoDocRoot() { // Check wp-content // ---------------------- self::$checking = 'path to wp-content dir'; // Passed in env variable? $wpContentDirRelToPluginDir = self::getEnvPassedInRewriteRule('WE_WP_CONTENT_REL_TO_PLUGIN_DIR'); if ($wpContentDirRelToPluginDir === false) { // Passed in QS? if (isset($_GET['xwp-content-rel-to-plugin-dir'])) { $xwpContentDirRelToPluginDir = SanityCheck::noControlChars($_GET['xwp-content-rel-to-plugin-dir']); $wpContentDirRelToPluginDir = SanityCheck::pathDirectoryTraversalAllowed(substr($xwpContentDirRelToPluginDir, 1)); } else { throw new \Exception('Path to wp-content was not received'); } } // Check WebP Express content dir // --------------------------------- self::$checking = 'WebP Express content dir'; // echo 'dir:' . $wpContentDirRelToPluginDir . '
'; exit; $pathToPluginDir = dirname(dirname(dirname(__DIR__))); //echo $pathToPluginDir; exit; $webExpressContentDirAbs = SanityCheck::pathDirectoryTraversalAllowed($pathToPluginDir . '/' . $wpContentDirRelToPluginDir . '/webp-express'); //echo $webExpressContentDirAbs; exit; if (@!file_exists($webExpressContentDirAbs)) { throw new \Exception('Dir not found'); } $webExpressContentDirAbs = @realpath($webExpressContentDirAbs); if ($webExpressContentDirAbs === false) { throw new \Exception('WebP Express content dir is outside restricted open_basedir!'); } return $webExpressContentDirAbs; } protected static function getImageRootsDef() { if (!isset(self::$wodOptions['image-roots'])) { throw new \Exception('No image roots defined in config.'); } return new ImageRoots(self::$wodOptions['image-roots']); } protected static function loadConfig() { $usingDocRoot = !( isset($_GET['xwp-content-rel-to-plugin-dir']) || self::getEnvPassedInRewriteRule('WE_WP_CONTENT_REL_TO_PLUGIN_DIR') ); self::$usingDocRoot = $usingDocRoot; if ($usingDocRoot) { // Check DOCUMENT_ROOT // ---------------------- self::$checking = 'DOCUMENT_ROOT'; $docRootAvailable = PathHelper::isDocRootAvailableAndResolvable(); if (!$docRootAvailable) { throw new \Exception( 'Document root is no longer available. It was available when the .htaccess rules was created and ' . 'the rules are based on that. You need to regenerate the rules (or fix your document root configuration)' ); } $docRoot = SanityCheck::absPath($_SERVER["DOCUMENT_ROOT"]); $docRoot = rtrim($docRoot, '/'); self::$docRoot = $docRoot; } if ($usingDocRoot) { self::$webExpressContentDirAbs = self::getWebPExpressContentDirWithDocRoot(); } else { self::$webExpressContentDirAbs = self::getWebPExpressContentDirNoDocRoot(); } // Check config file name // --------------------------------- self::$checking = 'config file'; $configFilename = self::$webExpressContentDirAbs . '/config/wod-options.json'; if (!file_exists($configFilename)) { throw new \Exception('Configuration file was not found (wod-options.json)'); } // Check config file // -------------------- $configLoadResult = file_get_contents($configFilename); if ($configLoadResult === false) { throw new \Exception('Cannot open config file'); } $json = SanityCheck::isJSONObject($configLoadResult); self::$options = json_decode($json, true); self::$wodOptions = self::$options['wod']; } /** * Must be called after conversion. */ protected static function fixConfigIfEwwwDiscoveredNonFunctionalApiKeys() { if (isset(Ewww::$nonFunctionalApiKeysDiscoveredDuringConversion)) { // We got an invalid or exceeded api key (at least one). //error_log('look:' . print_r(Ewww::$nonFunctionalApiKeysDiscoveredDuringConversion, true)); EwwwTools::markApiKeysAsNonFunctional( Ewww::$nonFunctionalApiKeysDiscoveredDuringConversion, self::$webExpressContentDirAbs . '/config' ); } } }