Status: offline

::Ben

Forum User
Full Member
Registered: 14/01/2005
Posts: 1569
I'm creating and testing plugins for Geeklog CMS with WAMP. As files for a plugin are store in 3 directories (plugins, public_html, admin) I wrote a function to copy all new or modified files and folders to a unique folder. And from this folder I can push to Github.

Customize this code for your needs and put it in your system/lib-custom.php file

PHP Formatted Code

// Geeklog CMS - Copy plugins to external folder if files are new

global $_PLUGINS;

// List of plugins you want to copy
$github_plugins = array('test','captcha');

foreach ($_PLUGINS as $plugin) {

    if (!in_array($plugin, $github_plugins)) continue;
   
    //Sources in plugins folder
    $src = $_CONF['path'] . 'plugins/' . $plugin;
    //Customize your destination
    $dst = "c:/plugins/$plugin";
    CUSTOM_recurse_copy($src, $dst);
   
    //Sources in public_html folder
    $src = $_CONF['path_html'] . $plugin;
    //Customize your destination
    $dst = "c:/plugins/$plugin/public_html";
    CUSTOM_recurse_copy($src, $dst);
   
    //Sources in admin folder
    $src = $_CONF['path_html'] . 'admin/plugins/' . $plugin;
    //Customize your destination
    $dst = "c:/plugins/$plugin/admin";
    CUSTOM_recurse_copy($src, $dst);

}

function CUSTOM_recurse_copy($src,$dst) {
   
    //Uncomment this line if you do not need to copy files
    //return;  
   
    global $_CONF;
   
    if (is_dir($src)) {
        $dir = opendir($src);
        if (!is_dir($dst)) mkdir($dst);
        while(false !== ( $file = readdir($dir)) ) {
            if (( $file != '.' ) && ( $file != '..' )) {
                if ( is_dir($src . '/' . $file) ) {
                    CUSTOM_recurse_copy( $src . '/' . $file, $dst . '/' . $file);
                }
                else {
                    //Check if source is newer
                    if ( file_exists($dst . '/' . $file) ) {
                        if ( filemtime($dst . '/' . $file) < filemtime($src . '/' . $file) ) copy($src . '/' . $file, $dst . '/' . $file);                             
                    } else {
                        copy($src . '/' . $file, $dst . '/' . $file);
                    }
                }
            }
        }
        closedir($dir);
    }
}

I'm available to customise your themes or plugins for your Geeklog CMS

Status: offline

Laugh

Site Admin
Admin
Registered: 27/09/2005
Posts: 1232
A good idea. It has always been a bit of a pain to remember which files have changed.
One of the Geeklog Core Developers.