Esempio n. 1
0
  public static function options_form( $options ) {

    global $meow_provider;

    global $wf;
    
    $p = self::type_prefix(__CLASS__);

    $defaults = array();

    if (MPC::is_create()) {
      $defaults = array("maxwidth" => 580, "height" => 300, "control_style" => "drop_down_list");
    }

    $options = wp_parse_args( $options, $defaults );

    if (MPC::is_create()) {
      $options["post_types"] = array();
    }
      
    // setup variables to insert into the heredoc string
    // (this is required where we cannot call functions within heredoc strings)

    $taxonomies_label = __("Available Taxonomies:", MASTERPRESS_DOMAIN);

    $taxonomies_note = __("Select the taxonomies of terms available for selection in the field control", MASTERPRESS_DOMAIN);

    $taxonomies_items = array();

    MPM::incl("taxonomy");

    $taxonomies = MPM_Taxonomy::find("orderby=disabled,name ASC");

    $taxonomies_selected = array();

    foreach ($taxonomies as $taxonomy) {
    
      if (!$taxonomy->disabled && $taxonomy->show_ui && $taxonomy->still_registered()) {
        $taxonomies_selected[] = $taxonomy->name;
        $taxonomies_items[$taxonomy->display_label()] = $taxonomy->name;
      }

    }

    if (!MPC::is_create()) {
      $taxonomies_selected = self::option_value($options, "taxonomies");
    }

    if (!is_array($taxonomies_selected)) {
      $taxonomies_selected = explode(",", $taxonomies_selected);
    }
  
    $id = $p."taxonomies-";
    
    $taxonomies_checkboxes = "";
    
    foreach ($taxonomies as $taxonomy) {


      if (!$taxonomy->disabled && $taxonomy->show_ui && $taxonomy->still_registered()) {
      
        $value = $taxonomy->name;
        $label = $taxonomy->display_label();
      
        $id_suffix = WOOF::sanitize($value);
      
        $attr = array( "id" => $id."_".$id_suffix, "class" => "checkbox", "type" => "checkbox", "name" => "type_options[taxonomies][]", "value" => $value );
      
        if (in_array($value, $taxonomies_selected)) {
          $attr["checked"] = "checked";
        }
      
        $taxonomies_checkboxes .= WOOF_HTML::open("div", "class=fwi");
        $taxonomies_checkboxes .= WOOF_HTML::tag("input", $attr );
        $taxonomies_checkboxes .= WOOF_HTML::tag("label", array( "for" => $id."_".$id_suffix, "class" => "checkbox mp-icon-taxonomy mp-icon-taxonomy-".$value ), $label );
        $taxonomies_checkboxes .= WOOF_HTML::close("div");

      }

    }
    
    $ex_label = __("Description", MASTERPRESS_DOMAIN);
    $title_label = __("Name", MASTERPRESS_DOMAIN);
    
    $results_row_style = MPFT::options_select_results_row_style( $p, $options, array("excerpt" => $ex_label, "title" => $title_label ) );

    $placeholder = MPFT::options_placeholder($p, $options);

    $basic = MPFT::options_select_basic( $p, $options );
    $multi_layout = MPFT::options_select_multi_layout( $p, $options );
    $control_style = MPFT::options_select_control_style( $p, $options );
    $maxwidth = MPFT::options_maxwidth( $p, $options );
    $height = MPFT::options_height( $p, $options );
    $grouping = MPFT::options_select_grouping( $p, $options, __("Taxonomy", MASTERPRESS_DOMAIN) );

    $results_input_length = MPFT::options_input_text( $p, $options, "results_input_length", __("Minimum Input Length", MASTERPRESS_DOMAIN), __("Enter the number of characters required before any results are displayed.<br />This is useful for large numbers of posts, where performance may become poor.", MASTERPRESS_DOMAIN));


    $data_source_label = __("Data Source - <span>specify the terms available for selection</span>", MASTERPRESS_DOMAIN); 
    $control_options_label = __("Control Options", MASTERPRESS_DOMAIN); 
    $control_results_label = __("Results Display - <span>settings for the display of the available terms</span>", MASTERPRESS_DOMAIN); 
    $control_selections_label = __("Selection Display - <span>settings for the display of the selected terms</span>", MASTERPRESS_DOMAIN); 



    // build a taxonomies grid
    
    $results_row_item_prop_label = __("Row Item Properties:", MASTERPRESS_DOMAIN);
    $results_row_item_prop_note = __("Defines the term properties used to derive the info shown in result rows.<br /><b>Note: </b>Descriptions and images will be truncated / resized automatically.", MASTERPRESS_DOMAIN);
    
    
    $row_style = self::option_value($options, "row_style", "icon_title");

    $grid  = WOOF_HTML::open("table", "class=grid mini not-selectable grid-row-item-prop&cellspacing=0");
      $grid .= WOOF_HTML::open("thead");
      
        $grid .= WOOF_HTML::tag("th", "class=icon taxonomy", WOOF_HTML::tag("i", "class=tags", "") . WOOF_HTML::tag("span", null, __("Taxonomy", MASTERPRESS_DOMAIN)));

        $grid .= WOOF_HTML::tag("th", "class=icon title", WOOF_HTML::tag("i", "class=title-bar", "") . WOOF_HTML::tag("span", null, $title_label));
        $grid .= WOOF_HTML::tag("th", "class=".(($row_style == "icon_title" || $row_style == "image_title") ? "disabled " : "")."icon excerpt", WOOF_HTML::tag("i", "class=content-bar", "") . WOOF_HTML::tag("span", null, $ex_label));
        $grid .= WOOF_HTML::tag("th", "class=".(($row_style == "icon_title" || $row_style == "icon_title_excerpt") ? "disabled " : "")."icon image", WOOF_HTML::tag("i", "class=image", "") . WOOF_HTML::tag("span", null, __("Image", MASTERPRESS_DOMAIN)));



      $grid .= WOOF_HTML::close("thead");

      $grid .= WOOF_HTML::open("tbody");
      
      $count = 1;
      
      
      foreach ($taxonomies as $taxonomy) {
        if (!$taxonomy->disabled && $taxonomy->show_ui) {
          
          $classes = array("taxonomy-".$taxonomy->name);
          
          if ($count == 1) {
            $classes[] = "first";
          }
          
          $attr = array("class" => implode(" ", $classes));
          
          if (!in_array($taxonomy->name, $taxonomies_selected)) {
            $attr["style"] = "display: none;";
          }

  
          $grid .= WOOF_HTML::open("tr", $attr);

          $count++;
            
            $span = WOOF_HTML::tag("span", array("class" => "mp-icon-taxonomy mp-icon-taxonomy-".$taxonomy->name ), $taxonomy->display_label());
            
            $grid .= WOOF_HTML::tag("td", "class=first taxonomy", $span);
            $grid .= WOOF_HTML::open("td", "class=title");
            
              $default = "name";
              $value = isset($options["result_row_prop"][$taxonomy->name]["title"]) ? $options["result_row_prop"][$taxonomy->name]["title"] : $default;
              
              if ($value == "") {
                $value = $default;
              }
              
              $input_attr = array(
                "type" => "text",
                "name" => "type_options[result_row_prop][".$taxonomy->name."][title]",
                "class" => "text",
                "value" => $value
              );

              $grid .= WOOF_HTML::open("div");

              $grid .= WOOF_HTML::tag("input", $input_attr);

              $grid .= WOOF_HTML::tag(
                "button", 
                array(
                  "type" => "button",
                  "class" => "ir",
                  "data-dialog" => "dialog-taxonomy-".$taxonomy->name,
                  "data-filter" => "text",
                  "title" => __("Select Field", MASTERPRESS_DOMAIN)
                ),
                "select"
              );

              $grid .= WOOF_HTML::close("div");
            
            $grid .= WOOF_HTML::close("td");
            $grid .= WOOF_HTML::open("td", "class=excerpt".(($row_style == "icon_title" || $row_style == "image_title") ? " disabled" : ""));

              $default = "description";
              $value = isset($options["result_row_prop"][$taxonomy->name]["excerpt"]) ? $options["result_row_prop"][$taxonomy->name]["excerpt"] : $default;
              
              if ($value == "") {
                $value = $default;
              }

              $input_attr = array(
                "type" => "text",
                "name" => "type_options[result_row_prop][".$taxonomy->name."][excerpt]",
                "class" => "text",
                "value" => $value
              );

              $grid .= WOOF_HTML::open("div");

              $grid .= WOOF_HTML::tag("input", $input_attr);

              $grid .= WOOF_HTML::tag(
                "button", 
                array(
                  "type" => "button",
                  "class" => "ir",
                  "data-dialog" => "dialog-taxonomy-".$taxonomy->name,
                  "data-filter" => "text",
                  "title" => __("Select Field", MASTERPRESS_DOMAIN)
                ),
                "select"
              );

              $grid .= WOOF_HTML::close("div");
                          
            $grid .= WOOF_HTML::close("td");
            $grid .= WOOF_HTML::open("td", "class=image".(($row_style == "icon_title" || $row_style == "icon_title_excerpt") ? " disabled" : ""));

              $default = "";
              $value = isset($options["result_row_prop"][$taxonomy->name]["image"]) ? $options["result_row_prop"][$taxonomy->name]["image"] : $default;
              
              if ($value == "") {
                $value = $default;
              }
              
              $input_attr = array(
                "type" => "text",
                "name" => "type_options[result_row_prop][".$taxonomy->name."][image]",
                "class" => "text",
                "value" => $value
              );

              $grid .= WOOF_HTML::open("div");

              $grid .= WOOF_HTML::tag("input", $input_attr);
            
              $grid .= WOOF_HTML::tag(
                "button", 
                array(
                  "type" => "button",
                  "class" => "ir",
                  "data-dialog" => "dialog-taxonomy-".$taxonomy->name,
                  "data-filter" => "image",
                  "title" => __("Select Field", MASTERPRESS_DOMAIN)
                ),
                "select"
              );

              $grid .= WOOF_HTML::close("div");
              
            $grid .= WOOF_HTML::close("td");

          $grid .= WOOF_HTML::close("tr");
          
        }
      }

      $grid .= WOOF_HTML::close("tbody");
    $grid .= WOOF_HTML::close("table");
  
    
    // build dialogs for selecting row properties in the grid
    
    $dialogs = "";
    
    foreach ($taxonomies as $taxonomy) {
      
      if (!$taxonomy->disabled && $taxonomy->show_ui) {
      
        $dialogs .= WOOF_HTML::open(
          "div", 
          array(
            "class" => "dialog dialog-fields",
            "id" => "dialog-taxonomy-".$taxonomy->name,
            "data-title" => __("Select a Field", MASTERPRESS_DOMAIN)
          )
        );
      
        $fs = $meow_provider->taxonomy_field_sets($taxonomy->name);

        $field_options = array();
        $field_options[""] = "";

        $field_options_attr = array("");

        $field_options[__("( Built-in Fields )", MASTERPRESS_DOMAIN)] = array(
          
          "options" => array(
            __("Name", MASTERPRESS_DOMAIN) => "name",
            __("Description", MASTERPRESS_DOMAIN) => "description"
          ),
          "options_attr" => array(
            array("data-icon" => "mp-icon mp-icon-field-type-text-box", "class" => "text"),
            array("data-icon" => "mp-icon mp-icon-field-type-text-box-multiline", "class" => "text")
          )

        );
          
        foreach ($fs as $set) {
        
          $fo = array();
          $fo_attr = array();
          
          foreach ($set->fields() as $field) {

            if ($type_class = MPFT::type_class($field->type)) {
              $image = call_user_func( array($type_class, "supports_image") ) ? " image" : "";
              $text = call_user_func( array($type_class, "supports_text") ) ? " text" : "";

              $fo[$field->display_label()] = $set->name.".".$field->name;
              $fo_attr[] = $field_options_attr[] = array("class" => $image.$text, "data-icon" => "mp-icon mp-icon-field-type-".$field->type);
            } 

            $field_options[$set->display_label()] = array("options" => $fo, "options_attr" => $fo_attr);

          }

        } 
                
        $dialogs .= WOOF_HTML::select(array("name" => "add-field-column-field-sets", "class" => "with-icons select2-source", "data-placeholder" => __("-- Select a Field --", MASTERPRESS_DOMAIN)), $field_options, "", $field_options_attr);
        $dialogs .= WOOF_HTML::close("div");
      
      }
      
    }
    


$html = <<<HTML

    {$dialogs}
    {$control_style}

    <div class="f f-taxonomies">
      <p class="label">{$taxonomies_label}</p>
      <div class="fw">

      <div id="{$p}taxonomies-wrap">
      {$taxonomies_checkboxes}
      </div>

      <div id="{$p}taxonomies-controls" class="controls">
        <button type="button" class="button button-small select-all">Select All</button>
        <button type="button" class="button button-small select-none">Select None</button>
      </div>
      <!-- /.controls -->

      <p class="note">{$taxonomies_note}</p>
      </div>
    </div>
    <!-- /.f -->
    
    {$placeholder}
    {$basic}
    {$maxwidth}
    
    
    
    <div class="divider">
    <h4><i class="menu-gray"></i>{$control_results_label}</h4>  
    {$grouping}
    {$results_input_length}
    {$results_row_style}
    
    <div id="{$p}results-row-item-prop-f" class="results-row-item-prop-f f">
    <p class="label">{$results_row_item_prop_label}</p> 
    
    <div class="fw">
      {$grid}
      <p class="note">{$results_row_item_prop_note}</p> 
    </div>
    
    </div>
    <!-- /.f -->
    
    </div>
    
    <div id="{$p}control-selections-wrap" class="divider">
    <h4><i class="buttons"></i>{$control_selections_label}</h4>  
    {$multi_layout}
    </div>



HTML;

    return $html;

  }
