public static function options_form( $options ) {

    $defaults = array();

    if (MPC::is_create()) {
      $defaults = array("height" => 160);
    }

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

    $p = self::type_prefix(__CLASS__);

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

    $maxlength_label = __("Maximum Length:", MASTERPRESS_DOMAIN);
    $maxlength_note = __("(characters)", MASTERPRESS_DOMAIN);

    $status_label = __("show a count of remaining characters", MASTERPRESS_DOMAIN);

    $status = self::option_value($options, "status");
    $maxlength = self::option_value($options, "maxlength");

    $status_checked_attr = WOOF_HTML::checked_attr($status == "yes");


    $maxwidth = MPFT::options_maxwidth( $p, $options );
    $height = MPFT::options_height( $p, $options );
    $font = MPFT::options_font( $p, $options );

$html = <<<HTML

    <div class="f">
      <label for="{$p}maxlength">{$maxlength_label}</label>
      <div id="fw-{$p}maxlength" class="fw">
        <input id="{$p}maxlength" type="text" name="type_options[maxlength]" value="{$maxlength}" class="text" /><span class="note">{$maxlength_note}</span>

        <div id="{$p}status-wrap">
          <input id="{$p}status" type="checkbox" name="type_options[status]" {$status_checked_attr} value="yes" class="checkbox" />
          <label for="{$p}status" class="checkbox">{$status_label}</label>
        </div>

      </div>
    </div>
    <!-- /.f -->

    {$maxwidth}
    {$height}
    {$font}

HTML;

    return $html;

  }
示例#2
0
  public static function options_form( $options ) {

    global $wf;

    $defaults = array();

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

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

    $p = self::type_prefix(__CLASS__);

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

    $exclude_current = MPFT::options_exclude_current( $p, $options, __('Check to exclude the current site from this list', MASTERPRESS_DOMAIN) );

    $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 sites</span>", MASTERPRESS_DOMAIN); 


$html = <<<HTML

    {$control_style}
    {$basic}
    {$exclude_current}
    {$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;

  }
示例#3
0
  public static function options_form( $options ) {

    $p = self::type_prefix(__CLASS__);

    $defaults = array();

    if (MPC::is_create()) {
      $defaults = array("step" => 1, "min" => 0, "format" => "0", "maxwidth" => 100, $negative_red = "yes");
    }

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

    $negative_red_label = __("Show Negative in red?:", MASTERPRESS_DOMAIN);

    $min_label = __("Minimum Value:", MASTERPRESS_DOMAIN);
    $max_label = __("Maximum Value:", MASTERPRESS_DOMAIN);

    $default_label = __("Default Value:", MASTERPRESS_DOMAIN);

    $step_label = __("Step By:", MASTERPRESS_DOMAIN);
    $step_note = __("Enter a numeric step amount for the up / down buttons or arrow keys.", MASTERPRESS_DOMAIN);

    $format_label = __("Number Format:", MASTERPRESS_DOMAIN);
    $format_note = __("Enter a numeric format to use made up of zeros (0), hashes (#), commas (,) a decimal point, and other symbols.<br />0 represents a decimal that will always be present (generally only used on either side of a decimal point).<br /># is a decimal that is present if needed, and commas and other symbols are placed into the same position.<br />Example: $#,###,###,##0.00 is a currency amount with 2 decimal places always shown,<br />and a leading zero always in front of the decimal point.", MASTERPRESS_DOMAIN);

    $negative_red = self::option_value($options, "negative_red");

    $negative_red_checked_attr = WOOF_HTML::checked_attr($negative_red == "yes");

    $min = self::option_value($options, "min");
    $default = self::option_value($options, "default");
    $max = self::option_value($options, "max");
    $step = self::option_value($options, "step");
    $format = self::option_value($options, "format");

    $maxwidth = MPFT::options_maxwidth( $p, $options );

    $html = <<<HTML

    <div class="f">
      <label for="{$p}min">{$min_label}</label>
      <div id="fw-{$p}min" class="fw">
        <input id="{$p}min" name="type_options[min]" type="text" value="{$min}" class="text" />
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}max">{$max_label}</label>
      <div id="fw-{$p}max" class="fw">
        <input id="{$p}max" name="type_options[max]" type="text" value="{$max}" class="text" />
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}default">{$default_label}</label>
      <div id="fw-{$p}default" class="fw">
        <input id="{$p}default" name="type_options[default]" type="text" value="{$default}" class="text" />
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}step">{$step_label}</label>
      <div id="fw-{$p}step" class="fw">
        <input id="{$p}step" name="type_options[step]" type="text" value="{$step}" class="text" />
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}format">{$format_label}</label>
      <div id="fw-{$p}format" class="fw">
        <input id="{$p}format" name="type_options[format]" type="text" value="{$format}" class="text" />
        <p class="note">{$format_note}</p>
      </div>
    </div>
    <!-- /.f -->

    {$maxwidth}

    <div class="f">
      <label for="{$p}negative_red">{$negative_red_label}</label>
      <div id="fw-{$p}negative_red" class="fw">
        <input id="{$p}negative_red" name="type_options[negative_red]" type="checkbox" {$negative_red_checked_attr} value="yes" class="checkbox" />
      </div>
    </div>
    <!-- /.f -->



HTML;

    return $html;

  }
