item)) { $id = $this->input->get('id', $id, 'int'); $this->item = CKFof::dbLoad($this->table, $id); } // transform params to JRegistry object // if (isset($this->item->params)) $this->item->params = new JRegistry($this->item->params); $this->item->htmlcode = str_replace("|URIROOT|", JUri::root(true), $this->item->htmlcode); return $this->item; } /** * Method to save the page. * * @param array The form data. * @return mixed The id on success, false on failure. */ public function save($data) { $id = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('style.id'); $user = CKFof::getUser(); $date = JFactory::getDate(); // if (isset($data['options']) && is_array($data['options'])) // { // $registry = new Registry; // $registry->loadArray($data['options']); // $data['params'] = (string) $registry; // } if ($id) { //Check the user can edit this item $authorised = $user->authorise('core.edit', 'style.' . $id); } else { //Check the user can create new items in this section $authorised = $user->authorise('core.create', 'com_pagebuilderck'); $data['created'] = $date->toSql(); } if ($authorised !== true) { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); return false; } // save the date $data['modified'] = $date->toSql(); // make a backup before save // PagebuilderckHelper::makeBackup($this->getItem()); $data['stylecode'] = $this->getStylesFromHtml($data['htmlcode']); //var_dump($data['stylecode']);die; $pageid = CKFof::dbStore($this->table, $data); return $pageid; } public function getElements() { $model = CKFof::getModel('elements'); return $model->getItems(); } private function getStylesFromHtml($htmlcode) { $regexStyle = "#]*ckstyleresponsive([^\"]*)\"[^>]*>(.*)<\/div>#siU"; // replace all divs with class ckstyleresponsive $htmlcode = preg_replace_callback($regexStyle, array($this, 'replaceResponsiveStyleTag'), $htmlcode); $regexStyle = "#]*ckstyle([^\"]*)\"[^>]*>(.*)<\/div>#siU"; // replace all divs with class ckstyle $htmlcode = preg_replace_callback($regexStyle, array($this, 'replaceStyleTag'), $htmlcode); $regexStyle2 = "#]*ckcolumnwidth([^\"]*)\"[^>]*>(.*)<\/style>#siU"; // replace all divs with class ckcolumnwidth $htmlcode = preg_replace_callback($regexStyle2, array($this, 'replaceResponsiveStyleTag'), $htmlcode); return trim($this->stylecode); } public function replaceResponsiveStyleTag($matches) { if (!$matches[2]) return; $styleTag = trim($matches[2]); $styleTag = str_replace('', '', $styleTag); $styleTag = str_replace(' ', ' ', $styleTag); $styleTag = str_replace('', '', $styleTag); $styleTag = str_replace(' ', ' ', $styleTag); $styleTag = str_replace('