diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/album.php | 23 | ||||
| -rw-r--r-- | lib/exif.php | 79 | ||||
| -rw-r--r-- | lib/image.php | 195 | ||||
| -rw-r--r-- | lib/migrate.php | 293 | ||||
| -rw-r--r-- | lib/resize.php | 543 | ||||
| -rw-r--r-- | lib/tidypics.php | 186 | ||||
| -rw-r--r-- | lib/watermark.php | 140 |
7 files changed, 0 insertions, 1459 deletions
diff --git a/lib/album.php b/lib/album.php deleted file mode 100644 index 7e03ed6eb..000000000 --- a/lib/album.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - /** - * Tidypics Album class - * - */ - - - class TidypicsAlbum extends ElggObject - { - protected function initialise_attributes() - { - parent::initialise_attributes(); - - $this->attributes['subtype'] = "album"; - } - - public function __construct($guid = null) - { - parent::__construct($guid); - } - } - -?>
\ No newline at end of file diff --git a/lib/exif.php b/lib/exif.php deleted file mode 100644 index 81f5dd960..000000000 --- a/lib/exif.php +++ /dev/null @@ -1,79 +0,0 @@ -<?php - -function td_get_exif($file) { - - // catch for those who don't have exif module loaded - if (!is_callable('exif_read_data')) - return; - - $mime = $file->mimetype; - if ($mime != 'image/jpeg' && $mime != 'image/pjpeg') - return; - - $filename = $file->getFilenameOnFilestore(); - $exif = exif_read_data($filename); - create_metadata($file->getGUID(), "tp_exif", serialize($exif), "text", $file->getObjectOwnerGUID(), ACCESS_PUBLIC); -} - -function tp_exif_formatted($file_guid) { - - $metadata_exif = get_metadata_byname($file_guid, "tp_exif"); - if (!$metadata_exif) { //try to load it from the file if its not in the database - $file = new ElggFile($file_guid); - td_get_exif($file); - unset($file); - $metadata_exif = get_metadata_byname($file_guid, "tp_exif"); - } - - if (!$metadata_exif) { - return false; - } - - $exif = unserialize($metadata_exif["value"]); - - $model = $exif['Model']; - if(!$model) $model = "N/A"; - $exif_data['Model'] = $model; - - $exposure = $exif['ExposureTime']; - if (!$exposure) $exposure = "N/A"; - $exif_data['Shutter'] = $exposure; - - //got the code snippet below from http://www.zenphoto.org/support/topic.php?id=17 - //convert the raw values to understandible values - $Fnumber = explode("/", $exif['FNumber']); - if ($Fnumber[1] != 0) - $Fnumber = $Fnumber[0] / $Fnumber[1]; - else - $Fnumber = 0; - if (!$Fnumber) { - $Fnumber = "N/A"; - } else { - $Fnumber = "f/$Fnumber"; - } - $exif_data['Aperture'] = $Fnumber; - - $iso = $exif['ISOSpeedRatings']; - if (!$iso) $iso = "N/A"; - $exif_data['ISO Speed'] = $iso; - - $Focal = explode("/", $exif['FocalLength']); - if ($Focal[1] != 0) - $Focal = $Focal[0] / $Focal[1]; - else - $Focal = 0; - if (!$Focal || round($Focal) == "0") $Focal = 0; - if (round($Focal) == 0) { - $Focal = "N/A"; - } else { - $Focal = round($Focal) . "mm"; - } - $exif_data['Focal Length'] = $Focal; - - $captured = $exif['DateTime']; - if (!$captured) $captured = "N/A"; - $exif_data['Captured'] = $captured; - - return $exif_data; -} -?>
\ No newline at end of file diff --git a/lib/image.php b/lib/image.php deleted file mode 100644 index f782f0386..000000000 --- a/lib/image.php +++ /dev/null @@ -1,195 +0,0 @@ -<?php - /** - * Tidypics Image class - * - */ - - - class TidypicsImage extends ElggFile - { - protected function initialise_attributes() - { - parent::initialise_attributes(); - - $this->attributes['subtype'] = "image"; - } - - public function __construct($guid = null) - { - parent::__construct($guid); - } - - /** - * Has the photo been tagged with "in this photo" tags - * - * @return true/false - */ - public function isPhotoTagged() - { - $num_tags = count_annotations($this->getGUID(), 'object', 'image', 'phototag'); - if ($num_tags > 0) - return true; - else - return false; - } - - /** - * Get an array of photo tag information - * - * @return array of json representations of the tags and the tag link text - */ - public function getPhotoTags() - { - global $CONFIG; - - // get tags as annotations - $photo_tags = get_annotations($this->getGUID(), 'object', 'image', 'phototag'); - if (!$photo_tags) - { - // no tags or user doesn't have permission to tags, so return - return false; - } - - $photo_tags_json = "["; - foreach ($photo_tags as $p) - { - $photo_tag = unserialize($p->value); - - // create link to page with other photos tagged with same tag - $phototag_text = $photo_tag->value; - $phototag_link = $CONFIG->wwwroot . 'search/?tag=' . $phototag_text . '&subtype=image&object=object'; - if ($photo_tag->type === 'user') - { - $user = get_entity($photo_tag->value); - if ($user) - $phototag_text = $user->name; - else - $phototag_text = "unknown user"; - - $phototag_link = $CONFIG->wwwroot . "pg/photos/tagged/" . $photo_tag->value; - } - - if (isset($photo_tag->x1)) { - // hack to handle format of Pedro Prez's tags - ugh - $photo_tag->coords = "\"x1\":\"{$photo_tag->x1}\",\"y1\":\"{$photo_tag->y1}\",\"width\":\"{$photo_tag->width}\",\"height\":\"{$photo_tag->height}\""; - $photo_tags_json .= '{' . $photo_tag->coords . ',"text":"' . $phototag_text . '","id":"' . $p->id . '"},'; - } else - $photo_tags_json .= '{' . $photo_tag->coords . ',"text":"' . $phototag_text . '","id":"' . $p->id . '"},'; - - // prepare variable arrays for tagging view - $photo_tag_links[$p->id] = array('text' => $phototag_text, 'url' => $phototag_link); - } - - $photo_tags_json = rtrim($photo_tags_json,','); - $photo_tags_json .= ']'; - - $ret_data = array('json' => $photo_tags_json, 'links' => $photo_tag_links); - return $ret_data; - } - - /** - * Get the view information for this image - * - * @param $viewer_guid the guid of the viewer (0 if not logged in) - * @return array with number of views, number of unique viewers, and number of views for this viewer - */ - public function getViews($viewer_guid) - { - $views = get_annotations($this->getGUID(), "object", "image", "tp_view", "", 0, 9999); - if ($views) - { - $total_views = count($views); - - if ($this->owner_guid == $viewer_guid) - { - // get unique number of viewers - foreach ($views as $view) - { - $diff_viewers[$view->owner_guid] = 1; - } - $unique_viewers = count($diff_viewers); - } - else if ($viewer_guid) - { - // get the number of times this user has viewed the photo - $my_views = 0; - foreach ($views as $view) - { - if ($view->owner_guid == $viewer_guid) - $my_views++; - } - } - - $view_info = array("total" => $total_views, "unique" => $unique_viewers, "mine" => $my_views); - } - else - { - $view_info = array("total" => 0, "unique" => 0, "mine" => 0); - } - - return $view_info; - } - - /** - * Add a tidypics view annotation to this image - * - * @param $viewer_guid - * @return none - */ - public function addView($viewer_guid) - { - if ($viewer_guid != $this->owner_guid) - create_annotation($this->getGUID(), "tp_view", "1", "integer", $viewer_guid, ACCESS_PUBLIC); - } - } - - /** - * get a list of people that can be tagged in an image - * - * @param $viewer entity - * @return array of guid->name for tagging - */ - function tp_get_tag_list($viewer) - { - $friends = get_user_friends($viewer->getGUID(), '', 999, 0); - $friend_list = array(); - if ($friends) { - foreach($friends as $friend) { - //error_log("friend $friend->name"); - $friend_list[$friend->guid] = $friend->name; - } - } - - // is this a group - $is_group = tp_is_group_page(); - if ($is_group) - { - $group_guid = page_owner(); - $viewer_guid = $viewer->guid; - $members = get_group_members($group_guid, 999); - if (is_array($members)) - { - foreach ($members as $member) - { - if ($viewer_guid != $member->guid) - { - $group_list[$member->guid] = $member->name; - //error_log("group $member->name"); - } - } - - // combine group and friends list - $intersect = array_intersect_key($friend_list, $group_list); - $unique_friends = array_diff_key($friend_list, $group_list); - $unique_members = array_diff_key($group_list, $friend_list); - //$friend_list = array_merge($friend_list, $group_list); - //$friend_list = array_unique($friend_list); - $friend_list = $intersect + $unique_friends + $unique_members; - } - } - - asort($friend_list); - - return $friend_list; - } -?>
\ No newline at end of file diff --git a/lib/migrate.php b/lib/migrate.php deleted file mode 100644 index ca68ec8c4..000000000 --- a/lib/migrate.php +++ /dev/null @@ -1,293 +0,0 @@ -<?php - -// need access to ElggDiskFilestore::make_file_matrix(), which is protected. -// this is a PITA. -class tempFilestore extends ElggDiskFilestore { - public function make_file_matrix($filename) { - return parent::make_file_matrix($filename); - } - -} -$filestore = new tempFilestore(); - - - -/** - * Migrates all pics from files to tidypics. - * - */ -function tidypics_migrate_pics() { - $limit = 100; - $r = true; - - // migrate - // @todo: should this return false since there was no error? - if (!$users = tidypics_get_user_guids_with_pics_in_files(0, $limit)) { - return $r; - } - - //echo "Grabbed " . count($users) . " users\n"; - while (is_array($users) AND count($users) > 0) { - foreach ($users as $user_guid) { - // reset the query cache. - $DB_QUERY_CACHE = array(); - if (!$user = get_entity($user_guid)) { - continue; - } - - $r = tidypics_migrate_user_pics($user); - } - - //echo "Trying to grab $limit more users...\n"; - $offset = $offset + $limit; - $users = tidypics_get_user_guids_with_pics_in_files($offset, $limit); - } - - return $r; -} - - -/** - * Migrates all pictures owned by a user regardless of - * if they're group or user files. - * - * @param ElggUser $user User to migrate. - * @return bool on success - */ -function tidypics_migrate_user_pics(ElggUser $user) { - global $CONFIG, $filestore; - - $user_guid = $user->getGUID(); - - // update all entity subtypes in a single go at the end. - $updated_guids = array(); - - if (!$pics = tidypics_get_user_pics_from_files($user_guid) OR count($pics) < 1) { - return false; - } - - //echo "{$user->name} ({$user->getGUID()}) has " . count($pics) . " pics.\n"; - - // get an album to migrate into if it already exists. - // will create later on if it doesn't. - $user_album_entities = get_entities_from_metadata('migrated_from_files', true, 'object', 'album', $user->getGUID(), 1); - $user_album_guid = isset($album_entities[0]) ? $album_entities[0]->getGUID() : false; - - // a list of albums to randomly select a cover for on newly created albums. - $new_album_guids = array(); - - foreach ($pics as $pic) { - // check that it's not already in tidy pics - if (false !== strpos($pic->filename, 'image/')) { - //echo "{$pic->filename} ({$pic->getGUID()}) looks like it's already in tidy pics. Ignoring.\n"; - continue; - } - - // blank some vars - $group_pic = $group_album_guid = $group_guid = false; - - // see if we're doing a group file migration. - if ($pic->container_guid != $user->getGUID() - AND $group = get_entity($pic->container_guid) - AND $group instanceof ElggGroup - ) { - //echo "{$pic->getGUID()} is in a group!\n"; - $group_pic = true; - $group_guid = $group->getGUID(); - - // yes, this is how you get entities by container_guid. - // yes, it's wrong, wrong, wrong for this function to work this way. - $group_album_entities = get_entities('object', 'album', $group_guid); - - // get_entities_from_metadata doesn't support container_guid (or owner_guid meaning container_guid) - // do it the hard way. - if (is_array($group_album_entities)) { - foreach ($group_album_entities as $group_album) { - if ($group_album->migrated_from_files == true) { - $group_album_guid = $group_album->getGUID(); - break; - } - } - } - $album_guid = $group_album_guid; - $group_album_guids[] = $group_album_guid; - } else { - $album_guid = $user_album_guid; - } - - //echo "album_guid is $album_guid and group_pic is: $group_pic\n"; - - // create an album if we need to. - if (!$album_guid) { - //echo "Creating new album...\n"; - $album = new ElggObject(); - $album->subtype = 'album'; - $album->new_album = TP_NEW_ALBUM; - - if ($group_pic) { - $album->container_guid = $group_guid; - $album->owner_guid = $group->owner_guid; - $album->access_id = $group->group_acl; - $album->title = $group->name; - } else { - $album->container_guid = $user_guid; - $album->owner_guid = $user->getGUID(); - $album->access_id = ACCESS_DEFAULT; - $album->title = $user->name; - } - - if (!$album->save()) { - //echo "Couldn't migrate pics for {$user->name} ($user_guid)!\n"; - return false; - } - $album->migrated_from_files = true; - $album_guid = $album->getGUID(); - $new_album_guids[] = $album_guid; - - // save the album guid as the users - if (!$group_pic) { - $user_album_guid = $album_guid; - } - } - - if (!tidypics_migrate_pic_from_files($pic, $album_guid)) { - //echo "{$pic->filename} ({$pic->getGUID()}) Couldn't be migrated. Ignoring.\n"; - continue; - } - } - - // randomly pic an image to be the cover for the user gallery - //$album->cover = $pic_guids[array_rand($pic_guids)]; - foreach ($new_album_guids as $guid) { - tidypics_set_random_cover_pic($guid); - } - - return true; -} - - -/** - * Randomly pics an image from an album to be the cover. - * @return bool on success - */ -function tidypics_set_random_cover_pic($album_guid) { - global $CONFIG; - - if ($album = get_entity($album_guid) AND $album instanceof TidypicsAlbum) { - $q = "SELECT guid FROM {$CONFIG->dbprefix}entities WHERE container_guid = $album_guid ORDER BY RAND() limit 1"; - $pic = get_data($q); - - return $album->cover = $pic[0]->guid; - } - - return false; -} - -/** - * Migrates a single pic from the file repo. - * @return bool on succes. - */ -function tidypics_migrate_pic_from_files($pic, $album_guid) { - global $CONFIG, $filestore; - - // get the subtype id. - $image_subtype_id = get_subtype_id('object', 'image'); - - // hold which metadata on the files need to be changes - // also holds the images we need to move - $file_md_fields = array('filename', 'thumbnail', 'smallthumb', 'largethumb'); - - if (!$user = get_entity($pic->owner_guid)) { - return false; - } - - // figure out where to move the files. - $matrix = $filestore->make_file_matrix($user->username); - $user_fs_path = $CONFIG->dataroot . $matrix; - $album_fs_path = $CONFIG->dataroot . $matrix . "image/$album_guid/"; - if (!is_dir($album_fs_path)) { - if (!mkdir($album_fs_path, 0700, true)) { - return false; - } - } - - // change all the 'file/'s to 'image/'s in certain metadata - // these are also the files we need to move. - foreach ($file_md_fields as $md_name) { - // $pic->$md_name = str_replace('file/', 'image/', $pic->$md_name); - $old_file = $pic->$md_name; - $new_file = str_replace('file/', "image/$album_guid", $old_file); - - if (!($old_fp = fopen($user_fs_path . $old_file, 'r') - AND $new_fp = fopen($user_fs_path . $new_file, 'w'))) { - //echo "Could not move {$user_fs_path}{$old_file} to {$user_fs_path}{$new_file}\n"; - continue; - } - - while (!feof($old_fp)) { - if (!fputs($new_fp, fread($old_fp, 8192))) { - //echo "Could not move {$user_fs_path}{$old_file} to {$user_fs_path}{$new_file} (Error writing.)\n"; - break; - } - } - - $pic->$md_name = $new_file; - } - // update container. - // this doesn't work...? - //$pic->container_guid = $album_guid; - - // delete old one. - unlink($user_fs_path . $old_file); - - $q = "UPDATE {$CONFIG->dbprefix}entities SET subtype = $image_subtype_id, container_guid = $album_guid WHERE guid = {$pic->getGUID()}"; - //echo "Finished moving {$user_fs_path}{$old_file} to {$user_fs_path}{$new_file}\n"; - - return update_data($q); -} - - -/** - * Grabs all user IDs with images in the files repo. - * return mixed. False on fail, array of GUIDs on success. - */ -function tidypics_get_user_guids_with_pics_in_files($offset, $limit) { - global $CONFIG; - - //$simpletype_ms_id = add_metastring('simple_type'); - //$image_ms_id = add_metastring('image'); - - $q = "SELECT DISTINCT e.owner_guid - FROM - {$CONFIG->dbprefix}entities as e, - {$CONFIG->dbprefix}entity_subtypes as st - - WHERE st.subtype = 'file' - AND e.subtype = st.id - LIMIT $offset, $limit"; - - if (!$data = get_data($q)) { - return false; - } - - // return an array of IDs - $r = array(); - foreach ($data as $row) { - $r[] = $row->owner_guid; - } - - return $r; -} - -/** - * Gets a list of images for a single user. - * @return array of GUIDs, false on fail. - */ -function tidypics_get_user_pics_from_files($user_guid) { - if (!$user = get_entity($user_guid) AND $user instanceof ElggUser) { - return false; - } - - // @todo Might have to cycle this through with standard while + foreach. - return get_entities_from_metadata('simpletype', 'image', 'object', 'file', $user_guid, 5000); -} diff --git a/lib/resize.php b/lib/resize.php deleted file mode 100644 index 803cb8fa7..000000000 --- a/lib/resize.php +++ /dev/null @@ -1,543 +0,0 @@ -<?php
- /**
- * Elgg tidypics library of resizing functions
- *
- */
-
- include dirname(__FILE__) . "/watermark.php";
-
-
- /**
- * Create thumbnails using PHP GD Library
- *
- * @param ElggFile holds the image that was uploaded
- * @param string folder to store thumbnail in
- * @param string name of the thumbnail
- * @return bool true on success
- */
- function tp_create_gd_thumbnails($file, $prefix, $filestorename)
- {
- global $CONFIG;
-
- $image_sizes = get_plugin_setting('image_sizes', 'tidypics');
- if (!$image_sizes) {
- register_error(elgg_echo('tidypics:nosettings'));
- forward($_SERVER['HTTP_REFERER']);
- return false;
- }
- $image_sizes = unserialize($image_sizes);
-
- $thumb = new ElggFile();
-
- // tiny thumbail
- $thumb->setFilename($prefix."thumb".$filestorename);
- $thumbname = $thumb->getFilenameOnFilestore();
- $rtn_code = tp_gd_resize( $file->getFilenameOnFilestore(),
- $thumbname,
- false,
- $image_sizes['thumb_image_width'],
- $image_sizes['thumb_image_height'],
- true);
- if (!$rtn_code)
- return false;
- $file->thumbnail = $prefix."thumb".$filestorename;
-
-
- // album thumbnail
- $thumb->setFilename($prefix."smallthumb".$filestorename);
- $thumbname = $thumb->getFilenameOnFilestore();
- $rtn_code = tp_gd_resize( $file->getFilenameOnFilestore(),
- $thumbname,
- false,
- $image_sizes['small_image_width'],
- $image_sizes['small_image_height'],
- true);
- if (!$rtn_code)
- return false;
- $file->smallthumb = $prefix."smallthumb".$filestorename;
-
-
- // main image
- $thumb->setFilename($prefix."largethumb".$filestorename);
- $thumbname = $thumb->getFilenameOnFilestore();
- $rtn_code = tp_gd_resize( $file->getFilenameOnFilestore(),
- $thumbname,
- true,
- $image_sizes['large_image_width'],
- $image_sizes['large_image_height'],
- false);
- if (!$rtn_code)
- return false;
- $file->largethumb = $prefix."largethumb".$filestorename;
-
-
- unset($thumb);
-
- return true;
- }
-
- /**
- * Writes resized version of an already uploaded image - original from Elgg filestore.php
- * Saves it in the same format as uploaded
- *
- * @param string $input_name The name of the file on the disk
- * @param string $output_name The name of the file to be written
- * @param bool - watermark this image?
- * @param int $maxwidth The maximum width of the resized image
- * @param int $maxheight The maximum height of the resized image
- * @param true|false $square If set to true, will take the smallest of maxwidth and maxheight and use it to set the dimensions on all size; the image will be cropped.
- * @return bool true on success or false on failure
- */
- function tp_gd_resize($input_name, $output_name, $watermark, $maxwidth, $maxheight, $square = false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0) {
-
- // Get the size information from the image
- $imgsizearray = getimagesize($input_name);
- if (!imgsizearray)
- return false;
-
- // Get width and height
- $width = $imgsizearray[0];
- $height = $imgsizearray[1];
- $newwidth = $width;
- $newheight = $height;
-
- // Square the image dimensions if we're wanting a square image
- if ($square) {
- if ($width < $height) {
- $height = $width;
- } else {
- $width = $height;
- }
-
- $newwidth = $width;
- $newheight = $height;
-
- }
-
- if ($width > $maxwidth) {
- $newheight = floor($height * ($maxwidth / $width));
- $newwidth = $maxwidth;
- }
- if ($newheight > $maxheight) {
- $newwidth = floor($newwidth * ($maxheight / $newheight));
- $newheight = $maxheight;
- }
-
- $accepted_formats = array(
- 'image/jpeg' => 'jpeg',
- 'image/pjpeg' => 'jpeg',
- 'image/png' => 'png',
- 'image/x-png' => 'png',
- 'image/gif' => 'gif'
- );
-
- // make sure the function is available
- $function = "imagecreatefrom" . $accepted_formats[$imgsizearray['mime']];
- if (!is_callable($function))
- return false;
-
-
- // load old image
- $oldimage = $function($input_name);
- if (!$oldimage)
- return false;
-
- // allocate the new image
- $newimage = imagecreatetruecolor($newwidth, $newheight);
- if (!$newimage)
- return false;
-
- // Crop the image if we need a square
- if ($square) {
- if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) {
- $widthoffset = floor(($imgsizearray[0] - $width) / 2);
- $heightoffset = floor(($imgsizearray[1] - $height) / 2);
- } else {
- $widthoffset = $x1;
- $heightoffset = $y1;
- $width = ($x2 - $x1);
- $height = $width;
- }
- } else {
- if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) {
- $widthoffset = 0;
- $heightoffset = 0;
- } else {
- $widthoffset = $x1;
- $heightoffset = $y1;
- $width = ($x2 - $x1);
- $height = ($y2 - $y1);
- }
- }
-
- if ($square) {
- $newheight = $maxheight;
- $newwidth = $maxwidth;
- }
-
- $rtn_code = imagecopyresampled($newimage, $oldimage, 0,0,$widthoffset,$heightoffset,$newwidth,$newheight,$width,$height);
- if (!rtn_code)
- return $rtn_code;
-
- if ($watermark)
- tp_gd_watermark($newimage);
-
- switch ($imgsizearray['mime']) {
- case 'image/jpeg':
- case 'image/pjpeg':
- $rtn_code = imagejpeg($newimage, $output_name, 85);
- break;
- case 'image/png':
- case 'image/x-png':
- $rtn_code = imagepng($newimage, $output_name);
- break;
- case 'image/gif':
- $rtn_code = imagegif($newimage, $output_name);
- break;
- }
-
- imagedestroy($newimage);
- imagedestroy($oldimage);
-
- return $rtn_code;
- }
-
-
- /**
- * Create thumbnails using PHP ImageMagick Library
- *
- * @param ElggFile holds the image that was uploaded
- * @param string folder to store thumbnail in
- * @param string name of the thumbnail
- * @return bool true on success
- */
- function tp_create_imagick_thumbnails($file, $prefix, $filestorename)
- {
- $image_sizes = get_plugin_setting('image_sizes', 'tidypics');
- if (!$image_sizes) {
- register_error(elgg_echo('tidypics:nosettings'));
- return false;
- }
- $image_sizes = unserialize($image_sizes);
-
- $thumb = new ElggFile();
-
-
- // tiny thumbnail
- $thumb->setFilename($prefix."thumb".$filestorename);
- $thumbname = $thumb->getFilenameOnFilestore();
- $rtn_code = tp_imagick_resize( $file->getFilenameOnFilestore(),
- $thumbname,
- $image_sizes['thumb_image_width'],
- $image_sizes['thumb_image_height'],
- true);
- if (!$rtn_code)
- return false;
- $file->thumbnail = $prefix."thumb".$filestorename;
-
-
- // album thumbnail
- $thumb->setFilename($prefix."smallthumb".$filestorename);
- $thumbname = $thumb->getFilenameOnFilestore();
- $rtn_code = tp_imagick_resize( $file->getFilenameOnFilestore(),
- $thumbname,
- $image_sizes['small_image_width'],
- $image_sizes['small_image_height'],
- true);
- if (!$rtn_code)
- return false;
- $file->smallthumb = $prefix."smallthumb".$filestorename;
-
-
- // main image
- $thumb->setFilename($prefix."largethumb".$filestorename);
- $thumbname = $thumb->getFilenameOnFilestore();
- $rtn_code = tp_imagick_resize( $file->getFilenameOnFilestore(),
- $thumbname,
- $image_sizes['large_image_width'],
- $image_sizes['large_image_height'],
- false);
- if (!$rtn_code)
- return false;
- $file->largethumb = $prefix."largethumb".$filestorename;
-
- tp_imagick_watermark($thumbname);
-
- unset($thumb);
-
- return true;
- }
-
-
- /**
- * Resize using PHP ImageMagick Library
- *
- * Writes resized version of an already uploaded image
- *
- *
- * @param string $input_name The name of the file input field on the submission form
- * @param string $output_name The name of the file to be written
- * @param int $maxwidth The maximum width of the resized image
- * @param int $maxheight The maximum height of the resized image
- * @param true|false $square If set to true, will take the smallest of maxwidth and maxheight and use it to set the dimensions on all size; the image will be cropped.
- * @return bool true on success
- */
- function tp_imagick_resize($input_name, $output_name, $maxwidth, $maxheight, $square = false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0) {
-
- // Get the size information from the image
- $imgsizearray = getimagesize($input_name);
- if (!$imgsizearray)
- return false;
-
-
- // Get width and height
- $width = $imgsizearray[0];
- $height = $imgsizearray[1];
- $newwidth = $width;
- $newheight = $height;
-
- // initial guess at final dimensions for new image (doesn't check for squareness yet
- if ($newwidth > $maxwidth) {
- $newheight = floor($newheight * ($maxwidth / $newwidth));
- $newwidth = $maxwidth;
- }
- if ($newheight > $maxheight) {
- $newwidth = floor($newwidth * ($maxheight / $newheight));
- $newheight = $maxheight;
- }
-
- // Handle squareness for both original and new image
- if ($square) {
- if ($width < $height) {
- $height = $width;
- } else {
- $width = $height;
- }
-
- if ($maxheight == $maxwidth) {
- // if input arguments = square, no need to use above calculations (which can have round-off errors)
- $newwidth = $maxwidth;
- $newheight = $maxheight;
- } else {
- if ($newwidth < $newheight) {
- $newheight = $newwidth;
- } else {
- $newwidth = $newheight;
- }
- }
- }
-
-
- // Crop the original image - this needs to be checked over
- if ($square) {
- if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) {
- $xoffset = floor(($imgsizearray[0] - $width) / 2);
- $yoffset = floor(($imgsizearray[1] - $height) / 2);
- } else { // assume we're being passed good croping coordinates
- $xoffset = $x1;
- $yoffset = $y1;
- $width = ($x2 - $x1);
- $height = $width;
- }
- } else {
- if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) {
- $xoffset = 0;
- $yoffset = 0;
- } else {
- $xoffset = $x1;
- $yoffset = $y1;
- $width = ($x2 - $x1);
- $height = ($y2 - $y1);
- }
- }
-
-
- try {
- $img = new Imagick($input_name);
- } catch (ImagickException $e) {
- return false;
- }
-
- $img->cropImage($width, $height, $xoffset, $yoffset);
-
- // use the default IM filter (windowing filter), I think 1 means default blurring or number of lobes
- $img->resizeImage($newwidth, $newheight, imagick::FILTER_LANCZOS, 1);
- $img->setImagePage($newwidth, $newheight, 0, 0);
-
- if ($img->writeImage($output_name) != true) {
- $img->destroy();
- return false;
- }
-
- $img->destroy();
-
- return true;
- }
-
- /**
- * Create thumbnails using ImageMagick executables
- *
- * @param ElggFile holds the image that was uploaded
- * @param string folder to store thumbnail in
- * @param string name of the thumbnail
- * @return bool true on success
- */
- function tp_create_imagick_cmdline_thumbnails($file, $prefix, $filestorename)
- {
- $image_sizes = get_plugin_setting('image_sizes', 'tidypics');
- if (!$image_sizes) {
- register_error(elgg_echo('tidypics:nosettings'));
- return false;
- }
- $image_sizes = unserialize($image_sizes);
-
- $thumb = new ElggFile();
-
-
- // tiny thumbnail
- $thumb->setFilename($prefix."thumb".$filestorename);
- $thumbname = $thumb->getFilenameOnFilestore();
- $rtn_code = tp_imagick_cmdline_resize( $file->getFilenameOnFilestore(),
- $thumbname,
- $image_sizes['thumb_image_width'],
- $image_sizes['thumb_image_height'],
- true);
- if (!$rtn_code)
- return false;
- $file->thumbnail = $prefix."thumb".$filestorename;
-
-
- // album thumbnail
- $thumb->setFilename($prefix."smallthumb".$filestorename);
- $thumbname = $thumb->getFilenameOnFilestore();
- $rtn_code = tp_imagick_cmdline_resize( $file->getFilenameOnFilestore(),
- $thumbname,
- $image_sizes['small_image_width'],
- $image_sizes['small_image_height'],
- true);
- if (!$rtn_code)
- return false;
- $file->smallthumb = $prefix."smallthumb".$filestorename;
-
-
- // main image
- $thumb->setFilename($prefix."largethumb".$filestorename);
- $thumbname = $thumb->getFilenameOnFilestore();
- $rtn_code = tp_imagick_cmdline_resize( $file->getFilenameOnFilestore(),
- $thumbname,
- $image_sizes['large_image_width'],
- $image_sizes['large_image_height'],
- false);
- if (!$rtn_code)
- return false;
- $file->largethumb = $prefix."largethumb".$filestorename;
-
-
- tp_imagick_cmdline_watermark($thumbname);
-
-
-
- unset($thumb);
-
- return true;
- }
-
- /*
- * Gets the jpeg contents of the resized version of an already uploaded image
- * (Returns false if the uploaded file was not an image)
- *
- * @param string $input_name The name of the file input field on the submission form
- * @param string $output_name The name of the file to be written
- * @param int $maxwidth The maximum width of the resized image
- * @param int $maxheight The maximum height of the resized image
- * @param true|false $square If set to true, will take the smallest of maxwidth and maxheight and use it to set the dimensions on all size; the image will be cropped.
- * @return bool
- */
- function tp_imagick_cmdline_resize($input_name, $output_name, $maxwidth, $maxheight, $square = false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0) {
-
-
- // Get the size information from the image
- if ($imgsizearray = getimagesize($input_name)) {
-
- // Get width and height
- $width = $imgsizearray[0];
- $height = $imgsizearray[1];
- $newwidth = $width;
- $newheight = $height;
-
- // Square the image dimensions if we're wanting a square image
- if ($square) {
- if ($width < $height) {
- $height = $width;
- } else {
- $width = $height;
- }
-
- $newwidth = $width;
- $newheight = $height;
-
- }
-
- if ($width > $maxwidth) {
- $newheight = floor($height * ($maxwidth / $width));
- $newwidth = $maxwidth;
- }
- if ($newheight > $maxheight) {
- $newwidth = floor($newwidth * ($maxheight / $newheight));
- $newheight = $maxheight;
- }
-
- $accepted_formats = array(
- 'image/jpeg' => 'jpeg',
- 'image/pjpeg' => 'jpeg',
- 'image/png' => 'png',
- 'image/x-png' => 'png',
- 'image/gif' => 'gif'
- );
- // If it's a file we can manipulate ...
- if (array_key_exists($imgsizearray['mime'],$accepted_formats)) {
-
- // Crop the image if we need a square
- if ($square) {
- if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) {
- $widthoffset = floor(($imgsizearray[0] - $width) / 2);
- $heightoffset = floor(($imgsizearray[1] - $height) / 2);
- } else {
- $widthoffset = $x1;
- $heightoffset = $y1;
- $width = ($x2 - $x1);
- $height = $width;
- }
- } else {
- if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) {
- $widthoffset = 0;
- $heightoffset = 0;
- } else {
- $widthoffset = $x1;
- $heightoffset = $y1;
- $width = ($x2 - $x1);
- $height = ($y2 - $y1);
- }
- }
-
- // Resize and return the image contents!
- if ($square) {
- $newheight = $maxheight;
- $newwidth = $maxwidth;
- }
- $im_path = get_plugin_setting('im_path', 'tidypics');
- if(!$im_path) {
- $im_path = "/usr/bin/";
- }
- if(substr($im_path, strlen($im_path)-1, 1) != "/") $im_path .= "/";
- $command = $im_path . "convert \"$input_name\" -resize ".$newwidth."x".$newheight."^ -gravity center -extent ".$newwidth."x".$newheight." \"$output_name\"";
- exec($command);
- return true;
-
- }
- }
-
- return false;
- }
-
-?>
\ No newline at end of file diff --git a/lib/tidypics.php b/lib/tidypics.php deleted file mode 100644 index 6bed421ed..000000000 --- a/lib/tidypics.php +++ /dev/null @@ -1,186 +0,0 @@ -<?php
- /**
- * Elgg tidypics library of common functions
- *
- */
-
- /**
- * Get images for display on front page
- *
- * @param int number of images
- * @param int (optional) guid of owner
- * @return string of html for display
- *
- * To use with the custom index plugin, use something like this:
-
- if (is_plugin_enabled('tidypics')) {
-?>
- <!-- display latest photos -->
- <div class="index_box">
- <h2><a href="<?php echo $vars['url']; ?>pg/photos/world/"><?php echo elgg_echo("tidypics:mostrecent"); ?></a></h2>
- <div class="contentWrapper">
- <?php
- echo tp_get_latest_photos(5);
- ?>
- </div>
- </div>
-<?php
- }
-?>
-
- * Good luck
- */
- function tp_get_latest_photos($num_images, $owner_guid = 0)
- {
- $prev_context = set_context('front');
- $image_html = tp_list_entities('object', 'image', $owner_guid, $num_images, false, false, false);
- set_context($prev_context);
- return $image_html;
- }
-
-
- /**
- * Get image directory path
- *
- * Each album gets a subdirectory based on its container id
- *
- * @return string path to image directory
- */
- function tp_get_img_dir()
- {
- $file = new ElggFile();
- return $file->getFilenameOnFilestore() . 'image/';
- }
-
-
-
- /*********************************************************************
- * the functions below replace broken core functions or add functions
- * that should exist in the core
- */
-
- /**
- *
- */
- function tp_get_entities($type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null, $timelower = 0, $timeupper = 0)
- {
- global $CONFIG;
-
- if ($subtype === false || $subtype === null || $subtype === 0)
- return false;
-
- if ($order_by == "") $order_by = "time_created desc";
- $order_by = sanitise_string($order_by);
- $limit = (int)$limit;
- $offset = (int)$offset;
- $site_guid = (int) $site_guid;
- $timelower = (int) $timelower;
- $timeupper = (int) $timeupper;
- if ($site_guid == 0)
- $site_guid = $CONFIG->site_guid;
-
- $where = array();
-
- if (is_array($subtype)) {
- $tempwhere = "";
- if (sizeof($subtype))
- foreach($subtype as $typekey => $subtypearray) {
- foreach($subtypearray as $subtypeval) {
- $typekey = sanitise_string($typekey);
- if (!empty($subtypeval)) {
- if (!$subtypeval = (int) get_subtype_id($typekey, $subtypeval))
- return false;
- } else {
- // @todo: Setting subtype to 0 when $subtype = '' returns entities with
- // no subtype. This is different to the non-array behavior
- // but may be required in some cases.
- $subtypeval = 0;
- }
- if (!empty($tempwhere)) $tempwhere .= " or ";
- $tempwhere .= "(type = '{$typekey}' and subtype = {$subtypeval})";
- }
- }
- if (!empty($tempwhere)) $where[] = "({$tempwhere})";
-
- } else {
-
- $type = sanitise_string($type);
- if ($subtype !== "" AND !$subtype = get_subtype_id($type, $subtype))
- return false;
-
- if ($type != "")
- $where[] = "type='$type'";
- if ($subtype!=="")
- $where[] = "subtype=$subtype";
- }
-
- if ($owner_guid != "") {
- if (!is_array($owner_guid)) {
- $owner_array = array($owner_guid);
- $owner_guid = (int) $owner_guid;
- $where[] = "owner_guid = '$owner_guid'";
- } else if (sizeof($owner_guid) > 0) {
- $owner_array = array_map('sanitise_int', $owner_guid);
- // Cast every element to the owner_guid array to int
- $owner_guid = array_map("sanitise_int", $owner_guid);
- $owner_guid = implode(",",$owner_guid);
- $where[] = "owner_guid in ({$owner_guid})";
- }
- }
- if ($site_guid > 0)
- $where[] = "site_guid = {$site_guid}";
-
- if (!is_null($container_guid)) {
- if (is_array($container_guid)) {
- foreach($container_guid as $key => $val) $container_guid[$key] = (int) $val;
- $where[] = "container_guid in (" . implode(",",$container_guid) . ")";
- } else {
- $container_guid = (int) $container_guid;
- $where[] = "container_guid = {$container_guid}";
- }
- }
- if ($timelower)
- $where[] = "time_created >= {$timelower}";
- if ($timeupper)
- $where[] = "time_created <= {$timeupper}";
-
- if (!$count) {
- $query = "SELECT * from {$CONFIG->dbprefix}entities where ";
- } else {
- $query = "SELECT count(guid) as total from {$CONFIG->dbprefix}entities where ";
- }
- foreach ($where as $w)
- $query .= " $w and ";
- $query .= get_access_sql_suffix(); // Add access controls
- if (!$count) {
- $query .= " order by $order_by";
- if ($limit) $query .= " limit $offset, $limit"; // Add order and limit
- $dt = get_data($query, "entity_row_to_elggstar");
- return $dt;
- } else {
- $total = get_data_row($query);
- return $total->total;
- }
- }
-
- function tp_list_entities($type= "", $subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = false, $pagination = true) {
-
- $offset = (int) get_input('offset');
- $count = tp_get_entities($type, $subtype, $owner_guid, "", $limit, $offset, true);
- $entities = tp_get_entities($type, $subtype, $owner_guid, "", $limit, $offset);
-
- return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle, $pagination);
-
- }
-
- function tp_is_group_page() {
-
- if ($group = page_owner_entity()) {
- if ($group instanceof ElggGroup)
- return true;
- }
-
- return false;
- }
-
-?>
\ No newline at end of file diff --git a/lib/watermark.php b/lib/watermark.php deleted file mode 100644 index e28194b18..000000000 --- a/lib/watermark.php +++ /dev/null @@ -1,140 +0,0 @@ -<?php - -function tp_process_watermark_text($text, $owner) { - global $CONFIG; - - $text = str_replace("%name%", $owner->name, $text); - $text = str_replace("%sitename%", $CONFIG->sitename, $text); - - return $text; -} - -function tp_get_watermark_filename($text, $owner) { - global $CONFIG; - - $base = strtolower($text); - $base = preg_replace("/[^\w-]+/", "-", $base); - $base = trim($base, '-'); - - $filename = tp_get_img_dir(); - $filename .= strtolower($owner->username . "_" . $base . "_stamp"); - - return $filename; -} - -function tp_gd_watermark($image) { - $watermark_text = get_plugin_setting('watermark_text', 'tidypics'); - if (!$watermark_text) - return; - - global $CONFIG; - - $owner = get_loggedin_user(); - - $watermark_text = tp_process_watermark_text($watermark_text, $owner); - - // transparent gray - imagealphablending($image, true); - $textcolor = imagecolorallocatealpha($image, 50, 50, 50, 60); - - // font and location - $font = $CONFIG->pluginspath . "tidypics/fonts/LiberationSerif-Regular.ttf"; - $bbox = imagettfbbox(20, 0, $font, $watermark_text); - - $text_width = $bbox[2] - $bbox[0]; - $text_height = $bbox[1] - $bbox[7]; - - $image_width = imagesx($image); - $image_height = imagesy($image); - - $left = $image_width / 2 - $text_width / 2; - $top = $image_height - 20; - - // write the text on the image - imagettftext($image, 20, 0, $left, $top, $textcolor, $font, $watermark_text); -} - -function tp_imagick_watermark($filename) { - - $watermark_text = get_plugin_setting('watermark_text', 'tidypics'); - if (!$watermark_text) - return; - - $owner = get_loggedin_user(); - - $watermark_text = tp_process_watermark_text($watermark_text, $owner); - - $img = new Imagick($filename); - - $img->readImage($image); - - $draw = new ImagickDraw(); - - //$draw->setFont(""); - - $draw->setFontSize(28); - - $draw->setFillOpacity(0.5); - - $draw->setGravity(Imagick::GRAVITY_SOUTH); - - $img->annotateImage($draw, 0, 0, 0, $watermark_text); - - if ($img->writeImage($filename) != true) { - $img->destroy(); - return false; - } - - $img->destroy(); - - return true; -} - -function tp_imagick_cmdline_watermark($filename) { - - $watermark_text = get_plugin_setting('watermark_text', 'tidypics'); - if (!$watermark_text) - return; - - - $im_path = get_plugin_setting('im_path', 'tidypics'); - if (!$im_path) { - $im_path = "/usr/bin/"; - } - - // make sure end of path is / - if (substr($im_path, strlen($im_path)-1, 1) != "/") $im_path .= "/"; - - - $owner = get_loggedin_user(); - - $watermark_text = tp_process_watermark_text($watermark_text, $owner); - - $ext = ".png"; - - $user_stamp_base = tp_get_watermark_filename($watermark_text, $owner); - - - if ( !file_exists( $user_stamp_base . $ext )) { //create the watermark if it doesn't exist - $commands = array(); - $commands[] = $im_path . 'convert -size 300x50 xc:grey30 -pointsize 20 -gravity center -draw "fill grey70 text 0,0 \''. $watermark_text . '\'" "'. $user_stamp_base . '_fgnd' . $ext . '"'; - $commands[] = $im_path . 'convert -size 300x50 xc:black -pointsize 20 -gravity center -draw "fill white text 1,1 \''. $watermark_text . '\' text 0,0 \''. $watermark_text . '\' fill black text -1,-1 \''. $watermark_text . '\'" +matte ' . $user_stamp_base . '_mask' . $ext; - $commands[] = $im_path . 'composite -compose CopyOpacity "' . $user_stamp_base . "_mask" . $ext . '" "' . $user_stamp_base . '_fgnd' . $ext . '" "' . $user_stamp_base . $ext . '"'; - $commands[] = $im_path . 'mogrify -trim +repage "' . $user_stamp_base . $ext . '"'; - $commands[] = 'rm "' . $user_stamp_base . '_mask' . $ext . '"'; - $commands[] = 'rm "' . $user_stamp_base . '_fgnd' . $ext . '"'; - - foreach( $commands as $command ) { - exec( $command ); - } - } - - //apply the watermark - $commands = array(); - $commands[] = $im_path . 'composite -gravity south -geometry +0+10 "' . $user_stamp_base . $ext . '" "' . $filename . '" "' . $filename . '_watermarked"'; - $commands[] = "mv \"$filename" . "_watermarked\" \"$filename\""; - foreach( $commands as $command ) { - exec( $command ); - } -} -?>
\ No newline at end of file |
