diff options
| -rw-r--r-- | engine/lib/metadata.php | 53 | ||||
| -rw-r--r-- | mod/profile/start.php | 3 | 
2 files changed, 55 insertions, 1 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index 4c2685296..4084d6959 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -766,6 +766,54 @@  			return get_extender_url($extender);	  		}   		return false; +	}
 +	
 +	/**
 +	 * Mark entities with a particular type and subtype as having access permissions
 +	 * that can be changed independently from their parent entity
 +	 *
 +	 * @param string $type The type - object, user, etc
 +	 * @param string $subtype The subtype; all subtypes by default
 +	 */
 +	function register_metadata_as_independent($type, $subtype = '*') {
 +		global $CONFIG;
 +		if (!isset($CONFIG->independents)) $CONFIG->independents = array();
 +		$CONFIG->independents[$type][$subtype] = true;
 +	}
 +	
 +	/**
 +	 * Determines whether entities of a given type and subtype should not change
 +	 * their metadata in line with their parent entity 
 +	 *
 +	 * @param string $type The type - object, user, etc
 +	 * @param string $subtype The entity subtype
 +	 * @return true|false
 +	 */
 +	function is_metadata_independent($type, $subtype) {
 +		global $CONFIG;
 +		if (empty($CONFIG->independents)) return false;
 +		if (!empty($CONFIG->independents[$type][$subtype])
 +			|| !empty($CONFIG->independents[$type]['*'])) return true;
 +		return false;
 +	}
 +	
 +	/**
 +	 * When an entity is updated, resets the access ID on all of its child metadata
 +	 *
 +	 * @param string $event The name of the event
 +	 * @param string $object_type The type of object
 +	 * @param ElggEntity $object The entity itself
 +	 */
 +	function metadata_update($event, $object_type, $object) {
 +		if ($object instanceof ElggEntity) {
 +			if (!is_metadata_independent($object->getType(), $object->getSubtype())) {
 +				global $CONFIG;
 +				$access_id = (int) $object->access_id;
 +				$guid = (int) $object->getGUID();
 +				update_data("update {$CONFIG->dbprefix}metadata set access_id = {$access_id} where entity_guid = {$guid}");
 +			}
 +		}	
 +		return true;	
  	}  	/** @@ -779,5 +827,8 @@  	}  	/** Register the hook */ -	register_plugin_hook("export", "all", "export_metadata_plugin_hook", 2); +	register_plugin_hook("export", "all", "export_metadata_plugin_hook", 2);
 +	/** Call a function whenever an entity is updated **/
 +	register_elgg_event_handler('update','all','metadata_update');
 +	  ?>
\ No newline at end of file diff --git a/mod/profile/start.php b/mod/profile/start.php index f47f44395..ff9d142a5 100644 --- a/mod/profile/start.php +++ b/mod/profile/start.php @@ -23,6 +23,9 @@  			// will dictate the URL for all ElggUser objects
  				register_entity_url_handler('profile_url','user','all');
 +			// Metadata on users needs to be independent
 +				register_metadata_as_independent('user');
 +				
  			// For now, we'll hard code the profile items as follows:
  			// TODO make this user configurable
  				$CONFIG->profile = array(
  | 
