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

Commit 67386b7

Browse files
author
Charles Marion
committed
ENH: 0009592: Improve upload link management
1 parent 7ae55d4 commit 67386b7

File tree

14 files changed

+174
-69
lines changed

14 files changed

+174
-69
lines changed

core/controllers/DownloadController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ public function indexAction()
103103
elseif(count($bitstreams) == 1)
104104
{
105105
$bitstream = $bitstreams[0];
106+
if(strpos($bitstream->getPath(), 'http://') !== false)
107+
{
108+
$this->_redirect($bitstream->getPath());
109+
return;
110+
}
106111
$this->view->mimetype = $bitstream->getMimetype();
107112
$this->view->path = $bitstream->getAssetstore()->getPath().'/'.$bitstream->getPath();
108113
$this->view->name = $bitstream->getName();

core/controllers/UploadController.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,28 +96,19 @@ public function savelinkAction()
9696
{
9797
throw new Zend_Exception("Error, should be an ajax action.");
9898
}
99-
$form = $this->Form->Upload->createUploadLinkForm();
100-
101-
if(true)
102-
{
103-
$path_parts = pathinfo($form->getValue('url'));
104-
$name = $path_parts['basename'];
105-
$item = new ItemDao;
106-
$item->setName($name);
107-
$this->Item->save($item);
108-
$this->userSession->uploaded[] = $item->getKey();
109-
$feed = $this->Feed->createFeed($this->userSession->Dao, MIDAS_FEED_CREATE_LINK_ITEM, $item);
110-
$this->Folder->addItem($this->userSession->Dao->getPrivateFolder(), $item);
111-
$this->Feedpolicyuser->createPolicy($this->userSession->Dao, $feed, MIDAS_POLICY_ADMIN);
112-
$this->Itempolicyuser->createPolicy($this->userSession->Dao, $item, MIDAS_POLICY_ADMIN);
113-
$itemRevisionDao = new ItemRevisionDao;
114-
$itemRevisionDao->setChanges('Initial revision');
115-
$itemRevisionDao->setUser_id($this->userSession->Dao->getKey());
116-
$this->Item->addRevision($item, $itemRevisionDao);
117-
$this->getLogger()->info(__METHOD__." Upload link ok ".$name.":".$form->getValue('url'));
118-
}
99+
119100
$this->_helper->layout->disableLayout();
120101
$this->_helper->viewRenderer->setNoRender();
102+
$parent = $this->_getParam("parent");
103+
$name = $this->_getParam("name");
104+
$url = $this->_getParam("url");
105+
$parent = $this->_getParam("parent");
106+
$license = $this->_getParam("license");
107+
if(!empty($url) && !empty($name))
108+
{
109+
$item = $this->Component->Upload->createLinkItem($this->userSession->Dao, $name, $url, $parent);
110+
$this->userSession->uploaded[] = $item->getKey();
111+
}
121112
}//end simple upload
122113

123114
/** java upload*/

