public static function field_set_icon_styles($field_sets) { ?> <style type="text/css"> <?php foreach ($field_sets as $field_set) : ?> <?php if ($field_set->icon != "") : ?> span.field-set-<?php echo $field_set->id ?> { background-image: url(<?php echo MPU::field_set_icon_url($field_set->icon) ?>) } <?php endif; ?> <?php endforeach; ?> <?php MPU::mq2x_start(); ?> <?php foreach ($field_sets as $field_set) : ?> <?php if ($field_set->icon != "") : ?> span.field-set-<?php echo $field_set->id ?> { background-image: url(<?php echo MPU::field_set_icon_2x_url($field_set->icon); ?>); background-size: 16px 16px; } <?php endif; ?> <?php endforeach; ?> <?php MPU::mq2x_end(); ?> </style> <?php }
public static function get_set($object, $set_items, $args = array("nested" => false)) { global $meow_provider, $wf; $data = array(); $set = $set_items->info; // check for versions $set_args = $args; if (WOOF::is_false_arg($args, "nested")) { $versions = $set_items->versions(); if (count($versions)) { $versions_options = array(); $count = 0; foreach ($versions as $version) { $count++; $prefix = ""; if ($count == 1) { $prefix .= __("Current", MASTERPRESS_DOMAIN); } else { $prefix = WOOF::items_number( $count - 1, __("Current", MASTERPRESS_DOMAIN), __("1 version ago", MASTERPRESS_DOMAIN), __("%d versions ago", MASTERPRESS_DOMAIN) ); } $text = $prefix." — ".$wf->format_date("[date-time-long]", strtotime(get_date_from_gmt($version->date))); if (!is_null($version->user_login)) { $text = $text." — ".$version->user_login; } if ($set->allow_multiple) { $text = $text." ( ".WOOF::items_number($version->field_set_count, __("no items", MASTERPRESS_DOMAIN), __("1 item", MASTERPRESS_DOMAIN), __("%d items", MASTERPRESS_DOMAIN))." )"; } $versions_options[$text] = $version->version_id; } $selected_version = ""; if (count($versions_options) > 1) { $vvals = array_values($versions_options); $selected_version = $vvals[1]; } $data["versions_select_id"] = "versions-".$set->id; if ($set->current_user_can_edit()) { $data["versions_select"] = WOOF_HTML::select( array("id" => $data["versions_select_id"]), $versions_options, $selected_version ); $data["versions_title"] = sprintf( __("Versions of '%s'", MASTERPRESS_DOMAIN), $set->display_label() ); $set_args["versions_select"] = $data["versions_select"]; } } } $set_classes = array(); if ($set->allow_multiple) { $set_classes[] = "multiple"; } else { $set_classes[] = "single"; } $data["allow_remove"] = true; $data["set_allow_add"] = true; $data["copy_paste_title"] = __("Copy / Paste Content", MASTERPRESS_DOMAIN); if (!$set->current_user_can_edit()) { $data["copy_paste_title"] = __("Copy Content", MASTERPRESS_DOMAIN); $data["readonly"] = true; $data["allow_remove"] = false; $data["set_allow_add"] = false; $set_classes[] = "readonly"; } $set_head_classes = array(); $add_item_title = strip_tags($set->label("add_another")); if ($set_items->count() == 0) { $set_head_classes[] = "hidden"; $add_item_title = strip_tags($set->label("click_to_add")); } else { $data["set_foot_controls_style"] = "display: none;"; } $type_key = $meow_provider->type_key($object); $set_description = trim( $set->label("description") ); if ($set_description != "") { $data["set_description"] = trim( $set->label("description") ); } $set_type_description = $set->label("description_".$type_key); if (isset($set_type_description) && trim($set_type_description) != "") { $data["set_description"] = trim($set_type_description); } $data["set_head_classes"] = implode(" ", $set_head_classes); $data["set_classes"] = implode(" ", $set_classes); $data["set_id"] = $set->id; $data["set_name"] = $set->name; if (isset($args["guid"])) { $data["add_item_template"] = "mpft_ui_{$set->name}"."_".$args["guid"]; } $data["set_dirty_name"] = "mp_meta_dirty[{$set->name}]"; $data["set_versions_name"] = "mp_meta_versions[{$set->name}]"; $data["set_versions"] = $set->versions; $data["set_allow_multiple"] = $set->allow_multiple; $data["set_expanded"] = $set->expanded; $data["add_item_title"] = $add_item_title; $data["set_name_sanitized"] = str_replace("_", "-", $wf->sanitize($set->name)); if (!isset($set->icon) && $set->icon != "") { $data["set_icon"] = MPU::field_set_icon_url($set->icon); $data["set_icon_2x"] = MPU::field_set_icon_2x_url($set->icon); } $data["label_add_another"] = esc_js( strip_tags($set->label("add_another")) ); $data["label_one_item"] = esc_js( $set->label("one_item")); $data["label_n_items"] = esc_js($set->label("n_items")); $data["label_no_items"] = esc_js($set->label("no_items")); $data["label_click_to_add"] = esc_js($set->label("click_to_add")); $data["label_remove_confirm"] = strip_tags($set->label("remove")).": ".__("Are you sure?", MASTERPRESS_DOMAIN); $data["set_items_count"] = MPU::__items($set_items->count(), $set->label("one_item"), $set->label("n_items"), $set->label("no_items")); if ($type_key == "post") { $data["save_nag_message"] = sprintf( __('To Save changes you must also <strong>Save Draft</strong> or <strong class="update">Update</strong> this %s', MASTERPRESS_DOMAIN ), $object->post_type()->singular_label() ); } else if ($type_key == "term") { $data["save_nag_message"] = sprintf( __('To Save changes you must also <strong class="update">Update</strong> this %s', MASTERPRESS_DOMAIN ), $object->taxonomy()->singular_label()); } else if ($type_key == "user") { $data["save_nag_message"] = __('To Save changes you must also <strong class="update">Update</strong> this user', MASTERPRESS_DOMAIN); } if (isset($data["save_nag_message"])) { $data["save_nag_tooltip"] = strip_tags($data["save_nag_message"]); } // loop through the fields, and output their model ids, so that the save action picks them up $data["fields"] = array(); $data["field_icons"] = array(); foreach ($set->fields() as $field) : if ($field->current_user_can_see()) { $field_data = array(); $field_data["field_id"] = $field->id; $field_data["field_model_name"] = "mp_meta_model[{$set->name}][{$field->name}]"; if (!is_null($field->icon) && $field->icon != "") { $data["field_icons"][] = array("url_2x" => MPU::field_icon_2x_url($field->icon), "url" => MPU::field_icon_url($field->icon), "field_path" => $set->name."-".$field->name); } $field_data["field_path"] = $set->name."-".$field->name; if (isset($field->labels["tooltip_help"])) { $tooltip_help = stripslashes(trim($field->label("tooltip_help"))); if ($tooltip_help != "") { $field_data["tooltip_help"] = $tooltip_help; } } $data["fields"][] = $field_data; } endforeach; // need to add creator support here! if ($set->creator) { $set_item = new MEOW_FieldSetCreator($set->name, $object, $set); $template_data = self::set_item_template_data($set_item, $set_args); $data["set_items"] = WOOF::render_template( self::set_item_template(), $template_data, false ); } else { if ($set->allow_multiple) { $data["set_items"] = ""; foreach ($set_items as $set_item) { // grab the data for the set template $template_data = self::set_item_template_data($set_item, $set_args); $data["set_items"] .= WOOF::render_template( self::set_item_template(), $template_data, false ); } // update the set_items (if dirty) $set_items->update(); } else { $set_item = new MEOW_FieldSet($set->name, 1, $object, $set, $set_items); // grab the data for the set template $template_data = self::set_item_template_data($set_item, $set_args); $data["set_items"] = WOOF::render_template( self::set_item_template(), $template_data, false ); } } return WOOF::render_template( self::set_template(), $data, false ); }