Пример #1
0
 /**
  * Paste copied block
  */
 private function pasteBlock()
 {
     $blockId = $this->request->gp('blockId');
     $op = $this->request->gp('op', 'copy') == 'copy' ? 'copy' : 'cut';
     $byRef = $this->request->gp('byRef', false) === 'true' ? true : false;
     $menuId = $this->request->gp('menuId', false);
     $contentId = $this->request->gp('contentId', false);
     if ($contentId && $blockId && ($block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockId))) {
         if ($op === 'copy') {
             $copiedBlock = clone $block;
             $copiedBlock->id = null;
             $copiedBlock->contentId = $contentId;
             $copiedBlock->menuItem = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuId);
             if ($byRef === true) {
                 $copiedBlock->config = null;
                 if ($block->byRef) {
                     $block = $block->byRef;
                     $copiedBlock->byRef = $block;
                 }
                 $copiedBlock->byRef = $block;
             }
             $this->db->persist($copiedBlock);
             $block = $copiedBlock;
         } else {
             $block->menuItem = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuId);
             $block->contentId = $contentId;
             $this->db->persist($block);
         }
         $this->db->flush();
         $this->response->sendAsJson(array('success' => true, 'data' => $this->prepareBlockOutput($block)));
     }
     $this->response->sendAsJson(array('success' => false, 'message' => $this->translation->getTranslation('Paste error, please copy again')));
 }
Пример #2
0
 /**
  * @param $site
  * @return $this
  */
 protected function addMenuItems($site)
 {
     $pageRoot = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById(1);
     /**
      * 404 Page
      */
     $newPage = new \Fraym\Menu\Entity\MenuItem();
     $newPage->site = $site;
     $newPage->caching = true;
     $newPage->https = false;
     $newPage->checkPermission = false;
     $newPage->is404 = true;
     $newPage->parent = $pageRoot;
     $newPageTranslation = new \Fraym\Menu\Entity\MenuItemTranslation();
     $newPageTranslation->menuItem = $newPage;
     $newPageTranslation->visible = false;
     $newPageTranslation->active = true;
     $newPageTranslation->title = $this->translation->autoTranslation('404 Page not found', 'en', $this->locale->getLocale()->locale);
     $newPageTranslation->subtitle = '';
     $newPageTranslation->url = '/' . $this->translation->autoTranslation('error', 'en', $this->locale->getLocale()->locale) . '-404';
     $newPageTranslation->description = $this->translation->autoTranslation('404 Page not found', 'en', $this->locale->getLocale()->locale);
     $newPageTranslation->externalUrl = false;
     $this->db->persist($newPageTranslation);
     $this->db->flush();
     $this->db->clear();
     return $this;
 }
Пример #3
0
 /**
  * @param $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $errors = array();
     $submit = false;
     $values = $this->request->getGPAsArray();
     if ($this->request->post('mailform')) {
         $submit = true;
         $required = $values['required'];
         $fields = $values['field'];
         $this->validation->setData($fields);
         $this->validation->addRule('email', 'email');
         $errorMessages = array();
         foreach ($required as $field => $val) {
             $this->validation->addRule($field, 'notEmpty');
             $errorMessages = array_merge($errorMessages, array($field => array($field => $this->translation->getTranslation('Please fill out the field'))));
         }
         $this->validation->setErrorMessages($errorMessages);
         $check = $this->validation->check();
         if ($check === true) {
             $msg = $this->mail->getMessageInstance();
             $msg->setFrom(array($fields['email']));
             $msg->setSubject($this->config->get('MAILFORM_SUBJECT')->value);
             $msg->setTo(explode(',', $this->config->get('MAILFORM_TO')->value));
             $this->template->assign('fields', $fields);
             $msg->setBody($this->template->fetch('Extension/Mailform/Mail'), 'text/html');
             $this->mail->send();
         } else {
             $errors = $check;
         }
     }
     $this->mailformController->renderHtml($submit, $values, $errors);
 }
Пример #4
0
 /**
  * @return mixed
  */
 public function getAdminPanel()
 {
     $extensions = $this->db->getRepository('\\Fraym\\SiteManager\\Entity\\Extension')->findBy(array('active' => 1), array('sorter' => 'asc'));
     $extensionSorted = array();
     foreach ($extensions as $extension) {
         if (!isset($extensionSorted[$extension->id])) {
             $extensionSorted[$extension->id] = array();
         }
         $extensionSorted[$extension->id] = array('name' => $this->translation->getTranslation($extension->name, 'SITE_EXT_' . strtoupper(str_ireplace(' ', '_', $extension->name))), 'iconCssClass' => $extension->iconCssClass);
     }
     uasort($extensionSorted, function ($a, $b) {
         return strcasecmp($a['name'], $b['name']);
     });
     $this->view->assign('extensions', $extensionSorted);
     $this->view->assign('inEditMode', $this->block->inEditMode());
     return $this->getIframeContent($this->view->fetch('AdminPanelContent'), array('cssClass' => 'admin-panel'));
 }
