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() { 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->failure($this->modx->lexicon('permission_denied')); } $this->source->setRequestProperties($this->getProperties()); $this->source->initialize(); $list = $this->source->getObjectsInContainer($this->getProperty('dir')); return $this->outputArray($list); }
/** * @return boolean|string */ public function getSource() { /** @var modMediaSource $source */ $this->modx->loadClass('sources.modMediaSource'); $this->source = $this->modx->getObject('modMediaSource', $_POST['sourceID']); if (!$this->source->getWorkingContext()) { return $this->modx->lexicon('permission_denied'); } $this->source->setRequestProperties($this->getProperties()); return $this->source->initialize(); }
/** * @return boolean|string */ public function getSource() { $source = $this->getProperty('source', 1); /** @var modMediaSource $source */ $this->modx->loadClass('sources.modMediaSource'); $this->source = modMediaSource::getDefaultSource($this->modx, $source); if (!$this->source->getWorkingContext()) { return $this->modx->lexicon('permission_denied'); } $this->source->setRequestProperties($this->getProperties()); return $this->source->initialize(); }
/** * @param string $ctx * * @return bool */ public function prepareSource($ctx = 'web') { if ($this->mediaSource) { $this->mediaSource->errors = array(); return $this->mediaSource; } elseif ($this->mediaSource = $this->xpdo->getObject('sources.modMediaSource', $this->get('source'))) { $this->mediaSource->set('ctx', $ctx); $this->mediaSource->initialize(); return $this->mediaSource; } return false; }
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(); $fields = $this->getProperties(); if (!$this->validate($fields)) { return $this->failure(); } $response = $this->source->renameContainer($fields['path'], $fields['name']); return $this->handleResponse($response); }
/** * Get the source to load the paths from * * @param int $sourceId * @return modMediaSource|modFileMediaSource */ public function getSource($sourceId) { /** @var modMediaSource|modWebDAVMediaSource $source */ $this->modx->loadClass('sources.modMediaSource'); $this->source = modMediaSource::getDefaultSource($this->modx, $sourceId, false); if (empty($this->source)) { return false; } if (!$this->source->getWorkingContext()) { return false; } $this->source->setRequestProperties($this->getProperties()); $this->source->initialize(); return $this->source; }
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(); $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() { 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); }
/** * @param string $ctx * @param $source * * @return bool|null|object */ public function initializeMediaSource($ctx = '', $source) { if ($this->mediaSource = $this->modx->getObject('sources.modMediaSource', $source)) { $this->mediaSource->set('ctx', $ctx); $this->mediaSource->initialize(); return $this->mediaSource; } else { return false; } }
/** * {@inheritDoc} * @return boolean */ public function initialize() { parent::initialize(); $options = array(); if (!$this->ctx) { $this->ctx =& $this->xpdo->context; } $options['context'] = $this->ctx->get('key'); $this->fileHandler = $this->xpdo->getService('fileHandler', 'modFileHandler', '', $options); return true; }
/** * Initialize the source * @return boolean */ public function initialize() { $ok = parent::initialize(); if ($ok !== true) { return $ok; } if (!$this->ctx) { $this->ctx =& $this->xpdo->context; } $this->ctx->prepare(); $this->_properties = $this->getPropertyList(); return true; }
/** * Initializes S3 media class, getting the S3 driver and loading the bucket * @return boolean */ public function initialize() { parent::initialize(); $properties = $this->getPropertyList(); if (!defined('AWS_KEY')) { define('AWS_KEY', $this->xpdo->getOption('key', $properties, '')); define('AWS_SECRET_KEY', $this->xpdo->getOption('secret_key', $properties, '')); /* (Not needed at this time) define('AWS_ACCOUNT_ID',$modx->getOption('aws.account_id',$config,'')); define('AWS_CANONICAL_ID',$modx->getOption('aws.canonical_id',$config,'')); define('AWS_CANONICAL_NAME',$modx->getOption('aws.canonical_name',$config,'')); define('AWS_MFA_SERIAL',$modx->getOption('aws.mfa_serial',$config,'')); define('AWS_CLOUDFRONT_KEYPAIR_ID',$modx->getOption('aws.cloudfront_keypair_id',$config,'')); define('AWS_CLOUDFRONT_PRIVATE_KEY_PEM',$modx->getOption('aws.cloudfront_private_key_pem',$config,'')); define('AWS_ENABLE_EXTENSIONS', 'false');*/ } include_once $this->xpdo->getOption('core_path', null, MODX_CORE_PATH) . 'model/aws/sdk.class.php'; $this->getDriver(); $this->setBucket($this->xpdo->getOption('bucket', $properties, '')); return true; }
/** * {@inheritDoc} * @return boolean */ public function initialize() { parent::initialize(); $properties = $this->getPropertyList(); $this->cached = $this->getOption('cached', $properties, false); $this->cacheTime = $this->getOption('cacheTime', $properties, 10) * 60; $this->proxified = $this->getOption('proxy', $properties, false); $this->preview = $this->getOption('preview', $properties, false); $this->basePath = $this->getOption('basePath', $properties); if (substr($this->basePath, -1) != '/') { $this->basePath .= '/'; } if ($this->proxified) { $this->baseUrl = $this->xpdo->getOption('site_url') . ltrim($this->xpdo->getOption('assets_url'), '/') . 'components/webdav/index.php?action=proxy&source=' . $this->get('id') . '&ctx=' . $this->xpdo->context->key . '&src='; } else { $this->baseUrl = $this->getOption('baseUrl', $properties) . '/'; if ($this->basePath != '/') { $this->baseUrl .= $this->basePath; } } $this->client = new WebDAV_Client(array('uri' => $this->getOption('server', $properties), 'path' => $this->basePath, 'user' => $this->getOption('login', $properties), 'password' => $this->getOption('password', $properties), 'auth' => $this->getOption('authMethod', $properties), 'ssl' => $this->getOption('verifySSL', $properties))); $this->xpdo->lexicon->load('webdav:default', 'webdav:source'); return true; }
/** * Initialize the source * @return boolean */ public function initialize() { parent::initialize(); return true; }