Don't like ads? PRO users don't see any ads ;-)
Guest

function wpsc_uploaded_files()

By: a guest on May 5th, 2012  |  syntax: PHP  |  size: 1.39 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. function wpsc_uploaded_files() {
  3.         global $wpdb, $wpsc_uploaded_file_cache;
  4.         $dir = @opendir( WPSC_FILE_DIR );
  5.         $num = 0;
  6.         $dirlist = array( );
  7.  
  8.         if ( count( $wpsc_uploaded_file_cache ) > 0 ) {
  9.                 $dirlist = $wpsc_uploaded_file_cache;
  10.         } elseif ( $dir ) {
  11.                 while ( ($file = @readdir( $dir )) !== false ) {
  12.                         //filter out the dots, macintosh hidden files and any backup files
  13.                         if ( ($file != "..") && ($file != ".") && ($file != "product_files") && ($file != "preview_clips") && !stristr( $file, "~" ) && !( strpos( $file, "." ) === 0 ) && !strpos( $file, ".old" ) ) {
  14.                                 $file_data = null;
  15.                                 $args = array(
  16.                                         'post_type' => 'wpsc-product-file',
  17.                                         'post_name' => $file,
  18.                                         'numberposts' => 1,
  19.                                         'post_status' => 'all'
  20.                                 );
  21.  
  22.                                 //// @TODO broken, does not select by post_name, need to loop at wordpress API to fix.
  23.                                 //$file_data = (array)get_posts($args);
  24.  
  25.  
  26.                                 if ( $file_data[0] != null ) {
  27.                                         $dirlist[$num]['display_filename'] = $file_data[0]->post_title;
  28.                                         $dirlist[$num]['file_id'] = $file_data[0]->ID;
  29.                                 } else {
  30.                                         $dirlist[$num]['display_filename'] = $file;
  31.                                         $dirlist[$num]['file_id'] = null;
  32.                                 }
  33.                                 $dirlist[$num]['real_filename'] = $file;
  34.                                 $num++;
  35.                         }
  36.                 }
  37.  
  38.                 if ( count( $dirlist ) > 0 ) {
  39.                         $wpsc_uploaded_file_cache = $dirlist;
  40.                 }
  41.         }
  42.  
  43.         $dirlist = apply_filters( 'wpsc_downloadable_file_list', $dirlist );
  44.  
  45.         return $dirlist;
  46. }