Esempio n. 1
0
 public static function find_by_name_and_template($name, $template, $orderby = "position ASC" ) {
   return self::find( array( "where" => "`name` = '{$name}' AND ".MPM::visibility_rlike("templates", $template)." AND `type` = 't'", "orderby" => $orderby ) ); 
 }
Esempio n. 2
0
 public static function find_by_name_and_role($name, $template) {
   return self::find( array( "where" => "`name` = '{$name}' AND ".MPM::visibility_rlike("roles", $role)." AND `type` = 'r'", "orderby" => $orderby ) ); 
 }
Esempio n. 3
0
  public function import() {
    global $wf;

    $base_dir = MASTERPRESS_TMP_DIR;
    $base_url = MASTERPRESS_TMP_URL;
    
    $restore = false;
    
    if (isset($_POST["import_masterplan"])) {
      $masterplan = $_POST["import_masterplan"];
    } else {
      if (isset($_POST["restore_masterplan"])) {
        $masterplan = $_POST["restore_masterplan"];
        $base_dir = MASTERPRESS_CONTENT_MASTERPLANS_DIR;
        $base_url = MASTERPRESS_CONTENT_MASTERPLANS_URL;
        $restore = true;
      }
    }
    
    
    $view = MasterPress::$view;
    
    if (isset($masterplan)) {
      
      extract(self::open_masterplan($masterplan, true, $base_dir, $base_url));
    
      if ($rep) {



        $icon_dest = MASTERPRESS_CONTENT_MENU_ICONS_DIR;
        $icon_src = $dir.WOOF_DIR_SEP."icons".WOOF_DIR_SEP;

        $field_type_dest = MASTERPRESS_EXTENSIONS_FIELD_TYPES_DIR;
        $field_type_src = $dir.WOOF_DIR_SEP."field-types".WOOF_DIR_SEP;
        
                   
        // install field type extensions
        
        foreach ($field_types as $field_type) {
          $dest = $field_type_dest.$field_type["name"];
          $src = $field_type_src.$field_type["name"];
          
          if (!(file_exists($dest) && !isset($_POST["import_types_overwrite"]))) {
            MPU::copyr($src, $dest);
          }
        
        }
        
        $info = array("log" => array());
          
        $mode = $_REQUEST["import_mode"];
        
        if ($restore) {
          $mode = "replace";
        }
        
        $log = &$info["log"];
        
        $backup = isset($_REQUEST["import_backup"]);

        $view->rep = $rep;
        $view->backup = $backup;
        $view->mode = $mode;
        
        // first obtain the current representation
        
        $current = self::get_current_rep();
        $view->current = $current;
      
        if ($backup) {
          
          // build the backup (a rollback point)
      
          $backup_filename = "_backup.pre-import.".$wf->format_date("[date-time-sortable]").".masterplan.zip";
          $backup_readme = "# Backup Masterplan for ".$wf->sites()->first()->name." #

+ Created: ".$wf->format_date("[date-time-long]");
        
          $backup_rep = $this->export_rep($current);
          $package = $this->build_package($backup_rep, $backup_filename, $backup_readme);
        
          if ($package) {
            $info["backup_package"] = $package;
            $info["backup_url"] = MASTERPRESS_CONTENT_MASTERPLANS_URL.$backup_filename;
            $info["backup_filename"] = $backup_filename;
          }
        
        }
        
        // process the representation

        // store all objects by key to look them up for potential removal (if mode is replace)
        
        $import = array(
          "post_types" => array(),
          "taxonomies" => array(),
          "shared_field_sets" => array(),
          "site_field_sets" => array(),
          "templates" => array(),
          "roles" => array()
        );

        $taxonomies_by_key = array();
        $shared_field_sets_by_key = array();
        $shared_field_sets_by_key = array();
        
        if (isset($rep["post_types"])) {
        
          foreach ($rep["post_types"] as $post_type) {
          
            $data = $post_type;
            unset($data["field_sets"], $data["id"], $data["sites"]);
          
            $name = $post_type["name"];
          
            $insert = true;
          
            if ($model = MPM_PostType::find_by_name($name)) {
              $insert = false;

            } else {
              $model = new MPM_PostType();
            }
            
            $model->set($data, true);
          
            if ($insert) {
              $model->insert();
            } else {
              $model->update();
            }
        
            // install icons
        
            if ($post_type["_builtin"] == "0" && !is_null($post_type["menu_icon"]) && $post_type["menu_icon"] != "") {
              copy($icon_src.$post_type["menu_icon"], $icon_dest.$post_type["menu_icon"]);
            }

            $import["post_types"][$name] = $post_type;
          
            // now run through the field sets, taking care to preserve 
            $import["post_types"][$name]["field_sets"] = self::import_field_sets($post_type["field_sets"], " AND `type` = 'p' AND ".MPM::visibility_rlike("post_types", $name), $dir);


          }
        
        }
        
        if (isset($rep["taxonomies"])) {
        
          foreach ($rep["taxonomies"] as $tax) {
          
            $data = $tax;
            unset($data["field_sets"], $data["id"], $data["sites"]);
          
            $name = $tax["name"];
            
            $insert = true;
          
            if ($model = MPM_Taxonomy::find_by_name($name)) {
              $insert = false;
            } else {
              $model = new MPM_Taxonomy();
            }
            
            $model->set($data, true);
          
            if ($insert) {
              $model->insert();
            } else {
              $model->update();
            }
      
            // install icons
        
            if ($tax["_builtin"] == "0" && !is_null($tax["title_icon"]) && $tax["title_icon"] != "") {
              copy($icon_src.$tax["title_icon"], $icon_dest.$tax["title_icon"]);
            }
          
            $import["taxonomies"][$name] = $tax;
          
            $import["taxonomies"][$name]["field_sets"] = self::import_field_sets($tax["field_sets"], " AND `type` = 'x' AND ".MPM::visibility_rlike("taxonomies", $name), $dir);
          
          }
          
        }

        if (isset($rep["shared_field_sets"])) {
          $import["shared_field_sets"] = self::import_field_sets($rep["shared_field_sets"], " AND `type` = 's' ", $dir);
        }

        if (isset($rep["site_field_sets"])) {
          $import["site_field_sets"] = self::import_field_sets($rep["site_field_sets"], " AND `type` = 'w' ", $dir);
        }
        
        if (isset($rep["templates"])) {
          foreach ($rep["templates"] as $template) {
            
            $id = $template["id"];
            
            // template models are self-creating, so no need for special handling here
            $model = MPM_Template::find_by_id($id);
            
            $data = $template;
            unset($data["field_sets"]);
            
            $model->set($data, true);
            $model->update();

            $import["templates"][$id] = $template;
            
            if (isset($template["field_sets"])) {
              $import["templates"][$id]["field_sets"] = self::import_field_sets($template["field_sets"], " AND `type` = 't' AND ".MPM::visibility_rlike("templates", $id), $dir);
            }

          
          }
        }

        if (isset($rep["roles"])) {
          foreach ($rep["roles"] as $role) {
            if (isset($role["field_sets"])) {
              $name = $role["name"];
              
              $import["roles"][$name] = $role;
              $import["roles"][$name]["field_sets"] = self::import_field_sets($role["field_sets"], " AND `type` = 'r' AND ".MPM::visibility_rlike("roles", $name), $dir);

            }
            
          }
        }
        
        
        if ($mode == "replace") {
          
          // we now need to remove anything in the current setup that ISN'T in the imported masterplan

          if (isset($current["post_types"])) {
            foreach ($current["post_types"] as $post_type) {
              
              $name = $post_type["name"];
              $builtin = $post_type["_builtin"] == "1";
              
              if (!isset($import["post_types"][$name]) && !$builtin) {
                
                $model = MPM_PostType::find_by_name($name);
    
                if ($model) {
                  $model->delete( array(
                    "posts" => "leave",
                    "posts_reassign_type" => "",
                    "field_sets" => "delete",
                    "field_data" => "keep"
                  ));
                }
                
              } else {
                
                if (isset($post_type["field_sets"])) {
                  self::replace_field_sets($post_type["field_sets"], $import["post_types"][$name]["field_sets"]);
                }
                
              }
              
            }
          }
          
          

          if (isset($current["taxonomies"])) {
            foreach ($current["taxonomies"] as $tax) {

              $name = $tax["name"];
              $builtin = $tax["_builtin"] == "1";
              
              if (!isset($import["taxonomies"][$name]) && !$builtin) {
                
                $model = MPM_Taxonomy::find_by_name($name);
                
                if ($model) {
                  $model->delete( array(
                    "existing_terms" => "leave",
                    "existing_terms_reassign_taxonomy" => "",
                    "field_sets" => "delete",
                    "field_data" => "leave"
                  ));
                }
                
              } else {
                if (isset($tax["field_sets"])) {
                  self::replace_field_sets($tax["field_sets"], $import["taxonomies"][$name]["field_sets"]);
                }
              
              }
              
            }
          }

          if (isset($current["shared_field_sets"])) {
            self::replace_field_sets($current["shared_field_sets"], $import["shared_field_sets"]);
          }

          if (isset($current["site_field_sets"])) {
            self::replace_field_sets($current["site_field_sets"], $import["site_field_sets"]);
          }

          if (isset($current["templates"])) {

            foreach ($current["templates"] as $template) {

              $id = $template["id"];

              if (isset($import["templates"][$id])) {
                if (isset($template["field_sets"])) {
                  self::replace_field_sets($template["field_sets"], $import["templates"][$id]["field_sets"]);
                }
              }
              
            }

          }


          if (isset($current["roles"])) {

            foreach ($current["roles"] as $name => $role) {

              if (isset($import["roles"][$name])) {
                  
                if (isset($role["field_sets"])) {
                  self::replace_field_sets($role["field_sets"], $import["roles"][$name]["field_sets"]);
                }
              }
              
            }
          }
          
        } // mode = replace
        
        
        // cleanup the unzipped folder
        
        MPU::rmdir_r($dir);
        
        if ($restore) {
          wp_redirect( MasterPress::admin_url( $this->key(), "manage", array("restore-complete" => "1"), false ) );
        } else {
          wp_redirect( MasterPress::admin_url( $this->key(), "manage", array("import-complete" => "1"), false ) );
        }
      
        
        $view->info = $info;
        
      } else {
        self::ajax_error(__("The Masterplan is no longer valid. Please try another file", MASTERPRESS_DOMAIN));
      }
      
    } else {
      self::ajax_error(__("The Masterplan is no longer valid. Please try another file", MASTERPRESS_DOMAIN));
    }

    
    
  }