Esempio 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) );
    }
    
  }
Esempio n. 3
0
  public static function restrict_manage_posts() {

    // sets up filter dropdowns on manage post listings linked to custom taxonomies
    
    global $typenow, $wf;
    
    MPM::incl("taxonomy");
    MPM::incl("post-type");
    
    if ($post_type = MPM_PostType::find_by_name($typenow) ) {
    
      foreach ($post_type->taxonomies() as $taxonomy) {
    
        if ($taxonomy->show_manage_filter) {
      
          // get the taxonomy API object

          $tax_slug = $taxonomy->name;
          
          if (apply_filters("manage_posts_show_taxonomy_filter", array("post_type" => $typenow, "taxonomy" => $tax_slug)) !== FALSE) { 
            
            $tax = $wf->taxonomy($tax_slug);
      
            if ($tax) {
        
              $terms = $tax->top_level_terms();
            
              if ($terms->count()) {
                // output html for taxonomy dropdown filter
                echo '<select name="'.$tax_slug.'" id="'.$tax_slug.'" class="postform custom-taxonomy-filter { taxonomy: \''.esc_attr($taxonomy->labels["singular_name"]).'\' }">';
                echo '<option value="">'.sprintf( __( " All %s&nbsp;&nbsp;" ), $tax->labels->name).'</option>';
              
                $current_term = "";
              
                if (isset($_GET[$tax_slug])) {
                  $current_term = $_GET[$tax_slug];
                }
              
                self::restrict_manage_posts_select_options( $current_term, $terms );
            
                echo '</select>';
              }
        
            }
          
          }
          
        }
      }
    
    }
    
  }
