Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additions #13

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
12950af
añado funcionalidad para que mediante parametros se pueda hacer crop …
SRJ9 Sep 17, 2014
f7f1464
añado hash a las imagenes que aparecen en los XMLs. Tengo que obtener…
SRJ9 Sep 26, 2014
d17caa7
añado principios para watermark.
SRJ9 Sep 26, 2014
8f68c22
logica de watermark ya avanzada.
SRJ9 Sep 26, 2014
5468de3
cambios definitivos, a falta de aclarar donde usar mejor getUserHash …
SRJ9 Sep 29, 2014
fc80b5f
version muy definitiva de phtagr, queda mirar caché.
SRJ9 Sep 29, 2014
9e5a1a4
añado comentarios. Tengo que optimizar cache.
SRJ9 Oct 1, 2014
213ec10
Solo una ruta de watermarks en el proyecto. Mejor estructura y arregl…
SRJ9 Oct 1, 2014
aec6169
Al importar una carpeta si esta contenia imagenes de las que no se ha…
SRJ9 Oct 6, 2014
51e853f
* Cache en consulta de BD
SRJ9 Oct 9, 2014
213dd2c
Corrijo API por key. Añado logout en dashboard.
SRJ9 Nov 11, 2014
f68d771
Quito caché temporalmente porque de esta manera no puedo ver instanta…
SRJ9 Nov 12, 2014
2d62ad8
En Config/Core.php
SRJ9 Oct 10, 2014
032af63
algún arreglo y más documentación.
SRJ9 Oct 14, 2014
f9ce987
Cambio el schema inicial para que añada el valor API a la tabla autom…
SRJ9 Oct 15, 2014
aca099b
quito API por key
SRJ9 Nov 11, 2014
46b5373
añado el ultimo directorio como etiqueta. Hecho en la edición, queda …
SRJ9 Nov 13, 2014
abbddb8
Last directory included as tag if not exists.
SRJ9 Nov 13, 2014
5e486da
Add TOP order. Medias with "top" tag lead the results.
SRJ9 Nov 13, 2014
7a667db
He omitido un warning en el exif para que siga adelante. El exif ISO …
SRJ9 Nov 14, 2014
76a316f
Only logged users can view the panel. Fixed the show function of Medi…
SRJ9 Dec 1, 2014
9ae363f
Allow panel view if /users/login is the current page.
SRJ9 Dec 1, 2014
c68b66d
arreglo de estilo de checkbox de las opciones del importador para res…
SRJ9 Dec 1, 2014
704d280
Volvemos a activar caché
SRJ9 Dec 23, 2014
dfe0666
añado tambien el setup como ruta donde si se debe mostrar el contenido.
SRJ9 Dec 23, 2014
a3e29f1
Queries cache is managed by Varnish now.
SRJ9 Feb 10, 2015
1086c7d
Añado función de deleteimport para borrar tras import.
SRJ9 Mar 5, 2015
7bb777a
arreglo la funcion para usar el parametro a traves del request
SRJ9 Mar 5, 2015
464885f
quito parametro de deleteimport
SRJ9 Mar 5, 2015
e6e7a2d
debug
SRJ9 Mar 5, 2015
e5d3097
quito debug
SRJ9 Mar 5, 2015
1bce8ca
funcion lsyncd de importacion
SRJ9 Mar 6, 2015
a425a50
ordenación por defecto en top
SRJ9 Mar 9, 2015
3a5d376
añado URL por param tipo w:600
SRJ9 Mar 9, 2015
ea91c58
añado otro caso al lsyncd. En este caso el de cuando un archivo es co…
SRJ9 Mar 23, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
</IfModule>


Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
19 changes: 18 additions & 1 deletion Config/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
/**
* A random string used in security hashing methods.
*/
Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');
Configure::write('Security.salt', '2Q6HX62YKE7FEtJsg4KS9Mg1tOyedpOV5KcSGVqRi');

/**
* A random numeric string (digits only) used to encrypt/decrypt strings.
Expand Down Expand Up @@ -430,3 +430,20 @@
'serialize' => ($engine === 'File'),
'duration' => $duration
));

// In development mode, caches should expire quickly.
$durationCacheDB = '+8 hours';
if (Configure::read('debug') > 0) {
$durationCacheDB = '+1 minutes';
}

/**
* Configure the cache for database queries
*/
Cache::config('_cake_db_', array(
'engine' => $engine,
'prefix' => $prefix . 'db_',
'path' => CACHE . 'db' . DS,
'serialize' => ($engine === 'File'),
'duration' => $durationCacheDB
));
99 changes: 99 additions & 0 deletions Controller/BrowserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,106 @@ public function import() {
$this->FilterManager->ImageFilter->Exiftool->exitExiftool();
$this->redirect('index/'.$path);
}

