Undo last two commits affecting trunk/ but not the Stable Tag.
= Stable Tag value = 2.5.10 (unchanged) = Commits undone = - 2484038 (2021-03-02 05:29:18 +0000 (Tue, 02 Mar 2021)) committer: pewgeuges -2484015 (2021-03-02 04:22:20 +0000 (Tue, 02 Mar 2021)) committer: pewgeuges = Rationale = By renaming a folder (and 3 out of 4 included files), the WordPress Coding Standards compliance upgrade (see changeset 2484015) has broken the traceability of the changes made to the following files: - footnotes/trunk/class/dashboard/init.php - footnotes/trunk/class/dashboard/layout.php - footnotes/trunk/class/dashboard/subpage-diagnostics.php - footnotes/trunk/class/dashboard/subpage-main.php git-svn-id: https://plugins.svn.wordpress.org/footnotes/trunk@2485882 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
parent
1fe04f9ac6
commit
dfcbdc6adc
36 changed files with 3920 additions and 5094 deletions
|
@ -1,20 +1,39 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
<?php
|
||||
/**
|
||||
* Includes the Template Engine to load and handle all Template files of the Plugin.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
* @date 14.09.14 10:58
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0 14.09.14 10:58
|
||||
*
|
||||
* @since 2.2.6 Adding: Templates: support for custom templates in sibling folder, thanks to @misfist issue report.
|
||||
* @since 2.5.0 Adding: Templates: Enable template location stack, thanks to @misfist code contribution.
|
||||
*
|
||||
* @lastmodified 2021-02-18T2024+0100
|
||||
*
|
||||
* @since 2.0.3 prettify reference container template
|
||||
* @since 2.0.3 replace tab with a space
|
||||
* @since 2.0.3 replace 2 spaces with 1
|
||||
* @since 2.0.4 collapse multiple spaces
|
||||
* @since 2.0.6 prettify other templates (footnote, tooltip script, ref container row)
|
||||
* @since 2.2.6 delete a space before a closing pointy bracket
|
||||
*
|
||||
* @since 2.2.6 support for custom templates in fixed location, while failing to add filter thanks to @misfist 2020-12-19T0606+0100
|
||||
* @link https://wordpress.org/support/topic/template-override-filter/
|
||||
*
|
||||
* @since 2.4.0 templates may be in active theme, thanks to @misfist
|
||||
* @link https://wordpress.org/support/topic/template-override-filter/#post-13846598
|
||||
*
|
||||
* @since 2.5.0 Enable template location stack, contributed by @misfist
|
||||
* @link https://wordpress.org/support/topic/template-override-filter/#post-13864301
|
||||
*
|
||||
* @since 2.5.4 collapse HTML comments and PHP/JS docblocks (only)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Handles each Template file for the Plugin Frontend (e.g. Settings Dashboard, Public pages, ...).
|
||||
* Loads a template file, replaces all Placeholders and returns the replaced file content.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class MCI_Footnotes_Template {
|
||||
|
@ -22,38 +41,43 @@ class MCI_Footnotes_Template {
|
|||
/**
|
||||
* Directory name for dashboard templates.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_DASHBOARD = 'dashboard';
|
||||
const C_STR_DASHBOARD = "dashboard";
|
||||
|
||||
/**
|
||||
* Directory name for public templates.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_PUBLIC = 'public';
|
||||
const C_STR_PUBLIC = "public";
|
||||
|
||||
/**
|
||||
* Contains the content of the template after initialize.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
private $a_str_original_content = '';
|
||||
private $a_str_OriginalContent = "";
|
||||
|
||||
/**
|
||||
* Contains the content of the template after initialize with replaced place holders.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
private $a_str_replaced_content = '';
|
||||
private $a_str_ReplacedContent = "";
|
||||
|
||||
/**
|
||||
* Plugin Directory
|
||||
*
|
||||
* @author Patrizia Lutz @misfist
|
||||
* @since 2.4.0d3
|
||||
*
|
||||
* @var string
|
||||
|
@ -63,39 +87,42 @@ class MCI_Footnotes_Template {
|
|||
/**
|
||||
* Class Constructor. Reads and loads the template file without replace any placeholder.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_file_type Template file type (take a look on the Class constants).
|
||||
* @param string $p_str_file_name Template file name inside the Template directory without the file extension.
|
||||
* @param string $p_str_extension Optional Template file extension (default: html).
|
||||
* @param string $p_str_FileType Template file type (take a look on the Class constants).
|
||||
* @param string $p_str_FileName Template file name inside the Template directory without the file extension.
|
||||
* @param string $p_str_Extension Optional Template file extension (default: html)
|
||||
*
|
||||
* - Adding: Templates: support for custom templates in sibling folder, thanks to @misfist issue report.
|
||||
*
|
||||
* @since 2.2.6
|
||||
* @date 2020-12-19T0606+0100
|
||||
*
|
||||
* @reporter @misfist
|
||||
* @since 2.2.6 support for custom templates 2020-12-19T0606+0100
|
||||
* @link https://wordpress.org/support/topic/template-override-filter/
|
||||
*
|
||||
* @since 2.4.0 look for custom template in the active theme first, thanks to @misfist
|
||||
* @link https://wordpress.org/support/topic/template-override-filter/#post-13846598
|
||||
*/
|
||||
public function __construct( $p_str_file_type, $p_str_file_name, $p_str_extension = 'html' ) {
|
||||
// No template file type and/or file name set.
|
||||
if ( empty( $p_str_file_type ) || empty( $p_str_file_name ) ) {
|
||||
public function __construct($p_str_FileType, $p_str_FileName, $p_str_Extension = "html") {
|
||||
// no template file type and/or file name set
|
||||
if (empty($p_str_FileType) || empty($p_str_FileName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define plugin root path.
|
||||
* Define plugin root path
|
||||
*
|
||||
* @since 2.4.0d3
|
||||
*
|
||||
* @author Patrizia Lutz @misfist
|
||||
*/
|
||||
$this->plugin_directory = plugin_dir_path( dirname( __FILE__ ) );
|
||||
|
||||
/**
|
||||
* Modularize functions.
|
||||
* Modularize functions
|
||||
*
|
||||
* @since 2.4.0d3
|
||||
*
|
||||
* @author Patrizia Lutz @misfist
|
||||
*/
|
||||
$template = $this->get_template( $p_str_file_type, $p_str_file_name, $p_str_extension );
|
||||
if ( $template ) {
|
||||
if( $template = $this->get_template( $p_str_FileType, $p_str_FileName, $p_str_Extension ) ) {
|
||||
$this->process_template( $template );
|
||||
} else {
|
||||
return;
|
||||
|
@ -106,125 +133,124 @@ class MCI_Footnotes_Template {
|
|||
/**
|
||||
* Replace all placeholders specified in array.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
* @param array $p_arr_placeholders Placeholders (key = placeholder, value = value).
|
||||
* @param array $p_arr_Placeholders Placeholders (key = placeholder, value = value).
|
||||
* @return bool True on Success, False if Placeholders invalid.
|
||||
*/
|
||||
public function replace( $p_arr_placeholders ) {
|
||||
// No placeholders set.
|
||||
if ( empty( $p_arr_placeholders ) ) {
|
||||
public function replace($p_arr_Placeholders) {
|
||||
// no placeholders set
|
||||
if (empty($p_arr_Placeholders)) {
|
||||
return false;
|
||||
}
|
||||
// Template content is empty.
|
||||
if ( empty( $this->a_str_replaced_content ) ) {
|
||||
// template content is empty
|
||||
if (empty($this->a_str_ReplacedContent)) {
|
||||
return false;
|
||||
}
|
||||
// Iterate through each placeholder and replace it with its value.
|
||||
foreach ( $p_arr_placeholders as $l_str_placeholder => $l_str_value ) {
|
||||
$this->a_str_replaced_content = str_replace( '[[' . $l_str_placeholder . ']]', $l_str_value, $this->a_str_replaced_content );
|
||||
// iterate through each placeholder and replace it with its value
|
||||
foreach($p_arr_Placeholders as $l_str_Placeholder => $l_str_Value) {
|
||||
$this->a_str_ReplacedContent = str_replace("[[" . $l_str_Placeholder . "]]", $l_str_Value, $this->a_str_ReplacedContent);
|
||||
}
|
||||
// Success.
|
||||
// success
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the original content of the template file.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function reload() {
|
||||
$this->a_str_replaced_content = $this->a_str_original_content;
|
||||
$this->a_str_ReplacedContent = $this->a_str_OriginalContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content of the template file with replaced placeholders.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
* @return string Template content with replaced placeholders.
|
||||
*/
|
||||
public function get_content() {
|
||||
return $this->a_str_replaced_content;
|
||||
public function getContent() {
|
||||
return $this->a_str_ReplacedContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process template file.
|
||||
* Process template file
|
||||
*
|
||||
* @author Patrizia Lutz @misfist
|
||||
*
|
||||
* @since 2.4.0d3
|
||||
*
|
||||
* @param string $template The template to be processed.
|
||||
* @param string $template
|
||||
* @return void
|
||||
*
|
||||
* @since 2.0.3 Replace tab with a space.
|
||||
* @since 2.0.3 Replace 2 spaces with 1.
|
||||
* @since 2.0.4 Collapse multiple spaces.
|
||||
* @since 2.2.6 Delete a space before a closing pointy bracket.
|
||||
* @since 2.5.4 Collapse HTML comments and PHP/JS docblocks (only).
|
||||
*
|
||||
* @since 2.0.3 replace tab with a space
|
||||
* @since 2.0.3 replace 2 spaces with 1
|
||||
* @since 2.0.4 collapse multiple spaces
|
||||
* @since 2.2.6 delete a space before a closing pointy bracket
|
||||
* @since 2.5.4 collapse HTML comments and PHP/JS docblocks (only)
|
||||
*/
|
||||
public function process_template( $template ) {
|
||||
// phpcs:disable WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
|
||||
$this->a_str_original_content = preg_replace( '#<!--.+?-->#s', '', file_get_contents( $template ) );
|
||||
// phpcs:enable
|
||||
$this->a_str_original_content = preg_replace( '#/\*\*.+?\*/#s', '', $this->a_str_original_content );
|
||||
$this->a_str_original_content = str_replace( "\n", '', $this->a_str_original_content );
|
||||
$this->a_str_original_content = str_replace( "\r", '', $this->a_str_original_content );
|
||||
$this->a_str_original_content = str_replace( "\t", ' ', $this->a_str_original_content );
|
||||
$this->a_str_original_content = preg_replace( '# +#', ' ', $this->a_str_original_content );
|
||||
$this->a_str_original_content = str_replace( ' >', '>', $this->a_str_original_content );
|
||||
$this->a_str_OriginalContent = preg_replace( '#<!--.+?-->#s', "", file_get_contents( $template ) );
|
||||
$this->a_str_OriginalContent = preg_replace( '#/\*\*.+?\*/#s', "", $this->a_str_OriginalContent );
|
||||
$this->a_str_OriginalContent = str_replace( "\n", "", $this->a_str_OriginalContent );
|
||||
$this->a_str_OriginalContent = str_replace( "\r", "", $this->a_str_OriginalContent );
|
||||
$this->a_str_OriginalContent = str_replace( "\t", " ", $this->a_str_OriginalContent );
|
||||
$this->a_str_OriginalContent = preg_replace( '# +#', " ", $this->a_str_OriginalContent );
|
||||
$this->a_str_OriginalContent = str_replace( " >", ">", $this->a_str_OriginalContent );
|
||||
$this->reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the template.
|
||||
* Get the template
|
||||
*
|
||||
* - Adding: Templates: Enable template location stack, thanks to @misfist code contribution.
|
||||
* @author Patrizia Lutz @misfist
|
||||
*
|
||||
* @since 2.4.0d3 Contribution.
|
||||
* @since 2.5.0 Release.
|
||||
* @since 2.4.0d3
|
||||
*
|
||||
* @contributor @misfist
|
||||
* @link https://wordpress.org/support/topic/template-override-filter/#post-13864301
|
||||
*
|
||||
* @param string $p_str_file_type The file type of the template.
|
||||
* @param string $p_str_file_name The file name of the template.
|
||||
* @param string $p_str_extension The file extension of the template.
|
||||
* @param string $p_str_FileType
|
||||
* @param string $p_str_FileName
|
||||
* @param string $p_str_Extension
|
||||
* @return mixed false | template path
|
||||
*/
|
||||
public function get_template( $p_str_file_type, $p_str_file_name, $p_str_extension = 'html' ) {
|
||||
public function get_template( $p_str_FileType, $p_str_FileName, $p_str_Extension = "html" ) {
|
||||
$located = false;
|
||||
|
||||
/**
|
||||
* The directory can be changed.
|
||||
*
|
||||
* @usage to change location of templates to 'template_parts/footnotes/':
|
||||
* The directory change be modified
|
||||
* @usage to change location of templates to `template_parts/footnotes/':
|
||||
* add_filter( 'mci_footnotes_template_directory', function( $directory ) {
|
||||
* return 'template_parts/footnotes/';
|
||||
* return 'template_parts/footnotes/;
|
||||
* } );
|
||||
*/
|
||||
$template_directory = apply_filters( 'mci_footnotes_template_directory', 'footnotes/templates/' );
|
||||
$custom_directory = apply_filters( 'mci_footnotes_custom_template_directory', 'footnotes-custom/' );
|
||||
$template_name = $p_str_file_type . '/' . $p_str_file_name . '.' . $p_str_extension;
|
||||
$custom_directory = apply_filters( 'mci_footnotes_custom_template_directory', 'footnotes-custom/' );
|
||||
$template_name = $p_str_FileType . '/' . $p_str_FileName . '.' . $p_str_Extension;
|
||||
|
||||
/**
|
||||
* Look in active theme.
|
||||
* Look in active (child) theme
|
||||
*/
|
||||
if ( file_exists( trailingslashit( get_stylesheet_directory() ) . $template_directory . $template_name ) ) {
|
||||
$located = trailingslashit( get_stylesheet_directory() ) . $template_directory . $template_name;
|
||||
|
||||
/**
|
||||
* Look in parent theme in case active is child.
|
||||
*/
|
||||
/**
|
||||
* Look in parent theme
|
||||
*/
|
||||
} elseif ( file_exists( trailingslashit( get_template_directory() ) . $template_directory . $template_name ) ) {
|
||||
$located = trailingslashit( get_template_directory() ) . $template_directory . $template_name;
|
||||
|
||||
/**
|
||||
* Look in custom plugin directory.
|
||||
*/
|
||||
/**
|
||||
* Look in custom directory
|
||||
*/
|
||||
} elseif ( file_exists( trailingslashit( WP_PLUGIN_DIR ) . $custom_directory . 'templates/' . $template_name ) ) {
|
||||
$located = trailingslashit( WP_PLUGIN_DIR ) . $custom_directory . 'templates/' . $template_name;
|
||||
|
||||
/**
|
||||
* Fall back to the templates shipped with the plugin.
|
||||
*/
|
||||
/**
|
||||
* Look in plugin
|
||||
*/
|
||||
} elseif ( file_exists( $this->plugin_directory . 'templates/' . $template_name ) ) {
|
||||
$located = $this->plugin_directory . 'templates/' . $template_name;
|
||||
}
|
||||
|
@ -232,4 +258,4 @@ class MCI_Footnotes_Template {
|
|||
return $located;
|
||||
}
|
||||
|
||||
}
|
||||
} // end of class
|
||||
|
|
Reference in a new issue