
function wpsc_uploaded_files()
By: a guest on
May 5th, 2012 | syntax:
PHP | size: 1.39 KB | hits: 23 | expires: Never
function wpsc_uploaded_files() {
global $wpdb, $wpsc_uploaded_file_cache;
$dir = @opendir( WPSC_FILE_DIR );
$num = 0;
$dirlist = array( );
if ( count( $wpsc_uploaded_file_cache ) > 0 ) {
$dirlist = $wpsc_uploaded_file_cache;
} elseif ( $dir ) {
while ( ($file = @readdir( $dir )) !== false ) {
//filter out the dots, macintosh hidden files and any backup files
if ( ($file != "..") && ($file != ".") && ($file != "product_files") && ($file != "preview_clips") && !stristr( $file, "~" ) && !( strpos( $file, "." ) === 0 ) && !strpos( $file, ".old" ) ) {
$file_data = null;
$args = array(
'post_type' => 'wpsc-product-file',
'post_name' => $file,
'numberposts' => 1,
'post_status' => 'all'
);
//// @TODO broken, does not select by post_name, need to loop at wordpress API to fix.
//$file_data = (array)get_posts($args);
if ( $file_data[0] != null ) {
$dirlist[$num]['display_filename'] = $file_data[0]->post_title;
$dirlist[$num]['file_id'] = $file_data[0]->ID;
} else {
$dirlist[$num]['display_filename'] = $file;
$dirlist[$num]['file_id'] = null;
}
$dirlist[$num]['real_filename'] = $file;
$num++;
}
}
if ( count( $dirlist ) > 0 ) {
$wpsc_uploaded_file_cache = $dirlist;
}
}
$dirlist = apply_filters( 'wpsc_downloadable_file_list', $dirlist );
return $dirlist;
}