/** * Pull in the latest avatar from twitter. * * @param unknown_type $user * @param unknown_type $file_location */ function twitter_api_update_user_avatar($user, $file_location) { // twitter's images have a few suffixes: // _normal // _resonably_small // _mini // the twitter app here returns _normal. We want standard, so remove the suffix. // @todo Should probably check that it's an image file. $file_location = str_replace('_normal.jpg', '.jpg', $file_location); $sizes = array('topbar' => array(16, 16, TRUE), 'tiny' => array(25, 25, TRUE), 'small' => array(40, 40, TRUE), 'medium' => array(100, 100, TRUE), 'large' => array(200, 200, FALSE), 'master' => array(550, 550, FALSE)); $filehandler = new ElggFile(); $filehandler->owner_guid = $user->getGUID(); foreach ($sizes as $size => $dimensions) { $image = get_resized_image_from_existing_file($file_location, $dimensions[0], $dimensions[1], $dimensions[2]); $filehandler->setFilename("profile/{$user->guid}{$size}.jpg"); $filehandler->open('write'); $filehandler->write($image); $filehandler->close(); } // update user's icontime $user->icontime = time(); return TRUE; }
/** * Pull in the latest avatar from facebook. * * @param unknown_type $user * @param unknown_type $file_location */ function facebook_connect_update_user_avatar($user, $file_location) { global $CONFIG; $tempfile = $CONFIG->dataroot . $user->getGUID() . 'img.jpg'; $imgContent = file_get_contents($file_location); $fp = fopen($tempfile, "w"); fwrite($fp, $imgContent); fclose($fp); $sizes = array('topbar' => array(16, 16, TRUE), 'tiny' => array(25, 25, TRUE), 'small' => array(40, 40, TRUE), 'medium' => array(100, 100, TRUE), 'large' => array(200, 200, FALSE), 'master' => array(550, 550, FALSE)); $filehandler = new ElggFile(); $filehandler->owner_guid = $user->getGUID(); foreach ($sizes as $size => $dimensions) { $image = get_resized_image_from_existing_file($tempfile, $dimensions[0], $dimensions[1], $dimensions[2]); $filehandler->setFilename("profile/{$user->guid}{$size}.jpg"); $filehandler->open('write'); $filehandler->write($image); $filehandler->close(); } // update user's icontime $user->icontime = time(); return TRUE; }
/** * Creates random annotations on $entity * * @param unknown_type $entity * @param unknown_type $max */ public function createRandomAnnotations($entity, $max = 1) { $annotations = array(); for ($i = 0; $i < $max; $i++) { $name = 'test_annotation_name_' . rand(); $value = rand(); $id = create_annotation($entity->getGUID(), $name, $value, 'integer', $entity->getGUID()); $annotations[] = elgg_get_annotation_from_id($id); } return $annotations; }