summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php5
-rw-r--r--plugins/GNUsocialPhotos/actions/photos.php61
-rw-r--r--plugins/GNUsocialPhotos/actions/photoupload.php7
-rw-r--r--plugins/GNUsocialPhotos/classes/gnusocialphoto.php2
-rw-r--r--plugins/GNUsocialPhotos/lib/photolib.php87
5 files changed, 98 insertions, 64 deletions
diff --git a/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php b/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
index d93bb8cca..f7cb6f398 100644
--- a/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
+++ b/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
@@ -42,9 +42,12 @@ class GNUsocialPhotosPlugin extends Plugin
switch ($cls)
{
case 'PhotosAction':
+ include_once $dir . '/lib/photolib.php';
include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
case 'PhotouploadAction':
+ include_once $dir . '/lib/photolib.php';
+ include_once $dir . '/classes/gnusocialphoto.php';
include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
default:
@@ -57,7 +60,7 @@ class GNUsocialPhotosPlugin extends Plugin
function onCheckSchema()
{
$schema = Schema::get();
- $schema->ensureTable('GNUsocialPhotos',
+ $schema->ensureTable('GNUsocialPhoto',
array(new ColumnDef('object_id', 'integer', null, false, 'PRI', true, null, null, true),
new ColumnDef('path', 'varchar(150)', null, false),
new ColumnDef('thumb_path', 'varchar(156)', null, false), // 156 = 150 + strlen('thumb.')
diff --git a/plugins/GNUsocialPhotos/actions/photos.php b/plugins/GNUsocialPhotos/actions/photos.php
index aef2478b1..29a70e458 100644
--- a/plugins/GNUsocialPhotos/actions/photos.php
+++ b/plugins/GNUsocialPhotos/actions/photos.php
@@ -97,7 +97,7 @@ class PhotosAction extends Action
$this->elementStart('li');
$this->elementStart('a', array('href' => 'http://' . common_config('site', 'server') . '/file/' . $file));
if (!file_exists(INSTALLDIR . '/file/thumb.' . $file)) {
- $this->makeThumb($file);
+ photo_make_thumbnail($file);
}
$this->element('img', array('src' => 'http://' . common_config('site', 'server') . '/file/' . 'thumb.' . $file));
$this->elementEnd('a');
@@ -107,63 +107,4 @@ class PhotosAction extends Action
$this->elementEnd('ul');
}
}
-
- function makeThumb($filename)
- {
- $height_dest = 192;
- $width_dest = 256;
-
- $size_src = getimagesize(INSTALLDIR . '/file/' . $filename);
- $image_type = $size_src[2];
-
- switch($image_type) {
- case IMAGETYPE_JPEG:
- $image_src = imagecreatefromjpeg(INSTALLDIR . '/file/' . $filename);
- break;
- case IMAGETYPE_PNG:
- $image_src = imagecreatefrompng(INSTALLDIR . '/file/' . $filename);
- break;
- case IMAGETYPE_GIF:
- $image_src = imagecreatefromgif(INSTALLDIR . '/file/' . $filename);
- break;
- default:
- return false;
- }
-
- $width_src = $size_src[0];
- $height_src = $size_src[1];
-
- $ratio_src = (float) $width_src / (float) $height_src;
- $ratio_dest = (float) $width_dest / (float) $height_dest;
-
- if ($ratio_src > $ratio_dest) {
- $height_crop = $height_src;
- $width_crop = (int)($height_crop * $ratio_dest);
- $x_crop = ($width_src - $width_crop) / 2;
- } else {
- $width_crop = $width_src;
- $height_crop = (int)($width_crop / $ratio_dest);
- $x_crop = 0;
- }
-
- $image_dest = imagecreatetruecolor($width_dest, $height_dest);
-
- imagecopyresampled($image_dest, $image_src, 0, 0, $x_crop, 0, $width_dest, $height_dest, $width_crop, $height_crop);
- switch ($image_type) {
- case IMAGETYPE_JPEG:
- imagejpeg($image_dest, INSTALLDIR . '/file/' . 'thumb.' . $filename, 100);
- break;
- case IMAGETYPE_PNG:
- imagepng($image_dest, INSTALLDIR . '/file/thumb.' . $filename);
- break;
- case IMAGETYPE_GIF:
- imagegif($image_dest, INSTALLDIR . '/file/thumb.' . $filename);
- break;
- }
-
- imagedestroy($image_src);
- imagedestroy($image_dest);
-
- return true;
- }
}
diff --git a/plugins/GNUsocialPhotos/actions/photoupload.php b/plugins/GNUsocialPhotos/actions/photoupload.php
index 286dd4386..aafa2d3fe 100644
--- a/plugins/GNUsocialPhotos/actions/photoupload.php
+++ b/plugins/GNUsocialPhotos/actions/photoupload.php
@@ -44,6 +44,9 @@ class PhotouploadAction extends Action
function handle($args)
{
parent::handle($args);
+ if($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $this->handlePost();
+ }
$this->showPage();
}
@@ -88,12 +91,12 @@ class PhotouploadAction extends Action
// CSRF protection
- $token = $this->trimmed('token');
+/* $token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
$this->showForm(_('There was a problem with your session token. '.
'Try again, please.'));
return;
- }
+ } */
if($this->arg('upload')) {
$this->uploadPhoto();
diff --git a/plugins/GNUsocialPhotos/classes/gnusocialphoto.php b/plugins/GNUsocialPhotos/classes/gnusocialphoto.php
index ecb90616e..0e3d24eed 100644
--- a/plugins/GNUsocialPhotos/classes/gnusocialphoto.php
+++ b/plugins/GNUsocialPhotos/classes/gnusocialphoto.php
@@ -32,7 +32,7 @@ if (!defined('STATUSNET')) {
require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
-class GNUsocialPhoto extends Memcahced_DataObject
+class GNUsocialPhoto extends Memcached_DataObject
{
public $object_id; // integer
public $path; // varchar(150)
diff --git a/plugins/GNUsocialPhotos/lib/photolib.php b/plugins/GNUsocialPhotos/lib/photolib.php
new file mode 100644
index 000000000..9e5ff61fa
--- /dev/null
+++ b/plugins/GNUsocialPhotos/lib/photolib.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * GNU Social
+ * Copyright (C) 2010, Free Software Foundation, Inc.
+ *
+ * PHP version 5
+ *
+ * LICENCE:
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Widget
+ * @package GNU Social
+ * @author Ian Denhardt <ian@zenhack.net>
+ * @copyright 2010 Free Software Foundation, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ */
+
+
+function photo_make_thumbnail($filename)
+{
+ $height_dest = 192;
+ $width_dest = 256;
+
+ $size_src = getimagesize(INSTALLDIR . '/file/' . $filename);
+ $image_type = $size_src[2];
+
+ switch($image_type) {
+ case IMAGETYPE_JPEG:
+ $image_src = imagecreatefromjpeg(INSTALLDIR . '/file/' . $filename);
+ break;
+ case IMAGETYPE_PNG:
+ $image_src = imagecreatefrompng(INSTALLDIR . '/file/' . $filename);
+ break;
+ case IMAGETYPE_GIF:
+ $image_src = imagecreatefromgif(INSTALLDIR . '/file/' . $filename);
+ break;
+ default:
+ return false;
+ }
+
+ $width_src = $size_src[0];
+ $height_src = $size_src[1];
+
+ $ratio_src = (float) $width_src / (float) $height_src;
+ $ratio_dest = (float) $width_dest / (float) $height_dest;
+
+ if ($ratio_src > $ratio_dest) {
+ $height_crop = $height_src;
+ $width_crop = (int)($height_crop * $ratio_dest);
+ $x_crop = ($width_src - $width_crop) / 2;
+ } else {
+ $width_crop = $width_src;
+ $height_crop = (int)($width_crop / $ratio_dest);
+ $x_crop = 0;
+ }
+
+ $image_dest = imagecreatetruecolor($width_dest, $height_dest);
+
+ imagecopyresampled($image_dest, $image_src, 0, 0, $x_crop, 0, $width_dest, $height_dest, $width_crop, $height_crop);
+ switch ($image_type) {
+ case IMAGETYPE_JPEG:
+ imagejpeg($image_dest, INSTALLDIR . '/file/' . 'thumb.' . $filename, 100);
+ break;
+ case IMAGETYPE_PNG:
+ imagepng($image_dest, INSTALLDIR . '/file/thumb.' . $filename);
+ break;
+ case IMAGETYPE_GIF:
+ imagegif($image_dest, INSTALLDIR . '/file/thumb.' . $filename);
+ break;
+ }
+
+ imagedestroy($image_src);
+ imagedestroy($image_dest);
+
+ return true;
+}