Ejemplo n.º 1
0
  public static function meta_script($type) {

    if ($type != "") {

      $js_file = MPU::type_file_path($type, "mpft-$type.js");

      if (file_exists($js_file)) : ?>
        <script type="text/javascript" src="<?php echo MPU::type_file_url($type, "mpft-$type.js")."?".filemtime($js_file) ?>"></script>
      <?php 
      endif;
      
    }

  }
Ejemplo n.º 2
0
  public function options() {
    
    // construct the HTML for the options UI
    
    $id = "";
    $type = "";
    
    if (isset($_REQUEST["type"])) {
      $type = $_REQUEST["type"];
    }
  
    if (isset($_GET["id"])) {
      $id = $_GET["id"];
    }
  
    // if the id is present, load a model
    
    if ($id && $id != "") {
      MPM::incl("field");
      $model = MPM_Field::find_by_id($id);
    }
      
    if ($type != "") {

      if ($type_class = MPFT::type_class($type)) {
        $type_options = array();
        
        if (isset($model) && isset($model->type_options)) {
          $type_options = $model->type_options;
        }
        
        $form = call_user_func_array( array($type_class, "options_form"), array(MPM::array_stripslashes($type_options)) );
      }
      
      $css_url = "";
      
      $css_file = MPU::type_file_path($type, "mpft-$type.options.css");

      if (file_exists($css_file)) {
        $css_url = MPU::type_file_url($type, "mpft-$type.options.css")."?".filemtime($css_file);
      }
      
      $js_file = MPU::type_file_path($type, "mpft-$type.options.js");

      if (file_exists($js_file)) {
        $js_url = MPU::type_file_url($type, "mpft-$type.options.js")."?".filemtime($js_file);
      }
    
      $ret = array( "form" => $form, "css_file" => $css_url, "type" => $type );
      
      if (isset($js_url)) {
        $ret["js_file"] = $js_url;
      }

      self::ajax_success( $ret );
      
    } else {
      self::ajax_error( __("field type options could not be loaded", MASTERPRESS_DOMAIN) );
    }
    
  }
Ejemplo n.º 3
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);
      }
      
    }

  }