示例#4
0
  public static function options_form( $options ) {

    global $wf;

    $defaults = array();

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

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

    $p = self::type_prefix(__CLASS__);

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

    $user_roles_label = __("Available User Roles:", MASTERPRESS_DOMAIN);

    $user_roles_note = __("Specify the user roles available for selection in the field control", MASTERPRESS_DOMAIN);

    $user_roles_items = array();

    $user_roles = get_editable_roles();

    foreach ($wf->roles() as $role) {
      $user_roles_items[$role->name()] = $role->id();
    }

    $user_roles_checkboxes = WOOF_HTML::input_checkbox_group( "type_options[user_roles][]", $p."user-roles-", $user_roles_items, self::option_value($options, "user_roles"), WOOF_HTML::open("div", "class=fwi"), 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 user roles</span>", MASTERPRESS_DOMAIN); 


$html = <<<HTML

    {$control_style}

    <div class="f f-user-roles">
      <p class="label">{$user_roles_label}</p>
      <div class="fw">

      <div id="{$p}user-roles-wrap">
      {$user_roles_checkboxes}
      </div>

      <div id="{$p}user-roles-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">{$user_roles_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;

  }
示例#5
0
  public function submit() {
    
    global $wpdb;
    
    $action = MasterPress::$action;
    
    if ($action == "create" || $action == "edit") {

      $builtin = $_POST["_builtin"] == "true";
      $external = $_POST["_external"] == "true";
      
      if ($builtin) {

        $post_type = MPM_PostType::find_by_name($_POST["name"]);
        $post_type->supports = implode(",", $_POST["supports"]);
        $post_type->disabled = isset($_POST["disabled"]);
        $post_type->visibility = $this->get_visibility_val("sites");
        $post_type->columns = $_POST["columns"];
        $post_type->labels = $_POST["labels"];
        
        $post_type->menu_icon = self::handle_icon("menu_icon", "menu_icon_select");
        
        if ($_POST["name"] == "page" && $post_type->menu_icon == "") {
          $post_type->menu_icon = "menu-icon-pages.png"; // restore default icon
        }

        if ($_POST["name"] == "post" && $post_type->menu_icon == "") {
          $post_type->menu_icon = "menu-icon-posts.png"; // restore default icon
        }
        
        if ($action == "edit") {
          $post_type->update(MasterPress::$id);
        }
        

      } else if ($external) {

        $post_type = MPM_PostType::find_by_name($_POST["name"]);
        $post_type->columns = $_POST["columns"];
        $post_type->menu_icon = self::handle_icon("menu_icon", "menu_icon_select");
        
        if ($action == "edit") {
          $post_type->update(MasterPress::$id);
        }
        
      } else {


        $post_type = new MPM_PostType(true);
    
        // consume the post data
        $post_type->name = $_POST["name"];
        $post_type->plural_name = $_POST["plural_name"];
        $post_type->disabled = isset($_POST["disabled"]);
        $post_type->labels = $_POST["labels"];
        $post_type->description = $_POST["description"];
        $post_type->publicly_queryable = isset($_POST["publicly_queryable"]);
        $post_type->exclude_from_search = isset($_POST["exclude_from_search"]);
        $post_type->show_ui = isset($_POST["show_ui"]);
        $post_type->show_in_menu = isset($_POST["show_in_menu"]);
        $post_type->hierarchical = isset($_POST["hierarchical"]);
        $post_type->menu_position = $_POST["menu_position"];
        $post_type->menu_sub_position = $_POST["menu_sub_position"];
        
        $post_type->menu_icon = self::handle_icon("menu_icon", "menu_icon_select");
        
        $post_type->manage_sort_order = $_POST["manage_sort_order"];
        
        $cap_type = $_POST["capability_type"];
        
        if ($cap_type == "specific") {
          $post_type->capability_type = $_POST["name"];
        } else if ($cap_type == "custom" && trim($_POST["capability_type_custom_value"]) != "") {
          $post_type->capability_type = $_POST["capability_type_custom_value"];
        } else {
          $post_type->capability_type = $cap_type;
        }
      
        $post_type->capabilities = MPC::post_val("capabilities");
        
        $post_type->map_meta_cap = isset($_POST["map_meta_cap"]);
        $post_type->hierarchical = isset($_POST["hierarchical"]);
        $post_type->supports = MPC::post_implode_val("supports");
        $post_type->permalink_epmask = $_POST["permalink_epmask"];
        $post_type->has_archive = isset($_POST["has_archive"]);
        $post_type->visibility = $this->get_visibility_val("sites,post_types");

        $post_type->show_in_menu = isset($_POST["show_in_menu"]);

        $rewrite = array(
          "slug" => $_POST["rewrite"]["slug"],
          "with_front" => isset($_POST["rewrite"]["with_front"]),
          "feeds" => isset($_POST["rewrite"]["feeds"])
        );
        
        $post_type->rewrite = $rewrite;
      
        $post_type->query_var = $_POST["query_var"];
        $post_type->can_export = isset($_POST["can_export"]);
        $post_type->show_in_nav_menus = isset($_POST["show_in_nav_menus"]);
        $post_type->_builtin = false;
        $post_type->_external = $_POST["_external"] == "true";
        $post_type->columns = $_POST["columns"];

        if ($action == "create") {
          $post_type->insert();
        } else if ($action == "edit") {
          $post_type->update(MasterPress::$id);

          if ($post_type->is_valid()) {
            global $meow_provider;
            $meow_provider->migrate_post_type($post_type, $_POST["name_original"]);
          }

        }
        
        
      }
      
      if ($post_type->is_valid() && !$external) {

        // auto-generate a sprite icon
        MPU::create_icon_sprite($post_type->menu_icon, "", true);

        // attach any taxonomies and shared field sets
        
        $post_type->unlink_taxonomies();
        
        if (MPC::post_val("taxonomies") != "" && count(MPC::post_val("taxonomies"))) {
          $post_type->link_taxonomies( MPM_Taxonomy::find_by_name_in( $_POST["taxonomies"] ) );
        }
        
        // update the menu positions of other post types
        
        $omp = MPC::post_val("other_menu_position");
        $omsp = MPC::post_val("other_menu_sub_position");
        
        if (isset($omp) && is_array($omp)) {
          foreach ($omp as $name => $position) {
            $wpdb->update(MPM::table("post-types"), array( "menu_position" => $position, "menu_sub_position" => $omsp[$name] ), array( "name" => $name ), "%d", "%s" ); 
          }
        }

        MasterPress::flag_for_rewrite();

      } 
    
      return $post_type;
      
      
    } else if ($action == "delete") {

      
      $pt = MPM_PostType::find_by_id(MasterPress::$id);
      $pt->delete(
        array(
          "posts" => $_POST["posts"],
          "posts_reassign_type" => $_POST["posts_reassign_type"],
          "field_sets" => $_POST["field_sets"],
          "field_data" => $_POST["field_data"]
        )
      );
      
      MasterPress::flag_for_rewrite();

      return true;
      
    } else if ($action == "create-field-set" || $action == "edit-field-set") {

      $field_set = new MPM_FieldSet();
      // consume the post data
      
      $field_set->name = $_POST["name"];
      $field_set->singular_name = $_POST["singular_name"];
      $field_set->disabled = isset($_POST["disabled"]);
      $field_set->labels = $_POST["labels"];
      $field_set->allow_multiple = isset($_POST["allow_multiple"]);
      $field_set->visibility = $_POST["visibility"];
      $field_set->capabilities = self::handle_capabilities();
      $field_set->type = "p"; // p = shared
      $field_set->position = $_POST["position"];
      $field_set->icon = self::handle_icon("icon", "icon_select");
      $field_set->expanded = isset($_POST["expanded"]);
      $field_set->sidebar = isset($_POST["sidebar"]);
      $field_set->versions = $_POST["versions"];
      $field_set->visibility = $this->get_visibility_val("sites,templates,post_types");
      
      $post_type = MPM_PostType::find_by_id(MasterPress::$parent);
      
      // inform the validation of the post type
      $field_set->meta("post_type", $post_type);
      
      if (MPC::is_create()) {
        $field_set->insert();
      } else if (MPC::is_edit()) {
        $field_set->update(MasterPress::$id);
      }

      if ($field_set->is_valid()) {

        if (MPC::is_edit()) {
          global $meow_provider;
          $meow_provider->migrate_field_set_meta($field_set, $_POST["name_original"]);
        }

        // update other menu positions
        
				if (isset($_POST["other_position"])) {
	        $op = $_POST["other_position"];
        
	        if (isset($op) && is_array($op)) {
	          foreach ($op as $id => $position) {
	            $wpdb->update(MPM::table("field-sets"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); 
	          }
          
	        }
        }
        
      }        
      
      return $field_set;
      

    } else if ($action == "delete-field-set") {
      
      $fg = MPM_FieldSet::find_by_id(MasterPress::$id);
      
      if ($fg) {
        $field_data_action = $_POST["field_data"];
        if ($field_data_action == "delete") {
          $fg->delete_meta();
        }
      }
      
      $fg->delete();
      
      return true;
      
    } else if ($action == "delete-field") {
      
      $f = MPM_Field::find_by_id(MasterPress::$id);
      
      if ($f) {

        $field_data_action = $_POST["field_data"];
        
        if ($field_data_action == "delete") {
          $f->delete_meta();
        }

      }
      
      $f->delete();
      
      return true;
      
    } else if ($action == "create-field" || $action == "edit-field") {
      
      // FIELD OPERATIONS (NOT FIELD GROUPS!)
       
      $field = new MPM_Field();
      // consume the post data
      
      $field->field_set_id = $_POST["parent"];
      $field->name = $_POST["name"];
      $field->disabled = isset($_POST["disabled"]);
      $field->summary_options = $_POST["summary_options"];
      $field->required = isset($_POST["required"]);
      $field->labels = $_POST["labels"];
      $field->type = $_POST["type"]; 
      $field->icon = self::handle_icon("icon", "icon_select");
      
      if (isset($_POST["type_options"])) {
        $field->type_options = $_POST["type_options"];
      }
    
      $field->position = $_POST["position"];
      $field->visibility = $this->get_visibility_val("sites,templates,post_types");
      $field->capabilities = self::handle_capabilities();

      $fg = MPM_FieldSet::find_by_id($_POST["parent"]);
        
        
      if (MPC::is_create()) {
        $field->insert();
      } else if (MPC::is_edit()) {
        $field->update(MasterPress::$id);
      }

      if ($field->is_valid()) {

        // update other menu positions

        if (MPC::is_edit()) {
          global $meow_provider;
          $meow_provider->migrate_field_meta($field, $_POST["name_original"]);
        }
        
        if (isset($_POST["other_position"])) {
          $op = $_POST["other_position"];
        
          if (isset($op) && is_array($op)) {
            foreach ($op as $id => $position) {
              $wpdb->update(MPM::table("fields"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); 
            }
          
          }
        }
        
        
      }     
      
      
      
      return $field;
      
      
    } 
    
    return false;
  }
示例#6
0
  public static function options_form( $options ) {

    $defaults = array();

    if (MPC::is_create()) {
      $defaults = array("minheight" => 100, "theme" => "sunburst", "mode" => "htmlmixed", "modeselect" => "yes");
    }

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

    $maxheight = self::option_value($options, "maxheight");
    $mode = self::option_value($options, "mode", "gfm");
    $theme = self::option_value($options, "theme");
    $minheight = self::option_value($options, "minheight");

    $p = self::type_prefix(__CLASS__);

    $minheight_label = __("Minimum Height:", MASTERPRESS_DOMAIN);
    $minheight_note = __("(pixels)", MASTERPRESS_DOMAIN);

    $maxheight_label = __("Maximum Height:", MASTERPRESS_DOMAIN);
    $maxheight_note = __("(pixels)", MASTERPRESS_DOMAIN);


    $maxheight_grow_note = __("The editor will automatically grow to accommodate its content up to this maximum value.", MASTERPRESS_DOMAIN);

    $hiddenmode = $mode;
    
    $modeselect_label = __("Show mode selector (allows mode to be changed when entering content)", MASTERPRESS_DOMAIN);
    $modeselect_checked_attr = WOOF_HTML::checked_attr(self::option_value($options, "modeselect") == "yes");

    $mode_label = __("Syntax Mode:", MASTERPRESS_DOMAIN);
    $mode_select = WOOF_HTML::select(
      array("id" => $p."mode", "name" => "type_options[mode]"), 
      self::modes(),
      $mode
    );

    $theme_label = __("Theme:", MASTERPRESS_DOMAIN);
    $theme_select = WOOF_HTML::select(
      array("id" => $p."theme", "name" => "type_options[theme]"), 
      array(
        "Default" => "default",
        "Cobalt" => "cobalt",
        "Eclipse" => "eclipse",
        "Elegant" => "elegant",
        "Lesser Dark" => "lesser-dark",
        "Monokai" => "monokai",
        "Neat" => "neat",
        "Night" => "night",
        "Ruby Blue" => "rubyblue",
        "Sunburst" => "sunburst",
        "XQuery Dark" => "xq-dark"
      ),
      $theme
    );

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

$html = <<<HTML

    <div class="f">
      <label for="{$p}minheight">{$minheight_label}</label>
      <div id="fw-{$p}minheight" class="fw">
        <input id="{$p}minheight" type="text" name="type_options[minheight]" value="{$minheight}" class="text" /><span class="note">{$minheight_note}</span>
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}maxheight">{$maxheight_label}</label>
      <div id="fw-{$p}maxheight" class="fw">
        <input id="{$p}maxheight" type="text" name="type_options[maxheight]" value="{$maxheight}" class="text" /><span class="note">{$maxheight_note}</span>
        <p class="note">{$maxheight_grow_note}</p>
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}mode">{$mode_label}</label>
      <div id="fw-{$p}mode" class="fw">
        {$mode_select}
        <input type="hidden" name="hiddenmode" id="{$p}hiddenmode" class="hiddenmode" value="{$hiddenmode}" />

        <div id="{$p}modeselect-wrap">
          <input id="{$p}modeselect" type="checkbox" name="type_options[modeselect]" {$modeselect_checked_attr} value="yes" class="checkbox" />
          <label for="{$p}modeselect" class="checkbox">{$modeselect_label}</label>
        </div>

      </div>



    </div>
    <!-- /.f -->

    <div id="{$p}theme-f" class="f">
      <label for="{$p}theme">{$theme_label}</label>
      <div id="fw-{$p}theme" class="fw">
        {$theme_select}
      </div>
    </div>
    <!-- /.f -->



HTML;

    return $html;

  }
示例#7
0
  public function submit() {
    
    global $wpdb;
    
    $action = MasterPress::$action;
      
    if ($action == "edit") {
      
      $template = new MPM_Template();
      
      if ($_POST["supports_type"] == "inherit") {
        $template->supports = "*";
      } else {
        $template->supports = implode(",", $_POST["supports"]);
      }

      $template->visibility = $this->get_visibility_val("post_types");
      
      $template->update(MasterPress::$id);
      
      return $template;
      
    } else if ($action == "create-field-set" || $action == "edit-field-set") {
      
      $field_set = new MPM_TemplateFieldSet();
      // consume the post data
      
      $field_set->name = $_POST["name"];
      $field_set->singular_name = $_POST["singular_name"];
      $field_set->disabled = isset($_POST["disabled"]);
      $field_set->labels = $_POST["labels"];
      $field_set->capabilities = self::handle_capabilities();
      $field_set->visibility = $_POST["visibility"];
      $field_set->allow_multiple = isset($_POST["allow_multiple"]);
      $field_set->type = "t"; // t = template
      $field_set->icon = self::handle_icon("icon", "icon_select");
      $field_set->position = $_POST["position"];
      $field_set->expanded = isset($_POST["expanded"]);
      $field_set->sidebar = isset($_POST["sidebar"]);
      $field_set->versions = $_POST["versions"];
      $field_set->visibility = $this->get_visibility_val();
      
      if (MPC::is_create()) {
        $field_set->insert();
      } else if (MPC::is_edit()) {
        $field_set->update(MasterPress::$id);
      }

      if ($field_set->is_valid()) {

        if (MPC::is_edit()) {
          global $meow_provider;
          $meow_provider->migrate_field_set_meta($field_set, $_POST["name_original"]);
        }

        // we don't attach post types to these. they are implicitly linked to the built-in "page" post type
        
        // update other menu positions
        
        $op = $_POST["other_position"];
        
        if (isset($op) && is_array($op)) {
          foreach ($op as $id => $position) {
            $wpdb->update(MPM::table("field-sets"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); 
          }
          
        }
        
        
      }        
      
      return $field_set;
      
    } else if ($action == "delete-field-set") {
      
      $fg = MPM_FieldSet::find_by_id(MasterPress::$id);

      if ($fg) {
        $field_data_action = $_POST["field_data"];
        if ($field_data_action == "delete") {
          $fg->delete_meta();
        }
      }

      $fg->delete();
      
      return true;

    } else if ($action == "delete-field") {

      $f = MPM_Field::find_by_id(MasterPress::$id);

      if ($f) {

        $field_data_action = $_POST["field_data"];
        
        if ($field_data_action == "delete") {
          $f->delete_meta();
        }

      }
      
      $f->delete();
      
      return true;
      
    } else if ($action == "create-field" || $action == "edit-field") {
      
      // FIELD OPERATIONS (NOT FIELD GROUPS!)
       
      $field = new MPM_Field();
      // consume the post data
      
      $field->field_set_id = $_POST["parent"];
      $field->name = $_POST["name"];
      $field->disabled = isset($_POST["disabled"]);
      $field->required = isset($_POST["required"]);
      $field->summary_options = $_POST["summary_options"];
      $field->labels = $_POST["labels"];
      $field->icon = self::handle_icon("icon", "icon_select");
      $field->type = $_POST["type"]; 
      $field->type_options = $_POST["type_options"];
      $field->position = $_POST["position"];
      $field->visibility = $this->get_visibility_val();
      $field->capabilities = self::handle_capabilities();

      
      if (MPC::is_create()) {
        $field->insert();
      } else if (MPC::is_edit()) {
        $field->update(MasterPress::$id);
      }

      if ($field->is_valid()) {
        
        if (MPC::is_edit()) {
          global $meow_provider;
          $meow_provider->migrate_field_meta($field, $_POST["name_original"]);
        }

        // update other menu positions
        
        $op = $_POST["other_position"];
        
        if (isset($op) && is_array($op)) {
          foreach ($op as $id => $position) {
            $wpdb->update(MPM::table("fields"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); 
          }
          
        }

        
      }    
      
      
      
      return $field;

    } 
    
    
    return false;
  }
示例#8
0
  public static function options_form( $options ) {

    $defaults = array();

    if (MPC::is_create()) {
      $defaults = array("default_tab" => "visual", "height" => 250, "html_editor" => "cm", "cm_theme" => "sunburst");
    }

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

    $p = self::type_prefix(__CLASS__);

    $height = self::option_value($options, "height");
    $mce_blockformats = self::option_value($options, "mce_blockformats");
    $mce_styles = self::option_value($options, "mce_styles");
    $default_tab = self::option_value($options, "default_tab");
    $cm_theme = self::option_value($options, "cm_theme");

    $height_label = __("Editor Height:", MASTERPRESS_DOMAIN);
    $height_note = __("(pixels)", MASTERPRESS_DOMAIN);

    $html_editor_label = __("HTML Editor:", MASTERPRESS_DOMAIN);
    $html_editor_note = __('<a href="http://codemirror.net" target="_blank">CodeMirror 2</a> is a wonderful JavaScript text editor that support live syntax-coloring, among other features.', MASTERPRESS_DOMAIN);
    $html_editor_select = WOOF_HTML::select(
      array("id" => $p."html-editor", "name" => "type_options[html_editor]"), 
      array(
        "CodeMirror 2" => "cm", 
        "Standard Textarea" => "textarea" 
      ),
      self::option_value($options, "html_editor")
      
    );

    $cm_theme_label = __("CodeMirror Theme:", MASTERPRESS_DOMAIN);
    $cm_theme_select = WOOF_HTML::select(
      array("id" => $p."cm-theme", "name" => "type_options[cm_theme]"), 
      array(
        "Default" => "default",
        "Cobalt" => "cobalt",
        "Elegant" => "elegant",
        "Neat" => "neat",
        "Night" => "night",
        "Sunburst" => "sunburst"
      ),
      $cm_theme
    );

    $mce_blockformats_label = __("Block Formats:", MASTERPRESS_DOMAIN);
    $mce_blockformats_note = __('Specify the block-level tags which appear in the <em>Format</em> dropdown list in TinyMCE.<br />Leave this value empty to use the same formats as the WordPress content editor. <a target="_blank" href="http://www.tinymce.com/wiki.php/Configuration:theme_advanced_blockformats">More Info</a>', MASTERPRESS_DOMAIN);

      
    
    $mce_styles_label = __("Styles:", MASTERPRESS_DOMAIN);
    $mce_styles_note = __('Specify the style names and the underlying CSS classes for these styles, in the form <span class="tt">label = css_class</span> separated by semi-colons (;). Leave this value empty to use the same formats as the WordPress content editor. <a target="_blank" href="http://www.tinymce.com/wiki.php/Configuration:theme_advanced_styles">More Info</a>', MASTERPRESS_DOMAIN);

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

    $default_tab_label = __("Default Tab:", MASTERPRESS_DOMAIN);

    $default_tab_select = WOOF_HTML::input_radio_group(
      "type_options[default_tab]", $p."default-tab-", 
      array( __("Visual <span>( TinyMCE )</span>", MASTERPRESS_DOMAIN) => "visual", __("HTML", MASTERPRESS_DOMAIN) => "html" ),
      $default_tab,
      WOOF_HTML::open("div", "class=fwi"), WOOF_HTML::close("div")
    );

$html = <<<HTML

    <div class="f">
      <label for="{$p}default_tab">{$default_tab_label}</label>
      <div id="fw-{$p}default_tab" class="fw">
        {$default_tab_select}
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}height">{$height_label}</label>
      <div id="fw-{$p}height" class="fw">
        <input id="{$p}height" type="text" name="type_options[height]" value="{$height}" class="text" />
        <span class="note">{$height_note}</span>
      </div>
    </div>
    
    
    <div class="f">
      <label for="{$p}html_editor">{$html_editor_label}</label>
      <div id="fw-{$p}html_editor" class="fw">
        {$html_editor_select}
        <p class="note">{$html_editor_note}</p>
      </div>
    </div>
    <!-- /.f -->

    <div id="{$p}cm-theme-f" class="f">
      <label for="{$p}cm_theme">{$cm_theme_label}</label>
      <div id="fw-{$p}cm_theme" class="fw">
        {$cm_theme_select}
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}mce_blockformats">{$mce_blockformats_label}</label>
      <div id="fw-{$p}mce_blockformats" class="fw">
        <input id="{$p}mce_blockformats" type="text" name="type_options[mce_blockformats]" value="{$mce_blockformats}" class="text" />
        <p class="note">{$mce_blockformats_note}</p>
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}mce_styles">{$mce_styles_label}</label>
      <div id="fw-{$p}mce_styles" class="fw">
        <textarea id="{$p}mce_styles" name="type_options[mce_styles]" class="mono">{$mce_styles}</textarea>
        <p class="note">{$mce_styles_note}</p>
      </div>
    </div>
    <!-- /.f -->

HTML;

    return $html;

  }
示例#9
0
  public static function options_form( $options ) {

    $defaults = array();

    if (MPC::is_create()) {
      $defaults = array(
        "prompting_label" => __("Please select an option:", MASTERPRESS_DOMAIN), 
        "maxwidth" => "", 
      ); 
    }

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

    $maxwidth = self::option_value($options, "maxwidth");
    $prompting_label = self::option_value($options, "prompting_label");
    $default_value = self::option_value($options, "default_value");
    $values = self::option_value($options, "values");
    
    $p = self::type_prefix(__CLASS__);

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

    $values_label = __("Choices:", MASTERPRESS_DOMAIN);
    $values_note = __('Specify the labels for each choice on separate lines. To use a different underlying <span class="tt">value</span> for any of the choices,<br /> use the form <strong><span class="tt">label = value</span></strong>. To create a group of choices, prefix the line you wish to use as a group label with <span class="tt">--</span> (group labels are not selectable)', MASTERPRESS_DOMAIN);

    $maxwidth_label = __("Maximum Width:", MASTERPRESS_DOMAIN);
    $maxwidth_note = __("(pixels)", MASTERPRESS_DOMAIN);

    $prompting_label_label = __("Empty Prompting Label:", MASTERPRESS_DOMAIN);
    $prompting_label_note = __("Enter a prompting label to use for an empty value, displayed above the <em>Choices</em>.<br />Clear this value if you don't wish to allow an empty value.", MASTERPRESS_DOMAIN);

    $default_value_label = __("Default State:", MASTERPRESS_DOMAIN);
    $default_value_note = __("Use the preview of your control above to setup the default state", MASTERPRESS_DOMAIN);


    $default_value_select = WOOF_HTML::select( 
      array("id" => $p."default-value", "name" => "type_options[default_value]"),
      WOOF_HTML::option_values($values, $prompting_label, true),
      $default_value
    );

    $html = <<<HTML

    <div class="f">
      <label for="{$p}maxwidth">{$maxwidth_label}</label>
      <div id="fw-{$p}maxwidth" class="fw">
        <input id="{$p}maxwidth" name="type_options[maxwidth]" type="text" maxlength="4" value="{$maxwidth}" class="text" /><span class="note">{$maxwidth_note}</span>
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}values">{$values_label}</label>
      <div id="fw-{$p}values" class="fw">
        <textarea id="{$p}values" class="mono" name="type_options[values]">{$values}</textarea>
        <p class="note">{$values_note}</p>
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}prompting-label">{$prompting_label_label}</label>
      <div id="fw-{$p}prompting-label" class="fw">
        <input id="{$p}prompting-label" name="type_options[prompting_label]" type="text" value="{$prompting_label}" class="text" />
        <p class="note">{$prompting_label_note}</p>
      </div>
    </div>
    <!-- /.f -->

    <div id="{$p}default-value-f" class="f">
      <label for="{$p}default-value">{$default_value_label}</label>
      <div id="fw-{$p}default-value" class="fw">
        <div class="preview">
          {$default_value_select}
        </div>

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

