Esempio n. 1
0
 public function __get($name)
 {
     switch ($name) {
         case 'ip':
             $out = long2ip(parent::__get($name));
             break;
         default:
             $out = parent::__get($name);
             break;
     }
     return $out;
 }
Esempio n. 2
0
	/**
	 * function __set
	 * Overrides QueryRecord __set to implement custom object properties
	 * @param string Name of property to return
	 * @return mixed The requested field value
	 */
	public function __set( $name, $value )
	{
		switch ( $name ) {
			case 'pubdate':
			case 'updated':
			case 'modified':
				if ( !( $value instanceOf HabariDateTime ) ) {
					$value = HabariDateTime::date_create( $value );
				}
				break;
			case 'tags':
				if ( $value instanceof Terms ) {
					return $this->tags_object = $value;
				}
				elseif ( is_array( $value ) ) {
					return $this->tags_object = new Terms($value);
				}
				else {
					return $this->tags_object = Terms::parse( $value, 'Term', Tags::vocabulary() );
				}
			case 'status':
				return $this->setstatus( $value );
		}
		return parent::__set( $name, $value );
	}
Esempio n. 3
0
 /**
  * Overrides QueryRecord __set to implement custom object properties
  * @param string $name Name of property to set
  * @param mixed $value Value of the property
  * @return mixed The set field value
  */
 public function __set($name, $value)
 {
     switch ($name) {
         case 'status':
             $value = self::status($value);
             break;
         case 'date':
             if (!$value instanceof DateTime) {
                 $value = DateTime::create($value);
             }
             break;
         case 'post':
             if (is_int($value)) {
                 // a post ID was passed
                 $p = Post::get(array('id' => $value));
                 $this->post_id = $p->id;
                 $this->post_object = $p;
             } elseif (is_string($value)) {
                 // a post Slug was passed
                 $p = Post::get(array('slug' => $value));
                 $this->post_id = $p->id;
                 $this->post_object = $p;
             } elseif (is_object($value)) {
                 // a Post object was passed, so just use it directly
                 $this->post_id = $value->id;
                 $this->post_object = $value;
             }
             return $value;
     }
     return parent::__set($name, $value);
 }
Esempio n. 4
0
 /**
  * Deletes an existing rule
  */
 public function delete()
 {
     return parent::deleteRecord(DB::table('rewrite_rules'), array('rule_id' => $this->rule_id));
 }
Esempio n. 5
0
 /**
  * Deletes an existing cron job.
  *
  * @see QueryRecord::deleteRecord()
  * @return bool If the delete was successful
  */
 public function delete()
 {
     return parent::deleteRecord(DB::table('crontab'), array('cron_id' => $this->cron_id));
 }
Esempio n. 6
0
	/**
	 * function __get
	 * Overrides QueryRecord __get to implement custom object properties
	 * @param $name string Name of property to return
	 * @return mixed The requested field value
	 */
	public function __get( $name )
	{
		switch ( $name ) {
			case 'vocabulary':
				$out = Vocabulary::get_by_id( $this->vocabulary_id );
				break;
			case 'tag_text_searchable':
				// if it's got spaces, then quote it.
				if ( strpos( $this->term_display, ' ' ) !== false ) {
					$out = '\'' . str_replace( "'", "\'", $this->term_display ) . '\'';
				}
				else {
					$out = $this->term_display;
				}
				break;
			case 'count':
				$out = (int)$this->count();
				break;
			case 'id':
				return (int)parent::__get( $name );
			case 'info':
				return $this->get_info();
			default:
				$out = parent::__get( $name );
				break;
		}
		return $out;
	}
Esempio n. 7
0
 /**
  * Delete this block
  *
  */
 public function delete()
 {
     // Let plugins disallow and act before we write to the database
     $allow = true;
     $allow = Plugins::filter('block_delete_allow', $allow, $this);
     if (!$allow) {
         return false;
     }
     Plugins::act('block_delete_before', $this);
     $result = parent::deleteRecord('{blocks}', array('id' => $this->id));
     EventLog::log(sprintf(_t('Block %1$s (%2$s) deleted.'), $this->id, $this->title), 'info', 'content', 'habari');
     // Let plugins act after we write to the database
     Plugins::act('block_delete_after', $this);
     return $result;
 }
