Ejemplo n.º 1
0
  static function combine_type_scripts() {
    
    $files = array();
    
    $type_keys = MPFT::type_keys();

    // files to merge
    
    foreach (MPFT::type_keys() as $type) {
      $base = WOOF::root_relative_url( MPU::type_file_url($type, "") );
      $file = MPU::type_file_path($type, "mpft-$type.js");
      
      if (file_exists($file)) {
        $files[] = array("base" => $base, "file" => $file);
      }
    }
    
    $image_base = WOOF::root_relative_url( MASTERPRESS_IMAGES_URL );
    // we'll be able to kick this off with an AJAX action in the MasterPress overview
    // the dev guide for field types must point the "REBUILD" process out to developers!
    // we can also run this on install and upgrade, so that if field types change, the files would be rebuilt 
    
    // get code from archive folder if it exists, otherwise grab latest files, merge and save in archive folder
    
    if (file_exists(MASTERPRESS_CONTENT_MPFT_CACHE_DIR) && is_writable ( MASTERPRESS_CONTENT_MPFT_CACHE_DIR ) ) {

      // get and merge code

      $content = '';

      foreach ($files as $file) {
         $content .= file_get_contents($file["file"]);
      }

      MPU::incl_lib("jsminplus.php");
      $content = JSMinPlus::minify($content);
      
      $handle = fopen(MASTERPRESS_CONTENT_MPFT_CACHE_DIR."mpft-all.js", 'w');

      if ($handle) {
        if (flock($handle, LOCK_EX)) {
          fwrite($handle, $content);
          flock($handle, LOCK_UN);
        }
    
        fclose($handle);
      }
      
    }

  }