Skip to content

Commit

Permalink
sf_type = file
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathologic committed Mar 4, 2015
1 parent 901be86 commit c2327a0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 7 additions & 1 deletion assets/plugins/simplefiles/lib/controller.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public function upload()
$this->data->create(array(
'sf_file' => $this->FS->relativePath($name),
'sf_rid' => $this->rid,
'sf_type' => 'file',
'sf_properties' => json_encode(array(
'filename' => $this->FS->takeFileName($name),
'basename' => $this->FS->takeFileBasename($name),
'mime' => $this->FS->takeFileMIME($name),
'ext' => $this->FS->takeFileExt($name)
)),
'sf_title' => preg_replace('/\\.[^.\\s]{2,4}$/', '', $_FILES["sf_files"]["name"]),
'sf_size' => $this->FS->fileSize($name)
))->save();
Expand Down Expand Up @@ -98,7 +105,6 @@ public function edit() {
if ($id) {
if ($this->FS->checkFile($_REQUEST['sf_file']) && in_array($this->FS->takeFileExt($_REQUEST['sf_file']), explode(',',$this->params['allowedFiles']))) {
$out = $this->data->edit($id)->toArray();
$out['sf_isactive'] = (int)!!$_REQUEST['sf_isactive'];
if ($out['sf_file'] !== $_REQUEST['sf_file']) {
$dest = $this->params['folder'] . $this->rid . "/";
$name = $this->FS->takeFileBasename($_REQUEST['sf_file']);
Expand Down
2 changes: 1 addition & 1 deletion assets/plugins/simplefiles/lib/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function createTable() {
`sf_description` varchar(255) NOT NULL default '',
`sf_size` int(10) default NULL,
`sf_isactive` int(1) NOT NULL default '1',
`sf_type` tinyint(2) NOT NULL default '0',
`sf_type` varchar(255) NOT NULL default '',
`sf_properties` varchar(255) NOT NULL default '',
`sf_rid` int(10) default NULL,
`sf_index` int(10) NOT NULL default '0',
Expand Down
10 changes: 8 additions & 2 deletions assets/plugins/simplefiles/lib/table.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ class sfData extends \autoTable {
/* @var autoTable $table */
protected $table = 'sf_files';
protected $pkName = 'sf_id';
protected $jsonFields = array(
'sf_properties'
);

public $_table = '';

public $default_field = array(
protected $default_field = array(
'sf_file' => '',
'sf_title' => '',
'sf_description' => '',
'sf_size' => 0,
'sf_createdon' => '',
'sf_index' => 0,
'sf_isactive' => '1',
'sf_type' => 'file',
'sf_properties' => '',
'sf_rid'=>0
);
protected $params = array();
Expand Down Expand Up @@ -46,7 +52,7 @@ public function deleteAll($ids, $rid, $fire_events = NULL) {
while ($row = $this->modx->db->getRow($files)) {
$url = $this->fs->relativePath($row['sf_file']);
if ($this->fs->checkFile($url)) {
unlink(MODX_BASE_PATH . $url);
@unlink(MODX_BASE_PATH . $url);
$dir = $this->fs->takeFileDir($url);
$iterator = new \FilesystemIterator($dir);
if (!$iterator->valid()) $this->fs->rmDir($dir);
Expand Down

0 comments on commit c2327a0

Please sign in to comment.