HTML;

    return $html;

  }  
示例#10
0
  public function form() {
    
    global $wf;
    
    $model = MasterPress::$model;
    
    $info = MasterPress::$view;
    
    $parent = $info->parent;
    
    $post_type = null;
    
    $post_type = $info->post_type;
  
    $prefix = "";
    $default_key = "";
    $keys = array();
    
    ?>
    
    <?php if (is_object($parent)) : ?>
    <div class="title-info-panel">
      <div class="title-info-panel-lt">
        <?php if ($parent->type == 's') : ?>
        <h3><i class="metabox-share"></i><span class="label"><?php _e("Shared Field Set", MASTERPRESS_DOMAIN) ?>:</span><span class="value"> <?php echo $parent->display_label() ?></span></h3> 
        <?php elseif ($parent->type == 'w') : ?>
        <h3><i class="metabox-sitemap-large"></i><span class="label"><?php _e("Site Field Set", MASTERPRESS_DOMAIN) ?>:</span><span class="value"> <?php echo $parent->display_label() ?></span></h3> 
        <?php elseif ($parent->type == "p") : ?>
          
        <?php

        $prefix = $post_type->name."_"; 
        $keys = array("edit_".$post_type->capability_type."s");

        ?>
        
        <h3><i class="mp-icon mp-icon-post-type mp-icon-post-type-<?php echo $post_type->name ?>"></i><span class="label"><?php _e("Post Type", MASTERPRESS_DOMAIN) ?>:</span><span class="value"> <?php echo $post_type->display_label() ?></span></h3> 
        <h3><i class="divide"></i><i class="metabox"></i><span class="label"><?php _e("Field Set", MASTERPRESS_DOMAIN) ?>:</span><span class="value"> <?php echo $parent->display_label() ?></span></h3> 
        
        <?php elseif ($parent->type == 't') : ?>
        <?php
        
        $file = $parent->visibility["templates"];
        $page_templates = array_flip(get_page_templates());
        $template_name = $page_templates[$file];
        
        ?>
        <input id="templates" name="templates" type="hidden" value="<?php echo $file ?>" />
        
        <h3><i class="template"></i><span class="label"><?php _e("Template:", MASTERPRESS_DOMAIN) ?></span><span class="value"> <?php echo $template_name ?></span></h3> 
        <h3><i class="divide"></i><i class="metabox"></i><span class="label"><?php _e("Field Set", MASTERPRESS_DOMAIN) ?>:</span><span class="value"> <?php echo $parent->display_label() ?></span></h3> 
        
        <?php elseif ($parent->type == 'r') : ?>
        <?php
        
        $role_name = $parent->visibility["roles"];
        $prefix = $role_name."_";
        
        ?>
        <input id="templates" name="templates" type="hidden" value="<?php echo $role_name ?>" />
        <h3><i class="user-role"></i><span class="label"><?php _e("User Role:", MASTERPRESS_DOMAIN) ?></span><span class="value"> <?php echo $role_name ?></span></h3> 
        <h3><i class="divide"></i><i class="metabox"></i><span class="label"><?php _e("Field Set", MASTERPRESS_DOMAIN) ?>:</span><span class="value"> <?php echo $parent->display_label() ?></span></h3> 
        
        
        <?php elseif ($parent->type == 'x') : ?>
        <?php
        
        $taxonomy_name = $parent->visibility["taxonomies"];
        $prefix = $taxonomy_name."_";
        $tax = MPM_Taxonomy::find_by_name($taxonomy_name);

        $keys = array(
          $tax->capabilities["manage_terms"],
          $tax->capabilities["edit_terms"],
          $tax->capabilities["assign_terms"]
        );
        
        ?>
        <input id="taxonomies" name="taxonomies" type="hidden" value="<?php echo $taxonomy_name ?>" />
        <h3><i class="mp-icon mp-icon-taxonomy-<?php echo $taxonomy_name ?>"></i><span class="label"><?php _e("Taxonomy:", MASTERPRESS_DOMAIN) ?></span><span class="value"> <?php echo $tax->display_label() ?></span></h3> 
        <h3><i class="divide"></i><i class="metabox"></i><span class="label"><?php _e("Field Set", MASTERPRESS_DOMAIN) ?>:</span><span class="value"> <?php echo $parent->display_label() ?></span></h3> 
        
        <?php endif; ?>
      </div>
    </div>
    <?php endif; ?>

    <?php MPV::messages(); ?>

    <div class="mpv-fields-form">
      
    <div class="f">
      <label for="name" class="icon"><i class="script-php"></i><?php _e("Name", MASTERPRESS_DOMAIN)?>:</label>
      <div class="fw">
        <input id="name_original" name="name_original" type="hidden" class="text mono key" maxlength="20" value="<?php echo $model->name ?>" />
        <input id="name_last" name="name_last" type="hidden" class="text mono key" maxlength="20" value="<?php echo $model->name ?>" />

        <input id="name" name="name" type="text" class="text mono key" maxlength="255" value="<?php echo $model->name ?>" /><em class="required">(required)</em>
        <p>
          <?php _e("This is a unique identifier for the field in the MasterPress API. Since it can be used as a PHP variable name, it is restricted to being a lowercase string with words separated by underscores.", MASTERPRESS_DOMAIN); ?>
        </p>
      </div>

    </div>
    <!-- /.f -->

    
    
    <div id="f-type" class="f clearfix">
      <label for="type" class="icon"><i class="types"></i><?php _e("Field Type", MASTERPRESS_DOMAIN)?>:</label>
      <div class="fw">
        
        
        <select id="type" name="type" class="with-icons select2-source" data-icon="mp-icon mp-icon-field-type-<?php echo $model->type ?>">
        <?php foreach (MPFT::types_by_category() as $category => $types) : ?>
        <?php if (count($types)) : ?>

        <optgroup label="<?php echo $category ?>">

        <?php foreach ($types as $type) : ?>
          <?php
            $type_class = MPFT::type_class($type);
          ?>
          <option data-icon="mp-icon mp-icon-field-type-<?php echo $type ?>" <?php echo WOOF_HTML::selected_attr($type == $model->type) ?> data-description="<?php echo addslashes(call_user_func( array($type_class, "__description") ) ) ?>" value="<?php echo $type ?>"><?php echo call_user_func( array($type_class, "__s") ) ?></option>  
        <?php endforeach; ?>
        
        </optgroup>
        
        <?php endif; ?>
        <?php endforeach; ?>
        </select>
        
        
        <p id="field-type-description"></p>
        
      </div>
    </div>
    <!-- /.f -->


    <div class="f">
      <label for="required" class="icon"><i class="warning-octagon"></i><?php _e("Required", MASTERPRESS_DOMAIN) ?>?</label>
      <div class="fw">
        <input id="required" name="required" type="checkbox" value="true" <?php echo WOOF_HTML::checked_attr( $model->required ) ?> class="checkbox" />
        <p class="checkbox-alt-label { for_el: '#required' }">
          <?php _e("A field value must be specified by the user, or the content editing form will not submit.", MASTERPRESS_DOMAIN); ?>
        </p>
      </div>
    </div>
    <!-- /.f -->
    
    <div id="f-disabled" class="f">
      <label for="disabled" class="icon"><i class="slash"></i><?php _e("Disabled", MASTERPRESS_DOMAIN) ?>?</label>
      <div class="fw">
        <input id="disabled" name="disabled" type="checkbox" value="true" <?php echo WOOF_HTML::checked_attr( $model->disabled ) ?> class="checkbox" />
        <p class="checkbox-alt-label { for_el: '#disabled' }">
          <?php _e("disabling a field will hide it from all content editing screens in WordPress, which may be <strong>preferable to deleting it</strong> completely.", MASTERPRESS_DOMAIN); ?>
        </p>
      </div>
    </div>
    <!-- /.f -->  
    
    <?php
      
      $options_form = "";
      
      $type_options = $model->type_options;
      
      if (isset($_POST["type_options"])) {
        $type_options = $_POST["type_options"];
      }
              
      if ($type_class = MPFT::type_class($model->type)) { 
        $options_form = call_user_func_array( array($type_class, "options_form"), array(MPM::array_stripslashes($type_options)) );
      }
      
    ?>
    
    <div class="fs fs-field-type-options" <?php echo $options_form == "" ? ' style="display:none;"' : '' ?>>
    
      <div class="fst">
      <div class="fstb">
        <h3><i class="switch"></i><strong><?php _e("Field Type Options", MASTERPRESS_DOMAIN) ?></strong> - <?php _e("defines the user-interface for this field", MASTERPRESS_DOMAIN) ?></h3>
      </div>
      </div>
    
        
      <div class="fsc">
      <div class="fscb">
      
        <div id="field-type-loading" class="fs-loading">Please wait&hellip;</div>
        
        <div id="field-type-options-content">
          <?php if ($type_class = MPFT::type_class($model->type)): ?>
            
          <div id="mpft-<?php echo $model->type ?>-options" class="mpft-options">
          <?php echo $options_form ?>
          </div>
          
          <?php endif; ?>
          
        </div>
        <!-- /#field-type-options-content -->
      
      </div>
      </div>

    </div>
    <!-- /.fs -->
    
        

    <div class="fs fs-labels">
    
      <div class="fst">
      <div class="fstb">
        <h3><i class="label-string"></i><strong><?php _e("Labels", MASTERPRESS_DOMAIN) ?></strong> - <?php _e("displayed throughout the WordPress administration UI", MASTERPRESS_DOMAIN) ?></h3>
      </div>
      </div>
    
        
      <div class="fsc">
      <div class="fscb">
      
        <div class="f">
          <label for="label_name"><?php _e("Field Label", MASTERPRESS_DOMAIN) ?>:</label>
          <div class="fw">
            <input id="label_name" name="labels[name]" value="<?php echo stripslashes($model->labels["name"]) ?>" type="text" class="text { tmpl: '{{name}}' }" />
            <em class="recommended">(recommended)</em>
          </div>
        </div>
        <!-- /.f -->

        <div class="f">
          <label for="label_description"><?php _e("Description", MASTERPRESS_DOMAIN)?>:</label>
          <div class="fw">
            <input id="label_description" name="labels[description]" type="text" maxlength="50" value="<?php echo stripslashes($model->label("description")) ?>" class="text" />
            <p>
              <?php _e("Appears adjacent to the label in brackets to provide a little extra information about the field.<br />For more extensive information, use <em>Tooltip Help</em>.", MASTERPRESS_DOMAIN); ?>
            </p>
          </div>
        </div>
        <!-- /.f -->

        <div class="f">
          <label for="label_tooltip_help"><?php _e("Tooltip Help", MASTERPRESS_DOMAIN)?>:</label>
          <div class="fw">
            <textarea id="label_tooltip_help" name="labels[tooltip_help]"><?php echo stripslashes($model->label("tooltip_help")) ?></textarea>
            <p>
              <?php _e("Provides more extensive help for this field through a tooltip, revealed by mousing over a question-mark badge adjacent to the field label", MASTERPRESS_DOMAIN); ?>
            </p>
          </div>
        </div>
        <!-- /.f -->
    
        
      
      </div>
      </div>

    </div>
    <!-- /.fs .fs-labels -->
    
    
    
    
    
    <?php
    
      
    $args = array();

    $args["supports"] = array();

    // $args["supports"][] = "fields"; COMING SOON

    $fields = $parent->fields();
    
    $fields_to_use = array();
    
    foreach ($fields as $field) {
      if ($field->id != $model->id) {
        $fields_to_use[] = $field;
      }
    }
    
    $args["fields"] = $fields_to_use;


    
    if (is_multisite()) {
      $args["supports"][] = "multisite";
    }
    
    if ($parent->is_shared()) {
      $args["supports"][] = "post_types";
      $args["supports"][] = "roles";
      $args["supports"][] = "taxonomies";
      $args["supports"][] = "templates";
    }
    
    $args["labels"] = array(
      "title" =>  __("control the visibility of this field within WordPress", MASTERPRESS_DOMAIN),   
      "title_multisite" =>  __("specify the sites in the multisite network that this field is available in", MASTERPRESS_DOMAIN),   
      "title_post_types" =>  __("specify the post types that this field is available in", MASTERPRESS_DOMAIN),   

      "templates_all" => sprintf( __( "All Templates <span>( that the <em>%s</em> field set is available in )</span>" ), $parent->display_label() ),
      "multisite_all" => sprintf( __( "All Sites <span>( that the <em>%s</em> field set is available in )</span>" ), $parent->display_label() ),
      "post_types_all" => sprintf( __( "All Post Types <span>( that the <em>%s</em> field set is available in )</span>" ), $parent->display_label() ),
      "roles_all" => sprintf( __( "All User Roles <span>( that the <em>%s</em> field set is available in )</span>" ), $parent->display_label() ),
      "taxonomies_all" => sprintf( __( "All Taxonomies <span>( that the <em>%s</em> field set is available in )</span>" ), $parent->display_label() )
    );

    $args["defaults"] = array(
      "taxonomies" => "all",
      "roles" => "all",
      "post_types" => "all",
      "multisite" => "all"
    );
  
    $args["post_types"] = $parent->post_types();
    
    if (isset($parent) && is_multisite()) {
      
      $site_options = array();
      
      foreach ($parent->sites() as $site) {
        $site_options[$site->full_path()] = $site->id();
      }
      
      $args["sites"] = $site_options;
      
    };
    
    // filter the available roles
    $roles = $parent->vis("roles");
    
    if ($roles != "" && $roles != "*") {
      $role_names = explode(",", $roles);
      
      $rc = array();
      
      foreach ($role_names as $role_name) {
        $rc[] = $wf->role($role_name);  
      }
      
      $args["roles"] = new WOOF_Collection($rc);
    }
    
    MPV::fs_visibility( $model, $args ); 
  
    ?>
    
    
    <div class="fs fs-capability-keys clearfix">
    
      <div class="fst">
      <div class="fstb">
        <h3><i class="key"></i><strong><?php _e("Capabilities", MASTERPRESS_DOMAIN) ?></strong> - <?php _e('the keys used to control access to this field', MASTERPRESS_DOMAIN) ?></h3>
      </div>
      </div>
    
      <div class="fsc">
      <div class="fscb clearfix">
      
      <div class="f f-capabilities f-capabilities-editable clearfix">
          <label for="label-capabilities-editable"><?php _e("Editable", MASTERPRESS_DOMAIN) ?>:</label>
          <div class="fw">
            
            <?php 
            
              $val = $model->capability("editable", false);
              $custom_val = "";

              $caps = array_unique(array_merge($keys, array("edit_posts", "edit_pages", "edit_".$prefix.$parent->name)));
              
              $caps = array( __("-- None (Same as Field Set) --", MASTERPRESS_DOMAIN) => "" ) + $caps;
              
              if (MPC::is_edit()) {
                $caps[] = "edit_".$prefix.$parent->name."_".$model->name;
              }


              if (!in_array($val, $caps)) {
                $custom_val = $val;
              } 
              
              echo WOOF_HTML::select( array("id" => "capabilities-editable", "name" => "capabilities[editable]", "class" => "capabilities" ), 
                $caps,
                $val
              );
      
            ?>
            
            <label for="capabilities-editable-custom" class="capabilities-custom"><?php _e("OR custom value") ?></label>
            <input id="capabilities-editable-custom" name="capabilities_custom[editable]" value="<?php echo $custom_val ?>" type="text" class="text mono capabilities-custom" />

            <p class="note">
              <?php _e("This field will be read-only for users without this capability", MASTERPRESS_DOMAIN) ?>
            </p>
          </div>
        </div>
        <!-- /.f -->
        
        <div class="f f-capabilities f-capabilities-visible clearfix">
          <label for="label-capabilities-visible"><?php _e("Visible", MASTERPRESS_DOMAIN) ?>:</label>
          <div class="fw">
            
            <?php 
            
              $val = $model->capability("visible", false);
              
              $caps = array_unique(array_merge($keys, array("edit_posts", "edit_pages", "view_".$prefix.$parent->name)));
              
              $caps = array( __("-- None (Same as Field Set) --", MASTERPRESS_DOMAIN) => "" ) + $caps;
              
              if (MPC::is_edit()) {
                $caps[] = "view_".$prefix.$parent->name."_".$model->name;
              }

              $custom_val = "";
              
              if (!in_array($val, $caps)) {
                $custom_val = $val;
              } 

              echo WOOF_HTML::select( array("id" => "capabilities-visible", "name" => "capabilities[visible]", "class" => "capabilities" ), 
                $caps,
                $val
              );
      
            ?>
            
            <label for="capabilities-visible-custom" class="capabilities-custom"><?php _e("OR custom value") ?></label>
            <input id="capabilities-visible-custom" name="capabilities_custom[visible]" value="<?php echo $custom_val ?>" type="text" class="text mono capabilities-custom" />
            
            <p class="note">
              <?php _e("This field will be invisible for users without this capability", MASTERPRESS_DOMAIN) ?>
            </p>
          </div>
        </div>
        <!-- /.f -->

        
      
      </div>
      </div>

    </div>
    <!-- /.fs -->
    

    <div class="fs fs-summary-options clearfix">
    
      <div class="fst">
      <div class="fstb">
        <h3><i class="set-summary"></i><strong><?php _e("Summary Options", MASTERPRESS_DOMAIN) ?></strong> - <?php _e('settings for the collapsed summary display', MASTERPRESS_DOMAIN) ?></h3>
      </div>
      </div>
    
      <div class="fsc">
      <div class="fscb clearfix">
        

      <div class="f">
        <label for="summary_options_emphasise"><?php _e("Emphasise", MASTERPRESS_DOMAIN) ?>?</label>
        <div class="fw">
          <input id="summary_options_emphasise" name="summary_options[emphasise]" type="checkbox" value="true" <?php echo WOOF_HTML::checked_attr( isset($model->summary_options["emphasise"]) && $model->summary_options["emphasise"] ) ?> class="checkbox" />
          <p class="checkbox-alt-label { for_el: '#summary_options_emphasise' }">
            <?php _e("Show the summary for this field in <strong>bold text</strong>, which may often be appropriate for the first field in a set, or for other important fields in your content.", MASTERPRESS_DOMAIN); ?>
          </p>
        </div>
      </div>
      <!-- /.f -->

      <div class="f f-summary_width">
        <label for="summary_options_width"><?php _e("Block Width", MASTERPRESS_DOMAIN) ?>?</label>
        <div class="fw">
          <input id="summary_options_width" name="summary_options[width]" type="text" maxlength="1" value="<?php echo isset($model->summary_options["width"]) ? $model->summary_options["width"] : "" ?>" class="text" />
          <p class="note">
            <?php _e("Override block width of the summary, when the field's set is collapsed (min value 1, max value 5)<br />Leave this value empty to use the block width recommended by the field type<br />The pixel width of the summary will be the value here x 150.", MASTERPRESS_DOMAIN); ?>
          </p>
        </div>
      </div>
      <!-- /.f -->

      <div class="f clearfix">
        <label id="label-icon" for="icon"><?php _e("Icon (16 x 16)", MASTERPRESS_DOMAIN) ?>:</label>
        <div class="fw">

          <div id="icon-file-uploader" class="icon-uploader file-uploader { ids: { drop: 'icon_drop_area' }, input: '#icon', inputName: 'icon_ul', base_url: '<?php echo MASTERPRESS_GLOBAL_CONTENT_URL ?>', params: { dir: 'menu-icons/' }, limit: 1, lang: { buttonChoose: '<?php _e("Choose from Computer&hellip;", MASTERPRESS_DOMAIN) ?>', buttonReplace: '<?php _e("Replace file&hellip;", MASTERPRESS_DOMAIN) ?>' } }">
          
            <div id="icon_drop_area" class="drop-area"><?php _e("Drop file here to upload", MASTERPRESS_DOMAIN) ?></div>

            <?php 
          
          
            $file_name = $model->icon;
            $file_class = "";
            $preview_class = "";
            $clear_class = "";
          
            if ($file_name == "") {
              $file_name = __("( None )", MASTERPRESS_DOMAIN);
              $file_class = "name-none";
              $preview_class = "preview-none";
              $clear_class = "hidden";
              $style = "";
            } else {
              $style = ' style="background-image: url('.MPU::field_set_icon_url($model->icon).')" ';
            }
          
          
            ?>
          
            <div class="file">
              <span class="preview <?php echo $preview_class ?>" <?php echo $style ?>></span><span data-none="<?php echo __("( None )", MASTERPRESS_DOMAIN) ?>" class="name <?php echo $file_class ?>"><?php echo $file_name ?></span>
              <button type="button" class="<?php echo $clear_class ?> clear ir" title="<?php _e("Clear", MASTERPRESS_DOMAIN) ?>">Clear</button>
            </div>
          
            <input id="icon" name="icon" value="<?php echo $model->icon ?>" type="hidden" />
            <div class="uploader-ui"></div>
          
          </div>
          <!-- /.file-uploader -->
        
          <?php MPV::icon_select($model->icon, "menu-icon-select", "icon_select", "icon-file-uploader"); ?>
        

        </div>
      </div>
      <!-- /.f -->
                
            
      
      </div>
      </div>

    </div>
    <!-- /.fs -->
    
    

    <?php
    
      // build a field list
      
      $fields = $parent->fields();
    
    ?>
    
    
    <?php if ( ( MPC::is_edit() && count($fields) > 1) || (MPC::is_create() && count($fields) > 0) ) : ?>
      
    <div id="f-position" class="f clearfix">
      <p class="label label-icon icon position"><?php _e("Position in set", MASTERPRESS_DOMAIN)?>:</p>
      <div class="fw">

          <div class="sortable-list sortable-list-fields">
            <span class="arrow"></span>
            
            <?php
            
            // build a field list
            
            $sort_fields = array();
            
            // now build a representable list of fields
            
                
            foreach ($fields as $field) {
              
              $position = $field->position;
            
              if (isset($_POST["other_position"]) && isset($_POST["other_position"][$field->id])) {
                $position = $_POST["other_position"][$field->id];
              }

              if ($ftc = MPFT::type_class($field->type)) {
                $sort_fields[] = array( "position" => $position, "disabled" => (bool) $field->disabled, "current" => $field->id == $model->id, "label" => $field->display_label(), "type" => $field->type, "id" => $field->id );
              }
            }
            
            if (MPC::is_create()) {
              $label = $model->display_label();
              
              if (!$label || $label == "") {
                $label = "?";
              }
            
            
              $sort_fields[] = array( "position" => $model->position, "disabled" => (bool) $field->disabled, "current" => true, "label" => $model->display_label(), "type" => $model->type );

            }
            
            $count = 0;
            
            ?>
            
            <ul>
              <?php foreach ($sort_fields as $f) : $count++; $first = $count == 1 ? "first " : ""; $current = $f["current"] ? 'current ' : '';  ?>

              <?php
                $disabled = $f["disabled"] ? 'disabled' : '';
                $disabled_title = $f["disabled"] ? __("This field is disabled", MASTERPRESS_DOMAIN) : '';
              ?>

              <li class="<?php echo $first.$current ?>  <?php echo $disabled ?>" title="<?php echo $disabled_title ?>">
                <span class="icon mp-icon mp-icon-field-type-<?php echo $f["type"] ?>"></span>
                <?php if ($f["current"]) : ?>
                <span class="fill { src: '#label_name'}"><?php echo $f["label"] ?></span>
                <input id="position" name="position" value="<?php echo $f["position"] ?>" type="hidden" />
                <?php else: ?>
                <span><?php echo $f["label"] ?></span>
                <input id="other_position_<?php echo $f["id"] ?>" name="other_position[<?php echo $f["id"] ?>]" value="<?php echo $f["position"] ?>" type="hidden" />
                <?php endif; ?>
              </li>
              <?php endforeach; ?>
            </ul>
            
          </div>
          <!-- /.sortable-list -->
          
        <p>
          <?php printf(__("Drag field to the desired position in the %s set.<br />Note: changes to the positions of other fields will also be saved.", MASTERPRESS_DOMAIN), '<em>'.$parent->display_label().'</em>') ?>
        </p>
      </div>
    </div>
    <!-- /.f -->
    
    <?php else: ?>
    <input id="position" name="position" value="1" type="hidden" />
    <?php endif; ?>
    
    
    
    </div>
    <!-- /.mpv-fields-form -->
    
    <?php
  } // end form()