Пример #5
0
 /**
  * @param $prop
  * @param $value
  * @param $modelName
  * @param $validationRule
  * @return mixed
  */
 public function getErrorMessage($prop, $value, $modelName, $validationRule)
 {
     $className = str_ireplace('\\', '_', $modelName);
     $messages = Validation::DEFAULT_ERROR_TRANSLATIONS;
     $rule = strtoupper($validationRule);
     $key = 'FIELD_ERROR' . strtoupper($className) . '_' . strtoupper($prop) . '_' . $rule;
     $default = isset($messages[$rule]) ? $messages[strtoupper($validationRule)] : $key;
     return $this->translation->getTranslation($default, $key);
 }
Пример #6
0
 /**
  * Create the table entries from the registry annotation
  *
  * @param $registry
  * @param $classAnnotation
  * @param $oldRegistryEntry
  * @return $this
  */
 private function createEntities($registry, $classAnnotation, $oldRegistryEntry = null)
 {
     if (count($classAnnotation->entity)) {
         foreach ($classAnnotation->entity as $className => $entries) {
             if ($oldRegistryEntry !== null && isset($classAnnotation->updateEntity[$className])) {
                 foreach ($classAnnotation->updateEntity[$className] as $entryData) {
                     $entry = $this->getEntity($className, $entryData);
                     if ($entry) {
                         $entryDataWithSubEntries['registry'] = $registry->id;
                         $data = $this->getEntityDataForUpdate($entryData, $classAnnotation->entity[$className]);
                         $entry->updateEntity($data);
                     }
                 }
             } elseif ($oldRegistryEntry === null) {
                 foreach ($entries as $entryData) {
                     $entryDataWithSubEntries = $this->getSubEntries($entryData, $registry);
                     if ($this->getEntity($className, $entryDataWithSubEntries) === null) {
                         $entry = new $className();
                         $entryDataWithSubEntries['registry'] = $registry->id;
                         $entry->updateEntity($entryDataWithSubEntries);
                     }
                 }
             }
         }
     }
     if (count($classAnnotation->config)) {
         foreach ($classAnnotation->config as $configName => $data) {
             $className = '\\Fraym\\Registry\\Entity\\Config';
             $data['name'] = $configName;
             $data['registry'] = $registry;
             $entity = $this->db->getRepository($className)->findOneByName($configName);
             if ($entity === null) {
                 $entry = new $className();
                 $entry->updateEntity($data);
             }
         }
     }
     if (count($classAnnotation->translation)) {
         foreach ($classAnnotation->translation as $translation) {
             $defaultValue = $translation[0];
             $key = isset($translation[1]) ? $translation[1] : $defaultValue;
             $locale = isset($translation[2]) ? $translation[2] : 'en_US';
             $this->translation->createTranslation($key, $defaultValue, $this->locale->getLocale()->locale, $locale);
         }
     }
     return $this;
 }
