function save_field() { $id = is_admin(); if ($id == false) { exit('Error: not logged in as admin.'); } if ($_POST) { $the_field_data_all = $_POST; } else { exit('Error: no POST?'); } $is_no_save = url_param('peview', true); //p($is_no_save); $ref_page = $_SERVER['HTTP_REFERER']; if ($ref_page != '') { //$page_id = $ref_page->page->id; //$the_ref_page = get_page ( $page_id ); $ref_page = $the_ref_page = get_ref_page(); //p($ref_page); $page_id = $ref_page['id']; } $json_print = array(); foreach ($the_field_data_all as $the_field_data) { if (!empty($the_field_data)) { $save_global = false; if ($the_field_data['attributes']) { //$the_field_data ['attributes'] = json_decode($the_field_data ['attributes']); //var_dump($the_field_data ['attributes']); } if (intval($the_field_data['attributes']['page']) != 0) { $page_id = intval($the_field_data['attributes']['page']); $content_id = $page_id; $the_ref_page = get_page($page_id); } if (intval($the_field_data['attributes']['post']) != 0) { $post_id = intval($the_field_data['attributes']['post']); $content_id = $post_id; $the_ref_post = get_post($post_id); } if (intval($the_field_data['attributes']['category']) != 0) { $category_id = intval($the_field_data['attributes']['category']); } $page_element_id = false; if (strval($the_field_data['attributes']['id']) != '') { $page_element_id = $the_field_data['attributes']['id']; } if ($the_field_data['attributes']['global'] != false) { $save_global = true; } if ($the_field_data['attributes']['rel'] == 'global') { $save_global = true; } if ($the_field_data['attributes']['rel'] == 'post') { if ($ref_page != '') { $save_global = false; $ref_post = $the_ref_post = get_ref_post(); //p ( $ref_post ); $post_id = $ref_post['id']; $page_id = $ref_page['id']; $content_id = $post_id; } } if ($the_field_data['attributes']['rel'] == 'page') { // p ( $_SERVER ); if ($ref_page != '') { $save_global = false; $ref_page = $the_ref_page = get_ref_page(); $page_id = $ref_page['id']; $content_id = $page_id; } } if ($the_field_data['attributes']['rel'] == 'PAGE_ID') { // p ( $_SERVER ); if ($ref_page != '') { $save_global = false; $ref_page = $the_ref_page = get_ref_page(); $page_id = $ref_page['id']; $content_id = $page_id; } } if ($the_field_data['attributes']['rel'] == 'POST_ID') { // p ( $_SERVER ); if ($ref_page != '') { $save_global = false; $ref_page = $the_ref_page = get_ref_page(); $page_id = $ref_page['id']; $content_id = $page_id; } } if ($category_id == false and $page_id == false and $post_id == false and $save_global == false) { print 'Error: plase specify integer value for at least one of those attributes - page, post or category'; } else { $some_mods = array(); if ($the_field_data['attributes']['field'] != '') { if ($the_field_data['html'] != '') { $field = trim($the_field_data['attributes']['field']); $html_to_save = $the_field_data['html']; $html_to_save = str_replace('MICROWEBER', 'microweber', $html_to_save); //$html_to_save = str_replace ( '<div><br></div>', '<br>', $html_to_save ); //$html_to_save = str_replace ( '<div><br /></div>', '<br />', $html_to_save ); //$html_to_save = str_replace ( '<div></div>', '<br />', $html_to_save ); $content = $html_to_save; $html_to_save = $content; if (strstr($content, 'mw_params_encoded') == true) { $tags1 = extract_tags($content, 'div', $selfclosing = true, $return_the_entire_tag = true, $charset = 'UTF-8'); // p($tags); $matches = $tags1; if (!empty($matches)) { // foreach ($matches as $m) { // if ($m['tag_name'] == 'div') { $attr = $m['attributes']; if (strval($attr['module_id']) == '') { $attr['module_id'] = 'module_' . rand() . rand() . rand() . rand(); } if ($attr['module_id'] != '') { $mw_params_encoded = $attr; $mod_id = $attr['module_id']; $tag1 = "<microweber "; foreach ($mw_params_encoded as $k => $v) { $skip_key = false; if ($k == 'edit') { $v = 'edit_tag'; } if ($k == 'onmouseup') { $v = ''; $skip_key = true; } if ($k == 'class') { $v = ''; $skip_key = true; } if ($skip_key == false) { if (strtolower(trim($k)) != 'save' and strtolower(trim($k)) != 'submit') { $tag1 = $tag1 . "{$k}=\"{$v}\" "; } } $tag1 = $tag1 . "module=\"{$attr['mw_params_module']}\" "; } $tag1 .= " />"; $some_mods[$mod_id] = $tag1; } } } } /*$doc = new DOMDocument (); $doc->preserveWhiteSpace = true; $doc->loadHTML ( $content ); $xpath = new DOMXpath ( $doc ); foreach ( $xpath->query ( '//div[@mw_params_encoded]' ) as $a ) { // $clunker_vars = get_object_vars($a->nodeValue); // we pass the object, not th //echo "Found {$a->previousSibling->previousSibling->nodeValue}," . " by {$a->previousSibling->nodeValue}\n"; $mw_params_encoded = $a->getAttribute ( 'mw_params_encoded' ); $mod_id = $a->getAttribute ( 'module_id' ); $mw_params_encoded = base64_decode ( $mw_params_encoded ); $mw_params_encoded = unserialize ( $mw_params_encoded ); //$c1 = $a->nodeValue; $c1 = domNodeContent ( $a, 1 ); if (! empty ( $mw_params_encoded )) { $tag1 = "<microweber "; foreach ( $mw_params_encoded as $k => $v ) { if ($k == 'edit') { $v = 'edit_tag'; } if ((strtolower ( trim ( $k ) ) != 'save') and (strtolower ( trim ( $k ) ) != 'submit')) { $tag1 = $tag1 . "{$k}=\"{$v}\" "; } } $tag1 .= " />"; $some_mods [$mod_id] = $tag1; //p ( $tag1 ); // p ( $c1 ); //$c1 = trim ( $c1 ); //$content = trim ( $content ); //$content123 = explode ( $c1, $content ); //$content = str_ireplace ( $c1, $tag1, $content ); // p($content123); } }*/ // //$parsed = get_string_between ( $content, "mw_params_encoded=\"", '"' ); // } //p($some_mods,1); $html_to_save = $content; foreach ($some_mods as $some_mod_k => $some_mod_v) { //$t1 = extact_tag_by_attr ( 'module_id', $some_mod_k, $content, 'div' ); //p ( $t1 ); $content = preg_replace("#<div[^>]*id=\"{$some_mod_k}\".*?</div>#si", $some_mod_v, $content); } if ($is_no_save != true) { $pattern = "/mw_last_hover=\"[0-9]*\"/"; $pattern = "/mw_last_hover=\"[0-9]*\"/i"; $content = preg_replace($pattern, "", $content); $pattern = "/mw_last_hover=\"\"/"; $content = preg_replace($pattern, "", $content); $pattern = "/mw_tag_edit=\"[0-9]*\"/i"; $content = preg_replace($pattern, "", $content); $pattern = "/mw_tag_edit=\"\"/"; $content = preg_replace($pattern, "", $content); } //$content = preg_replace ( "#<div[^>]*id=\"{$some_mod_k}\".*?</div>#si", $some_mod_v, $content ); $html_to_save = $content; // p ( $content,1 ); if (strstr($content, '<div') == true) { $relations = array(); $tags = extract_tags($content, 'div', $selfclosing = false, $return_the_entire_tag = true, $charset = 'UTF-8'); $matches = $tags; if (!empty($matches)) { // foreach ($matches as $m) { // // p ( ($m) ); if ($m['tag_name'] == 'div') { $replaced = false; $attr = $m['attributes']; if ($attr['mw_params_encoded']) { $decode_params = $attr['mw_params_encoded']; //$decode_params = base64_decode ( $decode_params ); $decode_params = 'edit_tag'; //p ( $decode_params ); //p ( $attr, 1 ); //print 1111111111111111111111111111111111111111111111111111111; } foreach ($some_mods as $some_mod_k => $some_mod_v) { //p(($m)); // p($some_mod_v); if (stristr($content, $some_mod_k)) { //p ( $content ); //$content = str_ireplace ( $m ['full_tag'], $some_mod_v, $content ); //p ( $content, 1 ); } } //p ( $content, 1 ); if ($attr['class'] == 'module') { // p($attr); if ($attr['base64_array'] != '') { $base64_array = base64_decode($attr['base64_array']); $base64_array = unserialize($base64_array); if (!empty($base64_array)) { $tag1 = "<microweber "; foreach ($base64_array as $k => $v) { if (strtolower(trim($k)) != 'save' and strtolower(trim($k)) != 'submit') { $tag1 = $tag1 . "{$k}=\"{$v}\" "; } } $tag1 .= " />"; $to_save[] = $tag1; $content = str_ireplace($m['full_tag'], $tag1, $content); $replaced = true; //p($base64_array); } } if ($replaced == false) { if ($attr['edit'] != '') { $tag = $attr['edit']; $tag = 'edit_tag'; //$tag = base64_decode ( $tag ); //p ( $tag ); if (strstr($tag, 'module_id=') == false) { $tag = str_replace('/>', ' module_id="module_' . date('Ymdhis') . rand() . '" />', $tag); } $to_save[] = $tag; if ($tag != false) { $content = str_ireplace($m['full_tag'], $tag, $content); } } } } } } $html_to_save = $content; } } $html_to_save = str_ireplace('class="ui-droppable"', '', $html_to_save); $html_to_save = str_ireplace('<div><div></div><div><div></div>', '<br />', $html_to_save); //$html_to_save = str_ireplace ( 'class="ui-droppable"', '', $html_to_save ); //$html_to_save =utfString( $html_to_save ); //$html_to_save = htmlspecialchars ( $html_to_save, ENT_QUOTES ); //$html_to_save = html_entity_decode ( $html_to_save ); //p($html_to_save); // p($content,1); $html_to_save = clean_word($html_to_save); if ($save_global == false) { if ($content_id) { if ($page_id) { $for_histroy = $the_ref_page; if ($post_id) { $for_histroy = $the_ref_post; } if (stristr($field, 'custom_field_')) { $field123 = str_ireplace('custom_field_', '', $field); $old = $for_histroy['custom_fields'][$field123]; } else { $old = $for_histroy[$field]; } $history_to_save = array(); $history_to_save['table'] = 'table_content'; $history_to_save['id'] = $content_id; $history_to_save['value'] = $old; $history_to_save['field'] = $field; //p ( $history_to_save ); if ($is_no_save != true) { CI::model('core')->saveHistory($history_to_save); } } $to_save = array(); $to_save['id'] = $content_id; $to_save['quick_save'] = true; $to_save['page_element_id'] = $page_element_id; $to_save['page_element_content'] = CI::model('template')->parseMicrwoberTags($html_to_save, $options = false); $to_save[$field] = $html_to_save; //print "<h2>For content $content_id</h2>"; //p ( $to_save ); //p ( $html_to_save, 1 ); $json_print[] = $to_save; if ($is_no_save != true) { $saved = CI::model('content')->saveContent($to_save); // p($to_save); //p($content_id); //p($page_id); // p ( $html_to_save ,1); } //print ($html_to_save) ; $html_to_save = CI::model('template')->parseMicrwoberTags($html_to_save, $options = false); } else { if ($category_id) { print __FILE__ . __LINE__ . ' category is not implemented not rady yet'; } } } else { $field_content = CI::model('core')->optionsGetByKey($the_field_data['attributes']['field'], $return_full = true, $orderby = false); $to_save = $field_content; $to_save['option_key'] = $the_field_data['attributes']['field']; $to_save['option_value'] = $html_to_save; $to_save['option_key2'] = 'editable_region'; $to_save['page_element_id'] = $page_element_id; $to_save['page_element_content'] = CI::model('template')->parseMicrwoberTags($html_to_save, $options = false); //print "<h2>Global</h2>"; if ($is_no_save != true) { $to_save = CI::model('core')->optionsSave($to_save); } $json_print[] = $to_save; $history_to_save = array(); $history_to_save['table'] = 'global'; // $history_to_save ['id'] = 'global'; $history_to_save['value'] = $field_content['option_value']; $history_to_save['field'] = $field; if ($is_no_save != true) { CI::model('core')->saveHistory($history_to_save); } $html_to_save = CI::model('template')->parseMicrwoberTags($html_to_save, $options = false); // $json_print[] = array ($the_field_data ['attributes'] ['id'] => $html_to_save ); // print ($html_to_save) ; // print ($to_save) ; //p ( $field_content ); //optionsSave($data) } } } else { // print ('Error: plase specify a "field" attribute') ; // p($the_field_data); } } } } // p($_POST); /* if (! empty ( $_POST )) { foreach ( $_POST as $k => $v ) { // $v2 = array (); foreach ( $v as $v1_k => $v1_v ) { $html = CI::model ( 'template' )->parseMicrwoberTags ( $v1_v, $options = false ); $v2 [$v1_k] = ( $html ); } $json_print [$k] = $v2; } } */ header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Content-type: application/json'); $json_print = json_encode($json_print); print $json_print; CI::model('core')->cleanCacheGroup('global/blocks'); exit; }
function index() { $module_info = url_param('module_info', true); if ($module_info) { if ($_POST['module']) { $_POST['module'] = str_replace('..', '', $_POST['module']); $try_config_file = MODULES_DIR . '' . $_POST['module'] . '_config.php'; if (is_file($try_config_file)) { include $try_config_file; if ($config['icon'] == false) { $config['icon'] = MODULES_DIR . '' . $_POST['module'] . '.png'; $config['icon'] = pathToURL($config['icon']); } print json_encode($config); exit; } } } $is_iframe = url_param('iframe'); $base64 = url_param('base64', true); $admin = url_param('admin', true); $mod1 = url_param('module_name', true); $decode_vars = url_param('decode_vars', true); $reload_module = url_param('reload_module', true); $mod_to_edit = url_param('module_to_edit', true); $element_id = url_param('element_id', true); if ($mod1 != false) { $mod1 = urldecode($mod1); } $mod_iframe = false; if ($mod_to_edit != false) { $mod_to_edit = str_ireplace('_mw_slash_replace_', '/', $mod_to_edit); $mod_iframe = true; } //p($mod_to_edit); if ($base64 == false) { if ($is_iframe) { $data = $is_iframe; $data = base64_decode($data); $data = unserialize($data); } else { $data = $_POST; } if ($reload_module == 'edit_tag') { $reload_module = $_POST; $data = $reload_module; //p($data); } if ($mod1 != '') { $data['module'] = $mod1; } $is_page_id = url_param('page_id', true); if ($is_page_id != '') { $data['page_id'] = $is_page_id; } $is_post_id = url_param('post_id', true); if ($is_post_id != '') { $data['post_id'] = $is_post_id; } $is_category_id = url_param('category_id', true); if ($is_category_id != '') { $data['category_id'] = $is_category_id; } $is_rel = url_param('rel', true); if ($is_rel != '') { $data['rel'] = $is_rel; if ($is_rel == 'page') { $test = get_ref_page(); if (!empty($test)) { if ($data['page_id'] == false) { $data['page_id'] = $test['id']; } } //p($test); } if ($is_rel == 'post') { //$refpage = get_ref_page (); $refpost = get_ref_post(); if (!empty($refpost)) { if ($data['post_id'] == false) { $data['post_id'] = $refpost['id']; } } } if ($is_rel == 'category') { //$refpage = get_ref_page (); $refpost = get_ref_post(); if (!empty($refpost)) { if ($data['post_id'] == false) { $data['post_id'] = $refpost['id']; } } } } $tags = false; if ($data['mw_params_module'] != false) { if (trim($data['mw_params_module']) != '') { $data['module'] = $data['mw_params_module']; } } //p($data); foreach ($data as $k => $v) { $tags .= "{$k}=\"{$v}\" "; } $tags = "<microweber {$tags}></microweber>"; } else { if ($base64 == 'undefined') { exit; } //$base64 = base64_decode ( $base64 ); if (is_string($base64) == false) { // $base64 = false; } //$base64 = unserialize($base64); //p ( $base64 ); // } if ($base64 != false) { $tags = $base64; if ($mod_iframe == true) { $mod_iframe = 'quick_edit="true"'; } $tags = "<microweber module='{$mod_to_edit}' module_id='{$element_id}' {$mod_iframe} ></microweber>"; } //p ( $tags ); //exit; $opts = array(); $opts['admin'] = $admin; if ($base64 != false or $is_iframe != false) { $opts['do_not_wrap'] = true; } $res = CI::model('template')->parseMicrwoberTags($tags, $opts); if ($admin == true) { $is_admin = is_admin(); if ($is_admin == false) { $go = site_url('login'); safe_redirect($go); } $opts['no_cache'] = true; $res_1 = CI::view('admin/module_admin', true, true); $res_1 = CI::model('template')->parseMicrwoberTags($res_1, $opts); } if ($res_1) { $res = str_replace('{content}', $res, $res_1); } print $res; exit; // phpinfo(); }