示例#11
0
文件: mpv.php 项目: verbazend/AWFA
 public function form_buttons($action) {
   
   $actions = array();
   
   if (MPC::is_edit($action)) {
     $actions = array("update");
   } else if (MPC::is_create($action)) {
     $actions = array("save");
   }
   
   return $actions;
 }
示例#12
0
  public static function options_form( $options ) {

    $defaults = array();

    if (MPC::is_create()) {
      $defaults = array("default_value" => "#");
    }

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

    $p = self::type_prefix(__CLASS__);

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

    $value = self::option_value($options, "default_value", "");
    
    $style = "";
    
    if ($value != "") {
      $style = WOOF_HTML::attr(array("style" => "background-color: $value"));
      
    }
    
    $default_value_label = __("Default Color:", MASTERPRESS_DOMAIN);

$html = <<<HTML

    <div class="f">
      <label for="{$p}default-value">{$default_value_label}</label>
      <div id="fw-{$p}default-value" class="fw">
	    <div class="input-wrap">
	       <input id="{$p}default-value" name="type_options[default_value]" maxlength="7" type="text" value="{$options['default_value']}" class="text" />
	       <span id="{$p}colorpreview" {$style}></span>
		</div>
	
        <div id="{$p}colorpicker"></div>

      </div>


    </div>
    <!-- /.f -->


HTML;

    return $html;

  }