Пример #7
0
 /**
  * Paste copied block
  */
 protected function pasteBlock()
 {
     $blockId = $this->request->gp('blockId');
     $op = $this->request->gp('op', 'copy') == 'copy' ? 'copy' : 'cut';
     $byRef = $this->request->gp('byRef', false) === 'true' ? true : false;
     $menuId = $this->request->gp('menuId', false);
     $contentId = $this->request->gp('contentId', false);
     if ($contentId && $blockId && ($block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockId))) {
         $menuItem = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuId);
         $blocks = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findBy(['menuItem' => $menuItem, 'contentId' => $contentId], ['position' => 'asc']);
         // Re-Order other blocks
         foreach ($blocks as $k => $b) {
             $b->position = $k + 1;
         }
         if ($op === 'copy') {
             $block = $block->changeSets->count() ? $block->changeSets->last() : $block;
             $copiedBlock = clone $block;
             $copiedBlock->id = null;
             $copiedBlock->position = 0;
             $copiedBlock->contentId = $contentId;
             $copiedBlock->menuItem = $menuItem;
             if ($byRef === true) {
                 $copiedBlock->config = null;
                 if ($block->byRef) {
                     $block = $block->byRef;
                     $copiedBlock->byRef = $block;
                 }
                 $copiedBlock->byRef = $block;
             }
             $changedBlock = $this->createChangeSet($copiedBlock, null, \Fraym\Block\Entity\ChangeSet::ADDED);
         } else {
             $changedBlock = $block->changeSets->count() ? $block->changeSets->last() : $block;
             $changedBlock->position = 0;
             $changedBlock->menuItem = $menuItem;
             $changedBlock->contentId = $contentId;
             $this->createChangeSet($changedBlock, $block, \Fraym\Block\Entity\ChangeSet::MOVED);
         }
         $this->db->flush();
         $this->response->sendAsJson(['success' => true, 'data' => $this->prepareBlockOutput($changedBlock)]);
     }
     $this->response->sendAsJson(['success' => false, 'message' => $this->translation->getTranslation('Paste error, please reload the page and copy again.')]);
 }
Пример #8
0
 /**
  * @param $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $errors = [];
     $submit = false;
     $values = $this->request->getGPAsArray();
     $requiredFields = $this->getRequiredFields($xml);
     $formHash = $this->createFormHash($requiredFields);
     if ($this->request->post('mailform')) {
         $required = $values['required'];
         $fields = $values['field'];
         if ($this->isFormValid($formHash, $this->getValidationRules($required))) {
             $submit = true;
             $this->validation->setData($fields);
             $this->validation->addRule('email', 'email');
             $errorMessages = [];
             foreach ($requiredFields as $field => $val) {
                 $this->validation->addRule($field, $val['rule'], $val['param']);
                 $errorMessages = array_merge($errorMessages, [$field => [$field => $this->translation->getTranslation('Please fill out the field')]]);
             }
             $this->validation->setErrorMessages($errorMessages);
             $check = $this->validation->check();
             if ($check === true) {
                 $config = json_decode($xml->mailformOptions, true);
                 $receiver = $config[$this->locale->getLocale()->id]['email'];
                 $subject = $config[$this->locale->getLocale()->id]['subject'];
                 $msg = $this->mail->getMessageInstance();
                 $msg->setFrom([$fields['email']]);
                 $msg->setSubject($subject);
                 $msg->setTo(explode(',', $receiver));
                 $this->template->assign('fields', $fields, false);
                 $msg->setBody($this->template->fetch('Extension/Mailform/Mail'), 'text/html');
                 $this->mail->send();
             } else {
                 $errors = $check;
             }
         }
     }
     $this->mailformController->renderHtml($submit, $values, $errors);
 }
Пример #9
0
 /**
  * @param $prop
  * @param $value
  * @param $modelName
  * @param $validationRule
  * @return mixed
  */
 public function getErrorMessage($prop, $value, $modelName, $validationRule)
 {
     $className = str_ireplace('\\', '_', $modelName);
     return str_ireplace("#{$prop}", "{$value}", $this->translation->getTranslation('FIELD_ERROR' . strtoupper($className) . '_' . strtoupper($prop) . '_' . strtoupper($validationRule)));
 }
