Ejemplo n.º 1
0
 public function __get($name) {
   
   if (method_exists($this, $name)) {
     return $this->{$name}();
   } else if (isset($this->item->{$name})) {
     return $this->item->{$name};
   } 
   
   $set = $this->set($name);
   
   if (is_woof_silent($set)) {
     return parent::__get($name);
   } else {
     return $set;
   }
   
 }
Ejemplo n.º 2
0
  public static function select($options, $value, $blank = false, $editable = true) {
   
    global $wf;

    $control_style = self::option_value($options, "control_style", "drop_down_list");

    if ($control_style == "dual_list_box") {
      // legacy patch for dual list box - it had bad performance for a large number of items
      $control_style = "list_box_multiple";
    }

    $blank = false;
    $selected_values = array();
    $options_attr = array();
    $values_select = "";
    $values_options = array_flip($value);
    $values_options_attr = array_flip($value);
    $count = -1;
    $multiple = count($options["user_roles"]) > 1;
    $items = array();

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

    // build a list of users

    self::$values_keys = array();

    foreach ($options["user_roles"] as $role_name) {
      $count++;

      $role = $wf->role($role_name);
      
      if (!$role || is_woof_silent($role)) {
        $role = $wf->role(strtolower($role_name));
      }
      
      if ($role && !is_woof_silent($role)) {
        $title = $role->name();

        $attr = array();

        if (!$blank && in_array($title, $value)) {

          $values_options[$title] = $title;
          $values_options_attr[$title] = $attr;
          $selected_values[] = $title;
        } 

        $items[] = $title;
      }
    
    }

    self::$values_keys = array_values($values_options);

    $select_style = "";

    $select_attr = array("id" => "{{id}}", "name" => "{{name}}");

    if (is_numeric($maxwidth)) {
      $select_style .= "width: 99%; max-width: ".$maxwidth."px;";
    } else {
      if ($control_style == "dual_list_box") {
        $select_style .= "width: 580px;";
      }
    }

    if ($control_style == "list_box_multiple") {
      if (is_numeric($height)) {
        $select_style .= "height: ".$options["height"]."px;";
      } else {
        $select_style .= "height: 250px;";
      }
    }

    if ($control_style == "list_box_multiple") {
      $select_attr["multiple"] = "multiple";
      $select_attr["name"] = "{{name}}[]";
    } 


    if ($select_style != "") {
      $select_attr["style"] = $select_style;
    }

    $basic = self::option_value($options, "basic") == "yes";

    if ($control_style == "drop_down_list") {


      $placeholder = self::option_value($options, "placeholder", __("-- Select a User Role --", MASTERPRESS_DOMAIN));
    
      if ($basic) {
        $items = array($placeholder => "") + $items;
        array_unshift($options_attr, array());
      } else {
        $items = array("" => "") + $items;
        array_unshift($options_attr, array());
        $select_attr["data-placeholder"] = $placeholder;
      }

    
    } else {
      
      $placeholder = self::option_value($options, "placeholder", __("-- Select User Roles --", MASTERPRESS_DOMAIN));
      $select_attr["data-placeholder"] = $placeholder;
      $select_attr["data-value-input"] = "{{id}}-value-input";
      
      if (!$basic) {
        // ensure the select control does not affect the values posted, the hidden input is responsible for this
        $select_attr["name"] = "src_".$select_attr["name"];
      }

    }

    if (!$editable) {
      $select_attr["data-placeholder"] = __("-- None Selected --", MASTERPRESS_DOMAIN);
      $select_attr["disabled"] = "disabled";
    }

    return WOOF_HTML::select( 
      $select_attr,
      $items,
      $selected_values,
      $options_attr
    );
    
  }
Ejemplo n.º 3
0
  public static function get_row_prop_image($obj, $result_row_prop, $post_type_name, $width = 60) {

    $image = self::get_row_prop($obj, $result_row_prop, $post_type_name, "image", "featured_image");
    
    if ($image && !is_woof_silent($image) && !$image->blank() && $image->exists()) {
      
      $w = $width * 2;
      $h = $width * 2;
        
      if ($image->is_image() && $image->width() > $width) {
        $image = $image->resize("w=$w&h=$h");
      }
      
      return array("data-image" => $image->url, "data-image_width" => $width, "data-image_height" => $width);
    } else {
      return array("data-image" => __("no image", MASTERPRESS_DOMAIN), "data-no_image" => "true");
    }
    
  }