示例#13
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;

  }
示例#14
0
  public static function options_form( $options ) {

    $defaults = array();

    if (MPC::is_create()) {
      $defaults = array("mode" => "single");
    }

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

    $mode = self::option_value($options, "mode");
    
    if ($mode == "") {
      $mode = "single";
    }

    $p = self::type_prefix(__CLASS__);



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

    $mode_label = __("Selection Mode:", MASTERPRESS_DOMAIN);

    $mode_select = WOOF_HTML::input_radio_group(
      "type_options[mode]", $p."mode-", 
      array(__("Single Date", MASTERPRESS_DOMAIN) => "single", __("Start / End Date", MASTERPRESS_DOMAIN) => "start_end" ),
      self::option_value($options, "mode"),
      WOOF_HTML::open("div", "class=fwi"), WOOF_HTML::close("div")
    );

    $mindate_label = __("Minimum Date:", MASTERPRESS_DOMAIN);
    $maxdate_label = __("Maximum Date:", MASTERPRESS_DOMAIN);
    $default_value_label = __("Default Date:", MASTERPRESS_DOMAIN);

    $time_select_label = __("Allow Time Selection?", MASTERPRESS_DOMAIN);
    $time_select_checked_attr = WOOF_HTML::checked_attr(self::option_value($options, "timeselect") == "yes");

    $date_format_note = __("Note: for minumum, maximum, and default dates, you may also enter a number of days from today (e.g. +7) or a string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '-1y -1m').", MASTERPRESS_DOMAIN);

    $button_text = esc_js(__("choose&hellip;", MASTERPRESS_DOMAIN));

    $font_select = WOOF_HTML::select(
      array("id" => $p."font", "name" => "type_options[font]"), 
      array(
        "Sans-Serif&nbsp;&nbsp;-&nbsp;&nbsp;Helvetica, Arial, sans-serif" => "helvetica, arial, sans-serif", 
        "Serif&nbsp;&nbsp;-&nbsp;&nbsp;Georgia, Times New Roman, serif" => "georgia, 'times new roman', serif", 
        "Fixed Width&nbsp;&nbsp;-&nbsp;&nbsp;Consolas, Menlo, Andale Mono, Lucida Console, monospace" => "consolas, menlo, 'andale mono', 'lucida console', monospace"
      ),
      self::option_value($options, "font")
    );

 
    $mindate = esc_attr(self::option_value($options, "mindate"));
    $maxdate = esc_attr(self::option_value($options, "maxdate"));
    $default_value = esc_attr(self::option_value($options, "default_value"));

$html = <<<HTML


    <!--
    TODO - re-enable dual date support (not important right now)
    <div class="f">
      <label for="{$p}mode_select">{$mode_label}</label>
      <div id="fw-{$p}mode_select" class="fw">
        {$mode_select}
      </div>
    </div>
    -->
    <!-- /.f -->

    <div class="f">
      <label for="{$p}timeselect">{$time_select_label}</label>
      <div id="fw-{$p}timeselect" class="fw">
        <input id="{$p}timeselect" type="checkbox" name="type_options[timeselect]" {$time_select_checked_attr} value="yes" class="checkbox" />
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}mindate">{$mindate_label}</label>
      <div id="fw-{$p}mindate" class="fw">
        <input id="{$p}mindate" name="type_options[mindate]" type="text" maxlength="4" value="{$mindate}" class="text date { buttonText: '{$button_text}' }" />
      </div>
    </div>
    <!-- /.f -->


    <div class="f">
      <label for="{$p}maxdate">{$maxdate_label}</label>
      <div id="fw-{$p}maxdate" class="fw">
        <input id="{$p}maxdate" name="type_options[maxdate]" type="text" maxlength="4" value="{$maxdate}" class="text date { buttonText: '{$button_text}' }" />
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}default_value">{$default_value_label}</label>
      <div id="fw-{$p}default_value" class="fw">
        <input id="{$p}default_value" name="type_options[default_value]" type="text" defaultlength="4" value="{$default_value}" class="text date { buttonText: '{$button_text}' }" />
      </div>
    </div>
    <!-- /.f -->

    <p class="note format-note">
      {$date_format_note}
    </p>


HTML;

    return $html;

  }
