/**
  * Generate the module
  */
 protected function compile()
 {
     $arrModules = deserialize($this->module_summarize_modules);
     $arrBuffer = array();
     // load the frontend module
     foreach ($arrModules as $module) {
         $arrBuffer[] = array('pre_code' => $module['pre_code'], 'module' => \Controller::getFrontendModule($module['module']), 'after_code' => $module['after_code']);
     }
     $this->Template->arrModules = $arrBuffer;
 }
 /**
  * Display a wildcard in the back end
  *
  * @return string
  */
 public function generate()
 {
     if (TL_MODE == 'BE') {
         $objTemplate = new \BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['eventreader_plus'][0]) . ' ###';
         $objTemplate->title = $this->headline;
         $objTemplate->id = $this->id;
         $objTemplate->link = $this->name;
         $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
         return $objTemplate->parse();
     }
     global $objPage;
     // add registration before generating event details, otherwise formhybrid ajax requests wont get triggered
     if (in_array('event_registration', \ModuleLoader::getActive()) && $this->addRegistration && $this->checkConditions() && $this->objEvent->addRegistration) {
         if (!$this->objEvent->codes && !\Input::get('step') || \Input::get('step') == EventRegistration::STEP_REGISTRATION) {
             if ($this->registrationFormModule > 0) {
                 $this->registration = \Controller::getFrontendModule($this->registrationFormModule);
             }
         } else {
             if (\Input::get('step') == EventRegistration::STEP_SUMMARY) {
                 if ($this->summaryModule > 0) {
                     $this->registration = \Controller::getFrontendModule($this->summaryModule);
                 }
             } else {
                 if ($this->codeCheckModule > 0) {
                     $this->registration = \Controller::getFrontendModule($this->codeCheckModule);
                 }
             }
         }
     }
     if ($this->cal_template_modal) {
         $this->strTemplate = $this->customTpl ?: 'mod_event_modal';
         $this->cal_template = $this->cal_template_modal;
         // list config
         $this->cal_showInModal = true;
         $this->cal_readerModule = $this->id;
         // set modal css ID for generateModal() and parent::generate()
         $arrCss = deserialize($this->cssID, true);
         $arrCss[0] = EventsPlusHelper::getCSSModalID($this->id);
         $this->cssID = $arrCss;
         $this->base = \Controller::generateFrontendUrl($objPage->row());
         if ($this->Environment->isAjaxRequest && !$this->isSearchIndexer()) {
             $this->strTemplate = 'mod_event_modal_ajax';
             if (!$this->generateAjax()) {
                 return '';
             }
         }
         if (!$this->checkConditions()) {
             return $this->generateModal();
         }
     }
     return parent::generate();
 }
Example #3
0
 /**
  * Load modal.
  *
  * @param int $modalId Modal model id.
  *
  * @return void
  */
 private function loadModal($modalId)
 {
     if (!Bootstrap::getConfigVar('runtime.modals.' . $modalId)) {
         \Controller::getFrontendModule($modalId);
     }
 }