Ejemplo n.º 4
0
  public function has($key) {
    
    $val = $this->get($key);

    if ($val && !is_woof_silent($val)) {
      return $val;
    }
    
    return false;
    
  }
Ejemplo n.º 5
0
    public function taxonomies_for_type($type_name) {
      if (!isset($this->tft)) {
        $tft = array();
        
        foreach ($this->taxonomies() as $tax) {
          foreach ($tax->types() as $type) {
            
            $type_name = $type->name;
            
            if (!is_woof_silent($type_name)) {
              if (!isset($tft[$type_name])) {
                $tft[$type_name] = array();
              }
            
              $tft[$type_name][] = $tax;
            }
          
          }
          
        }

        $this->tft = array();
        
        foreach ($tft as $type => $taxonomies) {
          $this->tft[$type] = new WOOF_Collection($taxonomies);
        }
        
      }
      
      if (isset($this->tft[$type_name])) {
        return $this->tft[$type_name];
      }
      
      return new WOOF_Silent( sprintf( __( "No taxonomies for %s", WOOF_DOMAIN ), $type_name ) );
      
    }
Ejemplo n.º 6
0
  function group_by($name) {

    $this->init_items();

    $abt = array();
    $ret = array();
    
    foreach ($this->_items as $item) {
      $val = $item->__get($name);
      
      if (!is_woof_silent($val)) {
        $abt[$val][] = $item;
      }
      
    }
    
    foreach ($abt as $key => $arr) {
      $ret[$key] = new WOOF_Collection($arr);
    }

    return $ret;
    
  }
