Exemplo n.º 1
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);
    
  }
Exemplo n.º 2
0
 public function model_key() {
   return WOOF_Inflector::singularize($this->key());
 }
Exemplo n.º 3
0
 public function __get($name) {
   
   global $wf;
   
   // try to find a post type with this name, to get posts for this term
   
   $singular = WOOF_Inflector::singularize($name);
   
   $type = $wf->type($singular);
   
   if ($type->exists()) {
     return $this->posts(array("post_type" => $singular));
   }
   
   return parent::__call($name, array());
   
 }
Exemplo n.º 4
0
    public function __get($name) {

      $type = $this->type($name);
      
      if ($type->exists()) {
        return $type;        
      }
      
      $singular = WOOF_Inflector::singularize($name);
      
      $type = $this->type($singular);
      
      if ($type->exists()) {
        return $type;
      }
      
      // next look for a taxonomy

      $tax = $this->taxonomy($name);
      
      if ($tax->exists()) {
        return $tax;
      }
      
      $tax = $this->taxonomy($singular);
      
      if ($tax->exists()) {
        return $tax;
      }
      
      // now try to call a method on the current wordpress object
      // this way, extension classes can work correctly without needing to call $wf->the.
      
      $obj = $this->object();
      
      if (method_exists($obj, $name)) {
        return call_user_func( array($obj, $name) );
      }
      
      return parent::__get($name);

    }
Exemplo n.º 5
0
 public static function model_class($key) {
   return "MPM_".MPU::title_case(WOOF_Inflector::singularize($key), true);
 }
Exemplo n.º 6
0
 /**
 * Converts a table name to its class name according to rails
 * naming conventions.
 * 
 * Converts "people" to "Person"
 * 
 * @access public
 * @static
 * @see tableize
 * @param    string    $table_name    Table name for getting related ClassName.
 * @return string SingularClassName
 */
 function classify($table_name)
 {
     return WOOF_Inflector::camelize(WOOF_Inflector::singularize($table_name));
 }
Exemplo n.º 7
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);

  }
Exemplo n.º 8
0
 public function __get($name) {
   
   global $wf;
   
   // try to find a taxonomy whose plural name is this $name
   
   $singular = WOOF_Inflector::singularize($name);
   
   $tax = $wf->taxonomy($singular);
   
   if ($tax->exists()) {
     return $this->terms($singular);  
   }
   
   return parent::__get($name);
   
 }