Ejemplo n.º 1
0
/**
 * recurse a folder and apply a custom function to the files
 *
 * @param type $base_folder
 * @param type $function
 * @return array
 */
function unc_tools_recurse_files($base_folder, $file_function, $dir_function)
{
    global $TMP_FOLDERS, $UNC_GALLERY;
    if ($UNC_GALLERY['debug']) {
        XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    }
    // safety net
    if (strpos($base_folder, './')) {
        die("Error, recursive path! {$base_folder}");
    }
    if (!file_exists($base_folder)) {
        return false;
    }
    foreach (glob($base_folder . "/*") as $file) {
        if (is_dir($file)) {
            $TMP_FOLDERS[] = unc_tools_recurse_files($file, $file_function, $dir_function);
        } else {
            // working on $file in folder $main
            $TMP_FOLDERS[] = $file_function($file);
        }
    }
    $TMP_FOLDERS[] = $dir_function($base_folder);
    return $TMP_FOLDERS;
}
Ejemplo n.º 2
0
/**
 * Function to delte all contents
 * @global type $UNC_GALLERY
 */
function unc_gallery_admin_delete_everything()
{
    global $UNC_GALLERY, $wpdb;
    if ($UNC_GALLERY['debug']) {
        XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    }
    ob_clean();
    if (!current_user_can('manage_options')) {
        echo "Cannot delete all, you are not admin!";
    } else {
        // delete all images
        unc_tools_recurse_files($UNC_GALLERY['upload_path'], 'unlink', 'rmdir');
        // delete all data
        $sql1 = "TRUNCATE " . $wpdb->prefix . "unc_gallery_img";
        $wpdb->get_results($sql1);
        $sql2 = "TRUNCATE " . $wpdb->prefix . "unc_gallery_att";
        $wpdb->get_results($sql2);
        echo "Done!";
    }
    wp_die();
}