Esempio n. 4
0
  public static function upload_field() {
    global $wf;
    
    $user = $wf->the_user();
    
    if (is_user_logged_in()) {
      // work out the directory - for now, we'll store files in a directory that's named after the post type, but we'll make this more
      // flexible later on
      
      // check if this user has permission to uplaod
      
      if (!$user->can("upload_files")) {
        self::ajax_error(__("You do not have permission to upload files", MASTERPRESS_DOMAIN));
      }
      
      MPM::incl("field");

      $model_id = $_GET["model_id"];
      $field = MPM_Field::find_by_id($model_id);
      
      list($dir, $sub) = self::upload_dir($field);
    
      $type_options = $field->type_options;
      
      $options = array(
        "sub_dir" => $sub,
        "dir" => $dir,
        "allowed_extensions" => $type_options["allowed_types"],
        "filename_case" => $type_options["filename_case"],
        "filename_sanitize" => $type_options["filename_sanitize"]
      );
      
      if ($type_options["allowed_maxsize"] != "") {
        $options["size_limit"] = $type_options["allowed_maxsize"]."M";
      }
      
      $uploader = new qqFileUploader($options);
      
      $result = $uploader->handleUpload();

      // to pass data through iframe you will need to encode all html tags
      echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
    } else {
      self::ajax_error(__("You do not have permission to upload", MASTERPRESS_DOMAIN));
    }
    
  }
