Exemplo n.º 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);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 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');
 }
Exemplo n.º 3
0
 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');
 }
Exemplo n.º 4
0
 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());
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
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();
 }
Exemplo n.º 8
0
 /**
  * Imports a local file into the system. The file must be added to this path
  * somehow. That's what happens in tools/files/importers/.
  * If a $fr (FileRecord) object is passed, we assign the newly imported FileVersion
  * object to that File. If not, we make a new filerecord.
  *
  * @param string $pointer path to file
  * @param string|bool $filename
  * @param ConcreteFile|bool $fr
  *
  * @return number Error Code | \Concrete\Core\File\Version
  */
 public function import($pointer, $filename = false, $fr = false)
 {
     return parent::import($pointer, $filename, $fr);
 }