[dev] [commit] r950 - phplib/models wwwbase/ajax wwwbase/elfinder-connector wwwbase/js

Grigoroiu Marian Alexandru grigoroiualexandru at gmail.com
Wed Aug 21 21:54:07 EEST 2013


„cut-paste” în loc de „cut-delete” în comment. Greșeala mea.


On Wed, Aug 21, 2013 at 9:52 PM, <automailer at dexonline.ro> wrote:

> Author: grigoroiualex
> Date: Wed Aug 21 21:52:39 2013
> New Revision: 950
>
> Log:
> Creates and deletes thumbnails for uploaded visual images. TODO: rename,
> copy-paste, copy-delete
>
> Modified:
>    phplib/models/Visual.php
>    wwwbase/ajax/visualTag.php
>    wwwbase/elfinder-connector/elFinderModToDB.class.php
>    wwwbase/elfinder-connector/visual_connector.php
>    wwwbase/js/visualTag.js
>
> Modified: phplib/models/Visual.php
>
> ==============================================================================
> --- phplib/models/Visual.php    Wed Aug 21 18:39:17 2013        (r949)
> +++ phplib/models/Visual.php    Wed Aug 21 21:52:39 2013        (r950)
> @@ -3,6 +3,8 @@
>  class Visual extends BaseObject implements DatedObject {
>    public static $_table = 'Visual';
>    public static $parentDir = 'visual';
> +  public static $thumbDir = '.thumb';
> +  public static $cmd, $altPath;
>
>    /** Retrieves the path relative to the visual folder */
>    public static function getPath($givenPath) {
> @@ -12,10 +14,64 @@
>      return $matches[0];
>    }
>
> +  /** Creates the absolute path of the thumb directory based on the $path
> parameter */
> +  static function thumbDirPath($path) {
> +    preg_match('/[^\/]+$/', $path, $name);
> +    $path = str_replace($name[0], '', $path);
> +
> +    return util_getRootPath() . 'wwwbase/img/' . $path . self::$thumbDir;
> +  }
> +
> +  /** Creates the absolute path of the thumbnail file based on the $path
> parameter */
> +  static function thumbPath($path) {
> +    preg_match('/[^\/]+$/', $path, $name);
> +    $path = str_replace($name[0], '', $path);
> +
> +    return util_getRootPath() . 'wwwbase/img/' . $path . self::$thumbDir
> . '/' . $name[0];
> +  }
> +
> +  /** Checks if the directory specified in $path is empty */
> +  static function isDirEmpty($path) {
> +    $files = scandir($path);
> +    if(count($files) == 2) {
> +      return true;
> +    } else {
> +      return false;
> +    }
> +  }
> +
> +  /** Extended by deleting removed image thumbnails */
>    function delete() {
>      VisualTag::deleteByImageId($this->id);
> +
> +    $thumbPath = self::thumbPath($this->path);
> +    $thumbDirPath = self::thumbDirPath($this->path);
> +
> +    if(file_exists($thumbPath)) {
> +      unlink($thumbPath);
> +    }
> +
> +    if(file_exists($thumbDirPath) && self::isDirEmpty($thumbDirPath)) {
> +      rmdir($thumbDirPath);
> +    }
>
>      parent::delete();
>    }
> +
> +  /** Extended by creating uploaded image thumbnail */
> +  function save() {
> +    $thumbDirPath = self::thumbDirPath($this->path);
> +
> +    if(!file_exists($thumbDirPath)) {
> +      mkdir($thumbDirPath);
> +    }
> +
> +    $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/ajax/visualTag.php
>
> ==============================================================================
> --- wwwbase/ajax/visualTag.php  Wed Aug 21 18:39:17 2013        (r949)
> +++ wwwbase/ajax/visualTag.php  Wed Aug 21 21:52:39 2013        (r950)
> @@ -9,7 +9,7 @@
>
>  $resp = array('more' => 'false', 'results' => array());
>  foreach($lexems as $lexem) {
> -  $resp['results'][] = array('id' => $lexem->id, 'text' =>
> (string)$lexem->formUtf8General);
> +  $resp['results'][] = array('id' => $lexem->id, 'text' =>
> (string)$lexem->formUtf8General, 'description' =>
> (string)$lexem->description);
>  }
>
>  echo json_encode($resp);
>
> Modified: wwwbase/elfinder-connector/elFinderModToDB.class.php
>
> ==============================================================================
> --- wwwbase/elfinder-connector/elFinderModToDB.class.php        Wed Aug 21
> 18:39:17 2013        (r949)
> +++ wwwbase/elfinder-connector/elFinderModToDB.class.php        Wed Aug 21
> 21:52:39 2013        (r950)
> @@ -1,6 +1,8 @@
>  <?php
>
> -include_once '../../phplib/models/Visual.php';
> +autoloadModelsClass('Visual');
> +autoloadModelsClass('BaseObject');
> +autoloadModelsClass('DatedObject');
>
>  class elFinderModToDB extends Visual {
>
> @@ -17,6 +19,7 @@
>      if(!empty($result['added'])) {
>        foreach($result['added'] as $file) {
>          $path = Visual::getPath($elfinder->realpath($file['hash']));
> +        Visual::$cmd = $cmd;
>
>          $line = Model::factory('Visual')->create();
>          $line->path = $path;
> @@ -50,6 +53,7 @@
>          $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();
> +        Visual::$cmd = $cmd;
>
>          if(!empty($entries)) {
>            /** Directory was renamed **/
> @@ -63,7 +67,6 @@
>            $line = Visual::get_by_path($oldPath);
>
>            if(!empty($line)) {
> -            $line->path = $newPath;
>              $line->save();
>            }
>          }
>
> Modified: wwwbase/elfinder-connector/visual_connector.php
>
> ==============================================================================
> --- wwwbase/elfinder-connector/visual_connector.php     Wed Aug 21
> 18:39:17 2013        (r949)
> +++ wwwbase/elfinder-connector/visual_connector.php     Wed Aug 21
> 21:52:39 2013        (r950)
> @@ -1,6 +1,6 @@
>  <?php
>
> -error_reporting(0); // Set E_ALL for debuging
> +error_reporting(E_ALL); // Set E_ALL for debuging
>
>  include_once __DIR__ . '/elFinderConnector.class.php';
>  include_once __DIR__ . '/elFinder.class.php';
> @@ -50,7 +50,7 @@
>        'uploadAllow'   => array('image'), // mimetypes allowed to upload
>        'disabled'      => array('resize', 'mkfile', 'duplicate'), // list
> of not allowed commands
>        'imgLib'        => 'gd', // image manipulation library (imagick,
> mogrify, gd)
> -      'tmbPath'       => '.tmb', // directory name for image thumbnails.
> Set to "" to avoid thumbnails generation
> +      'tmbPath'       => '.elfTmb', // directory name for image
> thumbnails. Set to "" to avoid thumbnails generation
>      )
>    )
>  );
>
> Modified: wwwbase/js/visualTag.js
>
> ==============================================================================
> --- wwwbase/js/visualTag.js     Wed Aug 21 18:39:17 2013        (r949)
> +++ wwwbase/js/visualTag.js     Wed Aug 21 21:52:39 2013        (r950)
> @@ -46,8 +46,6 @@
>    $('#clrSel').click(function(e) {
>      jcrop_api.release();
>
> -    alert($('#lexem').select2('data').text);
> -
>      resetCoords();
>    });
>
> @@ -88,12 +86,14 @@
>        data: function(term, page) { return {term: term}; },
>        results: function(data, page) { return { results: data.results }; },
>      },
> -    formatResult: function(data) {
> +    formatResult: select2Format,
> +    /*function(data) {
>        return data.text;
> -    },
> -    formatSelection: function(data) {
> +    },*/
> +    formatSelection: select2Format,
> +    /*function(data) {
>        return data.text;
> -    },
> +    },*/
>      width: '200px',
>
>    }).on('change', function(e) {
> @@ -106,22 +106,26 @@
>  });
>
>  function validateTag() {
> -  var lexem = document.getElementById('lexem').value;
> -  var xImg = document.getElementById('xImg').value;
> -  var yImg = document.getElementById('yImg').value;
> -  var xTag = document.getElementById('xTag').value;
> -  var yTag = document.getElementById('yTag').value;
> +  var lexeme = $('#lexeme').val();
> +  var xImg = $('#xImg').val();
> +  var yImg = $('#yImg').val();
> +  var xTag = $('#xTag').val();
> +  var yTag = $('#yTag').val();
>
> -  if(!lexem) {
> +  if(!lexeme) {
>      alert('Ai uitat să completezi câmpul Cuvânt');
>      return false;
>
> -  } else if(!xImg || !yImg) {
> +  } else if(!xTag || !yTag) {
>      alert('Ai uitat să completezi câmpurile Coordonatele centrului
> etichetei');
>      return false;
>
> -  } else if(!xTag || !yTag) {
> +  } else if(!xImg || !yImg) {
>      alert('Ai uitat să completezi câmpurile Coordonatele zonei
> etichetate');
>      return false;
>    }
>  };
> +
> +function select2Format(lex) {
> +  return lex.text + '  ' + lex.description;
> +}
> _______________________________________________
> Dev mailing list
> Dev at dexonline.ro
> http://list.dexonline.ro/listinfo/dev
>



-- 
Toate cele bune,
Grigoroiu Marian Alexandru
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.dexonline.ro/pipermail/dev/attachments/20130821/d34baa7f/attachment-0001.html>


More information about the Dev mailing list