Esempio n. 8
0
 /**
  * function __set
  * Overrides QueryRecord __set to implement custom object properties
  * @param string Name of property to return
  * @return mixed The requested field value
  */
 public function __set($name, $value)
 {
     switch ($name) {
         case 'pubdate':
         case 'updated':
         case 'modified':
             if (!$value instanceof HabariDateTime) {
                 $value = HabariDateTime::date_create($value);
             }
             break;
         case 'tags':
             if (is_array($value)) {
                 return $this->tags = $value;
             } else {
                 return $this->tags = $this->parsetags($value);
             }
         case 'status':
             return $this->setstatus($value);
     }
     return parent::__set($name, $value);
 }
Esempio n. 9
0
 /**
  * Capture requests for the info object so that it can be initialized properly when
  * the constructor is bypassed (see PDO::FETCH_CLASS pecularities). Passes all other
  * requests to parent.
  *
  * @param string $name requested field name
  * @return mixed the requested field value
  */
 public function __get($name)
 {
     switch ($name) {
         case 'info':
             if (!isset($this->info)) {
                 $this->info = new UserInfo($this->fields['id']);
             } else {
                 $this->info->set_key($this->fields['id']);
             }
             return $this->info;
         case 'groups':
             return $this->list_groups();
         case 'displayname':
             return empty($this->info->displayname) ? $this->username : $this->info->displayname;
         case 'loggedin':
             return $this->id != 0;
         default:
             return parent::__get($name);
     }
 }
Esempio n. 10
0
 /**
  * Delete an existing vocabulary
  */
 public function delete()
 {
     // Let plugins disallow and act before we write to the database
     $allow = true;
     $allow = Plugins::filter('vocabulary_delete_allow', $allow, $this);
     if (!$allow) {
         return;
     }
     Plugins::act('vocabulary_delete_before', $this);
     // Get the ids for all this vocabulary's terms
     $ids = DB::get_column('SELECT id FROM {terms} WHERE vocabulary_id = ?', array($this->id));
     // Delete the records from object_terms for those ids (if there were any)
     if (count($ids)) {
         $placeholder = Utils::placeholder_string(count($ids));
         DB::query("DELETE FROM {object_terms} WHERE term_id IN ({$placeholder})", $ids);
     }
     // Delete this vocabulary's terms
     DB::delete('{terms}', array('vocabulary_id' => $this->id));
     // Finally, delete the vocabulary
     $result = parent::deleteRecord('{vocabularies}', array('id' => $this->id));
     EventLog::log(_t('Vocabulary %1$s (%2$s) deleted.', array($this->id, $this->name)), 'info', 'content', 'habari');
     // Let plugins act after we write to the database
     Plugins::act('vocabulary_delete_after', $this);
     return $result;
 }
Esempio n. 11
0
 /**
  * Capture requests for the info object so that it can be initialized properly when
  * the constructor is bypassed (see PDO::FETCH_CLASS pecularities). Passes all other
  * requests to parent.
  *
  * @param string $name requested field name
  * @return mixed the requested field value
  */
 public function __get($name)
 {
     $fieldnames = array_merge(array_keys($this->fields), array('groups', 'displayname', 'loggedin', 'info'));
     if (!in_array($name, $fieldnames) && strpos($name, '_') !== false) {
         preg_match('/^(.*)_([^_]+)$/', $name, $matches);
         list($junk, $name, $filter) = $matches;
     } else {
         $filter = false;
     }
     switch ($name) {
         case 'info':
             $out = $this->get_info();
             break;
         case 'groups':
             $out = $this->list_groups();
             break;
         case 'displayname':
             $out = empty($this->info->displayname) ? $this->username : $this->info->displayname;
             break;
         case 'loggedin':
             $out = $this->id != 0;
             break;
         default:
             $out = parent::__get($name);
             break;
     }
     $out = Plugins::filter("user_get", $out, $name, $this);
     $out = Plugins::filter("user_{$name}", $out, $this);
     if ($filter) {
         $out = Plugins::filter("user_{$name}_{$filter}", $out, $this);
     }
     return $out;
 }