示例#15
0
  public function submit() {
    
    global $wpdb, $wf;
    
    $action = MasterPress::$action;

    if ($action == "create") {
      
      $role_id = $_POST["name"];
      
      if ($role_id == "") {
        MPV::err(__("A role name must be provided", MASTERPRESS_DOMAIN) );
        return false;
      }
      
      // check that there isn't a role of this name already
      
      $role = $wf->role($role_id);
      
      if ($role && !is_woof_silent($role)) {
        MPV::err( sprintf( __("Sorry a role named %s already exists. Please choose another name", MASTERPRESS_DOMAIN), $role_id ) );
        return false;
      }
      
      // all okay, save the role
      
      if (isset($_POST["display_name"]) && trim($_POST["display_name"]) != "") {
        $display_name = $_POST["display_name"];
      } else {
        $display_name = WOOF_Inflector::titleize($role_id);
      }
      
      $caps = array_keys($_POST["cap"]);
      
      foreach ($_POST["new_caps"] as $cap) {
        
        if (trim($cap) != "") {
          $norm = WOOF_Inflector::underscore($cap);
        
          if (!in_array($norm, $_POST["all_caps"])) {
            $caps[] = $norm;
          }
        }
      
      }
         
      
      add_role($role_id, $display_name, array_fill_keys($caps, true) );
      
      return true;

    }  else if ($action == "edit") {

      $role_id = MasterPress::$id;

      $wf_role = $wf->role($role_id);
      
      if (!is_woof_silent($wf_role)) {
        
        $role = get_role($wf_role->id());
        
        $all_caps = explode(",", $_POST["all_caps"]);
        $selected_caps = array_keys($_POST["cap"]);

        $role_caps = array_keys($role->capabilities);
      
        $add_caps = array_diff($selected_caps, $role_caps);
        $remove_caps = array_diff($all_caps, $selected_caps);
        
        foreach ($remove_caps as $cap) {
          
          if ($role->has_cap($cap)) {
            $role->remove_cap($cap);
          }
          
        }


        foreach ($_POST["new_caps"] as $cap) {
        
          if (trim($cap) != "") {
            $norm = WOOF_Inflector::underscore($cap);
            
            if (!in_array($norm, $all_caps)) {
              $add_caps[] = $norm;
            }
          }
      
        }
      
        foreach ($add_caps as $cap) {

          if (!$role->has_cap($cap)) {
            $role->add_cap($cap);
          }
        
        }
        
      
      }

      return true;

    } else if ($action == "create-field-set" || $action == "edit-field-set") {
      
      $field_set = new MPM_RoleFieldSet();
      // consume the post data
      
      $field_set->name = $_POST["name"];
      $field_set->singular_name = $_POST["singular_name"];
      $field_set->disabled = isset($_POST["disabled"]);
      $field_set->labels = $_POST["labels"];
      $field_set->visibility = $_POST["visibility"];
      $field_set->capabilities = self::handle_capabilities();
      $field_set->allow_multiple = isset($_POST["allow_multiple"]);
      $field_set->type = "r"; // r = role
      $field_set->icon = self::handle_icon("icon", "icon_select");
      $field_set->position = $_POST["position"];
      $field_set->expanded = isset($_POST["expanded"]);
      $field_set->sidebar = false;
      $field_set->visibility = $this->get_visibility_val("sites,roles");
      
      if (MPC::is_create()) {
        $field_set->insert();
      } else if (MPC::is_edit()) {
        $field_set->update(MasterPress::$id);
      }

      if ($field_set->is_valid()) {

        if (MPC::is_edit()) {
          global $meow_provider;
          $meow_provider->migrate_field_set_meta($field_set, $_POST["name_original"]);
        }

        // we don't attach post types to these. they are implicitly linked to the built-in "page" post type
        
        // update other menu positions
        
        $op = $_POST["other_position"];
        
        if (isset($op) && is_array($op)) {
          foreach ($op as $id => $position) {
            $wpdb->update(MPM::table("field-sets"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); 
          }
          
        }
        
        
      }        
      
      return $field_set;
      
    } else if ($action == "delete-field-set") {
      
      $fg = MPM_FieldSet::find_by_id(MasterPress::$id);

      if ($fg) {
        $field_data_action = $_POST["field_data"];
        if ($field_data_action == "delete") {
          $fg->delete_meta();
        }
      }

      $fg->delete();
      
      return true;

    } else if ($action == "delete-field") {

      $f = MPM_Field::find_by_id(MasterPress::$id);

      if ($f) {

        $field_data_action = $_POST["field_data"];
        
        if ($field_data_action == "delete") {
          $f->delete_meta();
        }

      }
      
      $f->delete();
      
      return true;
      
    } else if ($action == "create-field" || $action == "edit-field") {
      
      // FIELD OPERATIONS (NOT FIELD GROUPS!)
       
      $field = new MPM_Field();
      // consume the post data
      
      $field->field_set_id = $_POST["parent"];
      $field->name = $_POST["name"];
      $field->disabled = isset($_POST["disabled"]);
      $field->required = isset($_POST["required"]);
      $field->summary_options = $_POST["summary_options"];
      $field->labels = $_POST["labels"];
      $field->icon = self::handle_icon("icon", "icon_select");
      $field->type = $_POST["type"]; 
      $field->type_options = $_POST["type_options"];
      $field->position = $_POST["position"];
      $field->visibility = $this->get_visibility_val();
      $field->capabilities = self::handle_capabilities();

      
      if (MPC::is_create()) {
        $field->insert();
      } else if (MPC::is_edit()) {
        $field->update(MasterPress::$id);
      }

      if ($field->is_valid()) {
        
        if (MPC::is_edit()) {
          global $meow_provider;
          $meow_provider->migrate_field_meta($field, $_POST["name_original"]);
        }

        // update other menu positions
        
        $op = $_POST["other_position"];
        
        if (isset($op) && is_array($op)) {
          foreach ($op as $id => $position) {
            $wpdb->update(MPM::table("fields"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); 
          }
          
        }
        
      }    
      
      
      
      return $field;

    } 
    
    
    return false;
  }
示例#16
0
  public function submit() {
    
    global $wpdb;
    
    $action = MasterPress::$action;
    
    if ($action == "create" || $action == "edit") {
      
      $field_set = new $this->model_class();
      // consume the post data
      
      $field_set->name = $_POST["name"];
      $field_set->singular_name = $_POST["singular_name"];
      $field_set->disabled = isset($_POST["disabled"]);
      $field_set->labels = $_POST["labels"];
      $field_set->visibility = MPC::post_val("visibility");
      $field_set->capabilities = self::handle_capabilities();
      $field_set->allow_multiple = isset($_POST["allow_multiple"]);
      $field_set->type = $this->db_type;
      $field_set->position = $_POST["position"];
      $field_set->icon = self::handle_icon("icon", "icon_select");
      $field_set->expanded = isset($_POST["expanded"]);
      $field_set->sidebar = isset($_POST["sidebar"]);
      $field_set->versions = $_POST["versions"];
      $field_set->visibility = $this->get_visibility_val();

      if ($action == "create") {
        $field_set->insert();
      } else if ($action == "edit") {
        $field_set->update(MasterPress::$id);
      }

      if ($field_set->is_valid()) {

        if (MPC::is_edit()) {
          global $meow_provider;
          $meow_provider->migrate_field_set_meta($field_set, $_POST["name_original"]);
        }

        // update other menu positions
        
        $op = MPC::post_val("other_position");
        
        if (isset($op) && is_array($op)) {
          foreach ($op as $id => $position) {
            $wpdb->update(MPM::table("field-sets"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); 
          }
          
        }
        
        
      }        
      
      return $field_set;
      
    } else if ($action == "delete") { 

      $fg = MasterPress::$view->parent = call_user_func_array( array($this->model_class, "find_by_id"), array(MasterPress::$id));

      if ($fg) {

        $field_data_action = $_POST["field_data"];
        
        if ($field_data_action == "delete") {
          $fg->delete_meta();
        }

      }
      
      $fg->delete();
      
      return true;

    } else if ($action == "delete-field") {

      $f = MPM_Field::find_by_id(MasterPress::$id);
      
      if ($f) {

        $field_data_action = $_POST["field_data"];
        
        if ($field_data_action == "delete") {
          $f->delete_meta();
        }

      }
      
      $f->delete();
      
      return true;
      
    } else if ($action == "create-field" || $action == "edit-field") {
      
      // FIELD OPERATIONS (NOT FIELD GROUPS!)
       
      $field = new MPM_Field();
      // consume the post data
      
      $field->field_set_id = $_POST["parent"];
      $field->name = $_POST["name"];
      $field->disabled = isset($_POST["disabled"]);
      $field->summary_options = $_POST["summary_options"];
      $field->required = isset($_POST["required"]);
      $field->labels = $_POST["labels"];
      $field->type = $_POST["type"]; 
      $field->icon = self::handle_icon("icon", "icon_select");
      $field->type_options = $_POST["type_options"];
      $field->position = $_POST["position"];
      $field->visibility = $this->get_visibility_val();
      $field->capabilities = self::handle_capabilities();

      if (MPC::is_create()) {
        $field->insert();
      } else if (MPC::is_edit()) {
        $field->update(MasterPress::$id);
      }

      if ($field->is_valid()) {

        if (MPC::is_edit()) {
          global $meow_provider;
          $meow_provider->migrate_field_meta($field, $_POST["name_original"]);
        }
        
        // update other menu positions
        
        $op = MPC::post_val("other_position");
        
        if (isset($op) && is_array($op)) {
          foreach ($op as $id => $position) {
            $wpdb->update(MPM::table("fields"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); 
          }
          
        }

        // clear the parent for the redirect
      
        MasterPress::$parent = null;

        
      }    
      
      
      return $field;
    } 
    
    
  }
示例#17
0
  public function submit() {

    global $wpdb;
    
    $action = MasterPress::$action;
    
    if ($action == "create" || $action == "edit") {

      $builtin = $_POST["_builtin"] == "true";
      $external = $_POST["_external"] == "true";
      
      if ($builtin) {
        
        $tax = MPM_Taxonomy::find_by_name($_POST["name"]);
        $tax->disabled = isset($_POST["disabled"]);
        $tax->object_type = $_POST["post_types"];
        $tax->visibility = $this->get_visibility_val("sites");
        $tax->title_icon = self::handle_icon("title_icon", "title_icon_select");
        $tax->columns = $_POST["columns"];

        if ($action == "edit") {
          $tax->update(MasterPress::$id);
        }

      } else if ($external) {

        $tax = MPM_Taxonomy::find_by_name($_POST["name"]);
        $tax->columns = $_POST["columns"];
        $tax->title_icon = self::handle_icon("title_icon", "title_icon_select");

        if ($action == "edit") {
          $tax->update(MasterPress::$id);
        }
        
      } else {
        
        $tax = new MPM_Taxonomy();
    
        // consume the post data
        $tax->name = $_POST["name"];
        $tax->plural_name = $_POST["plural_name"];
        $tax->object_type = MPC::post_val("post_types");
        $tax->disabled = isset($_POST["disabled"]);
        $tax->labels = $_POST["labels"];
        $tax->show_ui = isset($_POST["show_ui"]);
        $tax->hide_term_ui = isset($_POST["hide_term_ui"]);
        $tax->show_in_nav_menus = isset($_POST["show_in_nav_menus"]);
        $tax->show_manage_filter = isset($_POST["show_manage_filter"]);
        $tax->show_tagcloud = isset($_POST["show_tagcloud"]);
        $tax->hierarchical = isset($_POST["hierarchical"]);
        $tax->query_var = $_POST["query_var"];
        $tax->title_icon = self::handle_icon("title_icon", "title_icon_select");
        $tax->capabilities = $_POST["capabilities"];
        $tax->update_count_callback = $_POST["update_count_callback"];
        $tax->visibility = $this->get_visibility_val("sites,taxonomies");
        $tax->columns = $_POST["columns"];

        $rewrite = array(
          "slug" => $_POST["rewrite"]["slug"],
          "with_front" => isset($_POST["rewrite"]["with_front"]),
          "hierarchical" => isset($_POST["rewrite"]["hierarchical"])
        );

        $tax->rewrite = $rewrite;
        $tax->_builtin = false;
        $tax->_external = $external;

        if ($action == "create") {
          $tax->insert();
        } else if ($action == "edit") {
          $tax->update(MasterPress::$id);

          if ($tax->is_valid()) {
            global $meow_provider;
            $meow_provider->migrate_taxonomy($tax, $_POST["name_original"]);
          }

        }
        
      }
      
      if ($tax->is_valid()) {
        MasterPress::flag_for_rewrite();
      } 
    
      return $tax;
      
    } else if ($action == "delete") {
      
      $tax = MPM_Taxonomy::find_by_id(MasterPress::$id);
      
      if ($tax) {

        $tax->delete(
          array(
            "existing_terms" => MPC::post_val("existing_terms"),
            "existing_terms_reassign_taxonomy" => MPC::post_val("existing_terms_reassign_taxonomy"),
            "field_sets" => MPC::post_val("field_sets"),
            "field_data" => MPC::post_val("field_data")
          )
        );
      
      }
      
      MasterPress::flag_for_rewrite();

      return true;
    
    } else if ($action == "create-field-set" || $action == "edit-field-set") {
      
      $field_set = new MPM_TaxonomyFieldSet();
      // consume the post data
      
      $field_set->name = $_POST["name"];
      $field_set->singular_name = $_POST["singular_name"];
      $field_set->disabled = isset($_POST["disabled"]);
      $field_set->labels = $_POST["labels"];
      $field_set->allow_multiple = isset($_POST["allow_multiple"]);
      $field_set->visibility = $_POST["visibility"];
      $field_set->capabilities = self::handle_capabilities();
      $field_set->icon = self::handle_icon("icon", "icon_select");
      $field_set->type = "x"; // x = taXonomy
      $field_set->position = $_POST["position"];
      $field_set->expanded = isset($_POST["expanded"]);
      $field_set->sidebar = isset($_POST["sidebar"]);
      $field_set->versions = $_POST["versions"];
      $field_set->visibility = $this->get_visibility_val("sites,taxonomies");

      if (MPC::is_create()) {
        $field_set->insert();
      } else if (MPC::is_edit()) {
        $field_set->update(MasterPress::$id);
      }
      
      if ($field_set->is_valid()) {

        if (MPC::is_edit()) {
          global $meow_provider;
          $meow_provider->migrate_field_set_meta($field_set, $_POST["name_original"]);
        }
        
        // update other menu positions
        
        $op = $_POST["other_position"];
        
        if (isset($op) && is_array($op)) {
          foreach ($op as $id => $position) {
            $wpdb->update(MPM::table("field-sets"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); 
          }
          
        }
        
        
      }        
      
      return $field_set;
      

    } else if ($action == "delete-field-set") {
      
      $fg = MPM_TaxonomyFieldSet::find_by_id(MasterPress::$id);
      
      if ($fg) {
        $field_data_action = $_POST["field_data"];
        if ($field_data_action == "delete") {
          $fg->delete_meta();
        }
      }
      
      $fg->delete();
      
      return true;
      
    } else if ($action == "delete-field") {
      
      $f = MPM_Field::find_by_id(MasterPress::$id);
      
      if ($f) {

        $field_data_action = $_POST["field_data"];
        
        if ($field_data_action == "delete") {
          $f->delete_meta();
        }

      }
      
      $f->delete();
      
      return true;
      
    } else if ($action == "create-field" || $action == "edit-field") {
      
      // FIELD OPERATIONS (NOT FIELD GROUPS!)
       
      $field = new MPM_Field();
      // consume the post data
      
      $field->field_set_id = $_POST["parent"];
      $field->name = $_POST["name"];
      $field->disabled = isset($_POST["disabled"]);
      $field->summary_options = $_POST["summary_options"];
      $field->required = isset($_POST["required"]);
      $field->labels = $_POST["labels"];
      $field->icon = self::handle_icon("icon", "icon_select");
      $field->type = $_POST["type"]; 
      $field->type_options = $_POST["type_options"];
      $field->position = $_POST["position"];
      $field->visibility = $this->get_visibility_val("sites,taxonomies");
      $field->capabilities = self::handle_capabilities();

      $fg = MPM_TaxonomyFieldSet::find_by_id($_POST["parent"]);
        
        
      if (MPC::is_create()) {
        $field->insert();
      } else if (MPC::is_edit()) {
        $field->update(MasterPress::$id);
      }

      if ($field->is_valid()) {

        if (MPC::is_edit()) {
          global $meow_provider;
          $meow_provider->migrate_field_meta($field, $_POST["name_original"]);
        }

        // update other menu positions
        
        $op = $_POST["other_position"];
        
        if (isset($op) && is_array($op)) {
          foreach ($op as $id => $position) {
            $wpdb->update(MPM::table("fields"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); 
          }
          
        }
        
      }     
      
      
      
      return $field;
    }
  
  }
示例#18
0
  public static function options_form( $options ) {

    $defaults = array();

    if (MPC::is_create()) {
      $defaults = array();
    }

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

    $values = self::option_value($options, "values");

    $p = self::type_prefix(__CLASS__);

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

    $values_label = __("Choices:", MASTERPRESS_DOMAIN);
    $values_note = __('Specify the labels for each choice on separate lines. To use a different underlying <span class="tt">value</span> for any of the choices,<br /> use the form <strong><span class="tt">label = value</span></strong>.', MASTERPRESS_DOMAIN);

    $default_value_label = __("Default State:", MASTERPRESS_DOMAIN);
    $default_value_note = __("Use the preview of your control above to setup the default state", MASTERPRESS_DOMAIN);

    $option_values = WOOF_HTML::option_values($values);

    $default_value_checkboxes = WOOF_HTML::input_checkbox_group( "type_options[default_value][]", $p."default-value-", $option_values, self::option_value($options, "default_value"), WOOF_HTML::open("div", "class=fwi"), WOOF_HTML::close("div")); 


$html = <<<HTML

    <div class="f">
      <label for="{$p}values">{$values_label}</label>
      <div id="fw-{$p}values" class="fw">
        <textarea id="{$p}values" class="mono" name="type_options[values]">{$values}</textarea>
        <span class="note">{$values_note}</span>
      </div>
    </div>
    <!-- /.f -->

    <div id="{$p}default-value-f" class="f">
      <label for="{$p}default-value">{$default_value_label}</label>
      <div id="fw-{$p}default-value" class="fw">
        <div class="preview">{$default_value_checkboxes}</div>

        <div id="{$p}default-value-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">{$default_value_note}</p>

      </div>
    </div>
    <!-- /.f -->

HTML;

    return $html;

  }
示例#19
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;

  }
示例#20
0
  public function form() {
    $model = MasterPress::$model;
    $info = MasterPress::$view;
    
    $parent = $info->parent;
    
    global $wf;
    
    $prefix = "";
    $default_key = "edit_posts";
    $keys = array();


    ?>
    
    <div class="mpv-field-sets-form">
      
    <?php if (isset(MasterPress::$parent)) : ?>
    <div class="title-info-panel">
      <div class="title-info-panel-lt">
        <?php if (get_class($parent) == "MPM_PostType") : ?>
          
          <?php
          
          $post_type = $parent;
          
          $prefix = $post_type->name."_"; 
          $default_key = "edit_".$post_type->capability_type."s";
          $keys = array($default_key);
          
          ?>
          
          <h3 class="post-type"><i class="mp-icon mp-icon-post-type mp-icon-post-type-<?php echo $post_type->name ?>"></i><span class="label"><?php _e("Post Type:", MASTERPRESS_DOMAIN) ?></span><span class="value"> <?php echo $parent->labels["name"] ?></span></h3> 
          <input id="post_type_name" type="hidden" value="<?php echo $parent->name ?>" />
        <?php elseif ($model->template) : ?>

          <?php
        
          $file = MasterPress::$parent;
          $page_templates = array_flip(get_page_templates());
          $template_name = $page_templates[$file];
        
          ?>
          <input id="templates" name="templates" type="hidden" value="<?php echo $file ?>" />
          <h3><i class="template"></i><span class="label"><?php _e("Template:", MASTERPRESS_DOMAIN) ?></span><span class="value"> <?php echo $template_name ?></span></h3> 
        
        <?php elseif ($model->role) : ?>

          <?php
        
          $role_name = MasterPress::$parent;
          $prefix = $role_name."_";

          ?>
          <input id="roles" name="roles" type="hidden" value="<?php echo $role_name ?>" />
          <h3><i class="user-role"></i><span class="label"><?php _e("User Role:", MASTERPRESS_DOMAIN) ?></span><span class="value"> <?php echo $role_name ?></span></h3> 

        <?php elseif ($model->taxonomy) : ?>
          
          <?php
        
          $taxonomy_id = MasterPress::$parent;
          
          $tax = MPM_Taxonomy::find_by_id($taxonomy_id);
          
          $prefix = $tax->name."_";

          $default_key = $tax->capabilities["edit_terms"];

          $keys = array(
            $tax->capabilities["manage_terms"],
            $tax->capabilities["edit_terms"],
            $tax->capabilities["assign_terms"]
          );


          ?>
          <input id="taxonomies" name="taxonomies" type="hidden" value="<?php echo $tax->name ?>" />
          <h3><i class="mp-icon mp-icon-taxonomy mp-icon-taxonomy-<?php echo $tax->name ?>"></i><span class="label"><?php _e("Taxonomy:", MASTERPRESS_DOMAIN) ?></span><span class="value"> <?php echo $tax->display_label() ?></span></h3> 

        <?php endif; ?>
      </div>
    </div>
    <?php endif; ?>

    <?php MPV::messages(); ?>

    <div class="mpv-field-sets-form">
      
    <div class="f">
      <label for="name" class="icon"><i class="script-php"></i><?php _e("Name", MASTERPRESS_DOMAIN)?>:</label>
      <div class="fw">
        <input id="name_original" name="name_original" type="hidden" class="text mono key" maxlength="20" value="<?php echo $model->name ?>" />
        <input id="name_last" name="name_last" type="hidden" class="text mono key" maxlength="20" value="<?php echo $model->name ?>" />
        <input id="name" name="name" type="text" class="text mono key" maxlength="255" value="<?php echo $model->name ?>" /><em class="required">(required)</em>
        <p>
          <?php _e("This is a unique identifier for the field set used in the MasterPress API. Since it can be used as a PHP variable name, it is restricted to being a lowercase string with words separated by underscores.", MASTERPRESS_DOMAIN); ?>
        </p>
      </div>

    </div>
    <!-- /.f -->

    <div id="f-singular_name" class="f">
      <label for="singular_name" class="icon" maxlength="255"><i class="script-php"></i><?php _e("<strong>Singular</strong> Name", MASTERPRESS_DOMAIN)?>:</label>
      <div class="fw">
        <input id="singular_name" name="singular_name" type="text" value="<?php echo $model->singular_name ?>" class="text mono key" /><em class="required">(required)</em>

        <p>
          <?php _e("The singular form of <em>Name</em>, following the same naming conventions", MASTERPRESS_DOMAIN); ?>
        </p>

      </div>
    </div>
    <!-- /.f -->
  
    <div class="f">
      <label for="allow_multiple" class="icon"><i class="add-remove"></i><?php _e("Allow Multiple Items", MASTERPRESS_DOMAIN) ?>?</label>
      <div class="fw">
        <input id="allow_multiple" name="allow_multiple" type="checkbox" value="true" <?php echo WOOF_HTML::checked_attr( $model->allow_multiple ) ?> class="checkbox" />
        <p id="name_warning" class="warning">
		  <i class="error-circle"></i>
          <?php _e("For multiple-item field sets, <em>Name</em> should be specified in <strong>plural form</strong>. Please verify that this is correct above.", MASTERPRESS_DOMAIN) ?>
        </p>
      </div>

    </div>
    <!-- /.f -->
    
    
    
    <div class="f clearfix">
      <label id="label-icon" for="icon" class="icon"><i class="image-small"></i><?php _e("Title Icon (16 x 16)", MASTERPRESS_DOMAIN) ?>:</label>
      <div class="fw">

        <div id="icon-file-uploader" class="icon-uploader file-uploader { ids: { drop: 'icon_drop_area' }, input: '#icon', inputName: 'icon_ul', base_url: '<?php echo MASTERPRESS_GLOBAL_CONTENT_URL ?>', params: { dir: 'menu-icons/' }, limit: 1, lang: { buttonChoose: '<?php _e("Choose from Computer&hellip;", MASTERPRESS_DOMAIN) ?>', buttonReplace: '<?php _e("Replace file&hellip;", MASTERPRESS_DOMAIN) ?>' } }">
          
          <div id="icon_drop_area" class="drop-area"><?php _e("Drop file here to upload", MASTERPRESS_DOMAIN) ?></div>

          <?php 
          
          
          $file_name = $model->icon;
          $file_class = "";
          $clear_class = "";
          $preview_class = "";
          
          if ($file_name == "") {
            $file_name = __("( None )", MASTERPRESS_DOMAIN);
            $file_class = "name-none";
            $preview_class = "preview-none";
            $style = "";
            $clear_class = "hidden";
          } else {
            $style = ' style="background-image: url('.MPU::field_set_icon_url($model->icon).')" ';
          }
          
          
          ?>
          
          <div class="file">
            <span class="preview <?php echo $preview_class ?>" <?php echo $style ?>></span><span data-none="<?php echo __("( None )", MASTERPRESS_DOMAIN) ?>" class="name <?php echo $file_class ?>"><?php echo $file_name ?></span>
            <button type="button" class="<?php echo $clear_class ?> clear ir" title="<?php _e("Clear", MASTERPRESS_DOMAIN) ?>">Clear</button>
          </div>
          
          <input id="icon" name="icon" value="<?php echo $model->icon ?>" type="hidden" />
          <div class="uploader-ui"></div>
          
        </div>
        <!-- /.file-uploader -->
        
        <?php MPV::icon_select($model->icon, "menu-icon-select", "icon_select", "icon-file-uploader"); ?>
        

      </div>
    </div>
    <!-- /.f -->
        
    <div class="f">
      <label for="expanded" class="icon"><i class="expand"></i><?php _e("Expanded", MASTERPRESS_DOMAIN) ?>?</label>
      <div class="fw">
        <input id="expanded" name="expanded" type="checkbox" value="true" <?php echo WOOF_HTML::checked_attr( $model->expanded ) ?> class="checkbox" />
        <p class="checkbox-alt-label { for_el: '#expanded' }">
          <?php _e("this field set will be expanded (not summarised) by default in the edit post screen, but can still be collapsed. It is recommended that this is <strong>unchecked if <em>Allow Multiple Items</em> is checked.</strong>", MASTERPRESS_DOMAIN); ?>
        </p>
      </div>
    </div>
    <!-- /.f -->

    <?php if (!$model->role) : ?>

    <div class="f">
      <label for="sidebar" class="icon"><i class="sidebar"></i><?php _e("Show in Sidebar", MASTERPRESS_DOMAIN) ?>?</label>
      <div class="fw">
        <input id="sidebar" name="sidebar" type="checkbox" value="true" <?php echo WOOF_HTML::checked_attr( $model->sidebar ) ?> class="checkbox" />
        <p class="checkbox-alt-label { for_el: '#sidebar' }">
          <?php _e("this field set will be positioned in the sidebar of the edit post screen by default (but may still be dragged across to the main content area by users)", MASTERPRESS_DOMAIN); ?>
        </p>
      </div>
    </div>
    <!-- /.f -->

    <?php endif; ?>

    <div class="f">
      <label for="disabled" class="icon"><i class="slash"></i><?php _e("Disabled", MASTERPRESS_DOMAIN) ?>?</label>
      <div class="fw">
        <input id="disabled" name="disabled" type="checkbox" value="true" <?php echo WOOF_HTML::checked_attr( $model->disabled ) ?> class="checkbox" />
        <p class="checkbox-alt-label { for_el: '#disabled' }">
          <?php _e("disabling a field set will keep its definition in the database but it will not be available in any post editing screens in WordPress, which may be <strong>preferable to deleting it</strong> completely.", MASTERPRESS_DOMAIN); ?>
        </p>
      </div>
    </div>
    <!-- /.f -->
    
    <div class="f">
      <label for="versions_store" class="icon"><i class="metabox-versions size-20"></i><?php _e("Version Limit", MASTERPRESS_DOMAIN) ?></label>
      <div class="fw">
        <input id="versions" name="versions" type="text" value="<?php echo $model->versions ?>" class="text" />
        <p class="note">
          <?php _e("Set a <b>maximum number of versions</b> of content based on this field set to retain.<br />Versions can be used to restore previous revisions of content at a later time.<br />Set this value to 0 if you do not wish to retain previous versions.", MASTERPRESS_DOMAIN); ?>
        </p>
      </div>
    </div>
    <!-- /.f -->
      

    <div class="fs fs-labels">
    
      <div class="fst">
      <div class="fstb">
        <h3><i class="label-string"></i><strong><?php _e("Labels", MASTERPRESS_DOMAIN) ?></strong> - <?php _e("displayed in the <em>Edit Post</em> and MasterPress admin screens", MASTERPRESS_DOMAIN) ?></h3>

        <div class="buttons">
          <button id="autofill-labels" class="button button-autofill" type="button"><?php _e('<strong>Auto-Fill</strong> Labels', MASTERPRESS_DOMAIN) ?></button>
        </div>


      </div>
      </div>
    
        
      <div class="fsc fscs">
      <div class="fscb">
      <div class="scroll">

        <div class="f">
          <label for="label_name"><?php _e("Set Label", MASTERPRESS_DOMAIN) ?>:</label>
          <div class="fw">
            <input id="label_name" name="labels[name]" value="<?php echo $model->labels["name"] ?>" type="text" class="text { tmpl: '{{plural_name}}' }" />
            <em class="recommended">(recommended)</em>
          </div>
        </div>
        <!-- /.f -->

        <div class="f">
          <label for="label_description"><?php _e("Description", MASTERPRESS_DOMAIN)?>:</label>
          <div class="fw">
            <textarea id="label_description" name="labels[description]"><?php echo $model->label("description") ?></textarea>
            <p>
              <?php _e("Displayed on the Create / Edit Post screen in the info area above the fields in this set.", MASTERPRESS_DOMAIN); ?>
            </p>
          </div>
        </div>
        <!-- /.f -->

        <?php if ($model->shared) : ?>
        <div class="f">
          <label for="label_description_user"><?php _e("Description (User)", MASTERPRESS_DOMAIN)?>:</label>
          <div class="fw">
            <textarea id="label_description_user" name="labels[description_user]"><?php echo $model->label("description_user") ?></textarea>
            <p>
              <?php _e("Displayed on the Create / Edit User and Profile screen in the info area above the fields in this set.<br />If not specified, the standard <em>Description</em> label will be used (if available)", MASTERPRESS_DOMAIN); ?>
            </p>
          </div>
        </div>
        <!-- /.f -->
        
        <div class="f">
          <label for="label_description_term"><?php _e("Description (Term)", MASTERPRESS_DOMAIN)?>:</label>
          <div class="fw">
            <textarea id="label_description_term" name="labels[description_term]"><?php echo $model->label("description_term") ?></textarea>
            <p>
              <?php _e("Displayed on the Edit (Taxonomy) Term in the info area above the fields in this set.<br />If not specified, the standard <em>Description</em> label will be used (if available)", MASTERPRESS_DOMAIN); ?>
            </p>
          </div>
        </div>
        <!-- /.f -->
        <?php endif; ?>

        <div class="f f-allow-multiple">
          <label for="label_singular_name"><?php _e("<em>Singular</em> Name", MASTERPRESS_DOMAIN) ?>:</label>
          <div class="fw">
            <input id="label_singular_name" name="labels[singular_name]" value="<?php echo $model->label("singular_name") ?>" type="text" class="text { tmpl: '{{singular_name}}' }" />
            <em class="recommended">(recommended)</em>
          </div>
        </div>
        <!-- /.f -->

        <div class="f f-allow-multiple">
          <label for="label_add"><?php _e("Add", MASTERPRESS_DOMAIN) ?>:</label>
          <div class="fw">
            <input id="label_add" name="labels[add]" value="<?php echo $model->label("add") ?>" type="text" class="text { tmpl: '<?php _e("Add {{singular_name}}", MASTERPRESS_DOMAIN) ?>' }" />
          </div>
        </div>
        <!-- /.f -->

        <div class="f f-allow-multiple">
          <label for="label_add_another"><?php _e("Add Another", MASTERPRESS_DOMAIN) ?>:</label>
          <div class="fw">
            <input id="label_add_another" name="labels[add_another]" value="<?php echo $model->label("add_another") ?>" type="text" class="text { tmpl: '<?php _e("Add Another {{singular_name}}", MASTERPRESS_DOMAIN) ?>' }" />
          </div>
        </div>
        <!-- /.f -->
              
        <div class="f f-allow-multiple">
          <label for="label_remove"><?php _e("Remove", MASTERPRESS_DOMAIN) ?>:</label>
          <div class="fw">
            <input id="label_remove" name="labels[remove]" value="<?php echo $model->label("remove") ?>" type="text" class="text { tmpl: '<?php _e("Remove {{singular_name}}", MASTERPRESS_DOMAIN) ?>' }"  />
          </div>
        </div>
        <!-- /.f -->

        <div class="f f-allow-multiple">
          <label for="label_click_to_add"><?php _e("Click to Add", MASTERPRESS_DOMAIN) ?>:</label>
          <div class="fw">
            <input id="label_click_to_add" name="labels[click_to_add]" value="<?php echo $model->label("click_to_add") ?>" type="text" class="text { tmpl: '<?php _e("Click to add {{singular_name}}", MASTERPRESS_DOMAIN) ?>' }" />
          </div>
        </div>
        <!-- /.f -->

        <div class="f f-allow-multiple">
          <label for="label_one_item"><?php _e("1 Item", MASTERPRESS_DOMAIN) ?>:</label>
          <div class="fw">
            <input id="label_one_item" name="labels[one_item]" value="<?php echo $model->label("one_item") ?>" type="text" class="text { tmpl: '<?php _e("1 {{singular_name}}", MASTERPRESS_DOMAIN) ?>' }" />
          </div>
        </div>
        <!-- /.f -->

        <div class="f f-allow-multiple">
          <label for="label_n_items"><?php _e("n Items", MASTERPRESS_DOMAIN) ?>:</label>
          <div class="fw">
            <input id="label_n_items" name="labels[n_items]" value="<?php echo $model->label("n_items") ?>" type="text" class="text { tmpl: '<?php _e("%d {{plural_name}}", MASTERPRESS_DOMAIN) ?>' }" />
          </div>
        </div>
        <!-- /.f -->
        
        <div class="f f-allow-multiple">
          <label for="label_no_items"><?php _e("No Items", MASTERPRESS_DOMAIN) ?>:</label>
          <div class="fw">
            <input id="label_no_items" name="labels[no_items]" value="<?php echo $model->label("no_items") ?>" type="text" class="text { tmpl: '<?php _e("No {{plural_name}}", MASTERPRESS_DOMAIN) ?>' }" />
          </div>
        </div>
        <!-- /.f -->

      </div>
      </div>
      </div>

    </div>
    <!-- /.fs -->



    <div class="fs fs-capability-keys clearfix">
    
      <div class="fst">
      <div class="fstb">
        <h3><i class="key"></i><strong><?php _e("Capabilities", MASTERPRESS_DOMAIN) ?></strong> - <?php _e('the keys used to control access to this field set', MASTERPRESS_DOMAIN) ?></h3>
      </div>
      </div>
    
      <div class="fsc">
      <div class="fscb clearfix">
      
        <div class="f f-capabilities f-capabilities-editable clearfix">
          <label for="label-capabilities-editable"><?php _e("Editable", MASTERPRESS_DOMAIN) ?>:</label>
          <div class="fw">
            
            <?php 
            
              $val = $model->capability("editable", false);
              
              $caps = array_unique(array_merge($keys, array("edit_posts", "edit_pages")));
              
              $caps = array( __("-- None (Always Editable) --", MASTERPRESS_DOMAIN) => "" ) + $caps;
              
              if (MPC::is_edit()) {
                $caps[] = "edit_".$prefix.$model->name;
              }

              $custom_val = "";
              
              if (!in_array($val, $caps)) {
                $custom_val = $val;
              } 

              echo WOOF_HTML::select( array("id" => "capabilities-editable", "name" => "capabilities[editable]", "class" => "capabilities" ), 
                $caps,
                $val
              );
      
            ?>
            
            <label for="capabilities-editable-custom" class="capabilities-custom"><?php _e("OR custom value") ?></label>
            <input id="capabilities-editable-custom" name="capabilities_custom[editable]" value="<?php echo $custom_val ?>" type="text" class="text mono capabilities-custom" />
            
            <p class="note">
              <?php _e("All fields in this set will be read-only for users without this capability.<br />Individual fields may override this with their own capabilities.", MASTERPRESS_DOMAIN) ?>
            </p>
          </div>
        </div>
        <!-- /.f -->
        
        <div class="f f-capabilities f-capabilities-visible clearfix">
          <label for="label-capabilities-visible"><?php _e("Visible", MASTERPRESS_DOMAIN) ?>:</label>
          <div class="fw">
            
            <?php 
            
              $val = $model->capability("visible", false);
              
              $caps = array_unique(array_merge($keys, array("edit_posts", "edit_pages")));

              $caps = array( __("-- None (Always Visible) --", MASTERPRESS_DOMAIN) => "" ) + $caps;
              
              if (MPC::is_edit()) {
                $caps[] = "view_".$prefix.$model->name;
              }

              $custom_val = "";
              
              if (!in_array($val, $caps)) {
                $custom_val = $val;
              } 

              echo WOOF_HTML::select( array("id" => "capabilities-visible", "name" => "capabilities[visible]", "class" => "capabilities" ), 
                $caps,
                $val
              );
      
            ?>
            
            <label for="capabilities-visible-custom" class="capabilities-custom"><?php _e("OR custom value") ?></label>
            <input id="capabilities-visible-custom" name="capabilities_custom[visible]" value="<?php echo $custom_val ?>" type="text" class="text mono capabilities-custom" />
            
            <p class="note">
              <?php _e("This field set will be invisible for users without this capability", MASTERPRESS_DOMAIN) ?>
            </p>
          </div>
        </div>
        <!-- /.f -->

        
        
        
        
      </div>
      </div>

    </div>
    <!-- /.fs -->
    

    <?php
    
    
    $args = array();

    $args["supports"] = array();
    
    if (is_multisite() && MASTERPRESS_MULTISITE_SHARING) {
      $args["supports"] = array("multisite");
    }
  
    if ($model->is_shared()) {
      $args["supports"][] = "post_types";
    }
    
    if (!isset($info->is_template_set) && $model->is_shared() ) {
      $args["supports"][] = "templates";
    }
    
    if (!isset($info->is_role_set) && $model->is_shared() ) {
      $args["supports"][] = "roles";
    }

    if (!isset($info->is_taxonomy_set) && $model->is_shared() ) {
      $args["supports"][] = "taxonomies";
    }

    $args["labels"] = array(
      "title" =>  __("control the visibility of this field set within WordPress", MASTERPRESS_DOMAIN),   
      "title_multisite" =>  __("specify the sites in the multisite network that this field set is available in", MASTERPRESS_DOMAIN),   
      "title_post_types" =>  __("specify the post types that this field set is available in", MASTERPRESS_DOMAIN),   
      "title_templates" => __("specify the templates that this field set is available in", MASTERPRESS_DOMAIN),   
      "title_roles" => __("specify the roles that users must have for this field set to be available in their profile edit screen", MASTERPRESS_DOMAIN),   
      "multisite_all" => __( "All Sites" ),
      "post_types_all" => __( "All Post Types" ),
      "templates_all" => __( "All Templates" )
      
    );

    $args["defaults"] = array(
      "post_types" => "all"
    );

  
    if ($model->type == "p") {
      
      $post_type = $parent;
      
      $templates = $post_type->templates();
      
      if (count($templates)) {
        $args["supports"][] = "templates";
        $args["templates"] = array();
        
        $all = array_flip(get_page_templates());
        
        foreach ($templates as $t) {
          $name = $all[$t->id];
          $args["templates"][$name] = $t->id;
        }
      
      }
      
      
    }
    
    if (isset($parent) && is_multisite()) {
      
      $site_options = array();
      
      foreach ($parent->sites() as $site) {
        $site_options[$site->full_path()] = $site->id();
      }
      
      $args["sites"] = $site_options;
      
    };
        
    MPV::fs_visibility( $model, $args ); 
    
    ?>
    
    <?php if ($info->is_template_set) : ?>
    <input id="visibility-templates" name="visibility[templates]" type="hidden" value="<?php echo $file ?>" />   
    <?php endif; ?>

    <?php if ($info->is_role_set) : ?>
    <input id="visibility-roles" name="visibility[roles]" type="hidden" value="<?php echo $role_name ?>" />   
    <?php endif; ?>

    <?php if ($info->is_taxonomy_set) : ?>
    <input id="visibility-taxonomies" name="visibility[taxonomies]" type="hidden" value="<?php echo $tax->name ?>" />   
    <?php endif; ?>

    <?php if ($model->is_post_type() && isset($parent)) : ?>
    <input id="visibility-post-types" name="visibility[post_types]" type="hidden" value="<?php echo $parent->name ?>" />   
    <?php endif; ?>
    
    
    
    
    <div id="f-position" class="f clearfix">
      <label for="position" class="icon"><i class="sort"></i><?php _e("Set Position", MASTERPRESS_DOMAIN)?>:</label>
      <div class="fw">

          <div class="sortable-list sortable-list-fields">
            <span class="arrow"></span>
            
            <?php
            
            // build a field list
            
            $field_sets = array();
            
            if ($model->shared) {
              $field_sets = MPM_SharedFieldSet::find( array( "orderby" => "position ASC" ) );
            } else if ($model->template) {
              $field_sets = MPM_TemplateFieldSet::find_by_template( MasterPress::$parent );
            } else if ($model->role) {
              $field_sets = MPM_RoleFieldSet::find_by_role( MasterPress::$parent );
            } else if ($model->taxonomy) {
              $field_sets = MPM_TaxonomyFieldSet::find_by_taxonomy( $tax );
            } else if ($model->site) {
              $field_sets = MPM_SiteFieldSet::find( array( "orderby" => "position ASC" ) );
            } else {
              $sql = "SELECT * FROM ".MPU::table("field-sets")." WHERE ( type = 'p' ) AND ".MPM::visibility_rlike("post_types", $parent->name)." ORDER BY position";
              $field_sets = MPM::get_models("field-set", $sql);
            }
            
            $sort_field_sets = array();
            
            // now build a representable list of field_sets
            
            $icon = $model->shared ? MPU::img_url("icon-shared-field-set.png") : MPU::img_url("icon-field-set-small.png");
            
            $icon_class = $model->shared ? "metabox-share" : "metabox";
            
            foreach ($field_sets as $field_set) {
              
              $position = $field_set->position;
            
              if (isset($_POST["other_position"]) && $_POST["other_position"][$field_set->id]) {
                $position = $_POST["other_position"][$field_set->id];
              }

              $sort_field_sets[] = array( "position" => $position, "disabled" => $field_set->disabled, "current" => $field_set->id == $model->id, "label" => $field_set->display_label(), "icon_class" => $icon_class, "icon" => $icon, "id" => $field_set->id );
            }

            
            if (MPC::is_create()) {
              $label = $model->display_label();
              
              if (!$label || $label == "") {
                $label = "?";
              }
              
              $sort_field_sets[] = array( "position" => $model->position, "disabled" => $model->disabled, "current" => true, "label" => $model->display_label(), "icon" => $icon, "icon_class" => $icon_class );
            }
            
            $count = 0;
            
            ?>
            
            <ul>
              <?php foreach ($sort_field_sets as $f) : $count++; $first = $count == 1 ? "first " : ""; $current = $f["current"] ? 'current ' : '';  ?>

              <?php
                $disabled = $f["disabled"] ? 'disabled' : '';
                $disabled_title = $f["disabled"] ? __("This field set is disabled", MASTERPRESS_DOMAIN) : '';
              ?>

              <li class="<?php echo $first.$current ?> <?php echo $disabled ?>" title="<?php echo $disabled_title ?>">
                <i class="<?php echo $icon_class ?>"></i>
                <?php if ($f["current"]) : ?>
                <span class="inline fill { src: '#label_name,#label_singular_name'}"><?php echo $f["label"] ?></span>
                <input id="position" name="position" value="<?php echo $f["position"] ?>" type="hidden" class="text" />
                <?php else: ?>
                <span class="inline"><?php echo $f["label"] ?></span>
                <input id="other_position" name="other_position[<?php echo $f["id"] ?>]" value="<?php echo $f["position"] ?>" type="hidden" />
                <?php endif; ?>
              </li>
              <?php endforeach; ?>
            </ul>
            
          </div>
          <!-- /.sortable-list -->
          
        <p>
          <?php _e("Drag set to the desired <em>default</em> position in the WordPress <em>Create / Edit Post</em> screen.<br />Note: Field sets are displayed in a standard WordPress UI panel (metabox), which can be dragged around by the user to also influence the order.", MASTERPRESS_DOMAIN) ?>
        </p>
      </div>
    </div>
    <!-- /.f -->
    
    
    
    </div>
    <!-- /.mpv-field-sets-form -->

    <?php
    
  }
示例#21
0
  public static function options_form( $options ) {

    $defaults = array();

    if (MPC::is_create()) {
      $defaults = array("maxlength" => 400 , "width" => 400, "height" => 160);
    }

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


    $p = self::type_prefix(__CLASS__);

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

    $values_label = __("Choices:", MASTERPRESS_DOMAIN);
    $values_note = __('Specify the labels for each choice on separate lines. To use a different underlying <span class="tt">value</span> for any of the choices,<br /> use the form <strong><span class="tt">label = value</span></strong>.', MASTERPRESS_DOMAIN);

    $default_value_label = __("Default State:", MASTERPRESS_DOMAIN);
    $default_value_note = __("Use the preview of your control above to setup the default state", MASTERPRESS_DOMAIN);

    $default_value = self::option_value($options, "default_value");
    $allow_uncheck = self::option_value($options, "allow_uncheck");
    $values = self::option_value($options, "values");

    $allow_uncheck_label = __("Allow Uncheck?:", MASTERPRESS_DOMAIN);
    $allow_uncheck_checked_attr = WOOF_HTML::checked_attr($allow_uncheck == "yes");
    $allow_uncheck_note = __("Include a button to uncheck all radio buttons in the set", MASTERPRESS_DOMAIN);

    $select_none_label = __("Select None", MASTERPRESS_DOMAIN);


    $option_values = WOOF_HTML::option_values($values);

    $default_value_radio_buttons = WOOF_HTML::input_radio_group( "type_options[default_value]", $p."default-value-", $option_values, $default_value, WOOF_HTML::open("div", "class=fwi"), WOOF_HTML::close("div")); 


$html = <<<HTML

    <div class="f">
      <label for="{$p}values">{$values_label}</label>
      <div id="fw-{$p}values" class="fw">
        <textarea id="{$p}values" class="mono" name="type_options[values]">{$values}</textarea>
        <p class="note">{$values_note}</p>
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}allow-unselect">{$allow_uncheck_label}</label>
      <div id="fw-{$p}allow-unselect" class="fw">
        <input id="{$p}allow-unselect" name="type_options[allow_uncheck]" type="checkbox" {$allow_uncheck_checked_attr} value="yes" class="checkbox" />
        <span class="note checkbox-alt-label">{$allow_uncheck_note}</span>
      </div>
    </div>
    <!-- /.f -->

    <div id="{$p}default-value-f" class="f">
      <label for="{$p}default-value">{$default_value_label}</label>
      <div id="fw-{$p}default-value" class="fw">
        <div class="preview">{$default_value_radio_buttons}</div>
        <div id="{$p}default-value-controls" class="controls divider">
          <button type="button" class="button uncheck-all">{$select_none_label}</button>
        </div>
        <!-- /.controls -->
        <p class="note">{$default_value_note}</p>
      </div>
    </div>
    <!-- /.f -->    

HTML;

    return $html;

  }
示例#22
0
  public static function options_form( $options ) {

    $defaults = array();

    if (MPC::is_create()) {
      $defaults = array(
          "buttons" => "select_all,select_none",
          "width" => 400, 
          "height" => 160,
          "allow_multiple" => "yes" 
      ); 
    }

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

    $p = self::type_prefix(__CLASS__);


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

    $maxwidth_label = __("Maximum Width:", MASTERPRESS_DOMAIN);
    $height_label = __("Height:", MASTERPRESS_DOMAIN);

    $height_note = __("(pixels)", MASTERPRESS_DOMAIN);
    $maxwidth_note = __("(pixels)", MASTERPRESS_DOMAIN);


    $maxwidth = self::option_value($options, "maxwidth");
    $values = self::option_value($options, "values");
    $default_value = self::option_value($options, "default_value");
    $buttons = self::option_value($options, "buttons");
    $height = self::option_value($options, "height");

    $allow_multiple_label = __("Multiple Selections?:", MASTERPRESS_DOMAIN);
    $allow_multiple_checked_attr = WOOF_HTML::checked_attr( $options["allow_multiple"] == "yes" );

    $values_label = __("Choices:", MASTERPRESS_DOMAIN);
    $values_note = __('Specify the labels for each choice on separate lines. To use a different underlying <span class="tt">value</span> for any of the choices,<br /> use the form <strong><span class="tt">label = value</span></strong>. To create a group of choices, prefix the line you wish to use as a group label with <span class="tt">--</span> (group labels are not selectable)', MASTERPRESS_DOMAIN);

    $default_value_label = __("Default State:", MASTERPRESS_DOMAIN);
    $default_value_note = __("Use the preview of your control above to setup the default state", MASTERPRESS_DOMAIN);


    $buttons_label = __("Selection Buttons:", MASTERPRESS_DOMAIN);
    $buttons_checkboxes = WOOF_HTML::input_checkbox_group( "type_options[buttons][]", $p."buttons-", array("Select All" => "select_all", "Select None" => "select_none"), $buttons, WOOF_HTML::open("div", "class=fwi"), WOOF_HTML::close("div")); 


    $default_value_attr = array( "id" => $p."default-value", "name" => "type_options[default_value][]" );

    if ($options["allow_multiple"] == "yes") {
      $default_value_attr["multiple"] = "multiple";
    } else {
      $default_value_attr["size"] = 2;
    }


    $default_value_select = WOOF_HTML::select( 
      $default_value_attr,
      WOOF_HTML::option_values($values, "", true),
      $default_value
    );

    $html = <<<HTML

    <div class="f">
      <label for="{$p}values">{$values_label}</label>
      <div id="fw-{$p}values" class="fw">
        <textarea id="{$p}values" class="mono" name="type_options[values]">{$values}</textarea>
        <p class="note">{$values_note}</p>
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}maxwidth">{$maxwidth_label}</label>
      <div id="fw-{$p}maxwidth" class="fw">
        <input id="{$p}maxwidth" type="text" name="type_options[maxwidth]" maxlength="4" value="{$maxwidth}" class="text" /><span class="note">{$maxwidth_note}</span>
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}height">{$height_label}</label>
      <div id="fw-{$p}height" class="fw">
        <input id="{$p}height" type="text" name="type_options[height]" value="{$height}" class="text" /><span class="note">{$height_note}</span>
      </div>
    </div>
    <!-- /.f -->

    <div class="f">
      <label for="{$p}allow-multiple">{$allow_multiple_label}</label>
      <div id="fw-{$p}allow-multiple" class="fw">
        <input id="{$p}allow-multiple" name="type_options[allow_multiple]" type="checkbox" {$allow_multiple_checked_attr} value="yes" class="checkbox" />
      </div>
    </div>
    <!-- /.f -->


    <div id="{$p}default-value-f" class="f">
      <label for="{$p}default-value">{$default_value_label}</label>
      <div id="fw-{$p}default-value" class="fw">

        <div class="preview">
          {$default_value_select}
          <div id="{$p}default-value-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 -->
        </div>

        <p class="note">{$default_value_note}</p>

      </div>
    </div>
    <!-- /.f -->

HTML;

    return $html;

  }