Example #1
0
 public function executePost(sfWebRequest $request)
 {
     $this->forward400If('' === (string) $request['title'], 'title parameter is not specified.');
     $this->forward400If('' === (string) $request['body'], 'body parameter is not specified.');
     $this->forward400If(!isset($request['public_flag']) || '' === (string) $request['public_flag'], 'public flag is not specified');
     if (isset($request['id']) && '' !== $request['id']) {
         $diary = Doctrine::getTable('Diary')->findOneById($request['id']);
         $this->forward400If(false === $diary, 'the specified diary does not exit.');
         $this->forward400If(false === $diary->isAuthor($this->member->getId()), 'this diary is not yours.');
     } else {
         $diary = new Diary();
         $diary->setMemberId($this->member->getId());
     }
     $diary->setTitle($request['title']);
     $diary->setBody($request['body']);
     $diary->setPublicFlag($request['public_flag']);
     $diary->save();
     $this->diary = $diary;
     for ($i = 1; $i <= 3; $i++) {
         $diaryImage = Doctrine::getTable('DiaryImage')->retrieveByDiaryIdAndNumber($diary->getId(), $i);
         $filename = basename($_FILES['diary_photo_' . $i]['name']);
         if (!is_null($filename) && '' !== $filename) {
             try {
                 $validator = new opValidatorImageFile(array('required' => false));
                 $validFile = $validator->clean($_FILES['diary_photo_' . $i]);
             } catch (Exception $e) {
                 $this->forward400($e->getMessage());
             }
             $f = new File();
             $f->setFromValidatedFile($validFile);
             $f->setName(hash('md5', uniqid((string) $i) . $filename));
             if ($stream = fopen($_FILES['diary_photo_' . $i]['tmp_name'], 'r')) {
                 if (!is_null($diaryImage)) {
                     $diaryImage->delete();
                 }
                 $bin = new FileBin();
                 $bin->setBin(stream_get_contents($stream));
                 $f->setFileBin($bin);
                 $f->save();
                 $di = new DiaryImage();
                 $di->setDiaryId($diary->getId());
                 $di->setFileId($f->getId());
                 $di->setNumber($i);
                 $di->save();
                 $diary->updateHasImages();
             } else {
                 $this->forward400(__('Failed to write file to disk.'));
             }
         }
         $deleteCheck = $request['diary_photo_' . $i . '_photo_delete'];
         if ('on' === $deleteCheck && !is_null($diaryImage)) {
             $diaryImage->delete();
         }
     }
 }
Example #2
0
 public function getFileCollection($where)
 {
     global $dRep;
     $where = $this->sqlBuilder->createWhere($where, '');
     $sql = "SELECT * FROM ink_files WHERE {$where};";
     $data = $this->runManyQuery($sql);
     $files = array();
     foreach ($data as $index => $row) {
         $file = new File();
         $properties = array('id' => $row['fileId'], 'siteId' => $row['siteId'], 'filename' => $row['filename'], 'folderId' => $row['folderId'], 'size' => $row['filesize'], 'type' => $dRep->getFiletype($row['filetypeId']), 'timestamp' => $row['uploaded']);
         $file->setProperties($properties);
         //			$file = $this->getFiletext($file);
         $this->fileCache[$file->getId()] = $file;
         $files[] = $file;
     }
     return $files;
 }
 public function savePchFileFromRawData(&$pchData, Doctrine_Connection $conn = null)
 {
     if ($this->getPchFileId()) {
         $pchFile = $this->getPchFile();
     } else {
         $pchFile = new File();
     }
     $pchFile->setType('image/pch');
     $pchFile->setName('cccc_' . time() . '_pch');
     $pchFile->save($conn);
     $fileBin = $pchFile->getFileBin();
     if (!$fileBin) {
         $fileBin = new FileBin();
         $fileBin->setFileId($pchFile->getId);
     }
     $fileBin->setBin($pchData);
     $fileBin->save($conn);
     $this->setPchFileId($pchFile->getId());
 }