Example #4
0
 /**
  * Replace modal tag, modal tag supports following formats:
  *
  * modal::id
  *      - SimpleAjax.php?modal=id?page=Pageid
  * modal::link::id
  *      - <a href="#modal-id" data-toggle="modal">Module name</a>
  * modal::url::id
  *      - #modal-id
  * modal::link::id::title
  *      - <a href="#modal-id" data-toggle="modal">Title</a>
  *
  * modal::id::type::typeid
  *      - SimpleAjax.php?modal=id?page=Pageid&dynamic=type&id=typeid
  * modal::link::id::type::typeid
  *      - <a href="SimpleAjax.php?modal=id?page=Pageid&dynamic=type&id=typeid" data-toggle="modal" data-remote="SimpleAjax.php?modal=id?page=Pageid&dynamic=type&id=typeid">Module name</a>
  *      - The data-target is nessecary because Bootstrap ony checks for data-remote if content is cached
  *      - href attribute is set for accessibility issues
  * modal::link::id::type::typeid::title
  *      - <a href="SimpleAjax.php?modal=id?page=Pageid&dynamic=type&id=typeid" data-toggle="modal" data-remote="SimpleAjax.php?modal=id?page=Pageid&dynamic=type&id=typeid">Title</a>
  *
  * modal::url::
  *
  * @param ReplaceInsertTagsEvent $event
  * @return void
  */
 public function replaceInsertTags(ReplaceInsertTagsEvent $event)
 {
     if ($event->getTag() != 'modal') {
         return;
     }
     $params = $event->getParams();
     if (is_numeric($params[0])) {
         array_insert($params, 0, array('remote'));
     }
     if (!isset($GLOBALS['TL_BODY']['bootstrap-modal-' . $params[1]])) {
         $model = \ModuleModel::findByPk($params[1]);
         if ($model != null && $model->type == 'bootstrap_modal') {
             $event->setHtml(\Controller::getFrontendModule($params[1]));
         }
     }
     $count = count($params);
     if ($count == 2 || $count == 3) {
         switch ($params[0]) {
             case 'remote':
                 $buffer = \Controller::generateFrontendUrl($GLOBALS['objPage']->row()) . '?bootstrap_modal=' . $params[1];
                 break;
             case 'url':
             case 'link':
                 $model = \ModuleModel::findByPk($params[1]);
                 if ($model === null || $model->type != 'bootstrap_modal') {
                     return;
                 }
                 $cssId = deserialize($model->cssID, true);
                 $buffer = '#' . ($cssId[0] != '' ? $cssId[0] : 'modal-' . $model->id);
                 if ($params[0] != 'link') {
                     break;
                 }
                 $params[2] = $count == 3 ? $params[2] : $model->name;
                 $buffer = sprintf('<a href="%s" data-toggle="modal">%s</a>', $buffer, $params[2]);
                 break;
             default:
                 return;
         }
         $event->setHtml($buffer);
     } elseif ($count == 4 || $count == 5) {
         switch ($params[0]) {
             case 'url':
             case 'link':
             case 'remote':
                 $params[0] = $GLOBALS['objPage']->id;
                 $buffer = vsprintf(Bootstrap::getConfigVar('modal.remoteDynamicUrl'), $params);
                 if ($params[0] != 'link') {
                     break;
                 }
                 if ($count == 4) {
                     $model = \ModuleModel::findByPk($params[1]);
                     if ($model === null || $model->type != 'bootstrap_modal') {
                         return;
                     }
                     $params[6] = $model->name;
                     $cssId = deserialize($model->cssID, true);
                     $cssId = '#' . ($cssId[0] != '' ? $cssId[0] : 'modal-' . $model->id);
                     $buffer = sprintf('<a href="%s" data-toggle="modal" data-remote="%s">%s</a>', $cssId, $buffer, $params[6]);
                 }
                 break;
             default:
                 return;
         }
         $event->setHtml($buffer);
     }
 }
 /**
  * Return the demanded frontend module or content element parsed as html string
  *
  * Required GET data:
  * * action: "reload-element"
  * * element: "ce::id" or "mod::id" (replace 'id' with the element's id)
  * * page: "id" (optionally, replace 'id' with the current page's id)
  * * auto_item: (an optional auto_item which will be set before fetching the element)
  */
 public function getModuleOrContentElement()
 {
     if (!\Environment::get('isAjaxRequest') || Input::get('action') != 'reload-element') {
         return;
     }
     global $objPage;
     // Set page object as it may be needed for the language e.g.
     if (!$objPage && (int) Input::get('page')) {
         $objPage = \PageModel::findWithDetails((int) Input::get('page'));
     }
     $GLOBALS['TL_LANGUAGE'] = null !== $objPage ? $objPage->language : $GLOBALS['TL_LANGUAGE'];
     list($strElementType, $intElementId) = trimsplit('::', Input::get('element'));
     $strError = '';
     $return = '';
     // Authenticate front end user, e.g. for insert tags
     if (FE_USER_LOGGED_IN) {
         /** @noinspection PhpUndefinedMethodInspection */
         $this->import('FrontendUser', 'User');
         /** @var \FrontendUser $this ->User */
         $this->User->authenticate();
     }
     // Load default language file
     \System::loadLanguageFile('default');
     // Set a given auto_item to fetch the correct version of a module or content element
     if ($strAutoItem = Input::get('auto_item')) {
         Input::setGet('auto_item', $strAutoItem);
     }
     switch ($strElementType) {
         case 'mod':
             /** @type \Model $objModule */
             $objModule = \ModuleModel::findByPk($intElementId);
             if (null === $objModule) {
                 $strError = sprintf('Could not find module ID %s', $intElementId);
                 continue;
             }
             if (!$objModule->allowAjaxReload) {
                 $strError = sprintf('Module ID %u is not allowed to fetch', $intElementId);
                 continue;
             }
             $return = \Controller::getFrontendModule($objModule);
             break;
         case 'ce':
             /** @type \Model $objContent */
             $objContent = ContentModel::findByPk($intElementId);
             if (null === $objContent) {
                 $strError = sprintf('Could not find content element ID %s', $intElementId);
                 continue;
             }
             if (!$objContent->allowAjaxReload) {
                 $strError = sprintf('Content element ID %u is not allowed to fetch', $intElementId);
                 continue;
             }
             $return = \Controller::getContentElement($objContent);
             break;
         default:
             $strError = 'Could not determine whether the element is a module or content element';
             break;
     }
     $arrResponse = array();
     if ($strError) {
         $arrResponse['status'] = 'error';
         $arrResponse['error'] = $strError;
     } else {
         $arrResponse['status'] = 'ok';
         $arrResponse['html'] = $return;
     }
     $objResponse = new JsonResponse($arrResponse);
     $objResponse->send();
 }