core/controllers/UserController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public function settingsAction()
360360
{
361361
$userDao = $this->User->load($userDao->getKey());
362362
$oldThumbnail = $userDao->getThumbnail();
363-
if(!empty($oldThumbnail))
363+
if(!empty($oldThumbnail) && file_exists(BASE_PATH.'/'.$oldThumbnail))
364364
{
365365
unlink(BASE_PATH.'/'.$oldThumbnail);
366366
}
@@ -385,7 +385,7 @@ public function settingsAction()
385385
{
386386
$userDao = $this->User->load($userDao->getKey());
387387
$oldThumbnail = $userDao->getThumbnail();
388-
if(!empty($oldThumbnail))
388+
if(!empty($oldThumbnail) && file_exists(BASE_PATH.'/'.$oldThumbnail))
389389
{
390390
unlink(BASE_PATH.'/'.$oldThumbnail);
391391
}

core/controllers/components/HttpuploadComponent.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ function process_http_upload($params)
4545
set_time_limit(0); // Timeout of the PHP script set to Infinite
4646
ignore_user_abort(TRUE);
4747

48-
$test = @$params['testingmode'];
48+
if(isset($params['testingmode']))
49+
{
50+
$test = $params['testingmode'];
51+
}
4952
if(isset($test) && !empty($test))
5053
{
5154
if(!isset($params['path']) || empty($params['path']))

core/controllers/components/UploadComponent.php

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,108 @@ function uploadBitstream($bitstreamdao, $assetstoredao)
8585
return true;
8686
} // end uploadBitstream()
8787

88+
/** save upload item in the DB */
89+
public function createLinkItem($userDao, $name, $url, $parent = null)
90+
{
91+
$modelLoad = new MIDAS_ModelLoader();
92+
$itemModel = $modelLoad->loadModel('Item');
93+
$feedModel = $modelLoad->loadModel('Feed');
94+
$folderModel = $modelLoad->loadModel('Folder');
95+
$bitstreamModel = $modelLoad->loadModel('Bitstream');
96+
$assetstoreModel = $modelLoad->loadModel('Assetstore');
97+
$feedpolicygroupModel = $modelLoad->loadModel('Feedpolicygroup');
98+
$itemRevisionModel = $modelLoad->loadModel('ItemRevision');
99+
$feedpolicyuserModel = $modelLoad->loadModel('Feedpolicyuser');
100+
$itempolicyuserModel = $modelLoad->loadModel('Itempolicyuser');
101+
$itemKeywordModel = $modelLoad->loadModel('ItemKeyword');
102+
103+
if($userDao == null)
104+
{
105+
throw new Zend_Exception('Please log in');
106+
}
107+
108+
if($parent == null)
109+
{
110+
$parent = $userDao->getPrivateFolder();
111+
}
112+
if(is_numeric($parent))
113+
{
114+
$parent = $folderModel->load($parent);
115+
}
116+
117+
if($parent == false || !$folderModel->policyCheck($parent, $userDao, MIDAS_POLICY_WRITE))
118+
{
119+
throw new Zend_Exception('Parent permissions errors');
120+
}
121+
122+
Zend_Loader::loadClass("ItemDao", BASE_PATH . '/core/models/dao');
123+
$item = new ItemDao;
124+
$item->setName($name);
125+
$item->setDate(date('c'));
126+
$item->setDescription('');
127+
$item->setType(0);
128+
$item->setThumbnail('');
129+
$itemModel->save($item);
130+
131+
$feed = $feedModel->createFeed($userDao, MIDAS_FEED_CREATE_ITEM, $item);
132+
133+
$folderModel->addItem($parent, $item);
134+
$itemModel->copyParentPolicies($item, $parent, $feed);
135+
136+
$feedpolicyuserModel->createPolicy($userDao, $feed, MIDAS_POLICY_ADMIN);
137+
$itempolicyuserModel->createPolicy($userDao, $item, MIDAS_POLICY_ADMIN);
138+
139+
Zend_Loader::loadClass("ItemRevisionDao", BASE_PATH . '/core/models/dao');
140+
$itemRevisionDao = new ItemRevisionDao;
141+
$itemRevisionDao->setChanges('Initial revision');
142+
$itemRevisionDao->setUser_id($userDao->getKey());
143+
$itemRevisionDao->setDate(date('c'));
144+
$itemRevisionDao->setLicense(null);
145+
$itemModel->addRevision($item, $itemRevisionDao);
146+
147+
// Set the keyword for the item
148+
Zend_Loader::loadClass("ItemKeywordDao", BASE_PATH . '/core/models/dao');
149+
$keyword = new ItemKeywordDao();
150+
$keyword->setValue($name);
151+
$itemKeywordModel->insertKeyword($keyword);
152+
$itemModel->addKeyword($item, $keyword);
153+
154+
$tmp = str_replace('.', ' ', $name);
155+
$tmp = str_replace('_', ' ', $tmp);
156+
$tmp = str_replace('-', ' ', $tmp);
157+
158+
$keywords = explode(' ', $tmp);
159+
if(count($keywords) > 1)
160+
{
161+
foreach($keywords as $key => $value)
162+
{
163+
$keyword = new ItemKeywordDao();
164+
$keyword->setValue($value);
165+
$itemKeywordModel->insertKeyword($keyword);
166+
$itemModel->addKeyword($item, $keyword);
167+
}
168+
}
169+
170+
// Add bitstreams to the revision
171+
Zend_Loader::loadClass("BitstreamDao", BASE_PATH . '/core/models/dao');
172+
$bitstreamDao = new BitstreamDao;
173+
$bitstreamDao->setName($url);
174+
$bitstreamDao->setPath($url);
175+
$bitstreamDao->setMimetype('url');
176+
$bitstreamDao->setSizebytes(0);
177+
$bitstreamDao->setChecksum(' ');
178+
179+
$defaultAssetStoreId = Zend_Registry::get('configGlobal')->defaultassetstore->id;
180+
$bitstreamDao->setAssetstoreId($defaultAssetStoreId);
181+
$assetstoreDao = $assetstoreModel->load($defaultAssetStoreId);
182+
183+
$itemRevisionModel->addBitstream($itemRevisionDao, $bitstreamDao);
184+
185+
$this->getLogger()->info(__METHOD__." Upload ok ");
186+
return $item;
187+
}//end createUploadedItem
188+
189+
88190
/** save upload item in the DB */
89191
public function createUploadedItem($userDao, $name, $path, $parent = null, $license = null)
90192
{

core/controllers/forms/UploadForm.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public function createUploadLinkForm()
1111
->setMethod('post');
1212

1313
$validator = new Zend_Validate_Callback(array('Zend_Uri', 'check'));
14+
15+
$name = new Zend_Form_Element_Text('name');
16+
$name ->setRequired(true);
1417
$url = new Zend_Form_Element_Text('url');
1518
$url ->setValue('http://')
1619
->setRequired(true)
@@ -19,10 +22,10 @@ public function createUploadLinkForm()
1922

2023

2124
$submit = new Zend_Form_Element_Submit('submit');
22-
$submit ->setLabel($this->t("Link"))
25+
$submit ->setLabel($this->t("Save Link"))
2326
->setAttrib('class', 'globalButton');
2427

25-
$form->addElements(array($url, $submit));
28+
$form->addElements(array($name, $url, $submit));
2629
return $form;
2730
}
2831

core/models/pdo/ItemRevisionModel.php

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,30 +100,24 @@ function addBitstream($itemRevisionDao, $bitstreamDao)
100100
$item = $itemRevisionDao->getItem($bitstreamDao);
101101
$item->setSizebytes($this->getSize($itemRevisionDao));
102102
$item->setDate(date('c'));
103-
104-
/** thumbnail*/
105-
/* $procces = Zend_Registry::get('configGlobal')->processing;
106-
if($procces == 'cron')
107-
{
108-
$TaskModel->createTask(MIDAS_TASK_ITEM_THUMBNAIL, MIDAS_RESOURCE_ITEM, $item->getKey(), '');
109-
}
110-
else
103+
104+
$procces = Zend_Registry::get('configGlobal')->processing;
105+
require_once BASE_PATH.'/core/controllers/components/FilterComponent.php';
106+
$filterComponent = new FilterComponent();
107+
$thumbnailCreator = $filterComponent->getFilter('ThumbnailCreator');
108+
$thumbnailCreator->inputFile = $bitstreamDao->getFullPath();
109+
$thumbnailCreator->inputName = $bitstreamDao->getName();
110+
$hasThumbnail = $thumbnailCreator->process();
111+
if(isset($thumbnailCreator->outputFile) && $hasThumbnail && file_exists($thumbnailCreator->outputFile))
111112
{
112-
$thumbnailCreator = $this->Component->Filter->getFilter('ThumbnailCreator');
113-
$thumbnailCreator->inputFile = $bitstreamDao->getPath();
114-
$thumbnailCreator->inputName = $bitstreamDao->getName();
115-
$hasThumbnail = $thumbnailCreator->process();
116-
$thumbnail_output_file = $thumbnailCreator->outputFile;
117-
if($hasThumbnail&& file_exists($thumbnail_output_file))
113+
$oldThumbnail = $item->getThumbnail();
114+
if(!empty($oldThumbnail))
118115
{
119-
$oldThumbnail = $item->getThumbnail();
120-
if(!empty($oldThumbnail))
121-
{
122-
unlink($oldThumbnail);
123-
}
124-
$item->setThumbnail(substr($thumbnail_output_file, strlen(BASE_PATH)+1));
125-
}
126-
}*/
116+
unlink($oldThumbnail);
117+
}
118+
$item->setThumbnail(substr($thumbnailCreator->outputFile, strlen(BASE_PATH)+1));
119+
}
120+
127121
$ItemModel->save($item);
128122
} // end addBitstream
129123

