예제 #1
0
 /**
  * @return bool|mixed
  */
 public function getContent()
 {
     if ($this->user->isAdmin() === false) {
         return false;
     }
     $currentEntity = false;
     $errors = false;
     $data = array();
     $formFields = array();
     $entities = array();
     $modelClass = false;
     $model = false;
     $modelName = $this->request->gp('model', false);
     $groupedModels = $this->db->getRepository('\\Fraym\\EntityManager\\Entity\\Group')->findAll();
     if ($modelName) {
         $model = $this->entityManager->getEntityByStringOrId($modelName);
         if ($model) {
             $modelClass = $model->className;
         }
     }
     if ($this->request->isXmlHttpRequest()) {
         return $this->createEntityFromSingleField($modelClass);
     }
     if ($modelClass && $this->request->isPost()) {
         $data = $this->request->getGPAsArray();
         $validation = $this->validation->setData($data)->getFormFieldValidation($modelClass);
         if ($id = $this->request->post('id')) {
             $currentEntity = $this->db->getRepository($modelClass)->findOneById($id);
             if (isset($data['cmd']) && $data['cmd'] == 'update' && $currentEntity && ($errors = $validation->check()) === true) {
                 $currentEntity->updateEntity($data);
             } elseif (isset($data['cmd']) && $data['cmd'] == 'remove' && $currentEntity) {
                 $this->db->remove($currentEntity);
                 $this->db->flush();
                 $data = array();
                 $currentEntity = false;
             } elseif (isset($data['cmd']) && $data['cmd'] == 'update') {
                 $currentEntity->updateEntity($data, false);
             }
         } else {
             if (isset($data['cmd']) && $data['cmd'] == 'new' && ($errors = $validation->check()) === true) {
                 $currentEntity = new $modelClass();
                 $currentEntity->updateEntity($data);
             }
         }
     }
     if ($modelClass && $model) {
         $entities = $this->db->getRepository($modelClass)->findAll();
         $formFields = $this->formField->setClassName($modelClass)->getFields();
     }
     $this->view->assign('locales', $this->locale->getLocales());
     $this->view->assign('data', $data);
     $this->view->assign('errors', $errors);
     $this->view->assign('currentEntity', $currentEntity);
     $this->view->assign('entities', $entities);
     $this->view->assign('groupedModels', $groupedModels);
     $this->view->assign('model', $model);
     $this->view->assign('formFields', $formFields);
     return $this->siteManagerController->getIframeContent($this->template->fetch('EntityView'));
 }
예제 #2
0
파일: Mailform.php 프로젝트: jewelhuq/fraym
 /**
  * @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);
 }
예제 #3
0
 /**
  *
  */
 public function getContent()
 {
     $values = array();
     $errors = array();
     $result = array();
     if ($this->request->isPost()) {
         $fields = $this->request->post('field');
         $this->validation->setData($fields);
         $this->validation->addRule('email', 'email')->addRule('subject', 'notEmpty')->addRule('name', 'notEmpty')->addRule('description', 'notEmpty')->addRule('reproduce', 'notEmpty');
         $check = $this->validation->check();
         if ($check === true) {
             $params = array('fields' => $fields, 'client_info' => array('version' => \Fraym\Core::VERSION, 'php_version' => phpversion(), 'os' => php_uname('s'), 'apc_enabled' => APC_ENABLED, 'image_processor' => IMAGE_PROCESSOR, 'server' => $_SERVER, 'env' => ENV));
             $result = $this->request->send(self::BUGREPORT_URL, $params);
         } else {
             $errors = $check;
         }
     }
     $this->view->assign('result', $result);
     $this->view->assign('values', $values);
     $this->view->assign('errors', $errors);
     return $this->siteManagerController->getIframeContent($this->view->fetch('BugReport'));
 }
예제 #4
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);
 }