Example #4
0
 /**
  * Filter the query by a related File object
  *
  * @param     File|PropelCollection $file The related object(s) to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return    CommentQuery The current query, for fluid interface
  */
 public function filterByFile($file, $comparison = null)
 {
     if ($file instanceof File) {
         return $this->addUsingAlias(CommentPeer::FILE_ID, $file->getId(), $comparison);
     } elseif ($file instanceof PropelCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(CommentPeer::FILE_ID, $file->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByFile() only accepts arguments of type File or PropelCollection');
     }
 }
Example #5
0
 public function executePost(sfWebRequest $request)
 {
     $body = (string) $request['body'];
     $this->forward400If('' === $body, 'body parameter not specified.');
     $this->forward400If(mb_strlen($body) > 140, 'The body text is too long.');
     $memberId = $this->getUser()->getMemberId();
     $options = array();
     if (isset($request['public_flag'])) {
         $options['public_flag'] = $request['public_flag'];
     }
     if (isset($request['in_reply_to_activity_id'])) {
         $options['in_reply_to_activity_id'] = $request['in_reply_to_activity_id'];
     }
     if (isset($request['uri'])) {
         $options['uri'] = $request['uri'];
     } elseif (isset($request['url'])) {
         $options['uri'] = $request['url'];
     }
     if (isset($request['target']) && 'community' === $request['target']) {
         if (!isset($request['target_id'])) {
             $this->forward400('target_id parameter not specified.');
         }
         $options['foreign_table'] = 'community';
         $options['foreign_id'] = $request['target_id'];
     }
     $options['source'] = 'API';
     $imageFiles = $request->getFiles('images');
     if (!empty($imageFiles)) {
         foreach ((array) $imageFiles as $imageFile) {
             $validator = new opValidatorImageFile(array('required' => false));
             try {
                 $obj = $validator->clean($imageFile);
             } catch (sfValidatorError $e) {
                 $this->forward400('This image file is invalid.');
             }
             if (is_null($obj)) {
                 continue;
                 // empty value
             }
             $file = new File();
             $file->setFromValidatedFile($obj);
             $file->setName('ac_' . $this->getUser()->getMemberId() . '_' . $file->getName());
             $file->save();
             $options['images'][]['file_id'] = $file->getId();
         }
     }
     $this->activity = Doctrine::getTable('ActivityData')->updateActivity($memberId, $body, $options);
     if ('1' === $request['forceHtml']) {
         // workaround for some browsers (see #3201)
         $this->getRequest()->setRequestFormat('html');
         $this->getResponse()->setContentType('text/html');
     }
     $this->setTemplate('object');
 }
 public function createActivityImageByFileInfoAndActivityId(array $fileInfo, $activityId)
 {
     $file = new File();
     $file->setOriginalFilename(basename($fileInfo['name']));
     $file->setType($fileInfo['type']);
     $fileFormat = $file->getImageFormat();
     if (is_null($fileFormat) || '' == $fileFormat) {
         $fileFormat = pathinfo($fileInfo['name'], PATHINFO_EXTENSION);
     }
     $fileBaseName = md5(time()) . '_' . $fileFormat;
     $filename = 'ac_' . $fileInfo['member_id'] . '_' . $fileBaseName;
     $file->setName($filename);
     $file->setFilesize($fileInfo['size']);
     $bin = new FileBin();
     $bin->setBin($fileInfo['binary']);
     $file->setFileBin($bin);
     $file->save();
     $activityImage = new ActivityImage();
     $activityImage->setActivityDataId($activityId);
     $activityImage->setFileId($file->getId());
     $activityImage->setUri($this->getActivityImageUriByfileInfoAndFilename($fileInfo, $filename));
     $activityImage->setMimeType($file->type);
     $activityImage->save();
     $this->createUploadImageFileByFileInfoAndSaveFileName($fileInfo, $filename);
     return $activityImage;
 }
 /**
  * writeViewData
  * @param File $objFile
  * @author Cornelius Hansjakob <*****@*****.**>
  * @version 1.0
  */
 private function writeViewData(File &$objFile)
 {
     $this->core->logger->debug('media->controllers->UploadController->writeViewData()');
     $this->view->assign('fileId', $objFile->getId());
     $this->view->assign('fileFileId', $objFile->getFileId());
     $this->view->assign('fileExtension', $objFile->getExtension());
     $this->view->assign('fileTitle', $objFile->getTitle());
     $this->view->assign('mimeType', $objFile->getMimeType());
     $this->view->assign('strDefaultDescription', 'Beschreibung hinzufügen...');
     // TODO : guiTexts
     $this->view->assign('languageId', 1);
     // TODO : language
 }
Example #8
0
 /**
  * Exclude object from result
  *
  * @param     File $file Object to remove from the list of results
  *
  * @return    FileQuery The current query, for fluid interface
  */
 public function prune($file = null)
 {
     if ($file) {
         $this->addUsingAlias(FilePeer::ID, $file->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Example #9
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      File $value A File object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(File $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Example #10
0
 public function add($name)
 {
     $this->view = null;
     try {
         $user = User::find(Session::uid());
         if (!$user->getId() || !$user->getIs_admin()) {
             throw new Exception('Action not allowed.');
         }
         if (!preg_match('/^\\d*[-a-zA-Z][-a-zA-Z0-9]*$/', $name)) {
             throw new Exception('The name of the project can only contain alphanumeric characters plus dashes and must have 1 alpha character at least');
         }
         try {
             $project = Project::find($name);
         } catch (Exception $e) {
         }
         if (is_object($project) && $project->getProjectId($name)) {
             throw new Exception('Project with the same name already exists!');
         }
         $file = new File();
         $logo = '';
         if (!empty($_POST['logo'])) {
             $file->findFileById($_POST['logo']);
             $logo = basename($file->getUrl());
         }
         $project = new Project();
         $project->setName($name);
         $project->setDescription($_POST['description']);
         $project->setWebsite($_POST['website']);
         $project->setContactInfo($user->getUsername());
         $project->setOwnerId($user->getId());
         $project->setActive(true);
         $project->setInternal(true);
         $project->setRequireSandbox(true);
         $project->setLogo($logo);
         $project->setRepo_type('git');
         $project->setRepository($_POST['github_repo_url']);
         $project->setGithubId($_POST['github_client_id']);
         $project->setGithubSecret($_POST['github_client_secret']);
         $project->save();
         if ($file->getId()) {
             $file->setProjectId($project->getProjectId());
             $file->save();
         }
         $journal_message = '@' . $user->getNickname() . ' added project *' . $name . '*';
         Utils::systemNotification($journal_message);
         echo json_encode(array('success' => true, 'message' => $journal_message));
     } catch (Exception $e) {
         $error = $e->getMessage();
         echo json_encode(array('success' => false, 'message' => $error));
     }
 }
 public function test_for_multiple_inclussion()
 {
     $AkelosLogFile = new File(array('name' => 'akelos.log'));
     $this->assertTrue($AkelosLogFile->save());
     $LogTag =& $AkelosLogFile->tag->create(array('name' => 'logs'));
     $KasteLogFile = new File(array('name' => 'kaste.log'));
     $this->assertTrue($KasteLogFile->save());
     $KasteLogFile->tag->add($LogTag);
     $BermiLogFile = new File(array('name' => 'bermi.log'));
     $this->assertTrue($BermiLogFile->save());
     $BermiLogFile->tag->add($LogTag);
     $ids = array($AkelosLogFile->getId(), $KasteLogFile->getId(), $BermiLogFile->getId());
     $File = new File();
     $Files =& $File->find($ids, array('include' => array('tags', 'taggings')));
     foreach ($Files as $File) {
         foreach ($File->tags as $Tag) {
             $this->assertEqual($Tag->name, $LogTag->name);
         }
         foreach ($File->taggings as $Tagging) {
             $this->assertEqual($Tagging->tag_id, $LogTag->id);
         }
     }
     $File = new File();
     $this->assertTrue($Files =& $File->find($ids, array('conditions' => "name = 'kaste.log'")));
     $this->assertEqual($Files[0]->name, 'kaste.log');
     /**
      * @todo Implement eager loading for second-level associations
      */
     $File = new File();
     $Files =& $File->find('all', array('include' => array('taggings')));
     foreach (array_keys($Files) as $k) {
         $File =& $Files[$k];
         foreach (array_keys($File->taggings) as $l) {
             $Tagging =& $File->taggings[$l];
             $Tagging->tag->load();
             $this->assertEqual($Tagging->tag->name, $LogTag->name);
             $this->assertEqual($Tagging->tag_id, $LogTag->id);
         }
     }
     /**
      * @todo Implement eager loading for second-level associations
      */
     $Files =& $File->find('all', array('include' => array('tags')));
     foreach ($Files as $File) {
         foreach ($File->tags as $Tag) {
             $this->assertEqual($Tag->name, $LogTag->name);
             $Tag->tagging->load();
             foreach ($Tag->taggings as $Tagging) {
                 $this->assertEqual($Tagging->tag_id, $LogTag->id);
             }
         }
     }
     $File = new File();
     $Files =& $File->find('all', array('include' => array('tags')));
     $tag_ids = array();
     foreach ($Files as $File) {
         foreach ($File->tags as $Tag) {
             $tag_ids[] = $Tag->getId();
         }
     }
     $Tag = new Tag();
     $Tags =& $Tag->find($tag_ids, array('include' => 'taggings'));
     foreach (array_keys($Files) as $k) {
         foreach (array_keys($Files[$k]->tags) as $m) {
             foreach (array_keys($Tags) as $n) {
                 if ($Tags[$n]->id == $Files[$k]->tags[$m]->id) {
                     $Files[$k]->tags[$m]->taggings =& $Tags[$n]->taggings;
                 }
             }
         }
     }
 }
 /**
  * writeViewData
  * @param File $objFile
  * @author Cornelius Hansjakob <*****@*****.**>
  * @version 1.0
  */
 private function writeViewData(File &$objFile)
 {
     $this->core->logger->debug('media->controllers->UploadController->writeViewData()');
     $this->view->assign('fileId', $objFile->getId());
     $this->view->assign('fileFileId', $objFile->getFileId());
     $this->view->assign('fileExtension', $objFile->getExtension());
     $this->view->assign('fileTitle', $objFile->getTitle());
     $this->view->assign('fileVersion', $objFile->getVersion());
     $this->view->assign('filePath', sprintf($this->core->sysConfig->media->paths->icon32, $objFile->getSegmentPath()));
     $this->view->assign('mimeType', $objFile->getMimeType());
     $this->view->assign('strDefaultDescription', $this->core->translate->_('Add_description_'));
     $this->view->assign('languageId', $this->intLanguageId);
 }
Example #13
0
 /**
  * Declares an association between this object and a File object.
  *
  * @param      File $v
  * @return     CollectionFile The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setFile(File $v = null)
 {
     if ($v === null) {
         $this->setFileId(NULL);
     } else {
         $this->setFileId($v->getId());
     }
     $this->aFile = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the File object, it will not be re-added.
     if ($v !== null) {
         $v->addCollectionFile($this);
     }
     return $this;
 }
Example #14
0
 public function createActivityImageByFileInfoAndActivity(sfValidatedFile $fileInfo, ActivityData $activity)
 {
     $file = new File();
     $file->setFromValidatedFile($fileInfo);
     $file->name = 'ac_' . $activity->member_id . '_' . $file->name;
     $file->save();
     $activityImage = new ActivityImage();
     $activityImage->setActivityData($activity);
     $activityImage->setFileId($file->getId());
     $activityImage->setMimeType($file->type);
     $activityImage->save();
     return $activityImage;
 }
Example #15
0
 public function scan($id)
 {
     $scanner = new ScanAssets();
     $file_id = (int) $id;
     $file = new File();
     $file->findFileById($file_id);
     $success = false;
     $icon = File::getIconFromMime($file->getMime());
     if ($scanner->scanFile($file->getId())) {
         $success = true;
     }
     if ($icon === false) {
         $icon = $file->getUrl();
     }
     if ($success) {
         // we need to reload the file because scanner might have updated fields
         // and our object is out of date
         $file->findFileById($file_id);
         // move file to S3
         try {
             File::s3Upload($file->getRealPath(), APP_ATTACHMENT_PATH . $file->getFileName(), true, $file->getTitle());
             $file->setUrl(APP_ATTACHMENT_URL . $file->getFileName());
             $file->save();
             // delete the physical file now it is in S3
             unlink($file->getRealPath());
         } catch (Exception $e) {
             $success = false;
             $error = 'There was a problem uploading your file';
             error_log(__FILE__ . ": Error uploading images to S3:\n{$e}");
         }
     }
     return $this->setOutput(array('success' => $success, 'error' => isset($error) ? $error : '', 'fileid' => $file->getId(), 'url' => $file->getUrl(), 'icon' => $icon));
 }
 /**
  * Return file revisions
  *
  * @param File $file
  * @return integer
  */
 function countRevisions($file)
 {
     return Attachments::count(array('parent_id = ? AND parent_type = ?', $file->getId(), 'File'));
 }