public function process() { // Even though we're not using media sources, it seems like the // easiest way to check permissions (and waste time/effort/memory) $this->source->initialize(); if (!$this->source->checkPolicy('create')) { return $this->failure($this->modx->lexicon('permission_denied')); } // Prepare the upload path and check it exists $destination = $this->modx->getOption('core_path') . 'packages/'; if (!is_dir($destination)) { return $this->failure("Packages directory doesnt appear to exist!"); //@TODO Lexiconize } // Grab the file $file = array_shift($this->getProperty('files')); // Check MIME type of file if (!in_array(strtolower($file['type']), array('application/zip', 'application/x-zip-compressed', 'application/x-zip', 'application/octet-stream'))) { return $this->failure("1 This file does not appear to be a transport package"); //@TODO Lexiconize } // Check valid name of file if (!preg_match("/.+\\.transport\\.zip\$/i", $file['name'])) { return $this->failure("2 This file [{$file['name']}] does not appear to be a transport package"); //@TODO Lexiconize } // Return response if (move_uploaded_file($file['tmp_name'], $destination . $file['name'])) { return $this->success(); } else { return $this->failure($this->modx->lexicon('unknown_error')); } }
public function process() { $sources = $this->getProperty('sources'); if (empty($sources)) { return $this->failure($this->modx->lexicon('source_err_ns')); } $sourceIds = explode(',', $sources); foreach ($sourceIds as $sourceId) { /** @var modMediaSource $source */ $this->source = $this->modx->getObject('sources.modMediaSource', $sourceId); if (empty($this->source)) { continue; } if ($this->source->get('id') == 1) { continue; } if (!$this->source->checkPolicy('remove')) { continue; } if ($this->source->remove() == false) { $this->modx->log(modX::LOG_LEVEL_ERROR, $this->modx->lexicon('source_err_remove')); continue; } $this->logManagerAction(); } return $this->success(); }
public function process() { /* get base paths and sanitize incoming paths */ $directory = rawurldecode($this->getProperty('directory', '')); $directory = ltrim(strip_tags(str_replace(array('../', './'), '', $directory)), '/'); $name = $this->getProperty('name'); $name = ltrim(strip_tags(str_replace(array('../', './'), '', $name)), '/'); $loaded = $this->getSource(); if (!$this->source instanceof modMediaSource) { return $loaded; } if (!$this->source->checkPolicy('create')) { return $this->failure($this->modx->lexicon('permission_denied')); } $path = $this->source->createObject($directory, $name, $this->getProperty('content')); if (empty($path)) { $msg = ''; $errors = $this->source->getErrors(); foreach ($errors as $k => $msg) { $this->addFieldError($k, $msg); } return $this->failure($msg); } return $this->success('', array('file' => $directory . ltrim($name, '/'))); }
public function process() { if (!$this->getSource()) { return $this->failure($this->modx->lexicon('permission_denied')); } $this->source->setRequestProperties($this->getProperties()); $this->source->initialize(); if (!$this->source->checkPolicy('create')) { return $this->failure($this->modx->lexicon('permission_denied')); } $this->ensureSavePathExists($_POST['path']); $success = $this->source->uploadObjectsToContainer($_POST['path'], $_FILES); /* Check for upload errors * Remove 'directory already exists' error */ $errors = array(); if (empty($success)) { $msg = ''; $errors = $this->source->getErrors(); if (isset($errors['name'])) { unset($errors['name']); } } if (count($errors) > 0) { foreach ($errors as $k => $msg) { $this->modx->error->addField($k, $msg); } return $this->failure($msg); } return $this->success(); }
public function process() { if (!$this->getSource()) { return $this->modx->toJSON(array()); } if (!$this->source->checkPolicy('list')) { return $this->modx->toJSON(array()); } $this->source->setRequestProperties($this->getProperties()); $this->source->initialize(); $list = $this->source->getContainerList($this->getProperty('dir')); return $this->modx->toJSON($list); }
public function process() { if (!$this->getSource()) { return $this->failure($this->modx->lexicon('permission_denied')); } $this->source->setRequestProperties($this->getProperties()); $this->source->initialize(); if (!$this->source->checkPolicy('list')) { return $this->failure($this->modx->lexicon('permission_denied')); } $list = $this->source->getObjectsInContainer($this->getProperty('dir')); return $this->outputArray($list); }
public function process() { $source = $this->getSource(); if ($source !== true) { return $source; } if (!$this->source->checkPolicy('view')) { return $this->failure($this->modx->lexicon('permission_denied')); } if ($this->getProperty('download', false)) { return $this->download(); } else { return $this->getObjectUrl(); } }
public function process() { $tv = $_POST['tv_id']; $resId = $_POST['resource_id']; $page = $this->modx->getObject('modResource', $resId); $tvvalue = $page->getTVValue($tv); $nowTVarray = json_decode($tvvalue, true); if (!$this->getSource()) { return $this->modx->toJSON(array()); } if (!$this->source->checkPolicy('list')) { return $this->modx->toJSON(array()); } $this->source->setRequestProperties($this->getProperties()); $this->source->initialize(); $list = $this->source->getContainerList($this->getProperty('dir')); foreach ($list as $file) { if ('.' != $file && '..' != $file && '.DS_Store' != $file && '.htaccess' != $file && is_dir($storeFolder . $file) != true) { //If there is no file in TV, it was uploaded another way. Let it be in the end of the list. $obj['index'] = '9999'; foreach ($nowTVarray as $key => $value) { if ($key == $file['text']) { $obj['index'] = $value['index']; } } //Define picture size $path_info = pathinfo($file['url']); $extension = strtolower($path_info['extension']); if ($extension == 'jpg' || $extension == 'png' || $extension == 'gif' || $extension == 'jpeg') { list($width, $height, $type, $attr) = getimagesize($file['path']); $obj['width'] = $width; $obj['height'] = $height; } $obj['name'] = $file['text']; $obj['url'] = $file['url']; $obj['obj'] = $file; $obj['ext'] = $path_info['extension']; $obj['size'] = filesize($file['path']); $result[] = $obj; } } foreach ($result as $key => $row) { $index[$key] = $row['index']; $name[$key] = $row['name']; } array_multisort($index, SORT_ASC, $name, SORT_ASC, $result); return $this->modx->toJSON($result); }
public function process() { if (!$this->getSource()) { return $this->failure($this->modx->lexicon('permission_denied')); } $this->source->setRequestProperties($this->getProperties()); $this->source->initialize(); if (!$this->source->checkPolicy('save')) { return $this->failure($this->modx->lexicon('permission_denied')); } $fields = $this->getProperties(); if (!$this->validate($fields)) { return $this->failure(); } $response = $this->source->renameContainer($fields['path'], $fields['name']); return $this->handleResponse($response); }
public function process() { if (!$this->getSource()) { return $this->failure($this->modx->lexicon('permission_denied')); } $allowedFileTypes = $this->getProperty('allowedFileTypes'); if (empty($allowedFileTypes)) { // Prevent overriding media source configuration unset($this->properties['allowedFileTypes']); } $this->source->setRequestProperties($this->getProperties()); $this->source->initialize(); if (!$this->source->checkPolicy('list')) { return $this->failure($this->modx->lexicon('permission_denied')); } $list = $this->source->getObjectsInContainer($this->getProperty('dir')); return $this->outputArray($list); }
public function process() { $file = $this->getProperty('file'); if (empty($file)) { return $this->modx->error->failure($this->modx->lexicon('file_err_ns')); } $loaded = $this->getSource(); if (!$this->source instanceof modMediaSource) { return $loaded; } if (!$this->source->checkPolicy('remove')) { return $this->failure($this->modx->lexicon('permission_denied')); } $success = $this->source->removeObject($file); if (empty($success)) { $errors = $this->source->getErrors(); $msg = implode("\n", $errors); return $this->failure($msg); } return $this->success(); }
public function process() { if (!$this->getSource()) { return $this->failure($this->modx->lexicon('permission_denied')); } $this->source->setRequestProperties($this->getProperties()); $this->source->initialize(); if (!$this->source->checkPolicy('create')) { return $this->failure($this->modx->lexicon('permission_denied')); } $success = $this->source->createContainer($this->getProperty('name'), $this->getProperty('parent')); if (empty($success)) { $msg = ''; $errors = $this->source->getErrors(); foreach ($errors as $k => $msg) { $this->modx->error->addField($k, $msg); } return $this->failure($msg); } return $this->success(); }
public function process() { /* get base paths and sanitize incoming paths */ $filePath = rawurldecode($this->getProperty('file', '')); $loaded = $this->getSource(); if (!$this->source instanceof modMediaSource) { return $loaded; } if (!$this->source->checkPolicy('save')) { return $this->failure($this->modx->lexicon('permission_denied')); } $path = $this->source->updateObject($filePath, $this->getProperty('content')); if (empty($path)) { $msg = ''; $errors = $this->source->getErrors(); foreach ($errors as $k => $msg) { $this->addFieldError($k, $msg); } return $this->failure($msg); } return $this->success('', array('file' => $path)); }
public function process() { /* format filename */ $file = rawurldecode($this->getProperty('file', '')); $loaded = $this->getSource(); if ($loaded !== true) { return $loaded; } if (!$this->source->checkPolicy('delete')) { return $this->failure($this->modx->lexicon('permission_denied')); } $fileArray = $this->source->getObjectContents($file); if (empty($fileArray)) { $msg = ''; $errors = $this->source->getErrors(); foreach ($errors as $k => $msg) { $this->addFieldError($k, $msg); } return $this->failure($msg); } return $this->success('', $fileArray); }
public function process() { if (!$this->validate()) { return $this->failure(); } $oldFile = $this->getProperty('path'); $loaded = $this->getSource(); if (!$this->source instanceof modMediaSource) { return $loaded; } if (!$this->source->checkPolicy('save')) { return $this->failure($this->modx->lexicon('permission_denied')); } $success = $this->source->renameObject($oldFile, $this->getProperty('name')); if (empty($success)) { $msg = ''; $errors = $this->source->getErrors(); foreach ($errors as $k => $msg) { $this->addFieldError($k, $msg); } return $this->failure($msg); } return $this->success(); }
public function process() { $file = $this->getProperty('file'); if (empty($file)) { return $this->modx->error->failure($this->modx->lexicon('file_err_ns')); } $loaded = $this->getSource(); if (!$this->source instanceof modMediaSource) { return $loaded; } if (!$this->source->checkPolicy('remove')) { return $this->failure($this->modx->lexicon('permission_denied')); } $success = $this->source->removeObject($file); if (empty($success)) { $msg = ''; $errors = $this->source->getErrors(); foreach ($errors as $k => $msg) { $this->addFieldError($k, $msg); } return $this->failure(); } return $this->success(); }