<?php
/**
 * @copyright	Copyright (C) 2015 Cédric KEIFLIN alias ced1870
 * http://www.template-creator.com
 * http://www.joomlack.fr
 * @license		GNU/GPL
 * */

defined('_JEXEC') or die;

if (! file_exists(JPATH_ADMINISTRATOR . '/components/com_pagebuilderck/helpers/pagebuilderckfront.php')) return;
include_once JPATH_ADMINISTRATOR . '/components/com_pagebuilderck/helpers/pagebuilderckfront.php';

// get the html code of the page
$modulecontent = $params->get('pagedition');

$app             = \Joomla\CMS\Factory::getApplication();
// Detecting Active Variables
$templateedition = $app->input->get('tckedition', 0, 'int');
global $pagebuilderckEditionLoaded, $ckFrontEditionLoaded;
if ($templateedition && $pagebuilderckEditionLoaded === true) {
	echo '<div class="workspaceck pagebuilderck pbck-module-edition" data-id="' . $module->id . '">' . $modulecontent . '</div>';
} else {

// pass through the content plugins 
if ($params->get('preparecontent', '0')) {
	\Joomla\CMS\Plugin\PluginHelper::importPlugin('content');
	$modulecontent = \Joomla\CMS\HTML\HTMLHelper::_('content.prepare', $modulecontent, '', 'mod_pagebuilderck.content');
}

$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx', ''));

// frontend medias
PagebuilderckFrontHelper::loadFrontendAssets();

// get the page model
include_once JPATH_ROOT . '/components/com_pagebuilderck/models/page.php';
$model	= \Joomla\CMS\MVC\Model\BaseDatabaseModel::getInstance('Page', 'PagebuilderckModel');

// parse the html code through the model page
$model->parseHtml($modulecontent);

require \Joomla\CMS\Helper\ModuleHelper::getLayoutPath('mod_pagebuilderck', $params->get('layout', 'default'));
}
