public function process($layout, $options = false, $coming_from_parent = false, $coming_from_parent_id = false)
{
global $mw_replaced_edit_fields_vals;
if (!isset($parser_mem_crc)) {
$parser_mem_crc = 'parser_' . crc32($layout) . content_id();
$parser_modules_crc = 'parser_modules' . crc32($layout) . content_id();
}
//$this->layout = $layout;
static $process_started;
if ($process_started == false) {
$process_started = true;
$this->app->event_manager->trigger('parser.process', $layout);
}
if (isset($mw_replaced_edit_fields_vals[$parser_mem_crc])) {
return $mw_replaced_edit_fields_vals[$parser_mem_crc];
}
$layout = str_replace('<?', '<?', $layout);
$layout = str_replace('<microweber module=', '<module data-type=', $layout);
$layout = str_replace('</microweber>', '', $layout);
$layout = str_replace('></module>', '/>', $layout);
$script_pattern = '/<module[^>]*>/Uis';
preg_match_all($script_pattern, $layout, $mw_script_matches);
if (!empty($mw_script_matches)) {
$matches1 = $mw_script_matches[0];
foreach ($matches1 as $key => $value) {
if ($value != '') {
$v1 = crc32($value);
$v1 = '<!-- mw_replace_back_this_module_' . $v1 . ' -->';
$layout = str_replace($value, $v1, $layout);
if (!isset($this->mw_replaced_modules[$v1])) {
$this->mw_replaced_modules[$v1] = $value;
}
}
}
}
if (!isset($options['parse_only_vars'])) {
$layout = str_replace('<mw ', '<module ', $layout);
$layout = str_replace('<editable ', '<div class="edit" ', $layout);
$layout = str_replace('</editable>', '</div>', $layout);
$layout = str_replace('<microweber module=', '<module data-type=', $layout);
$layout = str_replace('</microweber>', '', $layout);
$layout = str_replace('></module>', '/>', $layout);
$replaced_scripts = array();
$script_pattern = "/<script[^>]*>(.*)<\\/script>/Uis";
preg_match_all($script_pattern, $layout, $mw_script_matches);
if (!empty($mw_script_matches)) {
foreach ($mw_script_matches[0] as $key => $value) {
if ($value != '') {
$v1 = crc32($value);
$v1 = '<x-tag> mw_replace_back_this_script_' . $v1 . ' </x-tag>';
$layout = str_replace($value, $v1, $layout);
if (!isset($replaced_scripts[$v1])) {
$replaced_scripts[$v1] = $value;
}
}
}
}
$script_pattern = "/<code[^>]*>(.*)<\\/code>/Uis";
preg_match_all($script_pattern, $layout, $mw_script_matches);
if (!empty($mw_script_matches)) {
foreach ($mw_script_matches[0] as $key => $value) {
if ($value != '') {
$v1 = crc32($value);
$v1 = '<tag>mw_replace_back_this_code_' . $v1 . '</tag>';
$layout = str_replace($value, $v1, $layout);
if (!isset($replaced_scripts[$v1])) {
$this->_replaced_codes[$v1] = $value;
}
}
}
}
preg_match_all('/.*?class=..*?edit.*?.[^>]*>/', $layout, $layoutmatches);
if (!empty($layoutmatches) and isset($layoutmatches[0][0])) {
$layout = $this->_replace_editable_fields($layout);
}
$layout = str_replace('<microweber module=', '<module data-type=', $layout);
$layout = str_replace('</microweber>', '', $layout);
$layout = str_replace('></module>', '/>', $layout);
$script_pattern = '/<module[^>]*>/Uis';
preg_match_all($script_pattern, $layout, $mw_script_matches);
if (!empty($mw_script_matches)) {
$matches1 = $mw_script_matches[0];
foreach ($matches1 as $key => $value) {
if ($value != '') {
$v1 = crc32($value);
$v1 = '<!-- mw_replace_back_this_module_111' . $v1 . ' -->';
$layout = str_replace($value, $v1, $layout);
if (!isset($this->mw_replaced_modules[$v1])) {
$this->mw_replaced_modules[$v1] = $value;
}
}
}
}
if (!empty($replaced_scripts)) {
foreach ($replaced_scripts as $key => $value) {
if ($value != '') {
$layout = str_replace($key, $value, $layout);
}
unset($replaced_scripts[$key]);
}
}
if (is_array($this->mw_replaced_modules)) {
$attribute_pattern = '@
(?P<name>\\w+)# attribute name
\\s*=\\s*
(
(?P<quote>[\\"\'])(?P<value_quoted>.*?)(?P=quote) # a quoted value
| # or
(?P<value_unquoted>[^\\s"\']+?)(?:\\s+|$) # an unquoted value (terminated by whitespace or EOF)
)
@xsi';
$attribute_pattern = '@(?P<name>[a-z-_A-Z]+)\\s*=\\s*((?P<quote>[\\"\'])(?P<value_quoted>.*?)(?P=quote)|(?P<value_unquoted>[^\\s"\']+?)(?:\\s+|$))@xsi';
$attribute_pattern = '@(?P<name>[a-z-_A-Z]+)\\s*=\\s*((?P<quote>[\\"\'])(?P<value_quoted>.*?)(?P=quote)|(?P<value_unquoted>[^\\s"\']+?)(?:\\s+|$))@xsi';
$attrs = array();
foreach ($this->mw_replaced_modules as $key => $value) {
if ($value != '') {
$replace_key = $key;
$attrs = array();
if (preg_match_all($attribute_pattern, $value, $attrs1, PREG_SET_ORDER)) {
foreach ($attrs1 as $item) {
$m_tag = trim($item[0], "\"'");
$m_tag = trim($m_tag, "'\"");
$m_tag = explode('=', $m_tag);
$a = trim($m_tag[0], "''");
$a = trim($a, '""');
$b = trim($m_tag[1], "''");
$b = trim($b, '""');
if (isset($m_tag[2])) {
$rest_pieces = $m_tag;
if (isset($rest_pieces[0])) {
unset($rest_pieces[0]);
}
if (isset($rest_pieces[1])) {
unset($rest_pieces[1]);
}
$rest_pieces = implode('=', $rest_pieces);
$b = $b . $rest_pieces;
}
$attrs[$a] = $b;
}
}
$m_tag = ltrim($value, '<module');
$m_tag = rtrim($m_tag, '/>');
$m_tag = rtrim($m_tag);
$userclass = '';
$module_html = "<div class='__USER_DEFINED_CLASS__ __MODULE_CLASS__ __WRAP_NO_WRAP__' __MODULE_ID__ __MODULE_NAME__";
$module_has_class = false;
if (!empty($attrs)) {
if (isset($attrs['module']) and $attrs['module']) {
$attrs['data-type'] = $attrs['module'];
unset($attrs['module']);
}
if ($coming_from_parent == true) {
$attrs['data-parent-module'] = $coming_from_parent;
}
if ($coming_from_parent_id == true) {
$attrs['data-parent-module-id'] = $coming_from_parent_id;
}
if (isset($attrs['type']) and $attrs['type']) {
$attrs['data-type'] = $attrs['type'];
unset($attrs['type']);
}
$z = 0;
$mod_as_element = false;
$mod_no_wrapper = false;
if (isset($attrs['data-module'])) {
$attrs['data-type'] = $attrs['data-module'];
unset($attrs['data-module']);
}
foreach ($attrs as $nn => $nv) {
if ($nn == 'class') {
$module_has_class = $userclass = $nv;
if (strstr($nv, 'module-as-element')) {
$mod_as_element = true;
$userclass = str_replace('module-as-element', '', $userclass);
}
$userclass = str_replace(' module module ', 'module ', $userclass);
$userclass = str_replace('ui-sortable', '', $userclass);
$userclass = str_replace('module-item', '', $userclass);
$userclass = str_replace('module module module', 'module', $userclass);
$userclass = str_replace('module module ', 'module ', $userclass);
} else {
$module_html .= " {$nn}='{$nv}' ";
}
if ($nn == 'module') {
$module_name = $nv;
$attrs['data-type'] = $module_name;
unset($attrs[$nn]);
}
if ($nn == 'no_wrap') {
$mod_no_wrapper = true;
unset($attrs[$nn]);
}
if ($nn == 'data-no-wrap') {
$mod_no_wrapper = true;
unset($attrs[$nn]);
}
if ($nn == 'data-module-name') {
$module_name = $nv;
$attrs['data-type'] = $module_name;
unset($attrs[$nn]);
}
if ($nn == 'data-module-name-enc') {
unset($attrs[$nn]);
}
if ($nn == 'type') {
$module_name = $nv;
$attrs['data-type'] = $module_name;
unset($attrs[$nn]);
}
if ($nn == 'data-type') {
$module_name = $nv;
}
if ($nn == 'data-module') {
$attrs['data-type'] = $module_name;
$module_name = $nv;
}
++$z;
}
$module_title = false;
if (isset($module_name)) {
$module_class = $this->module_css_class($module_name);
$module_title = module_info($module_name);
if (!isset($attrs['id'])) {
global $mw_mod_counter;
++$mw_mod_counter;
if (!defined('MW_1_0_4_COMPAT')) {
$mw_mod_counter1 = md5(serialize($attrs));
} else {
$mw_mod_counter1 = crc32(serialize($attrs));
}
$seg_clean = $this->app->url_manager->segment(0, url_current());
//
if (defined('IS_HOME')) {
$seg_clean = '';
}
$seg_clean = str_replace('.', '', $seg_clean);
$seg_clean = str_replace('%20', '-', $seg_clean);
// $mod_id = $module_class . '-' . crc32($seg_clean) . ($mw_mod_counter1);
if (defined('CONTENT_ID') and CONTENT_ID != 0) {
$mod_id = $module_class . '-' . $mw_mod_counter1;
}
// $mod_id = $module_class . ($mw_mod_counter1).crc32($replace_key);
$mod_id = $module_class . $mw_mod_counter1;
static $last_content_id = null;
if (defined('CONTENT_ID') and CONTENT_ID == 0) {
if ($last_content_id == null) {
$last_content_id = $this->app->database_manager->last_id('content');
}
$last_content_id = intval($last_content_id) + 1;
$mod_id = $mod_id . '-' . $last_content_id;
} elseif (defined('CONTENT_ID')) {
$mod_id = $mod_id . '-' . CONTENT_ID;
}
//
if ($this->_current_parser_rel == 'global') {
$mod_id = $module_class . $mw_mod_counter1;
// if(isset($attrs['data-type']) && $attrs['data-type'] == 'video'){
// d($attrs);
// d($mod_id);
// d(CONTENT_ID);
// }
} else {
//$mod_id = $module_class . '-' . $seg_clean . ($mw_mod_counter1);
}
if (!in_array($mod_id, $this->_existing_module_ids)) {
$this->_existing_module_ids[] = $mod_id;
} else {
if (isset($attrs['data-parent-module-id'])) {
$mod_id = $mod_id . crc32($attrs['data-parent-module-id']);
} else {
$mod_id = $mod_id . uniqid();
}
}
$attrs['id'] = $mod_id;
$module_html = str_replace('__MODULE_ID__', "id='{$attrs['id']}'", $module_html);
} else {
$module_html = str_replace('__MODULE_ID__', '', $module_html);
}
}
if (is_array($module_title) and isset($module_title['name'])) {
$module_title['name'] = addslashes($module_title['name']);
$module_html = str_replace('__MODULE_NAME__', ' data-mw-title="' . $module_title['name'] . '"', $module_html);
} else {
$module_html = str_replace('__MODULE_NAME__', '', $module_html);
}
if (isset($module_name)) {
if (strstr($module_name, 'admin')) {
$module_html = str_replace('__WRAP_NO_WRAP__', '', $module_html);
} else {
$module_html = str_replace('__WRAP_NO_WRAP__', '', $module_html);
}
$module_name_url = $this->app->url_manager->slug($module_name);
if ($mod_as_element == false) {
if (strstr($module_name, 'text')) {
$module_html = str_replace('__MODULE_CLASS__', 'layout-element ' . $module_name_url, $module_html);
} else {
$module_html = str_replace('__MODULE_CLASS__', 'module ' . $module_class, $module_html);
}
} else {
$module_html = str_replace('__MODULE_CLASS__', 'element ' . $module_name_url, $module_html);
}
$userclass = str_replace(trim($module_class), '', $userclass);
$userclass = trim(str_replace(' module ', ' ', $userclass));
$userclass = trim(str_replace(' disabled module ', ' module ', $userclass));
$module_class = trim(str_replace(' disabled module ', ' module ', $module_class));
$userclass = trim(str_replace(' module module ', ' module ', $userclass));
$module_html = str_replace('__MODULE_CLASS_NAME__', '' . $module_class, $module_html);
$module_html = str_replace('__USER_DEFINED_CLASS__', $userclass, $module_html);
if ($coming_from_parent == false and isset($module_name) == true) {
$coming_from_parentz = $module_name;
} else {
$coming_from_parentz = $coming_from_parent;
}
$coming_from_parent_str = false;
if ($coming_from_parent == true) {
$coming_from_parent_str = " data-parent-module='{$coming_from_parent}' ";
}
if ($coming_from_parent_id == false and isset($attrs['id']) == true) {
$coming_from_parent_strz1 = $attrs['id'];
} else {
$coming_from_parent_strz1 = $coming_from_parent_id;
}
if ($coming_from_parent == true) {
$attrs['data-parent-module'] = $coming_from_parent;
}
if ($coming_from_parent_id == true) {
$attrs['data-parent-module-id'] = $coming_from_parent_strz1;
}
// d($attrs);
$mod_content = $this->load($module_name, $attrs);
$plain_modules = mw_var('plain_modules');
if ($plain_modules != false) {
if (!defined('MW_PLAIN_MODULES')) {
define('MW_PLAIN_MODULES', true);
}
}
$plain_modules = false;
preg_match_all('/.*?class=..*?edit.*?.[^>]*>/', $mod_content, $modinner);
$proceed_with_parse = false;
if (!empty($modinner) and isset($modinner[0][0])) {
$proceed_with_parse = true;
} else {
preg_match_all('/<module.*[^>]*>/', $mod_content, $modinner);
if (!empty($modinner) and isset($modinner[0][0])) {
$proceed_with_parse = true;
} else {
preg_match_all('/<mw.*[^>]*>/', $mod_content, $modinner);
if (!empty($modinner) and isset($modinner[0][0])) {
$proceed_with_parse = true;
} else {
preg_match_all('/<microweber.*[^>]*>/', $mod_content, $modinner);
if (!empty($modinner) and isset($modinner[0][0])) {
$proceed_with_parse = true;
}
}
}
}
unset($this->mw_replaced_modules[$key]);
if ($proceed_with_parse == true) {
$mod_content = $this->process($mod_content, $options, $coming_from_parentz, $coming_from_parent_strz1);
}
if ($mod_no_wrapper == false) {
$module_html .= $coming_from_parent_str . '>' . $mod_content . '</div>';
} else {
$module_html = $mod_content;
}
$this->mw_replaced_modules_values[$replace_key] = $module_html;
$layout = str_replace($value, $module_html, $layout);
$layout = str_replace($replace_key, $module_html, $layout);
}
}
}
$layout = str_replace($key, $value, $layout);
}
}
}
if (!empty($this->_replaced_codes)) {
foreach ($this->_replaced_codes as $key => $value) {
if ($value != '') {
$layout = str_replace($key, $value, $layout);
}
unset($this->_replaced_codes[$key]);
}
}
if (!empty($this->mw_replaced_modules_values)) {
$reps_arr = array();
$reps_arr2 = array();
foreach ($this->mw_replaced_modules_values as $key => $value) {
if ($value != '') {
$reps_arr[] = $key;
$reps_arr2[] = $value;
// $layout = str_replace($key, $value, $layout);
}
}
$layout = str_replace($reps_arr, $reps_arr2, $layout);
}
$layout = str_replace('{rand}', uniqid() . rand(), $layout);
$layout = str_replace('{SITE_URL}', $this->app->url_manager->site(), $layout);
$layout = str_replace('{MW_SITE_URL}', $this->app->url_manager->site(), $layout);
$layout = str_replace('%7BSITE_URL%7D', $this->app->url_manager->site(), $layout);
$mw_replaced_edit_fields_vals[$parser_mem_crc] = $layout;
return $layout;
}