Esempio n. 5
0
  public static function save_meta($object_id, $object_type) {
    
    global $wpdb, $meow_provider;
    global $wf;
    
    do_action("mp_pre_save_meta", $object_id, $object_type);
    
    if (apply_filters("mp_do_save_meta", $do = true, $object_id, $object_type)) { 
    
      MPM::incl("field");

      $object_type_type = "";
    
      $current_data = array();

      if ($object_type == "post") {

        // check the edit post meta cap for this type
      
        $cap = "edit_post";
      
        $post = $wf->post($object_id);

      
        if ($post->exists()) {
          $type = $post->type();
      
          $cap = $type->cap("edit_post", "edit_post");
      
          // update the template meta
        
          if ($type->supports("mp-page-attributes")) {
            if (isset($_POST["page_template"])) {
              $template = $_POST["page_template"];
            
              if ($template == "") {
                delete_post_meta($object_id, "_wp_page_template");
              } else {
                update_post_meta($object_id, "_wp_page_template", $template);
              }
            }
          
          }
        
        }
      
        if ( !current_user_can( $cap, $object_id ) ) {
          return $object_id;
        }

      
      } else if ($object_type == "term") {
      
        // check the edit terms cap for the taxonomy
        $cap = "manage_categories";

        $taxonomy_name = self::infer_taxonomy_name();
        $tax = $wf->taxonomy($taxonomy_name);
      
        $object_type_type = $taxonomy_name;
      
        if ($tax->exists()) {
          $cap = $tax->cap("edit_terms", "manage_categories");
        }
    
        if ( !current_user_can( $cap ) ) {
          return $object_id;
        }
      } else if ($object_type == "user") {
        if ( !current_user_can( 'edit_users' ) ) {
          return $object_id;
        }
      } else if ($object_type == "site") {
        if ( !current_user_can( 'edit_posts' ) ) {
          return $object_id;
        }
      }
  
      $meta = self::post_val('mp_meta', array());
      $meta_order = self::post_val('mp_meta_order', array());
      $meta_model = self::post_val('mp_meta_model', array());
      $meta_prop = self::post_val('mp_meta_prop', array());
      $meta_field_ids = self::post_val('mp_meta_field_ids', array());

      $meta_dirty = self::post_val('mp_meta_dirty', array());
      $meta_versions = self::post_val('mp_meta_versions', array());

      $field_models = array();
    
      if (is_array($meta_field_ids)) {
        $meta_field_ids = array_unique($meta_field_ids);
      
        $results = MPM_Field::find_by_id_in($meta_field_ids);
      
        foreach ($results as $field) {
          $field_models[$field->id] = $field;
        }
      
      }
    
      $wpdb->show_errors();
    
      if (isset($_POST["mp_meta_model"])) {
      
        if ($object_type == "post") {
          if ( $the_post = wp_is_post_revision( $object_id ) ) {
            $object_id = $the_post;
          }
        } 

        try {
          $meow_provider->create_version($object_id, $object_type, $object_type_type, "initial", $meta_versions);
        } catch( Exception $e) {
          // silently catch, we REALLY don't want this to prevent a data save if something goes wrong!
        }
      
        /* Delete the old post meta */

        foreach ( $meta_model as $set_name => $fields ) {
        
          foreach ($fields as $field_name => $model_id) {
            $field = $field_models[$model_id];
          
            $meta_name = $set_name.".".$field_name;

            self::delete_object_meta($object_type, $object_id, $meta_name);
        
            // now go through the properties too

            $dont_care = MPFT::type_class($field->type);
          
            foreach (MPFT::type_properties($field->type) as $prop) {
              self::delete_object_meta($object_type, $object_id, $meta_name.":".$prop);
            }
             
          
          }
        
        }

        $model_id_prop_stored = array();
      
        // Create the new values
        foreach( $meta as $set_name => $set_items ) {
        
          $set_index = 0;
        
          if (is_array($set_items)) {
        
            foreach ($set_items as $fields) {

              $set_index++;

          
              foreach ($fields as $field_name => $value) {
            
                // here the field type should prepare the value, if necessary
            
                // grab the type
            
                $model_id = $meta_model[$set_name][$field_name];
            
                $model = $field_models[$model_id];
            
                $val = MPU::db_encode($value);
            
                if ($model) {
              
                  if ($type_class = MPFT::type_class($model->type)) {
                    $val = MPU::db_encode(call_user_func_array( array($type_class, "value_for_save"), array($value, $model)));
                  }
            
                  // create the post meta
              
                  $meta_name = MPFT::meta_key($set_name, $field_name);
              
                  self::add_object_meta($object_type, $object_id, "{$meta_name}", $val);

                  // now store the properties
              
                  foreach (MPFT::type_properties($model->type) as $prop) {

                    if ($prop == "field_id" && !isset($model_id_prop_stored[$model_id])) {
                      $model_id_prop_stored[$model_id] = true;

                      self::add_object_meta($object_type, $object_id, "{$meta_name}:{$prop}", $model_id);
                  
                    } else {
                  
                      $prop_set_index = $meta_order[$set_name][$set_index];

                      if (isset($meta_prop[$set_name][(int) $prop_set_index][$field_name][$prop])) {
                        $prop_value = $meta_prop[$set_name][(int) $prop_set_index][$field_name][$prop];
                      }
                  
                      if (isset($prop_value)) {
                        self::add_object_meta($object_type, $object_id, "{$meta_name}:{$prop}", $prop_value);
                      }
                  
                    }

                  }
          
              
                }
            
              } // endforeach $fields
          
          
              // fill in blanks for any values that weren't submitted (this happens with checkboxes that are not checked)
          
              foreach ($meta_model[$set_name] as $field_name => $model_id) {
                if (!isset($fields[$field_name])) {
                  $meta_name = MPFT::meta_key($set_name, $field_name);
                  self::add_object_meta($object_type, $object_id, "{$meta_name}", "");
              
                  // now store the properties for blanks (if required)
              
                  foreach (MPFT::type_properties($field->type) as $prop) {

                    if ($prop == "field_id" && !isset($model_id_prop_stored[$model_id])) {
                      $model_id_prop_stored[$model_id] = true;
                      self::add_object_meta($object_type, $object_id, "{$meta_name}:{$prop}", $model_id);

                    } else {
                  
                      if (isset($meta_prop[$set_name][$set_index][$field_name][$prop])) {
                        $prop_value = $meta_prop[$set_name][$set_index][$field_name][$prop];
                        self::add_object_meta($object_type, $object_id, "{$meta_name}:{$prop}", $prop_value);
                      }
                  
                    }

                  }

              
                }

              }

          
            } 

    
          } // endif is_array(set_items)


        } // foreach $set_name => $set_items


        // create the current content version

        if (!self::$version_saved) {
          try {
            $meow_provider->create_version($object_id, $object_type, $object_type_type, $meta_dirty, $meta_versions);
          } catch( Exception $e) {
          
            // silently catch, we REALLY don't want this to prevent a data save if something goes wrong!
          }

          self::$version_saved = true;
        }
      
      } // isset $_POST["mp_meta_model"]
    
    }
  
    do_action("mp_after_save_meta", $object_id, $object_type);

    
  }
