Esempio n. 1
0
  public static function refresh() {

    global $wf;

    $values = json_decode(stripslashes($_REQUEST["values"]), true);

    if (!is_array($values)) {
      $values = array($values);
    }
    
    $model_id = $_REQUEST["model_id"];
    
    $field = MPM_Field::find_by_id($model_id);
    
    if ($field) {
      $selects = self::selects($field->type_options, $values);
      $info["select"] = WOOF::render_template($selects["select"], array("id" => $_REQUEST["id"], "name" => str_replace("[]", "", $_REQUEST["name"])  ) );
      self::ajax_success( $info );
    }
    
  }
Esempio n. 2
0
  function t($tmpl, $default = null) {
    
    $blank = $this->blank();
    
    if (!$blank || !is_null($default)) {
      if ($blank) {
        $value = $default;
      } else {
        $value = $this->__toString();
      }
      
      if (!preg_match("/\{\{.+\}\}/", $tmpl)) {
      
        // assume we want the value in the innermost tag
      
        WOOF::incl_phpquery();
        phpQuery::newDocumentHTML('<div class="context"></div>', $charset = 'utf-8');
        pq($tmpl)->appendTo(".context");
        pq("*:only-child:last")->append("{{val}}");
        $tmpl = pq(".context")->html();
      }

      return WOOF::render_template($tmpl, array("value" => $value, "val" => $value) );
    }
    
    return "";
    
  }
Esempio n. 3
0
 function render($data = array(), $strip_whitespace = false) {
   return WOOF::render_template($this->contents(), array_filter( $data, "is_not_woof_silent" ), $strip_whitespace );
 }