Ejemplo n.º 7
0
  public function submit() {
    
    global $wpdb, $wf;
    
    $action = MasterPress::$action;

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

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

      $role_id = MasterPress::$id;

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

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


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

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

      return true;

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

      if ($field_set->is_valid()) {

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

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

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

      $fg->delete();
      
      return true;

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

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

      if ($f) {

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

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

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

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

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

    } 
    
    
    return false;
  }
Ejemplo n.º 8
0
  function update() {
    
    if ($this->dirty && $this->exists()) {
      
      $this->dirty = false; // do this now in case of any SQL errors
      $this->updated = true;
      
      global $wpdb;
      global $wf, $meow_provider;
  
      $value_type = null;
      
      $object_type = $meow_provider->type_key($this->object);
   
      $object_id = $this->object->id();
      
      if ($object_type == "term") {
        $tax = $this->object->taxonomy->name();
        
        if ($tax && !is_woof_silent($tax)) {
          $value_type = $tax;
        }
      }

      /* Delete the old post meta */
  
			$this->object->switch_site();
			
      $set_name = $this->name;
  
      foreach ( $this->info->fields as $field) {
        
        if (!$field->disabled && $field->in_current_site()) {
         
          $meta_name = $set_name.".".$field->name;

          MPC_Meta::delete_object_meta($object_type, $object_id, $meta_name);
  
          // now go through the properties too

          $dont_care = MPFT::type_class($field->type);
    
          foreach (MPFT::type_properties($field->type) as $prop) {
            MPC_Meta::delete_object_meta($object_type, $object_id, $meta_name.":".$prop);
          }
        
        }
      
      }
  
      $model_id_prop_stored = array();
  
    
      // Create the new values
    
      foreach( $this->_items as $set_index => $set_item ) {
      
        foreach ($this->info->fields as $field) {
          
          if (!$field->disabled && $field->in_current_site()) {

            // here the field type should prepare the value, if necessary
    
            // grab the type
    
            $model_id = $field->id;
    
            $model = $field;
    
            $field_item = $this->field($field->name, $set_index);
      
            if ($field_item->exists()) {
              
              $value = $field_item->raw();
              
              $val = MPU::db_encode($value);
    
              if ($type_class = MPFT::type_class($model->type)) {
                $val = MPU::db_encode( call_user_func_array( array($type_class, "value_for_save"), array($value, $model)) );
              }
              
  
              // create the post meta
    
              $meta_name = MPFT::meta_key($set_name, $field->name);
    
              //echo "would add $object_type, $object_id, $meta_name, $val<br>";

              
              if (! (!$this->info->allow_multiple && $val == "") ) {
                // don't record blank entries for non-multiple field sets, as this is wasteful
              
                MPC_Meta::add_object_meta($object_type, $object_id, "{$meta_name}", $val, $value_type);

                // now store the properties
    
                foreach (MPFT::type_properties($model->type) as $prop) {

                  if ($prop == "field_id" && !isset($model_id_prop_stored[$model_id])) {
                    $model_id_prop_stored[$model_id] = true;
          
                    MPC_Meta::add_object_meta($object_type, $object_id, "{$meta_name}:{$prop}", $model_id, $value_type);
        
                  } else {

                    $prop_value = $field_item->prop_val($prop);
        
                    if (!isset($prop_value)) {
                      $prop_value = "";
                    }
                    
                    if ($prop != "field_id") {
                      MPC_Meta::add_object_meta($object_type, $object_id, "{$meta_name}:{$prop}", $prop_value, $value_type);
                    }
                  
                  } // $prop = field_id

                } // foreach MPFT::type_properties
            
              } // if (!allow_multiple)
            
            } // if (field_item->exists)
          
          } // if (!field->disabled)
        
    
        } // endforeach $fields
    
    
      } // endforeach ($this->items)

      $this->object->restore_site();

    } // if ($dirty)
    
    
  }
Ejemplo n.º 9
0
  public function get_prop($name) {
    global $wf;
    
    $vid = $this->prop_val("video_id");
    
    if (!$this->blank() && ( is_woof_silent($vid) || $vid == "" )) {

      // WARNING - DON'T check the prop value using "prop" here, as we'll get infinite recursion
      
      // the video URL has been set, but the video id has not
      // this will generally be because the field URL has been set programatically
      
      $info = self::fetch_video_info($this->value(), false);
      
      if (!$info["error"]) {
        $this->fill_prop(__CLASS__, $info);
      }
      
    } 
    
    $val = $this->prop_val($name);
    
    if (isset($val) && !is_woof_silent($val)) {
      
      if ($name == "thumbnail") {
        return $wf->image_from_url($val);
      } else if ($name == "description") {
        return html_entity_decode($val);
      } else if ($name == "duration") {
        
        if (is_numeric($val)) {
          return date("H:i:s", (int) $val);
        }
        
      }
      
      return $val;
      
    }
  
  }
Ejemplo n.º 10
0
  public function __get($name) {
    
    global $wf;
    
    $value = $this->get($name);

    if (is_woof_silent($value)) {
      $value = $this->set($name);
    }

    if (!is_woof_silent($value)) {
      return $value;
    }

    // look for "incoming" post types, so that we can get "incoming_cars" for example
    
    if (preg_match("/incoming\_([a-z0-9\_]+)/", $name, $matches)) {
    
      $pt_name = $matches[1];
      $singular = WOOF_Inflector::singularize($pt_name);
      
      foreach ($wf->types() as $type) {
        if ($type->name == $singular) {
          return $this->incoming("post_type=".$singular);
        } 
      }
      
      // next we'll try taxonomy names
      
      foreach ($wf->taxonomies() as $tax) {
        if ($tax->name == $singular) {
          return $this->incoming_terms($tax->name);
        } 
      }
      
      
    }

    
    return parent::__get($name);

  }
Ejemplo n.º 11
0
  public function create_version($object_id, $object_type, $object_type_meta = "", $dirty = array(), $versions_count = array()) {
    
    global $wf, $wpdb, $current_user;
    
    $initial = !is_array($dirty) && $dirty == "initial";
    
    if ($object_type == "post") {
      $object = $wf->post($object_id);
    } else if ($object_type == "term") {
      $object = $wf->term_by_id($object_id, $object_type_meta);
    } else if ($object_type == "user") {
      $object = $wf->user($object_id);
    } else if ($object_type == "site") {
      $object = $wf->site($object_id);
    }
    
    if (isset($object) && !is_woof_silent($object)) {
      
      $sets_to_record = array();

      $sets = array();
      
      foreach ($versions_count as $set => $count) {
        
        if ($count != 0) {

          // don't record if version recording is off (zero value)
        
          $sql = "SELECT * FROM ".MPU::site_table('versions')." WHERE object_id = $object_id AND object_type = '$object_type' "; 
        
          if ($object_type_meta != "") {
            $sql .= " AND object_type_meta = '$object_type_meta' ";
          }

          $sql .= " AND field_set_name = '".$set."'";

          $vr = $wpdb->get_results($sql);

          $record = false;
          
          if ($initial) {
            if (count($vr) == 0) {
              $record = true;
            }
          }
          
          if (is_array($dirty) && isset($dirty[$set])) {
            $record = true;
          }
          
          if ($record) {
            $sets_to_record[$set] = count($vr) - $count; // store the number of versions to delete (the -1 is because we ALSO store the current version)
          }
        
          
        }
        
      }
      
      
      if (!count($sets_to_record)) {
        return array(); // no need to do anything
      }
      
      $data = $this->get_meta($object);
      
      
      foreach ($data as $set => $fields) {
              
        if (isset($sets_to_record[$set])) {
        
          $json = json_encode($fields);

          if (! ( $initial && $json && $json == "[]" ) ) {
            
            $wpdb->insert( MPU::site_table("versions"), array(
                "date" => date("Y-m-d H:i:s"),
                "user_id" => $wf->the_user()->id,
                "object_id" => $object_id,
                "object_type" => $object_type,
                "object_type_meta" => $object_type_meta,
                "field_set_count" => count($fields),
                "field_set_name" => $set,
                "value" => "json:".$json
              )
            );
          
          
            if ($sets_to_record[$set] > 0) {
              // delete older versions of the content
            
              $sql = "SELECT version_id FROM ".MPU::site_table('versions')." WHERE object_id = $object_id AND object_type = '$object_type' "; 
              if ($object_type_meta != "") {
                $sql .= " AND object_type_meta = '$object_type_meta' ";
              }
              $sql .= " AND field_set_name = '".$set."' ORDER BY version_id LIMIT ".$sets_to_record[$set];
          
              $versions_to_delete = $wpdb->get_col($sql);
            
              if (count($versions_to_delete)) {
                $wpdb->query("DELETE FROM ".MPU::site_table('versions')." WHERE version_id IN (".implode(",", $versions_to_delete).")");
              }
            }
          
          }
        
        
        }

      
      }
      
      $this->uncache_data();
      
      return true;
      
    }
    
  }
Ejemplo n.º 12
0
  function __get($name) {

    // is we're accessing the set named "content" and it exists, prioritise this first
    // this allows us to call "content()" to get the standard content FIELD.
    
    if ($name == "content") {
      $set = $this->set("content");
      
      if ($set->exists()) {
        return $set;
      }
    }

    if ($name == "posts" || $name == "pages") {
      return parent::__get($name);
    }
    
    // first, look for a property named $name
    $result = $this->get($name);
    
    if (!is_woof_silent($result)) {
      return $result;
    }    
    
    // next, try to get a set named $name
    $result = $this->s($name);
    
    if (!is_woof_silent($result)) {
      return $result;
    }    

    // next try the parent, which will get post types, or taxonomies with this name
    return parent::__get($name);
    
  }
Ejemplo n.º 13
0
  public static function eval_token($object, $token) {
    
    $parts = explode(".", $token);

    $base = $object;

    foreach ($parts as $part) {
      
      // enhanced support for arguments etc
      
      if (preg_match("/([A-Za-z0-9\_]+)\((.+)\)/", $part, $matches)) {

        $args = array();
        
        $targs = json_decode($matches[2], true);
        
        if ($targs) {
          // args are a single associative array
          $args = array( $targs );
        } else if (is_numeric($matches[2])) {
          $args = array( (float) $matches[2] );
        } else { // treat as a string
          $args = array( $matches[2] );
        }

        if (is_object($base)) {
          $base = $base->__call($matches[1], $args);
        }

        if (is_woof_silent($base)) {
          $base = $base->__get($matches[1]);
        }
        
        
      } else {
        
        if (is_object($base)) {
          
          if ($part == "content") {
            // content exception
            $base = $base->__get($part);
          } else {
            
            if (method_exists($base, $part)) {
              $base = call_user_func(array($base, $part)); 
            } else {
              $base = $base->__get($part);
            }
          
          }
          
        }

      }

    }

    if (!is_woof_silent($base)) {
      return $base;
    }
    
    return "";
  }
Ejemplo n.º 14
0
	public function still_registered() {
	  global $wf;
	  $type = $wf->type($this->name);
	  return (!$this->_external) || ($this->_external && !is_woof_silent($type));
  }
Ejemplo n.º 15
0
  public function __get($name) {
  
    global $wf;
    
    // is we're accessing the set named "content" and it exists, prioritise this first
    // this allows us to call "content()" to get the standard content FIELD.
    
    if ($name == "content") {
      $set = $this->set("content");
      
      if ($set->exists()) {
        return $set;
      }
    }
    
    // fallback to WOOF_Wrap's get FIRST.
    
    $value = $this->get($name);
    
    if (is_woof_silent($value)) {
      $value = $this->set($name);
    }

    if (!is_woof_silent($value)) {
      return $value;
    }

    // look for "incoming" post types, so that we can get "incoming_cars" for example
    
    if (preg_match("/incoming\_([a-z0-9\_]+)/", $name, $matches)) {
    
      $pt_name = $matches[1];
      $singular = WOOF_Inflector::singularize($pt_name);
      
      foreach ($wf->types() as $type) {
        if ($type->name == $pt_name) {
          return $this->incoming("post_type=".$pt_name)->first(); // return the first incoming post
        } else if ($type->name == $singular) {
          return $this->incoming("post_type=".$singular);
        }
      }
      
      
      // next we'll try taxonomy names
      
      foreach ($wf->taxonomies() as $tax) {
        if ($tax->name == $singular) {
          return $this->incoming_terms($tax);
        } 
      }
      
      
    } else {

      $singular = WOOF_Inflector::singularize($name);

      foreach ($wf->types() as $type) {
        if ($type->name == $name) {
          return $this->posts("post_type=".$name)->first(); // return the first post (ignore the args)
        } else if ($type->name == $singular) {
          return $this->posts("post_type=" . $singular);
        } 
      }

    }
    
    // fallback to the parent method
    
    return parent::__get($name);
    
  }
Ejemplo n.º 16
0
  function field($name) {
    
    if (!is_woof_silent($name)) {
      
      if (!isset($this->fields[$name])) {

        $data = null;
        
        if (isset($this->data["data"][$this->set_index][$name])) {
          $data = $this->data["data"][$this->set_index][$name];
        }
        
        if ($this->exists()) {
          
          $field = new MEOW_Field($this->name.".".$name, $this->set_index, $this->object, $this, $data);
          $this->fields[$name] = $field;
          
        } else {
          // return a silent object for silent failure
          return new WOOF_Silent( sprintf( __( "No field named %s", MASTERPRESS_DOMAIN ), $name ) );
        }
      
      }
    
      if (isset($this->fields[$name])) {
        return $this->fields[$name];
      }
    
    }
  
    return new WOOF_Silent( sprintf( __( "No field named %s", MASTERPRESS_DOMAIN ), $name ) );
  }
Ejemplo n.º 17
0
  public function __call($name, $arguments) {
    
    global $wf;

    $res = parent::__call($name, $arguments);

    if (is_woof_silent($res)) {

      if (is_multisite()) {

        // for unknown methods switch the blog and access this property on WOOF
    
        if (switch_to_blog( $this->id(), true )) {

			    if (method_exists($wf, $name)) {
			      $res = call_user_func_array (array($wf, $name), $arguments); 
			    } else {
				  	$res = $wf->__call($name, $arguments);
					}
					
          restore_current_blog();

          if (!is_woof_silent($res)) {
            return $res;
          }
        }
    
      }
    
    }
    
    return $res;
    
  }
Ejemplo n.º 18
0
  public function tmpl($key, $tmpl = "", $default = null) {
    
    $blank = true;
    
    $val = $this->get($key);

    if ($val && !is_woof_silent($val)) {
      $blank = false;
    }
    
    if (!$blank || !is_null($default)) {
      if ($blank) {
        $value = $default;
      } else {
        $value = $val;
      }
      
      if (!preg_match("/\{\{.+\}\}/", $tmpl)) {
      
        // assume we want the value in the innermost tag
      
        WOOF::incl_phpquery();

        phpQuery::newDocumentHTML('<div class="context"></div>', $charset = 'utf-8');
        pq($tmpl)->appendTo(".context");
        pq("*:only-child:last")->append("{{val}}");
        $tmpl = pq(".context")->html();
      }

      return WOOF::render_template($tmpl, array("value" => $value, "val" => $value) );
    }
    
    return "";
    
  }
Ejemplo n.º 19
0
  public function __get($name) {
    
    // first check if this field has a data property named $name

    $prop = $this->prop($name);
    
    if (isset($prop)) {
      return $prop;
    }
    
    // delegate the property access to the type delegate
    
    if ($this->type_delegate) {
      
      if (!$this->type_delegate->valid()) {
        return new WOOF_Silent( __("invalid resource", MASTERPRESS_DOMAIN ) );
      }
      
      // next try to call "forward" on the delegate
      // this is a special function to allow "related" objects to forward the call on
      
      $value = $this->type_delegate->forward($name);

      if (!is_woof_silent($value)) {
        return $value;
      }
    
      $value = $this->type_delegate->get($name);
      
      
      if (!is_woof_silent($value)) {
        return $value;
      }
    }
      
    return new WOOF_Silent( sprintf( __( "No property named %s", MASTERPRESS_DOMAIN ), $name ) );
  }
Ejemplo n.º 20
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);
          }
        }

      }
    
    }
  
  }
