Skip to content

Commit

Permalink
v 3.13.0
Browse files Browse the repository at this point in the history
- Code cleaning.
- Use WPU Base File cache for external ressources.
  • Loading branch information
Darklg committed Mar 18, 2024
1 parent dcf20ba commit 1940c6e
Show file tree
Hide file tree
Showing 40 changed files with 140 additions and 37 deletions.
2 changes: 1 addition & 1 deletion 404.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname( __FILE__ ) . '/z-protect.php';
include __DIR__ . '/z-protect.php';
get_header();
?>
<div class="main-content">
Expand Down
2 changes: 1 addition & 1 deletion archive.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname( __FILE__ ) . '/z-protect.php';
include __DIR__ . '/z-protect.php';
get_header();

$shown_title = wp_title( "", false );
Expand Down
2 changes: 1 addition & 1 deletion attachment.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname(__FILE__) . '/z-protect.php';
include __DIR__ . '/z-protect.php';
get_header();
the_post();

Expand Down
2 changes: 1 addition & 1 deletion comments.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname(__FILE__) . '/z-protect.php';
include __DIR__ . '/z-protect.php';

if (post_password_required()) {
return;
Expand Down
2 changes: 1 addition & 1 deletion examplechildtheme/functions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
require_once dirname(__FILE__) . '/../WPUTheme/z-protect.php';
require_once __DIR__ . '/../WPUTheme/z-protect.php';

/* ----------------------------------------------------------
Hide these blocks on parent theme
Expand Down
2 changes: 1 addition & 1 deletion examplechildtheme/woocommerce.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname( __FILE__ ) . '/z-protect.php';
include __DIR__ . '/z-protect.php';
get_header();
?>
<div class="main-content">
Expand Down
2 changes: 1 addition & 1 deletion footer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname(__FILE__) . '/z-protect.php';
include __DIR__ . '/z-protect.php';
do_action('qm/stop', 'wputheme_content');
do_action('qm/start', 'wputheme_footer');

Expand Down
2 changes: 1 addition & 1 deletion front-page.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname( __FILE__ ) . '/z-protect.php';
include __DIR__ . '/z-protect.php';
get_header();
do_action('wputheme_home_content');
get_sidebar();
Expand Down
8 changes: 7 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
require_once dirname(__FILE__) . '/z-protect.php';
require_once __DIR__ . '/z-protect.php';

$WPUTheme_infos = wp_get_theme('WPUTheme');
define('WPUTHEME_VERSION', $WPUTheme_infos->Version);
Expand Down Expand Up @@ -76,6 +76,12 @@
Includes
---------------------------------------------------------- */

/* Utilities
-------------------------- */

require_once get_template_directory() . '/inc/WPUBaseFileCache/WPUBaseFileCache.php';
$wputheme_wpubasefilecache = new \WPUTheme\WPUBaseFileCache('wputheme');

/* Theme
-------------------------- */

Expand Down
2 changes: 1 addition & 1 deletion header.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
require_once dirname(__FILE__) . '/z-protect.php';
require_once __DIR__ . '/z-protect.php';
if (!defined('IS_AJAX') || !IS_AJAX) {

/* ----------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions inc/WPUBaseFileCache/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all
25 changes: 25 additions & 0 deletions inc/WPUBaseFileCache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
WPU Base File Cache
---

A class to handle basic file cache.


## Insert in construct

```php
/* Cache */
include __DIR__ . '/inc/WPUBaseFileCache/WPUBaseFileCache.php';
$this->wpubasefilecache = new \mypluginid\WPUBaseFileCache('mypluginid');

```

## Insert when needed

```php
$cache_key = 'mycachekey';
$query_value = $this->wpubasefilecache->get_cache($cache_key, 24 * 60 * 60);
if (!$query_value) {
$query_value = 'BIG QUERY';
$this->wpubasefilecache->set_cache($cache_key, $query_value);
}
```
68 changes: 68 additions & 0 deletions inc/WPUBaseFileCache/WPUBaseFileCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
namespace WPUTheme;

/*
Class Name: WPU Base File Cache
Description: A class to handle basic file cache
Version: 0.1.2
Author: Darklg
Author URI: https://darklg.me/
License: MIT License
License URI: https://opensource.org/licenses/MIT
*/

defined('ABSPATH') || die;

class WPUBaseFileCache {
private $cache_dir;
public function __construct($cache_dir) {
$this->cache_dir = $cache_dir;
$this->get_cache_dir();
}

public function get_cache_dir() {
$root_cache_dir = WP_CONTENT_DIR . '/cache';
if (!is_dir($root_cache_dir) && !mkdir($root_cache_dir)) {
return false;
}
$cache_dir = $root_cache_dir . '/' . $this->cache_dir . '/';
if (!is_dir($cache_dir)) {
mkdir($cache_dir);
file_put_contents($cache_dir . 'index.html', '');
file_put_contents($cache_dir . '.htaccess', 'deny from all');
}
return $cache_dir;
}

public function purge_cache_dir() {
$upload_dir = $this->get_cache_dir();
if ($handle = opendir($upload_dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != ".htaccess" && !is_dir($upload_dir . DIRECTORY_SEPARATOR . $file)) {
unlink($upload_dir . DIRECTORY_SEPARATOR . $file);
}
}
closedir($handle);
}
}

public function get_cache($cache_id, $expiration = 3600) {
$cached_file = $this->get_cache_dir() . $cache_id;
if (!file_exists($cached_file)) {
return false;
}
if ($expiration && filemtime($cached_file) + $expiration < time()) {
return false;
}

return unserialize(file_get_contents($cached_file));
}

public function set_cache($cache_id, $content = '') {
$cached_file = $this->get_cache_dir() . '/' . $cache_id;
file_put_contents($cached_file, serialize($content));

return true;
}

}
1 change: 1 addition & 0 deletions inc/WPUBaseFileCache/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php /* Silence */
2 changes: 1 addition & 1 deletion inc/assets/scripts.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname(__FILE__) . '/../../z-protect.php';
include __DIR__ . '/../../z-protect.php';

/* ----------------------------------------------------------
Common libraries
Expand Down
2 changes: 1 addition & 1 deletion inc/assets/styles.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname(__FILE__) . '/../../z-protect.php';
include __DIR__ . '/../../z-protect.php';

/* ----------------------------------------------------------
Insert all available CSS files
Expand Down
2 changes: 1 addition & 1 deletion inc/plugins/wpu-options.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname(__FILE__) . '/../../z-protect.php';
include __DIR__ . '/../../z-protect.php';

/* ----------------------------------------------------------
Options for the plugin "WPU Options"
Expand Down
2 changes: 1 addition & 1 deletion inc/theme/default-items.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname(__FILE__) . '/../../z-protect.php';
include __DIR__ . '/../../z-protect.php';

/* ----------------------------------------------------------
Main
Expand Down
2 changes: 1 addition & 1 deletion inc/theme/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function wputh_pages_site_setup() {

/* Default content : try to load template */
if (empty($page['post_content'])) {
$file_name = dirname(__FILE__) . '/activation/' . str_replace('__page_id', '', $id) . '.php';
$file_name = __DIR__ . '/activation/' . str_replace('__page_id', '', $id) . '.php';
ob_start();
locate_template($file_name, 1);
$page['post_content'] = ob_get_clean();
Expand Down
2 changes: 1 addition & 1 deletion inc/theme/params.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname(__FILE__) . '/../../z-protect.php';
include __DIR__ . '/../../z-protect.php';

/* ----------------------------------------------------------
Supported features
Expand Down
6 changes: 4 additions & 2 deletions inc/theme/utilities/external-ressources.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
-------------------------- */

function wputh_get_cached_metas($url) {
global $wputheme_wpubasefilecache;

$cache_id = 'wputh_get_cached_metas_' . md5($url);

/* Valid metas */
$cached_metas = get_transient($cache_id);
$cached_metas = $wputheme_wpubasefilecache->get_cache($cache_id, 0);
if (is_array($cached_metas)) {
return $cached_metas;
}
Expand Down Expand Up @@ -51,7 +53,7 @@ function wputh_get_cached_metas($url) {
}

/* Cache & return result */
set_transient($cache_id, $cached_metas, 0);
$wputheme_wpubasefilecache->set_cache($cache_id, $cached_metas);

return $cached_metas;
}
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname( __FILE__ ) . '/z-protect.php';
include __DIR__ . '/z-protect.php';
get_header();

echo '<div class="main-content">';
Expand Down
2 changes: 1 addition & 1 deletion loop-small.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname( __FILE__ ) . '/z-protect.php';
include __DIR__ . '/z-protect.php';
$has_thumb = has_post_thumbnail();
?><article <?php post_class( 'loop-small' ); ?>>
<div class="<?php echo $has_thumb ? 'bmedia':''; ?>">
Expand Down
2 changes: 1 addition & 1 deletion loop.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname( __FILE__ ) . '/z-protect.php';
include __DIR__ . '/z-protect.php';
?><article <?php post_class(); ?>>
<h1><?php the_title(); ?></h1>
<aside class="lp-metas">
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wputheme",
"version": "3.12.0",
"version": "3.13.0",
"description": "WPUTheme",
"dependencies": {},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion page-templates/page-bigpictures.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/* Template Name: Big Pictures */
include dirname( __FILE__ ) . '/../z-protect.php';
include __DIR__ . '/../z-protect.php';

get_header();
the_post();
Expand Down
2 changes: 1 addition & 1 deletion page-templates/page-contact.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/* Template Name: Contact */
include dirname(__FILE__) . '/../z-protect.php';
include __DIR__ . '/../z-protect.php';
get_header();
the_post();
?>
Expand Down
2 changes: 1 addition & 1 deletion page-templates/page-downloads.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/* Template Name: Downloads */
include dirname( __FILE__ ) . '/../z-protect.php';
include __DIR__ . '/../z-protect.php';

get_header();
the_post();
Expand Down
2 changes: 1 addition & 1 deletion page-templates/page-faq.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/* Template Name: FAQ */
include dirname( __FILE__ ) . '/../z-protect.php';
include __DIR__ . '/../z-protect.php';
the_post();
$content_faq = '';
ob_start();
Expand Down
2 changes: 1 addition & 1 deletion page-templates/page-forgottenpassword.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/* Template Name: Forgotten Password */
include dirname(__FILE__) . '/../z-protect.php';
include __DIR__ . '/../z-protect.php';

if (is_user_logged_in()) {
wp_redirect(apply_filters('wputh_forgottenpassword_url_logged_in', site_url()));
Expand Down
2 changes: 1 addition & 1 deletion page-templates/page-gallery.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/* Template Name: Gallery */
include dirname(__FILE__) . '/../z-protect.php';
include __DIR__ . '/../z-protect.php';

get_header();
the_post();
Expand Down
2 changes: 1 addition & 1 deletion page-templates/page-sitemap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/* Template Name: Sitemap */
include dirname(__FILE__) . '/../z-protect.php';
include __DIR__ . '/../z-protect.php';
include get_template_directory() . '/tpl/sitemap/datas.php';

/* ----------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion page-templates/page-webservice.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/* Template Name: Webservice */

include dirname(__FILE__) . '/../z-protect.php';
include __DIR__ . '/../z-protect.php';

$mode = '';
if (isset($_GET['mode'])) {
Expand Down
2 changes: 1 addition & 1 deletion page-templates/page-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* Template Name: Woocommerce */

include dirname(__FILE__) . '/../z-protect.php';
include __DIR__ . '/../z-protect.php';

the_post();
get_header();
Expand Down
2 changes: 1 addition & 1 deletion page.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname( __FILE__ ) . '/z-protect.php';
include __DIR__ . '/z-protect.php';
get_header();
the_post();
?>
Expand Down
2 changes: 1 addition & 1 deletion search.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname( __FILE__ ) . '/z-protect.php';
include __DIR__ . '/z-protect.php';

$number_results = (int) $wp_query->found_posts;
$search_results = __( '<strong>no</strong> search results', 'wputh' );
Expand Down
2 changes: 1 addition & 1 deletion sidebar.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname( __FILE__ ) . '/z-protect.php';
include __DIR__ . '/z-protect.php';
if ( WPUTH_HAS_SIDEBAR && is_active_sidebar( 'wputh-sidebar' ) ) : ?>
<aside>
<ul class="wputh-sidebar">
Expand Down
2 changes: 1 addition & 1 deletion single.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include dirname(__FILE__) . '/z-protect.php';
include __DIR__ . '/z-protect.php';
get_header();
the_post();
?>
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Theme Name: WP Utilities Base Theme
Theme URI: https://github.com/WordPressUtilities/WPUTheme
Update URI: https://github.com/WordPressUtilities/WPUTheme
Description: A Framework WordPress Theme
Version: 3.12.0
Version: 3.13.0
Author: Darklg
Author URI: https://darklg.me/
License: GPLv2 or later
Expand Down
2 changes: 1 addition & 1 deletion tpl/header/searchform.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
$_min_count = apply_filters('wputh_searchform_datalist_mincount', 3);
include dirname(__FILE__) . '/../../z-protect.php';
include __DIR__ . '/../../z-protect.php';
?>
<div class="search search--header header-search">
<form role="search" method="get" id="header-search" class="search__form" action="<?php echo home_url(); ?>">
Expand Down

0 comments on commit 1940c6e

Please sign in to comment.