Skip to content

Commit

Permalink
Update Wordpress to be compatible with cloudflare-plugin-backend changes
Browse files Browse the repository at this point in the history
  • Loading branch information
manatarms committed Sep 23, 2020
1 parent e2a5871 commit 40b457f
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 5 deletions.
0 config.js → config.json
100755 → 100644
File renamed without changes.
2 changes: 1 addition & 1 deletion scripts/deployment/publish_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

COMPOSER_FILE_NAME = "composer.json"
README_FILE_NAME = "readme.txt"
CONFIG_FILE_NAME = "config.js"
CONFIG_FILE_NAME = "config.json"
CLOUDFLARE_PHP_FILE_NAME = "cloudflare.php"
README_TXT_STABLE_TAG_LINE_NUMBER = 6
CLOUDFLARE_PHP_VERSION_LINE_NUMBER = 6
Expand Down
2 changes: 1 addition & 1 deletion src/WordPress/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Hooks

public function __construct()
{
$this->config = new Integration\DefaultConfig(file_get_contents(CLOUDFLARE_PLUGIN_DIR.'config.js', true));
$this->config = new Integration\DefaultConfig(file_get_contents(CLOUDFLARE_PLUGIN_DIR.'config.json', true));
$this->logger = new Integration\DefaultLogger($this->config->getValue('debug'));
$this->dataStore = new DataStore($this->logger);
$this->integrationAPI = new WordPressAPI($this->dataStore);
Expand Down
95 changes: 92 additions & 3 deletions src/WordPress/PluginActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,55 @@
namespace CF\WordPress;

use CF\API\APIInterface;
use CF\API\Request;
use CF\API\AbstractPluginActions;
use CF\API\Exception\ZoneSettingFailException;
use CF\API\Plugin;
use CF\API\Request;
use CF\Integration\DefaultIntegration;
use CF\API\Exception\ZoneSettingFailException;
use CF\WordPress\Constants\Plans;
use CF\API\AbstractPluginActions;

class PluginActions extends AbstractPluginActions
{
protected $api;
protected $clientAPI;
protected $composer;
protected $request;
protected $userConfig;

const CONFIG = [
"debug" => false,
"featureManagerIsFullZoneProvisioningEnabled" => false,
"isDNSPageEnabled" => false,
"isSubdomainCheckEnabled" => true,
"useHostAPILogin" => false,
"homePageCards" => [
"ApplyDefaultSettingsCard",
"PurgeCacheCard",
"PluginSpecificCacheCard"
],
"moreSettingsCards" => [
"container.moresettings.speed" => [
"AlwaysOnlineCard",
"ImageOptimizationCard",
"DevelopmentModeCard",
"BypassCacheByCookieCard"
],
"container.moresettings.security" => [
"SecurityLevelCard",
"WAFCard",
"AdvanceDDoSCard",
"AutomaticHTTPSRewritesCard"
]
],
"locale" => "en",
"integrationName" => "wordpress"
];

const BANNED_KEYS = [
'isDNSPageEnabled',
'useHostAPILogin',
'integrationName',
];

public function __construct(DefaultIntegration $defaultIntegration, APIInterface $api, Request $request)
{
Expand Down Expand Up @@ -132,4 +169,56 @@ public function applyDefaultSettings()
}
}
}

public function getConfig()
{
$this->getUserConfig();
$this->getComposerJson();

//Clone the config to manipulate
$config = array_merge(array(), self::CONFIG);

//Add version from composer.json to the config
$config['version'] = $this->composer['version'];

//This removes all the banned keys from the userConfig so we don't over write them
$this->userConfig = array_diff_key($this->userConfig, array_flip(self::BANNED_KEYS));

//Merge and intersect userConfig with default config and return response
$response = array_intersect_key($this->userConfig + $config, $config);

return $this->api->createAPISuccessResponse($response);
}

public function getUserConfig()
{
if ($this->userConfig === null) {
//Need to suppress the File not found error with @
$userConfigContent = @file_get_contents(dirname(__FILE__) . '/config.json');

//Need to set an empty array for merge into config so it doesnt throw a type error
$this->userConfig = [];
//If we did find a config decode it
if ($userConfigContent) {
$this->userConfig = json_decode($userConfigContent, true);
}
}
}

public function setUserConfig($userConfig)
{
$this->userConfig = $userConfig;
}

public function getComposerJson()
{
if ($this->composer === null) {
$this->composer = json_decode(file_get_contents(dirname(__FILE__) . '/composer.json'), true);
}
}

public function setComposerJson($composer)
{
$this->composer = $composer;
}
}

0 comments on commit 40b457f

Please sign in to comment.