예제 #5
0
 /**
  * Save the block configuration received by the client.
  *
  * @return bool
  */
 public function saveBlockConfig()
 {
     $blockConfigGP = $this->request->getGPAsObject();
     $validate = $this->validation->setData($blockConfigGP);
     $validate->addRule('id', 'numeric')->addRule('menuId', 'numeric')->addRule('contentId', 'notEmpty');
     $block = false;
     $menuItemTranslation = null;
     if (($result = $validate->check()) === true) {
         $extension = $this->db->getRepository('\\Fraym\\Block\\Entity\\BlockExtension')->findOneById($blockConfigGP->id);
         $menu = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($blockConfigGP->menuId);
         $menuItemTranslation = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItemTranslation')->findOneById($blockConfigGP->menuTranslationId);
         if (isset($blockConfigGP->currentBlockId)) {
             $block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockConfigGP->currentBlockId);
         }
         if ($extension) {
             if ($block) {
                 $newBlock = new BlockXML();
                 $newBlock->init($block->config);
             } else {
                 $newBlock = new BlockXML();
             }
             if (isset($blockConfigGP->excludedDevices)) {
                 $newBlock->setExcludedDevices($blockConfigGP->excludedDevices);
             }
             if (isset($blockConfigGP->permissions)) {
                 $newBlock->setPermissions($blockConfigGP->permissions);
             }
             $newBlock->setActive($blockConfigGP->active);
             $newBlock->setCache($blockConfigGP->cache);
             $newBlock->setMethod($extension->execMethod);
             $newBlock->setClass($extension->class);
             if (!empty($blockConfigGP->startDate)) {
                 $date = new \DateTime(date('Y-m-d H:i:s', strtotime($blockConfigGP->startDate)));
                 $newBlock->setStartDate($date);
             }
             if (!empty($blockConfigGP->endDate)) {
                 $date = new \DateTime(date('Y-m-d H:i:s', strtotime($blockConfigGP->endDate)));
                 $newBlock->setEndDate($date);
             }
             if ($blockConfigGP->template == 'custom') {
                 $newBlock->setTemplate($blockConfigGP->templateContent);
                 $newBlock->setTemplateType('string');
             } elseif (empty($blockConfigGP->template)) {
                 $newBlock->setTemplate($blockConfigGP->templateFile);
                 $newBlock->setTemplateType('file');
             } else {
                 $newBlock->setTemplateType($blockConfigGP->template);
             }
             $saveMethod = $extension->saveMethod;
             $instance = $this->serviceLocator->get($extension->class);
             if (empty($block)) {
                 $block = new \Fraym\Block\Entity\Block();
             }
             $blockCount = count($this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findByContentId($blockConfigGP->contentId));
             $block->contentId = $blockConfigGP->contentId;
             $block->position = $block->position ? $block->position : $blockCount;
             $block->menuItem = isset($blockConfigGP->menu) && $blockConfigGP->menu == '1' ? null : $menu;
             $block->site = $menu->site;
             $block->menuItemTranslation = $blockConfigGP->menuTranslation === 'current' ? $menuItemTranslation : null;
             $block->extension = $extension;
             $this->db->persist($block);
             $this->db->flush();
             /**
              * Set configuration for the block output
              */
             $this->locale->setLocale($menuItemTranslation->locale->id);
             $this->route->setCurrentMenuItem($menu);
             $this->route->setCurrentMenuItemTranslation($menuItemTranslation);
             /**
              * Extension event callback
              */
             if (method_exists($instance, $saveMethod)) {
                 $newBlock = $instance->{$saveMethod}($block->id, $newBlock);
             }
             $blockConfig = $this->blockParser->getBlockConfig((string) $newBlock);
             $block->config = $blockConfig;
             $this->db->flush();
             /**
              * Save block in history
              */
             if (isset($blockConfigGP->currentBlockId)) {
                 $this->block->saveHistory($block, 'edited');
             } else {
                 $this->block->saveHistory($block, 'added');
             }
             $data = $this->prepareBlockOutput($block);
             $this->response->sendAsJson(array('data' => $data, 'blockId' => $block->id));
         }
     }
     $this->response->sendAsJson(array('error' => $result));
 }