Exemple #1
0
 /**
  * Add a block
  * @param string $popBlock
  * @param string $parentBlock
  * @param string $idBlock
  * @param string $id_next_block
  * @param string $stop_typecont
  * @return string 
  */
 protected function addBlockAction($popBlock, $parentBlock, $idBlock, $id_next_block, $stop_typecont, $content, $MODULE, $THEMEMODULE, $THEME)
 {
     $this->initObjects();
     $idBlock = strtolower($idBlock);
     if ($stop_typecont === 'page') {
         /* block id in page have to start with a capital */
         $idBlock = ucfirst($idBlock);
     }
     $tempBlock = new $popBlock($idBlock);
     $idBlock = $tempBlock->getId();
     /* To sanitize id */
     if (method_exists($tempBlock, 'onMove')) {
         /* init path of views */
         if ($stop_typecont === 'theme') {
             if ($tempBlock->onMove('theme', $THEMEMODULE, $THEME)) {
                 return $this->returnResult(array('notification' => t('ID block already exists in this theme, please choose antother')));
             }
         } else {
             if ($tempBlock->onMove('page', $MODULE, $this->page->getId())) {
                 return $this->returnResult(array('notification' => t('ID block already exists in this page, please choose antother')));
             }
         }
     }
     if (!empty($content) && method_exists($tempBlock, 'setContent')) {
         /* external DND */
         $tempBlock->setContent($content);
     }
     $block = $this->{$stop_typecont}->searchBlock($parentBlock);
     $block->addBlock($tempBlock, $id_next_block);
     /* If exists : Add default block CSS in current theme  */
     if (is_file('modules/' . str_replace('\\', '/', $popBlock) . '/default.css')) {
         $css = new \css('modules/' . str_replace('\\', '/', $popBlock) . '/default.css');
         if (!is_file(PROFILE_PATH . $THEMEMODULE . '/themes/' . $THEME . '/style.css') && is_file('modules/' . $this->theme->getModule() . '/themes/' . $this->theme->getName() . '/style.css')) {
             file_put_contents(PROFILE_PATH . $THEMEMODULE . '/themes/' . $THEME . '/style.css', file_get_contents('modules/' . $this->theme->getModule() . '/themes/' . $this->theme->getName() . '/style.css'));
         }
         $cssCurrentTheme = new \css(PROFILE_PATH . $THEMEMODULE . '/themes/' . $THEME . '/style.css');
         foreach ($css->getAllSselectors() as $selector) {
             $rules = $css->extractSelectorRules($selector);
             if (!empty($rules)) {
                 $newSelector = '#' . $idBlock . ' ' . str_replace(':host', '', $selector);
                 if (!$cssCurrentTheme->selectorExists($newSelector)) {
                     $cssCurrentTheme->addSelector($newSelector);
                 }
                 foreach ($rules as $property => $value) {
                     $value = str_replace('BASE_PATH', BASE_PATH, $value);
                     if (!$cssCurrentTheme->propertyExists($newSelector, $property)) {
                         $cssCurrentTheme->addProperty($newSelector, $property, $value);
                     } else {
                         $cssCurrentTheme->updateProperty($newSelector, $property, $value);
                     }
                 }
             }
         }
         $cssCurrentTheme->save();
     }
     $response = $tempBlock->ajaxRefresh('add');
     /* Get content before __sleep() */
     $this->saveAll();
     if ($this->{$stop_typecont}->searchBlock($idBlock) != NULL) {
         $return = array('eval' => $response, 'notification' => t('The Block is saved'), 'notificationType' => 'positive');
     } else {
         $return = array('notification' => t('Error on drop'), 'notificationType' => 'negative');
     }
     return $this->returnResult($return);
 }