function ui_register_object($object_name, $objecttype) { $prop_path = GLOBALDATA_PATH; $slug_name = sanitize_title($object_name); /* ----------------------------------- */ /* 2.1. Create View page */ ui_create_post($object_name . ' - view', $objecttype, $slug_name); echo '<div><p style="font-family:courier; color:green;">New view ' . $objecttype . ' created</p></div>'; /* ----------------------------------- */ /* 2.2. Create Form page */ if ($objecttype != 'landingpage') { ui_create_post($object_name . ' - form', $objecttype, $slug_name, 'basic-create-post'); echo '<div><p style="font-family:courier; color:green;">New form ' . $objecttype . ' created</p></div>'; } /* ----------------------------------- */ /* 2.3. Create List page */ if ($objecttype != 'landingpage') { ui_create_post($object_name . ' - list', $objecttype, $slug_name); echo '<div><p style="font-family:courier; color:green;">New list ' . $objecttype . ' created</p></div>'; } /* ------------------------------------ */ if ($objecttype == 'old_posttype') { /* check is name exist */ /*foreach ($posttypes_array as $key => $value) { if($key == $slug_name){ ?> <div> <pre class="alert alert-warning" style="font-size:24px; margin:20px; font-family:arial">Posttype on this NAME already exist.<br>Input diffrent name !!!</pre> </div> <?php die(); } }*/ /* ----------------------------------- */ /* 1.1. Create posttype declaration */ /*$posttypes_array = Spyc::YAMLLoad( $prop_path . 'uigen-posttype/arguments/uigen-posttype-creator-arguments.yaml' ); $posttype_schema = Spyc::YAMLLoad( $prop_path . 'uigen-posttype/schemas/uigen-posttype-creator-schema.yaml' ); $posttype_added_array[$slug_name] = $posttype_schema['example_posttype']; $posttype_added_array[$slug_name]['label'] = $object_name; $posttype_added_array[$slug_name]['labels']['name'] = $object_name; $posttype_added_array[$slug_name]['labels']['singular_name'] = $object_name; require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/core-files/init-uigen-yaml-get-merge.php'; $posttypes_array = ui_merge_data_array($posttypes_array,$posttype_added_array);*/ /* echo '<div><h2>Declarated posttype - OK</h2><pre>'; print_r(Spyc::YAMLDump($posttype_added_array )); echo '</pre></div>';*/ /*echo '<div><p style="font-family:courier; color:green;">Declarated posttype - OK</p><div>';*/ /* create posttype declarations array */ /*file_put_contents( $prop_path . 'uigen-posttype/arguments/uigen-posttype-creator-arguments.yaml' , Spyc::YAMLDump($posttypes_array ));*/ } if ($objecttype == 'landingpage') { /* ----------------------------------- */ /* 1.1. Create database declaration */ $posttype_array[$object_name] = $_POST['object_data']; $posttype_array[$object_name]['object_name'] = $slug_name; /* create posttype declarations array */ $prop_path = GLOBALDATA_PATH; $posttype_old_array = Spyc::YAMLLoad($prop_path . 'uigen-landing-pages/arguments/landingpages-arguments.yaml'); require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/core-files/init-uigen-yaml-get-merge.php'; $posttype_array = ui_merge_data_array($posttype_old_array, $posttype_array); file_put_contents($prop_path . 'uigen-landing-pages/arguments/landingpages-arguments.yaml', Spyc::YAMLDump($posttype_array)); } if ($objecttype == 'posttype') { $posttypes_array = Spyc::YAMLLoad($prop_path . 'uigen-posttype/arguments/uigen-posttype-creator-arguments.yaml'); $posttype_schema = Spyc::YAMLLoad($prop_path . 'uigen-posttype/schemas/uigen-posttype-creator-schema.yaml'); $posttype_added_array[$slug_name] = $posttype_schema['example_posttype']; $posttype_added_array[$slug_name]['label'] = $object_name; $posttype_added_array[$slug_name]['labels']['name'] = $object_name; $posttype_added_array[$slug_name]['labels']['singular_name'] = $object_name; require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/core-files/init-uigen-yaml-get-merge.php'; $posttypes_array = ui_merge_data_array($posttypes_array, $posttype_added_array); /* create posttype declarations array */ file_put_contents($prop_path . 'uigen-posttype/arguments/uigen-posttype-creator-arguments.yaml', Spyc::YAMLDump($posttypes_array)); } if ($objecttype == 'db') { /* ----------------------------------- */ /* 1.1. Create database declaration */ $db_array[$object_name] = $_POST['object_data']; $db_array[$object_name]['object_name'] = $slug_name; /* create posttype declarations array */ $prop_path = GLOBALDATA_PATH; $db_old_array = Spyc::YAMLLoad($prop_path . 'uigen-database/arguments/database-arguments.yaml'); require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/core-files/init-uigen-yaml-get-merge.php'; // update yaml file $db_array = ui_merge_data_array($db_old_array, $db_array); file_put_contents($prop_path . 'uigen-database/arguments/database-arguments.yaml', Spyc::YAMLDump($db_array)); // create new table global $wpdb; //require_once UIGENCLASS_PATH . 'Spyc.php'; //$debuger_db = Spyc::YAMLLoad( GLOBALDATA_PATH . 'uigen-database/arguments/database-arguments.yaml' ); $debuger_db = $db_array; foreach ($debuger_db as $db_tb_name => $db_props) { $db_create_table_string = ''; $db_create_table_string .= "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}" . $db_tb_name . "` ( \n"; $db_create_table_string .= "`ID` int(5) NOT NULL AUTO_INCREMENT, \n"; foreach ($db_props['db_table_columns'] as $db_col_props) { $db_create_table_string .= "`" . $db_col_props['db_column_name'] . "` " . $db_col_props['db_column_type'] . " NOT NULL, \n"; //var_dump('db>' , $db_col_props['db_column_name']); //var_dump('db>' , $db_col_props['db_column_type']); } $db_create_table_string .= " PRIMARY KEY (`ID`) \n"; //$db_create_table_string .= " CHARACTER SET utf8 COLLATE utf8_general_ci \n"; $db_create_table_string .= " ) \n"; $db_tables_array[$db_tb_name] = $db_create_table_string; } //var_dump($db_tables_array); // Create tables echo '<pre>'; foreach ($db_tables_array as $db_tb => $db_sql_synax) { echo '<br/>----------------<br/>create ' . $db_tb . '<br/>----------------<br/>'; echo $db_sql_synax; $wpdb->query($db_sql_synax); } echo '</pre>'; } if ($objecttype == 'user') { /* ----------------------------------- */ /* 1.1. Create database declaration */ $users_array = Spyc::YAMLLoad($prop_path . 'uigen-users/arguments/users-arguments.yaml'); $users_schema = Spyc::YAMLLoad($prop_path . 'uigen-users/schemas/uigen-users-creator-schema.yaml'); $users_added_array[$slug_name] = $users_schema['example_user']; $users_added_array[$slug_name]['label'] = $object_name; $users_added_array[$slug_name]['labels']['name'] = $object_name; $users_added_array[$slug_name]['labels']['singular_name'] = $object_name; require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/core-files/init-uigen-yaml-get-merge.php'; $users_array = ui_merge_data_array($users_array, $users_added_array); /* create users declarations array */ file_put_contents($prop_path . 'uigen-users/arguments/users-arguments.yaml', Spyc::YAMLDump($users_array)); } /* ------------------------------------ */ /* 3.1. Create View properties and hierarchy yaml file */ //chmod($prop_path . 'template-hierarchy/arguments', 0755); create_properties_and_hierarchy_files($slug_name, $objecttype, 'view'); /* ------------------------------------ */ /* ------------------------------------ */ // 3.2. Create Form properties and hierarchy yaml file */ if ($objecttype != 'landingpage') { create_properties_and_hierarchy_files($slug_name, $objecttype, 'form'); } /* ------------------------------------ */ /* ------------------------------------ */ // 3.3. Create list properties and hierarchy yaml file */ if ($objecttype != 'landingpage') { create_properties_and_hierarchy_files($slug_name, $objecttype, 'list'); } /* ------------------------------------ */ /* ------------------------------------ */ // 4.1. Create page template php file */ //$output = "<?php\n"; //$output .= "/* Template Name: " . $slug_name . " " . $objecttype . " Template */\n"; //$output .= "get_header();\n"; //$output .= "\$ui_page_name = \$post -> post_name;\n"; //$output .= "require_once COREFILES_PATH . 'init-uigen-tdc.php';\n"; //$output .= "require_once COREFILES_PATH . 'init-uigen-yaml-get-merge.php';\n"; //$output .= "require_once COREFILES_PATH . 'init-uigen-flow.php';\n"; //$output .= "\$TDC -> tdc_get_grid(\$args['grid'], \$args, \$slots_handler,\$SPD);\n"; //$output .= "get_footer();\n"; // /*chmod($prop_path . TEMPLATEPATH, 0755);*/ //file_put_contents( TEMPLATEPATH . '/UiGEN_Tpl_' . $slug_name . '_'.$objecttype.'.php' , $output); }
<?php // ARGS -> load yaml // parse data url if ($_GET['data'] != '') { $getParsedYAML = urldecode($_GET['data']); $YAMLParsedArray = Spyc::YAMLLoadString($getParsedYAML); $args = ui_merge_data_array($args, $YAMLParsedArray); echo '<pre>'; var_dump($getParsedYAML); echo '</pre>'; } function ui_merge_data_array($orgin_array, $part_to_merge) { $args = array_merge($orgin_array, $part_to_merge); return $args; }
//$loadedYAML = Spyc::YAMLLoadString(GLOBALDATA_PATH.'template-hierarchy/arguments/'.$_POST['ui_page_name'].'-slots-properties.yaml'); $loaded_orginal_YAML = Spyc::YAMLLoad(GLOBALDATA_PATH . 'template-hierarchy/arguments/' . $_POST['ui_page_name'] . '-slots-properties.yaml'); $loaded_saved_YAML = Spyc::YAMLLoadString($_POST['yaml']); //$YAMLParsedArray = Spyc::YAMLDump($loadedYAML); // if grid-name == first key then this is all properties array // if grid-name != first key then this is slot properties $first_key = key($loaded_saved_YAML); if ($first_key == $_POST['ui_grid_name']) { //var_dump($loaded_saved_YAML[$_POST['ui_grid_name']]); $returnYAML = Spyc::YAMLDump(ui_merge_data_array($loaded_orginal_YAML, $loaded_saved_YAML[$_POST['ui_grid_name']])); /* WARNING - Stripshlashes post data - but only to admin or high level users */ $returnYAML = str_replace("'", "", $returnYAML); $returnYAML = stripslashes($returnYAML); file_put_contents(GLOBALDATA_PATH . 'template-hierarchy/arguments/' . $_POST['ui_page_name'] . '-slots-properties.yaml', $returnYAML); } else { $returnYAML = Spyc::YAMLDump(ui_merge_data_array($loaded_orginal_YAML, $loaded_saved_YAML)); /* WARNING - Stripshlashes post data - but only to admin or high level users */ $returnYAML = str_replace("'", "", $returnYAML); $returnYAML = stripslashes($returnYAML); file_put_contents(GLOBALDATA_PATH . 'template-hierarchy/arguments/' . $_POST['ui_page_name'] . '-slots-properties.yaml', $returnYAML); } ?> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close and dont previw saved changes</button> <a href="<?php the_permalink(); ?> " type="button" class="btn btn-primary">Reload page to see changes<a> </div> </div>