]> source.dussan.org Git - nextcloud-server.git/commitdiff
merged
authorBartek Przybylski <bart.p.pl@gmail.com>
Wed, 21 Dec 2011 17:35:29 +0000 (18:35 +0100)
committerBartek Przybylski <bart.p.pl@gmail.com>
Wed, 21 Dec 2011 17:35:29 +0000 (18:35 +0100)
1  2 
.htaccess
apps/gallery/ajax/getAlbums.php
apps/gallery/ajax/scanForAlbums.php
apps/gallery/index.php
apps/gallery/js/albums.js
apps/gallery/lib/scanner.php

diff --cc .htaccess
index bd2f42d665865522b6f36014de92d8c0a7a19ddd,0d334503d07d7152e3b167463d50bac6a989965a..b181f8b8452aeea506c695a0be3d74e05ea682f6
+++ b/.htaccess
@@@ -2,11 -2,8 +2,9 @@@ ErrorDocument 404 /core/templates/404.p
  <IfModule mod_php5.c>
  php_value upload_max_filesize 512M
  php_value post_max_size 512M
 +php_value memory_limit 512M
  SetEnv htaccessWorking true
  </IfModule>
- <IfModule !mod_php5.c>
  RewriteEngine on
  RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]
- </IfModule>
  Options -Indexes
index 98d92c5f31ac4ca505b1518df589ae9ebd0ea5c4,856f29344d71e07c2bd11791bffbdab6a42df7cc..7454b18edab4ba0a14a80db329e67fea5f511392
@@@ -9,9 -8,8 +8,9 @@@ $result = OC_Gallery_Album::find(OC_Use
  
  while ($r = $result->fetchRow()) {
    $album_name = $r['album_name'];
-   $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE album_id = ?');
-   $tmp_res = $stmt->execute(array($r['album_id']));
+   $tmp_res = OC_Gallery_Photo::find($r['album_id']);
 -  $a[] = array('name' => $album_name, 'numOfItems' => min($tmp_res->numRows(), 10));
++
 +  $a[] = array('name' => $album_name, 'numOfItems' => min($tmp_res->numRows(), 10), 'bgPath' => OC::$WEBROOT.'/data/'.OC_User::getUser().'/gallery/'.$album_name.'.png');
  }
  
  OC_JSON::success(array('albums'=>$a));
index bdd591d04227797ba2a1bbe84d3e4c133232a285,ff696804b00630a0a4744228fc1fa7effddea979..f603cbb497173b95f02123f188db511552590494
@@@ -3,10 -3,8 +3,8 @@@
  require_once('../../../lib/base.php');
  OC_JSON::checkLoggedIn();
  OC_JSON::checkAppEnabled('gallery');
- require_once('../lib_scanner.php');
  
- OC_GALLERY_SCANNER::cleanUp();
- OC_JSON::success(array('albums' => OC_GALLERY_SCANNER::scan('')));
- //OC_JSON::success(array('albums' => array(array('name' => 'test', 'imagesCount' => 1, 'images' => array('dupa')))));
++OC_Gallery_Scanner::cleanUp();
+ OC_JSON::success(array('albums' => OC_Gallery_Scanner::scan('')));
 -//OC_JSON::success(array('albums' => array(array('name' => 'test', 'imagesCount' => 1, 'images' => array('dupa')))));
  
  ?>
index cb567e3c8f6bf7f3123799acdb67bc3607237308,2c409089ebe5b1511a9cd8cb19320e79a6f1136b..0cd795bac0137d470dae0bca4d9e4d05e0927801
@@@ -5,16 -5,9 +5,15 @@@ OC_Util::checkLoggedIn()
  OC_Util::checkAppEnabled('gallery');
  OC_App::setActiveNavigationEntry( 'gallery_index' );
  
 +if (!file_exists(OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery')) {
 +  mkdir(OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery');
 +  $f = fopen(OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/.htaccess', 'w');
 +  fwrite($f, "allow from all");
 +  fclose($f);
 +}
  
  if (!isset($_GET['view'])) {
-   $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?');
-   $result = $stmt->execute(array(OC_User::getUser()));
+   $result = OC_Gallery_Album::find(OC_User::getUser());
  
    $r = array();
    while ($row = $result->fetchRow())
Simple merge
index 0000000000000000000000000000000000000000,1590051c48da51fe748b6ee600ea2150b1845895..ef210327966f35f769d5f117a523111e7533c93d
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,49 +1,73 @@@
+ <?php
++require_once('base.php'); // base lib
++require_once('images_utils.php');
++
+ class OC_Gallery_Scanner {
++
+   public static function scan($root) {
+     $albums = array();
+     self::scanDir($root, $albums);
+     return $albums;
+   }
++  public static function cleanUp() {
++    $stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_albums');
++    $stmt->execute(array());
++    $stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_photos');
++    $stmt->execute(array());
++  }
++
+   public static function scanDir($path, &$albums) {
+     $current_album = array('name'=> $path, 'imagesCount' => 0, 'images' => array());
+     $current_album['name'] = str_replace('/', '.', str_replace(OC::$CONFIG_DATADIRECTORY, '', $current_album['name']));
+     $current_album['name'] = ($current_album['name']==='')?'main':$current_album['name'];
+     if ($dh = OC_Filesystem::opendir($path)) {
+       while (($filename = readdir($dh)) !== false) {
+         $filepath = $path.'/'.$filename;
+         if (substr($filename, 0, 1) == '.') continue;
+         if (OC_Filesystem::is_dir($filepath)) {
+           self::scanDir($filepath, $albums);
+         } elseif (self::isPhoto($path.'/'.$filename)) {
+           $current_album['images'][] = $filepath;
+         }
+       }
+     }
+     $current_album['imagesCount'] = count($current_album['images']);
+     $albums[] = $current_album;
++
+     $result = OC_Gallery_Album::find(OC_User::getUser(), $current_album['name']);
+     if ($result->numRows() == 0 && count($current_album['images'])) {
+           OC_Gallery_Album::create(OC_User::getUser(), $current_album['name']);
+           $result = OC_Gallery_Album::find(OC_User::getUser(), $current_album['name']);
+     }
+     $albumId = $result->fetchRow();
+     $albumId = $albumId['album_id'];
+     foreach ($current_album['images'] as $img) {
+       $result = OC_Gallery_Photo::find($albumId, $img);
+       if ($result->numRows() == 0) {
+             OC_Gallery_Photo::create($albumId, $img);
+       }
+     }
++    if (count($current_album['images'])) {
++      self::createThumbnail($current_album['name'],$current_album['images']);
++    }
++  }
++
++  public static function createThumbnail($albumName, $files) {
++    $file_count = min(count($files), 10);
++    $thumbnail = imagecreatetruecolor($file_count*200, 200);
++    for ($i = 0; $i < $file_count; $i++) {
++      CroppedThumbnail(OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/files/'.$files[$i], 200, 200, $thumbnail, $i*200);
++    }
++    imagepng($thumbnail, OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/' . $albumName.'.png');
+   }
+   public static function isPhoto($filename) {
+     if (substr(OC_Filesystem::getMimeType($filename), 0, 6) == "image/")
+       return 1;
+     return 0;
+   }
+ }
+ ?>