The process is as follows:
First, the entity is saved with this method (the system itself):
For example, there is an activity class that inherits from Elggobject, creating an instance of it activity,
Copy CodeThe code is as follows:
Now see if we have a file icon
if ((Isset ($_files[' icon ')) && (Substr_count ($_files[' icon ' [' type '], ' image/'))) {
$prefix = "activity/". $activity->guid;
$filehandler = new Elggfile ();
$filehandler->owner_guid = $activity->owner_guid;
$filehandler->setfilename ($prefix. ". jpg");
$filehandler->open ("write");
$filehandler->write (get_uploaded_file (' icon '));
$filehandler->close ();
$thumbtiny = Get_resized_image_from_existing_file ($filehandler->getfilenameonfilestore (), 25,25, true);
$thumbsmall = Get_resized_image_from_existing_file ($filehandler->getfilenameonfilestore (), 40,40, true);
$thumbmedium = Get_resized_image_from_existing_file ($filehandler->getfilenameonfilestore (), 100,100, true);
$thumblarge = Get_resized_image_from_existing_file ($filehandler->getfilenameonfilestore (), 200,200, false);
if ($thumbtiny) {
$thumb = new Elggfile ();
$thumb->owner_guid = $activity->owner_guid;
$thumb->setmimetype (' image/jpeg ');
$thumb->setfilename ($prefix. " Tiny.jpg ");
$thumb->open ("write");
$thumb->write ($thumbtiny);
$thumb->close ();
$thumb->setfilename ($prefix. " Small.jpg ");
$thumb->open ("write");
$thumb->write ($thumbsmall);
$thumb->close ();
$thumb->setfilename ($prefix. " Medium.jpg ");
$thumb->open ("write");
$thumb->write ($thumbmedium);
$thumb->close ();
$thumb->setfilename ($prefix. " Large.jpg ");
$thumb->open ("write");
$thumb->write ($thumblarge);
$thumb->close ();
}
}
After this process, the file will be saved to a directory structure consisting of a user name string, such as the user name is ABC, is saved under the a/b/c/, and then the image of the Guid+size+.jpg form a file name.
When acquiring the SRC address, it is obtained through the entity->geticon () method. GetIcon is the method in entities.php. This method then invokes the Get_entity_icon_url method, which has one line in the Get_entity_icon_url method:
$url = Trigger_plugin_hook (' Entity:icon:url ', $entity->gettype (), Array (' entity ' + $entity, ' viewtype ' = = $ ViewType, ' size ' = $size), $url);
It triggers a hook, and the hood needs to be registered in the plugin's start.php. This is written when registering:
Register_plugin_hook (' Entity:icon:url ', ' object ', ' Activity_activityicon_hook ');
The first parameter is the hook type, the second is the entity type, the activity type, and the third is the hook function name.
Then write the Activity_activityicon_hook method in start.php:
Copy CodeThe code is as follows:
/**
* Get icon
* This hooks to the GetIcon API and provides nice user icons for users where possible.
*
* @param string $hook hook name
* @param string $entity _type entity type
* @param string $returnvalue picture URL address
* @param unknow $params parameter table column
* @return string $url picture URL address
*/
function Activity_activityicon_hook ($hook, $entity _type, $returnvalue, $params) {
Global $CONFIG;
if ((! $returnvalue) && ($hook = = ' Entity:icon:url ') && ($params [' entity '] instanceof Activity)} {
$entity = $params [' entity '];
$type = $entity->type;
$viewtype = $params [' ViewType '];
$size = $params [' Size '];
if ($icontime = $entity->icontime) {
$icontime = "{$icontime}";
} else {
$icontime = "Default";
}
$filehandler = new Elggfile ();
$filehandler->owner_guid = $entity->owner_guid;
$filehandler->setfilename ("activity/". $entity->guid. $size. ". jpg");
if ($filehandler->exists ()) {
$url = $CONFIG->url. "pg/activityicon/{$entity->guid}/$size/$icontime. jpg";
return $url;
}
}
}
This method returns a URL, which is the SRC address. After the URL is returned to Get_entity_icon_url, it continues processing according to the picture size, returning the final URL. This will get the SRC address.
http://www.bkjia.com/PHPjc/321496.html www.bkjia.com true http://www.bkjia.com/PHPjc/321496.html techarticle The process is as follows: First, the entity is saved with this method (the system itself): for example, there is an activity class, inheriting from Elggobject, creating an instance of it activity, copying code ...