Пример #1
0
 /**
  * Media browser with KCFinder.
  *
  * The KCFinder component is loaded by the `initialize()` method.
  * @return void
  * @uses MeCms\Controller\Component\KcFinderComponent::getTypes()
  */
 public function browser()
 {
     //Gets the supported types
     $types = $this->KcFinder->getTypes();
     //If there's only one type, it automatically sets the query value
     if (!$this->request->query('type') && count($types) < 2) {
         $this->request->query['type'] = firstKey($types);
     }
     //Gets the type from the query and the types from configuration
     $type = $this->request->query('type');
     //Checks the type, then sets the KCFinder path
     if ($type && array_key_exists($type, $types)) {
         //Sets locale
         $locale = substr(\Cake\I18n\I18n::locale(), 0, 2);
         $locale = empty($locale) ? 'en' : $locale;
         $this->set('kcfinder', sprintf('%s/kcfinder/browse.php?lang=%s&type=%s', Router::url('/vendor', true), $locale, $type));
     }
     $this->set('types', array_combine(array_keys($types), array_keys($types)));
 }
Пример #2
0
 /**
  * Uploads photos
  * @return void
  * @uses MeTools\Controller\Component\UploaderComponent::error()
  * @uses MeTools\Controller\Component\UploaderComponent::mimetype()
  * @uses MeTools\Controller\Component\UploaderComponent::save()
  * @uses MeTools\Controller\Component\UploaderComponent::set()
  */
 public function upload()
 {
     $album = $this->request->query('album');
     //If there's only one album, it automatically sets the query value
     if (!$album && count($this->viewVars['albums']) < 2) {
         $this->request->query['album'] = firstKey($this->viewVars['albums']);
     }
     if ($this->request->data('file')) {
         if (empty($album)) {
             throw new InternalErrorException(__d('me_cms', 'Missing album ID'));
         }
         http_response_code(500);
         $uploaded = $this->Uploader->set($this->request->data('file'))->mimetype('image')->save(PHOTOS . DS . $album);
         if (!$uploaded) {
             exit($this->Uploader->error());
         }
         $saved = $this->Photos->save($this->Photos->newEntity(['album_id' => $album, 'filename' => basename($uploaded)]));
         if (!$saved) {
             exit(__d('me_cms', 'The photo could not be saved'));
         }
         http_response_code(200);
         $this->render(false);
     }
 }
Пример #3
0
 /**
  * Uploads banners
  * @return void
  * @uses MeTools\Controller\Component\UploaderComponent::error()
  * @uses MeTools\Controller\Component\UploaderComponent::mimetype()
  * @uses MeTools\Controller\Component\UploaderComponent::save()
  * @uses MeTools\Controller\Component\UploaderComponent::set()
  */
 public function upload()
 {
     $position = $this->request->query('position');
     //If there's only one position, it automatically sets the query value
     if (!$position && count($this->viewVars['positions']) < 2) {
         $this->request->query['position'] = firstKey($this->viewVars['positions']);
     }
     if ($this->request->data('file')) {
         if (empty($position)) {
             throw new InternalErrorException(__d('me_cms', 'Missing position ID'));
         }
         http_response_code(500);
         $uploaded = $this->Uploader->set($this->request->data('file'))->mimetype('image')->save(BANNERS);
         if (!$uploaded) {
             exit($this->Uploader->error());
         }
         $saved = $this->Banners->save($this->Banners->newEntity(['position_id' => $position, 'filename' => basename($uploaded)]));
         if (!$saved) {
             exit(__d('me_cms', 'The banner could not be saved'));
         }
         http_response_code(200);
         $this->render(false);
     }
 }