Example #1
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;
  }
Example #2
0
  protected function export_rep($export) {
    global $wf;
    
    // create the associative array representation
    
    $rep = array(
      "created" => date("c"),
      "masterpress_version" => MasterPress::$version,
      "icons" => array()
    );
    
    $types = array();

    if (isset($export["post_types"])) {
      
      $rep["post_types"] = array();
      
      foreach (array_keys($export["post_types"]) as $post_type_name) {
        $post_type = MPM_PostType::find_by_name($post_type_name);
        
        $r = $post_type->rep();
        $rep["post_types"][] = $r;
        
        self::add_icon($rep["icons"], $r, "menu_icon");

        if (isset($r["field_sets"])) {
          
          foreach ($r["field_sets"] as $set) {
            self::add_icon($rep["icons"], $set);

            foreach ($set["fields"] as $field) {

              self::add_icon($rep["icons"], $field);
              $types[$field["type"]] = true;

            }
          }
        
        }
      
      }
      
    }    

    if (isset($export["taxonomies"])) {
      
      $rep["taxonomies"] = array();
      
      foreach (array_keys($export["taxonomies"]) as $tax_name) {
        $tax = MPM_Taxonomy::find_by_name($tax_name);
        $r = $tax->rep();
        $rep["taxonomies"][] = $r;

        self::add_icon($rep["icons"], $r, "title_icon");

        if (isset($r["field_sets"])) {
          foreach ($r["field_sets"] as $set) {
            self::add_icon($rep["icons"], $set);

            foreach ($set["fields"] as $field) {
              self::add_icon($rep["icons"], $field);
              $types[$field["type"]] = true;
            }
          }
        }
          
      }
      
    } 

    if (isset($export["shared_field_sets"])) {
      
      $rep["shared_field_sets"] = array();
      
      foreach (array_keys($export["shared_field_sets"]) as $id) {
        $set = MPM_FieldSet::find_by_id($id);
        $r = $set->rep();

        self::add_icon($rep["icons"], $r);

        $rep["shared_field_sets"][] = $r;
        
        if (isset($r["fields"])) {

          foreach ($r["fields"] as $field) {
            self::add_icon($rep["icons"], $field);
            $types[$field["type"]] = true;
          }
        
        }
      
      }
      
    } 

    if (isset($export["site_field_sets"])) {
      
      $rep["site_field_sets"] = array();
      
      foreach (array_keys($export["site_field_sets"]) as $id) {
        $set = MPM_FieldSet::find_by_id($id);
        $r = $set->rep();
        $rep["site_field_sets"][] = $r;

        self::add_icon($rep["icons"], $r);

        if (isset($r["fields"])) {

          foreach ($r["fields"] as $field) {
            self::add_icon($rep["icons"], $field);
            $types[$field["type"]] = true;
          }
        
        }
      
      }
      
    } 

    if (isset($export["templates"])) {
      
      $rep["templates"] = array();
      
      foreach (array_keys($export["templates"]) as $template) {

        $template = MPM_Template::find_by_id($template);
        
        $r = $template->rep();
        $rep["templates"][] = $r;

        if (isset($r["field_sets"])) {

          foreach ($r["field_sets"] as $set) {
            self::add_icon($rep["icons"], $set);

            foreach ($set["fields"] as $field) {
              self::add_icon($rep["icons"], $field);
              $types[$field["type"]] = true;
            }
          }

        }
      

      }
      
    } 
    
    
    if (isset($export["roles"])) {
      
      $rep["roles"] = array();
      
      foreach (array_keys($export["roles"]) as $role) {
        
        $wr = $wf->role($role);
        
        $rr = array("id" => $role, "name" => $wr->name, "capabilities" => $wr->capabilities, "field_sets" => array());

        foreach (MPM_RoleFieldSet::find_by_role($role, "id ASC") as $set) {
          $r = $set->rep();

          self::add_icon($rep["icons"], $r);
          
          if (isset($r["fields"])) {

            foreach ($r["fields"] as $field) {
              $types[$field["type"]] = true;
              self::add_icon($rep["icons"], $field);
            }
          
          }
        
          $rr["field_sets"][] = $r;

        }
        
        $rep["roles"][] = $rr;

      }
      
    } 
    
    $rep["field_types"] = array_keys($types);
    
    return $rep;
    
  }
