Elgg obtains the file icon address. The process is as follows: first, this method is used when the object is saved (the system itself): for example, there is an Activity class that inherits from ElggObject and creates an instance activity, the code copying 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,
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:
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.
Handler first, this method is used when the object is saved (the system itself): for example, there is an Activity class that inherits from ElggObject and creates an instance activity ,...