/** * Returns publically accessible URL * @return string|false */ public function getURL() { if (!$this->file instanceof \ElggFile || !$this->file->exists()) { elgg_log("Unable to resolve resource URL for a file that does not exist on filestore"); return false; } $relative_path = ''; $root_prefix = _elgg_services()->config->get('dataroot'); $path = $this->file->getFilenameOnFilestore(); if (substr($path, 0, strlen($root_prefix)) == $root_prefix) { $relative_path = substr($path, strlen($root_prefix)); } if (!$relative_path) { elgg_log("Unable to resolve relative path of the file on the filestore"); return false; } $data = array('expires' => isset($this->expires) ? $this->expires : 0, 'last_updated' => filemtime($this->file->getFilenameOnFilestore()), 'disposition' => $this->disposition == self::DISPOSITION_INLINE ? 'i' : 'a', 'path' => $relative_path); if ($this->use_cookie) { $data['cookie'] = _elgg_services()->session->getId(); if (empty($data['cookie'])) { return false; } $data['use_cookie'] = 1; } else { $data['use_cookie'] = 0; } ksort($data); $mac = elgg_build_hmac($data)->getToken(); return elgg_normalize_url("mod/proxy/e{$data['expires']}/l{$data['last_updated']}/d{$data['disposition']}/c{$data['use_cookie']}/{$mac}/{$relative_path}"); }
/** * Remove the icon of a blog * * @param ElggBlog $blog The blog to remove the icon from * * @return bool */ function blog_tools_remove_blog_icon(ElggBlog $blog) { $result = false; if (!empty($blog) && elgg_instanceof($blog, "object", "blog", "ElggBlog")) { if (!empty($blog->icontime)) { $icon_sizes = elgg_get_config("icon_sizes"); if (!empty($icon_sizes)) { $fh = new ElggFile(); $fh->owner_guid = $blog->getOwnerGUID(); $prefix = "blogs/" . $blog->getGUID(); foreach ($icon_sizes as $name => $info) { $fh->setFilename($prefix . $name . ".jpg"); if ($fh->exists()) { $fh->delete(); } } } unset($blog->icontime); $result = true; } else { $result = true; } } return $result; }
/** * Returns publicly accessible URL * @return string|false */ public function getURL() { if (!$this->file instanceof \ElggFile || !$this->file->exists()) { elgg_log("Unable to resolve resource URL for a file that does not exist on filestore"); return false; } $relative_path = ''; $root_prefix = _elgg_services()->config->getDataPath(); $path = $this->file->getFilenameOnFilestore(); if (substr($path, 0, strlen($root_prefix)) == $root_prefix) { $relative_path = substr($path, strlen($root_prefix)); } if (!$relative_path) { elgg_log("Unable to resolve relative path of the file on the filestore"); return false; } $data = array('expires' => isset($this->expires) ? $this->expires : 0, 'last_updated' => filemtime($this->file->getFilenameOnFilestore()), 'disposition' => $this->disposition == self::INLINE ? 'i' : 'a', 'path' => $relative_path); if ($this->use_cookie) { $data['cookie'] = _elgg_services()->session->getId(); if (empty($data['cookie'])) { return false; } $data['use_cookie'] = 1; } else { $data['use_cookie'] = 0; } ksort($data); $mac = _elgg_services()->crypto->getHmac($data)->getToken(); $url_segments = array('serve-file', "e{$data['expires']}", "l{$data['last_updated']}", "d{$data['disposition']}", "c{$data['use_cookie']}", $mac, $relative_path); return elgg_normalize_url(implode('/', $url_segments)); }
function group_icon_url_override($hook, $type, $returnvalue, $params) { $group = $params['entity']; $size = $params['size']; $icontime = $group->icontime; if (null === $icontime) { $file = new ElggFile(); $file->owner_guid = $group->owner_guid; $file->setFilename("groups/" . $group->guid . "large.jpg"); $icontime = $file->exists() ? time() : 0; create_metadata($group->guid, 'icontime', $icontime, 'integer', $group->owner_guid, ACCESS_PUBLIC); } if ($icontime) { // return thumbnail return "groupicon/{$group->guid}/{$size}/{$group->name}.jpg"; } return "mod/groups/graphics/default{$size}.gif"; }
function blog_tools_icon_hook($hook, $entity_type, $returnvalue, $params) { if (!empty($params) && is_array($params)) { $entity = $params["entity"]; if (elgg_instanceof($entity, "object", "blog")) { $size = $params["size"]; if ($icontime = $entity->icontime) { $icontime = "{$icontime}"; $filehandler = new ElggFile(); $filehandler->owner_guid = $entity->getOwnerGUID(); $filehandler->setFilename("blogs/" . $entity->getGUID() . $size . ".jpg"); if ($filehandler->exists()) { $url = elgg_get_site_url() . "blogicon/{$entity->getGUID()}/{$size}/{$icontime}.jpg"; return $url; } } } } }
/** * Get the steps from disk * * @param bool $count get the count of the steps * * @return false|string[]|int */ public function getSteps($count = false) { $count = (bool) $count; $fh = new ElggFile(); $fh->owner_guid = $this->getGUID(); $fh->setFilename('steps.json'); if (!$fh->exists()) { return false; } $steps = $fh->grabFile(); unset($fh); $steps = @json_decode($steps, true); if ($count) { return count($steps); } // reset indexing on steps $steps = array_values($steps); return $steps; }
public function migrateJsonSteps() { $fh = new \ElggFile(); $fh->owner_guid = $this->getGUID(); $fh->setFilename('steps.json'); if (!$fh->exists()) { return false; } $steps = $fh->grabFile(); $steps = @json_decode($steps, true); foreach ($steps as $step) { $new_step = new WizardStep(); $new_step->container_guid = $this->getGUID(); $new_step->description = $step; $new_step->save(); } $fh->delete(); return true; }
/** * Get URL data * * @param string $url URL * @return array|false */ function seo_get_data($url) { $path = seo_get_path($url); if (!$path) { return false; } $hash = sha1($path); $site = elgg_get_site_entity(); $file = new ElggFile(); $file->owner_guid = $site->guid; $file->setFilename("seo/{$hash}.json"); $data = false; if ($file->exists()) { $file->open('read'); $json = $file->grabFile(); $file->close(); $data = json_decode($json, true); } return $data; }
/** * Listen to upgrade event * * @param string $event the name of the event * @param string $type the type of the event * @param mixed $object supplied params * * @return void */ public static function migrateSteps($event, $type, $object) { $path = 'admin/upgrades/migrate_wizard_steps'; $upgrade = new \ElggUpgrade(); // ignore acces while checking for existence $ia = elgg_set_ignore_access(true); // already registered? if ($upgrade->getUpgradeFromPath($path)) { // restore access elgg_set_ignore_access($ia); return; } // find if upgrade is needed $upgrade_needed = false; $batch = new \ElggBatch('elgg_get_entities', ['type' => 'object', 'subtype' => \Wizard::SUBTYPE, 'limit' => false]); foreach ($batch as $entity) { $fa = new \ElggFile(); $fa->owner_guid = $entity->getGUID(); $fa->setFilename('steps.json'); if (!$fa->exists()) { continue; } $upgrade_needed = true; break; } if (!$upgrade_needed) { // restore access elgg_set_ignore_access($ia); return; } $upgrade->title = elgg_echo('admin:upgrades:migrate_wizard_steps'); $upgrade->description = elgg_echo('admin:upgrades:migrate_wizard_steps:description'); $upgrade->setPath($path); $upgrade->save(); // restore access elgg_set_ignore_access($ia); }
/** * Remove the icon of a blog * * @param ElggBlog $blog The blog to remove the icon from * * @return bool */ function blog_tools_remove_blog_icon(ElggBlog $blog) { if (!$blog instanceof ElggBlog) { return false; } if (empty($blog->icontime)) { // no icon return true; } $icon_sizes = elgg_get_icon_sizes('object', 'blog'); if (!empty($icon_sizes)) { $fh = new ElggFile(); $fh->owner_guid = $blog->getOwnerGUID(); $prefix = "blogs/{$blog->getGUID()}"; foreach ($icon_sizes as $name => $info) { $fh->setFilename("{$prefix}{$name}.jpg"); if ($fh->exists()) { $fh->delete(); } } } unset($blog->icontime); return true; }
/** * Update the user profile icon based on profile_sync data * * @param string $event the name of the event * @param string $type the type of the event * @param mixed $object supplied object * * @return void */ function theme_haarlem_intranet_profile_sync_profile_icon($event, $type, $object) { if (empty($object) || !is_array($object)) { return; } $user = elgg_extract('entity', $object); if (empty($user) || !elgg_instanceof($user, 'user')) { return; } // handle icons $datasource = elgg_extract('datasource', $object); $source_row = elgg_extract('source_row', $object); if (empty($datasource) || empty($source_row)) { return; } // handle custom icon $fh = new ElggFile(); $fh->owner_guid = $user->getGUID(); $icon_sizes = elgg_get_config('icon_sizes'); $icon_path = elgg_extract('profielfoto', $source_row); $icon_path = profile_sync_filter_var($icon_path); if (empty($icon_path)) { // remove icon foreach ($icon_sizes as $size => $info) { $fh->setFilename("haarlem_icon/{$size}.jpg"); if ($fh->exists()) { $fh->delete(); } } unset($user->haarlem_icontime); return; } $csv_location = $datasource->csv_location; if (empty($csv_location)) { return; } $csv_filename = basename($csv_location); $base_location = rtrim(str_ireplace($csv_filename, "", $csv_location), DIRECTORY_SEPARATOR); $icon_path = sanitise_filepath($icon_path, false); // prevent abuse (like ../../......) $icon_path = ltrim($icon_path, DIRECTORY_SEPARATOR); // remove beginning / $icon_path = $base_location . DIRECTORY_SEPARATOR . $icon_path; // concat base location and rel path // icon exists if (!file_exists($icon_path)) { return; } // was csv image updated $csv_iconsize = @filesize($icon_path); if ($csv_iconsize !== false) { $csv_iconsize = md5($csv_iconsize); $icontime = $user->haarlem_icontime; if ($csv_iconsize === $icontime) { // icons are the same return; } } // try to get the user icon $icon_contents = file_get_contents($icon_path); if (empty($icon_contents)) { return; } // make sure we have a hash to save if ($csv_iconsize === false) { $csv_iconsize = strlen($icon_contents); $csv_iconsize = md5($csv_iconsize); } // write icon to a temp location for further handling $tmp_icon = tempnam(sys_get_temp_dir(), $user->getGUID()); file_put_contents($tmp_icon, $icon_contents); // resize icon $icon_updated = false; foreach ($icon_sizes as $size => $icon_info) { $icon_contents = get_resized_image_from_existing_file($tmp_icon, $icon_info["w"], $icon_info["h"], $icon_info["square"], 0, 0, 0, 0, $icon_info["upscale"]); if (empty($icon_contents)) { continue; } $fh->setFilename("haarlem_icon/{$size}.jpg"); $fh->open("write"); $fh->write($icon_contents); $fh->close(); $icon_updated = true; } // did we have a successfull icon upload? if ($icon_updated) { $user->haarlem_icontime = $csv_iconsize; } // cleanup unlink($tmp_icon); }
<?php $icon = (int) get_input("icon"); $plugin = elgg_get_plugin_from_id("theme_eersel"); $fh = new ElggFile(); $fh->owner_guid = $plugin->getGUID(); $fh->setFilename("slider_images/" . $icon . ".jpg"); if ($fh->exists()) { $contents = $fh->grabFile(); header("Content-type: image/jpeg", true); header("Expires: " . gmdate("D, d M Y H:i:s \\G\\M\\T", strtotime("+6 months")), true); header("Pragma: public", true); header("Cache-Control: public", true); header("Content-Length: " . strlen($contents)); echo $contents; } else { header("HTTP/1.1 404 Not Found"); }
/** * Reads cached menu items from file for give root entity * * @param \ElggEntity $root_entity root entity to fetch the cache from * * @return array */ public static function getMenuItemsCache(\ElggEntity $root_entity) { $static_items = []; $file = new \ElggFile(); $file->owner_guid = $root_entity->getGUID(); $file->setFilename('static_menu_item_cache'); if ($file->exists()) { $static_items = unserialize($file->grabFile()); } return $static_items; }
/** * Returns media file * * @param \ElggEntity $entity Entity * @param string $type Media type * @return \ElggFile */ function elgg_get_media_file(\ElggEntity $entity, $type = 'icon', $size = 'small', $ext = 'jpg') { $file = new \ElggFile(); $file->owner_guid = $entity->guid; $file->setFilename("media/{$type}/{$size}.{$ext}"); return $file->exists() ? $file : false; }
function theme_eersel_get_slider_images() { static $result; if (!isset($result)) { $result = false; $plugin = elgg_get_plugin_from_id("theme_eersel"); $fh = new ElggFile(); $fh->owner_guid = $plugin->getGUID(); $prefix = "slider_images/"; for ($i = 1; $i <= 5; $i++) { $fh->setFilename($prefix . $i . ".jpg"); if ($fh->exists()) { $mod_time = filemtime($fh->getFilenameOnFilestore()); if (!$result) { $result = array(); } $result[$i] = "theme_eersel/slider/" . $i . "/" . $mod_time . ".jpg"; } } } return $result; }
/** * Convert a video/audio file to a web compatible format * * @param ElggFile $file File entity * @param string $format Format to convert to (extension) * @return ElggFile|false */ function elgg_file_viewer_convert_file($file, $format) { if (!$file instanceof ElggFile || !$format) { return false; } $ffmpeg_path = elgg_get_plugin_setting('ffmpeg_path', 'elgg_file_viewer'); if (!$ffmpeg_path) { return false; } $info = pathinfo($file->getFilenameOnFilestore()); $filename = $info['filename']; $output = new ElggFile(); $output->owner_guid = $file->owner_guid; $output->setFilename("projekktor/{$file->guid}/{$filename}.{$format}"); $output->open('write'); $output->close(); try { $FFmpeg = new FFmpeg($ffmpeg_path); if (!$file->icontime) { $icon = new ElggFile(); $icon->owner_guid = $file->owner_guid; $icon->setFilename("projekktor/{$file->guid}/{$filename}.jpg"); $FFmpeg->input($file->getFilenameOnFilestore())->thumb(0, 1)->output($icon->getFilenameOnFilestore())->ready(); if ($icon->exists()) { $file->icontime = time(); $file->ffmpeg_thumb = $icon->getFilename(); $prefix = 'file/'; $filestorename = $file->icontime . $filename . '.jpg'; $thumbnail = get_resized_image_from_existing_file($icon->getFilenameOnFilestore(), 60, 60, true); if ($thumbnail) { $thumb = new ElggFile(); $thumb->setMimeType($_FILES['upload']['type']); $thumb->setFilename($prefix . "thumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbnail); $thumb->close(); $file->thumbnail = $prefix . "thumb" . $filestorename; unset($thumbnail); } $thumbsmall = get_resized_image_from_existing_file($icon->getFilenameOnFilestore(), 153, 153, true); if ($thumbsmall) { $thumb->setFilename($prefix . "smallthumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbsmall); $thumb->close(); $file->smallthumb = $prefix . "smallthumb" . $filestorename; unset($thumbsmall); } $thumblarge = get_resized_image_from_existing_file($icon->getFilenameOnFilestore(), 600, 600, false); if ($thumblarge) { $thumb->setFilename($prefix . "largethumb" . $filestorename); $thumb->open("write"); $thumb->write($thumblarge); $thumb->close(); $file->largethumb = $prefix . "largethumb" . $filestorename; unset($thumblarge); } } } $FFmpeg->input($file->getFilenameOnFilestore())->output($output->getFilenameOnFilestore())->ready(); elgg_log("Converting file {$file->guid} to {$format}: {$FFmpeg->command}", 'NOTICE'); } catch (Exception $ex) { elgg_log($ex->getMessage(), 'ERROR'); return false; } return $output; }
$autoload_root = dirname(dirname(dirname($autoload_root))); } require_once "{$autoload_root}/vendor/autoload.php"; \Elgg\Application::start(); // Get videolist item GUID $guid = (int) get_input('guid', 0); // Get file thumbnail size $size = get_input('size', 'small'); $item = get_entity($guid); if (!elgg_instanceof($item, 'object', 'videolist_item')) { exit; } $readfile = new ElggFile(); $readfile->owner_guid = $item->owner_guid; $readfile->setFilename("videolist/{$item->guid}.jpg"); if ($readfile->exists()) { $contents = $readfile->grabFile(); $content_length = strlen($contents); header("Content-type: image/jpeg"); // cache image for 10 days header('Expires: ' . date('r', time() + 864000)); header("Pragma: public", true); header("Cache-Control: public", true); } else { // icon was deleted // stop using this script to fetch thumb $ignore_access = elgg_set_ignore_access(true); $item->deleteMetadata('thumbnail'); elgg_set_ignore_access($ignore_access); if (in_array($size, array('tiny', 'medium', 'small'))) { $filename = elgg_get_plugins_path() . "videolist/graphics/videolist_icon_{$size}.png";
/** * Deletes the previous uploaded icon * * @param string $type Icon type * @return bool */ public function deleteIcon($type = 'icon') { if ($type == 'icon') { $fh = new \ElggFile(); $fh->owner_guid = $this->guid; $icon_sizes = elgg_get_icon_sizes('object', 'event'); foreach ($icon_sizes as $name => $info) { $fh->setFilename("{$name}.jpg"); if ($fh->exists()) { $fh->delete(); } } unset($this->icontime); } return parent::deleteIcon($type); }
/** * This makes sure that the image is present (builds it if it isn't) and then * displays it. */ function identicon_check($entity) { //make sure the image functions are available before trying to make avatars if (function_exists("imagecreatetruecolor")) { // entity is group, user or something else? if ($entity instanceof ElggGroup) { $file = new ElggFile(); $file->owner_guid = $entity->owner_guid; $seed = identicon_seed($entity); $file->setFilename('identicon/' . $seed . '/master.jpg'); $file->setMimeType('image/jpeg'); if (!$file->exists()) { if (identicon_build_group($seed, $file)) { return true; } else { // there was some error building the icon return false; } } else { // file's already there return true; } } else { if ($entity instanceof ElggUser) { $file = new ElggFile(); $file->owner_guid = $entity->getGUID(); $seed = identicon_seed($entity); $file->setFilename('identicon/' . $seed . '/master.jpg'); $file->setMimeType('image/jpeg'); if (!$file->exists()) { if (identicon_build($seed, $file)) { return true; } else { // there was some error building the icon return false; } } else { // file's already there return true; } } else { // neither group nor user return false; } } } // we can't build the icon return false; }
/** * Removes the file cache for keywords * * @return void */ function search_advanced_clear_keywords_cache() { $plugin_entity = elgg_get_plugin_from_id("search_advanced"); if ($plugin_entity) { // check if cachefile exists, if exists delete it $file = new ElggFile(); $file->owner_guid = $plugin_entity->getGUID(); $file->setFilename("search_advanced_keywords_cache.json"); if ($file->exists()) { $file->delete(); } } }
/** * Outputs raw icon * * @param int $entity_guid GUID of an entity * @param string $size Icon size * @return void */ public function outputRawIcon($entity_guid, $size = null) { if (headers_sent()) { exit; } $ha = access_get_show_hidden_status(); access_show_hidden_entities(true); $entity = get_entity($entity_guid); if (!$entity) { exit; } $size = strtolower($size ?: 'medium'); $filename = "icons/" . $entity->guid . $size . ".jpg"; $etag = md5($entity->icontime . $size); $filehandler = new \ElggFile(); $filehandler->owner_guid = $entity->owner_guid; $filehandler->setFilename($filename); if ($filehandler->exists()) { $filehandler->open('read'); $contents = $filehandler->grabFile(); $filehandler->close(); } else { forward('', '404'); } $mimetype = $entity->mimetype ? $entity->mimetype : 'image/jpeg'; access_show_hidden_entities($ha); header("Content-type: {$mimetype}"); header("Etag: {$etag}"); header('Expires: ' . date('r', time() + 864000)); header("Pragma: public"); header("Cache-Control: public"); header("Content-Length: " . strlen($contents)); echo $contents; exit; }
/** * Removes the thumbnail * * @return void */ public function removeThumbnail() { if (empty($this->icontime)) { return; } $fh = new \ElggFile(); $fh->owner_guid = $this->getGUID(); $prefix = 'thumb'; $icon_sizes = elgg_get_config('icon_sizes'); if (empty($icon_sizes)) { return; } foreach ($icon_sizes as $size => $info) { $fh->setFilename($prefix . $size . '.jpg'); if ($fh->exists()) { $fh->delete(); } } unset($this->icontime); }
/** * Use a URL for avatars that avoids loading Elgg engine for better performance * * @param string $hook * @param string $entity_type * @param string $return_value * @param array $params * @return string */ function profile_override_avatar_url($hook, $entity_type, $return_value, $params) { // if someone already set this, quit if ($return_value) { return null; } $user = $params['entity']; $size = $params['size']; if (!elgg_instanceof($user, 'user')) { return null; } $user_guid = $user->getGUID(); $icon_time = $user->icontime; if (!$icon_time) { return "_graphics/icons/user/default{$size}.gif"; } if ($user->isBanned()) { return null; } $filehandler = new ElggFile(); $filehandler->owner_guid = $user_guid; $filehandler->setFilename("profile/{$user_guid}{$size}.jpg"); try { if ($filehandler->exists()) { $join_date = $user->getTimeCreated(); return "mod/profile/icondirect.php?lastcache={$icon_time}&joindate={$join_date}&guid={$user_guid}&size={$size}"; } } catch (InvalidParameterException $e) { elgg_log("Unable to get profile icon for user with GUID {$user_guid}", 'ERROR'); return "_graphics/icons/default/{$size}.png"; } return null; }
/** * Set the correct url for group thumbnails * * @param string $hook name of the hook * @param string $type type of the hook * @param string $return_value current return value * @param array $params supplied params * * @return string */ function groups_tools_group_icon_url_handler($hook, $type, $return_value, $params) { if (empty($params) || !is_array($params)) { return $return_value; } $group = elgg_extract("entity", $params); if (empty($group) || !elgg_instanceof($group, "group")) { return $return_value; } $size = elgg_extract("size", $params, "medium"); $iconsizes = elgg_get_config("icon_sizes"); if (empty($size) || empty($iconsizes) || !array_key_exists($size, $iconsizes)) { return $return_value; } $icontime = $group->icontime; if (is_null($icontime)) { $icontime = 0; // handle missing metadata (pre 1.7 installations) // @see groups_icon_url_override() $fh = new ElggFile(); $fh->owner_guid = $group->getOwnerGUID(); $fh->setFilename("groups/{$group->getGUID()}large.jpg"); if ($fh->exists()) { $icontime = time(); } create_metadata($group->getGUID(), "icontime", $icontime, "integer", $group->getOwnerGUID(), ACCESS_PUBLIC); } if (empty($icontime)) { return $return_value; } $params = array("group_guid" => $group->getGUID(), "guid" => $group->getOwnerGUID(), "size" => $size, "icontime" => $icontime); return elgg_http_add_url_query_elements("mod/group_tools/pages/groups/thumbnail.php", $params); }
/** * Gets tree html from cache * * @param ElggEntity $entity root page to get the cache for * * @return false|string */ function pages_tools_get_tree_html_from_cache(ElggEntity $entity) { if (!$entity) { return false; } $user_guid = elgg_get_logged_in_user_guid(); if (empty($user_guid)) { $user_guid = 'logged-out'; } $file_name = 'tree_cache/' . md5($user_guid . '-cached-' . $entity->getGUID()) . '.html'; $fh = new ElggFile(); $fh->owner_guid = $entity->getGUID(); $fh->setFilename($file_name); if (!$fh->exists()) { return false; } return $fh->grabFile(); }
/** * Custom icon only on this site * * @param string $hook the name of the hook * @param string $type the type of the hook * @param string $return_value current return value * @param array $params supplied params * * @return string */ function theme_haarlem_intranet_profile_icon($hook, $type, $return_value, $params) { if (!elgg_is_logged_in()) { return; } if (empty($params) || !is_array($params)) { return; } $user = elgg_extract('entity', $params); if (empty($user) || !$user instanceof ElggUser) { return; } if (!$user->haarlem_icontime) { return; } $size = elgg_extract('size', $params); $icon_sizes = elgg_get_config('icon_sizes'); if (!isset($icon_sizes[$size])) { return; } $fh = new ElggFile(); $fh->owner_guid = $user->getGUID(); $fh->setFilename("haarlem_icon/{$size}.jpg"); if (!$fh->exists()) { return; } return "haarlem_avatar/{$user->getGUID()}/{$size}/{$user->haarlem_icontime}.jpg"; }
<?php $user = elgg_extract('user', $vars); if (!$user instanceof ElggUser) { return; } $icontime = $user->icontime; if (empty($icontime)) { return; } $user_guid = $user->getGUID(); $filehandler = new ElggFile(); $filehandler->owner_guid = $user_guid; $filehandler->setFilename("profile/{$user_guid}master.jpg"); if ($filehandler->exists()) { $image_data = $filehandler->grabFile(); } if (empty($image_data)) { return; } $x1 = $user->x1; $x2 = $user->x2; $y1 = $user->y1; $y2 = $user->y2; if ($x1 === null) { return $image_data; } // apply user cropping config // create temp file for resizing $tmpfname = tempnam(elgg_get_data_path(), 'elgg_avatar_service'); $handle = fopen($tmpfname, 'w');
/** * This hooks into the getIcon API and provides nice user icons for users where possible. * * @param unknown_type $hook * @param unknown_type $entity_type * @param unknown_type $returnvalue * @param unknown_type $params * @return unknown */ function groups_groupicon_hook($hook, $entity_type, $returnvalue, $params) { global $CONFIG; if (!$returnvalue && $hook == 'entity:icon:url' && $params['entity'] instanceof ElggGroup) { $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("groups/" . $entity->guid . $size . ".jpg"); if ($filehandler->exists()) { $url = $CONFIG->url . "pg/groupicon/{$entity->guid}/{$size}/{$icontime}.jpg"; return $url; } } }
/** * Override the default entity icon for groups * * @param string $hook * @param string $type * @param string $url * @param array $params * @return string Relative URL */ function groups_set_icon_url($hook, $type, $url, $params) { /* @var ElggGroup $group */ $group = $params['entity']; $size = $params['size']; $icontime = $group->icontime; // handle missing metadata (pre 1.7 installations) if (null === $icontime) { $file = new ElggFile(); $file->owner_guid = $group->owner_guid; $file->setFilename("groups/" . $group->guid . "large.jpg"); $icontime = $file->exists() ? time() : 0; create_metadata($group->guid, 'icontime', $icontime, 'integer', $group->owner_guid, ACCESS_PUBLIC); } if ($icontime) { // return thumbnail return "groupicon/{$group->guid}/{$size}/{$icontime}.jpg"; } return elgg_get_simplecache_url("groups/default{$size}.gif"); }
<?php elgg_admin_gatekeeper(); $guid = (int) get_input('guid'); $filename = get_input('file'); $entity = get_entity($guid); if (empty($filename) || !elgg_instanceof($entity, 'object', 'profile_sync_config')) { return; } $fh = new ElggFile(); $fh->owner_guid = $entity->getGUID(); $fh->setFilename($filename); if (!$fh->exists()) { echo elgg_echo('notfound'); return; } list($time) = explode('.', $filename); $datetime = date(elgg_echo('friendlytime:date_format'), $time); $content = elgg_view('output/longtext', ['value' => $fh->grabFile()]); $content .= elgg_view('output/url', ['text' => elgg_echo('back'), 'href' => 'ajax/view/profile_sync/sync_logs/?guid=' . $entity->getGUID(), 'is_trusted' => true, 'class' => 'elgg-lightbox float-alt']); echo elgg_view_module('inline', elgg_echo('profile_sync:view_log:title', [$entity->title, $datetime]), $content, ['class' => 'profile-sync-log-wrapper']);