public function executeUpload_image(sfWebRequest $request) { $id = $request->getParameter('id'); $filename = $request->getParameter('name'); $this->forward404Unless($id && $filename); $valid_episode = $this->validateEpisodeForImageUpload($id, $filename); $this->forward404Unless($valid_episode); // Settings $targetDir = rtrim(ProjectConfiguration::getEpisodeGraphicFileLocalDirectory(), '/'); //$targetDir = 'uploads/'; //$cleanupTargetDir = false; // Remove old files //$maxFileAge = 60 * 60; // Temp file age in seconds // 5 minutes execution time @set_time_limit(5 * 60); $fileName = $this->getUser()->getAttribute('valid_episode_image_file_hash', ''); return $this->handlePlupload($request, $targetDir, $fileName); }
public function executeBackup(sfWebRequest $request) { $this->redirectUnless($this->getUser()->isAuthenticated() && $this->getUser()->getApiUserId(), '@sf_guard_signin'); $auth_key = $this->getUser()->getApiAuthKey(); $episode_data = Api::getInstance()->setUser($auth_key)->get('episode/' . $request->getParameter('id'), true); $episode = ApiDoctrine::createObject('Episode', $episode_data['body']); $quick_episode = ApiDoctrine::createQuickObject($episode_data['body']); $this->forward404Unless($episode && $episode->getId()); $this->forward404Unless(strtotime($quick_episode->getReleaseDate()) >= time()); // If the episode is not released, only the admins and moderators can view it. $permission = $this->verifyPermissionsForCurrentUser($quick_episode->getSubredditId(), array('admin')); // Unless the owner of the episode is trying to edit it. That's okay. $assignment_data = Api::getInstance()->setUser($auth_key)->get('episodeassignment/' . $quick_episode->getEpisodeAssignmentId(), true); $assignment = ApiDoctrine::createQuickObject($assignment_data['body']); $this->forward404Unless($permission || $assignment && $assignment->getSfGuardUserId() == $this->getUser()->getApiUserId()); $this->setLayout(false); ProjectConfiguration::registerAws(); if ($request->getParameter('which') == 'graphic') { $file_location = rtrim(ProjectConfiguration::getEpisodeGraphicFileLocalDirectory(), '/') . '/'; $filename = $episode->getGraphicFile(); if (file_exists($file_location . $filename)) { $result = $episode->saveFileToApplicationBucket($file_location, $filename, 'upload', AmazonS3::ACL_PUBLIC); if ($result->isOk()) { unlink($file_location . $filename); } } else { echo $file_location . $filename; } } elseif ($request->getParameter('which') == 'audio') { $file_location = rtrim(ProjectConfiguration::getEpisodeAudioFileLocalDirectory(), '/') . '/'; $filename = $episode->getAudioFile(); if (file_exists($file_location . $filename)) { $episode->saveFileToApplicationBucket($file_location, $filename, 'audio'); } } }
<?php use_javascript(sfConfig::get('app_plupload_web_dir') . '/plupload.js'); use_javascript(sfConfig::get('app_plupload_web_dir') . '/plupload.html4.js'); use_javascript(sfConfig::get('app_plupload_web_dir') . '/plupload.html5.js'); use_javascript(sfConfig::get('app_plupload_web_dir') . '/plupload.flash.js'); $graphic_file_web_location = '/' . trim(str_replace(sfConfig::get('sf_web_dir'), '', ProjectConfiguration::getEpisodeGraphicFileLocalDirectory()), '/') . '/'; ?> <script type="text/javascript"> // Custom example logic $(function() { var uploader = new plupload.Uploader({ runtimes : 'html5, html4', browse_button : 'graphic_pickfiles', container : 'image_uploader', max_file_size : '10mb', chunk_size : '2mb', unique_names : false, url : '<?php echo url_for('plupload/upload_image?id=' . $form->getObject()->getId()); ?> ', flash_swf_url : '<?php echo image_path('plupload.flash.swf'); ?> ', filters : [ {title : "Images", extensions : "gif,jpg,jpeg,png"}, {title : "ISOs", extensions : "iso"}, ],
public function save(Doctrine_Connection $conn = null) { if (!$this->isNew() && !$this->getSkipBackup() && in_array('graphic_file', $this->_modified) && $this->_get('graphic_file')) { $file_location = rtrim(ProjectConfiguration::getEpisodeGraphicFileLocalDirectory(), '/') . '/'; $filename = $this->_get('graphic_file'); if (file_exists($file_location . $filename)) { ProjectConfiguration::registerAws(); $response = $this->saveFileToApplicationBucket($file_location, $filename, 'upload', AmazonS3::ACL_PUBLIC); if ($response->isOK()) { unlink($file_location . $filename); } } } if (!$this->isNew() && !$this->getSkipBackup() && in_array('audio_file', $this->_modified) && $this->_get('audio_file')) { $file_location = rtrim(ProjectConfiguration::getEpisodeAudioFileLocalDirectory(), '/') . '/'; $filename = $this->_get('audio_file'); if (file_exists($file_location . $filename)) { ProjectConfiguration::registerAws(); $response = $this->saveFileToApplicationBucket($file_location, $filename, 'audio'); } } if (!$this->isNew() && in_array('is_submitted', $this->_modified) && $this->_get('is_submitted')) { /* The episode has been submitted. We need to send an email about * it to the subreddit moderators. */ $types = array('moderator'); $memberships = sfGuardUserSubredditMembershipTable::getInstance()->getAllBySubredditAndMemberships($this->getSubredditId(), $types); $initial_is_submitted = $this->_get('is_submitted'); $initial_submitted_at = $this->_get('submitted_at'); foreach ($memberships as $membership) { $user = $membership->getSfGuardUser(); $parameters = array('user_id' => $membership->getSfGuardUserId(), 'episode_id' => $this->getIncremented()); $prefer_html = $user->getPreferHtml(); $address = $user->getEmailAddress(); $name = $user->getPreferredName() ? $user->getPreferredName() : $user->getFullName(); $email = EmailTable::getInstance()->getFirstByEmailTypeAndLanguage('EpisodeApprovalPending', $user->getPreferredLanguage()); $subject = $email->generateSubject($parameters); $body = $email->generateBodyText($parameters, $prefer_html); $from = sfConfig::get('app_email_address', ProjectConfiguration::getApplicationName() . ' <' . ProjectConfiguration::getApplicationEmailAddress() . '>'); AppMail::sendMail($address, $from, $subject, $body, $prefer_html ? $body : null); $user->addLoginMessage('You have Episodes awaiting your approval.'); } // @todo: The previous foreach loop sets the 'is_submitted' and 'submitted_at' columns to null. I don't know why. $this->_set('is_submitted', $initial_is_submitted); $this->_set('submitted_at', $initial_submitted_at); } return parent::save($conn); }