[dev] [commit] r951 - phplib/models wwwbase/elfinder-connector

automailer at dexonline.ro automailer at dexonline.ro
Thu Aug 22 17:23:47 EEST 2013


Author: grigoroiualex
Date: Thu Aug 22 17:23:47 2013
New Revision: 951

Log:
Implemented rename, copy-paste and cut-paste for the thumbnails. Possible bug: although the .thumb directory is created using mkdir with 777 permissions, when elFinder tries to delete it, it throws an error stating that the folder is locked. Might be because I have the site data in /var/www which is owned by root.

Modified:
   phplib/models/Visual.php
   wwwbase/elfinder-connector/elFinderModToDB.class.php
   wwwbase/elfinder-connector/visual_connector.php

Modified: phplib/models/Visual.php
==============================================================================
--- phplib/models/Visual.php	Wed Aug 21 21:52:39 2013	(r950)
+++ phplib/models/Visual.php	Thu Aug 22 17:23:47 2013	(r951)
@@ -4,7 +4,8 @@
   public static $_table = 'Visual';
   public static $parentDir = 'visual';
   public static $thumbDir = '.thumb';
-  public static $cmd, $altPath;
+  public static $thumbSize = 200;
+  public static $cmd, $oldThumbPath;
 
   /** Retrieves the path relative to the visual folder */
   public static function getPath($givenPath) {
@@ -15,7 +16,7 @@
   }
 
   /** Creates the absolute path of the thumb directory based on the $path parameter */
-  static function thumbDirPath($path) {
+  static function getThumbDirPath($path) {
     preg_match('/[^\/]+$/', $path, $name);
     $path = str_replace($name[0], '', $path);
     
@@ -23,7 +24,7 @@
   }
 
   /** Creates the absolute path of the thumbnail file based on the $path parameter */
-  static function thumbPath($path) {
+  static function getThumbPath($path) {
     preg_match('/[^\/]+$/', $path, $name);
     $path = str_replace($name[0], '', $path);
 
@@ -44,8 +45,8 @@
   function delete() {
     VisualTag::deleteByImageId($this->id);    
 
-    $thumbPath = self::thumbPath($this->path);
-    $thumbDirPath = self::thumbDirPath($this->path);
+    $thumbPath = self::getThumbPath($this->path);
+    $thumbDirPath = self::getThumbDirPath($this->path);
 
     if(file_exists($thumbPath)) {
       unlink($thumbPath);
@@ -60,17 +61,31 @@
 
   /** Extended by creating uploaded image thumbnail */
   function save() {
-    $thumbDirPath = self::thumbDirPath($this->path);
-
-    if(!file_exists($thumbDirPath)) {
-      mkdir($thumbDirPath);
+    switch(self::$cmd) {
+    case 'upload':
+    case 'copy-paste':
+      $thumbDirPath = self::getThumbDirPath($this->path);
+
+      if(!file_exists($thumbDirPath)) {
+        mkdir($thumbDirPath, 0777);
+      }
+
+      $thumbPath = self::getThumbPath($this->path); 
+      $thumb = new Imagick(util_getRootPath() . 'wwwbase/img/' . $this->path);
+      $thumb->thumbnailImage(self::$thumbSize, self::$thumbSize, true);
+      $thumb->writeImage( $thumbPath);
+    break;
+
+    case 'rename':
+    case 'cut-paste':
+      $newThumbPath = self::getThumbPath($this->path);
+
+      if(file_exists(self::$oldThumbPath)) {
+        rename(self::$oldThumbPath, $newThumbPath);
+      }
+    break;
     }
 
-    $thumbPath = self::thumbPath($this->path); 
-    $thumb = new Imagick(util_getRootPath() . 'wwwbase/img/' . $this->path);
-    $thumb->thumbnailImage(200, 200, true);
-    $thumb->writeImage( $thumbPath);
-
     parent::save();
   }
 }

Modified: wwwbase/elfinder-connector/elFinderModToDB.class.php
==============================================================================
--- wwwbase/elfinder-connector/elFinderModToDB.class.php	Wed Aug 21 21:52:39 2013	(r950)
+++ wwwbase/elfinder-connector/elFinderModToDB.class.php	Thu Aug 22 17:23:47 2013	(r951)
@@ -52,14 +52,14 @@
         * paths of the files within it are modified accordingly. */
         $oldPath = Visual::getPath($result['removed'][0]['realpath']);
         $newPath = Visual::getPath($elfinder->realpath($result['added'][0]['hash']));
-        $entries = Model::factory('Visual')->where_like('path', "{$oldPath}/%")->find_many();
+        $lines = Model::factory('Visual')->where_like('path', "{$oldPath}/%")->find_many();
         Visual::$cmd = $cmd;
 
-        if(!empty($entries)) {
+        if(!empty($lines)) {
           /** Directory was renamed **/
-          foreach($entries as $entry) {
-            $entry->path = str_replace($oldPath, $newPath, $entry->path);
-            $entry->save();
+          foreach($lines as $line) {
+            $line->path = str_replace($oldPath, $newPath, $line->path);
+            $line->save();
           }
 
         } else {
@@ -67,6 +67,8 @@
           $line = Visual::get_by_path($oldPath);
 
           if(!empty($line)) {
+            Visual::$oldThumbPath = Visual::getThumbPath($oldPath);
+            $line->path = $newPath;
             $line->save();
           }
         }
@@ -76,12 +78,15 @@
       case 'paste':
       /** Cut - Paste */
       if(!empty($result['removed'])) {
+        Visual::$cmd = 'cut-paste';
+
         foreach($result['removed'] as $i => $file) {
           $oldPath = Visual::getPath($file['realpath']);
           $newPath = Visual::getPath($elfinder->realpath($result['added'][$i]['hash']));
           $line = Visual::get_by_path($oldPath);
 
           if(!empty($line)) {
+            Visual::$oldThumbPath = Visual::getThumbPath($oldPath);
             $line->path = $newPath;
             $line->save();
           }
@@ -89,6 +94,8 @@
 
       /** Copy - Paste */
       } else if(!empty($result['added'])) {
+        Visual::$cmd = 'copy-paste';
+
         foreach($result['added'] as $file) {
           $path = Visual::getPath($elfinder->realpath($file['hash']));
 

Modified: wwwbase/elfinder-connector/visual_connector.php
==============================================================================
--- wwwbase/elfinder-connector/visual_connector.php	Wed Aug 21 21:52:39 2013	(r950)
+++ wwwbase/elfinder-connector/visual_connector.php	Thu Aug 22 17:23:47 2013	(r951)
@@ -1,6 +1,6 @@
 <?php
 
-error_reporting(E_ALL); // Set E_ALL for debuging
+error_reporting(0); // Set E_ALL for debuging
 
 include_once __DIR__ . '/elFinderConnector.class.php';
 include_once __DIR__ . '/elFinder.class.php';


More information about the Dev mailing list