]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
got uploads sortof working - database portion doesn't work though.
authorIan Denhardt <ian@zenhack.net>
Thu, 5 Aug 2010 17:11:34 +0000 (13:11 -0400)
committerIan Denhardt <ian@zenhack.net>
Thu, 5 Aug 2010 17:11:34 +0000 (13:11 -0400)
plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
plugins/GNUsocialPhotos/actions/photos.php
plugins/GNUsocialPhotos/actions/photoupload.php
plugins/GNUsocialPhotos/classes/gnusocialphoto.php
plugins/GNUsocialPhotos/lib/photolib.php [new file with mode: 0644]

index d93bb8cca801172f505fe5b8e17a8f097ed4ac09..f7cb6f3982a76d2ecdb71edfab0c2c5b5a0f2b8c 100644 (file)
@@ -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.')
index aef2478b172650dd8f5d2bcb4942c4cad14889c6..29a70e4589b03e730502711f91261988f6d0fb8a 100644 (file)
@@ -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;
-    }
 }
index 286dd4386d98e99b05b1e937d9a577513e24ac0d..aafa2d3fef147a72f1e57c580e693873c53223b4 100644 (file)
@@ -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();
index ecb90616e1c5a49432a54692ee640be828cfc3bb..0e3d24eedc6847d45dae5b720072fa1e07cb7834 100644 (file)
@@ -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 (file)
index 0000000..9e5ff61
--- /dev/null
@@ -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;
+}