Пример #10
0
 private function addMenuItems($site)
 {
     $gp = $this->request->getGPAsObject();
     /**
      * Root Page
      */
     $pageRoot = new \Fraym\Menu\Entity\MenuItem();
     $pageRoot->site = $site;
     $pageRoot->caching = true;
     $pageRoot->visible = true;
     $pageRoot->active = true;
     $pageRoot->https = false;
     $pageRoot->checkPermission = false;
     $pageRoot->is404 = false;
     $pageRootTranslation = new \Fraym\Menu\Entity\MenuItemTranslation();
     $pageRootTranslation->menuItem = $pageRoot;
     $pageRootTranslation->title = $this->translation->autoTranslation('Home', 'en', $gp->locale);
     $pageRootTranslation->subtitle = $this->translation->autoTranslation('Welcome to my website.', 'en', $gp->locale);
     $pageRootTranslation->url = "";
     $pageRootTranslation->shortDescription = $this->translation->autoTranslation('My short website description', 'en', $gp->locale);
     $pageRootTranslation->longDescription = $this->translation->autoTranslation('My long website description', 'en', $gp->locale);
     $pageRootTranslation->externalUrl = false;
     $this->db->persist($pageRootTranslation);
     /**
      * 404 Page
      */
     $newPage = new \Fraym\Menu\Entity\MenuItem();
     $newPage->site = $site;
     $newPage->caching = true;
     $newPage->visible = false;
     $newPage->active = true;
     $newPage->https = false;
     $newPage->checkPermission = false;
     $newPage->is404 = true;
     $newPage->parent = $pageRoot;
     $newPageTranslation = new \Fraym\Menu\Entity\MenuItemTranslation();
     $newPageTranslation->menuItem = $newPage;
     $newPageTranslation->title = $this->translation->autoTranslation('404 Page not found', 'en', $gp->locale);
     $newPageTranslation->subtitle = '';
     $newPageTranslation->url = '/' . $this->translation->autoTranslation('error', 'en', $gp->locale) . '-404';
     $newPageTranslation->shortDescription = $this->translation->autoTranslation('404 Page not found', 'en', $gp->locale);
     $newPageTranslation->longDescription = $this->translation->autoTranslation('404 Page not found', 'en', $gp->locale);
     $newPageTranslation->externalUrl = false;
     $this->db->persist($newPageTranslation);
     /**
      * Blog Page
      */
     $newPage = new \Fraym\Menu\Entity\MenuItem();
     $newPage->site = $site;
     $newPage->caching = true;
     $newPage->visible = true;
     $newPage->active = true;
     $newPage->https = false;
     $newPage->checkPermission = false;
     $newPage->is404 = false;
     $newPage->parent = $pageRoot;
     $newPageTranslation = new \Fraym\Menu\Entity\MenuItemTranslation();
     $newPageTranslation->menuItem = $newPage;
     $newPageTranslation->title = $this->translation->autoTranslation('Blog', 'en', $gp->locale);
     $newPageTranslation->subtitle = $this->translation->autoTranslation('This is my blog.', 'en', $gp->locale);
     $newPageTranslation->url = "blog";
     $newPageTranslation->shortDescription = $this->translation->autoTranslation('Check out my blog.', 'en', $gp->locale);
     $newPageTranslation->longDescription = $this->translation->autoTranslation('Check out my blog.', 'en', $gp->locale);
     $newPageTranslation->externalUrl = false;
     $this->db->persist($newPageTranslation);
     $this->db->flush();
     $this->db->clear();
     return $this;
 }