Ejemplo n.º 21
0
 public function __toString() {
   $embed = $this->embed();
   
   if (!is_woof_silent($embed)) {
     return $embed;
   }
   
   return "";
 }
Ejemplo n.º 22
0
  function in_a($terms, $taxonomy = NULL, $args = array(), $operator = "IN", $relation = "OR") {
    
    global $wf;

    $posts = parent::in_a($terms, $taxonomy, $args, $operator, $relation);
    
    
    if ($wf->regard_field_terms()) {
      
      if (!is_array($terms) && is_string($terms)) {
        $terms = explode(",", $terms);
      }

      if (!isset($taxonomy)) {

        $term_objects = $terms;
        
        if (WOOF::is_or_extends($terms, "WOOF_Term")) {
          $terms = $wf->collection( array($terms) );
        }
      
      } else {
        
        $term_objects = array();
        
        foreach ($terms as $term) {
          
          $obj = $wf->term($term, $taxonomy);
      
          if (!is_woof_silent($obj)) {
            $term_objects[] = $obj;
          }

        }
    
        $term_objects = $wf->collection( $term_objects );

      }
      
      
      if (is_woof_collection($term_objects, "WOOF_Term") && count($term_objects)) {
        
        $grouped = $term_objects->group_by( "taxonomy_name" );

        $matching_posts = $wf->collection();
        
        foreach ($grouped as $taxonomy_name => $terms) {
          
          $tax_posts = $wf->collection();
          
          foreach ($terms as $term) {

            if ($operator == "IN") {
              $tax_posts->merge( $term->incoming( array("post_type" => $this->name ) ), false );
            } else if ($operator == "AND") {
              $tax_posts = $tax_posts->intersect( $term->incoming( array("post_type" => $this->name ) ), "slug" );
            }
          
          }

          if ($relation == "OR") {
            $matching_posts = $matching_posts->merge( $tax_posts, false );
          } else {
            $matching_posts = $matching_posts->intersect( $tax_posts, "slug" );
          }

          
        }
        
        $posts->merge( $matching_posts, false );

        $posts->dedupe();
        
      }
      
    }
    
    return $posts;
    
  }