Esempio n. 4
0
  public static function set_item_template_data(MEOW_FieldSet &$set, $args = array()) {
    
    $r = wp_parse_args(
      $args,
      array("preview" => false, "readonly" => !$set->is_editable(), "id_base" => "mp_meta_", "name_base" => "mp_meta", "order_base" => "mp_meta_order", "summary_preview_base" => "mp_summary_preview_", "summary_base" => "mp_summary_" )
    );
    
    $d = array();
     
    $set_item_classes = array();
    $set_fields_classes = array();
    $set_summary_classes = array();
    
    $d["allow_remove"] = true;
    
    if ($r["preview"]) {
      $d["preview"] = true;
      $d["allow_remove"] = false;
    } 
    
    if ($r["readonly"]) {
      $d["readonly"] = true;
      $d["allow_remove"] = false;
    }

    
    $info = $set->info();
    
    if ($info->expanded) {
      $d["toggle_class"] = "collapse";
      $set_item_classes[] = "expanded";
      $set_summary_classes[] = "hidden";
    } else {
      $d["toggle_class"] = "expand";
      $set_item_classes[] = "collapsed";
      $set_fields_classes[] = "hidden";
    }
    
    if (isset($args["versions_select"])) {
      $d["versions_select"] = $args["versions_select"];
    }
    
    $d["lang_are_you_sure"] = esc_js(__("Are you sure?", MASTERPRESS_DOMAIN));

    $d["label_collapse"] = __("Collapse", MASTERPRESS_DOMAIN);
    

    $d["set_item_classes"] = implode(" ", $set_item_classes);
    $d["set_fields_classes"] = implode(" ", $set_fields_classes);
    
    $d["description"] = trim( $info->label("description") );

    $d["allow_multiple"] = $info->allow_multiple;

    $d["labels_toggle"] = __("Toggle", MASTERPRESS_DOMAIN);
    
    $d["set_labels_remove_plain"] = strip_tags($info->label("remove"));
    $d["set_labels_remove"] = $info->label("remove");
        
    $d["fields"] = array();

    if ( WOOF::is_true_arg($args, "creator") ) {
      $i = "!!set_index!!";
    } else if ($set->creator) {
      // leave a placeholder for Handlebars to render into
      $i = "{{set_index}}";
    } else { 
      $i = $set->index();
    }
    
    
    
    $d["set_index"] = $i;
    
    $set_id = $r["id_base"]."{$info->name}_$i"; 
    $set_name = $r["name_base"]."[{$info->name}][$i]"; 
    
    if (WOOF::is_true_arg($r, "nested")) {
      $d["order_name"] = $r["order_base"]."[$i]"; 
    } else {
      $d["order_name"] = $r["order_base"]."[{$info->name}][$i]"; 
    }
  
    
    
    $d["fields"] = array();
    
    $fields = $info->fields(); 
    $fi = 0; 
    $fc = 0;
    
    foreach ($fields as $field) {
      if ($type_class = MPFT::type_class($field->type)) {
        $fc++;
      }
    }
    
    foreach ($fields as $field) {

      if ($field->current_user_can_see()) {

        $field_id = "{$set_id}_{$field->name}";
        $field_name = "{$set_name}[{$field->name}]";

        if ($r["preview"]) {
          $field_summary_id = $r["summary_preview_base"]."{$info->name}_{$field->name}";
        } else {
          $field_summary_id = $r["summary_base"]."{$info->name}_{$field->name}";
        }
      
      
        $fd = array(); // the field data

        if ($ftc = MPFT::type_class($field->type)) {
          $fi++; 

          $fd["model_id"] = $field->id;
          $fd["readonly"] = false; // reset
    
          $fd["label_is_header"] = call_user_func_array( array($ftc, "label_is_header"), array($field->type_options));
          $fd["type"] = $field->type;
          $fd["type_widget"] = "mpft_".str_replace("-", "_", $field->type);
          $fd["label"] = $field->display_label();
          $fd["esc_label"] = esc_attr($field->display_label());
          $fd["label_suffix"] = call_user_func( array($ftc, "label_suffix") );
        
          $fd["field_path"] = $info->name."-".$field->name;

          $fd["prop_list"] = implode(",", MPFT::type_properties($field->type));
        
          $fd["description"] = trim( $field->label("description") );

          $fd["pos_class"] = WOOF_HTML::pos_class_1($fi, $fc, " mp-field-");

          if ($field->current_user_can_manage()) {
            $mu = $field->manage_url($info);
            
            $mu .= "&mp_redirect=".urlencode($_SERVER["REQUEST_URI"]);
            
            if ($mu) {
              $fd["go"] = '<a href="'.$mu.'" class="mp-go with-mptt" data-tooltip="'.__("Edit Field Definition", MASTERPRESS_DOMAIN).'">'.__("Edit Field Definition").'</a>';
            }


          }
          
          $field_classes = array("mpft-".$field->type);
        
          if ($fi == $fc) {
            $field_classes[] = "mp-field-last";
          }
        
          $field_summary_classes = array();
        
          if ($field->required) {
            $field_classes[] = "required";
            $field_summary_classes[] = "required";
          }
        
          if (isset($field->summary_options["emphasise"])) {
            $field_summary_classes[] = "em";
          }
        
          $fd["name"] = $field->name;
          $fd["template_id"] = "{$info->name}_{$field->name}";
          $fd["summary_id"] = $field_summary_id."_".$i;
          $fd["field_id"] = $field_id;


        
          $fd["id_first"] = $field_id;
        
          $opts = call_user_func( array($ftc, "ui_options") );
        
          $ui = array();
        
          if (count($opts) ) {
            $ui = call_user_func_array( array($ftc, "extract_options"), array($field->type_options, $opts) );
            $ui = call_user_func_array( array($ftc, "normalize_options"), array($ui) );
          }
        
        
        
          $ui_parts = array();
        
          if (count($ui)) {
            foreach( $ui as $key => $value ) {
              $ui_parts[] = "'$key':'".esc_attr(esc_js($value))."'"; 
            } 
          }
        
          // $fd["lang"] = "{".implode(",", $lang_parts)."}";

          $fd["ui"] = "{".implode(",", $ui_parts)."}";
        
          if (isset($field->labels["tooltip_help"])) {
            $tooltip_help = trim($field->label("tooltip_help"));

            if ($tooltip_help != "") {
              $fd["label_tooltip"] = "#mptt_".$info->id."_".$field->id;
            }
          }

          if (!$field->current_user_can_edit($set->is_editable()) && !$r["preview"]) {
            $fd["readonly"] = true;
          }
        
          $strip_whitespace = !call_user_func( array($ftc, "ui_preserve_whitespace") );
        
          $ftd_args = $r;
          
          if ($set->creator) {
            
            $meow_field = new MEOW_FieldCreator($field->name, null, $field);
          
            call_user_func_array( array($ftc, "apply_default"), array($meow_field, $set, $ftc) );
            $field_ui_data = self::field_ui_template_data($set, $meow_field, $ftd_args);
            $field_ui = WOOF::render_template( self::field_ui_template(), $field_ui_data, $strip_whitespace );
          
          } else {

            // here we regard the actual field value, and build the UI from that
            $meow_field = $set->field($field->name); 

            $action = "";
          
            if (isset($_GET["action"])) {
              $action = $_GET["action"];
            }

            if (!$info->allow_multiple && $action != "edit") {
              call_user_func_array( array($ftc, "apply_default"), array($meow_field, $set, $ftc) );
            }

            $field_ui_data = self::field_ui_template_data($set, $meow_field, $ftd_args);
            $field_ui = WOOF::render_template( self::field_ui_template(), $field_ui_data, $strip_whitespace );
        
          }

          
          if ($fi == $fc) {
            if ($meow_field->blank()) {
              $set_summary_classes[] = "last-empty";
            }
        
          }
          
          $fd["field_ui"] = $field_ui;
        
        
          // now build out the summary info
        
        
          $fd["summary_width"] = call_user_func( array($ftc, "summary_width") );
        
          if (isset($field->summary_options["width"])) {
            $sw = (int) $field->summary_options["width"];
          
            if ($sw >= 1 && $sw <= 5) {
              $fd["summary_width"] = $sw;
            }
          
          }
        
        
          $max_length = ( $fd["summary_width"] * 138 ) / 10;
        
          $fd["label_truncated"] = WOOF::truncate_basic( $fd["label"], $max_length, "<span>&hellip;</span>" );
      
          if ($fd["label"] != $fd["label_truncated"]) {
            $fd["label_title"] = strip_tags($fd["label"]);
          }
        
          $label_classes = array();
        
          if (method_exists($ftc, "summary_label_classes")) {
            $label_classes = call_user_func_array( array($ftc, "summary_label_classes"), array($meow_field) );
          } 
          
          $fd["label_classes"] = implode(" ", $label_classes);
        
          $empty = $meow_field->blank();


          $fd["empty_summary"] = call_user_func_array( array($ftc, "empty_summary"), array($meow_field) );
          $fd["summary"] = call_user_func_array( array($ftc, "summary"), array($meow_field) );

          if ($empty) {
            $field_summary_classes[] = "empty";
          } else {
            $fd["is_edit"] = "is-edit";
          }
        
          $fd["classes"] = implode(" ", $field_classes);
          $fd["summary_classes"] = implode(" ", $field_summary_classes);
        
          // add the field data to the main data array
          $d["fields"][] = $fd;  
      
      
        } // endif class_exists($ftc)
    
      } // current user can see
    
    } // endforeach
      
    
    $d["set_summary_classes"] = implode(" ", $set_summary_classes);


    return $d;
    
  }