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

Commit

Permalink
ENH: fixed bug #153 Fixed dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Ma committed Jun 27, 2011
1 parent 57494d7 commit f3f5b4d
Show file tree
Hide file tree
Showing 29 changed files with 1,817 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/models/base/ItemRevisionModelBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function addBitstream($itemRevisionDao, $bitstreamDao)
$item->setSizebytes($this->getSize($itemRevisionDao));
$item->setDateCreation(date('c'));

$modulesThumbnail = Zend_Registry::get('notifier')->notifyEvent("EVENT_CORE_CREATE_THUMBNAIL", array($item));
$modulesThumbnail = Zend_Registry::get('notifier')->notifyEvent("EVENT_CORE_CREATE_THUMBNAIL", array($item->toArray(), $itemRevisionDao->toArray()));
if(empty($modulesThumbnail))
{
$mime = $bitstreamDao->getMimetype();
Expand Down
1 change: 1 addition & 0 deletions core/views/user/manage.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ $this->headScript()->appendFile($this->coreWebroot.'/public/js/common/common.bro
<div class="viewMain">
<div class="genericThumbnail">
<?php
$thumbnail=$this->user->getThumbnail();
echo $this->userthumbnail($thumbnail);
?>
</div>
Expand Down
18 changes: 18 additions & 0 deletions modules/thumbnailcreator/AppController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
69328 Lyon, FRANCE.
See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/


class Thumbnailcreator_AppController extends MIDAS_GlobalModule
{
public $moduleName='thumbnailcreator';
} //end class
?>
22 changes: 22 additions & 0 deletions modules/thumbnailcreator/Notification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/** notification manager*/
class Thumbnailcreator_Notification extends MIDAS_Notification
{
public $_moduleComponents=array('Imagemagick');
public $moduleName = 'thumbnailcreator';

/** init notification process*/
public function init()
{
$this->addTask("TASK_THUMBNAILCREATOR_CREATE", 'createThumbnail', "Create Thumbnail. Parameters: Item, Revision");
$this->addEvent('EVENT_CORE_CREATE_THUMBNAIL', 'TASK_THUMBNAILCREATOR_CREATE');
}//end init

/** createThumbnail */
public function createThumbnail($params)
{
$this->ModuleComponent->Imagemagick->createThumbnail($params[0]);
return;
}
} //end class
?>
2 changes: 2 additions & 0 deletions modules/thumbnailcreator/configs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.local.ini
*.local.ini.old
14 changes: 14 additions & 0 deletions modules/thumbnailcreator/configs/module.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[global]
; version of the module
version = 1.0.0
; full name
fullname= Thumbnail Creator
; description
description= Using Image Magick
;Category
category= Filter
;Dependencies
dependencies= scheduler

;image magick folder
imagemagick=
14 changes: 14 additions & 0 deletions modules/thumbnailcreator/constant/module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
69328 Lyon, FRANCE.
See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/

//define("MIDAS_EXAMPLE", 0);
?>
64 changes: 64 additions & 0 deletions modules/thumbnailcreator/controllers/ConfigController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
69328 Lyon, FRANCE.
See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/


class Thumbnailcreator_ConfigController extends Thumbnailcreator_AppController
{
public $_moduleForms=array('Config');
public $_components=array('Utility', 'Date');

/** index action*/
function indexAction()
{
if(!$this->logged||!$this->userSession->Dao->getAdmin()==1)
{
throw new Zend_Exception("You should be an administrator");
}

if(file_exists(BASE_PATH."/core/configs/".$this->moduleName.".local.ini"))
{
$applicationConfig = parse_ini_file(BASE_PATH."/core/configs/".$this->moduleName.".local.ini", true);
}
else
{
$applicationConfig = parse_ini_file(BASE_PATH.'/modules/'.$this->moduleName.'/configs/module.ini', true);
}
$configForm = $this->ModuleForm->Config->createConfigForm();

$formArray = $this->getFormAsArray($configForm);
$formArray['imagemagick']->setValue($applicationConfig['global']['imagemagick']);

$this->view->configForm = $formArray;

if($this->_request->isPost())
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$submitConfig = $this->_getParam('submitConfig');
if(isset($submitConfig))
{
if(file_exists(BASE_PATH."/core/configs/".$this->moduleName.".local.ini.old"))
{
unlink(BASE_PATH."/core/configs/".$this->moduleName.".local.ini.old");
}
if(file_exists(BASE_PATH."/core/configs/".$this->moduleName.".local.ini"))
{
rename(BASE_PATH."/core/configs/".$this->moduleName.".local.ini",BASE_PATH."/core/configs/".$this->moduleName.".local.ini.old");
}
$applicationConfig['global']['imagemagick'] = $this->_getParam('imagemagick');
$this->Component->Utility->createInitFile(BASE_PATH."/core/configs/".$this->moduleName.".local.ini", $applicationConfig);
echo JsonComponent::encode(array(true, 'Changed saved'));
}
}
}

}//end class
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
69328 Lyon, FRANCE.
See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/

class Thumbnailcreator_ImagemagickComponent extends AppComponent
{
/** createThumbnail */
public function createThumbnail($item)
{
$modelLoader = new MIDAS_ModelLoader;
$itemModel = $modelLoader->loadModel("Item");
$item = $itemModel->load($item['item_id']);
$revision = $itemModel->getLastRevision($item);
$bitstreams = $revision->getBitstreams();
if(count($bitstreams) != 1)
{
return;
}
$bitstream = $bitstreams[0];
$ext = strtolower(substr(strrchr($bitstream->getName(), '.'), 1));

// create destination
$tmpPath = BASE_PATH.'/data/thumbnail/'.rand(1, 1000);
if(!file_exists(BASE_PATH.'/data/thumbnail/'))
{
throw new Zend_Exception("Problem thumbnail path: ".BASE_PATH.'/data/thumbnail/');
}
if(!file_exists($tmpPath))
{
mkdir($tmpPath);
}
$tmpPath .= '/'.rand(1, 1000);
if(!file_exists($tmpPath))
{
mkdir($tmpPath);
}
$destionation = $tmpPath."/".rand(1, 1000).'.jpeg';
while(file_exists($destionation))
{
$destionation = $tmpPath."/".rand(1, 1000).'.jpeg';
}
$pathThumbnail = $destionation;

require_once BASE_PATH.'/modules/thumbnailcreator/library/Phmagick/phmagick.php';
$modulesConfig=Zend_Registry::get('configsModules');
$imageMagickPath = $modulesConfig['thumbnailcreator']->imagemagick;

// try to create a thumbnail (generic way)
try
{
switch($ext)
{
case "pdf":
case "mpg":
case "mpeg":
case "mp4":
case "m4v":
case "avi":
case "mov":
case "flv":
case "mp4":
case "rm":
$p = new phMagick("", $pathThumbnail);
$p->setImageMagickPath($imageMagickPath);
$p->acquireFrame($bitstream->getFullPath(), 0);
$p->resizeExactly(100,100);
break;
break;
default:
$p = new phMagick($bitstream->getFullPath(), $pathThumbnail);
$p->setImageMagickPath($imageMagickPath);
$p->resizeExactly(100,100);
}
}
catch (phMagickException $exc)
{
echo $exc->getMessage();
}
catch (Exception $exc)
{

}

if(file_exists($pathThumbnail))
{
$oldThumbnail = $item->getThumbnail();
if(!empty($oldThumbnail))
{
unlink($oldThumbnail);
}
$item->setThumbnail(substr($pathThumbnail, strlen(BASE_PATH) + 1));
$itemModel->save($item);
}
return;
}

} // end class
?>
34 changes: 34 additions & 0 deletions modules/thumbnailcreator/controllers/forms/ConfigForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
69328 Lyon, FRANCE.
See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/

class Thumbnailcreator_ConfigForm extends AppForm
{

/** create form */
public function createConfigForm()
{
$form = new Zend_Form;

$form->setAction($this->webroot.'/thumbnailcreator/config/index')
->setMethod('post');

$imagemagick = new Zend_Form_Element_Text('imagemagick');

$submit = new Zend_Form_Element_Submit('submitConfig');
$submit ->setLabel('Save configuration');

$form->addElements(array($imagemagick, $submit));
return $form;
}

} // end class
?>
31 changes: 31 additions & 0 deletions modules/thumbnailcreator/library/Phmagick/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Thank you for downloading phMagick

phMagick needs 2 things to be sucessfully installed

* imagemagick available ate http://www.imagemagick.org
* and php must allow access to the exec() function.

For examples you can browse http://www.francodacosta.com/phmagick there are pleanty of examples there.


Basic Mechanics

phMagick philosophy is extremely simple, you say where is the source image and where you want the new image and then apply actions to it
One great feature of phMagick is that you can apply several actions to an image, making it extremely powerful and able to create very complex images

In the combination example below you will see how easy it is to create a thumbnail with rounded corners and then applying a drop shadow to it.

Enough talking, let's look at some example code to see its simplicity

<?php
include "phMagick.php";
$p = new phMagick("source.png","destination.png");
$p->rotate(45);
?>

In the first line we tell PHP that we are using a file named phMagick.php, it's were phMagick is declared, you only need to do this once.
Line 2 creates a phMagick instance, and say that source.png will be our source image and destination.png will be the new image
Line 3 does the magic, in this case rotates source.png 45 degrees and saves it as destination.png


If you need assistance feel free to mail me at sven @ francodacosta.com .
Loading

0 comments on commit f3f5b4d

Please sign in to comment.