四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

elgg 獲取文件圖標地址的方法

過程如下:
首先,實體保存的時候用這個方法(系統本身的):
比如有一個Activity類,繼承自ElggObject,創建了一個它的實例 activity,
復制代碼 代碼如下:
// 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();
}
}

這個過程后,文件將被保存至一個由用戶名字符串組成的一個目錄結構下,比如用戶名是abc,則被保存在了a/b/c/下,然后由圖片的guid+size+.jpg組成一個文件名。
獲取src地址的時候,通過實體->getIcon();方法來獲取。getIcon是entities.php中的方法。然后這個方法會調用get_entity_icon_url方法,在get_entity_icon_url方法中有一行:
$url = trigger_plugin_hook('entity:icon:url', $entity->getType(), array('entity' => $entity, 'viewtype' => $viewtype, 'size' => $size), $url);
它會觸發一個鉤子(hook),這個hood需要在插件的start.php中注冊。注冊時這樣寫:
register_plugin_hook('entity:icon:url', 'object', 'activity_activityicon_hook');
第一個參數是鉤子類型,第二個是實體類型,也就是activity的類型,第三個是鉤子函數名。
然后在start.php中寫出activity_activityicon_hook方法:
復制代碼 代碼如下:
/**
* 獲取圖標
* This hooks into the getIcon API and provides nice user icons for users where possible.
*
* @param string $hook 鉤子名
* @param string $entity_type 實體類型
* @param string $returnvalue 圖片url地址
* @param unknow $params 參數表列
* @return string $url 圖片url地址
*/
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;
}
}
}

這個方法會返回一個url,這個url就是src的地址。url返回到get_entity_icon_url后,會根據圖片尺寸繼續加工,返回最終url。這樣就獲取到了src地址。

php技術elgg 獲取文件圖標地址的方法,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 韩国最火主播朴曼妮| dearestblue动漫免费观看| 阿星| 黑帮大佬365天| 奇门遁甲免费讲解全集| 网络查控申请书| 爱很美味电影| 那些女人电视剧免费观看全集剧情| 优秀范文| 上门女婿电影完整版免费| 麻仓桃| 台湾电视台| 3d成人国产同人动漫焰灵姬| 大空头 电影| free hd xxxx moms movie777| 韦伦| 娱乐金鱼眼| cgtn news在线直播| 3d成人国产同人动漫焰灵姬 | 林采薇| 我在等你回家剧情介绍| 美女mm| 伦理电影在线看| 广西地图全图可放大| 决不让步| 吻胸摸激情床激烈视频| 德川家康的地狱| 碧血蓝天| 裸色亮片| 买下我完整版电影免费观看| 伴娘| 一级特黄新婚之夜| 小小少年电影简介| 四川不锈钢水箱制造厂 | 大船| 吻激情| 白丝袜脚| 天机太阴在命宫| 阻击战电影大全| 被囚禁的女孩大结局| 搞怪情侣头像|