Changeset 1945065
- Timestamp:
- 09/22/2018 01:26:56 AM (8 years ago)
- Location:
- wp-clone-template
- Files:
-
- 12 added
- 2 edited
-
tags/2.1 (added)
-
tags/2.1/lib (added)
-
tags/2.1/lib/pclzip.lib.php (added)
-
tags/2.1/license.txt (added)
-
tags/2.1/main.php (added)
-
tags/2.1/readme.txt (added)
-
tags/2.1/screenshot-1.png (added)
-
tags/2.1/screenshot-2.png (added)
-
tags/2.1/screenshot-3.png (added)
-
tags/2.1/thumb.png (added)
-
tags/2.1/views (added)
-
tags/2.1/views/export.php (added)
-
trunk/main.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-clone-template/trunk/main.php
r1106766 r1945065 1 1 <?php 2 /*3 Plugin Name: WP-clone-template 4 Description: A simple plugin to export templates in a .zip file and then install them from the same package in other servers.5 Version: 2.0 6 Author: Sergio Milardovich7 Author URI: http://milardovich.com.ar/8 */2 /* 3 Plugin Name: Export Themes 4 Description: A simple plugin to export templates in a .zip file and then install them from the same package in other servers. 5 Version: 2.1 6 Author: Sergio Milardovich 7 Author URI: http://milardovich.com.ar/ 8 */ 9 9 10 define("WPCT_PATH", dirname(__FILE__).'/', true);11 add_action('activate_wp-clone-template/main.php','install_wpct');12 add_action('deactivate_wp-clone-template/main.php', 'uninstall_wpct');10 define("WPCT_PATH", dirname(__FILE__).'/', true); 11 add_action('activate_wp-clone-template/main.php','install_wpct'); 12 add_action('deactivate_wp-clone-template/main.php', 'uninstall_wpct'); 13 13 14 if (!function_exists('clone_plugin_url')){ 15 function clone_plugin_url(){ 16 return get_option('siteurl') . '/wp-content/plugins/' . plugin_basename(dirname(__FILE__)); 14 if (!function_exists('clone_plugin_url')){ 15 function clone_plugin_url(){ 16 return get_option('siteurl') . '/wp-content/plugins/' . plugin_basename(dirname(__FILE__)); 17 } 18 } 19 20 21 if (!isset($_SESSION['wpct_buffer'])) { 22 $_SESSION['wpct_buffer'] = false; 23 } 24 25 function wpct_install_wpct(){ 26 @mkdir(WPCT_PATH.'templates', 0755); 27 return true; 28 } 29 function wpct_uninstall_wpct(){ 30 return true; 31 } 32 33 function wpct_admin_actions(){ 34 add_theme_page('Clone Template options', 'Export', 'manage_options', 'clone_template', 'wpct_menu'); 35 } 36 function wpct_menu(){ 37 include_once WPCT_PATH.'views/export.php'; 38 } 39 add_action('admin_menu', 'wpct_admin_actions'); 40 function wpct_get_templates_options(){ 41 $root = substr($_SERVER['SCRIPT_FILENAME'],0,-19).'wp-content/themes'; 42 $dirs = array(); 43 if(is_dir($root)){ 44 $dir = opendir($root); 45 } 46 while ($direc = readdir($dir)){ 47 if(is_dir($root.'/'.$direc) && $direc !== '..' && $direc !== '.'){ 48 array_push($dirs, '<option value="'.$direc.'">'.$direc); 17 49 } 18 50 } 51 echo implode('</option>',$dirs).'</option>'; 52 } 53 /* 54 * Recursive scan, based on php.net function 55 */ 56 function rscandir($base='', &$data=array()) { 57 $array = array_diff(scandir($base), array('.', '..')); # remove ' and .. from the array */ 58 foreach($array as $value){ /* loop through the array at the level of the supplied $base */ 59 if (is_dir($base.$value)){ /* if this is a directory */ 60 $data[] = $base.$value.'/'; /* add it to the $data array */ 61 $data = rscandir($base.$value.'/', $data); /* then make a recursive call with the 62 current $value as the $base supplying the $data array to carry into the recursion */ 63 } elseif (is_file($base.$value)) { /* else if the current $value is a file */ 64 $data[] = array($base,$value); /* just add the current $value to the $data array */ 65 } 66 } 67 return $data; 68 } 19 69 20 21 if (!isset($_SESSION['wpct_buffer'])) { 22 $_SESSION['wpct_buffer'] = false; 23 } 24 25 function install_wpct(){ 26 @mkdir(WPCT_PATH.'templates', 0755); 27 return true; 70 function wpct_show_warn($warn){ 71 echo '<div class="error"><p>'.$warn.'</p></div>'; 72 } 73 function wpct_export_template($template){ 74 require_once WPCT_PATH.'lib/pclzip.lib.php'; 75 if(!is_dir(WPCT_PATH.'templates')){ 76 @mkdir(WPCT_PATH.'templates', 0755) or wpct_show_warn(__("I'm not able to create the tmp directory 'templates', please, check your permissons or create it manually.")); 28 77 } 29 function uninstall_wpct(){ 30 return true; 78 @chmod(WPCT_PATH."templates", 0755); 79 if(file_exists(WPCT_PATH.'templates/'.$template.'.zip')){ 80 @unlink(WPCT_PATH.'templates/'.$template.'.zip') or wpct_show_warn(__("I'm not able to delete the zip file in the directory 'templates', please, check your permissons or delete it manually.")); 81 } 82 $export = new PclZip(WPCT_PATH.'templates/'.$template.'.zip'); 83 $template_root = substr($_SERVER['SCRIPT_FILENAME'],0,-19).'wp-content/themes/'.$template.'/'; 84 $files = rscandir($template_root); 85 foreach($files as $file){ 86 if($file[0].$file[1] !== '/v' && (is_file($file[0].$file[1]) or is_dir($file[0].$file[1]))){ 87 $add[] = $file[0].$file[1]; 88 } 89 } 90 $add = implode(',',$add); 91 $make = $export->add($add, PCLZIP_OPT_REMOVE_PATH, substr($_SERVER['SCRIPT_FILENAME'],0,-19).'wp-content/themes'); 92 if ($make == 0) { 93 die("Error : ".$export->errorInfo(true)); 31 94 } 32 95 33 function wpct_admin_actions(){ 34 add_theme_page('Clone Template options', 'Export', 'manage_options', 'clone_template', 'wpct_menu'); 35 } 36 function wpct_menu(){ 37 include_once WPCT_PATH.'views/export.php'; 38 } 39 add_action('admin_menu', 'wpct_admin_actions'); 40 function wpct_get_templates_options(){ 41 $root = substr($_SERVER['SCRIPT_FILENAME'],0,-19).'wp-content/themes'; 42 $dirs = array(); 43 if(is_dir($root)){ 44 $dir = opendir($root); 45 } 46 while ($direc = readdir($dir)){ 47 if(is_dir($root.'/'.$direc) && $direc !== '..' && $direc !== '.'){ 48 array_push($dirs, '<option value="'.$direc.'">'.$direc); 49 } 50 } 51 echo implode('</option>',$dirs).'</option>'; 52 } 53 /* 54 * Recursive scan, based on php.net function 55 */ 56 function rscandir($base='', &$data=array()) { 57 $array = array_diff(scandir($base), array('.', '..')); # remove ' and .. from the array */ 58 foreach($array as $value){ /* loop through the array at the level of the supplied $base */ 59 if (is_dir($base.$value)){ /* if this is a directory */ 60 $data[] = $base.$value.'/'; /* add it to the $data array */ 61 $data = rscandir($base.$value.'/', $data); /* then make a recursive call with the 62 current $value as the $base supplying the $data array to carry into the recursion */ 63 } elseif (is_file($base.$value)) { /* else if the current $value is a file */ 64 $data[] = array($base,$value); /* just add the current $value to the $data array */ 65 } 66 } 67 return $data; 96 $_SESSION['wpct_buffer'] = true; 97 wp_redirect(get_option('siteurl') . '/wp-content/plugins/' . plugin_basename(dirname(__FILE__)).'/templates/'.$template.'.zip', 301); exit; 68 98 } 69 99 70 function wpct_show_warn($warn){ 71 echo '<div class="error"><p>'.$warn.'</p></div>'; 100 add_action('init', 'wpct_clean_output_buffer'); 101 function wpct_clean_output_buffer() { 102 ob_start(); 103 } 104 105 add_action('init', 'wpct_check_session_buffer'); 106 function wpct_check_session_buffer(){ 107 if($_SESSION['wpct_buffer'] == true){ 108 $files = glob(WPCT_PATH.'templates/*'); // get all file names 109 foreach($files as $file){ // iterate files 110 if(is_file($file)) 111 unlink($file); // delete file 112 } 113 $_SESSION['wpct_buffer'] = false; 72 114 } 73 function wpct_export_template($template){ 74 require_once WPCT_PATH.'lib/pclzip.lib.php'; 75 if(!is_dir(WPCT_PATH.'templates')){ 76 @mkdir(WPCT_PATH.'templates', 0755) or wpct_show_warn("I'm not able to create the directory '".WPCT_PATH."templates', please, check your permissons or create it manually."); 77 } 78 @chmod(WPCT_PATH."templates", 0755); 79 if(file_exists(WPCT_PATH.'templates/'.$template.'.zip')){ 80 @unlink(WPCT_PATH.'templates/'.$template.'.zip') or wpct_show_warn("I'm not able to delete the file $template.zip in the directory 'templates', please, check your permissons or delete it manually."); 81 } 82 $export = new PclZip(WPCT_PATH.'templates/'.$template.'.zip'); 83 $template_root = substr($_SERVER['SCRIPT_FILENAME'],0,-19).'wp-content/themes/'.$template.'/'; 84 $files = rscandir($template_root); 85 foreach($files as $file){ 86 if($file[0].$file[1] !== '/v' && (is_file($file[0].$file[1]) or is_dir($file[0].$file[1]))){ 87 $add[] = $file[0].$file[1]; 88 } 89 } 90 $add = implode(',',$add); 91 $make = $export->add($add, PCLZIP_OPT_REMOVE_PATH, substr($_SERVER['SCRIPT_FILENAME'],0,-19).'wp-content/themes'); 92 if ($make == 0) { 93 die("Error : ".$export->errorInfo(true)); 94 } 115 } 95 116 96 $_SESSION['wpct_buffer'] = true; 97 wp_redirect(get_option('siteurl') . '/wp-content/plugins/' . plugin_basename(dirname(__FILE__)).'/templates/'.$template.'.zip', 301); exit; 98 } 99 100 add_action('init', 'clean_output_buffer'); 101 function clean_output_buffer() { 102 ob_start(); 103 } 104 105 add_action('init', 'check_session_buffer'); 106 function check_session_buffer(){ 107 if($_SESSION['wpct_buffer'] == true){ 108 $files = glob(WPCT_PATH.'templates/*'); // get all file names 109 foreach($files as $file){ // iterate files 110 if(is_file($file)) 111 unlink($file); // delete file 112 } 113 $_SESSION['wpct_buffer'] = false; 114 } 115 } 116 117 add_action('init', 'init_session', 1); 118 function init_session(){ 119 session_start(); 120 } 121 122 ?> 117 add_action('init', 'wpct_init_session', 1); 118 function wpct_init_session(){ 119 session_start(); 120 } -
wp-clone-template/trunk/readme.txt
r1108517 r1945065 1 === WP-clone-template===1 === Export Themes === 2 2 Contributors: milardovich 3 3 Tags: template,templates,clone templates,themes,copy themes,export themes, export, exporter 4 Requires at least: 3.05 Tested up to: 4. 06 Stable tag: 2. 04 Requires at least: 4.0 5 Tested up to: 4.9.8 6 Stable tag: 2.1 7 7 Author: Sergio Milardovich 8 8 … … 29 29 * 100% WP 4.0 Compatible 30 30 31 [22-09-2018] 2.1 32 * Warning fixed 33 * Language functions added 34 31 35 == Screenshots == 32 36 1. "Export" option in the apparience menu.
Note: See TracChangeset
for help on using the changeset viewer.