private function _lsyncimport($filetoimport) {

if ($this->hasRole(ROLE_ADMIN)) {
ini_set('max_execution_time', 3600);//1 hour
}

$options = array();
$options['recursive'] = 1;
$options['forceReadMeta'] = 1;
$options['extensions'] = array('any');

$recursive = (bool) $options['recursive'];

// Get dir and imports
$dirs = array();
$files = array();
$toRead = array();

#$fsPath = $this->_getFsPath($filetoimport);
$fsPath = $filetoimport;
if (is_dir($fsPath)) {
$dirs[] = Folder::slashTerm($fsPath);
$toRead[] = $fsPath;
} elseif (file_exists($fsPath) && is_readable($fsPath)) {
$files[] = $fsPath;
$toRead[] = $fsPath;
}

$this->FilterManager->clearErrors();

$readed = $this->FilterManager->readFiles($toRead, $options);
$skipped = count($this->FilterManager->skipped);
$errorCount = count($this->FilterManager->errors);

$readCount = 0;
foreach ($readed as $file => $media) {
if ($media) {
$readCount++;
}
}
$this->Session->setFlash(__("Processed %d files (imported %d, skipped %d, %d errors)", $readCount, $readCount-$skipped, $skipped, $errorCount));

$this->FilterManager->ImageFilter->Exiftool->exitExiftool();
return true;
}


private function _lsyncdelete($filename=''){

if($filename != ''){
$file = $this->MyFile->findByFilename($filename);
if (!$file) {
return false;
} elseif ($file['User']['id'] != $this->getUserId()) {
return false;
} else {
$this->Session->setFlash(__("Media %d was unlinked successfully", $file['File']['media_id']));
$this->Media->unlinkFile($file['File']['media_id'], $file['File']['id']);
}
echo 'OK';
exit;
}
echo 'Nothing to do here';
exit;
}


