Example #1
0
 public function process()
 {
     $from = $this->getProperty('from');
     $to = $this->getProperty('to');
     $point = $this->getProperty('point', 'append');
     if (empty($from)) {
         return $this->failure($this->modx->lexicon('file_folder_err_ns'));
     }
     if (empty($to)) {
         return $this->failure($this->modx->lexicon('file_folder_err_ns'));
     }
     $source = $this->getProperty('source', 1);
     /** @var modMediaSource $source */
     $this->modx->loadClass('sources.modMediaSource');
     $source = modMediaSource::getDefaultSource($this->modx, $source);
     if (!$source->getWorkingContext()) {
         return $this->failure($this->modx->lexicon('permission_denied'));
     }
     $source->setRequestProperties($this->getProperties());
     $source->initialize();
     if (!$source->checkPolicy('save')) {
         return $this->failure($this->modx->lexicon('permission_denied'));
     }
     $success = $source->moveObject($from, $to, $point);
     if (!$success) {
         $errors = $source->getErrors();
         foreach ($errors as $k => $msg) {
             $this->addFieldError($k, $msg);
         }
         return $this->failure($this->modx->error->message);
     }
     return $this->success();
 }
Example #2
0
 public function process()
 {
     if (!$this->validate()) {
         return $this->failure();
     }
     $source = $this->getProperty('source', 1);
     /** @var modMediaSource $source */
     $this->modx->loadClass('sources.modMediaSource');
     $source = modMediaSource::getDefaultSource($this->modx, $source);
     if (!$source->getWorkingContext()) {
         return $this->failure($this->modx->lexicon('permission_denied'));
     }
     $source->setRequestProperties($this->getProperties());
     $source->initialize();
     $success = $source->renameContainer($this->getProperty('dir'), $this->getProperty('name'));
     if (!$success) {
         $msg = '';
         $errors = $source->getErrors();
         foreach ($errors as $k => $msg) {
             $this->addFieldError($k, $msg);
         }
         return $this->failure($msg);
     }
     return $this->success();
 }
Example #3
0
 /**
  * Get the active Source
  * @return modMediaSource|boolean
  */
 public function getSource()
 {
     $this->modx->loadClass('sources.modMediaSource');
     $this->source = modMediaSource::getDefaultSource($this->modx, $this->getProperty('source'));
     if (empty($this->source) || !$this->source->getWorkingContext()) {
         return false;
     }
     return $this->source;
 }
Example #4
0
 /**
  * @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();
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 public function getElementSources()
 {
     $c = $this->modx->newQuery('modContext');
     $c->where(array('key:!=' => 'mgr'));
     $c->sortby($this->modx->escape('rank'), 'ASC');
     $c->sortby($this->modx->escape('key'), 'DESC');
     $contexts = $this->modx->getCollection('modContext', $c);
     $list = array();
     $this->modx->loadClass('sources.modMediaSource');
     /** @var $source modMediaSource */
     $source = modMediaSource::getDefaultSource($this->modx);
     /** @var modContext $context */
     foreach ($contexts as $context) {
         $list[] = array($context->get('key'), $source->get('id'), $source->get('name'));
     }
     return $list;
 }
Example #7
0
 /**
  * Get the active source
  * @return modMediaSource
  */
 public function getSource()
 {
     /** @var modMediaSource|modFileMediaSource $source */
     $this->modx->loadClass('sources.modMediaSource');
     $source = $this->modx->getOption('source', $this->scriptProperties, false);
     if (!empty($source)) {
         $source = $this->modx->getObject('source.modMediaSource', $source);
     }
     if (empty($source)) {
         $source = modMediaSource::getDefaultSource($this->modx);
     }
     if (!$source->getWorkingContext()) {
         return $this->failure($this->modx->lexicon('permission_denied'));
     }
     $source->setRequestProperties($this->scriptProperties);
     $source->initialize();
     return $source;
 }
Example #8
0
 /**
  * Get the active Source
  * @return modMediaSource|boolean
  */
 public function getSource()
 {
     $path = $this->modx->getOption('modxsdk.core_path', null);
     if (!$path) {
         $path = MODX_CORE_PATH . 'components/modxsdk/';
     }
     $path .= 'model/modxSDK/';
     if (!$this->modx->loadClass('ModxsdkFileMediaSource', $path)) {
         return false;
     }
     $source = modMediaSource::getDefaultSource($this->modx, $this->getProperty('source'));
     if (empty($source) || !$source->getWorkingContext()) {
         return false;
     }
     $this->source = $this->modx->newObject('ModxsdkFileMediaSource');
     if (!$this->source->checkPolicy('list')) {
         return 'Source access denied';
     }
     $this->source->fromArray($source->toArray());
     $this->source->setRequestProperties($this->getProperties());
     $this->source->initialize();
     return true;
 }
Example #9
0
 /**
  * Retrieve the profile photo, if any
  *
  * @param int $width The desired photo width
  * @param int $height The desired photo height
  *
  * @return string The photo URL
  */
 public function getProfilePhoto($width = 128, $height = 128)
 {
     if (empty($this->Profile->photo)) {
         return '';
     }
     $this->xpdo->loadClass('sources.modMediaSource');
     /** @var modMediaSource $source */
     $source = modMediaSource::getDefaultSource($this->xpdo, $this->xpdo->getOption('photo_profile_source'));
     $source->initialize();
     $path = $source->getBasePath($this->Profile->photo) . $this->Profile->photo;
     return $this->xpdo->getOption('connectors_url', MODX_CONNECTORS_URL) . "system/phpthumb.php?zc=1&h={$height}&w={$width}&src={$path}";
 }
 /**
  * Get the Source for this Element
  *
  * @param string $contextKey
  * @param boolean $fallbackToDefault
  * @return modMediaSource|null
  */
 public function getSource($contextKey = '', $fallbackToDefault = true)
 {
     if (empty($contextKey)) {
         $contextKey = $this->xpdo->context->get('key');
     }
     $source = $this->_source;
     if (empty($source)) {
         $c = $this->xpdo->newQuery('sources.modMediaSource');
         $c->innerJoin('sources.modMediaSourceElement', 'SourceElement');
         $c->where(array('SourceElement.object' => $this->get('id'), 'SourceElement.object_class' => $this->_class, 'SourceElement.context_key' => $contextKey));
         $source = $this->xpdo->getObject('sources.modMediaSource', $c);
         if (!$source && $fallbackToDefault) {
             $source = modMediaSource::getDefaultSource($this->xpdo);
         }
         $this->setSource($source);
     }
     return $source;
 }
Example #11
0
 /**
  * @param $source_id
  * @return bool|modFileMediaSource|modMediaSource|null
  */
 protected function _getSource($source_id)
 {
     $this->modx->loadClass('sources.modMediaSource');
     $source = modMediaSource::getDefaultSource($this->modx, $source_id);
     if (empty($source) || !$source->getWorkingContext()) {
         return false;
     }
     $images = $this->modx->getOption('imageExtensions', $source->getPropertyList(), 'jpg,jpeg,png,gif');
     $this->_images = array_map('trim', explode(',', $images));
     return $source;
 }
Example #12
0
 function getFieldSource($field, &$tv)
 {
     //source from config
     $sourcefrom = isset($field['sourceFrom']) && !empty($field['sourceFrom']) ? $field['sourceFrom'] : 'config';
     if ($sourcefrom == 'config' && isset($field['sources'])) {
         if (is_array($field['sources'])) {
             foreach ($field['sources'] as $context => $sourceid) {
                 $sources[$context] = $sourceid;
             }
         } else {
             $fsources = $this->modx->fromJson($field['sources']);
             if (is_array($fsources)) {
                 foreach ($fsources as $source) {
                     if (isset($source['context']) && isset($source['sourceid'])) {
                         $sources[$source['context']] = $source['sourceid'];
                     }
                 }
             }
         }
     }
     if (isset($sources[$this->working_context]) && !empty($sources[$this->working_context])) {
         //try using field-specific mediasource from config
         if ($mediasource = $this->modx->getObject('sources.modMediaSource', $sources[$this->working_context])) {
             return $mediasource;
         }
     }
     if ($this->source && $sourcefrom == 'migx') {
         //use global MIGX-mediasource for all TVs
         $tv->setSource($this->source);
         $mediasource = $this->source;
     } else {
         //useTV-specific mediasource
         $mediasource = $tv->getSource($this->working_context, false);
     }
     //try to get the context-default-media-source
     if (!$mediasource) {
         $defaultSourceId = null;
         if ($contextSetting = $this->modx->getObject('modContextSetting', array('key' => 'default_media_source', 'context_key' => $this->working_context))) {
             $defaultSourceId = $contextSetting->get('value');
         }
         $mediasource = modMediaSource::getDefaultSource($this->modx, $defaultSourceId);
     }
     return $mediasource;
 }
Example #13
0
    $resource = $modx->newObject('modResource');
}
//set objectid for migxObjectMediaPath - snippet
$co_id = $modx->getOption('co_id', $scriptProperties, '');
if (!empty($co_id)) {
    $modx->setPlaceholder('objectid', $co_id);
}
if ($tv = $modx->getObject('modTemplateVar', array('name' => $tvname))) {
    $source = $tv->getSource($wctx, false);
}
if (!$source instanceof modMediaSource) {
    $sourceid = $modx->getOption('source', $_REQUEST, '');
    /**
     *  *  *  * @var modMediaSource $source */
    $modx->loadClass('sources.modMediaSource');
    $source = modMediaSource::getDefaultSource($modx, $sourceid);
    if (!$source->getWorkingContext()) {
        return $modx->lexicon('permission_denied');
    }
    $source->setRequestProperties($_REQUEST);
}
$result = array();
if ($source instanceof modMediaSource) {
    $dirTree = $modx->getOption('dirtree', $_REQUEST, '');
    $modx->setPlaceholder('docid', $resource_id);
    $source->initialize();
    $cachepath = str_replace('/./', '/', $source->getBasePath());
    $cachepath = $cachepath . $dirTree;
    $baseUrl = $modx->getOption('site_url') . $source->getBaseUrl();
    $baseUrl = $baseUrl . $dirTree;
    $sourceProperties = $source->getPropertyList();
Example #14
0
 function getDefaultSource($return = 'object')
 {
     $defaultSourceId = null;
     if ($contextSetting = $this->modx->getObject('modContextSetting', array('key' => 'default_media_source', 'context_key' => $this->working_context))) {
         $defaultSourceId = $contextSetting->get('value');
     }
     $mediasource = modMediaSource::getDefaultSource($this->modx, $defaultSourceId);
     return $return == 'object' ? $mediasource : $mediasource->get($return);
 }