Esempio n. 12
0
	/**
	 * Overrides QueryRecord __set to implement custom object properties
	 *
	 * @param string Name of property to return
	 * @return mixed The requested field value
	 */
	public function __set( $name, $value )
	{
		switch ( $name ) {
			case 'timestamp':
				if ( !( $value instanceOf HabariDateTime ) ) {
					$value = HabariDateTime::date_create( $value );
				}
				break;
		}
		return parent::__set( $name, $value );
	}
Esempio n. 13
0
 /**
  * function __get
  * Overrides QueryRecord __get to implement custom object properties
  * @param $name string Name of property to return
  * @return mixed The requested field value
  **/
 public function __get($name)
 {
     switch ($name) {
         case 'vocabulary':
             return Vocabulary::get_by_id($this->vocabulary_id);
         default:
             return parent::__get($name);
     }
 }
Esempio n. 14
0
 /**
  * function __set
  * Overrides QueryRecord __set to implement custom object properties
  * @param string Name of property to return
  * @return mixed The requested field value
  **/
 public function __set($name, $value)
 {
     return parent::__set($name, $value);
 }
Esempio n. 15
0
	/**
	 * function __get
	 * magic get function for returning virtual properties of the class
	 * @param mixed the property to get
	 * @return mixed the property
	 */
	public function __get( $param )
	{
		switch ( $param ) {
			case 'members':
				$this->load_member_cache();
				return (array) $this->member_ids;
				break;
			case 'users':
				$this->load_member_cache();
				$results = DB::get_results( 'SELECT u.* FROM {users} u INNER JOIN {users_groups} ug ON ug.user_id = u.id WHERE ug.group_id= ?', array( $this->id ), 'User' );
				if ( in_array( 0, $this->member_ids ) ) {
					$results[] = User::anonymous();
				}
				return $results;
			case 'permissions':
				$this->load_permissions_cache();
				return $this->permissions;
				break;
			default:
				return parent::__get( $param );
				break;
		}
	}
Esempio n. 16
0
 /**
  * Returns a set of properties used by URL::get to create URLs
  * @return array Properties of this post used to build a URL
  */
 public function get_url_args()
 {
     if (!$this->url_args) {
         $arr = array('content_type_name' => Post::type_name($this->content_type));
         $author = URL::extract_args($this->author, 'author_');
         $info = URL::extract_args($this->info, 'info_');
         $url_args = array_merge($author, $info, $arr, $this->pubdate->getdate());
         $this->url_args = Plugins::filter('post_url_args', $url_args, $this);
     }
     return array_merge($this->url_args, parent::get_url_args());
 }
Esempio n. 17
0
 /**
  * function delete
  * Deletes an existing tag and all relations to it (e.g. a post2tag relationship)
  */
 public function delete()
 {
     $allow = true;
     $allow = Plugins::filter('tag_delete_allow', $allow, $this);
     if (!$allow) {
         return;
     }
     // invoke plugins
     Plugins::act('tag_delete_before', $this);
     // Delete all tag2post records associated with this tag
     $sql = "DELETE FROM {tag2post} WHERE tag_id = ?";
     DB::query($sql, array($this->id));
     // Delete the parent tags record
     $result = parent::deleteRecord(DB::table('tags'), array('id' => $this->id));
     EventLog::log(sprintf(_t('Tag %1$s (%2$s) deleted.'), $this->id, $this->tag_text), 'info', 'content', 'habari');
     Plugins::act('tag_delete_after', $this);
     return $result;
 }
Esempio n. 18
0
 /**
  * Overrides QueryRecord __set to implement custom object properties
  *
  * @param string $name name of property to return
  * @param mixed $value The requested field value
  * @return mixed The requested field value
  */
 public function __set($name, $value)
 {
     switch ($name) {
         case 'timestamp':
             if (!$value instanceof DateTime) {
                 $value = DateTime::create($value);
             }
             break;
     }
     return parent::__set($name, $value);
 }