Example #3
0
  public function grid($id = null) {

    MPV::incl("field-sets");
    MPV::incl("fields");
    MPV::incl("taxonomies");
    MPC::incl("taxonomies");
    

    $has_actions = MasterPress::current_user_can("edit_templates,delete_templates,manage_template_field_sets");
    $can_edit = MasterPress::current_user_can("edit_templates");
    $can_delete = MasterPress::current_user_can("delete_templates");
    $can_create = MasterPress::current_user_can("create_templates");
    $can_manage_field_sets = MasterPress::current_user_can("manage_template_field_sets");

    $colspan = $has_actions ? 8 : 7;

    
  ?>


  <?php MPV::messages(); ?>
  
  <table cellspacing="0" class="grid grid-post-types">
    <thead>
    <tr>
      <th class="first file-name front-end-name"><i class="script-php"></i><span><?php _e("File Name", MASTERPRESS_DOMAIN) ?></span></th>
      <th class="name"><i class="template"></i><span><?php _e("Template Name", MASTERPRESS_DOMAIN) ?></span></th>
      <th class="field-sets"><i class="metaboxes"></i><span><?php _e("Field Sets", MASTERPRESS_DOMAIN) ?></span></th>
      <th class="post-types <?php echo $has_actions ? "" : "last" ?>"><i class="pins"></i><span><?php _e("Post Types", 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 $count = 0; $disabled = ""; ?>
    
    <?php $templates = get_page_templates();  ?>
    
    <?php foreach ($templates as $template => $file) : $count++; $first = $count == 1 ? 'first' : ''; $model = MPM_Template::find_by_id($file);
    
    
    $editable_class = $can_edit ? " editable " : "";
    $meta = $can_edit ? "{ href: '".MasterPress::admin_url("templates", "edit", "id=".$file)."' }" : "";


    ?>
    
    <tr class="<?php echo $first ?> <?php echo $editable_class.$disabled ?> <?php echo MPV::updated_class("edit,create", $file) ?> <?php echo $count % 2 == 0 ? "even" : "" ?> sub <?php echo $meta ?>">
      <td class="first file-name"><strong><span class="tt"><?php echo $file ?></span></strong></td>
      <td class="name"><?php echo $template ?></td>
      <td class="field-sets <?php echo $can_manage_field_sets ? "manage" : "" ?>">
        <?php if ($can_manage_field_sets) : ?>
        <a href="<?php echo MasterPress::admin_url( "templates", "manage-field-sets", "parent=".$file)?>">
		<i class="go"></i>
        <?php endif; ?>
        
        <?php 
        
        $field_sets = MPM_TemplateFieldSet::find_by_template( $file ); 

        $field_set_display = MPV::note_none();
        
        if (count($field_sets)) {
          $field_set_links = array();
          
          foreach ($field_sets as $field_set) {
            if (!$field_set->is_shared()) {
              $field_set_links[] =  $field_set->display_label();
            }
          }

          if (count($field_set_links)) {
            $field_set_display = implode($field_set_links, ", ");
          }
        
        }
        
        echo $field_set_display;
        ?>
        <?php if ($can_manage_field_sets) : ?>
        </a>
        <?php endif; ?>

      </td>
      
      <td class="post-types <?php echo $has_actions ? "" : "last" ?>">
        
        <?php 
        
        $vis = $model->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">( '.__("All", MASTERPRESS_DOMAIN).' )</span>';

        } else {
          
          if (is_null($vis_post_types) || $vis_post_types == "") {
          
            $post_type_display = __("( none )");
          
          } else {
            $post_types = $model->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>

      <?php if ($has_actions) : ?>

      <td class="actions last">
      <div>
        <?php if ($can_edit) : ?>
          <?php echo MPV::action_button("templates", "edit", self::__edit( ), "id=".$file, array("class" => "button button-edit")); ?>
        <?php endif; ?>

        <?php if ($can_manage_field_sets) : ?>
          <?php echo MPV::action_button("templates", "manage-field-sets", self::__manage( MPV_FieldSets::__p_short() ), "parent=".$file, array("class" => "button button-manage")); ?>
        <?php endif; ?>  
      </div>
      </td>

      <?php endif; // has_actions ?>

    </tr>
    
    <?php endforeach; ?>

    </tbody>
    </table>
    
    <?php
    
  } // end grid()
Example #4
0
  public static function register_template_support() {
   
    global $wf;

    if (isset($_REQUEST["post"])) {
      
      $the = $wf->post($_REQUEST["post"]);

      $type = $the->type_name();
      
      $template_name = $the->template();
  
      if ($template_name && !is_woof_silent($template_name)) {

        $template = MPM_Template::find_by_id($template_name);
      
        if ($template && $template->supports != "*") {
          
          remove_post_type_support($type, 'title');
          remove_post_type_support($type, 'editor');
          remove_post_type_support($type, 'author');
          remove_post_type_support($type, 'thumbnail');
          remove_post_type_support($type, 'excerpt');
          remove_post_type_support($type, 'trackbacks');
          remove_post_type_support($type, 'custom-fields');
          remove_post_type_support($type, 'comments');
          remove_post_type_support($type, 'revisions');
          remove_post_type_support($type, 'page-attributes');
        
          foreach (explode(",", $template->supports) as $support) {
            add_post_type_support($type, $support);
          }
        }

      }
    
    }
  
  }
Example #5
0
  public static function attributes_meta_box_content($post, $r) {
    
    // custom attributes metabox that mimics the core box, 
    // but allows templates to be assigned to other post types 
    
    global $wf, $meow_provider, $wpdb;
    $the = $wf->the();
    
    $type = $the->type();

    $type_name = $type->name;
    
    $type_model = MPM_PostType::find_by_name($type_name);

    $my_templates = array();
    
    // prime the templates
    
    $models = array();
     
    foreach (get_page_templates() as $template => $file) {
      $models[$file] = MPM_Template::find_by_id($file);
    }
    
    
    foreach ($type_model->templates() as $template) {
      $my_templates[] = $template->id;
    }

    
    $children = $the->children->extract("id");

    
    if (is_array($children) && count($children)) {
      $post__not_in = array_unshift($children, $the->id);
    } else {
      $post__not_in = array($the->id);
    }
  
    $meta_template = $the->meta("_wp_page_template", true);


    if (!is_array($post__not_in)) {
      $post__not_in = array($post__not_in);
    }
    
    if (count($post__not_in)) {
      $posts = $type->top_posts(array("cache_results" => false, "orderby" => "menu_order", "order" => "asc", "post__not_in" => $post__not_in));
    } else {
      $posts = $type->top_posts(array("cache_results" => false, "orderby" => "menu_order", "order" => "asc"));
    }
    
    $parent = apply_filters("mp_edit_post_parent", $the->post_parent, $the);
    
    if ($parent == 0) {
      $parent = apply_filters("mp_edit_post_default_parent", $parent, $the->id, $the);
    }
    
    
    
    $menu_order = $the->menu_order;
    
    ?>
    
    <?php if ($type->hierarchical() && count($posts)) : ?>
    <p><strong><?php _e("Parent") ?></strong></p>
    
    <select name="parent_id" id="parent_id">
      <option><?php _e("(no parent)") ?></option>
      <?php self::post_options($posts, $parent, $post__not_in ); ?>
    </select>
    <?php endif; ?>
    
    <?php if (count($my_templates)) : ?>
      
    <?php
      
    // get the fields for the current template

    $default_template = $the->default_template();
    
    $tm = MPM_Template::find_by_id($default_template);
    $data_sets = self::flatten_assigned($meow_provider->post_type_field_sets($type_name, $default_template));
    $supports = $tm->supports;
    
    $templates = get_page_templates();
      
    ksort($templates);
    
    
    ?>
    
    <p class="label_page_template"><strong><?php _e("Template") ?></strong></p>
    
    <select name="page_template" id="page_template" autocomplete="off">
      <option value="default" data-supports="<?php echo $supports ?>" data-sets="<?php echo $data_sets ?>"><?php _e( "( Default Template )", MASTERPRESS_DOMAIN) ?></option>
      <?php foreach ($templates as $template => $file) : $selected_attr = WOOF_HTML::selected_attr($meta_template == $file); ?>
      <?php if (in_array($file, $my_templates)) : ?>
      
      <?php 
      $tm = $models[$file];
      $data_sets = self::flatten_assigned($meow_provider->post_type_field_sets($type_name, $file)); 
      $supports = $tm->supports;
      ?>
      
      <option <?php echo $selected_attr ?> data-supports="<?php echo $supports ?>" data-sets="<?php echo $data_sets ?>" value="<?php echo $file ?>"><?php echo $template ?></option> 
      <?php endif; ?>
      <?php endforeach; ?>
    </select>

    
    <p id="mp-templates-loading-fields"><?php _e("Loading additional fields. Please wait&hellip;"); ?></p>
    
    <?php endif; ?>
    
    <p><strong><?php _e("Order") ?></strong></p>
    <p><label class="screen-reader-text" for="mp_menu_order"><?php _e("Order") ?></label>
    <input name="menu_order" type="text" size="4" id="menu_order" value="<?php echo $menu_order ?>"></p>    

    <?php

  }