コード例 #1
0
 public function importFiles($fromPath, $computeThumbnails = true)
 {
     $fh = new Importer();
     if (!$computeThumbnails) {
         $fh->setRescanThumbnailsOnImport(false);
         $helper = Core::make('helper/file');
     }
     $contents = Core::make('helper/file')->getDirectoryContents($fromPath);
     foreach ($contents as $filename) {
         if (!is_dir($filename)) {
             $fv = $fh->import($fromPath . '/' . $filename, $filename);
             if (!$computeThumbnails) {
                 $types = \Concrete\Core\File\Image\Thumbnail\Type\Type::getVersionList();
                 foreach ($types as $type) {
                     // since we provide the thumbnails, we're going to get a list of thumbnail types
                     // and loop through them, assigning them to all the files.
                     $thumbnailPath = $fromPath . '/' . $type->getHandle() . '/' . $filename;
                     if (file_exists($thumbnailPath)) {
                         $fv->importThumbnail($type, $thumbnailPath);
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
 public function exportProductPageBatch()
 {
     $pt = PageType::getByHandle('product');
     $xml = new SimpleXMLElement("<concrete5-cif></concrete5-cif>");
     $xml->addAttribute('version', '1.0');
     $pages = $xml->addChild("pages");
     $db = Loader::db();
     $r = $db->Execute('select Pages.cID from Pages
   where ptID = ? and cIsTemplate = 0 and cFilename is null or cFilename = ""
   order by cID asc', array($ptID));
     while ($row = $r->FetchRow()) {
         $pc = Page::getByID($row['cID'], 'RECENT');
         if ($pc->getPageTypeHandle() == STACKS_PAGE_TYPE) {
             continue;
         }
         $pc->export($pages);
     }
     $xml->asXml('application/files/razor/migrate/export/product/product.xml');
     $fi = new FileImporter();
     $file = $fi->import('application/files/razor/migrate/export/product/product.xml');
 }
コード例 #3
0
ファイル: team_edit.php プロジェクト: vipkailiai/FCVOVA
 public function add()
 {
     if (isset($_POST['sID']) && $_POST['sID'] != "0" && $_POST['sID'] != null && $_POST['sID'] != "") {
         $club = Club::getByID($_POST['sID']);
     } else {
         $club = new Club();
     }
     $fi = new Importer();
     $pathToFile = $_FILES['logoInput']['tmp_name'];
     $nameOfFile = $_FILES['logoInput']['name'];
     $result = $fi->import($pathToFile, $nameOfFile);
     if ($result instanceof \Concrete\Core\File\Version) {
         $club->setImageId($result->getFileID());
     }
     $club->setName($_POST['nameInput']);
     $club->setCountry($_POST['countryInput']);
     $club->setVenue($_POST['venueInput']);
     $club->setCoach($_POST['coachInput']);
     $club->setCreation($_POST['creationInput']);
     $club->setWebsite($_POST['websiteInput']);
     $club->add();
     $this->redirect('/dashboard/league/teams');
 }
コード例 #4
0
ファイル: File.php プロジェクト: kreativmind/concrete5-5.7.0
 public function duplicate()
 {
     $db = Loader::db();
     $em = \ORM::entityManager('core');
     $versions = $this->versions;
     // duplicate the core file object
     $nf = clone $this;
     $dh = Loader::helper('date');
     $date = $dh->getOverridableNow();
     $nf->fDateAdded = new Carbon($date);
     $em->persist($nf);
     $em->flush();
     // clear out the versions
     $nf->versions = new ArrayCollection();
     $fi = Core::make('helper/file');
     $cf = Core::make('helper/concrete/file');
     $importer = new Importer();
     $filesystem = $this->getFileStorageLocationObject()->getFileSystemObject();
     foreach ($versions as $version) {
         if ($version->isApproved()) {
             $cloneVersion = clone $version;
             $cloneVersion->setFile($nf);
             do {
                 $prefix = $importer->generatePrefix();
                 $path = $cf->prefix($prefix, $version->getFilename());
             } while ($filesystem->has($path));
             $filesystem->write($path, $version->getFileResource()->read(), array('visibility' => AdapterInterface::VISIBILITY_PUBLIC, 'mimetype' => Core::make('helper/mime')->mimeFromExtension($fi->getExtension($version->getFilename()))));
             $cloneVersion->updateFile($version->getFilename(), $prefix);
             $nf->versions->add($cloneVersion);
         }
     }
     $em->persist($nf);
     $em->flush();
     $r = $db->Execute('select fvID, akID, avID from FileAttributeValues where fID = ?', array($this->getFileID()));
     while ($row = $r->fetchRow()) {
         $db->Execute("insert into FileAttributeValues (fID, fvID, akID, avID) values (?, ?, ?, ?)", array($nf->getFileID(), $row['fvID'], $row['akID'], $row['avID']));
     }
     $v = array($this->fID);
     $q = "select fID, paID, pkID from FilePermissionAssignments where fID = ?";
     $r = $db->query($q, $v);
     while ($row = $r->fetchRow()) {
         $v = array($nf->getFileID(), $row['paID'], $row['pkID']);
         $q = "insert into FilePermissionAssignments (fID, paID, pkID) values (?, ?, ?)";
         $db->query($q, $v);
     }
     foreach ($nf->getVersionList() as $v) {
         $v->refreshAttributes();
     }
     $fe = new \Concrete\Core\File\Event\DuplicateFile($this);
     $fe->setNewFileObject($nf);
     Events::dispatch('on_file_duplicate', $fe);
     return $nf;
 }
コード例 #5
0
ファイル: FileListTest.php プロジェクト: ceko/concrete5-1
 public function testPaginationWithPermissions()
 {
     // first lets make some more files.
     $sample = dirname(__FILE__) . '/StorageLocation/fixtures/sample.txt';
     $image = DIR_BASE . '/concrete/images/logo.png';
     $fi = new Importer();
     $files = array('another.txt' => $sample, 'funtime.txt' => $sample, 'funtime2.txt' => $sample, 'awesome-o' => $sample, 'image.png' => $image);
     foreach ($files as $filename => $pointer) {
         $fi->import($pointer, $filename);
     }
     $nl = new \Concrete\Core\File\FileList();
     $nl->setPermissionsChecker(function ($file) {
         if ($file->getTypeObject()->getGenericType() == \Concrete\Core\File\Type\Type::T_IMAGE) {
             return true;
         } else {
             return false;
         }
     });
     $nl->sortByFilenameAscending();
     $results = $nl->getResults();
     $pagination = $nl->getPagination();
     $this->assertEquals(-1, $nl->getTotalResults());
     $this->assertEquals(6, $pagination->getTotalResults());
     $this->assertEquals(6, count($results));
     // so there are six "real" results, and 15 total results without filtering.
     $pagination->setMaxPerPage(4)->setCurrentPage(1);
     $this->assertEquals(2, $pagination->getTotalPages());
     $this->assertTrue($pagination->hasNextPage());
     $this->assertFalse($pagination->hasPreviousPage());
     // Ok, so the results ought to be the following files, broken up into pages of four, in this order:
     // foobley.png
     // image.png
     // logo1.png
     // logo2.png
     // -- page break --
     // logo3.png
     // test.png
     $results = $pagination->getCurrentPageResults();
     $this->assertInstanceOf('\\Concrete\\Core\\Search\\Pagination\\PermissionablePagination', $pagination);
     $this->assertEquals(4, count($results));
     $this->assertEquals('foobley.png', $results[0]->getFilename());
     $this->assertEquals('image.png', $results[1]->getFilename());
     $this->assertEquals('logo1.png', $results[2]->getFilename());
     $this->assertEquals('logo2.png', $results[3]->getFilename());
     $pagination->setCurrentPage(2);
     $results = $pagination->getCurrentPageResults();
     $this->assertEquals('logo3.png', $results[0]->getFilename());
     $this->assertEquals('test.png', $results[1]->getFilename());
     $this->assertEquals(2, count($results));
     $this->assertTrue($pagination->hasPreviousPage());
     $this->assertFalse($pagination->hasNextPage());
 }
コード例 #6
0
ファイル: controller.php プロジェクト: vr55/CaseManager
 public function action_document_submit($bID = false)
 {
     if ($this->bID != $bID) {
         return false;
     }
     //print_r( $_FILES );
     //		exit;
     $this->view();
     //$this->set('action', $this->post() );
     if ($this->CheckCase(intval($this->post('CaseID'))) == false) {
         return;
     }
     $error = \Concrete\Core\File\Importer::E_PHP_FILE_ERROR_DEFAULT;
     if (isset($_FILES['document']) && is_uploaded_file($_FILES['document']['tmp_name'])) {
         $file = $_FILES['document']['tmp_name'];
         $filename = $_FILES['document']['name'];
         $importer = new \Concrete\Core\File\Importer();
         $result = $importer->import($file, $filename);
         if ($result instanceof \Concrete\Core\File\Version) {
             //TODO::WARNING!!!
             //потенциальная опастность!
             //пользователь может подделать CaseID и добавить документ к другому делу
             $db = Loader::db();
             $ql = "INSERT INTO `CaseDocuments` ( bID, CaseID, DocumentOwnerID, DocumentID, DocumentDescription, DocumentURL, DocumentDate ) VALUES ( ?, ?, ?, ?, ?, ?, ? )";
             $val = array(intval($bID), intval($this->post('CaseID')), $result->getAuthorUserID(), $result->getFileID(), $this->post('Description'), $result->getURL(), $result->getDateAdded());
             $db->query($ql, $val);
             $this->redirect('/');
         } else {
             $error = $result;
         }
     } else {
         if (isset($_FILES['document'])) {
             $error = $_FILES['document']['error'];
         }
     }
     $this->set('errorMessage', \Concrete\Core\File\Importer::getErrorMessage($error));
 }
コード例 #7
0
ファイル: ImporterTest.php プロジェクト: masteramuk/concrete5
 public function testVersionApprove()
 {
     // create the default storage location first.
     mkdir($this->getStorageDirectory());
     $this->getStorageLocation();
     $file = dirname(__FILE__) . '/test.txt';
     touch($file);
     $fi = new Importer();
     $r = $fi->import($file, 'test.txt');
     $fv2 = $r->duplicate();
     $fv3 = $r->duplicate();
     $fv4 = $r->duplicate();
     $f = \File::getByID(1);
     $fv4b = $f->getVersion(4);
     $this->assertEquals(1, $r->getFileVersionID());
     $this->assertEquals(2, $fv2->getFileVersionID());
     $this->assertEquals(3, $fv3->getFileVersionID());
     $this->assertEquals(4, $fv4b->getFileVersionID());
     $this->assertEquals(4, $fv4->getFileVersionID());
     $this->assertEquals($fv4, $fv4b);
     $fv3->approve();
     $this->assertEquals(true, $fv3->isApproved());
     $f = \File::getByID(1);
     $fv1 = $f->getVersion(1);
     $this->assertEquals(false, $fv1->isApproved());
     $fva = $f->getApprovedVersion();
     $this->assertEquals($fva, $fv3);
 }
コード例 #8
0
ファイル: controller.php プロジェクト: seebaermichi/concrete5
 public function createAttributeValueFromRequest()
 {
     $data = $this->post();
     if ($this->getAttributeKeySettings()->isModeFileManager()) {
         if ($data['value'] > 0) {
             $f = File::getByID($data['value']);
             return $this->createAttributeValue($f);
         }
     }
     if ($this->getAttributeKeySettings()->isModeHtmlInput()) {
         // import the file.
         $tmp_name = $_FILES['akID']['tmp_name'][$this->attributeKey->getAttributeKeyID()]['value'];
         $name = $_FILES['akID']['name'][$this->attributeKey->getAttributeKeyID()]['value'];
         if (!empty($tmp_name) && is_uploaded_file($tmp_name)) {
             $importer = new Importer();
             $f = $importer->import($tmp_name, $name);
             if (is_object($f)) {
                 return $this->createAttributeValue($f->getFile());
             }
         }
     }
     return $this->createAttributeValue(null);
 }
コード例 #9
0
ファイル: Version.php プロジェクト: ppiedaderawnet/concrete5
 public function duplicateUnderlyingFile()
 {
     $importer = new Importer();
     $fi = Core::make('helper/file');
     $cf = Core::make('helper/concrete/file');
     $filesystem = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject();
     do {
         $prefix = $importer->generatePrefix();
         $path = $cf->prefix($prefix, $this->getFilename());
     } while ($filesystem->has($path));
     $filesystem->write($path, $this->getFileResource()->read(), ['visibility' => AdapterInterface::VISIBILITY_PUBLIC, 'mimetype' => Core::make('helper/mime')->mimeFromExtension($fi->getExtension($this->getFilename()))]);
     $this->updateFile($this->getFilename(), $prefix);
 }
コード例 #10
0
 public function upload_files()
 {
     $files = array();
     if ($this->token->validate('upload_files')) {
         $r = $this->entityManager->getRepository('\\PortlandLabs\\Concrete5\\MigrationTool\\Entity\\Import\\Batch');
         $batch = $r->findOneById($this->request->request('id'));
         if (is_object($batch)) {
             $cf = \Core::make('helper/file');
             $fp = \FilePermissions::getGlobal();
             if (isset($_FILES['file']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
                 if (!$fp->canAddFileType($cf->getExtension($_FILES['file']['name']))) {
                     throw new \Exception(Importer::getErrorMessage(Importer::E_FILE_INVALID_EXTENSION));
                 } else {
                     $ih = new Importer();
                     $response = $ih->import($_FILES['file']['tmp_name'], $_FILES['file']['name']);
                     if (!$response instanceof \Concrete\Core\File\Version) {
                         throw new \Exception(Importer::getErrorMessage($response));
                     } else {
                         $file = $response->getFile();
                         $fs = Set::getByName($batch->getID());
                         if (!is_object($fs)) {
                             $fs = Set::createAndGetSet($batch->getID(), Set::TYPE_PRIVATE);
                         }
                         $fs->addFileToSet($file);
                         $files[] = $file;
                     }
                 }
             }
         }
     }
     $this->flash('success', t('File(s) uploaded successfully'));
     $r = new \Concrete\Core\File\EditResponse();
     $r->setFiles($files);
     $r->outputJSON();
 }
コード例 #11
0
 public function setRescanThumbnailsOnImport($refresh)
 {
     return parent::setRescanThumbnailsOnImport($refresh);
 }