Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit f3f5b4d

Browse files
author
Charles Ma
committed
ENH: fixed bug #153 Fixed dashboard
1 parent 57494d7 commit f3f5b4d

File tree

29 files changed

+1817
-1
lines changed

29 files changed

+1817
-1
lines changed

core/models/base/ItemRevisionModelBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function addBitstream($itemRevisionDao, $bitstreamDao)
6060
$item->setSizebytes($this->getSize($itemRevisionDao));
6161
$item->setDateCreation(date('c'));
6262

63-
$modulesThumbnail = Zend_Registry::get('notifier')->notifyEvent("EVENT_CORE_CREATE_THUMBNAIL", array($item));
63+
$modulesThumbnail = Zend_Registry::get('notifier')->notifyEvent("EVENT_CORE_CREATE_THUMBNAIL", array($item->toArray(), $itemRevisionDao->toArray()));
6464
if(empty($modulesThumbnail))
6565
{
6666
$mime = $bitstreamDao->getMimetype();

core/views/user/manage.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ $this->headScript()->appendFile($this->coreWebroot.'/public/js/common/common.bro
2121
<div class="viewMain">
2222
<div class="genericThumbnail">
2323
<?php
24+
$thumbnail=$this->user->getThumbnail();
2425
echo $this->userthumbnail($thumbnail);
2526
?>
2627
</div>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
13+
14+
class Thumbnailcreator_AppController extends MIDAS_GlobalModule
15+
{
16+
public $moduleName='thumbnailcreator';
17+
} //end class
18+
?>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/** notification manager*/
3+
class Thumbnailcreator_Notification extends MIDAS_Notification
4+
{
5+
public $_moduleComponents=array('Imagemagick');
6+
public $moduleName = 'thumbnailcreator';
7+
8+
/** init notification process*/
9+
public function init()
10+
{
11+
$this->addTask("TASK_THUMBNAILCREATOR_CREATE", 'createThumbnail', "Create Thumbnail. Parameters: Item, Revision");
12+
$this->addEvent('EVENT_CORE_CREATE_THUMBNAIL', 'TASK_THUMBNAILCREATOR_CREATE');
13+
}//end init
14+
15+
/** createThumbnail */
16+
public function createThumbnail($params)
17+
{
18+
$this->ModuleComponent->Imagemagick->createThumbnail($params[0]);
19+
return;
20+
}
21+
} //end class
22+
?>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.local.ini
2+
*.local.ini.old
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[global]
2+
; version of the module
3+
version = 1.0.0
4+
; full name
5+
fullname= Thumbnail Creator
6+
; description
7+
description= Using Image Magick
8+
;Category
9+
category= Filter
10+
;Dependencies
11+
dependencies= scheduler
12+
13+
;image magick folder
14+
imagemagick=
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
13+
//define("MIDAS_EXAMPLE", 0);
14+
?>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
13+
14+
class Thumbnailcreator_ConfigController extends Thumbnailcreator_AppController
15+
{
16+
public $_moduleForms=array('Config');
17+
public $_components=array('Utility', 'Date');
18+
19+
/** index action*/
20+
function indexAction()
21+
{
22+
if(!$this->logged||!$this->userSession->Dao->getAdmin()==1)
23+
{
24+
throw new Zend_Exception("You should be an administrator");
25+
}
26+
27+
if(file_exists(BASE_PATH."/core/configs/".$this->moduleName.".local.ini"))
28+
{
29+
$applicationConfig = parse_ini_file(BASE_PATH."/core/configs/".$this->moduleName.".local.ini", true);
30+
}
31+
else
32+
{
33+
$applicationConfig = parse_ini_file(BASE_PATH.'/modules/'.$this->moduleName.'/configs/module.ini', true);
34+
}
35+
$configForm = $this->ModuleForm->Config->createConfigForm();
36+
37+
$formArray = $this->getFormAsArray($configForm);
38+
$formArray['imagemagick']->setValue($applicationConfig['global']['imagemagick']);
39+
40+
$this->view->configForm = $formArray;
41+
42+
if($this->_request->isPost())
43+
{
44+
$this->_helper->layout->disableLayout();
45+
$this->_helper->viewRenderer->setNoRender();
46+
$submitConfig = $this->_getParam('submitConfig');
47+
if(isset($submitConfig))
48+
{
49+
if(file_exists(BASE_PATH."/core/configs/".$this->moduleName.".local.ini.old"))
50+
{
51+
unlink(BASE_PATH."/core/configs/".$this->moduleName.".local.ini.old");
52+
}
53+
if(file_exists(BASE_PATH."/core/configs/".$this->moduleName.".local.ini"))
54+
{
55+
rename(BASE_PATH."/core/configs/".$this->moduleName.".local.ini",BASE_PATH."/core/configs/".$this->moduleName.".local.ini.old");
56+
}
57+
$applicationConfig['global']['imagemagick'] = $this->_getParam('imagemagick');
58+
$this->Component->Utility->createInitFile(BASE_PATH."/core/configs/".$this->moduleName.".local.ini", $applicationConfig);
59+
echo JsonComponent::encode(array(true, 'Changed saved'));
60+
}
61+
}
62+
}
63+
64+
}//end class
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
13+
class Thumbnailcreator_ImagemagickComponent extends AppComponent
14+
{
15+
/** createThumbnail */
16+
public function createThumbnail($item)
17+
{
18+
$modelLoader = new MIDAS_ModelLoader;
19+
$itemModel = $modelLoader->loadModel("Item");
20+
$item = $itemModel->load($item['item_id']);
21+
$revision = $itemModel->getLastRevision($item);
22+
$bitstreams = $revision->getBitstreams();
23+
if(count($bitstreams) != 1)
24+
{
25+
return;
26+
}
27+
$bitstream = $bitstreams[0];
28+
$ext = strtolower(substr(strrchr($bitstream->getName(), '.'), 1));
29+
30+
// create destination
31+
$tmpPath = BASE_PATH.'/data/thumbnail/'.rand(1, 1000);
32+
if(!file_exists(BASE_PATH.'/data/thumbnail/'))
33+
{
34+
throw new Zend_Exception("Problem thumbnail path: ".BASE_PATH.'/data/thumbnail/');
35+
}
36+
if(!file_exists($tmpPath))
37+
{
38+
mkdir($tmpPath);
39+
}
40+
$tmpPath .= '/'.rand(1, 1000);
41+
if(!file_exists($tmpPath))
42+
{
43+
mkdir($tmpPath);
44+
}
45+
$destionation = $tmpPath."/".rand(1, 1000).'.jpeg';
46+
while(file_exists($destionation))
47+
{
48+
$destionation = $tmpPath."/".rand(1, 1000).'.jpeg';
49+
}
50+
$pathThumbnail = $destionation;
51+
52+
require_once BASE_PATH.'/modules/thumbnailcreator/library/Phmagick/phmagick.php';
53+
$modulesConfig=Zend_Registry::get('configsModules');
54+
$imageMagickPath = $modulesConfig['thumbnailcreator']->imagemagick;
55+
56+
// try to create a thumbnail (generic way)
57+
try
58+
{
59+
switch($ext)
60+
{
61+
case "pdf":
62+
case "mpg":
63+
case "mpeg":
64+
case "mp4":
65+
case "m4v":
66+
case "avi":
67+
case "mov":
68+
case "flv":
69+
case "mp4":
70+
case "rm":
71+
$p = new phMagick("", $pathThumbnail);
72+
$p->setImageMagickPath($imageMagickPath);
73+
$p->acquireFrame($bitstream->getFullPath(), 0);
74+
$p->resizeExactly(100,100);
75+
break;
76+
break;
77+
default:
78+
$p = new phMagick($bitstream->getFullPath(), $pathThumbnail);
79+
$p->setImageMagickPath($imageMagickPath);
80+
$p->resizeExactly(100,100);
81+
}
82+
}
83+
catch (phMagickException $exc)
84+
{
85+
echo $exc->getMessage();
86+
}
87+
catch (Exception $exc)
88+
{
89+
90+
}
91+
92+
if(file_exists($pathThumbnail))
93+
{
94+
$oldThumbnail = $item->getThumbnail();
95+
if(!empty($oldThumbnail))
96+
{
97+
unlink($oldThumbnail);
98+
}
99+
$item->setThumbnail(substr($pathThumbnail, strlen(BASE_PATH) + 1));
100+
$itemModel->save($item);
101+
}
102+
return;
103+
}
104+
105+
} // end class
106+
?>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
13+
class Thumbnailcreator_ConfigForm extends AppForm
14+
{
15+
16+
/** create form */
17+
public function createConfigForm()
18+
{
19+
$form = new Zend_Form;
20+
21+
$form->setAction($this->webroot.'/thumbnailcreator/config/index')
22+
->setMethod('post');
23+
24+
$imagemagick = new Zend_Form_Element_Text('imagemagick');
25+
26+
$submit = new Zend_Form_Element_Submit('submitConfig');
27+
$submit ->setLabel('Save configuration');
28+
29+
$form->addElements(array($imagemagick, $submit));
30+
return $form;
31+
}
32+
33+
} // end class
34+
?>

0 commit comments

Comments
 (0)