📄 uploads_controller.php.svn-base
字号:
$this->Upload->rollback(); $this->set('error_mesg', 'There was an error saving your upload.'); } } else { $this->Upload->rollback(); $this->set('error_mesg', 'There was an error saving your upload.'); } } } else { // Something is wrong. Either there was an error uploading the file, or // they sent an incomplete POST. Either way, not much we can do. $this->set('error_mesg', 'Failing: There was an error saving your upload.'); } //@todo Really, they only need a file OR a contentsource[type], but this //will tell them they need all of them. Since this form isn't going to //go live anyway, I'll leave it, but if we ever need to make the form //public, this is something to fix. $this->Upload->validates($this->data); $this->File->validates($this->data); $this->Contentsource->validates($this->data); $this->Contentsourcetype->validates($this->data); // Send the errors to the form $this->validateErrors($this->Upload, $this->File); if ($this->nbClient) { $this->returnJoeyStatusCode($this->ERROR_UPLOAD); } } // handle XHTML MP browser if (BrowserAgent::isMobile()) { $this->action = 'mp_add'; $this->layout = 'mp'; } } function deleteAll() { $data = $this->User->findAllById($this->_user['id']); $_count = 0; foreach ($data[0]['Upload'] as $row) { $id = $row['id']; if ($this->delete($id) == false) { $this->log("deleteAll: Delete of " . $id . " failed."); } else { $_count++; } } $this->flash("{$_count} items deleted", '/uploads/index', 2); } function deleteByFileID($id) { $_item = $this->File->findById($id); $this->delete($_item['Upload']['id']); } function delete($id) { if (!is_numeric($id)) { if ($this->nbClient) { $this->returnJoeyStatusCode($this->ERROR_DELETE); } else { $this->flash('Delete failed', '/uploads/index',2); } } $_item = $this->Upload->findById($id, null,null,2);//@todo this pulls way too much data $_owner = $this->Upload->findOwnerDataFromUploadId($id); // Check for access if (empty($_owner) || ($_owner['User']['id'] != $this->_user['id'])) { if ($this->nbClient) { $this->returnJoeyStatusCode($this->ERROR_NOAUTH); } else { $this->flash('Delete failed', '/uploads/index',2); } } $this->Upload->begin(); // If this is a content source upload, kill that too. if (!empty( $_item['File'][0]['Contentsource'] )) { $csid = $_item['File'][0]['Contentsource'][0]['id']; if (! $this->Contentsource->delete($csid)) { $this->Upload->rollback(); if ($this->nbClient) { $this->returnJoeyStatusCode($this->ERROR_DELETE); } else { $this->flash('Content Source Delete Failed', '/uploads/index',2); } } } if ($this->Upload->delete($id)) { // Delete the files if they exist if (array_key_exists(0,$_item['File'])) { if (!unlink(UPLOAD_DIR."/{$this->_user['id']}/{$_item['File'][0]['name']}")) { // Don't make this fatal. If we couldn't unlink, it is a warning //$this->Upload->rollback(); //$this->flash('Delete failed', '/uploads/index',2); } if (!empty($_item['File'][0]['original_name'])) { if (!unlink(UPLOAD_DIR."/{$this->_user['id']}/originals/{$_item['File'][0]['original_name']}")) { // Don't make this fatal. If we couldn't unlink, it is a warning //$this->Upload->rollback(); //$this->flash('Delete failed', '/uploads/index',2); } } if (!empty($_item['File'][0]['preview_name'])) { if (!unlink(UPLOAD_DIR."/{$this->_user['id']}/previews/{$_item['File'][0]['preview_name']}")) { // Don't make this fatal. If we couldn't unlink, it is a warning //$this->Upload->rollback(); //$this->flash('Delete failed', '/uploads/index',2); } } } $this->Upload->commit(); if ($this->nbClient) { $this->returnJoeyStatusCode($this->SUCCESS); } else { $this->flash('Upload Deleted', '/uploads/index',2); } } else { if ($this->nbClient) { $this->returnJoeyStatusCode($this->ERROR_DELETE); } else { $this->flash('Delete failed', '/uploads/index',2); } } } function rss() { $this->layout = 'xml'; $this->set('uploads', $this->Upload->findAllUploadsForUserId($this->_user['id'])); } function index() { $_options = array(); // check to see if we have a filter "type" if (array_key_exists('type',$_POST)) $_options['types'] = $this->filetypes[ $_POST['type'] ]; else if (array_key_exists('type',$_GET)) $_options['types'] = $this->filetypes[ $_GET['type'] ]; else if (array_key_exists('type',$_GET)) { //@todo verify type $_options['types'] = $this->filetypes[ $_GET['type'] ]; } // check to see if we have to deal with "since" if (array_key_exists('since',$_POST)) $_options['since'] = $_POST['since']; else if (array_key_exists('since',$_GET)) $_options['since'] = $_GET['since']; // We are dealing with a J2ME client here if ($this->nbClient) { // testing $_GET is for testing really.... if (array_key_exists('limit',$_GET)) { $_options['limit'] = $_GET['limit']; } if (array_key_exists('start',$_GET)) { $_options['start'] = $_GET['start']; } if (array_key_exists('limit',$_POST)) { $_options['limit'] = $_POST['limit']; } if (array_key_exists('start',$_POST)) { $_options['start'] = $_POST['start']; } // the nbclient needs to see deleted items. $_options['deleted'] = true; $data = $this->Upload->findAllUploadsForUserId($this->_user['id'], $_options); $total_count = $this->Upload->findCountForUserId($this->_user['id']); $count = 0; foreach ($data as $row) { if (!empty($row['File']['preview_name']) && file_exists(UPLOAD_DIR."/{$this->_user['id']}/previews/{$row['File']['preview_name']}")) { $preview_data = file_get_contents (UPLOAD_DIR."/{$this->_user['id']}/previews/{$row['File']['preview_name']}"); $data[$count]['preview'] = base64_encode($preview_data); } else { $data[$count]['preview'] = ''; } // left joins bring back null rows if (array_key_exists('id',$row['Contentsource']) && !empty($row['Contentsource']['id'])) { $data[$count]['type'] = $row['Contentsourcetype']['name']; } else { $data[$count]['type'] = $row['File']['type']; } $count++; } $this->set('uploads', $data); $this->set('count', $count); $this->set('total_count', $total_count); $this->layout = NULL; $this->action = 'j2me_index'; header("X-joey-status: 200"); } else { // Render a page for the browser client $this->pageTitle = 'Uploads'; $_pagination_options = array( 'direction' => 'DESC', 'sortBy' => 'id', 'total' => count($this->Upload->findAllUploadsForUserId($this->_user['id'])) ); list(,$limit,$page) = $this->Pagination->init(array(), array(), $_pagination_options); // @todo need to calculate $start $_options['limit'] = $limit; $_options['start'] = ($page-1)*$limit; // @todo sometimes this is neg -- why? if ($_options['start'] < 0) $_options['start'] = 0; $data = $this->Upload->findAllUploadsForUserId($this->_user['id'], $_options); $this->set('uploads', $data); $_phone = $this->Phone->findById($this->_user['phone_id'], null, null, 0); // Get desired width and height for the transcoded media file $_width = intval($_phone['Phone']['screen_width']); $_height = intval($_phone['Phone']['screen_height']); //@todo fix data? if ($_width < 1 || $_height < 1) { // we have really no idea what the // size should be, so lets just say $_width = 100; $_height = 100; } // @todo previews are hardcoded to be 1/2. fix up? $this->set('upload_preview_width', $_width /2); $this->set('upload_preview_height', $_height/2); if (BrowserAgent::isMobile()) { $this->action = 'mp_index'; $this->layout = 'mp'; } else { $this->render('index'); } } }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -