Example #1
0
 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);
 }
Example #2
0
 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);
 }