Skip to content

Commit

Permalink
v 0.7.0
Browse files Browse the repository at this point in the history
- Update dependencies.
- Add PHP translation.
- Protect dirs.
  • Loading branch information
Darklg committed May 5, 2024
1 parent b3e8ec5 commit 074f553
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: PHP Lint
uses: michaelw90/[email protected]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.DS_Store
*.mo.php
1 change: 1 addition & 0 deletions inc/WPUBaseAdminPage/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all
29 changes: 26 additions & 3 deletions inc/WPUBaseAdminPage/WPUBaseAdminPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@
/*
Class Name: WPU Base Admin page
Description: A class to handle pages in WordPress
Version: 1.5.1
Version: 1.7.0
Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
Author URI: https://darklg.me/
License: MIT License
License URI: https://opensource.org/licenses/MIT
*/

defined('ABSPATH') || die;

class WPUBaseAdminPage {

public $page_hook = false;
private $pages;
private $options;
private $prefix;

private $default_options = array(
'level' => 'manage_options',
'network_page' => false
);

public function __construct() {}

/* ----------------------------------------------------------
Expand All @@ -33,7 +40,14 @@ public function init($options, $pages) {
$this->pages = $pages;
$this->prefix = $this->options['id'] . '-';
$this->pages = $this->set_pages($this->pages);
add_action('admin_menu', array(&$this,

/* Set default options */
if (!is_array($this->options)) {
$this->options = array();
}
$this->options = array_merge($this->default_options, $this->options);

add_action($this->options['network_page'] ? 'network_admin_menu' : 'admin_menu', array(&$this,
'set_admin_menu'
));
add_action('admin_bar_menu', array(&$this,
Expand Down Expand Up @@ -224,11 +238,13 @@ public function add_settings_link($links) {
public function set_admin_page_main() {
$page = $this->get_page();

$form_classname = $this->prefix . $page . '-form';

echo $this->get_wrapper_start();

// Default Form
if ($this->pages[$page]['has_form']):
echo '<form action="' . admin_url('admin-post.php') . '" method="post" ' . ($this->pages[$page]['has_file'] ? ' enctype="multipart/form-data"' : '') . '><div>';
echo '<form class="' . esc_attr($form_classname) . '" action="' . admin_url('admin-post.php') . '" method="post" ' . ($this->pages[$page]['has_file'] ? ' enctype="multipart/form-data"' : '') . '><div>';
echo '<input type="hidden" name="action" value="' . $this->options['id'] . '">';
echo '<input type="hidden" name="page_name" value="' . $page . '" />';
wp_nonce_field('action-main-form-' . $page, 'action-main-form-' . $this->options['id'] . '-' . $page);
Expand Down Expand Up @@ -269,4 +285,11 @@ private function get_page() {
}
return $page;
}

public function get_page_url($page_id){
if(!isset($this->pages[$page_id])){
return false;
}
return $this->pages[$page_id]['url'];
}
}
1 change: 1 addition & 0 deletions inc/WPUBaseAdminPage/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php /* Silence */
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
19 changes: 14 additions & 5 deletions inc/WPUBaseFileCache/WPUBaseFileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
/*
Class Name: WPU Base File Cache
Description: A class to handle basic file cache
Version: 0.1.1
Version: 0.2.0
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) {
Expand All @@ -26,8 +28,9 @@ public function get_cache_dir() {
$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');
chmod($cache_dir, 0775);
$this->file_put_contents($cache_dir . 'index.html', '');
$this->file_put_contents($cache_dir . '.htaccess', 'deny from all');
}
return $cache_dir;
}
Expand All @@ -49,7 +52,7 @@ public function get_cache($cache_id, $expiration = 3600) {
if (!file_exists($cached_file)) {
return false;
}
if (filemtime($cached_file) + $expiration < time()) {
if ($expiration && filemtime($cached_file) + $expiration < time()) {
return false;
}

Expand All @@ -58,9 +61,15 @@ public function get_cache($cache_id, $expiration = 3600) {

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

return true;
}

/* Fix content creation */
public function file_put_contents($file, $content) {
file_put_contents($file, $content);
chmod($file, 0664);
}

}
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 */
1 change: 1 addition & 0 deletions inc/WPUBaseMessages/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all
4 changes: 3 additions & 1 deletion inc/WPUBaseMessages/WPUBaseMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
/*
Class Name: WPU Base Messages
Description: A class to handle messages in WordPress
Version: 1.3.3
Version: 1.3.4
Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
Author URI: https://darklg.me/
License: MIT License
License URI: https://opensource.org/licenses/MIT
*/

defined('ABSPATH') || die;

class WPUBaseMessages {

private $transient_msg;
Expand Down
1 change: 1 addition & 0 deletions inc/WPUBaseMessages/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php /* Silence */
1 change: 1 addition & 0 deletions inc/WPUBaseUpdate/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all
7 changes: 6 additions & 1 deletion inc/WPUBaseUpdate/WPUBaseUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/*
Class Name: WPU Base Update
Description: A class to handle plugin update from github
Version: 0.4.3
Version: 0.4.5
Class URI: https://github.com/WordPressUtilities/wpubaseplugin
Author: Darklg
Author URI: https://darklg.me/
Expand All @@ -13,6 +13,8 @@
Thanks: https://gist.github.com/danielbachhuber/7684646
*/

defined('ABSPATH') || die;

class WPUBaseUpdate {

public $current_version;
Expand Down Expand Up @@ -126,6 +128,9 @@ public function get_new_plugin_info() {
/* Fetch plugin data */
$plugin_data = array();
if (file_exists($this->plugin_dir)) {
if (!function_exists('get_plugin_data')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugin_data = get_plugin_data($this->plugin_dir);
}

Expand Down
1 change: 1 addition & 0 deletions inc/WPUBaseUpdate/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php /* Silence */
2 changes: 2 additions & 0 deletions lang/wpu_override_gettext-fr_FR.l10n.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
return ['domain'=>NULL,'plural-forms'=>NULL,'messages'=>['Help'=>'Aide','Override gettext strings'=>'Remplacer les chaînes gettext','Settings'=>'Réglages','String'=>'Chaîne','Domain'=>'Domaine','Custom translation'=>'Traduction personnalisée','Save translations'=>'Enregistrer les traductions','The translations were successfully saved.'=>'Les traductions ont été sauvegardées avec succès.'],'language'=>'fr_FR','x-generator'=>'Poedit 3.3.2'];
1 change: 1 addition & 0 deletions uninstall.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
defined('ABSPATH') || die;
if (!defined('WP_UNINSTALL_PLUGIN')) {
die;
}
Expand Down
14 changes: 8 additions & 6 deletions wpu_override_gettext.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<?php
defined('ABSPATH') || die;
/*
Plugin Name: WPU Override gettext
Plugin URI: https://github.com/WordPressUtilities/wpu_override_gettext
Update URI: https://github.com/WordPressUtilities/wpu_override_gettext
Description: Override gettext strings
Version: 0.6.1
Version: 0.7.0
Author: darklg
Author URI: https://darklg.me/
Text Domain: wpu_override_gettext
Domain Path: /lang
Requires at least: 6.2
Requires PHP: 8.0
Network: Optional
License: MIT License
License URI: https://opensource.org/licenses/MIT
*/
Expand All @@ -20,7 +22,7 @@ class WPUOverrideGettext {
public $settings_update;
public $plugin_description;
public $adminpages;
private $plugin_version = '0.6.1';
private $plugin_version = '0.7.0';
private $plugin_settings = array(
'id' => 'wpu_override_gettext',
'name' => 'WPU Override gettext'
Expand Down Expand Up @@ -64,24 +66,24 @@ public function plugins_loaded() {
'level' => 'delete_users',
'basename' => plugin_basename(__FILE__)
);
require_once dirname(__FILE__) . '/inc/WPUBaseAdminPage/WPUBaseAdminPage.php';
require_once __DIR__ . '/inc/WPUBaseAdminPage/WPUBaseAdminPage.php';
$this->adminpages = new \wpu_override_gettext\WPUBaseAdminPage();
$this->adminpages->init($pages_options, $admin_pages);

# File Cache
require_once dirname(__FILE__) . '/inc/WPUBaseFileCache/WPUBaseFileCache.php';
require_once __DIR__ . '/inc/WPUBaseFileCache/WPUBaseFileCache.php';
$this->wpubasefilecache = new \wpu_override_gettext\WPUBaseFileCache('wpu_override_gettext');

# Base Update
require_once dirname(__FILE__) . '/inc/WPUBaseUpdate/WPUBaseUpdate.php';
require_once __DIR__ . '/inc/WPUBaseUpdate/WPUBaseUpdate.php';
$this->settings_update = new \wpu_override_gettext\WPUBaseUpdate(
'WordPressUtilities',
'wpu_override_gettext',
$this->plugin_version);

# MESSAGES
if (is_admin()) {
require_once dirname(__FILE__) . '/inc/WPUBaseMessages/WPUBaseMessages.php';
require_once __DIR__ . '/inc/WPUBaseMessages/WPUBaseMessages.php';
$this->messages = new \wpu_override_gettext\WPUBaseMessages($this->plugin_settings['id']);
}
}
Expand Down

0 comments on commit 074f553

Please sign in to comment.