Plugin Directory

Changeset 1945065


Ignore:
Timestamp:
09/22/2018 01:26:56 AM (8 years ago)
Author:
milardovich
Message:

new release

Location:
wp-clone-template
Files:
12 added
2 edited

Legend:

Unmodified
Added
Removed
  • wp-clone-template/trunk/main.php

    r1106766 r1945065  
    11<?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 Milardovich
    7       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*/
    99
    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');
     10define("WPCT_PATH", dirname(__FILE__).'/', true);
     11add_action('activate_wp-clone-template/main.php','install_wpct');
     12add_action('deactivate_wp-clone-template/main.php', 'uninstall_wpct');
    1313
    14     if (!function_exists('clone_plugin_url')){
    15         function clone_plugin_url(){
    16             return get_option('siteurl') . '/wp-content/plugins/' . plugin_basename(dirname(__FILE__));
     14if (!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
     21if (!isset($_SESSION['wpct_buffer'])) {
     22    $_SESSION['wpct_buffer'] = false;
     23}
     24
     25function wpct_install_wpct(){
     26    @mkdir(WPCT_PATH.'templates', 0755);
     27    return true;
     28}
     29function wpct_uninstall_wpct(){
     30    return true;
     31}
     32
     33function wpct_admin_actions(){
     34    add_theme_page('Clone Template options', 'Export', 'manage_options', 'clone_template', 'wpct_menu');
     35}
     36function wpct_menu(){
     37    include_once WPCT_PATH.'views/export.php';
     38}
     39add_action('admin_menu', 'wpct_admin_actions');
     40function 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);
    1749        }
    1850    }
     51    echo implode('</option>',$dirs).'</option>';       
     52}
     53/*
     54 * Recursive scan, based on php.net function
     55 */
     56function 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}
    1969
    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;
     70function wpct_show_warn($warn){
     71    echo '<div class="error"><p>'.$warn.'</p></div>';
     72}
     73function 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."));
    2877    }
    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));
    3194    }
    3295
    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;
    6898}
    6999
    70     function wpct_show_warn($warn){
    71         echo '<div class="error"><p>'.$warn.'</p></div>';
     100add_action('init', 'wpct_clean_output_buffer');
     101function wpct_clean_output_buffer() {
     102    ob_start();
     103}
     104
     105add_action('init', 'wpct_check_session_buffer');
     106function 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;
    72114    }
    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}
    95116
    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 ?>
     117add_action('init', 'wpct_init_session', 1);
     118function wpct_init_session(){
     119    session_start();
     120}
  • wp-clone-template/trunk/readme.txt

    r1108517 r1945065  
    1 === WP-clone-template ===
     1=== Export Themes ===
    22Contributors: milardovich
    33Tags: template,templates,clone templates,themes,copy themes,export themes, export, exporter
    4 Requires at least: 3.0
    5 Tested up to: 4.0
    6 Stable tag: 2.0
     4Requires at least: 4.0
     5Tested up to: 4.9.8
     6Stable tag: 2.1
    77Author: Sergio Milardovich
    88
     
    2929* 100% WP 4.0 Compatible
    3030
     31[22-09-2018] 2.1
     32* Warning fixed
     33* Language functions added
     34
    3135== Screenshots ==
    32361. "Export" option in the apparience menu.
Note: See TracChangeset for help on using the changeset viewer.