function wppa_delete_album_source($album)
{
    if (wppa_switch('keep_sync')) {
        @rmdir(wppa_get_source_album_dir($album));
    }
}
function wppa_remake_files($alb = '', $pid = '')
{
    global $wpdb;
    // Init
    $count = '0';
    // Find the album( s ) if any
    if (!$alb && !$pid) {
        $start_time = get_option('wppa_remake_start', '0');
        $albums = $wpdb->get_results('SELECT `id` FROM `' . WPPA_ALBUMS . '`', ARRAY_A);
    } elseif ($alb) {
        $start_time = get_option('wppa_remake_start_album_' . $alb, '0');
        $albums = array(array('id' => $alb));
    } else {
        $albums = false;
    }
    // Do it with albums
    if ($albums) {
        foreach ($albums as $album) {
            $source_dir = wppa_get_source_album_dir($album['id']);
            if (is_dir($source_dir)) {
                $files = glob($source_dir . '/*');
                if ($files) {
                    foreach ($files as $file) {
                        if (!is_dir($file)) {
                            $filename = basename($file);
                            $photos = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `filename` = %s OR ( `filename` = '' AND `name` = %s )", $filename, $filename), ARRAY_A);
                            if ($photos) {
                                foreach ($photos as $photo) {
                                    // Photo exists
                                    $modified_time = $photo['modified'];
                                    if ($modified_time < $start_time) {
                                        wppa_update_single_photo($file, $photo['id'], $filename);
                                        //							$wpdb->query( $wpdb->prepare( 'UPDATE `'.WPPA_PHOTOS.'` SET `modified` = %s WHERE `id` = %s', time(), $photo['id'] ) );
                                        $count++;
                                    }
                                    if (wppa_is_time_up($count)) {
                                        return false;
                                    }
                                }
                            } else {
                                // No photo yet
                                if (wppa_switch('remake_add')) {
                                    wppa_insert_photo($file, $album['id'], $filename);
                                    //	$wpdb->query( $wpdb->prepare( 'UPDATE `'.WPPA_PHOTOS.'` SET `modified` = %s WHERE `id` = %s', time(), $photo['id'] ) );
                                    $count++;
                                }
                            }
                            if (wppa_is_time_up($count)) {
                                return false;
                            }
                        }
                    }
                }
            }
        }
    } elseif ($pid) {
        $photo = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s", $pid), ARRAY_A);
        if ($photo) {
            $file = wppa_get_source_path($photo['id']);
            if (is_file($file)) {
                $name = $photo['filename'];
                wppa_update_single_photo($file, $pid, $name);
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
    return true;
}
Example #3
0
function wppa_delete_album_source($album)
{
    global $wppa_opt;
    if (wppa_switch('wppa_keep_sync')) {
        @rmdir(wppa_get_source_album_dir($album));
    }
}