The process is as follows:
First, this method is used when the object is saved (the system itself ):
For example, an activity class inherits from elggobject and creates an instance activity,
CopyCode The 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-& gt; getfilenameonfilestore (), 100,100, true );
$ Thumblarge = get_resized_image_from_existing_file ($ filehandler-& gt; 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, for example, the user name is ABC, it is saved under A/B/C/. Then, a file name is composed of guid1_size0000.jpg of the image.
You can use the entity-> getIcon (); method to obtain the SRC address. GetIcon is the method in entities. php. Then this method will call the get_entity_icon_url method. There is a row 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 will trigger a hook. This hood needs to be registered in start. php of the plug-in. Write as follows during registration:
Register_plugin_hook ('entity: icon: url', 'object', 'activity _ activityicon_hook ');
The first parameter is the hook type, the second is the entity type, that is, the activity type, and the third is the hook function name.
Then write the activity_activityicon_hook method in start. php: Copy code The Code is as follows :/**
* Retrieve icons
* This hooks into the getIcon API and provides nice user icons for users where possible.
*
* @ Param string $ hook name
* @ Param string $ entity_type object type
* @ Param string $ returnvalue URL of the image
* @ Param unknow $ Params parameter table column
* @ Return string $ URL of the image
*/
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, the final URL will be returned Based on the image size. In this way, the SRC address is obtained.