Esempio n. 6
0
  public static function options_form( $options ) {

    global $wf;
    
    $p = self::type_prefix(__CLASS__);

    $defaults = array();

    if (MPC::is_create()) {
      $defaults = array("maxwidth" => 580, "height" => 300, "control_style" => "drop_down_list");
    }

    $options = wp_parse_args( $options, $defaults );

    if (MPC::is_create()) {
      $options["post_types"] = array();
    }

    // setup variables to insert into the heredoc string
    // (this is required where we cannot call functions within heredoc strings)

    $taxonomies_label = __("Available Taxonomies:", MASTERPRESS_DOMAIN);

    $taxonomies_note = __("Select the taxonomies available for selection in the field control", MASTERPRESS_DOMAIN);

    $taxonomies_items = array();

    MPM::incl("taxonomy");

    $taxonomies = MPM_Taxonomy::find("orderby=disabled,name ASC");

    $ts = array();
    
    foreach ($taxonomies as $taxonomy) {

      if (MPC::is_create()) {
        $options["taxonomies"][] = $taxonomy->name;
      }
    
      if (!$taxonomy->disabled && $taxonomy->show_ui && $taxonomy->still_registered()) {
        $taxonomies_items[$taxonomy->display_label()] = $taxonomy->name;
        $ts[] = $taxonomy->name;
      }

    }

    
    if (!MPC::is_create()) {
      $ts = self::option_value($options, "taxonomies");
    }
    

    $id = $p."taxonomies-";
    
    $taxonomies_checkboxes = "";
    
    foreach ($taxonomies as $taxonomy) {


      if (!$taxonomy->disabled && $taxonomy->show_ui && $taxonomy->still_registered()) {
      
        $value = $taxonomy->name;
        $label = $taxonomy->display_label();
      
        $id_suffix = WOOF::sanitize($value);
      
        $attr = array( "id" => $id."_".$id_suffix, "class" => "checkbox", "type" => "checkbox", "name" => "type_options[taxonomies][]", "value" => $value );
      
        if (in_array($value, $ts)) {
          $attr["checked"] = "checked";
        }
      
        $taxonomies_checkboxes .= WOOF_HTML::open("div", "class=fwi");
        $taxonomies_checkboxes .= WOOF_HTML::tag("input", $attr );
        $taxonomies_checkboxes .= WOOF_HTML::tag("label", array( "for" => $id."_".$id_suffix, "class" => "checkbox mp-icon-taxonomy-".$value ), $label );
        $taxonomies_checkboxes .= WOOF_HTML::close("div");

      }

    }
    

    $basic = MPFT::options_select_basic( $p, $options );
    $multi_layout = MPFT::options_select_multi_layout( $p, $options );
    $control_style = MPFT::options_select_control_style( $p, $options );
    $maxwidth = MPFT::options_maxwidth( $p, $options );
    $height = MPFT::options_height( $p, $options );
    $placeholder = MPFT::options_placeholder($p, $options);

    $control_selections_label = __("Selection Display - <span>settings for the display of the selected taxonomies</span>", MASTERPRESS_DOMAIN); 


$html = <<<HTML


    {$control_style}

    <div class="f f-taxonomies">
      <p class="label">{$taxonomies_label}</p>
      <div class="fw">

      <div id="{$p}taxonomies-wrap">
      {$taxonomies_checkboxes}
      </div>

      <div id="{$p}taxonomies-controls" class="controls">
        <button type="button" class="button button-small select-all">Select All</button>
        <button type="button" class="button button-small select-none">Select None</button>
      </div>
      <!-- /.controls -->

      <p class="note">{$taxonomies_note}</p>
      </div>
    </div>
    <!-- /.f -->

    {$basic}
    {$placeholder}
    {$maxwidth}

    <div id="{$p}control-selections-wrap" class="divider">
    <h4><i class="buttons"></i>{$control_selections_label}</h4>  
    {$multi_layout}
    </div>

HTML;

    return $html;

  }