Esempio n. 4
0
  public function validate_name($op) {
    if ($this->name != "") {
      
      // check there isn't already a field set with this name 
      
      $taxonomy_name = $this->visibility["taxonomies"];

      if ($this->name != "") {

        $extra_check = "";
      
        if ($op != "insert") {

          $extra_check = " AND fg.id <> ".$this->id." ";

        }
      
      }
    
      // check if a field set already exists specific to this post type 

      if ($post_type) {
        $sql = "SELECT * FROM ".MPU::table("field-sets")." fg WHERE type = 'x' AND fg.name = '{$this->name}' AND ".MPM::visibility_rlike("taxonomies", $taxonomy_name).$extra_check;
        $result = MPM_FieldSet::get_model("field-set", $sql );
      }

      if (isset($result) && $result) {
        $this->err(sprintf(__("Sorry, a field set named <em>%s</em> already exists for taxonomy <em>%s</em>. Please enter another name.", MASTERPRESS_DOMAIN), $this->name, $taxonomy_name), "name");
      }
      
    }
  }
Esempio n. 5
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
    
  }
Esempio n. 6
0
  public function post_type_field_sets($post_type_name, $template_name = "", $orderby = "position ASC") {

    global $wf;
    
    if (is_null($template_name)) {
      $template_name = "";
    }
    
    $args = array($post_type_name, $template_name, $orderby);
    
    if (is_null($ret = $this->property_cache_args("post_type_field_sets", $args ))) {
    
      $this->field_types = array();
      
      global $wpdb;
  
      $field_sets_table = MPM::table("field-sets");
      $fields_table = MPM::table("fields");
  
      $select_list = $this->assigned_select_list();
  
      $sql = "
        SELECT 
        $select_list
        FROM $field_sets_table s
        INNER JOIN $fields_table f ON s.id = f.`field_set_id`
        WHERE  (s.type = 'p' OR s.type = 's') 
        AND ".MPM::visibility_rlike("post_types", $post_type_name, "s.")."  
        AND ".MPM::visibility_rlike("post_types", $post_type_name, "f.");
        
      if ($template_name != "") {
        // filter by template too
        $sql .= "
          AND ".MPM::visibility_rlike("templates", $template_name, "s.")."  
          AND ".MPM::visibility_rlike("templates", $template_name, "f.");
      }  
      
      $sql .= " 
        AND f.disabled = 0 AND s.disabled = 0
        ORDER BY set_type, set_position, field_position;
      ";
      
      $field_sets = array();
      $fields_by_set = array();
  
      $results = $wpdb->get_results($sql);
    
      if ($template_name != "") {
        
        $template_results = $this->template_field_sets($template_name);

        if ($template_results && count($template_results)) {
          $results = array_merge($results, $template_results);
        }
        
      }
      
      foreach ($results as $result) {
    
        $set_name = $result->set_name;
        $set_type = $result->set_type;
        $use_set = true;
        $use_field = true;
    
        if (isset($field_sets[$set_name])) {
      
          if ($set_type == $field_sets[$set_name]["type"]) {
            $use_set = false; // we already have this set recorded
          }
      
          if ($set_type == 't' && in_array($field_sets[$set_name]["type"], array('s','p'))) {
            // clear any existing fields already set
            $fields_by_set[$set_name] = null;
          }
          
          if ($set_type == 's' && $field_sets[$set_name]["type"] == 'p') {
            // the existing set is a post type field set, which holds greater specificity than this shared set, so don't use this set or field
            $use_set = false;
            $use_field = false;
          }
          
          if (in_array($set_type, array('p','s')) && $field_sets[$set_name]["type"] == 't') {
            // the existing set is a template field set, which holds greater specificity than this shared or post type set, so don't use this set's info
            $use_set = false;
            $use_field = false;
          }
          
          
          
        }
    
        if ($use_set) {
          
          $field_sets[$set_name] = $this->set_data_from_result($result);
        } 
    
        // now record the field too
    
        if ($use_field) {
          
          if (!in_array($result->field_type, $this->field_types)) {
            $this->field_types[] = $result->field_type; 
          }
          
          $fields_by_set[$set_name][$result->field_name] = $this->field_data_from_result($result);
        }
      
      } // endforeach
    
      
        
      $field_set_models = array();
      
      foreach ($field_sets as $field_set) {

        if ($field_set["type"] == "s") {
          $field_set_model = new MPM_SharedFieldSet();
        } else {
          $field_set_model = new MPM_FieldSet();
        }

        $field_set_model->set_from_row($field_set);
        
        $field_models = array();
        
        $fields = $fields_by_set[$field_set["name"]];
        
        if (is_array($fields) && count($fields)) {

          foreach ($fields as $field) {
            $field_model = new MPM_Field();
            $field_model->set_from_row($field);
            
            if ($field_model->in_current_site()) {
              $field_models[$field["name"]] = $field_model;
            }
          
          } 
        
          $field_set_model->set_fields($field_models);

        }
      
        if ($field_set_model->in_current_site()) {
          $field_set_models[$field_set_model->name] = $field_set_model;
        } 
        
      }
     
      
      $ret = $this->property_cache_args("post_type_field_sets", $args, $field_set_models );
      
    } 
    

    return $ret;
  }
Esempio n. 7
0
 public function field_set_count() {
   global $wpdb;
   $post_type_sets = $wpdb->get_col("SELECT id FROM ".MPU::table("field-sets")." WHERE type = 'p' AND ".MPM::visibility_rlike("post_types", $this->name));
   return count($post_type_sets);
 }
Esempio n. 8
0
  public function delete_field_sets() {
   
    global $wpdb;
    
    // delete the field sets of type 'x'

    $sql = "SELECT id FROM ".MPU::table("field-sets")." WHERE type = 'x' AND ".MPM::visibility_rlike("taxonomies", $this->name);
          
    $tax_sets = $wpdb->get_col($sql);

    if (count($tax_sets)) {
      // delete JUST the POST TYPE field sets assigned to this post type
      $wpdb->query("DELETE FROM ".MPU::table("field-sets")." WHERE id IN (".implode(",", $tax_sets).") ");
      
      // delete the fields within those sets
      $wpdb->query("DELETE FROM ".MPU::table("fields")." WHERE field_set_id IN (".implode(",", $tax_sets).") ");
    }
  }