Exemplo n.º 1
0
 public function add()
 {
     $filesystem = new Filesystem();
     if ($this->request->request->has('currentFolder')) {
         $node = Node::getByID($this->request->request->get('currentFolder'));
         if (is_object($node) && $node instanceof FileFolder) {
             $folder = $node;
         }
     }
     if (!isset($folder)) {
         $folder = $filesystem->getRootFolder();
     }
     $permissions = new \Permissions($folder);
     $error = $this->app->make('error');
     $response = new EditResponse();
     $response->setError($error);
     if (!$permissions->canAddTreeSubNode()) {
         $error->add(t('You do not have permission to add a folder here.'));
     }
     if (!$error->has()) {
         $folder = $filesystem->addFolder($folder, $this->request->request->get('folderName'));
         $response->setMessage(t('Folder added.'));
         $response->setAdditionalDataAttribute('folder', $folder);
     }
     $response->outputJSON();
 }
Exemplo n.º 2
0
 public function clear_attribute($ptID = false)
 {
     $this->setupPageType($ptID);
     $sr = new EditResponse();
     if (Loader::helper('validation/token')->validate()) {
         $ak = CollectionKey::getByID(Loader::helper('security')->sanitizeInt($_REQUEST['akID']));
         if (is_object($ak)) {
             $this->defaultPage->clearAttribute($ak);
         }
     } else {
         $this->error->add(Loader::helper('validation/token')->getErrorMessage());
     }
     if ($this->error->has()) {
         $sr->setError($this->error);
     } else {
         $sr->setMessage(t('Attribute cleared successfully.'));
     }
     $sr->outputJSON();
 }
Exemplo n.º 3
0
 public function add_items_to_batch()
 {
     if (!$this->token->validate('add_items_to_batch')) {
         $this->error->add($this->token->getErrorMessage());
     }
     $exporters = \Core::make('migration/manager/exporters');
     $r = $this->entityManager->getRepository('\\PortlandLabs\\Concrete5\\MigrationTool\\Entity\\Export\\Batch');
     $batch = $r->findOneById($this->request->request->get('batch_id'));
     if (!is_object($batch)) {
         $this->error->add(t('Invalid batch.'));
     }
     $selectedItemType = false;
     if ($this->request->request->has('item_type') && $this->request->request->get('item_type')) {
         $selectedItemType = $exporters->driver($this->request->request->get('item_type'));
     }
     if (!is_object($selectedItemType)) {
         $this->error->add(t('Invalid item type.'));
     }
     if (!$this->error->has()) {
         $values = $this->request->request->get('id');
         $exportItems = $selectedItemType->getItemsFromRequest($values[$selectedItemType->getHandle()]);
         $collection = $batch->getObjectCollection($selectedItemType->getHandle());
         if (!is_object($collection)) {
             $collection = new ObjectCollection();
             $collection->setType($selectedItemType->getHandle());
             $batch->getObjectCollections()->add($collection);
         }
         foreach ($exportItems as $item) {
             if (!$collection->contains($item)) {
                 $item->setCollection($collection);
                 $collection->getItems()->add($item);
             }
         }
         $this->entityManager->persist($batch);
         $this->entityManager->flush();
         $response = new JsonResponse($exportItems);
         return $response;
     }
     $r = new EditResponse();
     $r->setError($this->error);
     $r->outputJSON();
 }
Exemplo n.º 4
0
 public function export_translations($localeCode)
 {
     $result = new EditResponse();
     try {
         if (!Core::make('token')->validate('export_translations')) {
             throw new \Exception(Core::make('token')->getErrorMessage());
         }
         $section = Section::getByLocale($localeCode);
         if (is_object($section) && !$section->isError()) {
             if ($section->getLocale() == Config::get('concrete.multilingual.default_source_locale')) {
                 $section = null;
             }
         } else {
             $section = null;
         }
         if (!isset($section)) {
             throw new \Exception(t('Invalid language identifier'));
         }
         $translations = $section->getSectionInterfaceTranslations();
         $extractor = Core::make('multilingual/extractor');
         $extractor->mergeTranslationsWithSectionFile($section, $translations);
         $extractor->saveSectionTranslationsToFile($section, $translations);
         \Localization::clearCache();
         $result->setAdditionalDataAttribute('newToken', Core::make('token')->generate('export_translations'));
         $result->message = t('The translations have been exported to file and will be used by the website.');
     } catch (\Exception $x) {
         $result->setError($x);
     }
     $result->outputJSON();
 }