Skip to content

Commit

Permalink
Plugin source code export to github.
Browse files Browse the repository at this point in the history
  • Loading branch information
pauiglesias committed Oct 9, 2018
1 parent c85b938 commit db5a370
Show file tree
Hide file tree
Showing 37 changed files with 4,783 additions and 0 deletions.
107 changes: 107 additions & 0 deletions admin/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

// Subpackage namespace
namespace LittleBizzy\PurgeThemAll\Admin;

/**
* Admin area class
*
* @package Purge Them All
* @subpackage Admin
*/
class Admin {



// Properties
// ---------------------------------------------------------------------------------------------------



/**
* Plugin object
*/
private $plugin;



// Initialization
// ---------------------------------------------------------------------------------------------------



/**
* Constructor
*/
public function __construct($plugin) {

// Set plugin object
$this->plugin = $plugin;

// WP init hook
add_action('init', array(&$this, 'disableCloudflarePluginMenu'));

// Admin menu hook
add_action('admin_menu', array(&$this, 'menu'));
}



// WP Hooks
// ---------------------------------------------------------------------------------------------------



/**
* Add a submenu item to the WP Settings menu
*/
public function menu() {

// Create submenu page
$hook = add_submenu_page('options-general.php', 'Purge Them All', 'Purge Them All', 'manage_options', 'purge-them-all', array(&$this, 'page'));

// Add a load handler
if (false !== $hook)
add_action('load-'.$hook, array(&$this, 'onLoad'));
}



/**
* Load custom submenu handler
*/
public function onLoad() {
$this->plugin->wrapper = $this->plugin->factory->wrapper;
wp_enqueue_style( 'prgtha-admin', $this->plugin->wrapper->getURL('assets/admin.css'), array(), $this->plugin->version);
wp_enqueue_script('prgtha-admin', $this->plugin->wrapper->getURL('assets/admin.js'), array('jquery'), $this->plugin->version, true);
}



/**
* Load the plugin page
*/
public function page() {
$this->page = $this->plugin->factory->adminPage;
$this->page->show();
}



/**
* Hide the cloudflare plugin Options menu
*/
public function disableCloudflarePluginMenu() {

// Check Cloudflare plugin Admin class
$className = '\LittleBizzy\CloudFlare\Admin\Admin';
if (!class_exists($className) || !method_exists($className, 'instance'))
return;

// Remove menu
remove_action('admin_menu', array($className::instance(), 'adminMenu'));
}



}
176 changes: 176 additions & 0 deletions admin/page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<?php

// Subpackage namespace
namespace LittleBizzy\PurgeThemAll\Admin;

// Aliased namespaces
use \LittleBizzy\PurgeThemAll\Libraries;

/**
* Admin page class
*
* @package Purge Them All
* @subpackage Admin
*/
class Page extends Libraries\View_Display {



// Properties
// ---------------------------------------------------------------------------------------------------



/**
* Plugin object
*/
private $plugin;



/**
* Data object
*/
private $data;



/**
* Opcache object
*/
private $opcache;



/**
* Object Cache object
*/
private $objectCache;



/**
* Subpages
*/
private $viewOverview;
private $viewCloudflare;
private $viewOpCache;
private $viewNginx;
private $viewObjectCache;



// Initialization
// ---------------------------------------------------------------------------------------------------



/**
* Constructor
*/
public function __construct($plugin) {
$this->plugin = $plugin;
}



/**
* Prepare data just before to display
*/
protected function prepare($args) {

// Data object
$this->data = $this->plugin->factory->data;
$this->data->load();

// Creates the first view
$this->viewOverview = $this->plugin->factory->adminViewOverview;

// Creates the Cloudflare view
$this->viewCloudFlare = $this->plugin->factory->adminViewCloudflare([
'key' => $this->data->cloudflareKey,
'email' => $this->data->cloudflareEmail,
'zone' => $this->data->cloudflareZone,
'devMode' => $this->data->cloudflareDevMode,
'domain' => $this->data->domain,
'isCloudFlare' => $this->data->isCloudflare,
]);

// Creates the OpCache view
$this->opcache = $this->plugin->factory->opcache;
$this->viewOpCache = $this->plugin->factory->adminViewOpCache([
'loaded' => $this->opcache->isExtensionLoaded(),
'enabled' => $this->opcache->isEnabled(),
]);

// Creates the Nginx view
$this->viewNginx = $this->plugin->factory->adminViewNginx([
'path' => $this->data->nginxPath,
]);

// Creates the Object Cache view
$this->objectCache = $this->plugin->factory->objectCache;
$this->viewObjectCache = $this->plugin->factory->adminViewObjectCache([
'enabled' => $this->objectCache->isEnabled(),
]);
}



// Internal
// ---------------------------------------------------------------------------------------------------



/**
* Admin page output
*/
protected function display($args) { ?>

<div class="wrap">

<h1 id="prgtha-title">Purge Them All</h1>

<form id="prgtha-form" data-nonce="<?php echo $this->plugin->wrapper->createNonce($this->plugin->nonceSeed); ?>">

<h2 id="prgtha-nav-tabs" class="nav-tab-wrapper wp-clearfix">
<a id="prgtha-nav-tab-all" href="#" class="nav-tab nav-tab-active">Overview</a>
<a id="prgtha-nav-tab-cloudflare" href="#" class="nav-tab">CloudFlare Cache</a>
<a id="prgtha-nav-tab-opcache" href="#" class="nav-tab">PHP Opcache</a>
<a id="prgtha-nav-tab-nginx" href="#" class="nav-tab">Nginx Cache</a>
<a id="prgtha-nav-tab-object" href="#" class="nav-tab">Object Cache</a>
</h2>

<div class="prgtha-nav-content-wrapper">

<div id="prgtha-nav-content-all" class="prgtha-nav-content prgtha-nav-content-active">
<?php $this->viewOverview->show(); ?>
</div>

<div id="prgtha-nav-content-cloudflare" class="prgtha-nav-content">
<?php $this->viewCloudFlare->show(); ?>
</div>

<div id="prgtha-nav-content-opcache" class="prgtha-nav-content">
<?php $this->viewOpCache->show(); ?>
</div>

<div id="prgtha-nav-content-nginx" class="prgtha-nav-content">
<?php $this->viewNginx->show(); ?>
</div>

<div id="prgtha-nav-content-object" class="prgtha-nav-content">
<?php $this->viewObjectCache->show(); ?>
</div>

</div>

</form>

</div>

<?php }



}
Loading

0 comments on commit db5a370

Please sign in to comment.