Ejemplo n.º 1
0
 /**
  * Replace insert tags.
  *
  * @param ReplaceInsertTagsEvent $event Replace insert tags event.
  *
  * @return void
  */
 public function replaceIconInsertTag(ReplaceInsertTagsEvent $event)
 {
     if ($event->getTag() == 'icon' || $event->getTag() == 'i') {
         $icon = Bootstrap::generateIcon($event->getParam(0), $event->getParam(1));
         $event->setHtml($icon);
         $event->stopPropagation();
     }
 }
Ejemplo n.º 2
0
 /**
  * Translate event params.
  *
  * @param ReplaceInsertTagsEvent $event The subscribed event.
  *
  * @return array
  */
 private function translateParams(ReplaceInsertTagsEvent $event)
 {
     $infinite = false;
     $columnSetId = $event->getParam(0);
     if ($event->getParam(1) === 'begin' && $event->getParam(2)) {
         $columnSetId = $event->getParam(2);
         if ($event->getParam(3)) {
             $infinite = true;
         }
     }
     return array($columnSetId, $infinite);
 }
Ejemplo n.º 3
0
 /**
  * Replace deprecated insert tag.
  *
  * @param ReplaceInsertTagsEvent $event  Replace insert tag event.
  * @param array                  $params Insert tag params.
  * @param int                    $count  Number of params.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 private function replaceDeprecatedInsertTag(ReplaceInsertTagsEvent $event, $params, $count)
 {
     if (($count == 4 || $count == 5) && in_array($params[0], array('url', 'link', 'remote'))) {
         $params[0] = $GLOBALS['objPage']->id;
         $buffer = vsprintf(Bootstrap::getConfigVar('modal.remoteDynamicUrl'), $params);
         if ($params[0] === 'link' && $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-target="%s">%s</a>', $buffer, $cssId, $params[6]);
         }
         $event->setHtml($buffer);
     }
 }
Ejemplo n.º 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);
     }
 }