2010-12-07 20:19:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class PluploadController extends Zend_Controller_Action
|
|
|
|
{
|
|
|
|
public function init()
|
|
|
|
{
|
2012-03-14 16:14:22 +01:00
|
|
|
$ajaxContext = $this->_helper->getHelper('AjaxContext');
|
2014-03-13 16:14:30 +01:00
|
|
|
$ajaxContext->addActionContext('upload', 'json')
|
2014-03-21 18:22:00 +01:00
|
|
|
->addActionContext('recent-uploads', 'json')
|
2012-03-14 16:14:22 +01:00
|
|
|
->initContext();
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2011-03-06 22:45:11 +01:00
|
|
|
public function indexAction()
|
|
|
|
{
|
2013-01-14 22:16:14 +01:00
|
|
|
$CC_CONFIG = Config::getConfig();
|
2012-07-11 00:53:06 +02:00
|
|
|
|
2012-10-19 17:09:34 +02:00
|
|
|
$baseUrl = Application_Common_OsPath::getBaseDir();
|
2012-11-22 20:37:54 +01:00
|
|
|
$locale = Application_Model_Preference::GetLocale();
|
2011-04-18 17:02:09 +02:00
|
|
|
|
2014-03-21 18:22:00 +01:00
|
|
|
$this->view->headScript()->appendFile($baseUrl.'js/datatables/js/jquery.dataTables.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
|
2013-01-14 22:00:38 +01:00
|
|
|
$this->view->headScript()->appendFile($baseUrl.'js/plupload/plupload.full.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
|
|
|
$this->view->headScript()->appendFile($baseUrl.'js/plupload/jquery.plupload.queue.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
|
|
|
$this->view->headScript()->appendFile($baseUrl.'js/airtime/library/plupload.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
|
|
|
$this->view->headScript()->appendFile($baseUrl.'js/plupload/i18n/'.$locale.'.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
2011-04-18 17:02:09 +02:00
|
|
|
|
2013-01-14 22:00:38 +01:00
|
|
|
$this->view->headLink()->appendStylesheet($baseUrl.'css/plupload.queue.css?'.$CC_CONFIG['airtime_version']);
|
2014-03-21 18:22:00 +01:00
|
|
|
$this->view->headLink()->appendStylesheet($baseUrl.'css/addmedia.css?'.$CC_CONFIG['airtime_version']);
|
2014-04-14 17:24:39 +02:00
|
|
|
|
|
|
|
$this->view->quotaLimitReached = false;
|
2015-03-11 18:50:17 +01:00
|
|
|
if (Application_Model_Systemstatus::isDiskOverQuota()) {
|
2014-04-14 17:24:39 +02:00
|
|
|
$this->view->quotaLimitReached = true;
|
2015-03-11 18:50:17 +01:00
|
|
|
}
|
2014-10-02 04:04:03 +02:00
|
|
|
|
2015-02-24 17:13:39 +01:00
|
|
|
//Because uploads are done via AJAX (and we're not using Zend form for those), we manually add the CSRF
|
|
|
|
//token in here.
|
2014-10-02 04:04:03 +02:00
|
|
|
$csrf_namespace = new Zend_Session_Namespace('csrf_namespace');
|
2015-02-24 17:13:39 +01:00
|
|
|
//The CSRF token is generated in Bootstrap.php
|
2014-10-02 04:04:03 +02:00
|
|
|
|
|
|
|
$csrf_element = new Zend_Form_Element_Hidden('csrf');
|
|
|
|
$csrf_element->setValue($csrf_namespace->authtoken)->setRequired('true')->removeDecorator('HtmlTag')->removeDecorator('Label');
|
|
|
|
$csrf_form = new Zend_Form();
|
|
|
|
$csrf_form->addElement($csrf_element);
|
|
|
|
$this->view->form = $csrf_form;
|
2011-03-06 22:45:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function uploadAction()
|
|
|
|
{
|
2014-10-02 04:04:03 +02:00
|
|
|
$current_namespace = new Zend_Session_Namespace('csrf_namespace');
|
|
|
|
$observed_csrf_token = $this->_getParam('csrf_token');
|
|
|
|
$expected_csrf_token = $current_namespace->authtoken;
|
2011-03-18 22:15:12 +01:00
|
|
|
|
2014-10-02 04:04:03 +02:00
|
|
|
if($observed_csrf_token == $expected_csrf_token){
|
|
|
|
$upload_dir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
|
|
|
|
$tempFilePath = Application_Model_StoredFile::uploadFile($upload_dir);
|
|
|
|
$tempFileName = basename($tempFilePath);
|
|
|
|
|
|
|
|
$this->_helper->json->sendJson(array("jsonrpc" => "2.0", "tempfilepath" => $tempFileName));
|
|
|
|
}else{
|
|
|
|
$this->_helper->json->sendJson(array("jsonrpc" => "2.0", "valid" => false, "error" => "CSRF token did not match."));
|
|
|
|
}
|
2011-03-06 22:45:11 +01:00
|
|
|
}
|
|
|
|
|
2014-03-21 18:22:00 +01:00
|
|
|
public function recentUploadsAction()
|
2014-03-10 21:32:23 +01:00
|
|
|
{
|
2014-04-23 18:53:43 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
$filter = $request->getParam('uploadFilter', "all");
|
|
|
|
$limit = intval($request->getParam('iDisplayLength', 10));
|
|
|
|
$rowStart = intval($request->getParam('iDisplayStart', 0));
|
2014-03-10 21:32:23 +01:00
|
|
|
|
2014-04-23 18:53:43 +02:00
|
|
|
$recentUploadsQuery = CcFilesQuery::create();
|
|
|
|
//old propel 1.5 to reuse this query item (for counts/finds)
|
|
|
|
$recentUploadsQuery->keepQuery(true);
|
2014-03-22 07:12:03 +01:00
|
|
|
|
2014-06-02 20:14:09 +02:00
|
|
|
//Hide deleted files
|
|
|
|
$recentUploadsQuery->filterByDbFileExists(true);
|
2014-03-21 18:22:00 +01:00
|
|
|
|
2014-06-04 20:15:36 +02:00
|
|
|
$numTotalRecentUploads = $recentUploadsQuery->count();
|
|
|
|
$numTotalDisplayUploads = $numTotalRecentUploads;
|
|
|
|
|
2014-03-21 19:03:17 +01:00
|
|
|
if ($filter == "pending") {
|
2014-04-23 17:52:10 +02:00
|
|
|
$recentUploadsQuery->filterByDbImportStatus(1);
|
2014-04-23 18:53:43 +02:00
|
|
|
$numTotalDisplayUploads = $recentUploadsQuery->count();
|
2014-03-21 19:03:17 +01:00
|
|
|
} else if ($filter == "failed") {
|
2014-04-23 18:53:43 +02:00
|
|
|
$recentUploadsQuery->filterByDbImportStatus(2);
|
|
|
|
$numTotalDisplayUploads = $recentUploadsQuery->count();
|
2014-04-23 17:52:10 +02:00
|
|
|
//TODO: Consider using array('min' => 200)) or something if we have multiple errors codes for failure.
|
2014-03-21 19:03:17 +01:00
|
|
|
}
|
2014-03-22 07:12:03 +01:00
|
|
|
|
2014-04-23 18:53:43 +02:00
|
|
|
$recentUploads = $recentUploadsQuery
|
|
|
|
->orderByDbUtime(Criteria::DESC)
|
|
|
|
->offset($rowStart)
|
|
|
|
->limit($limit)
|
|
|
|
->find();
|
2014-03-21 18:22:00 +01:00
|
|
|
|
|
|
|
$uploadsArray = array();
|
2014-04-23 18:53:43 +02:00
|
|
|
$utcTimezone = new DateTimeZone("UTC");
|
|
|
|
$displayTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
|
2014-03-21 18:22:00 +01:00
|
|
|
|
|
|
|
foreach ($recentUploads as $upload)
|
|
|
|
{
|
2014-04-09 20:57:30 +02:00
|
|
|
$upload = $upload->toArray(BasePeer::TYPE_FIELDNAME);
|
|
|
|
//TODO: $this->sanitizeResponse($upload));
|
|
|
|
$upload['utime'] = new DateTime($upload['utime'], $utcTimezone);
|
|
|
|
$upload['utime']->setTimeZone($displayTimezone);
|
|
|
|
$upload['utime'] = $upload['utime']->format('Y-m-d H:i:s');
|
2014-04-23 18:53:43 +02:00
|
|
|
|
2014-06-02 20:14:09 +02:00
|
|
|
//TODO: Invoke sanitization here (MediaController's removeBlacklist stuff)
|
2014-04-09 20:57:30 +02:00
|
|
|
array_push($uploadsArray, $upload);
|
2014-03-21 18:22:00 +01:00
|
|
|
}
|
2014-03-10 21:32:23 +01:00
|
|
|
|
2014-04-23 18:53:43 +02:00
|
|
|
$this->view->sEcho = intval($request->getParam('sEcho'));
|
|
|
|
$this->view->iTotalDisplayRecords = $numTotalDisplayUploads;
|
|
|
|
$this->view->iTotalRecords = $numTotalRecentUploads;
|
|
|
|
$this->view->files = $uploadsArray;
|
2014-03-21 18:22:00 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|