Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #5752
    bebablub
    Participant

    Hello,

    thank you for your great plugin.

    Is there any possibility to import pictures from a given file system folder to a specific album automatically?
    I know about the import from folder feature. I only need the possibility to trigger it (or such a Post Request) via let’s say something like a cron job. I already captured the request but it includes a nonce value which is not infinite usable. But probably there are other (simple) ways to get it to work? I would like to avoid making a dedicated script which scans a directory, copies files and alters db (because i have to modify it probably with every update).

    The idea of this features is that i would like to import photos uploaded from my mobile phone to my owncloud storage (on same machine) automatically.

    Thank you very much!

    #5761
    Rattus
    Keymaster
    $skip_if_file_name_already_exists = true;
    $folder_path = 'PATH_TO_FOLDER_WITH_FILES';
    
    // if you do not want to assign any album or tags
    $terms = array();
    // else 
    /*
    $terms = array(
        'gmedia_album' => 'Album Name',
        'gmedia_tag' => 'tags, separated, by comma'
    );
    */
    
    $files = glob($folder_path . '?*.?*', GLOB_NOSORT);
    if (! empty($files)) {
        global $gmCore;
        $allowed_ext = get_allowed_mime_types();
        $allowed_ext = array_keys($allowed_ext);
        $allowed_ext = implode('|', $allowed_ext);
        $allowed_ext = explode('|', $allowed_ext);
        if ($skip_if_file_name_already_exists) {
            $exists = false;
        } else {
            $exists = 0;
        }
        foreach ($files as $i => $filepath) {
            $ext = pathinfo($filepath, PATHINFO_EXTENSION);
            if (! in_array(strtolower($ext), $allowed_ext)) {
                unset($files[$i]);
            }
        }
        $gmCore->gmedia_import_files($files, $terms, $move = false, $exists);
    }
    #5785
    bebablub
    Participant

    Hello,

    thank you for your reply. It gives me a brief idea on how to use gmedia functions.

    But how is this code meant to be? Probably it sounds stupid but how and from where to call that code?

    If i make a standalone php file out of it there are wordpress and gmedia gallery specific objects/methods are missing.I tried using it with the “insert php” wordpress plugin without success. If i add it to some gmedia button action, for example import it won’t give me the desired solution because the idea should be that a import should be initiated without activly logged in into admin panel (as mentions let’s say from a cron job with a call like “php -f import.php”)

    Greats

    #5787
    Rattus
    Keymaster

    You can add this code to your theme’s functions.php:

    // create a scheduled event (if it does not exist already)
    function cronstarter_activation() {
    	if( !wp_next_scheduled( 'mycronjob' ) ) {  
    	   wp_schedule_event( time(), 'daily', 'mycronjob' );  
    	}
    }
    // and make sure it's called whenever WordPress loads
    add_action('wp', 'cronstarter_activation');
    
    // here's the function we'd like to call with our cron job
    function my_repeat_function() {
    	// do here what needs to be done automatically as per your schedule
    }
    
    // hook that function onto our scheduled event:
    add_action ('mycronjob', 'my_repeat_function');

    Read more: http://wpguru.co.uk/2014/01/how-to-create-a-cron-job-in-wordpress-teach-your-plugin-to-do-something-automatically/

    #5792
    bebablub
    Participant

    Thank you very much! Seems to work now :)

    #7103
    sebastiaankop
    Participant

    Hi all,

    I used this code in functions.php.

    Works good.

    When importing large amounts of pictures the plugin has a timeout. When importing again the plugin creates doubles or triples from some pictures.

    I thought this line was to prevent doubles.

    $skip_if_file_name_already_exists = true;

    But even with this setting I get doubles.

    What can I do to prevent doubles?

    Thank you.

    Sebastiaan.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Requests and Feedback’ is closed to new topics and replies.
Forum closed. Use forum at Wordpress.org: Gmedia Support Forum