authorise('core.create', 'com_pagebuilderck') || (count($user->getAuthorisedCategories('com_pagebuilderck', 'core.create')))); if ($authorised !== true) { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); return false; } $this->item = CKFof::dbLoad($this->table, $id); } else { // item already exists if (empty($this->item)) { // $id = $this->input->get('id', $id, 'int'); $query = "SELECT * FROM " . $this->table . " AS a" . " WHERE a.state = 1" . " AND a.id = " . (int) $id; try { $this->item = CKFof::dbLoadObject($query); } catch(Exception $e) { return false; } } if (empty($this->item)) { return false; } if ($id !== 0) { // counter for hits $sql = "UPDATE #__pagebuilderck_pages SET hits = hits + 1 WHERE id= " . $this->item->id; CKFof::dbExecute($sql); } } if (! empty($this->item)) { // transform params to JRegistry object if (isset($this->item->params)) $this->item->params = new JRegistry($this->item->params); } // get the list of categories if (isset($this->item->categories)) $this->item->categories = explode(',', $this->item->categories); if (isset($this->item->htmlcode) && $this->item->htmlcode) { // replace the root path for all elements $this->item->htmlcode = trim(str_replace("|URIROOT|", JUri::root(true), $this->item->htmlcode)); // load the general style if (! empty($this->item->styles)) { foreach($this->item->styles as $style) { $this->styleTags .= PagebuilderckHelper::getStyleCode($style); } } // pass through the html code to convert what is needed if ($this->input->get('layout', '', 'cmd') !== 'edit') { $this->parseHtml($this->item->htmlcode); } // active the content plugins interaction if ($this->item->params->get('contentprepare', '0')) { CKFof::importPlugin('content'); $this->item->htmlcode = JHtml::_('content.prepare', $this->item->htmlcode, '', 'com_pagebuilderck.page'); } } return $this->item; } public function parseHtml(&$htmlcode) { $customcss = ''; // replace the root path for all elements $htmlcode = trim(str_replace("|URIROOT|", JUri::root(true), (string)$htmlcode)); // replace the tags for W3C compliance // $htmlcode = trim(str_replace('
', '', $styleTag); $styleTag = str_replace(' ', ' ', $styleTag); if ($styleTag) { if (stristr($matches[1], 'ckresponsiverange4')) { $this->responsiveStyleTags4 .= str_replace('.ckresponsiveactive[ckresponsiverange="4"] ', '', $styleTag); $this->responsiveStyleTags4 .= str_replace('.ckresponsiveactive[ckresponsiverange*="4"] ', '', $styleTag); } else if (stristr($matches[1], 'ckresponsiverange3')) { $this->responsiveStyleTags3 .= str_replace('.ckresponsiveactive[ckresponsiverange="3"] ', '', $styleTag); $this->responsiveStyleTags3 .= str_replace('.ckresponsiveactive[ckresponsiverange*="3"] ', '', $styleTag); } else if (stristr($matches[1], 'ckresponsiverange2')) { $this->responsiveStyleTags2 .= str_replace('.ckresponsiveactive[ckresponsiverange="2"] ', '', $styleTag); $this->responsiveStyleTags2 .= str_replace('.ckresponsiveactive[ckresponsiverange*="2"] ', '', $styleTag); } else if (stristr($matches[1], 'ckresponsiverange1')) { $this->responsiveStyleTags1 .= str_replace('.ckresponsiveactive[ckresponsiverange="1"] ', '', $styleTag); $this->responsiveStyleTags1 .= str_replace('.ckresponsiveactive[ckresponsiverange*="1"] ', '', $styleTag); } else if (stristr($styleTag, 'ckresponsiverange="4"')) { $this->responsiveStyleTags4 .= str_replace('[ckresponsiverange="4"] ', '', $styleTag); $this->responsiveStyleTags4 .= str_replace('[ckresponsiverange*="4"] ', '', $styleTag); } else if (stristr($styleTag, 'ckresponsiverange="3"')) { $this->responsiveStyleTags3 .= str_replace('[ckresponsiverange="3"] ', '', $styleTag); $this->responsiveStyleTags3 .= str_replace('[ckresponsiverange*="3"] ', '', $styleTag); } else if (stristr($styleTag, 'ckresponsiverange="2"')) { $this->responsiveStyleTags2 .= str_replace('[ckresponsiverange="2"] ', '', $styleTag); $this->responsiveStyleTags2 .= str_replace('[ckresponsiverange*="2"] ', '', $styleTag); } else if (stristr($styleTag, 'ckresponsiverange="1"')) { $this->responsiveStyleTags1 .= str_replace('[ckresponsiverange="1"] ', '', $styleTag); $this->responsiveStyleTags1 .= str_replace('[ckresponsiverange*="1"] ', '', $styleTag); } else if (stristr($styleTag, 'ckresponsiverange="4321"')) { $this->responsiveStyleTags1 .= str_replace('[ckresponsiverange="4321"] ', '', $styleTag); } else if (stristr($styleTag, 'ckresponsiverange="432"') || stristr($styleTag, 'ckresponsiverange="432')) { $this->responsiveStyleTags2 .= str_replace('[ckresponsiverange="432"] ', '', $styleTag); } else if (stristr($styleTag, 'ckresponsiverange="43"') || stristr($styleTag, 'ckresponsiverange="43')) { $this->responsiveStyleTags3 .= str_replace('[ckresponsiverange="43"] ', '', $styleTag); } else { if ($styleTag) $this->styleTags .= $styleTag; } } return ''; } /* * @param array the matching strings * * return the module cdoe */ public function replaceStyleTag($matches) { if (!$matches[2]) return; $styleTag = trim($matches[2]); $styleTag = str_replace('', '', $styleTag); $styleTag = str_replace(' ', ' ', $styleTag); $pagebuilderckParams = JComponentHelper::getParams('com_pagebuilderck'); // check for the image path, and fix it if (strpos($styleTag, 'url(\'/')) { if ((int)$pagebuilderckParams->get('image_path_fix', 0, 'int') === 1) { $find = "# url\('/(.*?)\'\)#si"; // masque de recherche pour le tag $styleTag = preg_replace($find, ' url(\'' . JUri::root(true) . '/$1\')' , $styleTag); } } if ($styleTag) $this->styleTags .= $styleTag; return ''; } /* * @param array the matching strings * * return the module code */ public function replaceModule($matches) { if (!$matches[2]) return; // look for the module ID $find = "#data-id=\"(.*?)\"#si"; // masque de recherche pour le tag preg_match($find, $matches[2], $result_id); if ($result_id && $result_id[1]) { return $this->renderModule($result_id[1]); } return ''; } /* * @param array the matching strings * * return the page code */ public function replacePage($matches) { if (!$matches[2]) return; // look for the module ID $find = "#data-id=\"(.*?)\"#si"; // masque de recherche pour le tag preg_match($find, $matches[2], $result_id); if ($result_id && $result_id[1]) { return $this->renderPage($result_id[1]); } return ''; } /* * @param object the element * * return the module cdoe */ public function replaceElement($e) { $type = $e->attr['data-type']; if ($type) { $new_e = $this->renderElement($type, $e); if ($new_e) { return $new_e; } else { return $e->innertext; } } else if ($type == 'audio') { return $this->renderAudioElement($e); } else { return '

ERROR - PAGEBUILDER CK DEBUG : ELEMENT TYPE NOT FOUND

'; } return $e->innertext; } /* * @param object the element * * return the element html code for html5 audio */ public function renderCode($e) { // check if there is a plugin for this type, and if it is enabled if ( !JPluginHelper::isEnabled('pagebuilderck', 'code')) { return ''; } JPluginHelper::importPlugin( 'pagebuilderck' ); // $dispatcher = JEventDispatcher::getInstance(); $otheritems = Pagebuilderck\CKFof::triggerEvent( 'onPagebuilderckRenderItem' . ucfirst('code') , array($e)); // load only the first instance found, because each plugin type must be unique // add override feature here, look in the template $template = JFactory::getApplication()->getTemplate(); $overridefile = JPATH_ROOT . '/templates/' . $template . '/html/pagebuilderck/' . strtolower('code') . '.php'; // var_dump($otheritems); if (file_exists($overridefile)) { $item = $e; include_once $overridefile; } else { // normal use // $html = $otheritems[0]; } // echo $html; return ''; } /* * @param object the element * * return the element html code for html5 audio */ public function renderAudioElement($e) { $attrs = $e->find('.tab_audio'); $params = PagebuilderckFrontHelper::createParamsFromElement($attrs); $audiosrc = PagebuilderckFrontHelper::getSource($params->get('audiourl')); $html =''; $html2 = preg_replace('#
(.*?)<\/div>#is', $html, $e->innertext); return $html2; } /* * @param string the element type * @param object the element * * return the element html code */ public function renderElement($type, $e) { // check if there is a plugin for this type, and if it is enabled if ( !JPluginHelper::isEnabled('pagebuilderck', $type)) { return ''; } $doc = JFactory::getDocument(); JPluginHelper::importPlugin( 'pagebuilderck' ); // $dispatcher = JEventDispatcher::getInstance(); $otheritems = Pagebuilderck\CKFof::triggerEvent( 'onPagebuilderckRenderItem' . ucfirst($type) , array($e)); ob_start(); if (count($otheritems) == 1) { // load only the first instance found, because each plugin type must be unique // add override feature here, look in the template $template = JFactory::getApplication()->getTemplate(); $overridefile = JPATH_ROOT . '/templates/' . $template . '/html/pagebuilderck/' . strtolower($type) . '.php'; if (file_exists($overridefile)) { $item = $e; include_once $overridefile; try { $class = 'plgPagebuilderck' . ucfirst($type) . 'Override'; $func = 'onPagebuilderckRenderItem' . ucfirst($type); $reflection = new ReflectionClass($class); $instance = $reflection->newInstanceWithoutConstructor(); if ($instance) { $html = $instance->$func($e); } } catch (Exception $e) { } } else { // normal use $html = $otheritems[0]; } echo $html; } else { echo '

ERROR - PAGEBUILDER CK DEBUG : ELEMENT TYPE INSTANCE : ' . $type . '. Number of instances found : ' . count($otheritems) . '

'; } $element_code = ob_get_clean(); return $element_code; } /* * @param int the module ID * * return the module html code */ public function renderModule($module_id) { $document = JFactory::getDocument(); $renderer = $document->loadRenderer('module'); $mod = $this->getModule($module_id); if (empty($mod)) $mod = JModuleHelper::getModuleById($module_id); if (!$mod) return; $params = array('style' => 'xhtml'); ob_start(); echo $renderer->render($mod, $params); $module_code = ob_get_clean(); return $module_code; } public function getModule($module_id) { $app = JFactory::getApplication(); $groups = implode(',', JFactory::getUser()->getAuthorisedViewLevels()); $lang = JFactory::getLanguage()->getTag(); $clientId = (int) $app->getClientId(); $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select('m.id, m.title, m.module, m.position, m.content, m.showtitle, m.params, mm.menuid') ->from('#__modules AS m') ->join('LEFT', '#__modules_menu AS mm ON mm.moduleid = m.id') ->where('m.published = 1') ->join('LEFT', '#__extensions AS e ON e.element = m.module AND e.client_id = m.client_id') ->where('e.enabled = 1'); $date = JFactory::getDate(); $now = $date->toSql(); $nullDate = $db->getNullDate(); $query->where('(m.publish_up = ' . $db->quote($nullDate) . ' OR m.publish_up <= ' . $db->quote($now) . ')') ->where('(m.publish_down = ' . $db->quote($nullDate) . ' OR m.publish_down >= ' . $db->quote($now) . ')') ->where('m.access IN (' . $groups . ')') ->where('m.client_id = ' . $clientId) ->where('m.id = ' . (int) $module_id) // ->where('(mm.menuid = ' . (int) $Itemid . ' OR mm.menuid <= 0)'); ; // Filter by language if (\Pagebuilderck\CKFof::isSite() && $app->getLanguageFilter()) { $query->where('m.language IN (' . $db->quote($lang) . ',' . $db->quote('*') . ')'); } // $query->order('m.position, m.ordering'); // Set the query $db->setQuery($query); try { $module = $db->loadObject(); } catch (RuntimeException $e) { JLog::add(JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $e->getMessage()), JLog::WARNING, 'jerror'); return array(); } return $module; } /** * Module list * * @return array */ public static function getModuleList() { $app = JFactory::getApplication(); $Itemid = $app->input->getInt('Itemid'); $groups = implode(',', JFactory::getUser()->getAuthorisedViewLevels()); $lang = JFactory::getLanguage()->getTag(); $clientId = (int) $app->getClientId(); $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select('m.id, m.title, m.module, m.position, m.content, m.showtitle, m.params, mm.menuid') ->from('#__modules AS m') ->join('LEFT', '#__modules_menu AS mm ON mm.moduleid = m.id') ->where('m.published = 1') ->join('LEFT', '#__extensions AS e ON e.element = m.module AND e.client_id = m.client_id') ->where('e.enabled = 1'); $date = JFactory::getDate(); $now = $date->toSql(); $nullDate = $db->getNullDate(); $query->where('(m.publish_up = ' . $db->quote($nullDate) . ' OR m.publish_up <= ' . $db->quote($now) . ')') ->where('(m.publish_down = ' . $db->quote($nullDate) . ' OR m.publish_down >= ' . $db->quote($now) . ')') ->where('m.access IN (' . $groups . ')') ->where('m.client_id = ' . $clientId) ->where('(mm.menuid = ' . (int) $Itemid . ' OR mm.menuid <= 0)'); // Filter by language if (\Pagebuilderck\CKFof::isSite() && $app->getLanguageFilter()) { $query->where('m.language IN (' . $db->quote($lang) . ',' . $db->quote('*') . ')'); } $query->order('m.position, m.ordering'); // Set the query $db->setQuery($query); try { $modules = $db->loadObjectList(); } catch (RuntimeException $e) { JLog::add(JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $e->getMessage()), JLog::WARNING, 'jerror'); return array(); } return $modules; } /** * Method to get an ojbect. * * @param integer The id of the object to get. * * @return mixed Object on success, false on failure. */ public function &getData($id = null) { if (empty($id)) { $id = $this->input->get('id', $id, 'int'); } if ($id === 0) { // check that the user has the rights to edit $authorised = ($user->authorise('core.create', 'com_pagebuilderck') || (count($user->getAuthorisedCategories('com_pagebuilderck', 'core.create')))); if ($authorised !== true) { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); return false; } $item = CKFof::dbLoad($this->table, $id); } else { $query = "SELECT * FROM " . $this->table . " AS a" . " WHERE a.state = 1" . " AND a.id = " . (int) $id; $item = CKFof::dbLoadObject($query); } return $this->item; } /** * Method to save the form data. * * @param array The form data. * @return mixed The user id on success, false on failure. * @since 1.6 */ public function save($data) { $id = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('page.id'); $user = CKFof::getUser(); $data['htmlcode'] = $this->input->get('htmlcode', '', 'raw'); $data['htmlcode'] = str_replace(JUri::root(true), "|URIROOT|", $data['htmlcode']); if (isset($data['options']) && is_array($data['options'])) { $registry = new Registry; $registry->loadArray($data['options']); $data['params'] = (string) $registry; } // save the date $date = JFactory::getDate(); $data['modified'] = $date->toSql(); if ($id) { //Check the user can edit this item $authorised = $user->authorise('core.edit', 'page.' . $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; } // make a backup before save PagebuilderckHelper::makeBackup($this->getData($data['id'])); $pageid = CKFof::dbStore($this->table, $data); return $pageid; } /* * @param int the module ID * * return the module html code */ public function renderPage($id) { include_once JPATH_ROOT . '/components/com_pagebuilderck/models/page.php'; $model = JModelLegacy::getInstance('Page', 'PagebuilderckModel'); $page = $model->getItem($id); ob_start(); if (isset($page->htmlcode) && $page->htmlcode) { echo $page->htmlcode; } $code = ob_get_clean(); return $code; } /* * @param string the styles comma separated * * return the css code */ private function loadStyles($stylestoload) { // Create a new query object. $db = CKFof::getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. $query->select('a.*'); $query->from('`#__pagebuilderck_styles` AS a'); $query->where('a.id in ( ' . $stylestoload .')'); // Do not list the trashed items $query->where('a.state > -1'); $db->setQuery($query); $styles = $db->loadObjectList(); foreach($styles as $style) { PagebuilderckFrontHelper::addStyleDeclaration($style->stylecode); } } }