public function lsyncd(){

if(isset($this->request->data['lsynclog']) && isset($this->request->data['folder_root'])){
$lsynclog=$this->request->data['lsynclog'];
$folder_root = $this->request->data['folder_root'];
$files = file($lsynclog);


for($i=0;$i<count($files);$i++){
$file = explode(' ', $files[$i], 5);
if(strpos($file[4], '.ini')!==false){
continue;
}
if($file[3] == 'cd+++++++++'){
// es una carpeta nueva
// no hacemos nada
} elseif($file[3] == "<f+++++++++" || $file[3] == "<f.sT......" || $file[3] == "<f..T......"){
#echo 'archivo nuevo: '.$folder_root.trim($file[4]).'<br/>';
// archivo nuevo, llamo a import
#$this->_lsyncimport($folder_root.'/'.trim($file[4]));
$this->_lsyncimport($folder_root.trim($file[4]));

} elseif($file[3] == "*deleting"){
#echo 'archivo eliminado'.$folder_root.trim($file[4]).'<br/>';
#$this->_lsyncdelete($folder_root.'/'.trim($file[4]));
$this->_lsyncdelete($folder_root.trim($file[4]));
// archivo borrado, llamo a delete
}
}
}
exit;
}
public function unlink() {
$path = $this->_getPathFromUrl();
$fsPath = $this->_getFsPath($path);
Expand Down
3 changes: 3 additions & 0 deletions Controller/Component/ExiftoolComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ public function extractImageDataSidecar(&$media, &$data) {
$v['shutter'] = $this->_extract($data, 'ShutterSpeed', $v['shutter']);
$v['model'] = $this->_extract($data, 'Model', $v['model']);
$v['iso'] = $this->_extract($data, 'ISO', $v['iso']);
if(is_array($v['iso'])){
$v['iso'] = null;
}
$v['caption'] = $this->_extract($data, 'Comment', $v['caption']);

// fetch GPS coordinates
Expand Down
7 changes: 6 additions & 1 deletion Controller/Component/FileCacheComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public function getFilePath($media, $alias, $ext = 'jpg') {
* @param userId Id of the current user
* @param mediaId Id of the current image/file
*/
public function delete(&$media) {
public function delete(&$media,$verbose=false) {
$verbose_str = array();
$mediaId = intval($media['Media']['id']);
$cacheDir = $this->getPath($media, false);
if (!$cacheDir) {
Expand All @@ -116,6 +117,7 @@ public function delete(&$media) {
$pattern = $this->getFilenamePrefix($mediaId).'.*';
$files = $folder->find($pattern);
if ($files) {
if($verbose) $verbose_str[] = "Delete cached files of image $mediaId";
CakeLog::debug("Delete cached files of image $mediaId");
foreach($files as $file) {
CakeLog::debug("Delete cache file '$file'");
Expand All @@ -124,8 +126,11 @@ public function delete(&$media) {
}
clearstatcache();
} else {

if($verbose) $verbose_str[] = "No cached files found for image $mediaId";
CakeLog::debug("No cached files found for image $mediaId");
}
if($verbose) return $verbose_str;
}

/**
Expand Down
12 changes: 11 additions & 1 deletion Controller/Component/FilterManagerComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ public function readFiles($files, $options = array()) {
}
}
}

CakeLog::debug("Found ".count($stack)." files to import");
$extStack = $this->_sortFilesByExtension($stack);
$order = $this->_getExtensionsByPriority();
Expand All @@ -333,6 +334,8 @@ public function readFiles($files, $options = array()) {
$importLog = $this->_importlog($importLog, $file);
}
}


return $result;
}

Expand Down Expand Up @@ -450,6 +453,7 @@ public function read($filename, $forceReadMeta = false) {
return false;
}
if (!$this->isSupported($filename)) {

CakeLog::debug("File $filename is not supported");
return false;
}
Expand Down Expand Up @@ -493,18 +497,24 @@ public function read($filename, $forceReadMeta = false) {
//return $media;//overload memory with 20kb for each file
return $filename;//around 0.2kb
}
} else {
}
/**
* Comment this else to create media if not exists
*/
/* else {
$media = false;
if ($forceReadMeta) {
//media missing, file will not be readed; force read meta only for EXISTING media;
return false;
}
}
*/

$filter = $this->getFilterByExtension($filename);
CakeLog::debug("Read file $filename with filter ".$filter->getName());
$result = $filter->read($file, $media);


if (isset($result['Media']['id'])) {
return $result['Media']['id'];
}
Expand Down
34 changes: 34 additions & 0 deletions Controller/Component/ImageFilterComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,43 @@ public function read(&$file, &$media = null, $options = array()) {
}
$media = $this->controller->Media->addDefaultAcl($media, $user);



$isNew = true;
};


if ($this->Exiftool->isEnabled()) {
$this->Exiftool->extractImageData($media, $meta);
} else {
$this->_extractImageDataGetId3($media, $meta);
}

if(isset($media['File']) && is_array($media['File']) && count($media['File'])>0){
for($if=0;$if<count($media['File']);$if++){
$path_tmp = $media['File'][$if]['path'];
$pos_path_tmp = strrpos($path_tmp, '/');
if($pos_path_tmp == (strlen($path_tmp)-1)){ // acaba en /, busco otra vez

$path_tmp = substr($media['File'][$if]['path'],0,-1);
$pos_path_tmp = (strrpos($path_tmp, '/')+1);
}
$tags_key[] = substr($path_tmp, $pos_path_tmp);
}

for($tk=0;$tk<count($tags_key);$tk++){
if(!isset($media['Field']['keyword'])){
$media['Field']['keyword'] = array();
}

if(!in_array($tags_key[$tk], $media['Field']['keyword'])) $media['Field']['keyword'][] = $tags_key[$tk];
}

// si existe.

}


if ($media['Media']['name'] != basename($filename)) {
$this->log(">>> File ". basename($filename) . " differs from {$media['Media']['name']} (extractImageData)", 'import');
}
Expand All @@ -103,6 +132,7 @@ public function read(&$file, &$media = null, $options = array()) {
$this->FilterManager->addError($filename, 'MediaSaveError');
return false;
}

if ($isNew) {
$mediaId = $this->Media->getLastInsertID();
if (!$this->controller->MyFile->setMedia($file, $mediaId)) {
Expand All @@ -116,6 +146,7 @@ public function read(&$file, &$media = null, $options = array()) {
} else {
CakeLog::debug("Updated media (id ".$media['Media']['id'].")");
}

$this->controller->MyFile->updateReaded($file);
$this->controller->MyFile->setFlag($file, FILE_FLAG_DEPENDENT);

Expand Down Expand Up @@ -201,6 +232,9 @@ private function _extractImageDataGetId3(&$media, &$data) {
$v['shutter'] = $this->_computeSutter($this->_extract($data, 'jpg/exif/EXIF/ShutterSpeedValue', null));
$v['model'] = $this->_extract($data, 'jpg/exif/IFD0/Model', null);
$v['iso'] = $this->_extract($data, 'jpg/exif/EXIF/ISOSpeedRatings', null);
if(is_array($v['iso'])){
$v['iso'] = null;
}
//CakeLog::debug($data);

// fetch GPS coordinates
Expand Down
Loading