core/public/js/browse/browse.movecopy.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
$('#selectElements').click(function(){
88
$('#destinationUpload').html($('#selectedDestination').html());
99
$('#destinationId').val($('#selectedDestinationHidden').val());
10+
$('.destinationUpload').html($('#selectedDestination').html());
11+
$('.destinationId').val($('#selectedDestinationHidden').val());
1012
$( "div.MainDialog" ).dialog('close');
1113
return false;
1214
});

core/public/js/upload/upload.simpleupload.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@
155155

156156

157157

158-
$('#browseMIDASLink').click(function()
158+
$('.browseMIDASLink').click(function()
159159
{
160160
loadDialog("select","/browse/movecopy/?selectElement=true");
161161
showDialog('Browse');
162-
});
162+
});
163+

core/translation/fr-main.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ Download lastest revision;T
182182
My information;Mes informations
183183
My Password;Mon Mot de Passe
184184
Current Avatar;Avatar actuel
185-
Upload new avatar;Uploader nouveau avatar
185+
Upload new avatar;Ajouter un nouvel avatar
186186
Modify password;Modifier mot de passe
187187
Retype new password;Retapper nouveau mot de passe
188188
Sharing settings;Param�tres de partage
189189
folder;r�pertoire
190-
item;docuement
190+
item;document
191191
You can use the following direct link to share the;Vous pouvez utiliser le lien suivant pour partager le
192192
Permissions;Autorisations
193193
Anyone on the Internet can find and access. No sign-in required.;Tous le monde peut trouver et voir. Pas d'authentification requise.

0 commit comments

Comments
 (0)