public function grid() { MPC::incl("post-types"); MPV::incl("fields"); MPV::incl("post-types"); $info = MasterPress::$view; ?> <?php MPV::messages(); ?> <div class="grid-set"> <?php $field_sets = MPM_SharedFieldSet::find( array("orderby" => "name ASC" ) ); ?> <?php MPV::field_set_icon_styles($field_sets); ?> <?php $has_actions = MasterPress::current_user_can("edit_shared_field_sets,delete_shared_field_sets,edit_shared_fields,delete_shared_fields"); $can_edit = MasterPress::current_user_can("edit_shared_field_sets"); $can_delete = MasterPress::current_user_can("delete_shared_field_sets"); $can_create = MasterPress::current_user_can("create_shared_field_sets"); $can_edit_fields = MasterPress::current_user_can("edit_shared_fields"); $can_delete_fields = MasterPress::current_user_can("delete_shared_fields"); $can_create_fields = MasterPress::current_user_can("create_shared_fields"); $less = ($can_create_fields) ? 1 : 0; $colspan = ( $has_actions ? 7 : 6 ) - $less; foreach ($field_sets as $field_set) { if (MPC::is_deleting($field_set->id, "delete")) { $this->confirm_delete($field_set); } else { foreach ($field_set->fields() as $field) { if (MPC::is_deleting($field->id, "delete-field")) { $this->confirm_delete_field($field); } } } } ?> <?php if (count($field_sets)) : ?> <table cellspacing="0" class="grid grid-field-sets grid-shared-field-sets"> <thead> <tr> <th class="first type"><i class="types"></i><span><?php _e("Type", MASTERPRESS_DOMAIN) ?></span></th> <th class="label"><i class="label-string"></i><span><?php _e("Label", MASTERPRESS_DOMAIN) ?></span></th> <th class="front-end-name"><i class="script-php"></i><span><?php _e("Front End Name", MASTERPRESS_DOMAIN) ?></span></th> <th class="post-types"><i class="pins"></i><span><?php _e("Post Types", MASTERPRESS_DOMAIN) ?></span></th> <th class="taxonomies"><i class="tags"></i><span><?php _e("Taxonomies", MASTERPRESS_DOMAIN) ?></span></th> <th class="roles <?php echo $has_actions ? "" : "last" ?>"><i class="user-role"></i><span><?php _e("User Roles", MASTERPRESS_DOMAIN) ?></span></th> <?php if ($has_actions) : ?> <th class="actions last"><i class="buttons"></i><span><?php _e("Actions", MASTERPRESS_DOMAIN) ?></span></th> <?php endif; ?> </tr> </thead> <tbody> <?php $fg_count = 0; ?> <?php foreach ($field_sets as $field_set) : $fg_count++; ?> <?php $display = $field_set->display_label(); ?> <?php $display_td = $display; if ($field_set->icon != "") { $display_td = WOOF_HTML::tag("span", array("class" => "with-icon field-set-".$field_set->id), $display); } ?> <?php $deleting_class = MPC::is_deleting($field_set->id, "delete") ? 'deleting' : ''; $editable_class = $can_edit ? " editable " : ""; $meta = $can_edit ? "{ href: '".MasterPress::admin_url("shared-field-sets", "edit", array("id" => $field_set->id) )."' }" : ""; ?> <?php $disabled = $field_set->disabled ? "disabled" : ""; $title = $field_set->disabled ? ' title="'.__("this field set is disabled", MASTERPRESS_DOMAIN).'" ' : ""; ?> <?php if (!$field_set->in_current_site()) { $disabled = "disabled"; $title = ' title="'.__("field set is not currently available in this site (multi-site setting)", MASTERPRESS_DOMAIN).'" '; } ?> <tr id="field_set_<?php echo $field_set->name ?>" <?php echo $title ?> class="<?php echo $disabled ?> <?php echo $editable_class ?> <?php echo $deleting_class ?> <?php echo MPV::updated_class("edit,create", $field_set->id) ?> <?php echo $meta ?>"> <?php if ($field_set->allow_multiple) : ?> <th class="first type icon"><i class="metabox-add-remove-large" title="<?php _e("Field Set (Multiple Items)", MASTERPRESS_DOMAIN) ?>"></i></th> <?php else : ?> <th class="first type icon"><i class="metabox-large" title="<?php _e("Field Set", MASTERPRESS_DOMAIN) ?>"></i></th> <?php endif; ?> <th class="label"><strong><?php echo $display_td ?></strong></th> <th class="front-end-name"><span class="tt"><?php echo $field_set->display_name() ?></span></th> <th class="post-types"> <?php $post_types = $field_set->post_types(); $vis = $field_set->visibility; $vis_post_types = ""; if (isset($vis["post_types"])) { $vis_post_types = $vis["post_types"]; } if ($vis_post_types == "*") { $post_type_display = __("( All )", MASTERPRESS_DOMAIN); } else { $post_type_display = __("( None )", MASTERPRESS_DOMAIN); if (count($post_types)) { $post_type_links = array(); foreach ($post_types as $post_type) { $post_type_links[] = $post_type->labels["name"]; } $post_type_display = implode($post_type_links, ", "); } } echo $post_type_display; ?> </th> <th class="taxonomies"> <?php $vis = $field_set->visibility; $vis_tax = ""; if (isset($vis["taxonomies"])) { $vis_tax = $vis["taxonomies"]; } if ($vis_tax == "*") { $taxonomy_display = __("( All )", MASTERPRESS_DOMAIN); } else { $taxonomy_display = __("( None )", MASTERPRESS_DOMAIN); if ($vis_tax != "") { $tax_models = MPM_Taxonomy::find_by_name_in(explode(",", $vis_tax)); $td = array(); foreach ($tax_models as $tax) { $td[] = $tax->display_label(); } $taxonomy_display = implode(", ", $td); } } echo $taxonomy_display; ?> </th> <th class="roles <?php echo $has_actions ? "" : "last" ?>"> <?php $vis = $field_set->visibility; $vis_roles = ""; if (isset($vis["roles"])) { $vis_roles = $vis["roles"]; } if ($vis_roles == "*") { $role_display = __("( All )", MASTERPRESS_DOMAIN); } else { if (is_null($vis_roles) || $vis_roles == "") { $role_display = __("( None )", MASTERPRESS_DOMAIN); } else { $role_display = implode(", ", explode(",", $vis_roles)); } } echo $role_display; ?> </th> <?php if ($has_actions) : ?> <th class="actions last"> <?php if (MPC::is_deleting($field_set->id, "delete")) : ?> <span class="confirm-action"> </span> <?php else: ?> <div> <?php if ($can_edit) : ?> <?php echo MPV::action_button("shared-field-sets", "edit", self::__edit(), array("id" => $field_set->id), array("class" => "button button-edit") ); ?> <?php endif; ?> <?php if ($can_delete) : ?> <?php echo MPV::action_button("shared-field-sets", "delete", self::__delete(), array("id" => $field_set->id), array("class" => "button button-delete") ); ?> <?php endif; ?> </div> <?php endif; ?> </th> <?php endif; // has_actions ?> </tr> <?php $count = 0; $fields = $field_set->fields(); ?> <?php foreach ($fields as $field) : $count++; $first = $count == 1 ? 'first' : ''; $disabled = $field_set->disabled || $field->disabled ? "disabled" : ""; $title = $field_set->disabled || $field->disabled ? ' title="'.__("this field is disabled", MASTERPRESS_DOMAIN).'" ' : ""; ?> <?php if (!$field_set->in_current_site() || !$field->in_current_site()) { $disabled = "disabled"; $title = ' title="'.__("field is not currently available in this site (multi-site setting)", MASTERPRESS_DOMAIN).'" '; } ?> <?php $deleting_class = MPC::is_deleting($field_set->id, "delete") || MPC::is_deleting($field->id, "delete-field") ? 'deleting' : ''; $editable_class = $can_edit_fields ? " editable " : ""; $meta = $can_edit ? "{ href: '".MasterPress::admin_url("shared-field-sets", "edit-field", array("id" => $field->id, "parent" => $field_set->id) )."' }" : ""; ?> <?php if ($type_class = MPFT::type_class($field->type)) : ?> <tr <?php echo $title ?> class="sub <?php echo $editable_class.$deleting_class ?> <?php echo $first ?> <?php echo $disabled ?> <?php echo $count % 2 == 0 ? "even" : "" ?> <?php echo MPV::updated_class("edit-field,create-field", $field->id) ?> <?php echo $meta ?>"> <td class="type icon first" title="<?php echo call_user_func( array($type_class, "__s") ) ?>"><span class="mp-icon mp-icon-field-type-<?php echo $field->type ?>"></span></td> <td class="label"><strong><?php echo $field->display_label() ?></strong></td> <td class="front-end-name"><span class="tt"><span class="arrow">-> </span><?php echo $field->display_name() ?></span></td> <td class="post-types"> <?php $vis = $field->visibility; $vis_post_types = ""; if (isset($vis["post_types"])) { $vis_post_types = $vis["post_types"]; } if ($vis_post_types == "*") { $post_type_display = '<span class="inherit">( '.__("same as set", MASTERPRESS_DOMAIN).' )</span>'; } else { $post_types = $field->post_types(); $post_type_display = MPV::note_none(); if (count($post_types)) { $post_type_links = array(); foreach ($post_types as $post_type) { $post_type_links[] = $post_type->labels["name"]; } $post_type_display = implode($post_type_links, ", "); } } echo $post_type_display; ?> </td> <td class="taxonomies"> <?php $vis = $field->visibility; $vis_tax = ""; if (isset($vis["taxonomies"])) { $vis_tax = $vis["taxonomies"]; } if ($vis_tax == "*") { $tax_display = '<span class="inherit">( '.__("same as set", MASTERPRESS_DOMAIN).' )</span>'; } else { $tax_display = MPV::note_none(); if ($vis_tax != "") { $tax_models = MPM_Taxonomy::find_by_name_in(explode(",", $vis_taxonomies)); $td = array(); foreach ($tax_models as $tax) { $td[] = $tax->display_label(); } $tax_display = implode(", ", $td); } } echo $tax_display; ?> </td> <td class="roles <?php echo $has_actions ? "" : "last" ?>"> <?php $vis = $field->visibility; $vis_roles = ""; if (isset($vis["roles"])) { $vis_roles = $vis["roles"]; } if ($vis_roles == "*") { $role_display = '<span class="inherit">( '.__("same as set", MASTERPRESS_DOMAIN).' )</span>'; } else { $role_display = MPV::note_none(); if ($vis_roles != "") { $role_display = implode(", ", explode(",", $vis_roles)); } } echo $role_display; ?> </td> <?php if ($has_actions) : ?> <td class="actions last"> <?php if (MPC::is_deleting($field->id, "delete-field")) : ?> <span class="confirm-action"> </span> <?php else: ?> <div> <?php if ($can_edit_fields) : ?> <?php echo MPV::action_button("shared-field-sets", "edit-field", self::__edit(), array("id" => $field->id, "parent" => $field_set->id), array("class" => "button button-edit") ); ?> <?php endif; ?> <?php if ($can_delete_fields) : ?> <?php echo MPV::action_button("shared-field-sets", "delete-field", self::__delete(), array("id" => $field->id, "parent" => $field_set->id), array("class" => "button button-delete") ); ?> <?php endif; ?> </div> <?php endif; ?> </td> <?php endif; // has_actions ?> </tr> <?php endif; ?> <?php endforeach; ?> <tr class="summary <?php echo $can_create_fields ? "editable" : "" ?>"> <?php if (count($fields)) : ?> <td colspan="<?php echo $colspan ?>" class="first <?php echo $can_create_fields ? "" : "last" ?>"><?php printf( __( "%s contains %s", MASTERPRESS_DOMAIN ), $display, MPU::__items( $field_set->field_count(), __("%d custom field", MASTERPRESS_DOMAIN), __("%d custom fields", MASTERPRESS_DOMAIN) ) ) ?></td> <?php else: ?> <?php if ($can_create_fields) : ?> <td colspan="<?php echo $colspan ?>" class="hl first last"><span><?php printf( __( "<strong>%s</strong> is not yet active as it contains <em>no custom fields</em>. Click here to create one", MASTERPRESS_DOMAIN ), $display ); ?></span></td> <?php endif; ?> <?php endif; ?> <?php if ($can_create_fields) : ?> <td class="last actions <?php echo count($fields) ? "" : "hl" ?>"> <?php echo MPV::action_button("shared-field-sets", "create-field", self::__create(MPV_Fields::__s()), array("parent" => $field_set->id), array("class" => "button create-field") ); ?> </td> <?php endif; ?> </tr> <tr class="gap <?php if ($fg_count == count($field_sets)) { echo "gap-last"; } ?>"> <td colspan="7"> </td> </tr> <?php endforeach; ?> </tbody> </table> <?php if ($can_create) : ?> <div class="grid-foot-controls"> <?php echo MPV::action_button("shared-field-sets", "create", MPV::__create( MPV_SharedFieldSets::__s() ), array() ); ?> </div> <?php endif; ?> <?php else: ?> <?php if ($can_create) : ?> <a href="<?php echo MasterPress::admin_url("shared-field-sets", "create") ?>" class="no-items-create"> <i class="plus-circle"></i> <span><?php _e( "There are currently no Shared Field Sets. Click here to create one." ) ?></span> </a> <?php endif; ?> <?php endif; ?> </div> <?php } // end grid()
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; }