Пример #1
0
	public function getByID($id) {
		$db = Loader::db();
		$r = $db->GetRow("select * from FileStorageLocations where fslID = ?", array($id));
		if (is_array($r) && $r['fslID'] == $id) {
			$obj = new FileStorageLocation();
			$obj->setPropertiesFromArray($r);
			return $obj;
		}
	}
Пример #2
0
 public function save()
 {
     $helper_file = Loader::helper('concrete/file');
     $validation_token = Loader::helper('validation/token');
     Loader::model('file_storage_location');
     if (!$validation_token->validate("file_storage")) {
         $this->set('error', array($validation_token->getErrorMessage()));
         return;
     }
     if ($_POST['delete']) {
         $fsl = FileStorageLocation::getByID(FileStorageLocation::ALTERNATE_ID);
         if (is_object($fsl)) {
             $fsl->delete();
             $this->redirect('/dashboard/system/environment/file_storage_locations', 'storage_deleted');
         }
     } else {
         Config::save('DIR_FILES_UPLOADED', $this->post('DIR_FILES_UPLOADED'));
         if ($this->post('fslName') != '' && $this->post('fslDirectory') != '') {
             $fsl = FileStorageLocation::getByID(FileStorageLocation::ALTERNATE_ID);
             if (!is_object($fsl)) {
                 FileStorageLocation::add($this->post('fslName'), $this->post('fslDirectory'), FileStorageLocation::ALTERNATE_ID);
             } else {
                 $fsl->update($this->post('fslName'), $this->post('fslDirectory'));
             }
         }
         $this->redirect('/dashboard/system/environment/file_storage_locations', 'storage_saved');
     }
 }
Пример #3
0
 private function storeFile($prefix, $pointer, $filename, $fr = false)
 {
     // assumes prefix are 12 digits
     $fi = Loader::helper('concrete/file');
     $path = false;
     if ($fr instanceof File) {
         if ($fr->getStorageLocationID() > 0) {
             Loader::model('file_storage_location');
             $fsl = FileStorageLocation::getByID($fr->getStorageLocationID());
             $path = $fi->mapSystemPath($prefix, $filename, true, $fsl->getDirectory());
         }
     }
     if ($path == false) {
         $path = $fi->mapSystemPath($prefix, $filename, true);
     }
     return @copy($pointer, $path);
 }
Пример #4
0
?>
)</td>
</tr>
<tr>
	<td><strong><?php 
echo t('Date Added');
?>
</strong></td>
	<td colspan="2"><?php 
echo t('Added by <strong>%s</strong> on %s', $fv->getAuthorName(), $dateHelper->formatSpecial('FILE_PROPERTIES', $f->getDateAdded()));
?>
</td>
</tr>
<?php 
Loader::model("file_storage_location");
$fsl = FileStorageLocation::getByID(FileStorageLocation::ALTERNATE_ID);
if (is_object($fsl)) {
    if ($f->getStorageLocationID() > 0) {
        $sli = $fsl->getName() . ' <span style="color: #afafaf">(' . $fsl->getDirectory() . ')</span>';
    }
}
if (!isset($sli)) {
    $sli = t('Default Location') . ' <span style="color: #afafaf">(' . DIR_FILES_UPLOADED . ')</span>';
}
?>
<tr>
	<td><strong><?php 
echo t('Location');
?>
</strong></td>
	<td colspan="2"><?php 
Пример #5
0
	/** 
	 * Returns a full filesystem path to the file on disk.
	 */
	public function getPath() {
		$f = Loader::helper('concrete/file');
		if ($this->fslID > 0) {
			Loader::model('file_storage_location');
			$fsl = FileStorageLocation::getByID($this->fslID);
			$path = $f->mapSystemPath($this->fvPrefix, $this->fvFilename, false, $fsl->getDirectory());
		} else {
			$path = $f->getSystemPath($this->fvPrefix, $this->fvFilename);
		}
		return $path;
	}
Пример #6
0
	/** 
	 * Removes a file, including all of its versions
	 */
	public function delete() {
		// first, we remove all files from the drive
		$db = Loader::db();
		$pathbase = false;
		$r = $db->GetAll('select fvFilename, fvPrefix from FileVersions where fID = ?', array($this->fID));
		$h = Loader::helper('concrete/file');
		Loader::model('file_storage_location');
		if ($this->getStorageLocationID() > 0) {
			$fsl = FileStorageLocation::getByID($this->getStorageLocationID());
			$pathbase = $fsl->getDirectory();
		}
		foreach($r as $val) {
			
			// Now, we make sure this file isn't referenced by something else. If it is we don't delete the file from the drive
			$cnt = $db->GetOne('select count(*) as total from FileVersions where fID <> ? and fvFilename = ? and fvPrefix = ?', array(
				$this->fID,
				$val['fvFilename'],
				$val['fvPrefix']
			));
			if ($cnt == 0) {
				if ($pathbase != false) {
					$path = $h->mapSystemPath($val['fvPrefix'], $val['fvFilename'], false, $pathbase);
				} else {
					$path = $h->mapSystemPath($val['fvPrefix'], $val['fvFilename'], false);
				}
				$t1 = $h->getThumbnailSystemPath($val['fvPrefix'], $val['fvFilename'], 1);
				$t2 = $h->getThumbnailSystemPath($val['fvPrefix'], $val['fvFilename'], 2);
				$t3 = $h->getThumbnailSystemPath($val['fvPrefix'], $val['fvFilename'], 3);
				if (file_exists($path)) {
					unlink($path);
				}
				if (file_exists($t1)) {
					unlink($t1);
				}
				if (file_exists($t2)) {
					unlink($t2);
				}
				if (file_exists($t3)) {
					unlink($t3);
				}
			}
		}
		
		// now from the DB
		$db->Execute("delete from Files where fID = ?", array($this->fID));
		$db->Execute("delete from FileVersions where fID = ?", array($this->fID));
		$db->Execute("delete from FileAttributeValues where fID = ?", array($this->fID));
		$db->Execute("delete from FileSetFiles where fID = ?", array($this->fID));
		$db->Execute("delete from FileVersionLog where fID = ?", array($this->fID));
		$this->refreshCache();
	}