deleted testfile
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Template Finder searches for all woocommerce templates in theme folder and passes them to Template Fixer
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Template_Finder{
|
||||
|
||||
private $theme_folder;
|
||||
|
||||
public function __construct($theme_folder){
|
||||
$this->theme_folder = $theme_folder;
|
||||
}
|
||||
|
||||
/** iterates over all themes in search for woocommerce template folder
|
||||
* iterates over woocommerce template folder in search of templates and subdirectories
|
||||
* iterates over subdirectories in search of templates
|
||||
* @return array (template path => template text domain )
|
||||
*/
|
||||
public function get_templates(){
|
||||
//get themes
|
||||
$themes = wp_get_themes();
|
||||
$template_files = array ();
|
||||
|
||||
foreach ($themes as $theme) {
|
||||
$theme_dir = $theme->get_stylesheet_directory();
|
||||
$textdomain = $theme->get('TextDomain');
|
||||
if (is_dir($theme_dir . '/woocommerce')){
|
||||
foreach ($this->extract_files_from_subfolders($theme_dir . '/woocommerce', $textdomain) as $subentry){
|
||||
$template_files = array_merge($template_files, array($subentry=>$textdomain));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $template_files;
|
||||
}
|
||||
|
||||
private function extract_files_from_subfolders($path){
|
||||
$files = array();
|
||||
if ($handle = opendir($path)){
|
||||
}
|
||||
else {
|
||||
echo "could not open directory $path";
|
||||
}
|
||||
|
||||
while (false != ($entry = readdir($handle))){
|
||||
if ($entry === '.' or $entry === '..') continue;
|
||||
$full_path = "$path/$entry";
|
||||
if (is_dir($full_path)){
|
||||
foreach ($this->extract_files_from_subfolders("$full_path") as $subentry){
|
||||
array_push($files, $subentry);
|
||||
}
|
||||
}
|
||||
else {
|
||||
array_push($files, "$full_path");
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* class Template Fixer gets one woocommerce template of foreign theme.
|
||||
* Example:
|
||||
* esc_html_e( 'Product', 'themename' ) becomes
|
||||
* esc_html_e( 'Product', 'woocommerce')
|
||||
*/
|
||||
class Template_Fixer{
|
||||
|
||||
private $template_path, //template file to be fixed
|
||||
$textdomain, //text domain of theme (has to be changed to woocommerce)
|
||||
$file_content, //the content of the template
|
||||
$search_string; //regex string, used for replacement
|
||||
|
||||
public function __construct($template_path, $textdomain){
|
||||
$this->template_path = $template_path;
|
||||
$this->textdomain = $textdomain;
|
||||
$this->file_content = file_get_contents($this->template_path);
|
||||
$this->search_string = REGEX_START.$textdomain.REGEX_END;
|
||||
}
|
||||
|
||||
public function fix_template(){
|
||||
$current_offset = 0;
|
||||
$next_match = array();
|
||||
do {
|
||||
preg_match($this->search_string, $this->file_content, $next_match, PREG_OFFSET_CAPTURE, $current_offset);
|
||||
if (empty($next_match)){
|
||||
break;
|
||||
}
|
||||
echo "<br>";
|
||||
echo var_dump ($next_match);
|
||||
//example: echo esc_attr_x( 'Search', 'submit button', 'understrap' );
|
||||
//matches[0] -> full match
|
||||
//matches[1] -> function prefix (_x)
|
||||
//matches[2] -> word to translate (unchanged, 'Search')
|
||||
//matches[3] -> context, if present (here 'submit button')
|
||||
$current_offset = $next_match[0][1]; //beginning of string to exchange
|
||||
$function_suffix = $next_match[1][0]; //eg _e or __ (zB esc_html_e)
|
||||
$word_to_translate = $next_match[2][0];
|
||||
$cutout_length = strlen ($next_match[0][0]);
|
||||
//3 function arguments (matches[3]) remains unchanged
|
||||
if(array_key_exists(3, $next_match)){
|
||||
$context = $next_match[3][0];
|
||||
$insert_string = "$function_suffix($word_to_translate $context , 'woocommerce')";
|
||||
}
|
||||
else{
|
||||
$insert_string = "$function_suffix( $word_to_translate, 'woocommerce')";
|
||||
}
|
||||
echo ("matches[0][0] " .$next_match[0][0]);
|
||||
echo ("part to exchange: " . substr($this->file_content, $current_offset, $cutout_length));
|
||||
|
||||
$pre = substr ($this->file_content, 0, $current_offset);
|
||||
$post = substr ($this->file_content, $current_offset + $cutout_length);
|
||||
$this->file_content = $pre . $insert_string . $post;
|
||||
}while (!empty($next_match));
|
||||
if (!file_put_contents($this->template_path, $this->file_content)){
|
||||
write_log ("trying to write template: " . $this->template_path);
|
||||
}
|
||||
}
|
||||
|
||||
/** only for echoing to frontend for developement */
|
||||
public function get_template(){
|
||||
return esc_html($this->file_content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* this file contains helper functions that are useful for any plugin
|
||||
*
|
||||
*/
|
||||
|
||||
if ( ! function_exists('write_log')) {
|
||||
/** function for easily writing data to the log */
|
||||
function write_log ( $log ) {
|
||||
if ( is_array( $log ) || is_object( $log ) ) {
|
||||
error_log( print_r( $log, true ) );
|
||||
} else {
|
||||
error_log( $log );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user